Sketcher: Blocked Constraint solver level

This commit is contained in:
Abdullah Tahiri
2017-12-21 00:41:25 +01:00
committed by wmayer
parent f64760b8a3
commit 48fc503364
3 changed files with 37 additions and 1 deletions

View File

@@ -55,6 +55,7 @@ enum ConstraintType {
Symmetric = 14,
InternalAlignment = 15,
SnellsLaw = 16,
Blocked = 17,
NumConstraintTypes // must be the last item!
};

View File

@@ -128,7 +128,12 @@ int Sketch::setUpSketch(const std::vector<Part::Geometry *> &GeoList,
for (int i=int(GeoList.size())-extGeoCount; i < int(GeoList.size()); i++)
extGeoList.push_back(GeoList[i]);
addGeometry(intGeoList);
std::vector<bool> blockedGeometry(intGeoList.size(),false);
if(!intGeoList.empty())
getBlockedGeometry(blockedGeometry,ConstraintList);
addGeometry(intGeoList,blockedGeometry);
int extStart=Geoms.size();
addGeometry(extGeoList, true);
int extEnd=Geoms.size()-1;
@@ -251,6 +256,19 @@ int Sketch::addGeometry(const std::vector<Part::Geometry *> &geo, bool fixed)
return ret;
}
int Sketch::addGeometry(const std::vector<Part::Geometry *> &geo, std::vector<bool> &blockedGeometry)
{
assert(geo.size() == blockedGeometry.size());
int ret = -1;
std::vector<Part::Geometry *>::const_iterator it;
std::vector<bool>::iterator bit;
for (it=geo.begin(),bit=blockedGeometry.begin(); it != geo.end() && bit !=blockedGeometry.end(); ++it,++bit)
ret = addGeometry(*it, *bit);
return ret;
}
int Sketch::addPoint(const Part::GeomPoint &point, bool fixed)
{
std::vector<double *> &params = fixed ? FixParameters : Parameters;
@@ -1309,6 +1327,19 @@ int Sketch::addConstraints(const std::vector<Constraint *> &ConstraintList)
return rtn;
}
void Sketch::getBlockedGeometry(std::vector<bool> & blockedGeometry, const std::vector<Constraint *> &ConstraintList)
{
for (std::vector<Constraint *>::const_iterator it = ConstraintList.begin();it!=ConstraintList.end();++it) {
if((*it)->Type == Blocked) {
int geoid = (*it)->First;
if(geoid>=0 && geoid<blockedGeometry.size())
blockedGeometry[geoid]=true;
}
}
}
int Sketch::addCoordinateXConstraint(int geoId, PointPos pos, double * value)
{
geoId = checkGeoId(geoId);

View File

@@ -78,6 +78,10 @@ public:
int addGeometry(const Part::Geometry *geo, bool fixed=false);
/// add unspecified geometry
int addGeometry(const std::vector<Part::Geometry *> &geo, bool fixed=false);
/// add unspecified geometry, where each element's "fixed" status is given by the blockedGeometry array
int addGeometry(const std::vector<Part::Geometry *> &geo, std::vector<bool> &blockedGeometry);
/// get boolean list indicating whether the geometry is to be blocked or not
void getBlockedGeometry(std::vector<bool> & blockedGeometry, const std::vector<Constraint *> &ConstraintList);
/// returns the actual geometry
std::vector<Part::Geometry *> extractGeometry(bool withConstructionElements=true,
bool withExternalElements=false) const;