Salome HOME
Add tutorial help page.
[modules/shaper.git] / src / Model / Model_Session.cpp
index 065e6276dbd5e8e95bc5ac4ba7ea445040af3ad6..2a830e788a740f3414a5ad29d9de423470f07db3 100644 (file)
@@ -464,6 +464,9 @@ void Model_Session::processEvent(const std::shared_ptr<Events_Message>& theMessa
         if(aMsgAttr->isConcealment()) {
           validators()->registerConcealment(aMsgAttr->featureId(), aMsgAttr->attributeId());
         }
+        if(aMsgAttr->isMainArgument()) {
+          validators()->registerMainArgument(aMsgAttr->featureId(), aMsgAttr->attributeId());
+        }
         const std::list<std::pair<std::string, std::string> >& aCases = aMsgAttr->getCases();
         if (!aCases.empty()) {
           validators()->registerCase(aMsgAttr->featureId(), aMsgAttr->attributeId(), aCases);
@@ -501,8 +504,14 @@ void Model_Session::processEvent(const std::shared_ptr<Events_Message>& theMessa
     if (theMessage->eventID() == kDeletedEvent) {
       std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDeleted =
         std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
-      if (aDeleted &&
-          aDeleted->groups().find(ModelAPI_ResultPart::group()) != aDeleted->groups().end())
+
+      std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>::const_iterator
+        aGIter = aDeleted->groups().cbegin();
+      for (; aGIter != aDeleted->groups().cend(); aGIter++) {
+        if (aGIter->second == ModelAPI_ResultPart::group())
+          break;
+      }
+      if (aGIter != aDeleted->groups().cend())
       {
          // check that the current feature of the session is still the active Part (even disabled)
         bool aFound = false;
@@ -568,3 +577,42 @@ int Model_Session::transactionID()
 {
   return ROOT_DOC->transactionID();
 }
+
+bool Model_Session::isAutoUpdateBlocked()
+{
+  Handle(Model_Application) anApp = Model_Application::getApplication();
+  if (!anApp->hasRoot()) // when document is not yet created, do not create it by such simple call
+    return false;
+  return !ROOT_DOC->autoRecomutationState();
+}
+
+void Model_Session::blockAutoUpdate(const bool theBlock)
+{
+  bool aCurrentState = isAutoUpdateBlocked();
+  if (aCurrentState != theBlock) {
+    // if there is no operation, start it to avoid modifications outside of transaction
+    bool isOperation = this->isOperation();
+    if (!isOperation)
+      startOperation("Auto update");
+    ROOT_DOC->setAutoRecomutationState(!theBlock);
+    static Events_Loop* aLoop = Events_Loop::loop();
+    if (theBlock) {
+      static const Events_ID kAutoOff = aLoop->eventByName(EVENT_AUTOMATIC_RECOMPUTATION_DISABLE);
+      std::shared_ptr<Events_Message> aMsg(new Events_Message(kAutoOff));
+      aLoop->send(aMsg);
+    } else {
+      // if there is no operation, start it to avoid modifications outside of transaction
+      bool isOperation = this->isOperation();
+      if (!isOperation)
+        startOperation("Auto update enabling");
+      static const Events_ID kAutoOn = aLoop->eventByName(EVENT_AUTOMATIC_RECOMPUTATION_ENABLE);
+      std::shared_ptr<Events_Message> aMsg(new Events_Message(kAutoOn));
+      aLoop->send(aMsg);
+    }
+    if (!isOperation) {
+      finishOperation();
+      // append this transaction to the previous one: ne don't need this separated operation in list
+      ROOT_DOC->appendTransactionToPrevious();
+    }
+  }
+}