Sketcher: Refactor for GCS magic numbers
======================================== - A small refactor to eliminate GCS magic numbers from Sketch.cpp.
This commit is contained in:
committed by
abdullahtahiriyo
parent
be61ad123e
commit
5a5e47560f
@@ -153,7 +153,7 @@ int Sketch::setUpSketch(const std::vector<Part::Geometry *> &GeoList,
|
||||
if (!Geoms.empty()) {
|
||||
addConstraints(ConstraintList,unenforceableConstraints);
|
||||
}
|
||||
GCSsys.clearByTag(-1);
|
||||
clearTemporaryConstraints();
|
||||
GCSsys.declareUnknowns(Parameters);
|
||||
GCSsys.declareDrivenParams(DrivenParameters);
|
||||
GCSsys.initSolution(defaultSolverRedundant);
|
||||
@@ -172,6 +172,11 @@ int Sketch::setUpSketch(const std::vector<Part::Geometry *> &GeoList,
|
||||
return GCSsys.dofsNumber();
|
||||
}
|
||||
|
||||
void Sketch::clearTemporaryConstraints(void)
|
||||
{
|
||||
GCSsys.clearByTag(GCS::DefaultTemporaryConstraint);
|
||||
}
|
||||
|
||||
void Sketch::calculateDependentParametersElements(void)
|
||||
{
|
||||
for(auto geo : Geoms) {
|
||||
@@ -276,7 +281,7 @@ void Sketch::calculateDependentParametersElements(void)
|
||||
|
||||
int Sketch::resetSolver()
|
||||
{
|
||||
GCSsys.clearByTag(-1);
|
||||
clearTemporaryConstraints();
|
||||
GCSsys.declareUnknowns(Parameters);
|
||||
GCSsys.declareDrivenParams(DrivenParameters);
|
||||
GCSsys.initSolution(defaultSolverRedundant);
|
||||
@@ -3120,7 +3125,7 @@ int Sketch::solve(void)
|
||||
{
|
||||
Base::TimeInfo start_time;
|
||||
if (!isInitMove) { // make sure we are in single subsystem mode
|
||||
GCSsys.clearByTag(-1);
|
||||
clearTemporaryConstraints();
|
||||
isFine = true;
|
||||
}
|
||||
|
||||
@@ -3200,7 +3205,7 @@ int Sketch::solve(void)
|
||||
int i=0;
|
||||
for (std::vector<double*>::iterator it = Parameters.begin(); it != Parameters.end(); ++it, i++) {
|
||||
InitParameters[i] = **it;
|
||||
GCSsys.addConstraintEqual(*it, &InitParameters[i], -1);
|
||||
GCSsys.addConstraintEqual(*it, &InitParameters[i], GCS::DefaultTemporaryConstraint);
|
||||
}
|
||||
GCSsys.initSolution();
|
||||
ret = GCSsys.solve(isFine);
|
||||
@@ -3229,7 +3234,7 @@ int Sketch::solve(void)
|
||||
}
|
||||
|
||||
if (soltype == 3) // cleanup temporary constraints of the augmented system
|
||||
GCSsys.clearByTag(-1);
|
||||
clearTemporaryConstraints();
|
||||
|
||||
if (valid_solution) {
|
||||
if (soltype == 1)
|
||||
@@ -3266,7 +3271,7 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
|
||||
geoId = checkGeoId(geoId);
|
||||
|
||||
GCSsys.clearByTag(-1);
|
||||
clearTemporaryConstraints();
|
||||
|
||||
// don't try to move sketches that contain conflicting constraints
|
||||
if (hasConflicts()) {
|
||||
@@ -3283,7 +3288,7 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
p0.y = &MoveParameters[1];
|
||||
*p0.x = *point.x;
|
||||
*p0.y = *point.y;
|
||||
GCSsys.addConstraintP2PCoincident(p0,point,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p0,point,GCS::DefaultTemporaryConstraint);
|
||||
}
|
||||
} else if (Geoms[geoId].type == Line) {
|
||||
if (pos == start || pos == end) {
|
||||
@@ -3295,12 +3300,12 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
GCS::Point &p = Points[Geoms[geoId].startPointId];
|
||||
*p0.x = *p.x;
|
||||
*p0.y = *p.y;
|
||||
GCSsys.addConstraintP2PCoincident(p0,p,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p0,p,GCS::DefaultTemporaryConstraint);
|
||||
} else if (pos == end) {
|
||||
GCS::Point &p = Points[Geoms[geoId].endPointId];
|
||||
*p0.x = *p.x;
|
||||
*p0.y = *p.y;
|
||||
GCSsys.addConstraintP2PCoincident(p0,p,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p0,p,GCS::DefaultTemporaryConstraint);
|
||||
}
|
||||
} else if (pos == none || pos == mid) {
|
||||
MoveParameters.resize(4); // x1,y1,x2,y2
|
||||
@@ -3314,8 +3319,8 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
*p1.y = *l.p1.y;
|
||||
*p2.x = *l.p2.x;
|
||||
*p2.y = *l.p2.y;
|
||||
GCSsys.addConstraintP2PCoincident(p1,l.p1,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p2,l.p2,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p1,l.p1,GCS::DefaultTemporaryConstraint);
|
||||
GCSsys.addConstraintP2PCoincident(p2,l.p2,GCS::DefaultTemporaryConstraint);
|
||||
}
|
||||
} else if (Geoms[geoId].type == Circle) {
|
||||
GCS::Point ¢er = Points[Geoms[geoId].midPointId];
|
||||
@@ -3326,20 +3331,21 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
p0.y = &MoveParameters[1];
|
||||
*p0.x = *center.x;
|
||||
*p0.y = *center.y;
|
||||
GCSsys.addConstraintP2PCoincident(p0,center,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p0,center,GCS::DefaultTemporaryConstraint);
|
||||
} else if (pos == none) {
|
||||
MoveParameters.resize(4); // x,y,cx,cy
|
||||
//bool pole = GeometryFacade::isInternalType(Geoms[geoId].geo, InternalType::BSplineControlPoint);
|
||||
MoveParameters.resize(4); // x,y,cx,cy - For poles blocking the center
|
||||
GCS::Circle &c = Circles[Geoms[geoId].index];
|
||||
p0.x = &MoveParameters[0];
|
||||
p0.y = &MoveParameters[1];
|
||||
*p0.x = *center.x;
|
||||
*p0.y = *center.y + *c.rad;
|
||||
GCSsys.addConstraintPointOnCircle(p0,c,-1);
|
||||
GCSsys.addConstraintPointOnCircle(p0,c,GCS::DefaultTemporaryConstraint);
|
||||
p1.x = &MoveParameters[2];
|
||||
p1.y = &MoveParameters[3];
|
||||
*p1.x = *center.x;
|
||||
*p1.y = *center.y;
|
||||
int i=GCSsys.addConstraintP2PCoincident(p1,center,-1);
|
||||
int i=GCSsys.addConstraintP2PCoincident(p1,center,GCS::DefaultTemporaryConstraint);
|
||||
GCSsys.rescaleConstraint(i-1, 0.01);
|
||||
GCSsys.rescaleConstraint(i, 0.01);
|
||||
}
|
||||
@@ -3354,7 +3360,7 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
*p0.x = *center.x;
|
||||
*p0.y = *center.y;
|
||||
|
||||
GCSsys.addConstraintP2PCoincident(p0,center,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p0,center,GCS::DefaultTemporaryConstraint);
|
||||
}
|
||||
} else if (Geoms[geoId].type == ArcOfEllipse) {
|
||||
|
||||
@@ -3366,7 +3372,7 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
p0.y = &MoveParameters[1];
|
||||
*p0.x = *center.x;
|
||||
*p0.y = *center.y;
|
||||
GCSsys.addConstraintP2PCoincident(p0,center,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p0,center,GCS::DefaultTemporaryConstraint);
|
||||
|
||||
} else if (pos == start || pos == end) {
|
||||
|
||||
@@ -3379,7 +3385,7 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
*p0.x = *p.x;
|
||||
*p0.y = *p.y;
|
||||
|
||||
GCSsys.addConstraintP2PCoincident(p0,p,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p0,p,GCS::DefaultTemporaryConstraint);
|
||||
}
|
||||
|
||||
p1.x = &MoveParameters[2];
|
||||
@@ -3387,7 +3393,7 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
*p1.x = *center.x;
|
||||
*p1.y = *center.y;
|
||||
|
||||
int i=GCSsys.addConstraintP2PCoincident(p1,center,-1);
|
||||
int i=GCSsys.addConstraintP2PCoincident(p1,center,GCS::DefaultTemporaryConstraint);
|
||||
GCSsys.rescaleConstraint(i-1, 0.01);
|
||||
GCSsys.rescaleConstraint(i, 0.01);
|
||||
}
|
||||
@@ -3402,7 +3408,7 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
*p0.x = *center.x;
|
||||
*p0.y = *center.y;
|
||||
|
||||
GCSsys.addConstraintP2PCoincident(p0,center,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p0,center,GCS::DefaultTemporaryConstraint);
|
||||
} else if (pos == start || pos == end) {
|
||||
|
||||
MoveParameters.resize(4); // x,y,cx,cy
|
||||
@@ -3414,14 +3420,14 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
*p0.x = *p.x;
|
||||
*p0.y = *p.y;
|
||||
|
||||
GCSsys.addConstraintP2PCoincident(p0,p,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p0,p,GCS::DefaultTemporaryConstraint);
|
||||
}
|
||||
p1.x = &MoveParameters[2];
|
||||
p1.y = &MoveParameters[3];
|
||||
*p1.x = *center.x;
|
||||
*p1.y = *center.y;
|
||||
|
||||
int i=GCSsys.addConstraintP2PCoincident(p1,center,-1);
|
||||
int i=GCSsys.addConstraintP2PCoincident(p1,center,GCS::DefaultTemporaryConstraint);
|
||||
GCSsys.rescaleConstraint(i-1, 0.01);
|
||||
GCSsys.rescaleConstraint(i, 0.01);
|
||||
|
||||
@@ -3437,7 +3443,7 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
*p0.x = *center.x;
|
||||
*p0.y = *center.y;
|
||||
|
||||
GCSsys.addConstraintP2PCoincident(p0,center,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p0,center,GCS::DefaultTemporaryConstraint);
|
||||
} else if (pos == start || pos == end) {
|
||||
|
||||
MoveParameters.resize(4); // x,y,cx,cy
|
||||
@@ -3449,14 +3455,14 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
*p0.x = *p.x;
|
||||
*p0.y = *p.y;
|
||||
|
||||
GCSsys.addConstraintP2PCoincident(p0,p,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p0,p,GCS::DefaultTemporaryConstraint);
|
||||
}
|
||||
p1.x = &MoveParameters[2];
|
||||
p1.y = &MoveParameters[3];
|
||||
*p1.x = *center.x;
|
||||
*p1.y = *center.y;
|
||||
|
||||
int i=GCSsys.addConstraintP2PCoincident(p1,center,-1);
|
||||
int i=GCSsys.addConstraintP2PCoincident(p1,center,GCS::DefaultTemporaryConstraint);
|
||||
GCSsys.rescaleConstraint(i-1, 0.01);
|
||||
GCSsys.rescaleConstraint(i, 0.01);
|
||||
|
||||
@@ -3471,12 +3477,12 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
GCS::Point &p = Points[Geoms[geoId].startPointId];
|
||||
*p0.x = *p.x;
|
||||
*p0.y = *p.y;
|
||||
GCSsys.addConstraintP2PCoincident(p0,p,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p0,p,GCS::DefaultTemporaryConstraint);
|
||||
} else if (pos == end) {
|
||||
GCS::Point &p = Points[Geoms[geoId].endPointId];
|
||||
*p0.x = *p.x;
|
||||
*p0.y = *p.y;
|
||||
GCSsys.addConstraintP2PCoincident(p0,p,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p0,p,GCS::DefaultTemporaryConstraint);
|
||||
}
|
||||
} else if (pos == none || pos == mid) {
|
||||
GCS::BSpline &bsp = BSplines[Geoms[geoId].index];
|
||||
@@ -3492,7 +3498,7 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
*p1.x = *(*it).x;
|
||||
*p1.y = *(*it).y;
|
||||
|
||||
GCSsys.addConstraintP2PCoincident(p1,(*it),-1);
|
||||
GCSsys.addConstraintP2PCoincident(p1,(*it),GCS::DefaultTemporaryConstraint);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3505,7 +3511,7 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
p0.y = &MoveParameters[1];
|
||||
*p0.x = *center.x;
|
||||
*p0.y = *center.y;
|
||||
GCSsys.addConstraintP2PCoincident(p0,center,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p0,center,GCS::DefaultTemporaryConstraint);
|
||||
} else if (pos == start || pos == end || pos == none) {
|
||||
MoveParameters.resize(4); // x,y,cx,cy
|
||||
if (pos == start || pos == end) {
|
||||
@@ -3515,20 +3521,20 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
|
||||
p0.y = &MoveParameters[1];
|
||||
*p0.x = *p.x;
|
||||
*p0.y = *p.y;
|
||||
GCSsys.addConstraintP2PCoincident(p0,p,-1);
|
||||
GCSsys.addConstraintP2PCoincident(p0,p,GCS::DefaultTemporaryConstraint);
|
||||
} else if (pos == none) {
|
||||
GCS::Arc &a = Arcs[Geoms[geoId].index];
|
||||
p0.x = &MoveParameters[0];
|
||||
p0.y = &MoveParameters[1];
|
||||
*p0.x = *center.x;
|
||||
*p0.y = *center.y + *a.rad;
|
||||
GCSsys.addConstraintPointOnArc(p0,a,-1);
|
||||
GCSsys.addConstraintPointOnArc(p0,a,GCS::DefaultTemporaryConstraint);
|
||||
}
|
||||
p1.x = &MoveParameters[2];
|
||||
p1.y = &MoveParameters[3];
|
||||
*p1.x = *center.x;
|
||||
*p1.y = *center.y;
|
||||
int i=GCSsys.addConstraintP2PCoincident(p1,center,-1);
|
||||
int i=GCSsys.addConstraintP2PCoincident(p1,center,GCS::DefaultTemporaryConstraint);
|
||||
GCSsys.rescaleConstraint(i-1, 0.01);
|
||||
GCSsys.rescaleConstraint(i, 0.01);
|
||||
}
|
||||
|
||||
@@ -471,6 +471,8 @@ private:
|
||||
|
||||
void calculateDependentParametersElements(void);
|
||||
|
||||
void clearTemporaryConstraints(void);
|
||||
|
||||
/// checks if the index bounds and converts negative indices to positive
|
||||
int checkGeoId(int geoId) const;
|
||||
GCS::Curve* getGCSCurveByGeoId(int geoId);
|
||||
|
||||
Reference in New Issue
Block a user