From: azv Date: Wed, 19 Aug 2015 07:00:50 +0000 (+0300) Subject: Update coincidence constraints X-Git-Tag: V_1.4.0_beta4~320 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0bfcff9bb7e0de59bd1dce0132a079eba5c6557e;p=modules%2Fshaper.git Update coincidence constraints --- diff --git a/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp b/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp index 5144f14fc..0840c3714 100644 --- a/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp @@ -32,20 +32,16 @@ bool SketchSolver_ConstraintCoincidence::hasConstraint(ConstraintPtr theConstrai { if (myBaseConstraint == theConstraint) return true; - std::map::const_iterator anIt = myExtraCoincidence.begin(); - for (; anIt != myExtraCoincidence.end(); anIt++) - if (anIt->second == theConstraint) - return true; - return false; + return myExtraCoincidence.find(theConstraint) != myExtraCoincidence.end(); } std::list SketchSolver_ConstraintCoincidence::constraints() const { std::list aConstraints; aConstraints.push_back(myBaseConstraint); - std::map::const_iterator anIt = myExtraCoincidence.begin(); + std::map::const_iterator anIt = myExtraCoincidence.begin(); for (; anIt != myExtraCoincidence.end(); anIt++) - aConstraints.push_back(anIt->second); + aConstraints.push_back(anIt->first); return aConstraints; } @@ -78,14 +74,35 @@ void SketchSolver_ConstraintCoincidence::attach( std::set aRemEnts; std::set aRemConstr; theConstraint->myStorage->getRemoved(aRemParams, aRemEnts, aRemConstr); + + if (!aRemEnts.empty()) { + std::map::iterator aFeatIt = theConstraint->myFeatureMap.begin(); + while (aFeatIt != theConstraint->myFeatureMap.end()) { + if (aRemEnts.find(aFeatIt->second) != aRemEnts.end()) { + // remove feature + std::map::iterator aRemoveIt = aFeatIt++; + theConstraint->myFeatureMap.erase(aRemoveIt); + } else + ++aFeatIt; + } + std::map::iterator anAttrIt = theConstraint->myAttributeMap.begin(); + while (anAttrIt != theConstraint->myAttributeMap.end()) { + if (aRemEnts.find(anAttrIt->second) != aRemEnts.end()) { + // remove attribute + std::map::iterator aRemoveIt = anAttrIt++; + theConstraint->myAttributeMap.erase(aRemoveIt); + } else + ++anAttrIt; + } + } } // Copy data. addConstraint(theConstraint->myBaseConstraint); - std::map::iterator aConstrIter = + std::map::iterator aConstrIter = theConstraint->myExtraCoincidence.begin(); for (; aConstrIter != theConstraint->myExtraCoincidence.end(); aConstrIter++) - addConstraint(aConstrIter->second); + addConstraint(aConstrIter->first); // Clear the lists to not remove the entities on destruction theConstraint->mySlvsConstraints.clear(); theConstraint->myFeatureMap.clear(); @@ -137,7 +154,7 @@ void SketchSolver_ConstraintCoincidence::addConstraint(ConstraintPtr theConstrai Slvs_Constraint aBaseCoincidence = myStorage->getConstraint(mySlvsConstraints.front()); for (; anEntIter != anEntities.end(); anEntIter++) aNewConstr = addConstraint(aBaseCoincidence.ptA, *anEntIter); - myExtraCoincidence[aNewConstr] = theConstraint; + myExtraCoincidence[theConstraint] = aNewConstr; } void SketchSolver_ConstraintCoincidence::process() @@ -163,20 +180,20 @@ bool SketchSolver_ConstraintCoincidence::remove(ConstraintPtr theConstraint) return true; ConstraintPtr aConstraint = theConstraint ? theConstraint : myBaseConstraint; int aPos = -1; // position of constraint in the list (-1 for base constraint) - std::map::iterator anExtraIt; + std::map::iterator anExtraIt; if (aConstraint != myBaseConstraint) { - anExtraIt = myExtraCoincidence.begin(); - for (aPos = 0; anExtraIt != myExtraCoincidence.end(); anExtraIt++, aPos++) - if (anExtraIt->second == aConstraint) - break; - if (aPos >= (int)myExtraCoincidence.size()) + anExtraIt = myExtraCoincidence.find(aConstraint); + if (anExtraIt == myExtraCoincidence.end()) return false; // there is no constraint, which is specified to remove else { - bool isEmpty = anExtraIt->first == SLVS_E_UNKNOWN; + bool isEmpty = anExtraIt->second == SLVS_E_UNKNOWN; if (!isEmpty) { + isEmpty = true; for (aPos = 0; aPos < (int)mySlvsConstraints.size(); aPos++) - if (mySlvsConstraints[aPos] == anExtraIt->first) + if (mySlvsConstraints[aPos] == anExtraIt->second) { + isEmpty = false; break; + } aPos -= 1; } myExtraCoincidence.erase(anExtraIt); @@ -191,13 +208,13 @@ bool SketchSolver_ConstraintCoincidence::remove(ConstraintPtr theConstraint) anExtraIt = myExtraCoincidence.begin(); // Remove invalid constraints while (anExtraIt != myExtraCoincidence.end()) { - if (!anExtraIt->second->data() || !anExtraIt->second->data()->isValid()) { - std::map::iterator aTempIt = anExtraIt++; + if (!anExtraIt->first->data() || !anExtraIt->first->data()->isValid()) { + std::map::iterator aTempIt = anExtraIt++; if (aTempIt->first != SLVS_E_UNKNOWN) { - myStorage->removeConstraint(aTempIt->first); + myStorage->removeConstraint(aTempIt->second); std::vector::iterator anIt = mySlvsConstraints.begin(); for (; anIt != mySlvsConstraints.end(); anIt++) - if (*anIt == aTempIt->first) { + if (*anIt == aTempIt->second) { mySlvsConstraints.erase(anIt); break; } @@ -209,11 +226,11 @@ bool SketchSolver_ConstraintCoincidence::remove(ConstraintPtr theConstraint) } // Find first non-extra conststraint anExtraIt = myExtraCoincidence.begin(); - while (anExtraIt != myExtraCoincidence.end() && anExtraIt->first == SLVS_E_UNKNOWN) + while (anExtraIt != myExtraCoincidence.end() && anExtraIt->second == SLVS_E_UNKNOWN) anExtraIt++; if (anExtraIt != myExtraCoincidence.end()) { // Need to specify another base coincidence constraint - myBaseConstraint = anExtraIt->second; + myBaseConstraint = anExtraIt->first; myExtraCoincidence.erase(anExtraIt); if (mySlvsConstraints.empty()) { std::vector::iterator aCIter = mySlvsConstraints.begin(); @@ -246,19 +263,19 @@ bool SketchSolver_ConstraintCoincidence::remove(ConstraintPtr theConstraint) anExtraIt = myExtraCoincidence.begin(); while (anExtraIt != myExtraCoincidence.end()) { if (anExtraIt->first == SLVS_E_UNKNOWN) { - if (!anExtraIt->second->data() || !anExtraIt->second->data()->isValid()) { - std::map::iterator aTempIt = anExtraIt++; + if (!anExtraIt->first->data() || !anExtraIt->first->data()->isValid()) { + std::map::iterator aTempIt = anExtraIt++; myExtraCoincidence.erase(aTempIt); continue; } if (mySlvsConstraints.empty()) { - myBaseConstraint = anExtraIt->second; - std::map::iterator aTempIt = anExtraIt++; + myBaseConstraint = anExtraIt->first; + std::map::iterator aTempIt = anExtraIt++; myExtraCoincidence.erase(aTempIt); process(); continue; } else - addConstraint(anExtraIt->second); + addConstraint(anExtraIt->first); } anExtraIt++; } diff --git a/src/SketchSolver/SketchSolver_ConstraintCoincidence.h b/src/SketchSolver/SketchSolver_ConstraintCoincidence.h index c1d1124af..43354e80d 100644 --- a/src/SketchSolver/SketchSolver_ConstraintCoincidence.h +++ b/src/SketchSolver/SketchSolver_ConstraintCoincidence.h @@ -60,7 +60,7 @@ private: private: int myType; ///< type of constraint (applicable SLVS_C_POINTS_COINCIDENT or SLVS_C_PT_ON_LINE or SLVS_C_PT_ON_CIRCLE) - std::map myExtraCoincidence; ///< multiple coincidence of points + std::map myExtraCoincidence; ///< multiple coincidence of points std::set myCoincidentPoints; ///< list of points under the Coincidence constraint }; diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index 3ee780ee0..f77a22f33 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -208,8 +208,8 @@ bool SketchSolver_Group::changeConstraint( std::shared_ptr aCoinc2 = std::dynamic_pointer_cast(aConstraint); if (aCoincidence != aCoinc2 && aCoincidence->isCoincide(aCoinc2)) { - aCoincidence->attach(aCoinc2); - aConstraint = aCoincidence; + aCoinc2->attach(aCoincidence); + aCIter->second = aCoinc2; } } } diff --git a/src/SketchSolver/SketchSolver_Storage.cpp b/src/SketchSolver/SketchSolver_Storage.cpp index a716b6859..793d6d42d 100644 --- a/src/SketchSolver/SketchSolver_Storage.cpp +++ b/src/SketchSolver/SketchSolver_Storage.cpp @@ -704,7 +704,8 @@ void SketchSolver_Storage::addCoincidentPoints( aFoundIter->insert(aCIter->begin(), aCIter->end()); myCoincidentPoints.erase(aCIter); break; - } + } else + aFoundIter = aCIter; aCIter->insert(thePoint1); aCIter->insert(thePoint2); }