diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2013-02-19 11:08:14 +0000 |
|---|---|---|
| committer | Jabiertxo Arraiza Zenotz <jtx@jtx.marker.es> | 2013-02-19 11:08:14 +0000 |
| commit | dfe131791aef37e26fd0358c32222dacf813864c (patch) | |
| tree | e513052d3e756b099a379a89332148494295693d /src/ui | |
| parent | refactor (diff) | |
| download | inkscape-dfe131791aef37e26fd0358c32222dacf813864c.tar.gz inkscape-dfe131791aef37e26fd0358c32222dacf813864c.zip | |
Mayor refactor
(bzr r11950.1.36)
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/tool/node.cpp | 39 | ||||
| -rw-r--r-- | src/ui/tool/path-manipulator.cpp | 90 | ||||
| -rw-r--r-- | src/ui/tool/path-manipulator.h | 4 |
3 files changed, 82 insertions, 51 deletions
diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index dff8d3dd9..1a196c857 100644 --- a/src/ui/tool/node.cpp +++ b/src/ui/tool/node.cpp @@ -135,6 +135,15 @@ void Handle::move(Geom::Point const &new_pos) Node *node_away = _parent->nodeAwayFrom(this); // node in the opposite direction Handle *towards = node_towards ? node_towards->handleAwayFrom(_parent) : NULL; Handle *towards_second = node_towards ? node_towards->handleToward(_parent) : NULL; + //BSpline + bool isBSpline = false; + double pos = 0; + Handle *h = NULL; + Handle *h2 = NULL; + if(_pm().isBSpline()){ + isBSpline = true; + //BSpline End + } if (Geom::are_near(new_pos, _parent->position())) { // The handle becomes degenerate. @@ -165,6 +174,15 @@ void Handle::move(Geom::Point const &new_pos) other->setDirection(*node_towards, *_parent); } } + //BSpline + if(isBSpline){ + h = this; + setPosition(_pm().BSplineHandleReposition(h)); + pos = _pm().BSplineHandlePosition(h); + h2 = this->other(); + this->other()->setPosition(_pm().BSplineHandleReposition(h2,pos)); + } + //BSpline End setPosition(new_pos); return; } @@ -195,12 +213,15 @@ void Handle::move(Geom::Point const &new_pos) break; default: break; } + setPosition(new_pos); //BSpline - if(_pm().isBSpline()){ - Handle *h = this; + if(isBSpline){ + h = this; setPosition(_pm().BSplineHandleReposition(h)); - }else - setPosition(new_pos); + pos = _pm().BSplineHandlePosition(h); + h2 = this->other(); + this->other()->setPosition(_pm().BSplineHandleReposition(h2,pos)); + } //BSpline End } @@ -555,10 +576,12 @@ void Node::move(Geom::Point const &new_pos) Geom::Point old_pos = position(); Geom::Point delta = new_pos - position(); //BSpline - float pos = 0; + double pos = 0; if(_pm().isBSpline()){ Node *n = this; - pos = _pm().BSplineMaxPosition(n); + pos = _pm().BSplineHandlePosition(n->front()); + if(pos == 0) + pos = _pm().BSplineHandlePosition(n->back()); } //BSpline End setPosition(new_pos); @@ -568,8 +591,8 @@ void Node::move(Geom::Point const &new_pos) if(_pm().isBSpline()){ Handle* front = &_front; Handle* back = &_back; - _front.setPosition(_pm().BSplineHandleRepositionFixed(front,pos)); - _back.setPosition(_pm().BSplineHandleRepositionFixed(back,pos)); + _front.setPosition(_pm().BSplineHandleReposition(front,pos)); + _back.setPosition(_pm().BSplineHandleReposition(back,pos)); } //BSpline End // if the node has a smooth handle after a line segment, it should be kept colinear diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index b650987bc..c4158931a 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -1182,31 +1182,8 @@ bool PathManipulator::isBSpline(){ } return false; } -double PathManipulator::BSplineMaxPosition(Node *n){ - double nearestPointAt = 0; - Geom::D2< Geom::SBasis > SBasisInsideNodes; - SPCurve *lineInsideNodes = new SPCurve(); - Node * frontNode = n->nodeToward(n->front()); - if(frontNode){ - lineInsideNodes->moveto(n->position()); - lineInsideNodes->lineto(frontNode->position()); - SBasisInsideNodes = lineInsideNodes->first_segment()->toSBasis(); - nearestPointAt = Geom::nearest_point(n->front()->position(),*lineInsideNodes->first_segment()); - } - Node * backNode = n->nodeToward(n->back()); - if(backNode){ - lineInsideNodes->reset(); - lineInsideNodes->moveto(n->position()); - lineInsideNodes->lineto(backNode->position()); - SBasisInsideNodes = lineInsideNodes->first_segment()->toSBasis(); - using std::max; - nearestPointAt = max(nearestPointAt,1-Geom::nearest_point(n->back()->position(),*lineInsideNodes->first_segment())); - } - return nearestPointAt; -} - -Geom::Point PathManipulator::BSplineHandleReposition(Handle *h){ - double nearestPointAt = 0; +double PathManipulator::BSplineHandlePosition(Handle *h){ + double pos = 0; Node *n = h->parent(); Geom::D2< Geom::SBasis > SBasisInsideNodes; SPCurve *lineInsideNodes = new SPCurve(); @@ -1215,19 +1192,23 @@ Geom::Point PathManipulator::BSplineHandleReposition(Handle *h){ lineInsideNodes->moveto(n->position()); lineInsideNodes->lineto(nextNode->position()); SBasisInsideNodes = lineInsideNodes->first_segment()->toSBasis(); - nearestPointAt = Geom::nearest_point(n->front()->position(),*lineInsideNodes->first_segment()); + pos = Geom::nearest_point(h->position(),*lineInsideNodes->first_segment()); } - return SBasisInsideNodes.valueAt(nearestPointAt); + return pos; } -Geom::Point PathManipulator::BSplineHandleRepositionFixed(Handle *h,double pos){ +Geom::Point PathManipulator::BSplineHandleReposition(Handle *h){ + double pos = 0; + pos = this->BSplineHandlePosition(h); + return BSplineHandleReposition(h,pos); +} + +Geom::Point PathManipulator::BSplineHandleReposition(Handle *h,double pos){ Node *n = h->parent(); - if(n->back()->position() == h->position()) - pos = 1-pos; Geom::D2< Geom::SBasis > SBasisInsideNodes; SPCurve *lineInsideNodes = new SPCurve(); Node * nextNode = n->nodeToward(h); - if(nextNode){ + if(nextNode && pos != 0){ lineInsideNodes->moveto(n->position()); lineInsideNodes->lineto(nextNode->position()); SBasisInsideNodes = lineInsideNodes->first_segment()->toSBasis(); @@ -1251,26 +1232,53 @@ void PathManipulator::_createGeometryFromControlPoints(bool alert_LPE) continue; } NodeList::iterator prev = subpath->begin(); + //BSpline + float pos = NULL; + bool isBSpline = false; + if(this->isBSpline()) + isBSpline = true; + if(isBSpline){ + pos = BSplineHandlePosition(prev.ptr()->front()); + prev.ptr()->front()->setPosition(BSplineHandleReposition(prev.ptr()->front(),pos)); + if(pos == 0){ + prev.ptr()->setPosition(BSplineHandleReposition(i.ptr()->front(),pos)); + } + } + //BSpline End builder.moveTo(prev->position()); for (NodeList::iterator i = ++subpath->begin(); i != subpath->end(); ++i) { - if (this->isBSpline()) { - float pos = BSplineMaxPosition(i.ptr()); - i.ptr()->front()->setPosition(BSplineHandleRepositionFixed(i.ptr()->front(),pos)); - i.ptr()->back()->setPosition(BSplineHandleRepositionFixed(i.ptr()->back(),pos)); + //BSpline + if (isBSpline) { + pos = BSplineHandlePosition(i.ptr()->front()); + if(pos == 0) + pos = BSplineHandlePosition(i.ptr()->back()); + i.ptr()->front()->setPosition(BSplineHandleReposition(i.ptr()->front(),pos)); + i.ptr()->back()->setPosition(BSplineHandleReposition(i.ptr()->back(),pos)); + if(pos == 0){ + i.ptr()->setPosition(BSplineHandleReposition(i.ptr()->front(),pos)); + } } - //BSplie End + + //BSpline End build_segment(builder, prev.ptr(), i.ptr()); prev = i; } if (subpath->closed()) { // Here we link the last and first node if the path is closed. // If the last segment is Bezier, we add it. - if (this->isBSpline()) { - float pos = BSplineMaxPosition(prev.ptr()); - subpath->begin().ptr()->front()->setPosition(BSplineHandleRepositionFixed(subpath->begin().ptr()->front(),pos)); - prev.ptr()->back()->setPosition(BSplineHandleRepositionFixed(prev.ptr()->back(),pos)); - + //BSpline + if (isBSpline) { + pos = BSplineHandlePosition(prev.ptr()->front()); + if(pos == 0) + pos = BSplineHandlePosition(subpath->begin().ptr()->back()); + subpath->begin().ptr()->front()->setPosition(BSplineHandleReposition(subpath->begin().ptr()->front(),pos)); + prev.ptr()->back()->setPosition(BSplineHandleReposition(prev.ptr()->back(),pos)); + if(pos == 0){ + subpath->begin().ptr()->setPosition(BSplineHandleReposition(subpath->begin().ptr()->front(),pos)); + prev.ptr()->setPosition(BSplineHandleReposition(prev.ptr()->back(),pos)); + } } + //BSpline End if (!prev->front()->isDegenerate() || !subpath->begin()->back()->isDegenerate()) { build_segment(builder, prev.ptr(), subpath->begin().ptr()); } diff --git a/src/ui/tool/path-manipulator.h b/src/ui/tool/path-manipulator.h index 72d84a241..55958530d 100644 --- a/src/ui/tool/path-manipulator.h +++ b/src/ui/tool/path-manipulator.h @@ -106,9 +106,9 @@ private: void _createControlPointsFromGeometry(); //BSpline bool isBSpline(); - double BSplineMaxPosition(Node *n); + double BSplineHandlePosition(Handle *h); Geom::Point BSplineHandleReposition(Handle *h); - Geom::Point BSplineHandleRepositionFixed(Handle *h,double pos); + Geom::Point BSplineHandleReposition(Handle *h,double pos); //BSpline End void _createGeometryFromControlPoints(bool alert_LPE = false); unsigned _deleteStretch(NodeList::iterator first, NodeList::iterator last, bool keep_shape); |
