Salome HOME
Small fix of ImportNaming.
[modules/shaper.git] / src / Model / Model_Session.cpp
index 9e87c0560c993e7d08b5084c07523f346786c9b8..159b7a2f678b19e60ac6fac4862c1881100dbeca 100644 (file)
@@ -53,6 +53,9 @@ void Model_Session::startOperation()
   static std::shared_ptr<Events_Message> aStartedMsg
     (new Events_Message(Events_Loop::eventByName("StartOperation")));
   Events_Loop::loop()->send(aStartedMsg);
+  // remove all useless documents that has been closed: on start of operation undo/redo is cleared
+  std::list<std::shared_ptr<ModelAPI_Document> > aUsedDocs = allOpenedDocuments();
+  Model_Application::getApplication()->removeUselessDocuments(aUsedDocs);
 }
 
 void Model_Session::finishOperation()
@@ -63,9 +66,15 @@ void Model_Session::finishOperation()
 void Model_Session::abortOperation()
 {
   ROOT_DOC->abortOperation();
+  // here the update mechanism may work after abort, so, supress the warnings about
+  // modifications outside of the transactions
+  bool aWasCheck = myCheckTransactions;
+  myCheckTransactions = false;
   static std::shared_ptr<Events_Message> anAbortMsg
     (new Events_Message(Events_Loop::eventByName("AbortOperation")));
   Events_Loop::loop()->send(anAbortMsg);
+  myCheckTransactions = true;
+  myCheckTransactions = aWasCheck;
 }
 
 bool Model_Session::isOperation()
@@ -100,8 +109,9 @@ void Model_Session::redo()
 
 FeaturePtr Model_Session::createFeature(string theFeatureID)
 {
-  if (this != myImpl)
+  if (this != myImpl) {
     return myImpl->createFeature(theFeatureID);
+  }
 
   // load all information about plugins, features and attributes
   LoadPluginsInfo();
@@ -117,7 +127,7 @@ FeaturePtr Model_Session::createFeature(string theFeatureID)
     myCurrentPluginName = aPlugin.first;
     if (myPluginObjs.find(myCurrentPluginName) == myPluginObjs.end()) {
       // load plugin library if not yet done
-      Config_ModuleReader::loadLibrary(myCurrentPluginName);
+      Config_ModuleReader::loadPlugin(myCurrentPluginName);
     }
     if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) {
       FeaturePtr aCreated = myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID);
@@ -183,8 +193,9 @@ std::list<std::shared_ptr<ModelAPI_Document> > Model_Session::allOpenedDocuments
     DocumentPtr anAPIDoc = *aDoc;
     std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(anAPIDoc);
     if (aDoc) {
-      std::set<std::string>::const_iterator aSubIter = aDoc->subDocuments().cbegin();
-      for(; aSubIter != aDoc->subDocuments().cend(); aSubIter++) {
+      const std::set<std::string> aSubs = aDoc->subDocuments(true);
+      std::set<std::string>::const_iterator aSubIter = aSubs.cbegin();
+      for(; aSubIter != aSubs.cend(); aSubIter++) {
         if (!Model_Application::getApplication()->isLoadByDemand(*aSubIter)) {
           aResult.push_back(Model_Application::getApplication()->getDocument(*aSubIter));
         }
@@ -291,6 +302,14 @@ void Model_Session::registerPlugin(ModelAPI_Plugin* thePlugin)
   static Events_ID EVENT_LOAD = Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED);
   ModelAPI_EventCreator::get()->sendUpdated(ObjectPtr(), EVENT_LOAD);
   Events_Loop::loop()->flush(EVENT_LOAD);
+  // If the plugin has an ability to process GUI events, register it
+  Events_Listener* aListener = dynamic_cast<Events_Listener*>(thePlugin);
+  if (aListener) {
+    Events_Loop* aLoop = Events_Loop::loop();
+    static Events_ID aStateRequestEventId =
+        Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_REQUEST);
+    aLoop->registerListener(aListener, aStateRequestEventId);
+  }
 }
 
 ModelAPI_ValidatorsFactory* Model_Session::validators()