Salome HOME
Fix for creation in GUI and unit-test for the issue #2681
[modules/shaper.git] / src / Model / Model_Session.cpp
index c0dde0f287ea7bea7ff7f529b0ed201c658cd845..a22db3780ba50741c258ef66f0e94007c4118420 100644 (file)
@@ -72,6 +72,10 @@ bool Model_Session::save(const char* theFileName, std::list<std::string>& theRes
 void Model_Session::closeAll()
 {
   Model_Application::getApplication()->deleteAllDocuments();
+  static const Events_ID aDocChangeEvent = Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED);
+  static std::shared_ptr<Events_Message> aMsg(new Events_Message(aDocChangeEvent));
+  Events_Loop::loop()->send(aMsg);
+  Events_Loop::loop()->flush(aDocChangeEvent);
 }
 
 void Model_Session::startOperation(const std::string& theId, const bool theAttachedToNested)
@@ -577,3 +581,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();
+    }
+  }
+}