From 19f8cf337ab1ceed9c654bb48b210fd9b391fcc8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 2 Aug 2015 13:33:58 +0200 Subject: Added point parameter (bzr r14272.1.1) --- src/live_effects/lpe-bendpath.cpp | 43 +++++++++++++++++++++++- src/live_effects/lpe-bendpath.h | 14 ++++++-- src/live_effects/lpe-patternalongpath.cpp | 56 +++++++++++++++++++++++++++++-- src/live_effects/lpe-patternalongpath.h | 12 ++++++- 4 files changed, 118 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index 33171b184..364c77ccb 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -48,17 +48,23 @@ first) but I think we can first forget about them. namespace Inkscape { namespace LivePathEffect { + LPEBendPath::LPEBendPath(LivePathEffectObject *lpeobject) : Effect(lpeobject), bend_path(_("Bend path:"), _("Path along which to bend the original path"), "bendpath", &wr, this, "M0,0 L1,0"), prop_scale(_("_Width:"), _("Width of the path"), "prop_scale", &wr, this, 1), scale_y_rel(_("W_idth in units of length"), _("Scale the width of the path in units of its length"), "scale_y_rel", &wr, this, false), - vertical_pattern(_("_Original path is vertical"), _("Rotates the original 90 degrees, before bending it along the bend path"), "vertical", &wr, this, false) + vertical_pattern(_("_Original path is vertical"), _("Rotates the original 90 degrees, before bending it along the bend path"), "vertical", &wr, this, false), + width(_("Width distance"), _("Change the width of bend path - Ctrl+Alt+Click: reset"), "width", &wr, this), + height(0), + original_height(0), + prop_scale_previous(1) { registerParameter( dynamic_cast(&bend_path) ); registerParameter( dynamic_cast(&prop_scale) ); registerParameter( dynamic_cast(&scale_y_rel) ); registerParameter( dynamic_cast(&vertical_pattern) ); + registerParameter( dynamic_cast(&width) ); prop_scale.param_set_digits(3); prop_scale.param_set_increments(0.01, 0.10); @@ -74,8 +80,38 @@ LPEBendPath::~LPEBendPath() void LPEBendPath::doBeforeEffect (SPLPEItem const* lpeitem) { + hp.clear(); // get the item bounding box original_bbox(lpeitem); + original_height = boundingbox_Y.max() - boundingbox_Y.min(); + bool prop_scale_modified = false; + + Geom::Path path_in = bend_path.get_pathvector().pathAt(Geom::PathVectorTime(0, 0, 0.0)); + Geom::Point ptA = path_in.pointAt(Geom::PathTime(0, 0.0)); + Geom::Point B = path_in.pointAt(Geom::PathTime(1, 0.0)); + Geom::Curve const *first_curve = &path_in.curveAt(Geom::PathTime(0, 0.0)); + Geom::CubicBezier const *cubic = dynamic_cast(&*first_curve); + Geom::Ray ray(ptA, B); + if (cubic) { + ray.setPoints((*cubic)[1], ptA); + } + if(height == 0){ + height = original_height; + width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA); + } + if( prop_scale_previous != prop_scale ){ + prop_scale_modified = true; + } + if(!prop_scale_modified){ + prop_scale.param_set_value(height/original_height); + } + height = Geom::distance(width,ptA) * 2; + width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), ((original_height*prop_scale)/2.0)) + ptA); + width.param_update_default(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA); + prop_scale_previous = prop_scale; + Geom::Path hp_path(width); + hp_path.appendNew(ptA); + hp.push_back(hp_path); SPLPEItem * item = const_cast(lpeitem); item->apply_to_clippath(item); item->apply_to_mask(item); @@ -148,6 +184,11 @@ LPEBendPath::resetDefaults(SPItem const* item) bend_path.set_new_value( path.toPwSb(), true ); } +void +LPEBendPath::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) +{ + hp_vec.push_back(hp); +} } // namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-bendpath.h b/src/live_effects/lpe-bendpath.h index 16b8c6137..6394ce07e 100644 --- a/src/live_effects/lpe-bendpath.h +++ b/src/live_effects/lpe-bendpath.h @@ -14,6 +14,7 @@ #include "live_effects/effect.h" #include "live_effects/parameter/path.h" #include "live_effects/parameter/bool.h" +#include "live_effects/parameter/point.h" #include <2geom/sbasis.h> #include <2geom/sbasis-geometric.h> @@ -27,6 +28,7 @@ namespace Inkscape { namespace LivePathEffect { + //for Bend path on group : we need information concerning the group Bounding box class LPEBendPath : public Effect, GroupBBoxEffect { public: @@ -39,15 +41,21 @@ public: virtual void resetDefaults(SPItem const* item); + void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); private: - PathParam bend_path; - ScalarParam prop_scale; + PathParam bend_path; + ScalarParam prop_scale; BoolParam scale_y_rel; - BoolParam vertical_pattern; + BoolParam vertical_pattern; + PointParam width; + double height; + double original_height; + double prop_scale_previous; Geom::Piecewise > uskeleton; Geom::Piecewise > n; + Geom::PathVector hp; void on_pattern_pasted(); diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index ed65a0d50..5215f94ec 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -75,7 +75,11 @@ LPEPatternAlongPath::LPEPatternAlongPath(LivePathEffectObject *lpeobject) : vertical_pattern(_("Pattern is _vertical"), _("Rotate pattern 90 deg before applying"), "vertical_pattern", &wr, this, false), fuse_tolerance(_("_Fuse nearby ends:"), _("Fuse ends closer than this number. 0 means don't fuse."), - "fuse_tolerance", &wr, this, 0) + "fuse_tolerance", &wr, this, 0), + width(_("Width distance"), _("Change the width of pattern path - Ctrl+Alt+Click: reset"), "width", &wr, this), + height(0), + original_height(0), + prop_scale_previous(1) { registerParameter( dynamic_cast(&pattern) ); registerParameter( dynamic_cast(©type) ); @@ -87,7 +91,7 @@ LPEPatternAlongPath::LPEPatternAlongPath(LivePathEffectObject *lpeobject) : registerParameter( dynamic_cast(&prop_units) ); registerParameter( dynamic_cast(&vertical_pattern) ); registerParameter( dynamic_cast(&fuse_tolerance) ); - + registerParameter( dynamic_cast(&width) ); prop_scale.param_set_digits(3); prop_scale.param_set_increments(0.01, 0.10); } @@ -97,6 +101,48 @@ LPEPatternAlongPath::~LPEPatternAlongPath() } +void +LPEPatternAlongPath::doBeforeEffect (SPLPEItem const* lpeitem) +{ + hp.clear(); + // get the pattern bounding box + Geom::OptRect bbox = pattern.get_pathvector().boundsFast(); + if (bbox) { + original_height = (*bbox)[Geom::Y].max() - (*bbox)[Geom::Y].min(); + bool prop_scale_modified = false; + SPShape const *sp_shape = dynamic_cast(lpeitem); + if (sp_shape) { + Geom::Path const *path_in = sp_shape->getCurveBeforeLPE()->first_path(); + Geom::Point ptA = path_in->pointAt(Geom::PathTime(0, 0.0)); + Geom::Point B = path_in->pointAt(Geom::PathTime(1, 0.0)); + Geom::Curve const *first_curve = &path_in->curveAt(Geom::PathTime(0, 0.0)); + Geom::CubicBezier const *cubic = dynamic_cast(&*first_curve); + Geom::Ray ray(ptA, B); + if (cubic) { + ray.setPoints((*cubic)[1], ptA); + } + if(height == 0){ + height = original_height; + width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA); + prop_scale.param_set_value(1); + } + if( prop_scale_previous != prop_scale ){ + prop_scale_modified = true; + } + height = Geom::distance(width,ptA) * 2; + if(!prop_scale_modified){ + prop_scale.param_set_value(height/original_height); + } + width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), ((original_height*prop_scale)/2.0)) + ptA); + width.param_update_default(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA); + prop_scale_previous = prop_scale; + Geom::Path hp_path(width); + hp_path.appendNew(ptA); + hp.push_back(hp_path); + } + } +} + Geom::Piecewise > LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise > const & pwd2_in) { @@ -238,6 +284,12 @@ LPEPatternAlongPath::transform_multiply(Geom::Affine const& postmul, bool set) } } +void +LPEPatternAlongPath::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) +{ + hp_vec.push_back(hp); +} + } // namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-patternalongpath.h b/src/live_effects/lpe-patternalongpath.h index be2197ddb..440c56548 100644 --- a/src/live_effects/lpe-patternalongpath.h +++ b/src/live_effects/lpe-patternalongpath.h @@ -13,6 +13,7 @@ #include "live_effects/effect.h" #include "live_effects/parameter/path.h" #include "live_effects/parameter/bool.h" +#include "live_effects/parameter/point.h" namespace Inkscape { namespace LivePathEffect { @@ -30,10 +31,15 @@ public: LPEPatternAlongPath(LivePathEffectObject *lpeobject); virtual ~LPEPatternAlongPath(); + virtual void doBeforeEffect (SPLPEItem const* lpeitem); + virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); virtual void transform_multiply(Geom::Affine const& postmul, bool set); + void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); + + PathParam pattern; private: EnumParam copytype; @@ -45,7 +51,11 @@ private: BoolParam prop_units; BoolParam vertical_pattern; ScalarParam fuse_tolerance; - + PointParam width; + double height; + double original_height; + double prop_scale_previous; + Geom::PathVector hp; void on_pattern_pasted(); LPEPatternAlongPath(const LPEPatternAlongPath&); -- cgit v1.2.3 From 7a19998853ca88c2ff03bcf7e0cbb049b693c106 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 5 Aug 2015 22:08:24 +0200 Subject: Fix bug on apply effect from pen/pencil toolbar (bzr r14272.1.2) --- src/live_effects/lpe-bendpath.cpp | 45 ++++++++++++++++++------------- src/live_effects/lpe-bendpath.h | 6 ++--- src/live_effects/lpe-patternalongpath.cpp | 41 ++++++++++++++++------------ src/live_effects/lpe-patternalongpath.h | 4 +-- src/ui/tools/freehand-base.cpp | 44 ++++++++++++------------------ 5 files changed, 72 insertions(+), 68 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index 364c77ccb..4d72af38c 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -52,13 +52,13 @@ namespace LivePathEffect { LPEBendPath::LPEBendPath(LivePathEffectObject *lpeobject) : Effect(lpeobject), bend_path(_("Bend path:"), _("Path along which to bend the original path"), "bendpath", &wr, this, "M0,0 L1,0"), - prop_scale(_("_Width:"), _("Width of the path"), "prop_scale", &wr, this, 1), + prop_scale(_("_Width:"), _("Width of the path"), "prop_scale", &wr, this, 1.0), + width(_("Width distance"), _("Change the width of bend path - Ctrl+Alt+Click: reset"), "width", &wr, this), scale_y_rel(_("W_idth in units of length"), _("Scale the width of the path in units of its length"), "scale_y_rel", &wr, this, false), vertical_pattern(_("_Original path is vertical"), _("Rotates the original 90 degrees, before bending it along the bend path"), "vertical", &wr, this, false), - width(_("Width distance"), _("Change the width of bend path - Ctrl+Alt+Click: reset"), "width", &wr, this), - height(0), - original_height(0), - prop_scale_previous(1) + height(0.0), + original_height(0.0), + prop_scale_from_widget(1.0) { registerParameter( dynamic_cast(&bend_path) ); registerParameter( dynamic_cast(&prop_scale) ); @@ -84,8 +84,6 @@ LPEBendPath::doBeforeEffect (SPLPEItem const* lpeitem) // get the item bounding box original_bbox(lpeitem); original_height = boundingbox_Y.max() - boundingbox_Y.min(); - bool prop_scale_modified = false; - Geom::Path path_in = bend_path.get_pathvector().pathAt(Geom::PathVectorTime(0, 0, 0.0)); Geom::Point ptA = path_in.pointAt(Geom::PathTime(0, 0.0)); Geom::Point B = path_in.pointAt(Geom::PathTime(1, 0.0)); @@ -95,20 +93,29 @@ LPEBendPath::doBeforeEffect (SPLPEItem const* lpeitem) if (cubic) { ray.setPoints((*cubic)[1], ptA); } - if(height == 0){ + //This Hack is to fix a boring bug in the first call to the function, we have + //a wrong "ptA" + if(height == 0.0 && Geom::are_near(width, Geom::Point())){ + height = 0.1; + std::cout << ptA << "ptA0.5\n"; + } else if(height == 0.1 && Geom::are_near(width, Geom::Point())){ + Geom::Point default_point = Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA; + prop_scale.param_set_value(1.0); height = original_height; - width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA); - } - if( prop_scale_previous != prop_scale ){ - prop_scale_modified = true; - } - if(!prop_scale_modified){ - prop_scale.param_set_value(height/original_height); + width.param_setValue(default_point); + width.param_update_default(default_point); + } else { + double distance_knot = Geom::distance(width , ptA); + width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), distance_knot) + ptA); + height = distance_knot * 2; + if(prop_scale_from_widget == prop_scale){ + prop_scale.param_set_value(height/original_height); + } else { + height = original_height * prop_scale; + width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), height/2.0) + ptA); + } } - height = Geom::distance(width,ptA) * 2; - width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), ((original_height*prop_scale)/2.0)) + ptA); - width.param_update_default(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA); - prop_scale_previous = prop_scale; + prop_scale_from_widget = prop_scale; Geom::Path hp_path(width); hp_path.appendNew(ptA); hp.push_back(hp_path); diff --git a/src/live_effects/lpe-bendpath.h b/src/live_effects/lpe-bendpath.h index 6394ce07e..cb9ced570 100644 --- a/src/live_effects/lpe-bendpath.h +++ b/src/live_effects/lpe-bendpath.h @@ -43,15 +43,15 @@ public: void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); -private: PathParam bend_path; +private: ScalarParam prop_scale; + PointParam width; BoolParam scale_y_rel; BoolParam vertical_pattern; - PointParam width; double height; double original_height; - double prop_scale_previous; + double prop_scale_from_widget; Geom::Piecewise > uskeleton; Geom::Piecewise > n; diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 5215f94ec..53730d4d4 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -59,7 +59,8 @@ LPEPatternAlongPath::LPEPatternAlongPath(LivePathEffectObject *lpeobject) : pattern(_("Pattern source:"), _("Path to put along the skeleton path"), "pattern", &wr, this, "M0,0 L1,0"), copytype(_("Pattern copies:"), _("How many pattern copies to place along the skeleton path"), "copytype", PAPCopyTypeConverter, &wr, this, PAPCT_SINGLE_STRETCHED), - prop_scale(_("_Width:"), _("Width of the pattern"), "prop_scale", &wr, this, 1), + prop_scale(_("_Width:"), _("Width of the pattern"), "prop_scale", &wr, this, 1.0), + width(_("Width distance"), _("Change the width of pattern path - Ctrl+Alt+Click: reset"), "width", &wr, this), scale_y_rel(_("Wid_th in units of length"), _("Scale the width of the pattern in units of its length"), "scale_y_rel", &wr, this, false), @@ -76,10 +77,9 @@ LPEPatternAlongPath::LPEPatternAlongPath(LivePathEffectObject *lpeobject) : "vertical_pattern", &wr, this, false), fuse_tolerance(_("_Fuse nearby ends:"), _("Fuse ends closer than this number. 0 means don't fuse."), "fuse_tolerance", &wr, this, 0), - width(_("Width distance"), _("Change the width of pattern path - Ctrl+Alt+Click: reset"), "width", &wr, this), height(0), original_height(0), - prop_scale_previous(1) + prop_scale_from_widget(1) { registerParameter( dynamic_cast(&pattern) ); registerParameter( dynamic_cast(©type) ); @@ -109,7 +109,6 @@ LPEPatternAlongPath::doBeforeEffect (SPLPEItem const* lpeitem) Geom::OptRect bbox = pattern.get_pathvector().boundsFast(); if (bbox) { original_height = (*bbox)[Geom::Y].max() - (*bbox)[Geom::Y].min(); - bool prop_scale_modified = false; SPShape const *sp_shape = dynamic_cast(lpeitem); if (sp_shape) { Geom::Path const *path_in = sp_shape->getCurveBeforeLPE()->first_path(); @@ -121,21 +120,29 @@ LPEPatternAlongPath::doBeforeEffect (SPLPEItem const* lpeitem) if (cubic) { ray.setPoints((*cubic)[1], ptA); } - if(height == 0){ + //This Hack is to fix a boring bug in the first call to the function, we have + //a wrong "ptA" + if(height == 0.0 && Geom::are_near(width, Geom::Point())){ + height = 0.1; + std::cout << ptA << "ptA0.5\n"; + } else if(height == 0.1 && Geom::are_near(width, Geom::Point())){ + Geom::Point default_point = Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA; + prop_scale.param_set_value(1.0); height = original_height; - width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA); - prop_scale.param_set_value(1); - } - if( prop_scale_previous != prop_scale ){ - prop_scale_modified = true; - } - height = Geom::distance(width,ptA) * 2; - if(!prop_scale_modified){ - prop_scale.param_set_value(height/original_height); + width.param_setValue(default_point); + width.param_update_default(default_point); + } else { + double distance_knot = Geom::distance(width , ptA); + width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), distance_knot) + ptA); + height = distance_knot * 2; + if(prop_scale_from_widget == prop_scale){ + prop_scale.param_set_value(height/original_height); + } else { + height = original_height * prop_scale; + width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), height/2.0) + ptA); + } } - width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), ((original_height*prop_scale)/2.0)) + ptA); - width.param_update_default(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA); - prop_scale_previous = prop_scale; + prop_scale_from_widget = prop_scale; Geom::Path hp_path(width); hp_path.appendNew(ptA); hp.push_back(hp_path); diff --git a/src/live_effects/lpe-patternalongpath.h b/src/live_effects/lpe-patternalongpath.h index 440c56548..df0ae9777 100644 --- a/src/live_effects/lpe-patternalongpath.h +++ b/src/live_effects/lpe-patternalongpath.h @@ -44,6 +44,7 @@ public: private: EnumParam copytype; ScalarParam prop_scale; + PointParam width; BoolParam scale_y_rel; ScalarParam spacing; ScalarParam normal_offset; @@ -51,10 +52,9 @@ private: BoolParam prop_units; BoolParam vertical_pattern; ScalarParam fuse_tolerance; - PointParam width; double height; double original_height; - double prop_scale_previous; + double prop_scale_from_widget; Geom::PathVector hp; void on_pattern_pasted(); diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp index bdce1cd46..6adece54f 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -215,7 +215,7 @@ static Glib::ustring const tool_name(FreehandBase *dc) : "/tools/freehand/pencil" ); } -static void spdc_paste_curve_as_freehand_shape(const SPCurve *c, FreehandBase *dc, SPItem *item) +static void spdc_paste_curve_as_freehand_shape(gchar const *svgd, FreehandBase *dc, SPItem *item) { using namespace Inkscape::LivePathEffect; @@ -223,7 +223,6 @@ static void spdc_paste_curve_as_freehand_shape(const SPCurve *c, FreehandBase *d Effect::createAndApply(PATTERN_ALONG_PATH, dc->desktop->doc(), item); Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE(); - gchar *svgd = sp_svg_write_path(c->get_pathvector()); static_cast(lpe)->pattern.paste_param_path(svgd); } @@ -278,10 +277,10 @@ static void spdc_apply_bend_shape(gchar const *svgd, FreehandBase *dc, SPItem *i Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE(); // write bend parameters: - lpe->getRepr()->setAttribute("bendpath", svgd); lpe->getRepr()->setAttribute("prop_scale", "1"); lpe->getRepr()->setAttribute("scale_y_rel", "false"); lpe->getRepr()->setAttribute("vertical", "false"); + static_cast(lpe)->bend_path.paste_param_path(svgd); } static void spdc_apply_simplify(std::string threshold, FreehandBase *dc, SPItem *item) @@ -386,7 +385,8 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, c->curveto(SHAPE_LENGTH, (1 + C1) * SHAPE_HEIGHT/2, (1 + C1) * SHAPE_LENGTH/2, SHAPE_HEIGHT, SHAPE_LENGTH/2, SHAPE_HEIGHT); c->curveto((1 - C1) * SHAPE_LENGTH/2, SHAPE_HEIGHT, 0, (1 + C1) * SHAPE_HEIGHT/2, 0, SHAPE_HEIGHT/2); c->closepath(); - spdc_paste_curve_as_freehand_shape(c, dc, item); + gchar const *svgd = sp_svg_write_path(c->get_pathvector()); + spdc_paste_curve_as_freehand_shape(svgd, dc, item); c->unref(); shape_applied = true; @@ -399,15 +399,7 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, Glib::ustring svgd = cm->getPathParameter(SP_ACTIVE_DESKTOP); if(svgd != ""){ previous_shape_pathv = sp_svg_read_pathv(svgd.data()); - Inkscape::XML::Node *nv_repr = SP_ACTIVE_DESKTOP->getNamedView()->getRepr(); - if (nv_repr->attribute("inkscape:document-units")){ - double scale_units = Inkscape::Util::Quantity::convert(1, "px", nv_repr->attribute("inkscape:document-units")); - if (!Geom::are_near(scale_units, 1.0, Geom::EPSILON)) { - previous_shape_pathv *= Geom::Scale(scale_units); - } - } - SPCurve const *c = new SPCurve(previous_shape_pathv); - spdc_paste_curve_as_freehand_shape(c, dc, item); + spdc_paste_curve_as_freehand_shape(svgd.data(), dc, item); shape_applied = true; } else { shape = NONE; @@ -419,14 +411,11 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); if(cm->paste(SP_ACTIVE_DESKTOP,true) == true){ gchar const *svgd = item->getRepr()->attribute("d"); - Geom::PathVector path = sp_svg_read_pathv(svgd); - path *= item->i2doc_affine().inverse(); - svgd = sp_svg_write_path( path ); bend_item = dc->selection->singleItem(); if(bend_item){ bend_item->moveTo(item,false); + bend_item->transform = Geom::Affine(1,0,0,1,0,0); spdc_apply_bend_shape(svgd, dc, bend_item); - bend_item->transform = Geom::Affine(1,0,0,1,0,0); dc->selection->add(SP_OBJECT(bend_item)); } else { shape = NONE; @@ -440,32 +429,33 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, { if(previous_shape_type == CLIPBOARD){ if(previous_shape_pathv.size() != 0){ - SPCurve * c = new SPCurve(); - c->set_pathvector(previous_shape_pathv); - spdc_paste_curve_as_freehand_shape(c, dc, item); - c->unref(); + gchar const *svgd = sp_svg_write_path(previous_shape_pathv); + spdc_paste_curve_as_freehand_shape(svgd, dc, item); shape_applied = true; + shape = CLIPBOARD; + } else{ + shape = NONE; } - shape = CLIPBOARD; } else { if(bend_item != NULL && bend_item->getRepr() != NULL){ gchar const *svgd = item->getRepr()->attribute("d"); - Geom::PathVector path = sp_svg_read_pathv(svgd); - path *= item->i2doc_affine().inverse(); - svgd = sp_svg_write_path( path ); dc->selection->add(SP_OBJECT(bend_item)); sp_selection_duplicate(dc->desktop); dc->selection->remove(SP_OBJECT(bend_item)); bend_item = dc->selection->singleItem(); if(bend_item){ bend_item->moveTo(item,false); - spdc_apply_bend_shape(svgd, dc, bend_item); bend_item->transform = Geom::Affine(1,0,0,1,0,0); + spdc_apply_bend_shape(svgd, dc, bend_item); dc->selection->add(SP_OBJECT(bend_item)); + shape = BEND_CLIPBOARD; + } else { + shape = NONE; } + } else { + shape = NONE; } - shape = BEND_CLIPBOARD; } break; } -- cgit v1.2.3 From c77df2a9ee1f988a2652528465ba5357a5e72ab2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 6 Aug 2015 02:24:34 +0200 Subject: fix a bug appliening from patheffect list the LPE (bzr r14272.1.5) --- src/live_effects/lpe-bendpath.cpp | 32 ++++++++++++++++++++++---------- src/live_effects/lpe-bendpath.h | 3 ++- 2 files changed, 24 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index 4d72af38c..9b015245d 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -58,7 +58,9 @@ LPEBendPath::LPEBendPath(LivePathEffectObject *lpeobject) : vertical_pattern(_("_Original path is vertical"), _("Rotates the original 90 degrees, before bending it along the bend path"), "vertical", &wr, this, false), height(0.0), original_height(0.0), - prop_scale_from_widget(1.0) + prop_scale_from_widget(1.0), + firstTime(false), + secondTime(false) { registerParameter( dynamic_cast(&bend_path) ); registerParameter( dynamic_cast(&prop_scale) ); @@ -91,28 +93,38 @@ LPEBendPath::doBeforeEffect (SPLPEItem const* lpeitem) Geom::CubicBezier const *cubic = dynamic_cast(&*first_curve); Geom::Ray ray(ptA, B); if (cubic) { - ray.setPoints((*cubic)[1], ptA); + ray.setPoints(ptA,(*cubic)[1]); } + + Geom::Angle first_curve_angle = ray.transformed(Geom::Rotate(Geom::deg_to_rad(90))).angle(); //This Hack is to fix a boring bug in the first call to the function, we have //a wrong "ptA" - if(height == 0.0 && Geom::are_near(width, Geom::Point())){ - height = 0.1; - std::cout << ptA << "ptA0.5\n"; - } else if(height == 0.1 && Geom::are_near(width, Geom::Point())){ - Geom::Point default_point = Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA; + if(!firstTime && Geom::are_near(width, Geom::Point())){ + firstTime = true; + } else if(firstTime && Geom::are_near(width, Geom::Point())){ + Geom::Point default_point = Geom::Point::polar(first_curve_angle, original_height/2.0) + ptA; prop_scale.param_set_value(1.0); height = original_height; width.param_setValue(default_point); width.param_update_default(default_point); } else { double distance_knot = Geom::distance(width , ptA); - width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), distance_knot) + ptA); + width.param_setValue(Geom::Point::polar(first_curve_angle, distance_knot) + ptA); height = distance_knot * 2; - if(prop_scale_from_widget == prop_scale){ + if(secondTime){ + prop_scale.param_set_value(1); + height = original_height; + width.param_setValue(Geom::Point::polar(first_curve_angle, height/2.0) + ptA); + secondTime = false; + } else if(prop_scale_from_widget == prop_scale){ prop_scale.param_set_value(height/original_height); } else { height = original_height * prop_scale; - width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), height/2.0) + ptA); + width.param_setValue(Geom::Point::polar(first_curve_angle, height/2.0) + ptA); + } + if(firstTime){ + firstTime = false; + secondTime = true; } } prop_scale_from_widget = prop_scale; diff --git a/src/live_effects/lpe-bendpath.h b/src/live_effects/lpe-bendpath.h index a59d2322a..5d58f3320 100644 --- a/src/live_effects/lpe-bendpath.h +++ b/src/live_effects/lpe-bendpath.h @@ -53,7 +53,8 @@ private: double height; double original_height; double prop_scale_from_widget; - + bool firstTime; + bool secondTime; Geom::Piecewise > uskeleton; Geom::Piecewise > n; Geom::PathVector hp; -- cgit v1.2.3 From 7ffbb0399458946dfdbbd14438521ab52acf48a6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 7 Aug 2015 23:54:00 +0200 Subject: Full refactor of the LPE now too much simple code (bzr r14272.1.6) --- src/live_effects/lpe-bendpath.cpp | 120 ++++++++++++++++-------------- src/live_effects/lpe-bendpath.h | 18 ++--- src/live_effects/lpe-patternalongpath.cpp | 120 ++++++++++++++++++------------ src/live_effects/lpe-patternalongpath.h | 17 +++-- 4 files changed, 158 insertions(+), 117 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index 9b015245d..d80f8e33a 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -20,7 +20,13 @@ #include <2geom/d2.h> #include <2geom/piecewise.h> +#include "knot-holder-entity.h" +#include "knotholder.h" + +#include + #include + using std::vector; @@ -48,29 +54,33 @@ first) but I think we can first forget about them. namespace Inkscape { namespace LivePathEffect { +Geom::PathVector bp_helper_path; +namespace BeP { +class KnotHolderEntityWidthBendPath : public LPEKnotHolderEntity { + public: + KnotHolderEntityWidthBendPath(LPEBendPath * effect) : LPEKnotHolderEntity(effect) {} + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); + virtual Geom::Point knot_get() const; + }; +} // BeP LPEBendPath::LPEBendPath(LivePathEffectObject *lpeobject) : Effect(lpeobject), bend_path(_("Bend path:"), _("Path along which to bend the original path"), "bendpath", &wr, this, "M0,0 L1,0"), + original_height(0.0), prop_scale(_("_Width:"), _("Width of the path"), "prop_scale", &wr, this, 1.0), - width(_("Width distance"), _("Change the width of bend path - Ctrl+Alt+Click: reset"), "width", &wr, this), scale_y_rel(_("W_idth in units of length"), _("Scale the width of the path in units of its length"), "scale_y_rel", &wr, this, false), - vertical_pattern(_("_Original path is vertical"), _("Rotates the original 90 degrees, before bending it along the bend path"), "vertical", &wr, this, false), - height(0.0), - original_height(0.0), - prop_scale_from_widget(1.0), - firstTime(false), - secondTime(false) + vertical_pattern(_("_Original path is vertical"), _("Rotates the original 90 degrees, before bending it along the bend path"), "vertical", &wr, this, false) { registerParameter( dynamic_cast(&bend_path) ); registerParameter( dynamic_cast(&prop_scale) ); registerParameter( dynamic_cast(&scale_y_rel) ); registerParameter( dynamic_cast(&vertical_pattern) ); - registerParameter( dynamic_cast(&width) ); prop_scale.param_set_digits(3); prop_scale.param_set_increments(0.01, 0.10); + _provides_knotholder_entities = true; concatenate_before_pwd2 = true; } @@ -82,56 +92,11 @@ LPEBendPath::~LPEBendPath() void LPEBendPath::doBeforeEffect (SPLPEItem const* lpeitem) { - hp.clear(); // get the item bounding box original_bbox(lpeitem); original_height = boundingbox_Y.max() - boundingbox_Y.min(); - Geom::Path path_in = bend_path.get_pathvector().pathAt(Geom::PathVectorTime(0, 0, 0.0)); - Geom::Point ptA = path_in.pointAt(Geom::PathTime(0, 0.0)); - Geom::Point B = path_in.pointAt(Geom::PathTime(1, 0.0)); - Geom::Curve const *first_curve = &path_in.curveAt(Geom::PathTime(0, 0.0)); - Geom::CubicBezier const *cubic = dynamic_cast(&*first_curve); - Geom::Ray ray(ptA, B); - if (cubic) { - ray.setPoints(ptA,(*cubic)[1]); - } - - Geom::Angle first_curve_angle = ray.transformed(Geom::Rotate(Geom::deg_to_rad(90))).angle(); - //This Hack is to fix a boring bug in the first call to the function, we have - //a wrong "ptA" - if(!firstTime && Geom::are_near(width, Geom::Point())){ - firstTime = true; - } else if(firstTime && Geom::are_near(width, Geom::Point())){ - Geom::Point default_point = Geom::Point::polar(first_curve_angle, original_height/2.0) + ptA; - prop_scale.param_set_value(1.0); - height = original_height; - width.param_setValue(default_point); - width.param_update_default(default_point); - } else { - double distance_knot = Geom::distance(width , ptA); - width.param_setValue(Geom::Point::polar(first_curve_angle, distance_knot) + ptA); - height = distance_knot * 2; - if(secondTime){ - prop_scale.param_set_value(1); - height = original_height; - width.param_setValue(Geom::Point::polar(first_curve_angle, height/2.0) + ptA); - secondTime = false; - } else if(prop_scale_from_widget == prop_scale){ - prop_scale.param_set_value(height/original_height); - } else { - height = original_height * prop_scale; - width.param_setValue(Geom::Point::polar(first_curve_angle, height/2.0) + ptA); - } - if(firstTime){ - firstTime = false; - secondTime = true; - } - } - prop_scale_from_widget = prop_scale; - Geom::Path hp_path(width); - hp_path.appendNew(ptA); - hp.push_back(hp_path); SPLPEItem * item = const_cast(lpeitem); + item->apply_to_clippath(item); item->apply_to_mask(item); } @@ -206,9 +171,54 @@ LPEBendPath::resetDefaults(SPItem const* item) void LPEBendPath::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) { - hp_vec.push_back(hp); + hp_vec.push_back(bp_helper_path); } +void +LPEBendPath::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +{ + KnotHolderEntity *e = new BeP::KnotHolderEntityWidthBendPath(this); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Change the width"), SP_KNOT_SHAPE_CIRCLE); + knotholder->add(e); +} + +namespace BeP { + +void +KnotHolderEntityWidthBendPath::knot_set(Geom::Point const &p, Geom::Point const& /*origin*/, guint state) +{ + LPEBendPath *lpe = dynamic_cast (_effect); + + Geom::Point const s = snap_knot_position(p, state); + Geom::Path path_in = lpe->bend_path.get_pathvector().pathAt(Geom::PathVectorTime(0, 0, 0.0)); + Geom::Point ptA = path_in.pointAt(Geom::PathTime(0, 0.0)); + lpe->prop_scale.param_set_value(Geom::distance(s , ptA)/(lpe->original_height/2.0)); + sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); +} + +Geom::Point +KnotHolderEntityWidthBendPath::knot_get() const +{ + LPEBendPath *lpe = dynamic_cast (_effect); + + bp_helper_path.clear(); + Geom::Path path_in = lpe->bend_path.get_pathvector().pathAt(Geom::PathVectorTime(0, 0, 0.0)); + Geom::Point ptA = path_in.pointAt(Geom::PathTime(0, 0.0)); + Geom::Point B = path_in.pointAt(Geom::PathTime(1, 0.0)); + Geom::Curve const *first_curve = &path_in.curveAt(Geom::PathTime(0, 0.0)); + Geom::CubicBezier const *cubic = dynamic_cast(&*first_curve); + Geom::Ray ray(ptA, B); + if (cubic) { + ray.setPoints(ptA,(*cubic)[1]); + } + Geom::Angle first_curve_angle = ray.transformed(Geom::Rotate(Geom::deg_to_rad(90))).angle(); + Geom::Point result_point = Geom::Point::polar(first_curve_angle, (lpe->original_height * lpe->prop_scale)/2.0) + ptA; + Geom::Path hp_path(result_point); + hp_path.appendNew(ptA); + bp_helper_path.push_back(hp_path); + return result_point; +} +} // namespace BeP } // namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-bendpath.h b/src/live_effects/lpe-bendpath.h index 5d58f3320..eeda86a5e 100644 --- a/src/live_effects/lpe-bendpath.h +++ b/src/live_effects/lpe-bendpath.h @@ -14,7 +14,6 @@ #include "live_effects/effect.h" #include "live_effects/parameter/path.h" #include "live_effects/parameter/bool.h" -#include "live_effects/parameter/point.h" #include <2geom/sbasis.h> #include <2geom/sbasis-geometric.h> @@ -28,6 +27,9 @@ namespace Inkscape { namespace LivePathEffect { +namespace BeP { +class KnotHolderEntityWidthBendPath; +} //for Bend path on group : we need information concerning the group Bounding box class LPEBendPath : public Effect, GroupBBoxEffect { @@ -43,21 +45,19 @@ public: void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); + virtual void addKnotHolderEntities(KnotHolder * knotholder, SPDesktop * desktop, SPItem * item); + PathParam bend_path; -private: + friend class BeP::KnotHolderEntityWidthBendPath; +protected: + double original_height; ScalarParam prop_scale; - PointParam width; +private: BoolParam scale_y_rel; BoolParam vertical_pattern; - double height; - double original_height; - double prop_scale_from_widget; - bool firstTime; - bool secondTime; Geom::Piecewise > uskeleton; Geom::Piecewise > n; - Geom::PathVector hp; void on_pattern_pasted(); diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 53730d4d4..72e1892ef 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -18,6 +18,9 @@ #include <2geom/d2.h> #include <2geom/piecewise.h> +#include "knot-holder-entity.h" +#include "knotholder.h" + #include using std::vector; @@ -45,6 +48,16 @@ first) but I think we can first forget about them. namespace Inkscape { namespace LivePathEffect { +Geom::PathVector pap_helper_path; + +namespace WPAP { + class KnotHolderEntityWidthPatternAlongPath : public LPEKnotHolderEntity { + public: + KnotHolderEntityWidthPatternAlongPath(LPEPatternAlongPath * effect) : LPEKnotHolderEntity(effect) {} + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); + virtual Geom::Point knot_get() const; + }; +} // WPAP static const Util::EnumData PAPCopyTypeData[PAPCT_END] = { {PAPCT_SINGLE, N_("Single"), "single"}, @@ -57,10 +70,10 @@ static const Util::EnumDataConverter PAPCopyTypeConverter(PAPCopyTy LPEPatternAlongPath::LPEPatternAlongPath(LivePathEffectObject *lpeobject) : Effect(lpeobject), pattern(_("Pattern source:"), _("Path to put along the skeleton path"), "pattern", &wr, this, "M0,0 L1,0"), + original_height(0), + prop_scale(_("_Width:"), _("Width of the pattern"), "prop_scale", &wr, this, 1.0), copytype(_("Pattern copies:"), _("How many pattern copies to place along the skeleton path"), "copytype", PAPCopyTypeConverter, &wr, this, PAPCT_SINGLE_STRETCHED), - prop_scale(_("_Width:"), _("Width of the pattern"), "prop_scale", &wr, this, 1.0), - width(_("Width distance"), _("Change the width of pattern path - Ctrl+Alt+Click: reset"), "width", &wr, this), scale_y_rel(_("Wid_th in units of length"), _("Scale the width of the pattern in units of its length"), "scale_y_rel", &wr, this, false), @@ -76,10 +89,7 @@ LPEPatternAlongPath::LPEPatternAlongPath(LivePathEffectObject *lpeobject) : vertical_pattern(_("Pattern is _vertical"), _("Rotate pattern 90 deg before applying"), "vertical_pattern", &wr, this, false), fuse_tolerance(_("_Fuse nearby ends:"), _("Fuse ends closer than this number. 0 means don't fuse."), - "fuse_tolerance", &wr, this, 0), - height(0), - original_height(0), - prop_scale_from_widget(1) + "fuse_tolerance", &wr, this, 0) { registerParameter( dynamic_cast(&pattern) ); registerParameter( dynamic_cast(©type) ); @@ -91,9 +101,11 @@ LPEPatternAlongPath::LPEPatternAlongPath(LivePathEffectObject *lpeobject) : registerParameter( dynamic_cast(&prop_units) ); registerParameter( dynamic_cast(&vertical_pattern) ); registerParameter( dynamic_cast(&fuse_tolerance) ); - registerParameter( dynamic_cast(&width) ); prop_scale.param_set_digits(3); prop_scale.param_set_increments(0.01, 0.10); + + _provides_knotholder_entities = true; + } LPEPatternAlongPath::~LPEPatternAlongPath() @@ -104,49 +116,10 @@ LPEPatternAlongPath::~LPEPatternAlongPath() void LPEPatternAlongPath::doBeforeEffect (SPLPEItem const* lpeitem) { - hp.clear(); // get the pattern bounding box Geom::OptRect bbox = pattern.get_pathvector().boundsFast(); if (bbox) { original_height = (*bbox)[Geom::Y].max() - (*bbox)[Geom::Y].min(); - SPShape const *sp_shape = dynamic_cast(lpeitem); - if (sp_shape) { - Geom::Path const *path_in = sp_shape->getCurveBeforeLPE()->first_path(); - Geom::Point ptA = path_in->pointAt(Geom::PathTime(0, 0.0)); - Geom::Point B = path_in->pointAt(Geom::PathTime(1, 0.0)); - Geom::Curve const *first_curve = &path_in->curveAt(Geom::PathTime(0, 0.0)); - Geom::CubicBezier const *cubic = dynamic_cast(&*first_curve); - Geom::Ray ray(ptA, B); - if (cubic) { - ray.setPoints((*cubic)[1], ptA); - } - //This Hack is to fix a boring bug in the first call to the function, we have - //a wrong "ptA" - if(height == 0.0 && Geom::are_near(width, Geom::Point())){ - height = 0.1; - std::cout << ptA << "ptA0.5\n"; - } else if(height == 0.1 && Geom::are_near(width, Geom::Point())){ - Geom::Point default_point = Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA; - prop_scale.param_set_value(1.0); - height = original_height; - width.param_setValue(default_point); - width.param_update_default(default_point); - } else { - double distance_knot = Geom::distance(width , ptA); - width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), distance_knot) + ptA); - height = distance_knot * 2; - if(prop_scale_from_widget == prop_scale){ - prop_scale.param_set_value(height/original_height); - } else { - height = original_height * prop_scale; - width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), height/2.0) + ptA); - } - } - prop_scale_from_widget = prop_scale; - Geom::Path hp_path(width); - hp_path.appendNew(ptA); - hp.push_back(hp_path); - } } } @@ -294,9 +267,62 @@ LPEPatternAlongPath::transform_multiply(Geom::Affine const& postmul, bool set) void LPEPatternAlongPath::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) { - hp_vec.push_back(hp); + hp_vec.push_back(pap_helper_path); } + +void +LPEPatternAlongPath::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +{ + KnotHolderEntity *e = new WPAP::KnotHolderEntityWidthPatternAlongPath(this); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Change the width"), SP_KNOT_SHAPE_CIRCLE); + knotholder->add(e); +} + +namespace WPAP { + +void +KnotHolderEntityWidthPatternAlongPath::knot_set(Geom::Point const &p, Geom::Point const& /*origin*/, guint state) +{ + LPEPatternAlongPath *lpe = dynamic_cast (_effect); + + Geom::Point const s = snap_knot_position(p, state); + SPShape const *sp_shape = dynamic_cast(SP_LPE_ITEM(item)); + if (sp_shape) { + Geom::Path const *path_in = sp_shape->getCurveBeforeLPE()->first_path(); + Geom::Point ptA = path_in->pointAt(Geom::PathTime(0, 0.0)); + lpe->prop_scale.param_set_value(Geom::distance(s , ptA)/(lpe->original_height/2.0)); + } + sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); +} + +Geom::Point +KnotHolderEntityWidthPatternAlongPath::knot_get() const +{ + LPEPatternAlongPath *lpe = dynamic_cast (_effect); + + SPShape const *sp_shape = dynamic_cast(SP_LPE_ITEM(item)); + if (sp_shape) { + pap_helper_path.clear(); + Geom::Path const *path_in = sp_shape->getCurveBeforeLPE()->first_path(); + Geom::Point ptA = path_in->pointAt(Geom::PathTime(0, 0.0)); + Geom::Point B = path_in->pointAt(Geom::PathTime(1, 0.0)); + Geom::Curve const *first_curve = &path_in->curveAt(Geom::PathTime(0, 0.0)); + Geom::CubicBezier const *cubic = dynamic_cast(&*first_curve); + Geom::Ray ray(ptA, B); + if (cubic) { + ray.setPoints((*cubic)[1], ptA); + } + Geom::Angle first_curve_angle = ray.transformed(Geom::Rotate(Geom::deg_to_rad(90))).angle(); + Geom::Point result_point = Geom::Point::polar(first_curve_angle, (lpe->original_height * lpe->prop_scale)/2.0) + ptA; + Geom::Path hp_path(result_point); + hp_path.appendNew(ptA); + pap_helper_path.push_back(hp_path); + return result_point; + } + return Geom::Point(); +} +} // namespace WPAP } // namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-patternalongpath.h b/src/live_effects/lpe-patternalongpath.h index df0ae9777..3b9a17ab0 100644 --- a/src/live_effects/lpe-patternalongpath.h +++ b/src/live_effects/lpe-patternalongpath.h @@ -18,6 +18,10 @@ namespace Inkscape { namespace LivePathEffect { +namespace WPAP { +class KnotHolderEntityWidthPatternAlongPath; +} + enum PAPCopyType { PAPCT_SINGLE = 0, PAPCT_SINGLE_STRETCHED, @@ -39,12 +43,17 @@ public: void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); + virtual void addKnotHolderEntities(KnotHolder * knotholder, SPDesktop * desktop, SPItem * item); PathParam pattern; + + friend class WPAP::KnotHolderEntityWidthPatternAlongPath; +protected: + double original_height; + ScalarParam prop_scale; + private: EnumParam copytype; - ScalarParam prop_scale; - PointParam width; BoolParam scale_y_rel; ScalarParam spacing; ScalarParam normal_offset; @@ -52,10 +61,6 @@ private: BoolParam prop_units; BoolParam vertical_pattern; ScalarParam fuse_tolerance; - double height; - double original_height; - double prop_scale_from_widget; - Geom::PathVector hp; void on_pattern_pasted(); LPEPatternAlongPath(const LPEPatternAlongPath&); -- cgit v1.2.3 From ec559a5dfe4b9ab24a9e8a0799fa490b70c1f0a4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 8 Aug 2015 12:28:31 +0200 Subject: minor changes (bzr r14272.1.10) --- src/live_effects/lpe-bendpath.cpp | 12 ++++++++---- src/live_effects/lpe-patternalongpath.cpp | 13 ++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index d80f8e33a..5c20a7f9e 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -193,6 +193,7 @@ KnotHolderEntityWidthBendPath::knot_set(Geom::Point const &p, Geom::Point const& Geom::Path path_in = lpe->bend_path.get_pathvector().pathAt(Geom::PathVectorTime(0, 0, 0.0)); Geom::Point ptA = path_in.pointAt(Geom::PathTime(0, 0.0)); lpe->prop_scale.param_set_value(Geom::distance(s , ptA)/(lpe->original_height/2.0)); + sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); } @@ -201,7 +202,6 @@ KnotHolderEntityWidthBendPath::knot_get() const { LPEBendPath *lpe = dynamic_cast (_effect); - bp_helper_path.clear(); Geom::Path path_in = lpe->bend_path.get_pathvector().pathAt(Geom::PathVectorTime(0, 0, 0.0)); Geom::Point ptA = path_in.pointAt(Geom::PathTime(0, 0.0)); Geom::Point B = path_in.pointAt(Geom::PathTime(1, 0.0)); @@ -213,9 +213,13 @@ KnotHolderEntityWidthBendPath::knot_get() const } Geom::Angle first_curve_angle = ray.transformed(Geom::Rotate(Geom::deg_to_rad(90))).angle(); Geom::Point result_point = Geom::Point::polar(first_curve_angle, (lpe->original_height * lpe->prop_scale)/2.0) + ptA; - Geom::Path hp_path(result_point); - hp_path.appendNew(ptA); - bp_helper_path.push_back(hp_path); + + bp_helper_path.clear(); + Geom::Path hp(result_point); + hp.appendNew(ptA); + bp_helper_path.push_back(hp); + hp.clear(); + return result_point; } } // namespace BeP diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 72e1892ef..ed377e7f9 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -285,7 +285,7 @@ void KnotHolderEntityWidthPatternAlongPath::knot_set(Geom::Point const &p, Geom::Point const& /*origin*/, guint state) { LPEPatternAlongPath *lpe = dynamic_cast (_effect); - + Geom::Point const s = snap_knot_position(p, state); SPShape const *sp_shape = dynamic_cast(SP_LPE_ITEM(item)); if (sp_shape) { @@ -303,7 +303,6 @@ KnotHolderEntityWidthPatternAlongPath::knot_get() const SPShape const *sp_shape = dynamic_cast(SP_LPE_ITEM(item)); if (sp_shape) { - pap_helper_path.clear(); Geom::Path const *path_in = sp_shape->getCurveBeforeLPE()->first_path(); Geom::Point ptA = path_in->pointAt(Geom::PathTime(0, 0.0)); Geom::Point B = path_in->pointAt(Geom::PathTime(1, 0.0)); @@ -315,9 +314,13 @@ KnotHolderEntityWidthPatternAlongPath::knot_get() const } Geom::Angle first_curve_angle = ray.transformed(Geom::Rotate(Geom::deg_to_rad(90))).angle(); Geom::Point result_point = Geom::Point::polar(first_curve_angle, (lpe->original_height * lpe->prop_scale)/2.0) + ptA; - Geom::Path hp_path(result_point); - hp_path.appendNew(ptA); - pap_helper_path.push_back(hp_path); + + pap_helper_path.clear(); + Geom::Path hp(result_point); + hp.appendNew(ptA); + pap_helper_path.push_back(hp); + hp.clear(); + return result_point; } return Geom::Point(); -- cgit v1.2.3 From 98a465905236cf97e2b3d163ff3df4ee43635038 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 8 Dec 2015 13:56:49 +0100 Subject: Fix incorrect variable type in SPILength constructor. (bzr r14513) --- src/style-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/style-internal.h b/src/style-internal.h index 889292454..33096f257 100644 --- a/src/style-internal.h +++ b/src/style-internal.h @@ -342,7 +342,7 @@ public: computed(0) {} - SPILength( Glib::ustring const &name, unsigned value = 0 ) + SPILength( Glib::ustring const &name, float value = 0 ) : SPIBase( name ), unit(SP_CSS_UNIT_NONE), value(value), -- cgit v1.2.3 From f16ffd203a902204895281423322625d86be6144 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 8 Dec 2015 14:09:52 +0100 Subject: Fix incorrect variable type in SPILengthOrNormal constructor. (bzr r14514) --- src/style-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/style-internal.h b/src/style-internal.h index 33096f257..767552784 100644 --- a/src/style-internal.h +++ b/src/style-internal.h @@ -401,7 +401,7 @@ public: normal(true) {} - SPILengthOrNormal( Glib::ustring const &name, unsigned value = 0 ) + SPILengthOrNormal( Glib::ustring const &name, float value = 0 ) : SPILength( name, value ), normal(true) {} -- cgit v1.2.3 From 5ffdf79a6ed7d33ca03d7da3d78cf75389486477 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 8 Dec 2015 14:18:15 +0100 Subject: add negative values to bend and pattern along path whith knot (bzr r14516) --- src/live_effects/lpe-bendpath.cpp | 20 +++++++++++++++++--- src/live_effects/lpe-patternalongpath.cpp | 23 +++++++++++++++++++---- 2 files changed, 36 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index 5c20a7f9e..874e23c4c 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -192,7 +192,21 @@ KnotHolderEntityWidthBendPath::knot_set(Geom::Point const &p, Geom::Point const& Geom::Point const s = snap_knot_position(p, state); Geom::Path path_in = lpe->bend_path.get_pathvector().pathAt(Geom::PathVectorTime(0, 0, 0.0)); Geom::Point ptA = path_in.pointAt(Geom::PathTime(0, 0.0)); - lpe->prop_scale.param_set_value(Geom::distance(s , ptA)/(lpe->original_height/2.0)); + Geom::Point B = path_in.pointAt(Geom::PathTime(1, 0.0)); + Geom::Curve const *first_curve = &path_in.curveAt(Geom::PathTime(0, 0.0)); + Geom::CubicBezier const *cubic = dynamic_cast(&*first_curve); + Geom::Ray ray(ptA, B); + if (cubic) { + ray.setPoints(ptA, (*cubic)[1]); + } + ray.setAngle(ray.angle() + Geom::deg_to_rad(90)); + Geom::Point knot_pos = this->knot->pos * item->i2dt_affine().inverse(); + Geom::Coord nearest_to_ray = ray.nearestTime(knot_pos); + if(nearest_to_ray == 0){ + lpe->prop_scale.param_set_value(-Geom::distance(s , ptA)/(lpe->original_height/2.0)); + } else { + lpe->prop_scale.param_set_value(Geom::distance(s , ptA)/(lpe->original_height/2.0)); + } sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); } @@ -211,8 +225,8 @@ KnotHolderEntityWidthBendPath::knot_get() const if (cubic) { ray.setPoints(ptA,(*cubic)[1]); } - Geom::Angle first_curve_angle = ray.transformed(Geom::Rotate(Geom::deg_to_rad(90))).angle(); - Geom::Point result_point = Geom::Point::polar(first_curve_angle, (lpe->original_height * lpe->prop_scale)/2.0) + ptA; + ray.setAngle(ray.angle() + Geom::deg_to_rad(90)); + Geom::Point result_point = Geom::Point::polar(ray.angle(), (lpe->original_height/2.0) * lpe->prop_scale) + ptA; bp_helper_path.clear(); Geom::Path hp(result_point); diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index ed377e7f9..706091be9 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -291,7 +291,22 @@ KnotHolderEntityWidthPatternAlongPath::knot_set(Geom::Point const &p, Geom::Poin if (sp_shape) { Geom::Path const *path_in = sp_shape->getCurveBeforeLPE()->first_path(); Geom::Point ptA = path_in->pointAt(Geom::PathTime(0, 0.0)); - lpe->prop_scale.param_set_value(Geom::distance(s , ptA)/(lpe->original_height/2.0)); + Geom::Point B = path_in->pointAt(Geom::PathTime(1, 0.0)); + Geom::Curve const *first_curve = &path_in->curveAt(Geom::PathTime(0, 0.0)); + Geom::CubicBezier const *cubic = dynamic_cast(&*first_curve); + Geom::Ray ray(ptA, B); + if (cubic) { + ray.setPoints(ptA, (*cubic)[1]); + } + ray.setAngle(ray.angle() + Geom::deg_to_rad(90)); + Geom::Point knot_pos = this->knot->pos * item->i2dt_affine().inverse(); + Geom::Coord nearest_to_ray = ray.nearestTime(knot_pos); + if(nearest_to_ray == 0){ + lpe->prop_scale.param_set_value(-Geom::distance(s , ptA)/(lpe->original_height/2.0)); + } else { + lpe->prop_scale.param_set_value(Geom::distance(s , ptA)/(lpe->original_height/2.0)); + } + } sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); } @@ -310,10 +325,10 @@ KnotHolderEntityWidthPatternAlongPath::knot_get() const Geom::CubicBezier const *cubic = dynamic_cast(&*first_curve); Geom::Ray ray(ptA, B); if (cubic) { - ray.setPoints((*cubic)[1], ptA); + ray.setPoints(ptA, (*cubic)[1]); } - Geom::Angle first_curve_angle = ray.transformed(Geom::Rotate(Geom::deg_to_rad(90))).angle(); - Geom::Point result_point = Geom::Point::polar(first_curve_angle, (lpe->original_height * lpe->prop_scale)/2.0) + ptA; + ray.setAngle(ray.angle() + Geom::deg_to_rad(90)); + Geom::Point result_point = Geom::Point::polar(ray.angle(), (lpe->original_height/2.0) * lpe->prop_scale) + ptA; pap_helper_path.clear(); Geom::Path hp(result_point); -- cgit v1.2.3 From 689ac8e0dc1edc3e53c88daa44fae0f8f1857346 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 8 Dec 2015 15:24:13 +0100 Subject: Fix return value for SPIEnumBits::write(). (bzr r14517) --- src/style-internal.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/style-internal.cpp b/src/style-internal.cpp index c117a97f9..b425a1c80 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -709,7 +709,8 @@ SPIEnumBits::write( guint const flags, SPIBase const *const base) const { unsigned j = 1; for (unsigned i = 0; enums[i].key; ++i) { if (j & this->value ) { - return_string += enums[i].value + " "; + return_string += enums[i].key; + return_string += " "; } j *= 2; } -- cgit v1.2.3