diff options
| author | jtx <javier.arraiza@marker.es> | 2013-03-20 15:15:12 +0000 |
|---|---|---|
| committer | jtx <javier.arraiza@marker.es> | 2013-03-20 15:15:12 +0000 |
| commit | 6bdbe4b651d2a643d751803572df3e8f247a8707 (patch) | |
| tree | b04d653761d70bc92858723b3f2ecc0e8010c077 /src | |
| parent | Fixing regression (diff) | |
| parent | For testing, widget added, regression fixed (diff) | |
| download | inkscape-6bdbe4b651d2a643d751803572df3e8f247a8707.tar.gz inkscape-6bdbe4b651d2a643d751803572df3e8f247a8707.zip | |
Fixing node creations in BSpline mode.
(bzr r11950.4.1)
Diffstat (limited to 'src')
| -rw-r--r-- | src/live_effects/lpe-bspline.cpp | 35 | ||||
| -rw-r--r-- | src/live_effects/lpe-bspline.h | 18 | ||||
| -rw-r--r-- | src/pen-context.cpp | 2 | ||||
| -rw-r--r-- | src/ui/tool/curve-drag-point.cpp | 4 | ||||
| -rw-r--r-- | src/ui/tool/multi-path-manipulator.h | 2 | ||||
| -rw-r--r-- | src/ui/tool/node.cpp | 18 | ||||
| -rw-r--r-- | src/ui/tool/path-manipulator.cpp | 39 | ||||
| -rw-r--r-- | src/ui/tool/path-manipulator.h | 6 |
8 files changed, 62 insertions, 62 deletions
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 <glibmm/i18n.h> #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<Parameter *>(&ignoreCusp) ); registerParameter( dynamic_cast<Parameter *>(&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 <defs> 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/curve-drag-point.cpp b/src/ui/tool/curve-drag-point.cpp index 40dcb5058..fce19f9ad 100644 --- a/src/ui/tool/curve-drag-point.cpp +++ b/src/ui/tool/curve-drag-point.cpp @@ -54,7 +54,7 @@ bool CurveDragPoint::grabbed(GdkEventMotion */*event*/) // delta is a vector equal 1/3 of distance from first to second Geom::Point delta = (second->position() - first->position()) / 3.0; //BSpline - if(!_pm.isBSpline()){ + if(!_pm.isBSpline){ first->front()->move(first->front()->position() + delta); second->back()->move(second->back()->position() - delta); } @@ -91,7 +91,7 @@ void CurveDragPoint::dragged(Geom::Point &new_pos, GdkEventMotion *event) Geom::Point offset0 = ((1-weight)/(3*t*(1-t)*(1-t))) * delta; Geom::Point offset1 = (weight/(3*t*t*(1-t))) * delta; //BSpline - if(!_pm.isBSpline()){ + if(!_pm.isBSpline){ first->front()->move(first->front()->position() + offset0); second->back()->move(second->back()->position() + offset1); }else if(weight>=0.8)second->back()->move(new_pos); diff --git a/src/ui/tool/multi-path-manipulator.h b/src/ui/tool/multi-path-manipulator.h index 54a9b5753..01033b3e5 100644 --- a/src/ui/tool/multi-path-manipulator.h +++ b/src/ui/tool/multi-path-manipulator.h @@ -71,7 +71,7 @@ public: void setLiveObjects(bool set); void updateOutlineColors(); void updateHandles(); - + sigc::signal<void> signal_coords_changed; /// Emitted whenever the coordinates /// shown in the status bar need updating private: diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index a1fa4e55b..e0aec8bb5 100644 --- a/src/ui/tool/node.cpp +++ b/src/ui/tool/node.cpp @@ -143,7 +143,7 @@ void Handle::move(Geom::Point const &new_pos) double pos = 0; Handle *h = NULL; Handle *h2 = NULL; - if(_pm().isBSpline()){ + if(_pm().isBSpline){ isBSpline = true; typedef ControlPointSelection::Set Set; Set &nodes = _parent->_selection.allPoints(); @@ -324,7 +324,7 @@ bool Handle::_eventHandler(SPEventContext *event_context, GdkEvent *event) //BSpline void Handle::handle_2button_press(){ - if(_pm().isBSpline()){ + if(_pm().isBSpline){ Handle *h = NULL; Handle *h2 = NULL; double pos = 0; @@ -386,19 +386,19 @@ void Handle::dragged(Geom::Point &new_pos, GdkEventMotion *event) } new_pos = result; //BSpline - if(_pm().isBSpline()){ + if(_pm().isBSpline){ Handle *h = NULL; double pos = 0; h = this; setPosition(new_pos); - pos = ceilf(_pm().BSplineHandlePosition(h)*_pm().getControlBsplineSteps())/_pm().getControlBsplineSteps(); + pos = ceilf(_pm().BSplineHandlePosition(h)*_pm().controlBSplineSteps)/_pm().controlBSplineSteps; new_pos=_pm().BSplineHandleReposition(h,pos); } //BSpline End } std::vector<Inkscape::SnapCandidatePoint> unselected; - if (snap && ( (!held_control(*event) && _pm().isBSpline()) || !_pm().isBSpline())) { + if (snap && ( (!held_control(*event) && _pm().isBSpline) || !_pm().isBSpline)) { ControlPointSelection::Set &nodes = _parent->_selection.allPoints(); for (ControlPointSelection::Set::iterator i = nodes.begin(); i != nodes.end(); ++i) { Node *n = static_cast<Node*>(*i); @@ -625,7 +625,7 @@ void Node::move(Geom::Point const &new_pos) Node *n = this; Node * nextNode = n->nodeToward(n->front()); Node * prevNode = n->nodeToward(n->back()); - if(_pm().isBSpline()){ + if(_pm().isBSpline){ if(prevNode) prevPos = _pm().BSplineHandlePosition(prevNode->front()); pos = _pm().BSplineHandlePosition(n->front()); @@ -637,7 +637,7 @@ void Node::move(Geom::Point const &new_pos) //BSpline End setPosition(new_pos); //BSpline - if(_pm().isBSpline()){ + if(_pm().isBSpline){ if(prevNode) prevNode->front()->setPosition(_pm().BSplineHandleReposition(prevNode->front(),prevPos)); if(nextNode) @@ -651,7 +651,7 @@ void Node::move(Geom::Point const &new_pos) // with the segment _fixNeighbors(old_pos, new_pos); //BSpline - if(_pm().isBSpline()){ + if(_pm().isBSpline){ Handle* front = &_front; Handle* back = &_back; _front.setPosition(_pm().BSplineHandleReposition(front,pos)); @@ -774,7 +774,7 @@ void Node::setType(NodeType type, bool update_handles) } //BSpline - if(_pm().isBSpline()){ + if(_pm().isBSpline){ if (isEndNode()) return; Handle* front = &_front; Handle* back = &_back; diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index 853d9336a..e789d5447 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -149,6 +149,19 @@ PathManipulator::PathManipulator(MultiPathManipulator &mpm, SPPath *path, sigc::hide( sigc::mem_fun(*this, &PathManipulator::_updateOutlineOnZoomChange))); _createControlPointsFromGeometry(); + + LivePathEffect::LPEBSpline *lpe_bsp = NULL; + if (SP_LPE_ITEM(_path) && sp_lpe_item_has_path_effect(SP_LPE_ITEM(_path))){ + 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<LivePathEffect::LPEBSpline*>(thisEffect->getLPEObj()->get_lpe()); + } + } + isBSpline = false; + if(lpe_bsp){ + isBSpline = true; + controlBSplineSteps = lpe_bsp->steps+1; + } } PathManipulator::~PathManipulator() @@ -897,7 +910,7 @@ void PathManipulator::showHandles(bool show) void PathManipulator::showOutline(bool show) { //BSpline - if(isBSpline()) show = true; + if(isBSpline) show = true; //BSpline if (show == _show_outline) return; _show_outline = show; @@ -1172,30 +1185,6 @@ 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<LivePathEffect::LPEBSpline*>(sp_lpe_item_has_path_effect_of_type(SP_LPE_ITEM(_path),Inkscape::LivePathEffect::BSPLINE)->getLPEObj()->get_lpe()); - }else{ - lpe_bsp = NULL; - } - if(lpe_bsp){ - return true; - } - return false; -} - -int PathManipulator::getControlBsplineSteps(){ - LivePathEffect::LPEBSpline *lpe_bsp = NULL; - if (SP_LPE_ITEM(_path) && sp_lpe_item_has_path_effect(SP_LPE_ITEM(_path))){ - lpe_bsp = dynamic_cast<LivePathEffect::LPEBSpline*>(sp_lpe_item_has_path_effect_of_type(SP_LPE_ITEM(_path),Inkscape::LivePathEffect::BSPLINE)->getLPEObj()->get_lpe()); - if(lpe_bsp){ - return lpe_bsp->steps+1; - } - } - return 2; -} double PathManipulator::BSplineHandlePosition(Handle *h){ using Geom::X; using Geom::Y; diff --git a/src/ui/tool/path-manipulator.h b/src/ui/tool/path-manipulator.h index 79db1a1c1..c9030b7bd 100644 --- a/src/ui/tool/path-manipulator.h +++ b/src/ui/tool/path-manipulator.h @@ -89,9 +89,6 @@ public: void updateHandles(); void setControlsTransform(Geom::Affine const &); void hideDragPoint(); - //BSpline - int getControlBsplineSteps(); - //BSpline End MultiPathManipulator &mpm() { return _multi_path_manipulator; } NodeList::iterator subdivideSegment(NodeList::iterator after, double t); @@ -108,7 +105,8 @@ private: void _createControlPointsFromGeometry(); //BSpline - bool isBSpline(); + int controlBSplineSteps; + bool isBSpline; double BSplineHandlePosition(Handle *h); Geom::Point BSplineHandleReposition(Handle *h); Geom::Point BSplineHandleReposition(Handle *h,double pos); |
