Code

Node tool: fix handle retraction with non-cusp nodes
[inkscape.git] / src / live_effects / lpe-line_segment.cpp
1 #define INKSCAPE_LPE_LINE_SEGMENT_CPP
3 /** \file
4  * LPE <line_segment> implementation
5  */
7 /*
8  * Authors:
9  *   Maximilian Albert
10  *
11  * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 #include "live_effects/lpe-line_segment.h"
17 #include "lpe-tool-context.h"
19 #include <2geom/pathvector.h>
20 #include <2geom/geom.h>
21 #include <2geom/bezier-curve.h>
23 namespace Inkscape {
24 namespace LivePathEffect {
26 static const Util::EnumData<EndType> EndTypeData[] = {
27     {END_CLOSED       , N_("Closed"), "closed"},
28     {END_OPEN_INITIAL , N_("Open start"), "open_start"},
29     {END_OPEN_FINAL   , N_("Open end"), "open_end"},
30     {END_OPEN_BOTH    , N_("Open both"), "open_both"},
31 };
32 static const Util::EnumDataConverter<EndType> EndTypeConverter(EndTypeData, sizeof(EndTypeData)/sizeof(*EndTypeData));
34 LPELineSegment::LPELineSegment(LivePathEffectObject *lpeobject) :
35     Effect(lpeobject),
36     end_type(_("End type"), _("Determines on which side the line or line segment is infinite."), "end_type", EndTypeConverter, &wr, this, END_OPEN_BOTH)
37 {
38     /* register all your parameters here, so Inkscape knows which parameters this effect has: */
39     registerParameter( dynamic_cast<Parameter *>(&end_type) );
40 }
42 LPELineSegment::~LPELineSegment()
43 {
45 }
47 void
48 LPELineSegment::doBeforeEffect (SPLPEItem *lpeitem)
49 {
50     lpetool_get_limiting_bbox_corners(SP_OBJECT_DOCUMENT(lpeitem), bboxA, bboxB);
51 }
53 std::vector<Geom::Path>
54 LPELineSegment::doEffect_path (std::vector<Geom::Path> const & path_in)
55 {
56     std::vector<Geom::Path> output;
58     A = initialPoint(path_in);
59     B = finalPoint(path_in);
61     Geom::Rect dummyRect(bboxA, bboxB);
62     boost::optional<Geom::LineSegment> intersection_segment = Geom::rect_line_intersect(dummyRect, Geom::Line(A, B));
64     if (!intersection_segment) {
65         g_print ("Possible error - no intersection with limiting bounding box.\n");
66         return path_in;
67     }
69     if (end_type == END_OPEN_INITIAL || end_type == END_OPEN_BOTH) {
70         A = (*intersection_segment).initialPoint();
71     }
73     if (end_type == END_OPEN_FINAL || end_type == END_OPEN_BOTH) {
74         B = (*intersection_segment).finalPoint();
75     }
77     Geom::Path path(A);
78     path.appendNew<Geom::LineSegment>(B);
80     output.push_back(path);
82     return output;
83 }
85 } //namespace LivePathEffect
86 } /* namespace Inkscape */
88 /*
89   Local Variables:
90   mode:c++
91   c-file-style:"stroustrup"
92   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
93   indent-tabs-mode:nil
94   fill-column:99
95   End:
96 */
97 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :