Salome HOME
Update of icons: recover, split, construction planes subtypes
[modules/shaper.git] / src / ModelAPI / ModelAPI_Feature.cpp
index 3ba486be3b2ba2c4fb1f15fc8f614b8a67e541bd..ad496462bd8c70e183b6e5574b320543313a0442 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,12 +194,42 @@ bool ModelAPI_Feature::setDisabled(const bool theFlag)
   return false;
 }
 
-bool ModelAPI_Feature::isDisabled() const
+bool ModelAPI_Feature::isDisabled()
 {
   return myIsDisabled;
 }
 
+bool ModelAPI_Feature::setStable(const bool theFlag)
+{
+  if (myIsStable != theFlag) {
+    myIsStable = theFlag;
+    // send an event about the stability change (editing is started/finished)
+    static Events_Loop* aLoop = Events_Loop::loop();
+    static Events_ID EVENT_STAB = aLoop->eventByName(EVENT_STABILITY_CHANGED);
+    std::shared_ptr<Events_Message> aMessage(new Events_Message(EVENT_STAB, this));
+    aLoop->send(aMessage, false);
+    return true;
+  }
+  return false;
+}
+
+bool ModelAPI_Feature::isStable()
+{
+  return myIsStable;
+}
+
+bool ModelAPI_Feature::customAction(const std::string& theActionId)
+{
+  return false;
+}
+
 bool ModelAPI_Feature::isPreviewNeeded() const
 {
   return true;
 }
+
+void ModelAPI_Feature::init()
+{
+  myIsDisabled = false;
+  myIsStable = true;
+}