From b887e821e03cae71b2116d58e64efb62eb9be0be Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 20 Mar 2013 01:47:49 +0100 Subject: For testing, widget added, regression fixed (bzr r11950.1.62) --- src/live_effects/lpe-bspline.cpp | 35 ++++++++++++++++++++++++----------- src/live_effects/lpe-bspline.h | 18 +++++++++--------- src/pen-context.cpp | 2 +- src/ui/tool/path-manipulator.cpp | 7 ++++++- 4 files changed, 40 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index e6461e94c..d3c64bb67 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -11,6 +11,7 @@ #include #include "sp-path.h" #include "style.h" +#include "document-private.h" #include "document.h" #include "document-undo.h" #include "desktop-handles.h" @@ -45,9 +46,9 @@ LPEBSpline::LPEBSpline(LivePathEffectObject *lpeobject) : Effect(lpeobject), // initialise your parameters here: //testpointA(_("Test Point A"), _("Test A"), "ptA", &wr, this, Geom::Point(100,100)), + steps(_("Steps whith CTRL:"), _("Change number of steps whith CTRL pressed"), "steps", &wr, this, 2), ignoreCusp(_("Ignore cusp nodes:"), _("Change ignoring cusp nodes"), "ignoreCusp", &wr, this, true), - weight(_("Change weight:"), _("Change weight of the effect"), "weight", &wr, this, 33.33), - steps(_("Steps whith CTRL:"), _("Change number of steps whith CTRL pressed"), "steps", &wr, this, 2) + weight(_("Change weight:"), _("Change weight of the effect"), "weight", &wr, this, 33.33) { registerParameter( dynamic_cast(&ignoreCusp) ); registerParameter( dynamic_cast(&weight) ); @@ -64,11 +65,24 @@ LPEBSpline::~LPEBSpline() { } -void -LPEBSpline::doOnApply(SPLPEItem const* lpeitem) +void +LPEBSpline::createAndApply(const char* name, SPDocument *doc, SPItem *item) { - if (!SP_IS_SHAPE(lpeitem)) { + if (!SP_IS_SHAPE(item)) { g_warning("LPE BSpline can only be applied to shapes (not groups)."); + }else{ + // Path effect definition + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + Inkscape::XML::Node *repr = xml_doc->createElement("inkscape:path-effect"); + repr->setAttribute("effect", name); + + doc->getDefs()->getRepr()->addChild(repr, NULL); // adds to and assigns the 'id' attribute + const gchar * repr_id = repr->attribute("id"); + Inkscape::GC::release(repr); + + gchar *href = g_strdup_printf("#%s", repr_id); + sp_lpe_item_add_path_effect(SP_LPE_ITEM(item), href, true); + g_free(href); } } @@ -289,16 +303,15 @@ LPEBSpline::newWidget() void LPEBSpline::toDefaultWeight(){ -double weightValue = 0.3333; -changeWeight(weightValue); -weight.param_set_value(33.33); -gtk_widget_draw(GTK_WIDGET(LPEBSpline::newWidget()), NULL); + double weightValue = 0.3334; + weight.param_set_value(33.33); + changeWeight(weightValue); } void LPEBSpline::toWeight(){ -double weightValue = weight/100; -changeWeight(weightValue); + double weightValue = weight/100; + changeWeight(weightValue); } void diff --git a/src/live_effects/lpe-bspline.h b/src/live_effects/lpe-bspline.h index 10d157ac1..44c3f451c 100644 --- a/src/live_effects/lpe-bspline.h +++ b/src/live_effects/lpe-bspline.h @@ -15,20 +15,13 @@ namespace LivePathEffect { class LPEBSpline : public Effect { -private: - BoolParam ignoreCusp; - ScalarParam weight; - - LPEBSpline(const LPEBSpline&); - LPEBSpline& operator=(const LPEBSpline&); - public: LPEBSpline(LivePathEffectObject *lpeobject); virtual ~LPEBSpline(); - virtual LPEPathFlashType pathFlashType() const { return SUPPRESS_FLASH; } + virtual void createAndApply(const char* name, SPDocument *doc, SPItem *item); - virtual void doOnApply(SPLPEItem const* lpeitem); + virtual LPEPathFlashType pathFlashType() const { return SUPPRESS_FLASH; } virtual void doEffect(SPCurve * curve); @@ -44,6 +37,13 @@ public: ScalarParam steps; +private: + BoolParam ignoreCusp; + ScalarParam weight; + + LPEBSpline(const LPEBSpline&); + LPEBSpline& operator=(const LPEBSpline&); + }; }; //namespace LivePathEffect diff --git a/src/pen-context.cpp b/src/pen-context.cpp index b43c2ff19..6f61ceb99 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -1791,7 +1791,7 @@ static void bspline_spiro_build(SPPenContext *const pc) //We create the base curve SPCurve *curve = new SPCurve(); //If we continuate the existing curve we add it at the start - if(pc->sa && !pc->sa->curve->is_empty() &&1>2){ + if(pc->sa && !pc->sa->curve->is_empty()){ curve = pc->sa->curve->copy(); if (pc->sa->start) { curve = curve->create_reverse(); diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index 853d9336a..c3ab19a4e 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -1176,7 +1176,12 @@ void PathManipulator::_createControlPointsFromGeometry() bool PathManipulator::isBSpline(){ LivePathEffect::LPEBSpline *lpe_bsp = NULL; if (SP_LPE_ITEM(_path) && sp_lpe_item_has_path_effect(SP_LPE_ITEM(_path))){ - lpe_bsp = dynamic_cast(sp_lpe_item_has_path_effect_of_type(SP_LPE_ITEM(_path),Inkscape::LivePathEffect::BSPLINE)->getLPEObj()->get_lpe()); + Inkscape::LivePathEffect::Effect* thisEffect = sp_lpe_item_has_path_effect_of_type(SP_LPE_ITEM(_path),Inkscape::LivePathEffect::BSPLINE); + if(thisEffect){ + lpe_bsp = dynamic_cast(thisEffect->getLPEObj()->get_lpe()); + }else{ + lpe_bsp = NULL; + } }else{ lpe_bsp = NULL; } -- cgit v1.2.3