From c5052205bdd490c042da4016ea07950d7eccc112 Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 23 Dec 2015 18:00:32 +0300 Subject: [PATCH] Update SolveSpaceSolver for correct processing of duplicated constraints (issues # 1103, #1147) --- .../SolveSpaceSolver_Storage.cpp | 42 ++++++++++++++++++- .../SolveSpaceSolver_Storage.h | 3 ++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp index e5e79492b..a34cee193 100644 --- a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp +++ b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp @@ -102,10 +102,14 @@ bool SolveSpaceSolver_Storage::update(ConstraintWrapperPtr theConstraint) aSlvsConstr.wrkpl = myWorkplaneID; if (aSlvsConstr.group == SLVS_G_UNKNOWN) aSlvsConstr.group = (Slvs_hGroup)myGroupID; + bool hasDupConstraints = myDuplicatedConstraint; Slvs_hConstraint aConstrID = updateConstraint(aSlvsConstr); if (aSlvsConstr.h == SLVS_C_UNKNOWN) { aConstraint->changeConstraint() = getConstraint(aConstrID); isUpdated = true; + // check duplicated constraints based on different attributes + if (myDuplicatedConstraint && !hasDupConstraints && findSameConstraint(aConstraint)) + myDuplicatedConstraint = false; } } return isUpdated; @@ -449,6 +453,40 @@ void SolveSpaceSolver_Storage::addSameConstraints(ConstraintWrapperPtr theConstr myEqualConstraints.push_back(aNewGroup); } +bool SolveSpaceSolver_Storage::findSameConstraint(ConstraintWrapperPtr theConstraint) +{ + if (theConstraint->type() == CONSTRAINT_PT_PT_COINCIDENT || + theConstraint->type() == CONSTRAINT_MULTI_ROTATION || + theConstraint->type() == CONSTRAINT_MULTI_TRANSLATION) + return false; + + const Slvs_Constraint& aCBase = + std::dynamic_pointer_cast(theConstraint)->constraint(); + + std::map >::const_iterator + aCIt = myConstraintMap.begin(); + std::list::const_iterator aCWIt; + for (; aCIt != myConstraintMap.end(); ++aCIt) + for (aCWIt = aCIt->second.begin(); aCWIt != aCIt->second.end(); ++aCWIt) { + if ((*aCWIt)->type() == CONSTRAINT_PT_PT_COINCIDENT || + (*aCWIt)->type() == CONSTRAINT_MULTI_ROTATION || + (*aCWIt)->type() == CONSTRAINT_MULTI_TRANSLATION) + continue; + if ((*aCWIt)->type() == theConstraint->type()) { + const Slvs_Constraint& aCComp = std::dynamic_pointer_cast< + SolveSpaceSolver_ConstraintWrapper>(*aCWIt)->constraint(); + if (aCBase.ptA == aCComp.ptA && aCBase.ptB == aCComp.ptB && + aCBase.entityA == aCComp.entityA && aCBase.entityB == aCComp.entityB && + aCBase.entityC == aCComp.entityC && aCBase.entityD == aCComp.entityD && + fabs(aCBase.valA -aCComp.valA) < tolerance) { + addSameConstraints(*aCWIt, theConstraint); + return true; + } + } + } + return false; +} + EntityWrapperPtr SolveSpaceSolver_Storage::calculateMiddlePoint( EntityWrapperPtr theBase, double theCoeff) @@ -1026,8 +1064,10 @@ Slvs_hConstraint SolveSpaceSolver_Storage::addConstraint(const Slvs_Constraint& continue; if (aConstraint.ptA == aCIt->ptA && aConstraint.ptB == aCIt->ptB && aConstraint.entityA == aCIt->entityA && aConstraint.entityB == aCIt->entityB && - aConstraint.entityC == aCIt->entityC && aConstraint.entityD == aCIt->entityD) + aConstraint.entityC == aCIt->entityC && aConstraint.entityD == aCIt->entityD) { myDuplicatedConstraint = true; + return aCIt->h; + } } if (aConstraint.h > myConstrMaxID) diff --git a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.h b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.h index 2824e29f8..bf742f513 100644 --- a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.h +++ b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.h @@ -253,6 +253,9 @@ private: /// of point coincidence. void addSameConstraints(ConstraintWrapperPtr theConstraint1, ConstraintWrapperPtr theConstraint2); + /// \brief Search constraint equal to the given in terms of SolveSpace notation + bool findSameConstraint(ConstraintWrapperPtr theConstraint); + private: Slvs_hEntity myWorkplaneID; ///< identifier of workplane -- 2.39.2