Salome HOME
Fix for hang up (and crash after) on remove of all features in the complicated model...
[modules/shaper.git] / src / ModelAPI / ModelAPI_Feature.cpp
index 3ba486be3b2ba2c4fb1f15fc8f614b8a67e541bd..9edfefa4c8f69ed57c5128ecadbc25342d675016 100644 (file)
@@ -17,7 +17,7 @@ const std::list<std::shared_ptr<ModelAPI_Result> >& ModelAPI_Feature::results()
   return myResults;
 }
 
-std::shared_ptr<ModelAPI_Result> ModelAPI_Feature::firstResult()
+std::shared_ptr<ModelAPI_Result> ModelAPI_Feature::firstResult() const
 {
   return myResults.empty() ? std::shared_ptr<ModelAPI_Result>() : *(myResults.begin());
 }
@@ -79,13 +79,14 @@ void ModelAPI_Feature::eraseResultFromList(const std::shared_ptr<ModelAPI_Result
     ResultPtr aRes = *aResIter;
     if (aRes == theResult) {
       std::string aGroup = aRes->groupName();
+      aRes->setDisabled(aRes, true); // for complex results to disable all subs
       aRes->data()->erase();
       myResults.erase(aResIter);
 
       static Events_Loop* aLoop = Events_Loop::loop();
       static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
       static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
-      ModelAPI_EventCreator::get()->sendDeleted(document(), aGroup);
+      aECreator->sendDeleted(document(), aGroup);
       aECreator->sendUpdated(aRes, EVENT_DISP);
       break;
     }
@@ -103,12 +104,12 @@ void ModelAPI_Feature::removeResults(const int theSinceIndex, const bool theFlus
   while( aNextIter != myResults.end()) {
     aGroup = (*aNextIter)->groupName();
     // remove previously erased results: to enable later if needed only actual (of history change)
-    if (theSinceIndex == 0 && (*aNextIter)->isDisabled()) {
-      aNextIter = myResults.erase(aNextIter);
-    } else {
+    //if (theSinceIndex == 0 && (*aNextIter)->isDisabled()) {
+    //  aNextIter = myResults.erase(aNextIter);
+    //} else {
       (*aNextIter)->setDisabled(*aNextIter, true); // just disable results
       aNextIter++;
-    }
+    //}
   }
   if (!aGroup.empty() && theFlush) {
     // flush visualisation changes
@@ -146,7 +147,8 @@ void ModelAPI_Feature::erase()
   while (!myResults.empty()) {  // remove one by one with messages
     std::shared_ptr<ModelAPI_Result> aRes = *(myResults.begin());
     aRes->setDisabled(aRes, true); // to avoid activation of the Part result
-    myResults.erase(myResults.begin());
+    if (!myResults.empty()) // disabling result may erase the list (on undo of Part, issue 665)
+      myResults.erase(myResults.begin());
   }
   ModelAPI_Object::erase();
 }
@@ -192,7 +194,7 @@ bool ModelAPI_Feature::setDisabled(const bool theFlag)
   return false;
 }
 
-bool ModelAPI_Feature::isDisabled() const
+bool ModelAPI_Feature::isDisabled()
 {
   return myIsDisabled;
 }
@@ -201,3 +203,8 @@ bool ModelAPI_Feature::isPreviewNeeded() const
 {
   return true;
 }
+
+void ModelAPI_Feature::init()
+{
+  myIsDisabled = false;
+}