try {
if (myStorage->hasDuplicatedConstraint())
aResult = SLVS_RESULT_INCONSISTENT;
- else
- aResult = myConstrSolver.solve();
+ else {
+ // To avoid overconstraint situation, we will remove temporary constraints one-by-one
+ // and try to find the case without overconstraint
+ int aNbTemp = (int)myTempConstraints.size();
+ while (true) {
+ aResult = myConstrSolver.solve();
+ if (aResult == SLVS_RESULT_OKAY || aNbTemp <= 0)
+ break;
+ aNbTemp = myStorage->removeFirstTemporaryConstraint();
+ myStorage->initializeSolver(myConstrSolver);
+ }
+ }
} catch (...) {
Events_Error::send(SketchSolver_Error::SOLVESPACE_CRASH(), this);
return false;
myEquationsSystem.constraints = theSize;
}
else if (myEquationsSystem.constraints != theSize) {
- delete[] myEquationsSystem.constraint;
- myEquationsSystem.constraint = new Slvs_Constraint[theSize];
+ if (theSize > myEquationsSystem.constraints) {
+ delete[] myEquationsSystem.constraint;
+ myEquationsSystem.constraint = new Slvs_Constraint[theSize];
+ }
myEquationsSystem.constraints = theSize;
}
memcpy(myEquationsSystem.constraint, theConstraints, theSize * sizeof(Slvs_Constraint));
myTemporaryConstraints.clear();
}
+int SketchSolver_Storage::removeFirstTemporaryConstraint()
+{
+ if (myTemporaryConstraints.empty())
+ return 0;
+ removeConstraint(*myTemporaryConstraints.begin());
+ myTemporaryConstraints.erase(myTemporaryConstraints.begin());
+ return (int)myTemporaryConstraints.size();
+}
+
bool SketchSolver_Storage::isTemporary(const Slvs_hConstraint& theConstraintID) const
{
return myTemporaryConstraints.find(theConstraintID) != myTemporaryConstraints.end();
void addTemporaryConstraint(const Slvs_hConstraint& theConstraintID);
/// \brief Remove all transient constraints
void removeTemporaryConstraints();
+ /// \brief Remove first temporary constraint
+ /// \return Number of remaining temporary constraints
+ int removeFirstTemporaryConstraint();
/// \brief Checks the constraint is temporary
bool isTemporary(const Slvs_hConstraint& theConstraintID) const;