X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_Application.cpp;h=4dddb449daf686c24185616677b8f45a6df6bed1;hb=5e9152f6da5141e26c07727e26a0ec89255ade87;hp=147bb4ac29e2c4450b28c73bafa042215c8c8c18;hpb=2f89053146098946372bae4d1a3fe2e5272ab9e2;p=modules%2Fshaper.git diff --git a/src/Model/Model_Application.cpp b/src/Model/Model_Application.cpp index 147bb4ac2..4dddb449d 100644 --- a/src/Model/Model_Application.cpp +++ b/src/Model/Model_Application.cpp @@ -7,6 +7,8 @@ #include #include +#include + IMPLEMENT_STANDARD_HANDLE(Model_Application, TDocStd_Application) IMPLEMENT_STANDARD_RTTIEXT(Model_Application, TDocStd_Application) @@ -28,13 +30,22 @@ const std::shared_ptr& 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 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()); + aNew->load(myPath.c_str(), aNew); myLoadedByDemand.erase(theDocID); // done, don't do it anymore + } else { + aNew->setThis(aNew); + static Events_ID anId = ModelAPI_DocumentCreatedMessage::eventId(); + std::shared_ptr aMessage = std::shared_ptr + (new ModelAPI_DocumentCreatedMessage(anId, this)); + aMessage->setDocument(aNew); + Events_Loop::loop()->send(aMessage); } return myDocs[theDocID]; @@ -51,6 +62,10 @@ void Model_Application::deleteDocument(string theDocID) void Model_Application::deleteAllDocuments() { + std::map >::iterator aDoc = myDocs.begin(); + for(; aDoc != myDocs.end(); aDoc++) { + aDoc->second->close(true); + } myDocs.clear(); myLoadedByDemand.clear(); } @@ -85,6 +100,27 @@ bool Model_Application::isLoadByDemand(std::string theID) return myLoadedByDemand.find(theID) != myLoadedByDemand.end(); } +//======================================================================= +void Model_Application::removeUselessDocuments( + std::list > theUsedDocs) +{ + std::map >::iterator aDoc = myDocs.begin(); + while(aDoc != myDocs.end()) { + bool aFound = false; + std::list >::iterator aUsed = theUsedDocs.begin(); + for(; !aFound && aUsed != theUsedDocs.end(); aUsed++) { + aFound = aDoc->second == *aUsed; + } + if (!aFound) { // remove the useless + aDoc->second->close(); + myDocs.erase(aDoc); + aDoc = myDocs.begin(); + } else { + aDoc++; + } + } +} + //======================================================================= Model_Application::Model_Application() {