summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 254b75c)
raw | patch | inline | side by side (parent: 254b75c)
author | johanengelen <johanengelen@users.sourceforge.net> | |
Sun, 23 Mar 2008 20:12:39 +0000 (20:12 +0000) | ||
committer | johanengelen <johanengelen@users.sourceforge.net> | |
Sun, 23 Mar 2008 20:12:39 +0000 (20:12 +0000) |
src/live_effects/parameter/path.cpp | patch | blob | history | |
src/live_effects/parameter/path.h | patch | blob | history |
index 028dd5e8b1dcea2c33c74c17f2affa7b525286e8..c87cff6135eddd48f583c44c6d80b249822d10e0 100644 (file)
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)
{
g_free(defvalue);
}
+std::vector<Geom::Path> const &
+PathParam::get_pathvector()
+{
+ if (!referring) {
+ return _pathvector;
+ } else {
+ update_from_referred();
+ must_recalculate_pwd2 = true;
+ return _pathvector;
+ }
+}
+
Geom::Piecewise<Geom::D2<Geom::SBasis> > 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;
}
}
PathParam::param_readSVGValue(const gchar * strvalue)
{
if (strvalue) {
- Geom::Piecewise<Geom::D2<Geom::SBasis> > newpath;
- std::vector<Geom::Path> 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;
}
gchar *
PathParam::param_writeSVGValue() const
{
- const std::vector<Geom::Path> temppath =
- Geom::path_from_piecewise(_pwd2, LPE_CONVERSION_TOLERANCE);
- gchar * svgd = SVGD_from_2GeomPath( temppath );
+ gchar * svgd = SVGD_from_2GeomPath( _pathvector );
return svgd;
}
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<Geom::D2<Geom::SBasis> > const & newpath)
{
- const std::vector<Geom::Path> 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 */
index 70f3cc20a5273051f6232303786c6e1684b5592f..6f2a0d1fdcc96ba8f6263efb1de88fe5280f0667 100644 (file)
const gchar * default_value = "M0,0 L1,1");
virtual ~PathParam();
+ std::vector<Geom::Path> const & get_pathvector();
Geom::Piecewise<Geom::D2<Geom::SBasis> > const & get_pwd2();
virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * tooltips);
sigc::signal <void> signal_path_changed;
protected:
- Geom::Piecewise<Geom::D2<Geom::SBasis> > _pwd2;
+ std::vector<Geom::Path> _pathvector; // this is primary data storage, since it is closest to SVG.
+
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > _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();