From 42e99769805c14a5cc01c805faa3c3b03f9dd1c0 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Tue, 30 Oct 2007 22:37:20 +0000 Subject: [PATCH] LPE: implement NEW path-along-path effect, i think that old one has become obsolete and is renamed accordingly. implement straight path node editting for gears effect. --- src/live_effects/effect.cpp | 18 +++++++++++++++++- src/live_effects/effect.h | 18 +++++++++++------- src/live_effects/lpe-gears.cpp | 2 ++ src/live_effects/parameter/path.cpp | 9 +++++++++ src/live_effects/parameter/path.h | 2 ++ src/nodepath.cpp | 15 +++++++++++++-- src/shape-editor.cpp | 2 +- src/ui/dialog/livepatheffect-editor.cpp | 8 +++++++- 8 files changed, 62 insertions(+), 12 deletions(-) diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 3802066ec..859bf8230 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -29,6 +29,7 @@ // include effects: #include "live_effects/lpe-skeletalstrokes.h" +#include "live_effects/lpe-pathalongpath.h" #include "live_effects/lpe-slant.h" #include "live_effects/lpe-test-doEffect-stack.h" #include "live_effects/lpe-gears.h" @@ -40,7 +41,8 @@ namespace LivePathEffect { const Util::EnumData LPETypeData[INVALID_LPE] = { // {constant defined in effect.h, N_("name of your effect"), "name of your effect in SVG"} - {SKELETAL_STROKES, N_("Path along path"), "skeletal"}, + {PATH_ALONG_PATH, N_("Path along path"), "path_along_path"}, + {SKELETAL_STROKES, N_("[obsolete?] Pattern along path"), "skeletal"}, #ifdef LPE_ENABLE_TEST_EFFECTS {SLANT, N_("Slant"), "slant"}, {DOEFFECTSTACK_TEST, N_("doEffect stack test"), "doeffectstacktest"}, @@ -58,6 +60,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) case SKELETAL_STROKES: neweffect = (Effect*) new LPESkeletalStrokes(lpeobj); break; + case PATH_ALONG_PATH: + neweffect = (Effect*) new LPEPathAlongPath(lpeobj); + break; #ifdef LPE_ENABLE_TEST_EFFECTS case SLANT: neweffect = (Effect*) new LPESlant(lpeobj); @@ -91,6 +96,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) tooltips = NULL; lpeobj = lpeobject; oncanvasedit_it = param_map.begin(); + straight_original_path = false; } Effect::~Effect() @@ -303,6 +309,16 @@ Effect::editNextParamOncanvas(SPItem * item, SPDesktop * desktop) } } +/* This function should reset the defaults and is used for example to initialize an effect right after it has been applied to a path +* The nice thing about this is that this function can use knowledge of the original path and set things accordingly for example to the size or origin of the original path! +*/ +void +Effect::resetDefaults(SPItem * /*item*/) +{ + // do nothing for simple effects +} + + } /* namespace LivePathEffect */ } /* namespace Inkscape */ diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 844a158b5..07dd72e47 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -42,7 +42,8 @@ namespace XML { namespace LivePathEffect { enum EffectType { - SKELETAL_STROKES = 0, + PATH_ALONG_PATH = 0, + SKELETAL_STROKES, #ifdef LPE_ENABLE_TEST_EFFECTS SLANT, DOEFFECTSTACK_TEST, @@ -59,18 +60,19 @@ class Parameter; class Effect { public: - virtual ~Effect(); + static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj); - Glib::ustring getName(); + virtual ~Effect(); virtual void doEffect (SPCurve * curve); - static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj); - virtual Gtk::Widget * getWidget(); - Inkscape::XML::Node * getRepr(); - SPDocument * getSPDoc(); + virtual void resetDefaults(SPItem * item); + + Glib::ustring getName(); + Inkscape::XML::Node * getRepr(); + SPDocument * getSPDoc(); LivePathEffectObject * getLPEObj() {return lpeobj;}; void readallParameters(Inkscape::XML::Node * repr); @@ -78,6 +80,8 @@ public: void editNextParamOncanvas(SPItem * item, SPDesktop * desktop); + bool straight_original_path; + protected: Effect(LivePathEffectObject *lpeobject); diff --git a/src/live_effects/lpe-gears.cpp b/src/live_effects/lpe-gears.cpp index 2176f3ba7..30500e3ab 100644 --- a/src/live_effects/lpe-gears.cpp +++ b/src/live_effects/lpe-gears.cpp @@ -212,6 +212,8 @@ LPEGears::LPEGears(LivePathEffectObject *lpeobject) : { registerParameter( dynamic_cast(&teeth) ); registerParameter( dynamic_cast(&phi) ); + + straight_original_path = true; } LPEGears::~LPEGears() diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index 2b558d2dd..68f7be4a9 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -147,6 +147,15 @@ PathParam::param_write_to_repr(const char * svgd) } +void +PathParam::param_set_and_write_new_value (Geom::Piecewise > newpath) +{ + const std::vector temppath = Geom::path_from_piecewise(newpath, LPE_CONVERSION_TOLERANCE); + gchar * svgd = SVGD_from_2GeomPath( temppath ); + param_write_to_repr(svgd); + g_free(svgd); +} + /* CALLBACK FUNCTIONS FOR THE BUTTONS */ void PathParam::on_edit_button_click() diff --git a/src/live_effects/parameter/path.h b/src/live_effects/parameter/path.h index 6ba6e7e4b..23f168c48 100644 --- a/src/live_effects/parameter/path.h +++ b/src/live_effects/parameter/path.h @@ -44,6 +44,8 @@ public: void param_set_default(); + void param_set_and_write_new_value (Geom::Piecewise > newpath); + void param_editOncanvas(SPItem * item, SPDesktop * dt); sigc::signal signal_path_pasted; diff --git a/src/nodepath.cpp b/src/nodepath.cpp index fa80f3baa..02b91eab0 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -224,6 +224,12 @@ Inkscape::NodePath::Path *sp_nodepath_new(SPDesktop *desktop, SPObject *object, if ( SP_SHAPE(np->object)->path_effect_href ) { np->repr_key = g_strdup("inkscape:original-d"); np->show_helperpath = true; + LivePathEffectObject *lpeobj = sp_shape_get_livepatheffectobject(SP_SHAPE(np->object)); + // ENHANCE THIS. Probably it is much nicer to have a virtual method in Effect class that modifies nodepath to its likings. + // so something like: "lpe->adjust_nodepath(np);" + if (lpeobj && lpeobj->lpe) { + np->straight_path = lpeobj->lpe->straight_original_path; + } } else { np->repr_key = g_strdup("d"); } @@ -2372,6 +2378,8 @@ sp_node_selected_set_type(Inkscape::NodePath::Path *nodepath, Inkscape::NodePath { if (nodepath == NULL) return; + if (nodepath->straight_path) return; // don't change type when it is a straight path! + for (GList *l = nodepath->selected; l != NULL; l = l->next) { sp_nodepath_convert_node_type((Inkscape::NodePath::Node *) l->data, type); } @@ -3184,8 +3192,10 @@ node_request(SPKnot *knot, NR::Point *p, guint state, gpointer data) Inkscape::NodePath::Node *n = (Inkscape::NodePath::Node *) data; // If either (Shift and some handle retracted), or (we're already dragging out a handle) - if (((state & GDK_SHIFT_MASK) && ((n->n.other && n->n.pos == n->pos) || (n->p.other && n->p.pos == n->pos))) || n->dragging_out) { - + if ( (!n->subpath->nodepath->straight_path) && + ( ((state & GDK_SHIFT_MASK) && ((n->n.other && n->n.pos == n->pos) || (n->p.other && n->p.pos == n->pos))) + || n->dragging_out ) ) + { NR::Point mouse = (*p); if (!n->dragging_out) { @@ -4471,6 +4481,7 @@ void sp_nodepath_show_helperpath(Inkscape::NodePath::Path *np, bool show) { np->show_helperpath = show; } +/* this function does not work yet */ void sp_nodepath_make_straight_path(Inkscape::NodePath::Path *np) { np->straight_path = true; np->show_handles = false; diff --git a/src/shape-editor.cpp b/src/shape-editor.cpp index 55f3183e5..508d2228d 100644 --- a/src/shape-editor.cpp +++ b/src/shape-editor.cpp @@ -476,7 +476,7 @@ void ShapeEditor::select_prev () { } void ShapeEditor::show_handles (bool show) { - if (this->nodepath) + if (this->nodepath && !this->nodepath->straight_path) sp_nodepath_show_handles (this->nodepath, show); } diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index ec6c5c6ee..b60d7e357 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -108,7 +108,8 @@ LivePathEffectEditor::LivePathEffectEditor(Behavior::BehaviorFactory behavior_fa setDesktop(SP_ACTIVE_DESKTOP); show_all_children(); - button_remove.hide(); + + button_remove.hide(); } LivePathEffectEditor::~LivePathEffectEditor() @@ -267,6 +268,11 @@ LivePathEffectEditor::onApply() } } + LivePathEffectObject *lpeobj = sp_shape_get_livepatheffectobject(SP_SHAPE(item)); + if (lpeobj && lpeobj->lpe) { + lpeobj->lpe->resetDefaults(item); + } + sp_document_done(doc, SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Create and apply path effect")); } -- 2.30.2