Skip to content

Commit

Permalink
Sketcher: BSpline Weights internal geometry support
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullahtahiriyo committed Jan 11, 2017
1 parent 6bd801d commit 1155022
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
45 changes: 45 additions & 0 deletions src/Mod/Sketcher/App/SketchObject.cpp
Expand Up @@ -3307,6 +3307,8 @@ int SketchObject::ExposeInternalGeometry(int GeoId)
std::vector<bool> controlpoints(bsp->countPoles());
std::vector<int> controlpointgeoids(bsp->countPoles());

bool isfirstweightconstrained = false;

std::vector<bool>::iterator itb;
std::vector<int>::iterator it;

Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -3340,6 +3353,8 @@ int SketchObject::ExposeInternalGeometry(int GeoId)

std::vector<Base::Vector3d> 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++) {
Expand All @@ -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);

Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/Sketcher/App/planegcs/GCS.cpp
Expand Up @@ -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);
}


Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Sketcher/Gui/CommandCreateGeo.cpp
Expand Up @@ -4426,10 +4426,10 @@ class DrawSketchHandlerBSpline: public DrawSketchHandler

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) {
Expand Down

0 comments on commit 1155022

Please sign in to comment.