void SketchSolver_ConstraintDistance::adjustConstraint()
{
- // Adjust point-line distance
- if (getType() != CONSTRAINT_PT_LINE_DISTANCE)
+ ConstraintWrapperPtr aConstraint = myStorage->constraint(myBaseConstraint).front();
+
+ // Adjust point-point distance if the points are equal
+ if (getType() == CONSTRAINT_PT_PT_DISTANCE) {
+ const std::list<EntityWrapperPtr>& aSubs = aConstraint->entities();
+ if (aSubs.front()->isEqual(aSubs.back())) {
+ // Change X coordinate of second point to eliminate coincidence
+ ParameterWrapperPtr aX = aSubs.back()->parameters().front();
+ aX->setValue(aX->value() + 1.0);
+ myStorage->update(aX);
+ }
return;
+ }
- // Check the sign of distance is changed
- ConstraintWrapperPtr aConstraint = myStorage->constraint(myBaseConstraint).front();
+ // Adjust point-line distance
if (fabs(myPrevValue) == fabs(aConstraint->value())) {
+ // sign of distance is not changed
aConstraint->setValue(myPrevValue);
myStorage->addConstraint(myBaseConstraint, aConstraint);
return;
#include <ModelAPI_Feature.h>
#include <SketchPlugin_Constraint.h>
-
+class SketchSolver_ConstraintDistance;
typedef std::map<EntityWrapperPtr, std::set<EntityWrapperPtr> > CoincidentPointsMap;
std::map<AttributePtr, EntityWrapperPtr> myAttributeMap;
CoincidentPointsMap myCoincidentPoints; ///< lists of coincident points (first is a master point, second is a set of slaves)
+
+ // to be able to update entities from constraints
+ friend class SketchSolver_ConstraintDistance;
};
typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;
return true;
bool isFullyRemoved = removeConstraint((Slvs_hConstraint)aConstraint->id());
- isFullyRemoved = SketchSolver_Storage::remove(theConstraint) && isFullyRemoved;
-
// remove point-point coincidence
if (aConstraint->type() == CONSTRAINT_PT_PT_COINCIDENT)
isFullyRemoved = removeCoincidence(theConstraint) && isFullyRemoved;
- return isFullyRemoved;
+ return SketchSolver_Storage::remove(theConstraint) && isFullyRemoved;
}
bool SolveSpaceSolver_Storage::remove(EntityWrapperPtr theEntity)
std::shared_ptr<SolveSpaceSolver_EntityWrapper> anEntity =
std::dynamic_pointer_cast<SolveSpaceSolver_EntityWrapper>(theEntity);
bool isFullyRemoved = isCoincide ? true : removeEntity((Slvs_hEntity)anEntity->id());
- return SketchSolver_Storage::remove(theEntity) && isFullyRemoved;
+ return (SketchSolver_Storage::remove(theEntity) || isCoincide) && isFullyRemoved;
}
bool SolveSpaceSolver_Storage::remove(ParameterWrapperPtr theParameter)