From 1155022a825707674f20a01accf8f9c50ec8faab Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Wed, 11 Jan 2017 01:15:44 +0100 Subject: [PATCH] Sketcher: BSpline Weights internal geometry support --- src/Mod/Sketcher/App/SketchObject.cpp | 45 +++++++++++++++++++++++ src/Mod/Sketcher/App/planegcs/GCS.cpp | 3 +- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 4 +- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 2c7af4f3e..f5660eb67 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -3307,6 +3307,8 @@ int SketchObject::ExposeInternalGeometry(int GeoId) std::vector controlpoints(bsp->countPoles()); std::vector controlpointgeoids(bsp->countPoles()); + bool isfirstweightconstrained = false; + std::vector::iterator itb; std::vector::iterator it; @@ -3317,6 +3319,7 @@ int SketchObject::ExposeInternalGeometry(int GeoId) const std::vector< Sketcher::Constraint * > &vals = Constraints.getValues(); + // search for existing poles for (std::vector< Sketcher::Constraint * >::const_iterator it= vals.begin(); it != vals.end(); ++it) { if((*it)->Type == Sketcher::InternalAlignment && (*it)->Second == GeoId) @@ -3331,6 +3334,16 @@ int SketchObject::ExposeInternalGeometry(int GeoId) } } } + + if(controlpoints[0]) { + // search for first pole weight constraint + for (std::vector< Sketcher::Constraint * >::const_iterator it= vals.begin(); + it != vals.end(); ++it) { + if((*it)->Type == Sketcher::Radius && (*it)->First == controlpointgeoids[0]) { + isfirstweightconstrained = true ; + } + } + } int currentgeoid = getHighestCurveIndex(); int incrgeo = 0; @@ -3340,6 +3353,8 @@ int SketchObject::ExposeInternalGeometry(int GeoId) std::vector poles = bsp->getPoles(); + double distance_p0_p1 = (poles[1]-poles[0]).Length(); // for visual purposes only + int index=0; for(it=controlpointgeoids.begin(), itb=controlpoints.begin(); it!=controlpointgeoids.end() && itb!=controlpoints.end(); ++it, ++itb, index++) { @@ -3348,6 +3363,7 @@ int SketchObject::ExposeInternalGeometry(int GeoId) { Part::GeomCircle *pc = new Part::GeomCircle(); pc->setCenter(poles[index]); + pc->setRadius(distance_p0_p1/6); igeo.push_back(pc); @@ -3360,9 +3376,38 @@ int SketchObject::ExposeInternalGeometry(int GeoId) newConstr->Third = index; icon.push_back(newConstr); + + if(it != controlpointgeoids.begin()) { + // if pole-weight newly created make it equal to first weight by default + Sketcher::Constraint *newConstr2 = new Sketcher::Constraint(); + newConstr2->Type = Sketcher::Equal; + newConstr2->First = currentgeoid+incrgeo+1; + newConstr2->FirstPos = Sketcher::none; + newConstr2->Second = controlpointgeoids[0]; + newConstr2->SecondPos = Sketcher::none; + + icon.push_back(newConstr2); + } + else { + controlpointgeoids[0] = currentgeoid+incrgeo+1; + } + incrgeo++; } } + + // constraint the first weight to allow for seamless weight modification and proper visualization + if(!isfirstweightconstrained) { + + Sketcher::Constraint *newConstr = new Sketcher::Constraint(); + newConstr->Type = Sketcher::Radius; + newConstr->First = controlpointgeoids[0]; + newConstr->FirstPos = Sketcher::none; + newConstr->setValue( round(distance_p0_p1/6)); // 1/6 is just an estimation for acceptable general visualization + + icon.push_back(newConstr); + + } this->addGeometry(igeo,true); this->addConstraints(icon); diff --git a/src/Mod/Sketcher/App/planegcs/GCS.cpp b/src/Mod/Sketcher/App/planegcs/GCS.cpp index 46dd6096b..3272e882c 100644 --- a/src/Mod/Sketcher/App/planegcs/GCS.cpp +++ b/src/Mod/Sketcher/App/planegcs/GCS.cpp @@ -1010,7 +1010,8 @@ int System::addConstraintInternalAlignmentParabolaFocus(Parabola &e, Point &p1, int System::addConstraintInternalAlignmentBSplineControlPoint(BSpline &b, Circle &c, int poleindex, int tagId) { addConstraintEqual(b.poles[poleindex].x, c.center.x, tagId); - return addConstraintEqual(b.poles[poleindex].y, c.center.y, tagId); + addConstraintEqual(b.poles[poleindex].y, c.center.y, tagId); + return addConstraintEqual(b.weights[poleindex], c.rad, tagId); } diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index deace1c96..3313d0b17 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -4426,10 +4426,10 @@ public: currentgeoid++; - /*Gui::Command::doCommand(Gui::Command::Doc, + Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.ExposeInternalGeometry(%d)", sketchgui->getObject()->getNameInDocument(), - currentgeoid);*/ + currentgeoid); } catch (const Base::Exception& e) {