From 92f5ad57273b390a63ee94a985ced600e429cd27 Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 21 Jan 2016 16:37:22 +0300 Subject: [PATCH] Distance constraint for equal points (issue #1061) --- .../SketchSolver_ConstraintDistance.cpp | 18 ++++++++++++++---- src/SketchSolver/SketchSolver_Storage.h | 5 ++++- .../SolveSpaceSolver_Storage.cpp | 6 ++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/SketchSolver/SketchSolver_ConstraintDistance.cpp b/src/SketchSolver/SketchSolver_ConstraintDistance.cpp index e82568d3e..2a75e1293 100644 --- a/src/SketchSolver/SketchSolver_ConstraintDistance.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintDistance.cpp @@ -32,13 +32,23 @@ void SketchSolver_ConstraintDistance::getAttributes( 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& 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; diff --git a/src/SketchSolver/SketchSolver_Storage.h b/src/SketchSolver/SketchSolver_Storage.h index ae0ac3602..7cd073f70 100644 --- a/src/SketchSolver/SketchSolver_Storage.h +++ b/src/SketchSolver/SketchSolver_Storage.h @@ -18,7 +18,7 @@ #include #include - +class SketchSolver_ConstraintDistance; typedef std::map > CoincidentPointsMap; @@ -213,6 +213,9 @@ protected: std::map 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 StoragePtr; diff --git a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp index fcd53d0e6..1f0632b71 100644 --- a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp +++ b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp @@ -974,12 +974,10 @@ bool SolveSpaceSolver_Storage::remove(ConstraintWrapperPtr theConstraint) 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) @@ -1013,7 +1011,7 @@ bool SolveSpaceSolver_Storage::remove(EntityWrapperPtr theEntity) std::shared_ptr anEntity = std::dynamic_pointer_cast(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) -- 2.39.2