X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_Application.cpp;h=a825e747104b6482f68a0b14a7bbbbcc4b13d182;hb=ca1d32b5d900a39c50749271b5dec53ed59c82af;hp=d53dc665c679dcd14f69eca5b2881a10655b910b;hpb=34b118cd5567416cde2d00a2b7d62832d62f7a51;p=modules%2Fshaper.git diff --git a/src/Model/Model_Application.cpp b/src/Model/Model_Application.cpp index d53dc665c..a825e7471 100644 --- a/src/Model/Model_Application.cpp +++ b/src/Model/Model_Application.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: Model_Application.cxx // Created: Fri Sep 2 2011 // Author: Mikhail PONIKAROV @@ -5,6 +7,8 @@ #include #include +#include + IMPLEMENT_STANDARD_HANDLE(Model_Application, TDocStd_Application) IMPLEMENT_STANDARD_RTTIEXT(Model_Application, TDocStd_Application) @@ -19,20 +23,28 @@ Handle(Model_Application) Model_Application::getApplication() } //======================================================================= -const boost::shared_ptr& Model_Application::getDocument(string theDocID) +const std::shared_ptr& Model_Application::getDocument(string theDocID) { if (myDocs.find(theDocID) != myDocs.end()) return myDocs[theDocID]; static const std::string thePartSetKind("PartSet"); static const std::string thePartKind("Part"); - boost::shared_ptr aNew( - new Model_Document(theDocID, theDocID == "root" ? thePartSetKind : thePartKind)); + bool isRoot = theDocID == "root"; // the document is root + std::shared_ptr aNew( + 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 aMessage = std::shared_ptr + (new ModelAPI_DocumentCreatedMessage(anId, this)); + aMessage->setDocument(aNew); + Events_Loop::loop()->send(aMessage); } return myDocs[theDocID]; @@ -65,6 +77,12 @@ void Model_Application::setLoadPath(std::string thePath) myPath = thePath; } +//======================================================================= +const std::string& Model_Application::loadPath() const +{ + return myPath; +} + //======================================================================= void Model_Application::setLoadByDemand(std::string theID) { @@ -77,6 +95,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() {