From: johanengelen Date: Sun, 23 Mar 2008 19:23:08 +0000 (+0000) Subject: remove multiple inheritance from lpe PathParam. since it is often desired to get... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=afb717c6e7d29c86c404b6627855c438d6dc2c0f;p=inkscape.git remove multiple inheritance from lpe PathParam. since it is often desired to get the path not as pw< d2<> >, but also as geom::path or maybe as dw< pw<> >. Plus this enabled linking to an object, instead of keeping its own path data. (i.e. linking to other objects) --- diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index 85d6e5e8f..dc9cfe635 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -80,7 +80,7 @@ LPECurveStitch::doEffect_path (std::vector & path_in) startpoint_spacing_variation.resetRandomizer(); endpoint_spacing_variation.resetRandomizer(); - D2 > stroke = make_cuts_independant(strokepath); + D2 > stroke = make_cuts_independant(strokepath.get_pwd2()); Interval bndsStroke = bounds_exact(stroke[0]); gdouble scaling = bndsStroke.max() - bndsStroke.min(); Interval bndsStrokeY = bounds_exact(stroke[1]); @@ -123,7 +123,7 @@ LPECurveStitch::doEffect_path (std::vector & path_in) transform.setXAxis( (end-start) / scaling ); transform.setYAxis( rot90(unit_vector(end-start)) * scaling_y); transform.setTranslation( start ); - Piecewise > pwd2_out = (strokepath-stroke_origin) * transform; + Piecewise > pwd2_out = (strokepath.get_pwd2()-stroke_origin) * transform; // add stuff to one big pw > and then outside the loop convert to path? // No: this way, the separate result paths are kept separate which might come in handy some time! @@ -157,12 +157,13 @@ LPECurveStitch::resetDefaults(SPItem * item) using namespace Geom; // set the stroke path to run horizontally in the middle of the bounding box of the original path + + // calculate bounding box: (isn't there a simpler way?) Piecewise > pwd2; std::vector temppath = SVGD_to_2GeomPath( SP_OBJECT_REPR(item)->attribute("inkscape:original-d")); for (unsigned int i=0; i < temppath.size(); i++) { pwd2.concat( temppath[i].toPwSb() ); } - D2 > d2pw = make_cuts_independant(pwd2); Interval bndsX = bounds_exact(d2pw[0]); Interval bndsY = bounds_exact(d2pw[1]); diff --git a/src/live_effects/lpe-pathalongpath.cpp b/src/live_effects/lpe-pathalongpath.cpp index 750d78346..0475f4603 100644 --- a/src/live_effects/lpe-pathalongpath.cpp +++ b/src/live_effects/lpe-pathalongpath.cpp @@ -81,7 +81,7 @@ LPEPathAlongPath::doEffect_pwd2 (Geom::Piecewise > & pwd2 /* Much credit should go to jfb and mgsloan of lib2geom development for the code below! */ - Piecewise > uskeleton = arc_length_parametrization(Piecewise >(bend_path),2,.1); + Piecewise > uskeleton = arc_length_parametrization(Piecewise >(bend_path.get_pwd2()),2,.1); uskeleton = remove_short_cuts(uskeleton,.01); Piecewise > n = rot90(derivative(uskeleton)); n = force_continuity(remove_short_cuts(n,.1)); @@ -123,7 +123,6 @@ LPEPathAlongPath::resetDefaults(SPItem * item) for (unsigned int i=0; i < temppath.size(); i++) { pwd2.concat( temppath[i].toPwSb() ); } - D2 > d2pw = make_cuts_independant(pwd2); Interval bndsX = bounds_exact(d2pw[0]); Interval bndsY = bounds_exact(d2pw[1]); diff --git a/src/live_effects/lpe-skeletalstrokes.cpp b/src/live_effects/lpe-skeletalstrokes.cpp index 0f8e013b8..77c5a75c8 100644 --- a/src/live_effects/lpe-skeletalstrokes.cpp +++ b/src/live_effects/lpe-skeletalstrokes.cpp @@ -103,7 +103,7 @@ LPESkeletalStrokes::doEffect_pwd2 (Geom::Piecewise > & pw Piecewise > n = rot90(derivative(uskeleton)); n = force_continuity(remove_short_cuts(n,.1)); - D2 > patternd2 = make_cuts_independant(pattern); + D2 > patternd2 = make_cuts_independant(pattern.get_pwd2()); Piecewise x = vertical_pattern.get_value() ? Piecewise(patternd2[1]) : Piecewise(patternd2[0]); Piecewise y = vertical_pattern.get_value() ? Piecewise(patternd2[0]) : Piecewise(patternd2[1]); Interval pattBndsX = bounds_exact(x); diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp index cb5ea126c..760295ed7 100644 --- a/src/live_effects/lpe-vonkoch.cpp +++ b/src/live_effects/lpe-vonkoch.cpp @@ -79,7 +79,7 @@ std::vector LPEVonKoch::doEffect_path (std::vector & path_in) { using namespace Geom; - std::vector generating_path = path_from_piecewise(generator,.01);//TODO what should that tolerance be? + std::vector generating_path = path_from_piecewise(generator.get_pwd2(),.01);//TODO what should that tolerance be? //Collect transform matrices. //FIXME: fusing/cutting nodes mix up component order in the path. This is why the last segment is used. diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index ded004eee..944fe3da7 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -40,7 +40,9 @@ namespace LivePathEffect { PathParam::PathParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, const gchar * default_value) - : Parameter(label, tip, key, wr, effect) + : Parameter(label, tip, key, wr, effect), + _pwd2(), + referring(false) { defvalue = g_strdup(default_value); param_readSVGValue(defvalue); @@ -52,6 +54,19 @@ PathParam::~PathParam() g_free(defvalue); } +Geom::Piecewise > & +PathParam::get_pwd2() +{ + if (!referring) { + return _pwd2; + } else { + /* update own pwd2 with data from path referred to + when this works, optimize to only update own pwd2 when referred path changed. */ + //_pwd2 = ...; + return _pwd2; + } +} + void PathParam::param_set_default() { @@ -73,7 +88,7 @@ PathParam::param_readSVGValue(const gchar * strvalue) for (unsigned int i=0; i < temppath.size(); i++) { newpath.concat( temppath[i].toPwSb() ); } - *( dynamic_cast > *> (this) ) = newpath; + _pwd2 = newpath; signal_path_changed.emit(); return true; } @@ -85,7 +100,7 @@ gchar * PathParam::param_writeSVGValue() const { const std::vector temppath = - Geom::path_from_piecewise(* dynamic_cast > *> (this), LPE_CONVERSION_TOLERANCE); + Geom::path_from_piecewise(_pwd2, LPE_CONVERSION_TOLERANCE); gchar * svgd = SVGD_from_2GeomPath( temppath ); return svgd; } @@ -157,11 +172,13 @@ PathParam::param_setup_nodepath(Inkscape::NodePath::Path *np) void PathParam::param_transform_multiply(Geom::Matrix const& postmul, bool /*set*/) { - param_set_and_write_new_value( (*this) * postmul ); + // only apply transform when not referring to other path + if (!referring) + param_set_and_write_new_value( _pwd2 * postmul ); } void -PathParam::param_set_and_write_new_value (Geom::Piecewise > newpath) +PathParam::param_set_and_write_new_value (Geom::Piecewise > const & newpath) { const std::vector temppath = Geom::path_from_piecewise(newpath, LPE_CONVERSION_TOLERANCE); gchar * svgd = SVGD_from_2GeomPath( temppath ); diff --git a/src/live_effects/parameter/path.h b/src/live_effects/parameter/path.h index 0bb65b77c..838543cd9 100644 --- a/src/live_effects/parameter/path.h +++ b/src/live_effects/parameter/path.h @@ -22,7 +22,7 @@ namespace Inkscape { namespace LivePathEffect { -class PathParam : public Geom::Piecewise >, public Parameter { +class PathParam : public Parameter { public: PathParam ( const Glib::ustring& label, const Glib::ustring& tip, @@ -32,6 +32,8 @@ public: const gchar * default_value = "M0,0 L1,1"); virtual ~PathParam(); + Geom::Piecewise > & get_pwd2(); + virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * tooltips); bool param_readSVGValue(const gchar * strvalue); @@ -39,7 +41,7 @@ public: void param_set_default(); void param_set_and_write_default(); - void param_set_and_write_new_value (Geom::Piecewise > newpath); + void param_set_and_write_new_value (Geom::Piecewise > const & newpath); virtual void param_editOncanvas(SPItem * item, SPDesktop * dt); virtual void param_setup_nodepath(Inkscape::NodePath::Path *np); @@ -49,15 +51,19 @@ public: sigc::signal signal_path_pasted; sigc::signal signal_path_changed; -private: - PathParam(const PathParam&); - PathParam& operator=(const PathParam&); +protected: + Geom::Piecewise > _pwd2; + bool referring; // set when referring to another path, i.e. does not have its own pwd2, but should get it from another path void on_edit_button_click(); void on_paste_button_click(); void on_copy_button_click(); gchar * defvalue; + +private: + PathParam(const PathParam&); + PathParam& operator=(const PathParam&); }; diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 81af6512a..e40746061 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -1178,7 +1178,7 @@ void sp_selection_copy_lpe_pathparam(Inkscape::LivePathEffect::PathParam * pathp clipboard = g_slist_prepend(clipboard, newnode); - Geom::Rect bnds = Geom::bounds_exact(*pathparam); + Geom::Rect bnds = Geom::bounds_exact(pathparam->get_pwd2()); size_clipboard = from_2geom(bnds); }