From 1673045848db9654bcb07a81fad34afb4b0623d1 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Sun, 23 Mar 2008 20:12:39 +0000 Subject: [PATCH] set primary path storage to vector in lpe-PathParam. only convert to pwd2 when needed. --- src/live_effects/parameter/path.cpp | 69 ++++++++++++++++++++++------- src/live_effects/parameter/path.h | 9 +++- 2 files changed, 61 insertions(+), 17 deletions(-) diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index 028dd5e8b..c87cff613 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -41,6 +41,8 @@ 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), + _pathvector(), + must_recalculate_pwd2(false), _pwd2(), referring(false) { @@ -54,15 +56,27 @@ PathParam::~PathParam() g_free(defvalue); } +std::vector const & +PathParam::get_pathvector() +{ + if (!referring) { + return _pathvector; + } else { + update_from_referred(); + must_recalculate_pwd2 = true; + return _pathvector; + } +} + Geom::Piecewise > const & PathParam::get_pwd2() { if (!referring) { + ensure_pwd2(); 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 = ...; + update_from_referred(); + ensure_pwd2(); return _pwd2; } } @@ -83,12 +97,10 @@ bool PathParam::param_readSVGValue(const gchar * strvalue) { if (strvalue) { - Geom::Piecewise > newpath; - std::vector temppath = SVGD_to_2GeomPath(strvalue); - for (unsigned int i=0; i < temppath.size(); i++) { - newpath.concat( temppath[i].toPwSb() ); - } - _pwd2 = newpath; + _pathvector.clear(); + _pathvector = SVGD_to_2GeomPath(strvalue); + must_recalculate_pwd2 = true; + signal_path_changed.emit(); return true; } @@ -99,9 +111,7 @@ PathParam::param_readSVGValue(const gchar * strvalue) gchar * PathParam::param_writeSVGValue() const { - const std::vector temppath = - Geom::path_from_piecewise(_pwd2, LPE_CONVERSION_TOLERANCE); - gchar * svgd = SVGD_from_2GeomPath( temppath ); + gchar * svgd = SVGD_from_2GeomPath( _pathvector ); return svgd; } @@ -172,18 +182,45 @@ PathParam::param_setup_nodepath(Inkscape::NodePath::Path *np) void PathParam::param_transform_multiply(Geom::Matrix const& postmul, bool /*set*/) { - // only apply transform when not referring to other path - if (!referring) + // TODO: recode this to apply transform to _pathvector instead? + if (!referring) { + // only apply transform when not referring to other path + ensure_pwd2(); param_set_and_write_new_value( _pwd2 * postmul ); + } } void 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 ); + _pathvector = Geom::path_from_piecewise(newpath, LPE_CONVERSION_TOLERANCE); + gchar * svgd = SVGD_from_2GeomPath( _pathvector ); param_write_to_repr(svgd); g_free(svgd); + // force value upon pwd2 and don't recalculate. + _pwd2 = newpath; + must_recalculate_pwd2 = false; +} + +void +PathParam::ensure_pwd2() +{ + if (must_recalculate_pwd2) { + _pwd2.clear(); + for (unsigned int i=0; i < _pathvector.size(); i++) { + _pwd2.concat( _pathvector[i].toPwSb() ); + } + + must_recalculate_pwd2 = false; + } +} + +void +PathParam::update_from_referred() +{ + // TODO + + // optimize, only update from referred when referred changed. } /* CALLBACK FUNCTIONS FOR THE BUTTONS */ diff --git a/src/live_effects/parameter/path.h b/src/live_effects/parameter/path.h index 70f3cc20a..6f2a0d1fd 100644 --- a/src/live_effects/parameter/path.h +++ b/src/live_effects/parameter/path.h @@ -32,6 +32,7 @@ public: const gchar * default_value = "M0,0 L1,1"); virtual ~PathParam(); + std::vector const & get_pathvector(); Geom::Piecewise > const & get_pwd2(); virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * tooltips); @@ -52,8 +53,14 @@ public: sigc::signal signal_path_changed; protected: - Geom::Piecewise > _pwd2; + std::vector _pathvector; // this is primary data storage, since it is closest to SVG. + + Geom::Piecewise > _pwd2; // secondary, hence the bool must_recalculate_pwd2 + bool must_recalculate_pwd2; // set when _pathvector was updated, but _pwd2 not + void ensure_pwd2(); // ensures _pwd2 is up to date + bool referring; // set when referring to another path, i.e. does not have its own pwd2, but should get it from another path + void update_from_referred(); // updates path data by looking up refered path void on_edit_button_click(); void on_paste_button_click(); -- 2.30.2