]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Update coincidence constraints
authorazv <azv@opencascade.com>
Wed, 19 Aug 2015 07:00:50 +0000 (10:00 +0300)
committerazv <azv@opencascade.com>
Thu, 20 Aug 2015 12:25:56 +0000 (15:25 +0300)
src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp
src/SketchSolver/SketchSolver_ConstraintCoincidence.h
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Storage.cpp

index 5144f14fc6bcf6fce4d8a7e266abcb16c376b254..0840c3714423d08c45d6a38435cb7d14d52bc8cd 100644 (file)
@@ -32,20 +32,16 @@ bool SketchSolver_ConstraintCoincidence::hasConstraint(ConstraintPtr theConstrai
 {
   if (myBaseConstraint == theConstraint)
     return true;
-  std::map<Slvs_hConstraint, ConstraintPtr>::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<ConstraintPtr> SketchSolver_ConstraintCoincidence::constraints() const
 {
   std::list<ConstraintPtr> aConstraints;
   aConstraints.push_back(myBaseConstraint);
-  std::map<Slvs_hConstraint, ConstraintPtr>::const_iterator anIt = myExtraCoincidence.begin();
+  std::map<ConstraintPtr, Slvs_hConstraint>::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<Slvs_hEntity> aRemEnts;
     std::set<Slvs_hConstraint> aRemConstr;
     theConstraint->myStorage->getRemoved(aRemParams, aRemEnts, aRemConstr);
+
+    if (!aRemEnts.empty()) {
+      std::map<FeaturePtr, Slvs_hEntity>::iterator aFeatIt = theConstraint->myFeatureMap.begin();
+      while (aFeatIt != theConstraint->myFeatureMap.end()) {
+        if (aRemEnts.find(aFeatIt->second) != aRemEnts.end()) {
+          // remove feature
+          std::map<FeaturePtr, Slvs_hEntity>::iterator aRemoveIt = aFeatIt++;
+          theConstraint->myFeatureMap.erase(aRemoveIt);
+        } else
+          ++aFeatIt;
+      }
+      std::map<AttributePtr, Slvs_hEntity>::iterator anAttrIt = theConstraint->myAttributeMap.begin();
+      while (anAttrIt != theConstraint->myAttributeMap.end()) {
+        if (aRemEnts.find(anAttrIt->second) != aRemEnts.end()) {
+          // remove attribute
+          std::map<AttributePtr, Slvs_hEntity>::iterator aRemoveIt = anAttrIt++;
+          theConstraint->myAttributeMap.erase(aRemoveIt);
+        } else
+          ++anAttrIt;
+      }
+    }
   }
 
   // Copy data.
   addConstraint(theConstraint->myBaseConstraint);
-  std::map<Slvs_hConstraint, ConstraintPtr>::iterator aConstrIter =
+  std::map<ConstraintPtr, Slvs_hConstraint>::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<Slvs_hConstraint, ConstraintPtr>::iterator anExtraIt;
+  std::map<ConstraintPtr, Slvs_hConstraint>::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<Slvs_hConstraint, ConstraintPtr>::iterator aTempIt = anExtraIt++;
+      if (!anExtraIt->first->data() || !anExtraIt->first->data()->isValid()) {
+        std::map<ConstraintPtr, Slvs_hConstraint>::iterator aTempIt = anExtraIt++;
         if (aTempIt->first != SLVS_E_UNKNOWN) {
-          myStorage->removeConstraint(aTempIt->first);
+          myStorage->removeConstraint(aTempIt->second);
           std::vector<Slvs_hConstraint>::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<Slvs_hConstraint>::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<Slvs_hConstraint, ConstraintPtr>::iterator aTempIt = anExtraIt++;
+      if (!anExtraIt->first->data() || !anExtraIt->first->data()->isValid()) {
+        std::map<ConstraintPtr, Slvs_hConstraint>::iterator aTempIt = anExtraIt++;
         myExtraCoincidence.erase(aTempIt);
         continue;
       }
       if (mySlvsConstraints.empty()) {
-        myBaseConstraint = anExtraIt->second;
-        std::map<Slvs_hConstraint, ConstraintPtr>::iterator aTempIt = anExtraIt++;
+        myBaseConstraint = anExtraIt->first;
+        std::map<ConstraintPtr, Slvs_hConstraint>::iterator aTempIt = anExtraIt++;
         myExtraCoincidence.erase(aTempIt);
         process();
         continue;
       } else
-        addConstraint(anExtraIt->second);
+        addConstraint(anExtraIt->first);
     }
     anExtraIt++;
   }
index c1d1124af4ecdd30641c5884d21688a5767ac7a0..43354e80d4e7c907d7bafeaf74695cf8ebed297c 100644 (file)
@@ -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<Slvs_hConstraint, ConstraintPtr> myExtraCoincidence; ///< multiple coincidence of points
+  std::map<ConstraintPtr, Slvs_hConstraint> myExtraCoincidence; ///< multiple coincidence of points
   std::set<AttributePtr> myCoincidentPoints; ///< list of points under the Coincidence constraint
 };
 
index 3ee780ee097557badd2bacfcf963aa3da3ddac59..f77a22f331f34667ffe068a75fddc14116da07ca 100644 (file)
@@ -208,8 +208,8 @@ bool SketchSolver_Group::changeConstraint(
         std::shared_ptr<SketchSolver_ConstraintCoincidence> aCoinc2 =
           std::dynamic_pointer_cast<SketchSolver_ConstraintCoincidence>(aConstraint);
         if (aCoincidence != aCoinc2 && aCoincidence->isCoincide(aCoinc2)) {
-          aCoincidence->attach(aCoinc2);
-          aConstraint = aCoincidence;
+          aCoinc2->attach(aCoincidence);
+          aCIter->second = aCoinc2;
         }
       }
     }
index a716b6859b2968ccc608e3fcd68efb85b3627c7e..793d6d42d43f14ad736e1fc2f92b061fe203858e 100644 (file)
@@ -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);
     }