From 2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2 Mon Sep 17 00:00:00 2001 From: cilix42 Date: Tue, 29 Jul 2008 14:53:07 +0000 Subject: [PATCH] Remove addHelperPaths() from Effect; now getHelperPaths() returns a list of canvas indicators provided by the effect itself or its parameters (overload addCanvasIndicators to provide them in derived effects) --- src/live_effects/effect.cpp | 60 +++++++++++++++----------- src/live_effects/effect.h | 7 ++- src/live_effects/lpe-lattice.cpp | 2 + src/live_effects/lpe-lattice.h | 2 +- src/live_effects/parameter/parameter.h | 4 ++ 5 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 467b1417d..0254c547c 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -36,7 +36,7 @@ #include <2geom/sbasis-to-bezier.h> #include <2geom/matrix.h> - +#include <2geom/pathvector.h> // include effects: #include "live_effects/lpe-patternalongpath.h" @@ -450,42 +450,49 @@ Effect::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem } } -void -Effect::addHelperPaths(SPLPEItem *lpeitem, SPDesktop *desktop) +/** + * Return a vector of PathVectors which contain all helperpaths that should be drawn by the effect. + * This is the function called by external code like SPLPEItem. + */ +std::vector +Effect::getHelperPaths(SPLPEItem *lpeitem) { - g_return_if_fail(desktop); - g_return_if_fail(SP_IS_PATH(lpeitem)); - - if (providesKnotholder() && showOrigPath()) { - // TODO: we assume that if the LPE provides its own knotholder, there is no nodepath so we - // must create the helper curve for the original path manually; once we allow nodepaths and - // knotholders alongside each other, this needs to be rethought! - SPCanvasItem *canvasitem = sp_nodepath_generate_helperpath(desktop, SP_PATH(lpeitem)); - Inkscape::Display::TemporaryItem* tmpitem = desktop->add_temporary_canvasitem (canvasitem, 0); - lpeitem->lpe_helperpaths.push_back(tmpitem); + std::vector hp_vec; + + if (!SP_IS_SHAPE(lpeitem)) { + g_print ("How to handle helperpaths for non-shapes?\n"); + return hp_vec; } - for (std::vector::iterator p = param_vector.begin(); p != param_vector.end(); ++p) { - if ( Inkscape::LivePathEffect::PathParam *pathparam = dynamic_cast(*p) ) { - SPCurve *c = new SPCurve(pathparam->get_pathvector()); + // TODO: we can probably optimize this by using a lot more references + // rather than copying PathVectors all over the place + if (show_orig_path) { + // add original path to helperpaths + SPCurve* curve = sp_shape_get_curve (SP_SHAPE(lpeitem)); + hp_vec.push_back(curve->get_pathvector()); + } - // TODO: factor this out (also the copied code above); see also lpe-lattice.cpp - SPCanvasItem *canvasitem = sp_nodepath_generate_helperpath(desktop, c, SP_ITEM(lpeitem), 0x009000ff); - Inkscape::Display::TemporaryItem* tmpitem = desktop->add_temporary_canvasitem (canvasitem, 0); - lpeitem->lpe_helperpaths.push_back(tmpitem); - } + // add other helperpaths provided by the effect itself + addCanvasIndicators(lpeitem, hp_vec); + + // add helperpaths provided by the effect's parameters + for (std::vector::iterator p = param_vector.begin(); p != param_vector.end(); ++p) { + (*p)->addCanvasIndicators(lpeitem, hp_vec); } - addHelperPathsImpl(lpeitem, desktop); + return hp_vec; } +/** + * Add possible canvas indicators (i.e., helperpaths other than the original path) to \a hp_vec + * This function should be overwritten by derived effects if they want to provide their own helperpaths. + */ void -Effect::addHelperPathsImpl(SPLPEItem */*lpeitem*/, SPDesktop */*desktop*/) +Effect::addCanvasIndicators(SPLPEItem *lpeitem, std::vector &hp_vec) { - // if this method is overloaded in derived classes, provides_own_flash_paths will be true - provides_own_flash_paths = false; } + /** * This *creates* a new widget, management of deletion should be done by the caller */ @@ -627,7 +634,8 @@ Effect::providesKnotholder() // otherwise: are there any PointParams? for (std::vector::iterator p = param_vector.begin(); p != param_vector.end(); ++p) { - if ( Inkscape::LivePathEffect::PointParam *pointparam = dynamic_cast(*p) ) { +// if ( Inkscape::LivePathEffect::PointParam *pointparam = dynamic_cast(*p) ) { + if (dynamic_cast(*p)) { return true; } } diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 2798f88ce..37170eae0 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -129,8 +129,8 @@ public: // (but spiro lpe still needs it!) virtual LPEPathFlashType pathFlashType() { return DEFAULT; } void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + std::vector getHelperPaths(SPLPEItem *lpeitem); - void addHelperPaths(SPLPEItem *lpeitem, SPDesktop *desktop); inline bool providesOwnFlashPaths() { return provides_own_flash_paths || show_orig_path; } @@ -167,7 +167,10 @@ protected: Parameter * getNextOncanvasEditableParam(); void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - virtual void addHelperPathsImpl(SPLPEItem *lpeitem, SPDesktop *desktop); + + //virtual std::vector getCanvasIndicators(SPLPEItem *lpeitem); + virtual void addCanvasIndicators(SPLPEItem *lpeitem, std::vector &hp_vec); + std::vector param_vector; std::vector > kh_entity_vector; diff --git a/src/live_effects/lpe-lattice.cpp b/src/live_effects/lpe-lattice.cpp index 8630c9cfa..74f032fd4 100644 --- a/src/live_effects/lpe-lattice.cpp +++ b/src/live_effects/lpe-lattice.cpp @@ -236,6 +236,7 @@ LPELattice::resetDefaults(SPItem * item) grid_point15[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min(); } +/** void LPELattice::addHelperPathsImpl(SPLPEItem *lpeitem, SPDesktop *desktop) { @@ -288,6 +289,7 @@ LPELattice::addHelperPathsImpl(SPLPEItem *lpeitem, SPDesktop *desktop) c->unref(); } +**/ /* ######################## */ diff --git a/src/live_effects/lpe-lattice.h b/src/live_effects/lpe-lattice.h index f22525b82..636b5e20b 100644 --- a/src/live_effects/lpe-lattice.h +++ b/src/live_effects/lpe-lattice.h @@ -40,7 +40,7 @@ public: virtual void resetDefaults(SPItem * item); protected: - virtual void addHelperPathsImpl(SPLPEItem *lpeitem, SPDesktop *desktop); + //virtual void addHelperPathsImpl(SPLPEItem *lpeitem, SPDesktop *desktop); private: diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 02d520fe4..8c24c50de 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -11,8 +11,10 @@ #include #include <2geom/forward.h> +#include <2geom/pathvector.h> class KnotHolder; +class SPLPEItem; struct SPDesktop; struct SPItem; @@ -57,7 +59,9 @@ public: virtual Glib::ustring * param_getTooltip() { return ¶m_tooltip; }; + // overload these for your particular parameter to make it provide knotholder handles or canvas helperpaths virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {} + virtual void addCanvasIndicators(SPLPEItem *lpeitem, std::vector &hp_vec) {}; virtual void param_editOncanvas(SPItem * /*item*/, SPDesktop * /*dt*/) {}; virtual void param_setup_nodepath(Inkscape::NodePath::Path */*np*/) {}; -- 2.30.2