From 6bd801d36336b5b27e9c070e2f1ff1ca4363a8cf Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Tue, 10 Jan 2017 23:13:50 +0100 Subject: [PATCH] Sketcher: expose Bspline pole internal geometry --- src/Mod/Sketcher/App/SketchObject.cpp | 80 +++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 6d45e60c4..2c7af4f3e 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -3300,6 +3300,86 @@ int SketchObject::ExposeInternalGeometry(int GeoId) return incrgeo; //number of added elements } + else if(geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { + + const Part::GeomBSplineCurve *bsp = static_cast(geo); + // First we search what has to be restored + std::vector controlpoints(bsp->countPoles()); + std::vector controlpointgeoids(bsp->countPoles()); + + std::vector::iterator itb; + std::vector::iterator it; + + for(it=controlpointgeoids.begin(), itb=controlpoints.begin(); it!=controlpointgeoids.end() && itb!=controlpoints.end(); ++it, ++itb) { + (*it)=-1; + (*itb)=false; + } + + const std::vector< Sketcher::Constraint * > &vals = Constraints.getValues(); + + for (std::vector< Sketcher::Constraint * >::const_iterator it= vals.begin(); + it != vals.end(); ++it) { + if((*it)->Type == Sketcher::InternalAlignment && (*it)->Second == GeoId) + { + switch((*it)->AlignmentType){ + case Sketcher::BSplineControlPoint: + controlpoints[(*it)->Third] = true; + controlpointgeoids[(*it)->Third] = (*it)->First; + break; + default: + return -1; + } + } + } + + int currentgeoid = getHighestCurveIndex(); + int incrgeo = 0; + + std::vector igeo; + std::vector icon; + + std::vector poles = bsp->getPoles(); + + int index=0; + + for(it=controlpointgeoids.begin(), itb=controlpoints.begin(); it!=controlpointgeoids.end() && itb!=controlpoints.end(); ++it, ++itb, index++) { + + if(!(*itb)) // if controlpoint not existing + { + Part::GeomCircle *pc = new Part::GeomCircle(); + pc->setCenter(poles[index]); + + igeo.push_back(pc); + + Sketcher::Constraint *newConstr = new Sketcher::Constraint(); + newConstr->Type = Sketcher::InternalAlignment; + newConstr->AlignmentType = Sketcher::BSplineControlPoint; + newConstr->First = currentgeoid+incrgeo+1; + newConstr->FirstPos = Sketcher::mid; + newConstr->Second = GeoId; + newConstr->Third = index; + + icon.push_back(newConstr); + incrgeo++; + } + } + + this->addGeometry(igeo,true); + this->addConstraints(icon); + + for (std::vector::iterator it=igeo.begin(); it != igeo.end(); ++it) + if (*it) + delete *it; + + for (std::vector::iterator it=icon.begin(); it != icon.end(); ++it) + if (*it) + delete *it; + + icon.clear(); + igeo.clear(); + + return incrgeo; //number of added elements + } else return -1; // not supported type }