Salome HOME
Merge remote-tracking branch 'remotes/origin/Dev_ResultNames'
[modules/shaper.git] / src / Model / Model_ResultCompSolid.cpp
index 231c0b6ed33290d915c5cfecb54ecccf1c1ed401..2446e4048e2582c495b42e8d7165bd3d9b26131b 100755 (executable)
@@ -98,12 +98,13 @@ std::shared_ptr<ModelAPI_ResultBody> Model_ResultCompSolid::subResult(const int
   return mySubs.at(theIndex);
 }
 
-bool Model_ResultCompSolid::isSub(ObjectPtr theObject) const
+bool Model_ResultCompSolid::isSub(ObjectPtr theObject, int& theIndex) const
 {
-  std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
-  for(; aSubIter != mySubs.cend(); aSubIter++)
-    if (*aSubIter == theObject)
-      return true;
+  std::map<ObjectPtr, int>::const_iterator aFound = mySubsMap.find(theObject);
+  if (aFound != mySubsMap.end()) {
+    theIndex = aFound->second;
+    return true;
+  }
   return false;
 }
 
@@ -213,6 +214,7 @@ void Model_ResultCompSolid::updateSubs(const std::shared_ptr<GeomAPI_Shape>& the
       if (mySubs.size() <= aSubIndex) { // it is needed to create a new sub-result
         aSub = anObjects->createBody(this->data(), aSubIndex);
         mySubs.push_back(aSub);
+        mySubsMap[aSub] = int(mySubs.size() - 1);
       } else { // just update shape of this result
         aSub = mySubs[aSubIndex];
       }
@@ -228,6 +230,7 @@ void Model_ResultCompSolid::updateSubs(const std::shared_ptr<GeomAPI_Shape>& the
     while(mySubs.size() > aSubIndex) {
       ResultBodyPtr anErased = *(mySubs.rbegin());
       anErased->setDisabled(anErased, true);
+      mySubsMap.erase(anErased);
       mySubs.pop_back();
     }
     if (aWasEmpty) { // erase all subs
@@ -237,10 +240,10 @@ void Model_ResultCompSolid::updateSubs(const std::shared_ptr<GeomAPI_Shape>& the
   } else if (!mySubs.empty()) { // erase all subs
     while(!mySubs.empty()) {
       ResultBodyPtr anErased = *(mySubs.rbegin());
-      if (anErased->data()->isValid())
-        anErased->setDisabled(anErased, true);
+      anErased->setDisabled(anErased, true); // even if it is invalid (to erase subs on abort/undo)
       mySubs.pop_back();
     }
+    mySubsMap.clear();
     // redisplay this because result with and without subs are displayed differently
     aECreator->sendUpdated(data()->owner(), EVENT_DISP);
   }