From ab35630144a13fa0129bb013fbd910ce8a928976 Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 26 May 2015 18:07:15 +0300 Subject: [PATCH] Issue #563: Fix the problem with translating on the given distance --- src/SketchSolver/SketchSolver_Constraint.cpp | 3 +-- ...ketchSolver_ConstraintMultiTranslation.cpp | 24 +++++++++---------- src/SketchSolver/SketchSolver_Group.cpp | 5 ++-- src/SketchSolver/SketchSolver_Storage.h | 3 +++ 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index 1ab3b596b..d5c3bbb5a 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -155,8 +155,7 @@ bool SketchSolver_Constraint::checkAttributesChanged(ConstraintPtr theConstraint std::list::iterator anIt = anItems.begin(); for (; anIt != anItems.end(); anIt++) { FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt); - std::map::iterator aFIt = myFeatureMap.find(aFeature); - if (aFeature && (aFIt == myFeatureMap.end() || aCurAttrs.find(aFIt->second) == aCurAttrs.end())) + if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end()) return true; } } diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp index 2e5bafbfe..a90354a84 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp @@ -164,17 +164,6 @@ void SketchSolver_ConstraintMultiTranslation::process() } } - // Set the translation line unchanged during constraint recalculation - for (int i = 0; i < 2; i++) { - if (myStorage->isPointFixed(aTranslationLine.point[i], aConstraint.h, true)) - continue; - aConstraint = Slvs_MakeConstraint( - SLVS_E_UNKNOWN, myGroup->getId(), SLVS_C_WHERE_DRAGGED, myGroup->getWorkplaneId(), 0.0, - aTranslationLine.point[i], SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN); - aConstraint.h = myStorage->addConstraint(aConstraint); - mySlvsConstraints.push_back(aConstraint.h); - } - adjustConstraint(); } @@ -222,6 +211,18 @@ bool SketchSolver_ConstraintMultiTranslation::remove(ConstraintPtr theConstraint void SketchSolver_ConstraintMultiTranslation::adjustConstraint() { Slvs_Entity aTranslationLine = myStorage->getEntity(myTranslationLine); + Slvs_hConstraint aFixed; // temporary variable + // Set the translation line unchanged during constraint recalculation + for (int i = 0; i < 2; i++) { + if (myStorage->isPointFixed(aTranslationLine.point[i], aFixed, true)) + continue; + Slvs_Constraint aConstraint = Slvs_MakeConstraint( + SLVS_E_UNKNOWN, myGroup->getId(), SLVS_C_WHERE_DRAGGED, myGroup->getWorkplaneId(), 0.0, + aTranslationLine.point[i], SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN); + aConstraint.h = myStorage->addConstraint(aConstraint); + myStorage->addTemporaryConstraint(aConstraint.h); + } + // Check if the distance between point is 0, no need to resolve constraints (just wait another values) double aXY[4]; for (int i = 0; i < 2; i++) { @@ -239,7 +240,6 @@ void SketchSolver_ConstraintMultiTranslation::adjustConstraint() std::list aParallel = myStorage->getConstraintsByType(SLVS_C_PARALLEL); std::list::iterator aParIt = aParallel.begin(); std::vector::iterator aCIt; - Slvs_hConstraint aFixed; // temporary variable for (; aParIt != aParallel.end(); aParIt++) { for (aCIt = mySlvsConstraints.begin(); aCIt != mySlvsConstraints.end(); aCIt++) if (aParIt->h == *aCIt) diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index 419cc3e87..794eb1a3f 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -424,7 +424,7 @@ bool SketchSolver_Group::resolveConstraints() else { // To avoid overconstraint situation, we will remove temporary constraints one-by-one // and try to find the case without overconstraint - int aNbTemp = (int)myTempConstraints.size(); + int aNbTemp = myStorage->numberTemporary(); while (true) { aResult = myConstrSolver.solve(); if (aResult == SLVS_RESULT_OKAY || aNbTemp <= 0) @@ -575,7 +575,8 @@ bool SketchSolver_Group::isConsistent() void SketchSolver_Group::removeTemporaryConstraints() { myTempConstraints.clear(); - myStorage->removeTemporaryConstraints(); + while (myStorage->numberTemporary()) + myStorage->deleteTemporaryConstraint(); // Clean lists of removed entities in the storage std::set aRemPar; std::set aRemEnt; diff --git a/src/SketchSolver/SketchSolver_Storage.h b/src/SketchSolver/SketchSolver_Storage.h index 669f2c0ea..3167dd157 100644 --- a/src/SketchSolver/SketchSolver_Storage.h +++ b/src/SketchSolver/SketchSolver_Storage.h @@ -113,6 +113,9 @@ public: int deleteTemporaryConstraint(); /// \brief Checks the constraint is temporary bool isTemporary(const Slvs_hConstraint& theConstraintID) const; + /// \brief Number of temporary constraints + int numberTemporary() const + { return (int)myTemporaryConstraints.size(); } /// \brief Shows the sketch should be resolved bool isNeedToResolve() const -- 2.39.2