From f387a286673e6be6e5c065f3bbf3c19ed5981a30 Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 16 Dec 2015 08:18:01 +0300 Subject: [PATCH] Fix the problem with multi-coincidence of points (issue #1143) --- .../SketchSolver_ConstraintFixed.cpp | 2 +- .../SketchSolver_ConstraintMovement.cpp | 21 ++++++++++++++++++- .../SketchSolver_ConstraintMovement.h | 4 ++++ .../SolveSpaceSolver_Solver.h | 2 +- .../SolveSpaceSolver_Storage.cpp | 5 +++-- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/SketchSolver/SketchSolver_ConstraintFixed.cpp b/src/SketchSolver/SketchSolver_ConstraintFixed.cpp index 1417bde62..cddafdb12 100644 --- a/src/SketchSolver/SketchSolver_ConstraintFixed.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintFixed.cpp @@ -53,7 +53,7 @@ void SketchSolver_ConstraintFixed::fixFeature(EntityWrapperPtr theFeature) // extract feature from the group if (theFeature->baseAttribute()) myStorage->update(theFeature->baseAttribute(), GID_OUTOFGROUP); - else + else if (theFeature->baseFeature()) myStorage->update(theFeature->baseFeature(), GID_OUTOFGROUP); } diff --git a/src/SketchSolver/SketchSolver_ConstraintMovement.cpp b/src/SketchSolver/SketchSolver_ConstraintMovement.cpp index 85542cb42..7f4c8d78b 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMovement.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMovement.cpp @@ -49,7 +49,8 @@ static std::list movedEntities( for (; anOldIt != anOldSubs.end() && aNewIt != aNewSubs.end(); ++anOldIt, ++aNewIt) { std::list aMovedSubs = movedEntities( *anOldIt, theOldStorage, *aNewIt, theNewStorage); - if (aMovedSubs.size() != 1 || aMovedSubs.front() != *anOldIt) + if ((*anOldIt)->type() == ENTITY_POINT && // check only the points to be moved (because arcs in PlaneGCS have scalar subs too) + (aMovedSubs.size() != 1 || aMovedSubs.front() != *anOldIt)) isFullyMoved = false; aMoved.insert(aMoved.end(), aMovedSubs.begin(), aMovedSubs.end()); } @@ -96,3 +97,21 @@ void SketchSolver_ConstraintMovement::getAttributes( theAttributes.clear(); theAttributes.insert(theAttributes.begin(), aMoved.begin(), aMoved.end()); } + +bool SketchSolver_ConstraintMovement::remove() +{ + cleanErrorMsg(); + // Move fixed entities back to the current group + std::vector::iterator aMoveIt = myMovedEntities.begin(); + for (; aMoveIt != myMovedEntities.end(); ++aMoveIt) { + if ((*aMoveIt)->baseAttribute()) + myStorage->update((*aMoveIt)->baseAttribute(), myGroupID); + else if ((*aMoveIt)->baseFeature()) + myStorage->update((*aMoveIt)->baseFeature(), myGroupID); + } + + // Remove base feature + if (myBaseFeature) + myStorage->removeEntity(myBaseFeature); + return true; +} diff --git a/src/SketchSolver/SketchSolver_ConstraintMovement.h b/src/SketchSolver/SketchSolver_ConstraintMovement.h index ba119beaa..93b2ea001 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMovement.h +++ b/src/SketchSolver/SketchSolver_ConstraintMovement.h @@ -28,6 +28,10 @@ public: : SketchSolver_ConstraintFixed(theFeature) {} + /// \brief Tries to remove constraint + /// \return \c false, if current constraint contains another SketchPlugin constraints (like for multiple coincidence) + virtual bool remove(); + protected: /// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints virtual void process(); diff --git a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Solver.h b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Solver.h index c853970a3..aa7729551 100644 --- a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Solver.h +++ b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Solver.h @@ -41,7 +41,7 @@ typedef unsigned int UINT32; */ class SolveSpaceSolver_Solver : public SketchSolver_ISolver { - public: +public: SolveSpaceSolver_Solver(); virtual ~SolveSpaceSolver_Solver(); diff --git a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp index 080e32138..c8113afb8 100644 --- a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp +++ b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp @@ -295,8 +295,9 @@ void SolveSpaceSolver_Storage::addCoincidentPoints( replaceInFeatures(theSlave, theMaster); replaceInConstraints(theSlave, theMaster); - // Remove slave entity - removeEntity((Slvs_hEntity)theSlave->id()); + // Remove slave entity (if the IDs are equal no need to remove slave entity, just update it) + if (theMaster->id() != theSlave->id()) + removeEntity((Slvs_hEntity)theSlave->id()); std::shared_ptr aPointMaster = std::dynamic_pointer_cast(theMaster); -- 2.39.2