Code

add comments about setting new LPE PathParam path data. refactor things a bit for...
authorjohanengelen <johanengelen@users.sourceforge.net>
Sun, 20 Jul 2008 18:32:15 +0000 (18:32 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Sun, 20 Jul 2008 18:32:15 +0000 (18:32 +0000)
src/live_effects/lpe-bendpath.cpp
src/live_effects/lpe-curvestitch.cpp
src/live_effects/lpe-envelope.cpp
src/live_effects/lpe-mirror_symmetry.cpp
src/live_effects/lpe-vonkoch.cpp
src/live_effects/parameter/path.cpp
src/live_effects/parameter/path.h

index dc98561e1b4e6500a6d759f4a5d8e02f68f7d14a..e2672670da3619e32462f33089a5ae9a33cb8488 100644 (file)
@@ -134,7 +134,7 @@ LPEBendPath::resetDefaults(SPItem * item)
     Geom::Path path;
     path.start( start );
     path.appendNew<Geom::LineSegment>( end );
-    bend_path.param_set_and_write_new_value( path.toPwSb() );
+    bend_path.set_new_value( path.toPwSb(), true );
 }
 
 void
index 34fb60a31fabf2669fa6c541247be43e288970ac..34c17a0256f3bcdf2b4fdf9608e9cbc2fdbfb802 100644 (file)
@@ -172,7 +172,7 @@ LPECurveStitch::resetDefaults(SPItem * item)
         Geom::Path path;
         path.start( start );
         path.appendNew<Geom::LineSegment>( 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();
index 7d2045d80a95bb478c534221faf535720f300a53..ef3d4cc82143ddb81e86c772ec0770436c02ba99 100755 (executable)
@@ -233,22 +233,22 @@ LPEEnvelope::resetDefaults(SPItem * item)
     Geom::Path path1;
     path1.start( Up_Left );
     path1.appendNew<Geom::LineSegment>( 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<Geom::LineSegment>( 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<Geom::LineSegment>( 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<Geom::LineSegment>( Down_Left );
-    bend_path4.param_set_and_write_new_value( path4.toPwSb() );
+    bend_path4.set_new_value( path4.toPwSb(), true );
 }
 
 void
index 8095e5360a5e59d805d1b92f491ab15efb7aba42..39d3bfe30488b76f78ae1bcd54da5bf53e5c9ed9 100644 (file)
@@ -50,7 +50,7 @@ LPEMirrorSymmetry::acceptParamPath (SPPath *param_path) {
     Geom::Point B(curve->last_point());
     
     Piecewise<D2<SBasis> > rline = Piecewise<D2<SBasis> >(D2<SBasis>(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);
 
index e448682909149d022d4385141fb7ba8fccf54f36..8937f7cec5e4f4a4778f57d96d5c9e25874149ce 100644 (file)
@@ -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<D2<SBasis> > default_gen;
 //     default_gen.concat(Piecewise<D2<SBasis> >(D2<SBasis>(Linear(bndsX.min(),bndsX.max()),Linear((bndsY.min()+bndsY.max())/2))));
 //     default_gen.concat(Piecewise<D2<SBasis> >(D2<SBasis>(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
index 1e470bb14e5d0e82f4ddec51e09ad59a50921c29..c954e09df85327eb1cf61a5d7e3ebce6cb95035f 100644 (file)
@@ -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<Geom::Path>).
+ */
 void
-PathParam::param_set_and_write_new_value (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & newpath)
+PathParam::set_new_value (Geom::Piecewise<Geom::D2<Geom::SBasis> > 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<Geom::Path> const & newpath)
+PathParam::set_new_value (std::vector<Geom::Path> 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
index 8dcda821517013991bfee877ddce85fe70732d51..e2d9c0e19074880485d637b651e1c20a59bbd18e 100644 (file)
@@ -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<Geom::D2<Geom::SBasis> > const & newpath);
-    void param_set_and_write_new_value (std::vector<Geom::Path> const & newpath);
+    void set_new_value (std::vector<Geom::Path> const &newpath, bool write_to_svg);
+    void set_new_value (Geom::Piecewise<Geom::D2<Geom::SBasis> > const &newpath, bool write_to_svg);
 
     virtual void param_editOncanvas(SPItem * item, SPDesktop * dt);
     virtual void param_setup_nodepath(Inkscape::NodePath::Path *np);