From: johanengelen Date: Sun, 20 Jul 2008 18:32:15 +0000 (+0000) Subject: add comments about setting new LPE PathParam path data. refactor things a bit for... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=94f2e710e9cc2e0eb14c8d73abfe77d60f961db2;p=inkscape.git add comments about setting new LPE PathParam path data. refactor things a bit for easier comprehension and optimization possibility from within nodepath --- diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index dc98561e1..e2672670d 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -134,7 +134,7 @@ LPEBendPath::resetDefaults(SPItem * item) Geom::Path path; path.start( start ); path.appendNew( end ); - bend_path.param_set_and_write_new_value( path.toPwSb() ); + bend_path.set_new_value( path.toPwSb(), true ); } void diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index 34fb60a31..34c17a025 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -172,7 +172,7 @@ LPECurveStitch::resetDefaults(SPItem * item) Geom::Path path; path.start( start ); path.appendNew( end ); - strokepath.param_set_and_write_new_value( path.toPwSb() ); + strokepath.set_new_value( path.toPwSb(), true ); } else { // bounding box is too small to make decent path. set to default default. :-) strokepath.param_set_and_write_default(); diff --git a/src/live_effects/lpe-envelope.cpp b/src/live_effects/lpe-envelope.cpp index 7d2045d80..ef3d4cc82 100755 --- a/src/live_effects/lpe-envelope.cpp +++ b/src/live_effects/lpe-envelope.cpp @@ -233,22 +233,22 @@ LPEEnvelope::resetDefaults(SPItem * item) Geom::Path path1; path1.start( Up_Left ); path1.appendNew( Up_Right ); - bend_path1.param_set_and_write_new_value( path1.toPwSb() ); + bend_path1.set_new_value( path1.toPwSb(), true ); Geom::Path path2; path2.start( Up_Right ); path2.appendNew( Down_Right ); - bend_path2.param_set_and_write_new_value( path2.toPwSb() ); + bend_path2.set_new_value( path2.toPwSb(), true ); Geom::Path path3; path3.start( Down_Left ); path3.appendNew( Down_Right ); - bend_path3.param_set_and_write_new_value( path3.toPwSb() ); + bend_path3.set_new_value( path3.toPwSb(), true ); Geom::Path path4; path4.start( Up_Left ); path4.appendNew( Down_Left ); - bend_path4.param_set_and_write_new_value( path4.toPwSb() ); + bend_path4.set_new_value( path4.toPwSb(), true ); } void diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 8095e5360..39d3bfe30 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -50,7 +50,7 @@ LPEMirrorSymmetry::acceptParamPath (SPPath *param_path) { Geom::Point B(curve->last_point()); Piecewise > rline = Piecewise >(D2(Linear(A[X], B[X]), Linear(A[Y], B[Y]))); - reflection_line.param_set_and_write_new_value(rline); + reflection_line.set_new_value( rline, true ); SP_OBJECT(param_path)->deleteObject(true); diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp index e44868290..8937f7cec 100644 --- a/src/live_effects/lpe-vonkoch.cpp +++ b/src/live_effects/lpe-vonkoch.cpp @@ -179,8 +179,7 @@ LPEVonKoch::resetDefaults(SPItem * item) paths.push_back(path * Matrix(1./3,0,0,1./3, end[X]*2./3, end[Y]*2./3 + bndsY.extent()/2)); paths.push_back(path); - //generator.param_set_and_write_new_value( path.toPwSb() ); - generator.param_set_and_write_new_value( paths_to_pw(paths) ); + generator.set_new_value(paths, true); @@ -188,7 +187,7 @@ LPEVonKoch::resetDefaults(SPItem * item) // Piecewise > default_gen; // default_gen.concat(Piecewise >(D2(Linear(bndsX.min(),bndsX.max()),Linear((bndsY.min()+bndsY.max())/2)))); // default_gen.concat(Piecewise >(D2(Linear(bndsX.max(),bndsX.max()+bndsX.extent()/2),Linear((bndsY.min()+bndsY.max())/2)))); -// generator.param_set_and_write_new_value( default_gen ); +// generator.set_new_value(default_gen, true); } void diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index 1e470bb14..c954e09df 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -12,6 +12,7 @@ #include "svg/svg.h" #include <2geom/svg-path-parser.h> #include <2geom/sbasis-to-bezier.h> +#include <2geom/pathvector.h> #include <2geom/d2.h> #include "ui/widget/point.h" @@ -216,41 +217,68 @@ PathParam::param_setup_nodepath(Inkscape::NodePath::Path *np) np->helperpath_width = 1.0; } +/* + * Only applies transform when not referring to other path! + */ void PathParam::param_transform_multiply(Geom::Matrix const& postmul, bool /*set*/) { + // only apply transform when not referring to other path if (!href) { - // TODO: recode this to apply transform to _pathvector instead? - - // only apply transform when not referring to other path - ensure_pwd2(); - param_set_and_write_new_value( _pwd2 * postmul ); + set_new_value( _pathvector * postmul, true ); } } +/* + * See comments for set_new_value(std::vector). + */ void -PathParam::param_set_and_write_new_value (Geom::Piecewise > const & newpath) +PathParam::set_new_value (Geom::Piecewise > const & newpath, bool write_to_svg) { remove_link(); _pathvector = Geom::path_from_piecewise(newpath, LPE_CONVERSION_TOLERANCE); - gchar * svgd = sp_svg_write_path( _pathvector ); - param_write_to_repr(svgd); - g_free(svgd); - // force value upon pwd2 and don't recalculate. - _pwd2 = newpath; - must_recalculate_pwd2 = false; + + if (write_to_svg) { + gchar * svgd = sp_svg_write_path( _pathvector ); + param_write_to_repr(svgd); + g_free(svgd); + + // After the whole "writing to svg avalanche of function calling": force value upon pwd2 and don't recalculate. + _pwd2 = newpath; + must_recalculate_pwd2 = false; + } else { + _pwd2 = newpath; + must_recalculate_pwd2 = false; + signal_path_changed.emit(); + } } +/* + * This method sets new path data. + * If this PathParam refers to another path, this link is removed (and replaced with explicit path data). + * + * If write_to_svg = true : + * The new path data is written to SVG. In this case the signal_path_changed signal + * is not directly emited in this method, because writing to SVG + * triggers the LPEObject to which this belongs to call Effect::setParameter which calls + * PathParam::readSVGValue, which finally emits the signal_path_changed signal. + * If write_to_svg = false : + * The new path data is not written to SVG. This method will emit the signal_path_changed signal. + */ void -PathParam::param_set_and_write_new_value (std::vector const & newpath) +PathParam::set_new_value (std::vector const &newpath, bool write_to_svg) { remove_link(); _pathvector = newpath; must_recalculate_pwd2 = true; - gchar * svgd = sp_svg_write_path( _pathvector ); - param_write_to_repr(svgd); - g_free(svgd); + if (write_to_svg) { + gchar * svgd = sp_svg_write_path( _pathvector ); + param_write_to_repr(svgd); + g_free(svgd); + } else { + signal_path_changed.emit(); + } } void @@ -308,7 +336,7 @@ PathParam::linked_delete(SPObject */*deleted*/) { quit_listening(); remove_link(); - param_set_and_write_new_value (_pathvector); + set_new_value (_pathvector, true); } void diff --git a/src/live_effects/parameter/path.h b/src/live_effects/parameter/path.h index 8dcda8215..e2d9c0e19 100644 --- a/src/live_effects/parameter/path.h +++ b/src/live_effects/parameter/path.h @@ -39,13 +39,13 @@ public: virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * tooltips); - bool param_readSVGValue(const gchar * strvalue); - gchar * param_getSVGValue() const; + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; - void param_set_default(); + virtual void param_set_default(); void param_set_and_write_default(); - void param_set_and_write_new_value (Geom::Piecewise > const & newpath); - void param_set_and_write_new_value (std::vector const & newpath); + void set_new_value (std::vector const &newpath, bool write_to_svg); + void set_new_value (Geom::Piecewise > const &newpath, bool write_to_svg); virtual void param_editOncanvas(SPItem * item, SPDesktop * dt); virtual void param_setup_nodepath(Inkscape::NodePath::Path *np);