From: azv Date: Thu, 21 Jan 2016 13:37:22 +0000 (+0300) Subject: Distance constraint for equal points (issue #1061) X-Git-Tag: V_2.2.0~185 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=92f5ad57273b390a63ee94a985ced600e429cd27;p=modules%2Fshaper.git Distance constraint for equal points (issue #1061) --- 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)