summaryrefslogtreecommitdiffstats
path: root/src/live_effects
diff options
context:
space:
mode:
authorMichael Soegtrop <MSoegtrop@yahoo.de>2016-05-23 20:36:18 +0000
committerMichael Soegtrop <MSoegtrop@yahoo.de>2016-05-23 20:36:18 +0000
commit9b667f5ad22543b88067107425ec55ef972e2ff0 (patch)
tree933384cbb74b5bca4c94417e1ebd6270688bbb9a /src/live_effects
parentAdded bool LPE (diff)
parentFix regression: restore order in resources (e.g. pattern list) (diff)
downloadinkscape-9b667f5ad22543b88067107425ec55ef972e2ff0.tar.gz
inkscape-9b667f5ad22543b88067107425ec55ef972e2ff0.zip
Fixed Bool LPE review issues
(bzr r14876.2.2)
Diffstat (limited to 'src/live_effects')
-rw-r--r--src/live_effects/effect.cpp4
-rw-r--r--src/live_effects/lpe-bool.cpp596
-rw-r--r--src/live_effects/lpe-bool.h41
-rw-r--r--src/live_effects/lpe-mirror_symmetry.cpp330
-rw-r--r--src/live_effects/lpe-mirror_symmetry.h37
5 files changed, 632 insertions, 376 deletions
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp
index b03671027..0d28836ca 100644
--- a/src/live_effects/effect.cpp
+++ b/src/live_effects/effect.cpp
@@ -105,7 +105,6 @@ const Util::EnumData<EffectType> LPETypeData[] = {
{EXTRUDE, N_("Extrude"), "extrude"},
{LATTICE, N_("Lattice Deformation"), "lattice"},
{LINE_SEGMENT, N_("Line Segment"), "line_segment"},
- {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"},
{OFFSET, N_("Offset"), "offset"},
{PARALLEL, N_("Parallel"), "parallel"},
{PATH_LENGTH, N_("Path length"), "path_length"},
@@ -114,6 +113,7 @@ const Util::EnumData<EffectType> LPETypeData[] = {
{RECURSIVE_SKELETON, N_("Recursive skeleton"), "recursive_skeleton"},
{TANGENT_TO_CURVE, N_("Tangent to curve"), "tangent_to_curve"},
{TEXT_LABEL, N_("Text label"), "text_label"},
+ {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet-chamfer"},
#endif
/* 0.46 */
{BEND_PATH, N_("Bend"), "bend_path"},
@@ -137,7 +137,6 @@ const Util::EnumData<EffectType> LPETypeData[] = {
{SIMPLIFY, N_("Simplify"), "simplify"},
{LATTICE2, N_("Lattice Deformation 2"), "lattice2"},
{PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective-envelope"},
- {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet-chamfer"},
{INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"},
{TRANSFORM_2PTS, N_("Transform by 2 points"), "transform_2pts"},
{SHOW_HANDLES, N_("Show handles"), "show_handles"},
@@ -145,6 +144,7 @@ const Util::EnumData<EffectType> LPETypeData[] = {
{BSPLINE, N_("BSpline"), "bspline"},
{JOIN_TYPE, N_("Join type"), "join_type"},
{TAPER_STROKE, N_("Taper stroke"), "taper_stroke"},
+ {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"},
{COPY_ROTATE, N_("Rotate copies"), "copy_rotate"},
/* Ponyscape -> Inkscape 0.92*/
{ATTACH_PATH, N_("Attach path"), "attach_path"},
diff --git a/src/live_effects/lpe-bool.cpp b/src/live_effects/lpe-bool.cpp
index 902bb081b..6c9830fbd 100644
--- a/src/live_effects/lpe-bool.cpp
+++ b/src/live_effects/lpe-bool.cpp
@@ -34,53 +34,55 @@ namespace LivePathEffect {
// Define an extended boolean operation type
static const Util::EnumData<LPEBool::bool_op_ex> BoolOpData[LPEBool::bool_op_ex_count] = {
- { LPEBool::bool_op_ex_union, N_("union"), "union" },
- { LPEBool::bool_op_ex_inters, N_("intersection"), "inters" },
- { LPEBool::bool_op_ex_diff, N_("difference"), "diff" },
- { LPEBool::bool_op_ex_symdiff, N_("symmetric difference"), "symdiff" },
- { LPEBool::bool_op_ex_cut, N_("cut"), "cut" },
- { LPEBool::bool_op_ex_slice, N_("slice, keep inner contours"), "slice" },
- { LPEBool::bool_op_ex_slice_inside, N_("slice inside, keep inner contours"), "slice-inside" },
- { LPEBool::bool_op_ex_slice_outside, N_("slice outside, keep inner contours"), "slice-outside" },
- { LPEBool::bool_op_ex_slice_rmv_inner, N_("slice, remove inner contours"), "slice-rmv-inner" },
- { LPEBool::bool_op_ex_slice_inside_rmv_inner, N_("slice inside, remove inner contours"), "slice-inside-rmv-inner" },
- { LPEBool::bool_op_ex_slice_outside_rmv_inner, N_("slice outside, remove inner contours"), "slice-outside-rmv-inner" }
+ { LPEBool::bool_op_ex_union, N_("union"), "union" },
+ { LPEBool::bool_op_ex_inters, N_("intersection"), "inters" },
+ { LPEBool::bool_op_ex_diff, N_("difference"), "diff" },
+ { LPEBool::bool_op_ex_symdiff, N_("symmetric difference"), "symdiff" },
+ { LPEBool::bool_op_ex_cut, N_("division"), "cut" },
+ // Note on naming of operations:
+ // bool_op_cut is called "Division" in the manu, see sp_selected_path_cut
+ // bool_op_slice is called "Cut path" in the menu, see sp_selected_path_slice
+ { LPEBool::bool_op_ex_slice, N_("cut"), "slice" },
+ { LPEBool::bool_op_ex_slice_inside, N_("cut inside"), "slice-inside" },
+ { LPEBool::bool_op_ex_slice_outside, N_("cut outside"), "slice-outside" },
};
-static const Util::EnumDataConverter<LPEBool::bool_op_ex> BoolOpConverter(BoolOpData, sizeof(BoolOpData)/sizeof(*BoolOpData));
+static const Util::EnumDataConverter<LPEBool::bool_op_ex> BoolOpConverter(BoolOpData, sizeof(BoolOpData) / sizeof(*BoolOpData));
static const Util::EnumData<fill_typ> FillTypeData[] = {
- { fill_oddEven, N_("odd-even"), "oddeven" },
- { fill_nonZero, N_("non-zero"), "nonzero" },
- { fill_positive, N_("positive"), "positive" },
- { fill_justDont, N_("from curve"), "from-curve" }
+ { fill_oddEven, N_("odd-even"), "oddeven" },
+ { fill_nonZero, N_("non-zero"), "nonzero" },
+ { fill_positive, N_("positive"), "positive" },
+ { fill_justDont, N_("from curve"), "from-curve" }
};
-static const Util::EnumDataConverter<fill_typ> FillTypeConverter(FillTypeData, sizeof(FillTypeData)/sizeof(*FillTypeData));
+static const Util::EnumDataConverter<fill_typ> FillTypeConverter(FillTypeData, sizeof(FillTypeData) / sizeof(*FillTypeData));
static const Util::EnumData<fill_typ> FillTypeDataThis[] = {
- { fill_oddEven, N_("odd-even"), "oddeven" },
- { fill_nonZero, N_("non-zero"), "nonzero" },
- { fill_positive, N_("positive"), "positive" }
+ { fill_oddEven, N_("odd-even"), "oddeven" },
+ { fill_nonZero, N_("non-zero"), "nonzero" },
+ { fill_positive, N_("positive"), "positive" }
};
-static const Util::EnumDataConverter<fill_typ> FillTypeConverterThis(FillTypeDataThis, sizeof(FillTypeDataThis)/sizeof(*FillTypeDataThis));
+static const Util::EnumDataConverter<fill_typ> FillTypeConverterThis(FillTypeDataThis, sizeof(FillTypeDataThis) / sizeof(*FillTypeDataThis));
LPEBool::LPEBool(LivePathEffectObject *lpeobject) :
- Effect(lpeobject),
- operand_path(_("Operand path:"), _("Operand for the boolean operation"), "operand-path", &wr, this),
- bool_operation(_("Operation:"), _("Boolean Operation"), "operation", BoolOpConverter, &wr, this, bool_op_ex_union),
- swap_operands(_("Swap operands:"), _("Swap operands (useful e.g. for difference)"), "swap-operands", &wr, this),
- fill_type_this(_("Fill type this:"), _("Fill type (winding mode) for this path"), "filltype-this", FillTypeConverterThis, &wr, this, fill_oddEven),
- fill_type_operand(_("Fill type operand:"), _("Fill type (winding mode) for operand path"), "filltype-operand", FillTypeConverter, &wr, this, fill_justDont)
+ Effect(lpeobject),
+ operand_path(_("Operand path:"), _("Operand for the boolean operation"), "operand-path", &wr, this),
+ bool_operation(_("Operation:"), _("Boolean Operation"), "operation", BoolOpConverter, &wr, this, bool_op_ex_union),
+ swap_operands(_("Swap operands:"), _("Swap operands (useful e.g. for difference)"), "swap-operands", &wr, this),
+ rmv_inner(_("Remove inner:"), _("For cut operations: remove inner (non-contour) lines of cutting path to avoid invisible extra points"), "rmv-inner", &wr, this),
+ fill_type_this(_("Fill type this:"), _("Fill type (winding mode) for this path"), "filltype-this", FillTypeConverterThis, &wr, this, fill_oddEven),
+ fill_type_operand(_("Fill type operand:"), _("Fill type (winding mode) for operand path"), "filltype-operand", FillTypeConverter, &wr, this, fill_justDont)
{
- registerParameter(&operand_path);
- registerParameter(&bool_operation);
- registerParameter(&swap_operands);
- registerParameter(&fill_type_this);
- registerParameter(&fill_type_operand);
-
- show_orig_path = true;
+ registerParameter(&operand_path);
+ registerParameter(&bool_operation);
+ registerParameter(&swap_operands);
+ registerParameter(&rmv_inner);
+ registerParameter(&fill_type_this);
+ registerParameter(&fill_type_operand);
+
+ show_orig_path = true;
}
LPEBool::~LPEBool()
@@ -92,231 +94,222 @@ void LPEBool::resetDefaults(SPItem const * /*item*/)
{
}
-bool cmp_cut_position( const Path::cut_position &a, const Path::cut_position &b )
+bool cmp_cut_position(const Path::cut_position &a, const Path::cut_position &b)
{
- return a.piece==b.piece ? a.t<b.t : a.piece<b.piece;
+ return a.piece == b.piece ? a.t < b.t : a.piece < b.piece;
}
Geom::PathVector
sp_pathvector_boolop_slice_intersect(Geom::PathVector const &pathva, Geom::PathVector const &pathvb, bool inside, fill_typ fra, fill_typ frb)
{
- // This is similar to sp_pathvector_boolop/bool_op_slice, but keeps only edges inside the cutter area.
- // The code is also based on sp_pathvector_boolop_slice.
- //
- // We have two paths on input
- // - a closed area which is used to cut out pieces from a contour (called area below)
- // - a contour which is cut into pieces by the border of thr area (called contour below)
- //
- // The code below works in the following steps
- // (a) Convert the area to a shape, so that we can ask the winding number for any point
- // (b) Add both, the contour and the area to a single shape and intersect them
- // (c) Find the intersection points between area border and contour (vector toCut)
- // (d) Split the original contour at the intersection points
- // (e) check for each contour edge in combined shape if its center is inside the area - if not discard it
- // (f) create a vector of all inside edges
- // (g) convert the piece numbers to the piece numbers after applying the cuts
- // (h) fill a bool vector with information which pieces are in
- // (i) filter the descr_cmd of the result path with this bool vector
- //
- // The main inefficieny here is step (e) because I use a winding function of the area-shape which goes
- // through teh complete edge list for each point I ask for, so effort is n-edges-contour * n-edges-area.
- // It is tricky to improve this without building into the livarot code.
- // One way might be to decide at the intersection points which edges touching the intersection points are
- // in by making a loop through all edges on the intersection vertex. Since this is a directed non intersecting
- // graph, this should provide sufficient information.
- // But since I anyway will change this to the new mechanism some time speed is fairly ok, I didn't look into this.
-
-
- // extract the livarot Paths from the source objects
- // also get the winding rule specified in the style
- // Livarot's outline of arcs is broken. So convert the path to linear and cubics only, for which the outline is created correctly.
- Path *contour_path = Path_for_pathvector(pathv_to_linear_and_cubic_beziers( pathva) );
- Path *area_path = Path_for_pathvector(pathv_to_linear_and_cubic_beziers( pathvb) );
-
- // Shapes from above paths
- Shape *area_shape = new Shape;
- Shape *combined_shape = new Shape;
- Shape *combined_inters = new Shape;
-
- // Add the area (process to intersection free shape)
- area_path->ConvertWithBackData(1.0);
- area_path->Fill(combined_shape, 1);
-
- // Convert this to a shape with full winding information
- area_shape->ConvertToShape(combined_shape, frb);
-
- // Add the contour to the combined path (just add, no winding processing)
- contour_path->ConvertWithBackData(1.0);
- contour_path->Fill(combined_shape, 0,true,false,false);
-
- // Intersect the area and the contour - no fill processing
- combined_inters->ConvertToShape(combined_shape, fill_justDont);
-
- // Result path
- Path *result_path = new Path;
- result_path->SetBackData(false);
-
- // Cutting positions for contour
- std::vector<Path::cut_position> toCut;
-
- if ( combined_inters->hasBackData() ) {
- // should always be the case, but ya never know
- {
- for (int i = 0; i < combined_inters->numberOfPoints(); i++) {
- if ( combined_inters->getPoint(i).totalDegree() > 2 ) {
- // possibly an intersection
- // we need to check that at least one edge from the source path is incident to it
- // before we declare it's an intersection
- int cb = combined_inters->getPoint(i).incidentEdge[FIRST];
- int nbOrig=0;
- int nbOther=0;
- int piece=-1;
- float t=0.0;
- while ( cb >= 0 && cb < combined_inters->numberOfEdges() ) {
- if ( combined_inters->ebData[cb].pathID == 0 ) {
- // the source has an edge incident to the point, get its position on the path
- piece=combined_inters->ebData[cb].pieceID;
- if ( combined_inters->getEdge(cb).st == i ) {
- t=combined_inters->ebData[cb].tSt;
- } else {
- t=combined_inters->ebData[cb].tEn;
- }
- nbOrig++;
- }
- if ( combined_inters->ebData[cb].pathID == 1 ) nbOther++; // the cut is incident to this point
- cb=combined_inters->NextAt(i, cb);
- }
- if ( nbOrig > 0 && nbOther > 0 ) {
- // point incident to both path and cut: an intersection
- // note that you only keep one position on the source; you could have degenerate
- // cases where the source crosses itself at this point, and you wouyld miss an intersection
- Path::cut_position cutpos;
- cutpos.piece=piece;
- cutpos.t=t;
- toCut.push_back( cutpos );
- }
- }
- }
- }
- {
- // remove the edges from the intersection polygon
- int i = combined_inters->numberOfEdges() - 1;
- for (;i>=0;i--) {
- if ( combined_inters->ebData[i].pathID == 1 ) {
- combined_inters->SubEdge(i);
- } else {
- const Shape::dg_arete &edge = combined_inters->getEdge(i);
- const Shape::dg_point &start = combined_inters->getPoint(edge.st);
- const Shape::dg_point &end = combined_inters->getPoint(edge.en);
- Geom::Point mid = 0.5*(start.x+end.x);
- int wind = area_shape->PtWinding( mid );
- if ( wind==0 ) {
- combined_inters->SubEdge(i);
- }
- }
- }
- }
- }
-
- // create a vector of pieces, which are in the intersection
- std::vector<Path::cut_position> inside_pieces( combined_inters->numberOfEdges() );
- for( int i=0; i<combined_inters->numberOfEdges(); i++ ) {
- inside_pieces[i].piece = combined_inters->ebData[i].pieceID;
- // Use the t middle point, this is safe to compare with values from toCut in the presence of roundoff errors
- inside_pieces[i].t = 0.5 * (combined_inters->ebData[i].tSt + combined_inters->ebData[i].tEn);
- }
- std::sort( inside_pieces.begin(), inside_pieces.end(), cmp_cut_position );
-
- // sort cut positions
- std::sort( toCut.begin(), toCut.end(), cmp_cut_position );
-
- // Compute piece ids after ConvertPositionsToMoveTo
- {
- int idIncr=0;
- std::vector<Path::cut_position>::iterator itPiece=inside_pieces.begin();
- std::vector<Path::cut_position>::iterator itCut=toCut.begin();
- while( itPiece!=inside_pieces.end() )
- {
- while( itCut!=toCut.end() && cmp_cut_position( *itCut, *itPiece ) )
- {
- ++itCut;
- idIncr+=2;
- }
- itPiece->piece += idIncr;
- ++itPiece;
- }
- }
-
- // Copy the original path to result and cut at the intersection points
- result_path->Copy( contour_path );
- result_path->ConvertPositionsToMoveTo( toCut.size(), toCut.data() ); // cut where you found intersections
-
- // Create an array of bools which states which pieces are in
- std::vector<bool> inside_flags(result_path->descr_cmd.size(), false );
- for( std::vector<Path::cut_position>::iterator itPiece=inside_pieces.begin(); itPiece!=inside_pieces.end(); ++itPiece )
- {
- inside_flags[ itPiece->piece ] = true;
- // also enable the element -1 to get the MoveTo
- if( itPiece->piece>=1 )
- {
- inside_flags[ itPiece->piece-1 ] = true;
- }
- }
+ // This is similar to sp_pathvector_boolop/bool_op_slice, but keeps only edges inside the cutter area.
+ // The code is also based on sp_pathvector_boolop_slice.
+ //
+ // We have two paths on input
+ // - a closed area which is used to cut out pieces from a contour (called area below)
+ // - a contour which is cut into pieces by the border of thr area (called contour below)
+ //
+ // The code below works in the following steps
+ // (a) Convert the area to a shape, so that we can ask the winding number for any point
+ // (b) Add both, the contour and the area to a single shape and intersect them
+ // (c) Find the intersection points between area border and contour (vector toCut)
+ // (d) Split the original contour at the intersection points
+ // (e) check for each contour edge in combined shape if its center is inside the area - if not discard it
+ // (f) create a vector of all inside edges
+ // (g) convert the piece numbers to the piece numbers after applying the cuts
+ // (h) fill a bool vector with information which pieces are in
+ // (i) filter the descr_cmd of the result path with this bool vector
+ //
+ // The main inefficieny here is step (e) because I use a winding function of the area-shape which goes
+ // through teh complete edge list for each point I ask for, so effort is n-edges-contour * n-edges-area.
+ // It is tricky to improve this without building into the livarot code.
+ // One way might be to decide at the intersection points which edges touching the intersection points are
+ // in by making a loop through all edges on the intersection vertex. Since this is a directed non intersecting
+ // graph, this should provide sufficient information.
+ // But since I anyway will change this to the new mechanism some time speed is fairly ok, I didn't look into this.
+
+
+ // extract the livarot Paths from the source objects
+ // also get the winding rule specified in the style
+ // Livarot's outline of arcs is broken. So convert the path to linear and cubics only, for which the outline is created correctly.
+ Path *contour_path = Path_for_pathvector(pathv_to_linear_and_cubic_beziers(pathva));
+ Path *area_path = Path_for_pathvector(pathv_to_linear_and_cubic_beziers(pathvb));
+
+ // Shapes from above paths
+ Shape *area_shape = new Shape;
+ Shape *combined_shape = new Shape;
+ Shape *combined_inters = new Shape;
+
+ // Add the area (process to intersection free shape)
+ area_path->ConvertWithBackData(1.0);
+ area_path->Fill(combined_shape, 1);
+
+ // Convert this to a shape with full winding information
+ area_shape->ConvertToShape(combined_shape, frb);
+
+ // Add the contour to the combined path (just add, no winding processing)
+ contour_path->ConvertWithBackData(1.0);
+ contour_path->Fill(combined_shape, 0, true, false, false);
+
+ // Intersect the area and the contour - no fill processing
+ combined_inters->ConvertToShape(combined_shape, fill_justDont);
+
+ // Result path
+ Path *result_path = new Path;
+ result_path->SetBackData(false);
+
+ // Cutting positions for contour
+ std::vector<Path::cut_position> toCut;
+
+ if (combined_inters->hasBackData()) {
+ // should always be the case, but ya never know
+ {
+ for (int i = 0; i < combined_inters->numberOfPoints(); i++) {
+ if (combined_inters->getPoint(i).totalDegree() > 2) {
+ // possibly an intersection
+ // we need to check that at least one edge from the source path is incident to it
+ // before we declare it's an intersection
+ int cb = combined_inters->getPoint(i).incidentEdge[FIRST];
+ int nbOrig = 0;
+ int nbOther = 0;
+ int piece = -1;
+ float t = 0.0;
+ while (cb >= 0 && cb < combined_inters->numberOfEdges()) {
+ if (combined_inters->ebData[cb].pathID == 0) {
+ // the source has an edge incident to the point, get its position on the path
+ piece = combined_inters->ebData[cb].pieceID;
+ if (combined_inters->getEdge(cb).st == i) {
+ t = combined_inters->ebData[cb].tSt;
+ } else {
+ t = combined_inters->ebData[cb].tEn;
+ }
+ nbOrig++;
+ }
+ if (combined_inters->ebData[cb].pathID == 1) {
+ nbOther++; // the cut is incident to this point
+ }
+ cb = combined_inters->NextAt(i, cb);
+ }
+ if (nbOrig > 0 && nbOther > 0) {
+ // point incident to both path and cut: an intersection
+ // note that you only keep one position on the source; you could have degenerate
+ // cases where the source crosses itself at this point, and you wouyld miss an intersection
+ Path::cut_position cutpos;
+ cutpos.piece = piece;
+ cutpos.t = t;
+ toCut.push_back(cutpos);
+ }
+ }
+ }
+ }
+ {
+ // remove the edges from the intersection polygon
+ int i = combined_inters->numberOfEdges() - 1;
+ for (; i >= 0; i--) {
+ if (combined_inters->ebData[i].pathID == 1) {
+ combined_inters->SubEdge(i);
+ } else {
+ const Shape::dg_arete &edge = combined_inters->getEdge(i);
+ const Shape::dg_point &start = combined_inters->getPoint(edge.st);
+ const Shape::dg_point &end = combined_inters->getPoint(edge.en);
+ Geom::Point mid = 0.5 * (start.x + end.x);
+ int wind = area_shape->PtWinding(mid);
+ if (wind == 0) {
+ combined_inters->SubEdge(i);
+ }
+ }
+ }
+ }
+ }
+
+ // create a vector of pieces, which are in the intersection
+ std::vector<Path::cut_position> inside_pieces(combined_inters->numberOfEdges());
+ for (int i = 0; i < combined_inters->numberOfEdges(); i++) {
+ inside_pieces[i].piece = combined_inters->ebData[i].pieceID;
+ // Use the t middle point, this is safe to compare with values from toCut in the presence of roundoff errors
+ inside_pieces[i].t = 0.5 * (combined_inters->ebData[i].tSt + combined_inters->ebData[i].tEn);
+ }
+ std::sort(inside_pieces.begin(), inside_pieces.end(), cmp_cut_position);
+
+ // sort cut positions
+ std::sort(toCut.begin(), toCut.end(), cmp_cut_position);
+
+ // Compute piece ids after ConvertPositionsToMoveTo
+ {
+ int idIncr = 0;
+ std::vector<Path::cut_position>::iterator itPiece = inside_pieces.begin();
+ std::vector<Path::cut_position>::iterator itCut = toCut.begin();
+ while (itPiece != inside_pieces.end()) {
+ while (itCut != toCut.end() && cmp_cut_position(*itCut, *itPiece)) {
+ ++itCut;
+ idIncr += 2;
+ }
+ itPiece->piece += idIncr;
+ ++itPiece;
+ }
+ }
+
+ // Copy the original path to result and cut at the intersection points
+ result_path->Copy(contour_path);
+ result_path->ConvertPositionsToMoveTo(toCut.size(), toCut.data()); // cut where you found intersections
+
+ // Create an array of bools which states which pieces are in
+ std::vector<bool> inside_flags(result_path->descr_cmd.size(), false);
+ for (std::vector<Path::cut_position>::iterator itPiece = inside_pieces.begin(); itPiece != inside_pieces.end(); ++itPiece) {
+ inside_flags[ itPiece->piece ] = true;
+ // also enable the element -1 to get the MoveTo
+ if (itPiece->piece >= 1) {
+ inside_flags[ itPiece->piece - 1 ] = true;
+ }
+ }
#if 0 // CONCEPT TESTING
- //Check if the inside/outside verdict is consistent - just for testing the concept
- // Retrieve the pieces
- int nParts=0;
- Path** parts=result_path->SubPaths(nParts,false);
+ //Check if the inside/outside verdict is consistent - just for testing the concept
+ // Retrieve the pieces
+ int nParts = 0;
+ Path **parts = result_path->SubPaths(nParts, false);
// Each piece should be either fully in or fully out
- int iPiece=0;
- for( int iPart=0; iPart<nParts; iPart++ )
- {
- bool andsum=true;
- bool orsum=false;
- for( int iCmd=0; iCmd<parts[iPart]->descr_cmd.size(); iCmd++, iPiece++ )
- {
- andsum = andsum && inside_flags[ iPiece ];
- orsum = andsum || inside_flags[ iPiece ];
- }
-
- if( andsum!=orsum )
- {
- g_warning( "Inconsistent inside/outside verdict for part=%d", iPart );
- }
+ int iPiece = 0;
+ for (int iPart = 0; iPart < nParts; iPart++) {
+ bool andsum = true;
+ bool orsum = false;
+ for (int iCmd = 0; iCmd < parts[iPart]->descr_cmd.size(); iCmd++, iPiece++) {
+ andsum = andsum && inside_flags[ iPiece ];
+ orsum = andsum || inside_flags[ iPiece ];
+ }
+
+ if (andsum != orsum) {
+ g_warning("Inconsistent inside/outside verdict for part=%d", iPart);
+ }
}
- g_free(parts);
+ g_free(parts);
#endif
- // iterate over the commands of a path and keep those which are inside
- int iDest=0;
- for( int iSrc=0; iSrc<result_path->descr_cmd.size(); iSrc++ )
- {
- if( inside_flags[iSrc]==inside )
- {
- result_path->descr_cmd[iDest++] = result_path->descr_cmd[iSrc];
- }
- else
- {
- delete result_path->descr_cmd[iSrc];
- }
- }
- result_path->descr_cmd.resize( iDest );
-
- delete combined_inters;
- delete combined_shape;
- delete area_shape;
- delete contour_path;
- delete area_path;
-
- gchar *result_str = result_path->svg_dump_path();
- Geom::PathVector outres = Geom::parse_svg_path(result_str);
- // CONCEPT TESTING g_warning( "%s", result_str );
- g_free(result_str);
- delete result_path;
-
- return outres;
+ // iterate over the commands of a path and keep those which are inside
+ int iDest = 0;
+ for (int iSrc = 0; iSrc < result_path->descr_cmd.size(); iSrc++) {
+ if (inside_flags[iSrc] == inside) {
+ result_path->descr_cmd[iDest++] = result_path->descr_cmd[iSrc];
+ } else {
+ delete result_path->descr_cmd[iSrc];
+ }
+ }
+ result_path->descr_cmd.resize(iDest);
+
+ delete combined_inters;
+ delete combined_shape;
+ delete area_shape;
+ delete contour_path;
+ delete area_path;
+
+ gchar *result_str = result_path->svg_dump_path();
+ Geom::PathVector outres = Geom::parse_svg_path(result_str);
+ // CONCEPT TESTING g_warning( "%s", result_str );
+ g_free(result_str);
+ delete result_path;
+
+ return outres;
}
// remove inner contours
@@ -324,17 +317,17 @@ Geom::PathVector
sp_pathvector_boolop_remove_inner(Geom::PathVector const &pathva, fill_typ fra)
{
Geom::PathVector patht;
- Path *patha = Path_for_pathvector(pathv_to_linear_and_cubic_beziers( pathva ) );
+ Path *patha = Path_for_pathvector(pathv_to_linear_and_cubic_beziers(pathva));
Shape *shape = new Shape;
Shape *shapeshape = new Shape;
Path *resultp = new Path;
resultp->SetBackData(false);
- patha->ConvertWithBackData(0.1);
- patha->Fill(shape, 0);
- shapeshape->ConvertToShape(shape, fra);
- shapeshape->ConvertToForme(resultp, 1, &patha);
+ patha->ConvertWithBackData(0.1);
+ patha->Fill(shape, 0);
+ shapeshape->ConvertToShape(shape, fra);
+ shapeshape->ConvertToForme(resultp, 1, &patha);
delete shape;
delete shapeshape;
@@ -361,73 +354,46 @@ static fill_typ GetFillTyp(SPItem *item)
}
}
-void LPEBool::doEffect (SPCurve * curve)
+void LPEBool::doEffect(SPCurve *curve)
{
Geom::PathVector path_in = curve->get_pathvector();
- if ( operand_path.linksToPath() && operand_path.getObject() )
- {
- bool_op_ex op = bool_operation.get_value();
- bool swap = swap_operands.get_value();
-
- Geom::PathVector path_a = swap ? operand_path.get_pathvector() : path_in;
- Geom::PathVector path_b = swap ? path_in : operand_path.get_pathvector();
-
- // TODO: I would like to use the original objects fill rule if the UI selected rule is fill_justDont.
- // But it doesn't seem possible to access them from here, because SPCurve is not derived from SPItem.
- // The nearest function in the call stack, where this is available is SPLPEItem::performPathEffect (this is then an SPItem)
- // For the parameter curve, this is possible.
- // fill_typ fill_this = fill_type_this. get_value()!=fill_justDont ? fill_type_this.get_value() : GetFillTyp( curve ) ;
- fill_typ fill_this = fill_type_this.get_value();
- fill_typ fill_operand = fill_type_operand.get_value()!=fill_justDont ? fill_type_operand.get_value() : GetFillTyp( operand_path.getObject() );
-
- fill_typ fill_a = swap ? fill_operand : fill_this;
- fill_typ fill_b = swap ? fill_this : fill_operand;
-
- switch( op )
- {
- case bool_op_ex_slice_rmv_inner:
- op = bool_op_ex_slice;
- path_b = sp_pathvector_boolop_remove_inner( path_b, fill_b );
- break;
-
- case bool_op_ex_slice_inside_rmv_inner:
- op = bool_op_ex_slice_inside;
- path_b = sp_pathvector_boolop_remove_inner( path_b, fill_b );
- break;
-
- case bool_op_ex_slice_outside_rmv_inner:
- op = bool_op_ex_slice_outside;
- path_b = sp_pathvector_boolop_remove_inner( path_b, fill_b );
- break;
- }
-
- Geom::PathVector path_out;
-
- if( op==bool_op_ex_slice || op == bool_op_ex_slice_rmv_inner) {
- if( op==bool_op_ex_slice_rmv_inner )
- {
- path_b = sp_pathvector_boolop_remove_inner( path_b, fill_b );
- }
- path_out = sp_pathvector_boolop( path_b, path_a, to_bool_op(op), fill_b, fill_a);
- }
- else if( op==bool_op_ex_slice_inside || op==bool_op_ex_slice_inside_rmv_inner ) {
- if( op==bool_op_ex_slice_inside_rmv_inner )
- {
- path_b = sp_pathvector_boolop_remove_inner( path_b, fill_b );
- }
- path_out = sp_pathvector_boolop_slice_intersect( path_a, path_b, true, fill_a, fill_b);
- } else if( op==bool_op_ex_slice_outside || op == bool_op_ex_slice_outside_rmv_inner ) {
- if( op==bool_op_ex_slice_outside_rmv_inner )
- {
- path_b = sp_pathvector_boolop_remove_inner( path_b, fill_b );
- }
- path_out = sp_pathvector_boolop_slice_intersect( path_a, path_b, false, fill_a, fill_b);
- } else {
- path_out = sp_pathvector_boolop( path_a, path_b, to_bool_op(op), fill_a, fill_b);
- }
- curve->set_pathvector( path_out );
- }
+ if (operand_path.linksToPath() && operand_path.getObject()) {
+ bool_op_ex op = bool_operation.get_value();
+ bool swap = swap_operands.get_value();
+
+ Geom::PathVector path_a = swap ? operand_path.get_pathvector() : path_in;
+ Geom::PathVector path_b = swap ? path_in : operand_path.get_pathvector();
+
+ // TODO: I would like to use the original objects fill rule if the UI selected rule is fill_justDont.
+ // But it doesn't seem possible to access them from here, because SPCurve is not derived from SPItem.
+ // The nearest function in the call stack, where this is available is SPLPEItem::performPathEffect (this is then an SPItem)
+ // For the parameter curve, this is possible.
+ // fill_typ fill_this = fill_type_this. get_value()!=fill_justDont ? fill_type_this.get_value() : GetFillTyp( curve ) ;
+ fill_typ fill_this = fill_type_this.get_value();
+ fill_typ fill_operand = fill_type_operand.get_value() != fill_justDont ? fill_type_operand.get_value() : GetFillTyp(operand_path.getObject());
+
+ fill_typ fill_a = swap ? fill_operand : fill_this;
+ fill_typ fill_b = swap ? fill_this : fill_operand;
+
+ if (rmv_inner.get_value()) {
+ path_b = sp_pathvector_boolop_remove_inner(path_b, fill_b);
+ }
+
+ Geom::PathVector path_out;
+
+ if (op == bool_op_ex_slice) {
+ // For slicing, the bool op is added to the line group which is sliced, not the cut path. This swapped order is correct.
+ path_out = sp_pathvector_boolop(path_b, path_a, to_bool_op(op), fill_b, fill_a);
+ } else if (op == bool_op_ex_slice_inside) {
+ path_out = sp_pathvector_boolop_slice_intersect(path_a, path_b, true, fill_a, fill_b);
+ } else if (op == bool_op_ex_slice_outside) {
+ path_out = sp_pathvector_boolop_slice_intersect(path_a, path_b, false, fill_a, fill_b);
+ } else {
+ path_out = sp_pathvector_boolop(path_a, path_b, to_bool_op(op), fill_a, fill_b);
+ }
+ curve->set_pathvector(path_out);
+ }
}
} // namespace LivePathEffect
diff --git a/src/live_effects/lpe-bool.h b/src/live_effects/lpe-bool.h
index 12c51b4ec..1c0aa0243 100644
--- a/src/live_effects/lpe-bool.h
+++ b/src/live_effects/lpe-bool.h
@@ -24,40 +24,37 @@ public:
LPEBool(LivePathEffectObject *lpeobject);
virtual ~LPEBool();
- void doEffect (SPCurve * curve);
- virtual void resetDefaults(SPItem const * item);
-
- enum bool_op_ex
- {
- bool_op_ex_union = bool_op_union,
- bool_op_ex_inters = bool_op_inters,
- bool_op_ex_diff = bool_op_diff,
- bool_op_ex_symdiff = bool_op_symdiff,
- bool_op_ex_cut = bool_op_cut,
- bool_op_ex_slice = bool_op_slice,
- bool_op_ex_slice_inside, // like bool_op_slice, but leaves only the contour pieces inside of the cut path
- bool_op_ex_slice_outside, // like bool_op_slice, but leaves only the contour pieces outside of the cut path
- bool_op_ex_slice_rmv_inner, // like bool_op_ex_slice, but remove inner contours
- bool_op_ex_slice_inside_rmv_inner, // like bool_op_ex_slice_inside, but remove inner contours
- bool_op_ex_slice_outside_rmv_inner, // like bool_op_ex_slice_outside, but remove inner contours
- bool_op_ex_count
+ void doEffect(SPCurve *curve);
+ virtual void resetDefaults(SPItem const *item);
+
+ enum bool_op_ex {
+ bool_op_ex_union = bool_op_union,
+ bool_op_ex_inters = bool_op_inters,
+ bool_op_ex_diff = bool_op_diff,
+ bool_op_ex_symdiff = bool_op_symdiff,
+ bool_op_ex_cut = bool_op_cut,
+ bool_op_ex_slice = bool_op_slice,
+ bool_op_ex_slice_inside, // like bool_op_slice, but leaves only the contour pieces inside of the cut path
+ bool_op_ex_slice_outside, // like bool_op_slice, but leaves only the contour pieces outside of the cut path
+ bool_op_ex_count
};
- inline friend bool_op to_bool_op( bool_op_ex val )
+ inline friend bool_op to_bool_op(bool_op_ex val)
{
- assert( val<=bool_op_ex_slice );
- (bool_op) val;
+ assert(val <= bool_op_ex_slice);
+ (bool_op) val;
}
private:
- LPEBool(const LPEBool&);
- LPEBool& operator=(const LPEBool&);
+ LPEBool(const LPEBool &);
+ LPEBool &operator=(const LPEBool &);
OriginalPathParam operand_path;
EnumParam<bool_op_ex> bool_operation;
EnumParam<fill_typ> fill_type_this;
EnumParam<fill_typ> fill_type_operand;
BoolParam swap_operands;
+ BoolParam rmv_inner;
};
}; //namespace LivePathEffect
diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp
index c13cffb6a..9f3070ff4 100644
--- a/src/live_effects/lpe-mirror_symmetry.cpp
+++ b/src/live_effects/lpe-mirror_symmetry.cpp
@@ -6,36 +6,84 @@
* Maximilian Albert
* Johan Engelen
* Abhishek Sharma
+ * Jabiertxof
*
* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
* Copyright (C) Maximilin Albert 2008 <maximilian.albert@gmail.com>
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-
+#include <gtkmm.h>
#include <glibmm/i18n.h>
#include "live_effects/lpe-mirror_symmetry.h"
#include <sp-path.h>
#include <display/curve.h>
#include <svg/path-string.h>
-
+#include "helper/geom.h"
#include <2geom/path.h>
+#include <2geom/path-intersection.h>
#include <2geom/transforms.h>
#include <2geom/affine.h>
+#include "knot-holder-entity.h"
+#include "knotholder.h"
+#include "inkscape.h"
namespace Inkscape {
namespace LivePathEffect {
+static const Util::EnumData<ModeType> ModeTypeData[MT_END] = {
+ { MT_V, N_("Vertical Page Center"), "Vertical Page Center, use select tool to move item instead line" },
+ { MT_H, N_("Horizontal Page Center"), "Horizontal Page Center, use select tool to move item instead line" },
+ { MT_FREE, N_("Free from reflection line"), "Free from path" },
+ { MT_X, N_("X from middle knot"), "X from middle knot" },
+ { MT_Y, N_("Y from middle knot"), "Y from middle knot" }
+};
+static const Util::EnumDataConverter<ModeType>
+MTConverter(ModeTypeData, MT_END);
+
+namespace MS {
+
+class KnotHolderEntityCenterMirrorSymmetry : public LPEKnotHolderEntity {
+public:
+ KnotHolderEntityCenterMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect){};
+ virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
+ virtual Geom::Point knot_get() const;
+};
+
+class KnotHolderEntityStartMirrorSymmetry : public LPEKnotHolderEntity {
+public:
+ KnotHolderEntityStartMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect){};
+ virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
+ virtual Geom::Point knot_get() const;
+};
+
+class KnotHolderEntityEndMirrorSymmetry : public LPEKnotHolderEntity {
+public:
+ KnotHolderEntityEndMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect){};
+ virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
+ virtual Geom::Point knot_get() const;
+};
+
+} // namespace MS
+
LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) :
Effect(lpeobject),
+ mode(_("Mode"), _("Symmetry move mode"), "mode", MTConverter, &wr, this, MT_FREE),
discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false),
- reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L100,100")
+ fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false),
+ oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false),
+ start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, "Adjust the start of mirroring"),
+ end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, "Adjust end of mirroring")
{
show_orig_path = true;
+ registerParameter(&mode);
+ registerParameter( &discard_orig_path);
+ registerParameter( &fuse_paths);
+ registerParameter( &oposite_fuse);
+ registerParameter( &start_point);
+ registerParameter( &end_point);
apply_to_clippath_and_mask = true;
- registerParameter( dynamic_cast<Parameter *>(&discard_orig_path) );
- registerParameter( dynamic_cast<Parameter *>(&reflection_line) );
}
LPEMirrorSymmetry::~LPEMirrorSymmetry()
@@ -43,60 +91,276 @@ LPEMirrorSymmetry::~LPEMirrorSymmetry()
}
void
+
+LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem)
+{
+ using namespace Geom;
+
+ Point point_a(boundingbox_X.max(), boundingbox_Y.min());
+ Point point_b(boundingbox_X.max(), boundingbox_Y.max());
+ Point point_c(boundingbox_X.max(), boundingbox_Y.middle());
+ if (mode == MT_Y) {
+ point_a = Geom::Point(boundingbox_X.min(),center_point[Y]);
+ point_b = Geom::Point(boundingbox_X.max(),center_point[Y]);
+ }
+ if (mode == MT_X) {
+ point_a = Geom::Point(center_point[X],boundingbox_Y.min());
+ point_b = Geom::Point(center_point[X],boundingbox_Y.max());
+ }
+ line_separation.setPoints(point_a, point_b);
+ if ( mode == MT_X || mode == MT_Y ) {
+ start_point.param_setValue(point_a);
+ end_point.param_setValue(point_b);
+ center_point = Geom::middle_point(point_a, point_b);
+ } else if ( mode == MT_FREE) {
+ if(!are_near(previous_center,center_point, 0.01)) {
+ Geom::Point trans = center_point - previous_center;
+ start_point.param_setValue(start_point * trans);
+ end_point.param_setValue(end_point * trans);
+ line_separation.setPoints(start_point, end_point);
+ } else {
+ center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point);
+ line_separation.setPoints(start_point, end_point);
+ }
+ } else if ( mode == MT_V){
+ if(SP_ACTIVE_DESKTOP){
+ SPDocument * doc = SP_ACTIVE_DESKTOP->getDocument();
+ Geom::Rect view_box_rect = doc->getViewBox();
+ Geom::Point sp = Geom::Point(view_box_rect.width()/2.0, 0);
+ sp *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse();
+ start_point.param_setValue(sp);
+ Geom::Point ep = Geom::Point(view_box_rect.width()/2.0, view_box_rect.height());
+ ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse();
+ end_point.param_setValue(ep);
+ center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point);
+ line_separation.setPoints(start_point, end_point);
+ }
+ } else { //horizontal page
+ if(SP_ACTIVE_DESKTOP){
+ SPDocument * doc = SP_ACTIVE_DESKTOP->getDocument();
+ Geom::Rect view_box_rect = doc->getViewBox();
+ Geom::Point sp = Geom::Point(0, view_box_rect.height()/2.0);
+ sp *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse();
+ start_point.param_setValue(sp);
+ Geom::Point ep = Geom::Point(view_box_rect.width(), view_box_rect.height()/2.0);
+ ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse();
+ end_point.param_setValue(ep);
+ center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point);
+ line_separation.setPoints(start_point, end_point);
+ }
+ }
+ previous_center = center_point;
+}
+
+void
LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem)
{
using namespace Geom;
- // fixme: what happens if the bbox is empty?
- // fixme: this is probably wrong
- Geom::Affine t = lpeitem->i2dt_affine();
- Geom::Rect bbox = *lpeitem->desktopVisualBounds();
-
- Point A(bbox.left(), bbox.bottom());
- Point B(bbox.left(), bbox.top());
- A *= t;
- B *= t;
- Piecewise<D2<SBasis> > rline = Piecewise<D2<SBasis> >(D2<SBasis>(SBasis(A[X], B[X]), SBasis(A[Y], B[Y])));
- reflection_line.set_new_value(rline, true);
+ original_bbox(lpeitem);
+
+ Point point_a(boundingbox_X.max(), boundingbox_Y.min());
+ Point point_b(boundingbox_X.max(), boundingbox_Y.max());
+ Point point_c(boundingbox_X.max(), boundingbox_Y.middle());
+ start_point.param_setValue(point_a);
+ start_point.param_update_default(point_a);
+ end_point.param_setValue(point_b);
+ end_point.param_update_default(point_b);
+ center_point = point_c;
+ previous_center = center_point;
}
+
Geom::PathVector
LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in)
{
- // Don't allow empty path parameter:
- if ( reflection_line.get_pathvector().empty() ) {
- return path_in;
- }
-
+ Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in);
Geom::PathVector path_out;
- if (!discard_orig_path) {
- path_out = path_in;
+
+ if (!discard_orig_path && !fuse_paths) {
+ path_out = pathv_to_linear_and_cubic_beziers(path_in);
}
- Geom::PathVector mline(reflection_line.get_pathvector());
- Geom::Point A(mline.front().initialPoint());
- Geom::Point B(mline.back().finalPoint());
+ Geom::Point point_a(line_separation.initialPoint());
+ Geom::Point point_b(line_separation.finalPoint());
- Geom::Affine m1(1.0, 0.0, 0.0, 1.0, A[0], A[1]);
- double hyp = Geom::distance(A, B);
- double c = (B[0] - A[0]) / hyp; // cos(alpha)
- double s = (B[1] - A[1]) / hyp; // sin(alpha)
+ Geom::Translate m1(point_a[0], point_a[1]);
+ double hyp = Geom::distance(point_a, point_b);
+ double c = (point_b[0] - point_a[0]) / hyp; // cos(alpha)
+ double s = (point_b[1] - point_a[1]) / hyp; // sin(alpha)
Geom::Affine m2(c, -s, s, c, 0.0, 0.0);
- Geom::Affine sca(1.0, 0.0, 0.0, -1.0, 0.0, 0.0);
+ Geom::Scale sca(1.0, -1.0);
Geom::Affine m = m1.inverse() * m2;
m = m * sca;
m = m * m2.inverse();
m = m * m1;
- for (int i = 0; i < static_cast<int>(path_in.size()); ++i) {
- path_out.push_back(path_in[i] * m);
+ if (fuse_paths && !discard_orig_path) {
+ for (Geom::PathVector::const_iterator path_it = original_pathv.begin();
+ path_it != original_pathv.end(); ++path_it)
+ {
+ if (path_it->empty()) {
+ continue;
+ }
+ Geom::PathVector tmp_path;
+ double time_start = 0.0;
+ int position = 0;
+ bool end_open = false;
+ if (path_it->closed()) {
+ const Geom::Curve &closingline = path_it->back_closed();
+ if (!are_near(closingline.initialPoint(), closingline.finalPoint())) {
+ end_open = true;
+ }
+ }
+ Geom::Path original = *path_it;
+ if (end_open && path_it->closed()) {
+ original.close(false);
+ original.appendNew<Geom::LineSegment>( original.initialPoint() );
+ original.close(true);
+ }
+ Geom::Point s = start_point;
+ Geom::Point e = end_point;
+ double dir = line_separation.angle();
+ double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max()));
+ Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max()));
+ double size_divider = Geom::distance(center_point, bbox) + diagonal;
+ s = Geom::Point::polar(dir,size_divider) + center_point;
+ e = Geom::Point::polar(dir + Geom::rad_from_deg(180),size_divider) + center_point;
+ Geom::Path divider = Geom::Path(s);
+ divider.appendNew<Geom::LineSegment>(e);
+ Geom::Crossings cs = crossings(original, divider);
+ std::vector<double> crossed;
+ for(unsigned int i = 0; i < cs.size(); i++) {
+ crossed.push_back(cs[i].ta);
+ }
+ std::sort(crossed.begin(), crossed.end());
+ for (unsigned int i = 0; i < crossed.size(); i++) {
+ double time_end = crossed[i];
+ if (time_start != time_end && time_end - time_start > Geom::EPSILON) {
+ Geom::Path portion = original.portion(time_start, time_end);
+ if (!portion.empty()) {
+ Geom::Point middle = portion.pointAt((double)portion.size()/2.0);
+ position = Geom::sgn(Geom::cross(e - s, middle - s));
+ if (!oposite_fuse) {
+ position *= -1;
+ }
+ if (position == 1) {
+ Geom::Path mirror = portion.reversed() * m;
+ mirror.setInitial(portion.finalPoint());
+ portion.append(mirror);
+ if(i!=0) {
+ portion.setFinal(portion.initialPoint());
+ portion.close();
+ }
+ tmp_path.push_back(portion);
+ }
+ portion.clear();
+ }
+ }
+ time_start = time_end;
+ }
+ position = Geom::sgn(Geom::cross(e - s, original.finalPoint() - s));
+ if (!oposite_fuse) {
+ position *= -1;
+ }
+ if (cs.size()!=0 && position == 1) {
+ if (time_start != original.size() && original.size() - time_start > Geom::EPSILON) {
+ Geom::Path portion = original.portion(time_start, original.size());
+ if (!portion.empty()) {
+ portion = portion.reversed();
+ Geom::Path mirror = portion.reversed() * m;
+ mirror.setInitial(portion.finalPoint());
+ portion.append(mirror);
+ portion = portion.reversed();
+ if (!original.closed()) {
+ tmp_path.push_back(portion);
+ } else {
+ if (cs.size() > 1 && tmp_path.size() > 0 && tmp_path[0].size() > 0 ) {
+ portion.setFinal(tmp_path[0].initialPoint());
+ portion.setInitial(tmp_path[0].finalPoint());
+ tmp_path[0].append(portion);
+ } else {
+ tmp_path.push_back(portion);
+ }
+ tmp_path[0].close();
+ }
+ portion.clear();
+ }
+ }
+ }
+ if (cs.size() == 0 && position == 1) {
+ tmp_path.push_back(original);
+ tmp_path.push_back(original * m);
+ }
+ path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end());
+ tmp_path.clear();
+ }
+ }
+
+ if (!fuse_paths || discard_orig_path) {
+ for (int i = 0; i < static_cast<int>(path_in.size()); ++i) {
+ path_out.push_back(path_in[i] * m);
+ }
}
return path_out;
}
+void
+LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
+{
+ using namespace Geom;
+ hp_vec.clear();
+ Geom::Path path;
+ Geom::Point s = start_point;
+ Geom::Point e = end_point;
+ path.start( s );
+ path.appendNew<Geom::LineSegment>( e );
+ Geom::PathVector helper;
+ helper.push_back(path);
+ hp_vec.push_back(helper);
+}
+
+void
+LPEMirrorSymmetry::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item)
+{
+ SPKnotShapeType knot_shape = SP_KNOT_SHAPE_CIRCLE;
+ SPKnotModeType knot_mode = SP_KNOT_MODE_XOR;
+ guint32 knot_color = 0x0000ff00;
+ {
+ KnotHolderEntity *c = new MS::KnotHolderEntityCenterMirrorSymmetry(this);
+ c->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN,
+ _("Adjust the center"), knot_shape, knot_mode, knot_color );
+ knotholder->add(c);
+ }
+};
+
+namespace MS {
+
+using namespace Geom;
+
+void
+KnotHolderEntityCenterMirrorSymmetry::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state)
+{
+ LPEMirrorSymmetry* lpe = dynamic_cast<LPEMirrorSymmetry *>(_effect);
+ Geom::Point const s = snap_knot_position(p, state);
+ lpe->center_point = s;
+
+ // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating.
+ sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
+}
+
+Geom::Point
+KnotHolderEntityCenterMirrorSymmetry::knot_get() const
+{
+ LPEMirrorSymmetry const *lpe = dynamic_cast<LPEMirrorSymmetry const*>(_effect);
+ return lpe->center_point;
+}
+
+} // namespace CR
+
} //namespace LivePathEffect
} /* namespace Inkscape */
diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h
index 64a72d7b3..3a244cb7e 100644
--- a/src/live_effects/lpe-mirror_symmetry.h
+++ b/src/live_effects/lpe-mirror_symmetry.h
@@ -8,6 +8,7 @@
* Authors:
* Maximilian Albert
* Johan Engelen
+ * Jabiertxof
*
* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
* Copyright (C) Maximilin Albert 2008 <maximilian.albert@gmail.com>
@@ -19,22 +20,50 @@
#include "live_effects/parameter/parameter.h"
#include "live_effects/parameter/point.h"
#include "live_effects/parameter/path.h"
+#include "live_effects/parameter/enum.h"
+#include "live_effects/lpegroupbbox.h"
namespace Inkscape {
namespace LivePathEffect {
-class LPEMirrorSymmetry : public Effect {
+namespace MS {
+// we need a separate namespace to avoid clashes with LPEPerpBisector
+class KnotHolderEntityCenterMirrorSymmetry;
+}
+
+enum ModeType {
+ MT_V,
+ MT_H,
+ MT_FREE,
+ MT_X,
+ MT_Y,
+ MT_END
+};
+
+class LPEMirrorSymmetry : public Effect, GroupBBoxEffect {
public:
LPEMirrorSymmetry(LivePathEffectObject *lpeobject);
virtual ~LPEMirrorSymmetry();
-
virtual void doOnApply (SPLPEItem const* lpeitem);
-
+ virtual void doBeforeEffect (SPLPEItem const* lpeitem);
virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in);
+ /* the knotholder entity classes must be declared friends */
+ friend class MS::KnotHolderEntityCenterMirrorSymmetry;
+ void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
+
+protected:
+ virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector<Geom::PathVector> &hp_vec);
private:
+ EnumParam<ModeType> mode;
BoolParam discard_orig_path;
- PathParam reflection_line;
+ BoolParam fuse_paths;
+ BoolParam oposite_fuse;
+ PointParam start_point;
+ PointParam end_point;
+ Geom::Line line_separation;
+ Geom::Point previous_center;
+ Geom::Point center_point;
LPEMirrorSymmetry(const LPEMirrorSymmetry&);
LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&);