]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix the problems with constraint removing
authorazv <azv@opencascade.com>
Tue, 7 Apr 2015 06:47:21 +0000 (09:47 +0300)
committerazv <azv@opencascade.com>
Tue, 7 Apr 2015 06:48:14 +0000 (09:48 +0300)
src/SketchSolver/SketchSolver_FeatureStorage.cpp
src/SketchSolver/SketchSolver_Group.cpp

index 610993a74eb5ede2eb4f1e7a634577d43da5a945..ef84612566b6d5249e188ba03c392ec2c8c76bc0 100644 (file)
@@ -91,14 +91,10 @@ void SketchSolver_FeatureStorage::removeConstraint(ConstraintPtr theConstraint)
     while (aFeatIter != myFeatures.end()) {
       aCIter = aFeatIter->second.find(theConstraint);
       if (aCIter != aFeatIter->second.end()) {
-        aFeatIter->second.erase(aCIter);
-        if (aFeatIter->second.empty()) {
-          MapFeatureConstraint::iterator aTmpIter = aFeatIter; // stores iterator for the next element, while the current is deleting
-          aTmpIter++;
-          myFeatures.erase(aFeatIter);
-          aFeatIter = aTmpIter;
-          continue;
-        }
+        FeaturePtr aFeature = aFeatIter->first;
+        aFeatIter++;
+        removeFeature(aFeature, theConstraint);
+        continue;
       }
       aFeatIter++;
     }
@@ -200,7 +196,7 @@ void SketchSolver_FeatureStorage::changeFeature(FeaturePtr theFeature, Constrain
 void SketchSolver_FeatureStorage::removeFeature(FeaturePtr theFeature)
 {
   MapFeatureConstraint::iterator aFeatIter = myFeatures.find(theFeature);
-  if (aFeatIter != myFeatures.end())
+  if (aFeatIter == myFeatures.end())
     return; // no such feature
 
   std::set<ConstraintPtr> aConstraints = aFeatIter->second;
@@ -212,7 +208,7 @@ void SketchSolver_FeatureStorage::removeFeature(FeaturePtr theFeature)
 void SketchSolver_FeatureStorage::removeFeature(FeaturePtr theFeature, ConstraintPtr theConstraint)
 {
   MapFeatureConstraint::iterator aFeatIter = myFeatures.find(theFeature);
-  if (aFeatIter != myFeatures.end())
+  if (aFeatIter == myFeatures.end())
     return; // no such feature
 
   std::list<AttributePtr> anAttributes = theFeature->data()->attributes(std::string());
@@ -287,7 +283,7 @@ void SketchSolver_FeatureStorage::removeAttribute(AttributePtr theAttribute)
 void SketchSolver_FeatureStorage::removeAttribute(AttributePtr theAttribute, FeaturePtr theFeature)
 {
   MapAttributeFeature::iterator anAttrIter = myAttributes.find(theAttribute);
-  if (anAttrIter != myAttributes.end())
+  if (anAttrIter == myAttributes.end())
     return; // no such attribute
 
   anAttrIter->second.erase(theFeature);
index 2c6d8f5763627c0d5c012814ce687a4d463d6741..b51828ba9d0eb78e560f1d934f11f9801a4642a3 100644 (file)
@@ -439,8 +439,20 @@ void SketchSolver_Group::splitGroup(std::vector<SketchSolver_Group*>& theCuts)
         anUnusedConstraints.push_back(*anIter);
   }
 
-  std::vector<SketchSolver_Group*>::iterator aCutsIter;
+  // Check the unused constraints once again, because they may become interacted with new storage since adding constraints
   std::vector<ConstraintPtr>::iterator aUnuseIt = anUnusedConstraints.begin();
+  while (aUnuseIt != anUnusedConstraints.end()) {
+    if (aNewFeatStorage->isInteract(*aUnuseIt)) {
+      size_t aShift = aUnuseIt - anUnusedConstraints.begin();
+      anUnusedConstraints.erase(aUnuseIt);
+      aUnuseIt = anUnusedConstraints.begin() + aShift;
+      continue;
+    }
+    aUnuseIt++;
+  }
+
+  std::vector<SketchSolver_Group*>::iterator aCutsIter;
+  aUnuseIt = anUnusedConstraints.begin();
   for ( ; aUnuseIt != anUnusedConstraints.end(); aUnuseIt++) {
     // Remove unused constraints
     removeConstraint(*aUnuseIt);