diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2013-02-18 10:23:51 +0000 |
|---|---|---|
| committer | Jabiertxo Arraiza Zenotz <jtx@jtx.marker.es> | 2013-02-18 10:23:51 +0000 |
| commit | 4a0858ff965d54fc08f721fbbc2503f9ab3d9d3c (patch) | |
| tree | 7719939529093ed6ed64f4d3873bc28d6c18a1cf /src/ui/tool/path-manipulator.cpp | |
| parent | Merge from lp:~jabiertxof/inkscape/SpiroLive+BSpline@BPower for fix diverged (diff) | |
| download | inkscape-4a0858ff965d54fc08f721fbbc2503f9ab3d9d3c.tar.gz inkscape-4a0858ff965d54fc08f721fbbc2503f9ab3d9d3c.zip | |
refactor
(bzr r11950.1.35)
Diffstat (limited to 'src/ui/tool/path-manipulator.cpp')
| -rw-r--r-- | src/ui/tool/path-manipulator.cpp | 102 |
1 files changed, 82 insertions, 20 deletions
diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index f1b2e12be..b650987bc 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -1102,7 +1102,6 @@ void PathManipulator::_createControlPointsFromGeometry() Geom::Curve const &cseg = pit->back_closed(); bool fuse_ends = pit->closed() && Geom::are_near(cseg.initialPoint(), cseg.finalPoint()); - for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_open(); ++cit) { Geom::Point pos = cit->finalPoint(); Node *current_node; @@ -1169,6 +1168,75 @@ void PathManipulator::_createControlPointsFromGeometry() } } + +bool PathManipulator::isBSpline(){ + LivePathEffect::LPEBSpline *lpe_bsp = NULL; + if (SP_IS_LPE_ITEM(_path) && sp_lpe_item_has_path_effect(SP_LPE_ITEM(_path))) { + PathEffectList effect_list = sp_lpe_item_get_effect_list(SP_LPE_ITEM(_path)); + lpe_bsp = dynamic_cast<LivePathEffect::LPEBSpline*>( effect_list.front()->lpeobject->get_lpe()); + }else{ + lpe_bsp = NULL; + } + if(lpe_bsp){ + return true; + } + 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; + Node *n = h->parent(); + Geom::D2< Geom::SBasis > SBasisInsideNodes; + SPCurve *lineInsideNodes = new SPCurve(); + Node * nextNode = n->nodeToward(h); + if(nextNode){ + lineInsideNodes->moveto(n->position()); + lineInsideNodes->lineto(nextNode->position()); + SBasisInsideNodes = lineInsideNodes->first_segment()->toSBasis(); + nearestPointAt = Geom::nearest_point(n->front()->position(),*lineInsideNodes->first_segment()); + } + return SBasisInsideNodes.valueAt(nearestPointAt); +} + +Geom::Point PathManipulator::BSplineHandleRepositionFixed(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){ + lineInsideNodes->moveto(n->position()); + lineInsideNodes->lineto(nextNode->position()); + SBasisInsideNodes = lineInsideNodes->first_segment()->toSBasis(); + }else{ + return n->position(); + } + return SBasisInsideNodes.valueAt(pos); +} + /** Construct the geometric representation of nodes and handles, update the outline * and display * \param alert_LPE if true, first the LPE is warned what the new path is going to be before updating it @@ -1184,14 +1252,25 @@ void PathManipulator::_createGeometryFromControlPoints(bool alert_LPE) } NodeList::iterator prev = subpath->begin(); 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)); + } + //BSplie 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)); + + } if (!prev->front()->isDegenerate() || !subpath->begin()->back()->isDegenerate()) { build_segment(builder, prev.ptr(), subpath->begin().ptr()); } @@ -1200,6 +1279,7 @@ void PathManipulator::_createGeometryFromControlPoints(bool alert_LPE) } ++spi; } + builder.finish(); Geom::PathVector pathv = builder.peek() * (_edit_transform * _i2d_transform).inverse(); _spcurve->set_pathvector(pathv); @@ -1261,24 +1341,6 @@ void PathManipulator::_updateOutline() } Geom::PathVector pv = _spcurve->get_pathvector(); pv *= (_edit_transform * _i2d_transform); - //BSpline - if (SP_IS_LPE_ITEM(_path) && sp_lpe_item_has_path_effect(SP_LPE_ITEM(_path))) { - PathEffectList effect_list = sp_lpe_item_get_effect_list(SP_LPE_ITEM(_path)); - LivePathEffect::LPEBSpline *lpe_bsp = dynamic_cast<LivePathEffect::LPEBSpline*>( effect_list.front()->lpeobject->get_lpe()); - if (lpe_bsp) { - Geom::PathVector pv2; - for (Geom::PathVector::iterator i = pv.begin(); i != pv.end(); ++i) { - Geom::Path &path = *i; - for (Geom::Path::const_iterator j = path.begin(); j != path.end_default(); ++j) { - Geom::Path pv2j(j->pointAt(0)); - pv2j.appendNew<Geom::LineSegment>(j->pointAt(1)); - pv2.push_back(pv2j); - } - } - pv = pv2; - } - } - //BSpline End // This SPCurve thing has to be killed with extreme prejudice SPCurve *_hc = new SPCurve(); if (_show_path_direction) { |
