myParameters.clear();
}
-void PlaneGCSSolver_Solver::addConstraint(GCSConstraintPtr theConstraint)
+void PlaneGCSSolver_Solver::addConstraint(GCSConstraintPtr theConstraint,
+ const SketchSolver_ConstraintType theType)
{
GCS::Constraint* aConstraint = theConstraint.get();
if (myConstraints.find(aConstraint) != myConstraints.end())
return; // constraint already exists, no need to add it again
myEquationSystem.addConstraint(aConstraint);
- myConstraints.insert(aConstraint);
+ myConstraints[aConstraint] = theType;
}
void PlaneGCSSolver_Solver::removeConstraint(GCSConstraintPtr theConstraint)
// if there is a constraint with all attributes constant, set fail status
GCS::SET_pD aParameters;
aParameters.insert(myParameters.begin(), myParameters.end());
- std::set<GCS::Constraint*>::const_iterator aConstrIt = myConstraints.begin();
+ ConstraintMap::const_iterator aConstrIt = myConstraints.begin();
for (; aConstrIt != myConstraints.end(); ++aConstrIt) {
- GCS::VEC_pD aParams = (*aConstrIt)->params();
+ GCS::VEC_pD aParams = aConstrIt->first->params();
GCS::VEC_pD::const_iterator aPIt = aParams.begin();
for (; aPIt != aParams.end(); ++aPIt)
if (aParameters.find(*aPIt) != aParameters.end())
break;
- if (aPIt == aParams.end() && (*aConstrIt)->getTag() > 0) {
- myConflictingIDs.push_back((*aConstrIt)->getTag());
+ if (aPIt == aParams.end() && aConstrIt->first->getTag() > 0) {
+ myConflictingIDs.push_back(aConstrIt->first->getTag());
myConfCollected = true;
aResult = GCS::Failed;
}
GCS::VEC_I aRedundantLocal;
myEquationSystem.getRedundant(aRedundantLocal);
aRedundantID.insert(aRedundantID.end(), aRedundantLocal.begin(), aRedundantLocal.end());
- // Workaround: remove all constraints "Equal"
+ // Workaround: remove all point-point coincidences from list of redundant
if (!aRedundantID.empty()) {
- std::set<GCS::Constraint*>::const_iterator aCIt = myConstraints.begin();
+ ConstraintMap::const_iterator aCIt = myConstraints.begin();
for (; aCIt != myConstraints.end(); ++aCIt) {
- if ((*aCIt)->getTypeId() != GCS::Equal)
+ if (aCIt->second != CONSTRAINT_PT_PT_COINCIDENT)
continue;
GCS::VEC_I::iterator aRIt = aRedundantID.begin();
for (; aRIt != aRedundantID.end(); ++aRIt)
- if ((*aCIt)->getTag() == *aRIt) {
+ if (aCIt->first->getTag() == *aRIt) {
aRedundantID.erase(aRIt);
break;
}
--aNbRemove;
}
- std::set<GCS::Constraint*>::const_iterator aConstrIt = myConstraints.begin();
+ ConstraintMap::const_iterator aConstrIt = myConstraints.begin();
while (aConstrIt != myConstraints.end()) {
- GCS::Constraint* aConstraint = *aConstrIt;
+ GCS::Constraint* aConstraint = aConstrIt->first;
int anID = aConstraint->getTag();
++aConstrIt;
if (aTangentToRemove.find(anID) != aTangentToRemove.end())
static const double aTol = 1e-7;
static const double aTol2 = aTol *aTol;
- std::set<GCS::Constraint*>::const_iterator anIt = myConstraints.begin();
+ ConstraintMap::const_iterator anIt = myConstraints.begin();
for (; anIt != myConstraints.end(); ++anIt) {
- if ((*anIt)->getTag() != theTagID)
+ if (anIt->first->getTag() != theTagID)
continue;
- if ((*anIt)->getTypeId() == GCS::TangentCircumf) {
- GCS::VEC_pD aParams = (*anIt)->params();
+ if (anIt->first->getTypeId() == GCS::TangentCircumf) {
+ GCS::VEC_pD aParams = anIt->first->params();
double dx = *(aParams[2]) - *(aParams[0]);
double dy = *(aParams[3]) - *(aParams[1]);
double aDist2 = dx * dx + dy * dy;
return fabs(aDist2 - aRadSum * aRadSum) <= aTol2 ||
fabs(aDist2 - aRadDiff * aRadDiff) <= aTol2;
}
- if ((*anIt)->getTypeId() == GCS::P2LDistance) {
- GCS::VEC_pD aParams = (*anIt)->params();
+ if (anIt->first->getTypeId() == GCS::P2LDistance) {
+ GCS::VEC_pD aParams = anIt->first->params();
double aDist2 = *(aParams[6]) * *(aParams[6]);
// orthogonal line direction
double aDirX = *(aParams[5]) - *(aParams[3]);
#define PlaneGCSSolver_Solver_H_
#include <SketchSolver_ISolver.h>
+#include <SketchSolver_IConstraintWrapper.h>
#include <PlaneGCSSolver_Defs.h>
#include <GCS.h>
void clear();
/// \brief Add constraint to the system of equations
- void addConstraint(GCSConstraintPtr theConstraint);
+ void addConstraint(GCSConstraintPtr theConstraint,
+ const SketchSolver_ConstraintType theType);
/// \brief Remove constraint from the system of equations
void removeConstraint(GCSConstraintPtr theConstraint);
bool isTangentTruth(int theTagID) const;
private:
- GCS::VEC_pD myParameters; ///< list of unknowns
- std::set<GCS::Constraint*> myConstraints; ///< list of constraints already processed by the system
- GCS::System myEquationSystem; ///< set of equations for solving in FreeGCS
+ typedef std::map<GCS::Constraint*, SketchSolver_ConstraintType> ConstraintMap;
- GCS::VEC_I myConflictingIDs; ///< list of IDs of conflicting constraints
- bool myConfCollected; ///< specifies the conflicting constraints are already collected
+ GCS::VEC_pD myParameters; ///< list of unknowns
+ ConstraintMap myConstraints; ///< list of constraints already processed by the system
+ GCS::System myEquationSystem; ///< set of equations for solving in FreeGCS
- GCS::SET_I myTangent; ///< list of tangent IDs to check incorrect redundant constraints
+ GCS::VEC_I myConflictingIDs; ///< list of IDs of conflicting constraints
+ bool myConfCollected; ///< specifies the conflicting constraints are already collected
+
+ GCS::SET_I myTangent; ///< list of tangent IDs to check incorrect redundant constraints
};
#endif
std::list<GCSConstraintPtr>::const_iterator anIt = aGCS->constraints().begin();
for (; anIt != aGCS->constraints().end(); ++anIt)
if (!isRedundant(*anIt, aGCS, aCoincidentPoints))
- aSolver->addConstraint(*anIt);
+ aSolver->addConstraint(*anIt, aGCS->type());
}
// store IDs of tangent constraints to avoid incorrect report of redundant constraints
if (aCIt->first && aCIt->first->getKind() == SketchPlugin_ConstraintTangent::ID())
for (; anArcIt != myArcConstraintMap.end(); ++anArcIt) {
std::vector<GCSConstraintPtr>::const_iterator anIt = anArcIt->second.begin();
for (; anIt != anArcIt->second.end(); ++anIt)
- aSolver->addConstraint(*anIt);
+ aSolver->addConstraint(*anIt, CONSTRAINT_UNKNOWN);
}
// removed waste constraints
std::list<GCSConstraintPtr>::const_iterator aRemIt = myRemovedConstraints.begin();