Code

try to make LPE optimizations easier. example in LPE Bend
authorjohanengelen <johanengelen@users.sourceforge.net>
Thu, 7 Aug 2008 17:45:53 +0000 (17:45 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Thu, 7 Aug 2008 17:45:53 +0000 (17:45 +0000)
src/live_effects/lpe-bendpath.cpp
src/live_effects/lpe-bendpath.h
src/live_effects/parameter/path.cpp
src/live_effects/parameter/path.h

index 47d029d602cbe029336e7864b2c6747666c46594..fb305130df201fb21653a74546d680f36d476e13 100644 (file)
@@ -83,14 +83,19 @@ LPEBendPath::doBeforeEffect (SPLPEItem *lpeitem)
 Geom::Piecewise<Geom::D2<Geom::SBasis> >
 LPEBendPath::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
 {
+g_message("doEffect_pwd2");
     using namespace Geom;
 
 /* Much credit should go to jfb and mgsloan of lib2geom development for the code below! */
 
-    Piecewise<D2<SBasis> > uskeleton = arc_length_parametrization(Piecewise<D2<SBasis> >(bend_path.get_pwd2()),2,.1);
-    uskeleton = remove_short_cuts(uskeleton,.01);
-    Piecewise<D2<SBasis> > n = rot90(derivative(uskeleton));
-    n = force_continuity(remove_short_cuts(n,.1));
+    if (bend_path.changed) {
+        uskeleton = arc_length_parametrization(Piecewise<D2<SBasis> >(bend_path.get_pwd2()),2,.1);
+        uskeleton = remove_short_cuts(uskeleton,.01);
+        n = rot90(derivative(uskeleton));
+        n = force_continuity(remove_short_cuts(n,.1));
+
+        bend_path.changed = false;
+    }
 
     D2<Piecewise<SBasis> > patternd2 = make_cuts_independent(pwd2_in);
     Piecewise<SBasis> x = vertical_pattern.get_value() ? Piecewise<SBasis>(patternd2[1]) : Piecewise<SBasis>(patternd2[0]);
index 1d3a9861ef8793e5307b87496232acf0616c14b8..20871bc0f3eafd3b5ba99e1e652d92c854c8aaa6 100644 (file)
@@ -47,6 +47,9 @@ private:
     BoolParam scale_y_rel;
     BoolParam    vertical_pattern;
 
+    Geom::Piecewise<Geom::D2<Geom::SBasis> > uskeleton;
+    Geom::Piecewise<Geom::D2<Geom::SBasis> > n;
+
     void on_pattern_pasted();
 
     LPEBendPath(const LPEBendPath&);
index 68cb5cd633bcc98b6f02c75aaf0d29988895b61f..84aadff3cae8f680d37a34201c33cfa36d9cc9a1 100644 (file)
@@ -49,6 +49,7 @@ 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),
+      changed(true),
       _pathvector(),
       _pwd2(),
       must_recalculate_pwd2(false),
@@ -119,7 +120,7 @@ PathParam::param_readSVGValue(const gchar * strvalue)
             _pathvector = sp_svg_read_pathv(strvalue);
         }
 
-        signal_path_changed.emit();
+        emit_changed();
         return true;
     }
 
@@ -254,7 +255,7 @@ PathParam::set_new_value (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & newpa
     } else {
         _pwd2 = newpath;
         must_recalculate_pwd2 = false;
-        signal_path_changed.emit();
+        emit_changed();
     }
 }
 
@@ -282,7 +283,7 @@ PathParam::set_new_value (std::vector<Geom::Path> const &newpath, bool write_to_
         param_write_to_repr(svgd);
         g_free(svgd);
     } else {
-        signal_path_changed.emit();
+        emit_changed();
     }
 }
 
@@ -299,6 +300,13 @@ PathParam::ensure_pwd2()
     }
 }
 
+void
+PathParam::emit_changed()
+{
+    changed = true;
+    signal_path_changed.emit();
+}
+
 void
 PathParam::start_listening(SPObject * to)
 {
@@ -364,7 +372,7 @@ PathParam::linked_modified(SPObject *linked_obj, guint /*flags*/)
     }
 
     must_recalculate_pwd2 = true;
-    signal_path_changed.emit();
+    emit_changed();
     SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG);
 }
 
index 76f3fa774ff61c633a23f6d598e65fca15c9ae97..23ad51417d9d9f7a599bf2ac68f567fbcd66d810 100644 (file)
@@ -53,6 +53,8 @@ public:
 
     sigc::signal <void> signal_path_pasted;
     sigc::signal <void> signal_path_changed;
+    bool changed; /* this gets set whenever the path is changed (this is set to true, and then the signal_path_changed signal is emitted).
+                   * the user must set it back to false if she wants to use it sensibly */
 
     void paste_param_path(const char *svgd);
     void on_paste_button_click();
@@ -80,6 +82,8 @@ protected:
     void on_copy_button_click();
     void on_link_button_click();
 
+    void emit_changed();
+
     gchar * defvalue;
 
 private: