Slvs_hConstraint SketchSolver_ConstraintCoincidence::addConstraint(
Slvs_hEntity thePoint1, Slvs_hEntity thePoint2)
{
+ bool hasDuplicated = myStorage->hasDuplicatedConstraint();
Slvs_Constraint aNewConstraint = Slvs_MakeConstraint(SLVS_E_UNKNOWN, myGroup->getId(),
SLVS_C_POINTS_COINCIDENT, myGroup->getWorkplaneId(), 0.0, thePoint1, thePoint2,
SLVS_E_UNKNOWN, SLVS_E_UNKNOWN);
Slvs_hConstraint aNewID = myStorage->addConstraint(aNewConstraint);
+ if (!hasDuplicated && myStorage->hasDuplicatedConstraint()) {
+ // the duplicated constraint appears
+ myStorage->removeConstraint(aNewID);
+ return SLVS_E_UNKNOWN;
+ }
mySlvsConstraints.push_back(aNewID);
return aNewID;
}
aResult = myConstrSolver.solve();
if (aResult == SLVS_RESULT_OKAY || aNbTemp <= 0)
break;
- aNbTemp = myStorage->removeFirstTemporaryConstraint();
+ aNbTemp = myStorage->deleteTemporaryConstraint();
myStorage->initializeSolver(myConstrSolver);
}
}
myTemporaryConstraints.clear();
}
-int SketchSolver_Storage::removeFirstTemporaryConstraint()
+int SketchSolver_Storage::deleteTemporaryConstraint()
{
if (myTemporaryConstraints.empty())
return 0;
- removeConstraint(*myTemporaryConstraints.begin());
- myTemporaryConstraints.erase(myTemporaryConstraints.begin());
+ // Search the point-on-line or a non-rigid constraint
+ std::set<Slvs_hConstraint>::iterator aCIt = myTemporaryConstraints.begin();
+ for (; aCIt != myTemporaryConstraints.end(); aCIt++) {
+ int aPos = Search(*aCIt, myConstraints);
+ if (myConstraints[aPos].type != SLVS_C_WHERE_DRAGGED)
+ break;
+ std::vector<Slvs_Constraint>::iterator anIt = myConstraints.begin();
+ for (; anIt != myConstraints.end(); anIt++)
+ if (anIt->type == SLVS_C_PT_ON_LINE && anIt->ptA == myConstraints[aPos].ptA)
+ break;
+ if (anIt != myConstraints.end())
+ break;
+ }
+ if (aCIt == myTemporaryConstraints.end())
+ aCIt = myTemporaryConstraints.begin();
+ bool aNewFixed = (*aCIt == myFixed);
+ removeConstraint(*aCIt);
+ myTemporaryConstraints.erase(aCIt);
+ if (aNewFixed) {
+ for (aCIt = myTemporaryConstraints.begin(); aCIt != myTemporaryConstraints.end(); aCIt++) {
+ int aPos = Search(*aCIt, myConstraints);
+ if (myConstraints[aPos].type == SLVS_C_WHERE_DRAGGED) {
+ myFixed = *aCIt;
+ break;
+ }
+ }
+ }
return (int)myTemporaryConstraints.size();
}
void addTemporaryConstraint(const Slvs_hConstraint& theConstraintID);
/// \brief Remove all transient constraints
void removeTemporaryConstraints();
- /// \brief Remove first temporary constraint
+ /// \brief Remove one temporary constraint. Preferable to remove the points under Point-on-Line constraint
/// \return Number of remaining temporary constraints
- int removeFirstTemporaryConstraint();
+ int deleteTemporaryConstraint();
/// \brief Checks the constraint is temporary
bool isTemporary(const Slvs_hConstraint& theConstraintID) const;