Salome HOME
Make initialization plugin:
[modules/shaper.git] / src / Model / Model_Application.cpp
index 204cafe1418d99d1e690eb87fe5b6242cc46003a..a825e747104b6482f68a0b14a7bbbbcc4b13d182 100644 (file)
@@ -7,6 +7,8 @@
 #include <Model_Application.h>
 #include <Model_Document.h>
 
+#include <ModelAPI_Events.h>
+
 IMPLEMENT_STANDARD_HANDLE(Model_Application, TDocStd_Application)
 IMPLEMENT_STANDARD_RTTIEXT(Model_Application, TDocStd_Application)
 
@@ -28,13 +30,21 @@ const std::shared_ptr<Model_Document>& Model_Application::getDocument(string the
 
   static const std::string thePartSetKind("PartSet");
   static const std::string thePartKind("Part");
+  bool isRoot = theDocID == "root"; // the document is root
   std::shared_ptr<Model_Document> aNew(
-    new Model_Document(theDocID, theDocID == "root" ? thePartSetKind : thePartKind));
+    new Model_Document(theDocID, isRoot ? thePartSetKind : thePartKind));
   myDocs[theDocID] = aNew;
+
   // load it if it must be loaded by demand
   if (myLoadedByDemand.find(theDocID) != myLoadedByDemand.end() && !myPath.empty()) {
     aNew->load(myPath.c_str());
     myLoadedByDemand.erase(theDocID);  // done, don't do it anymore
+  } else {
+    static Events_ID anId = ModelAPI_DocumentCreatedMessage::eventId();
+    std::shared_ptr<ModelAPI_DocumentCreatedMessage> aMessage = std::shared_ptr
+      <ModelAPI_DocumentCreatedMessage>(new ModelAPI_DocumentCreatedMessage(anId, this));
+    aMessage->setDocument(aNew);
+    Events_Loop::loop()->send(aMessage);
   }
 
   return myDocs[theDocID];
@@ -98,7 +108,8 @@ void Model_Application::removeUselessDocuments(
     }
     if (!aFound) { // remove the useless
       aDoc->second->close();
-      aDoc = myDocs.erase(aDoc);
+      myDocs.erase(aDoc);
+      aDoc = myDocs.begin();
     } else {
       aDoc++;
     }