X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_Application.cpp;h=204cafe1418d99d1e690eb87fe5b6242cc46003a;hb=a352874d231ad2b117f55cf384c18361a0dfe67a;hp=df32ef977d7c599acfbb7dbadc23c99492533fb7;hpb=80a21be87c81ef61f0842b32e8b2ac7d4359acb4;p=modules%2Fshaper.git diff --git a/src/Model/Model_Application.cpp b/src/Model/Model_Application.cpp index df32ef977..204cafe14 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 @@ -19,17 +21,20 @@ 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]; - boost::shared_ptr aNew(new Model_Document(theDocID)); + static const std::string thePartSetKind("PartSet"); + static const std::string thePartKind("Part"); + std::shared_ptr aNew( + new Model_Document(theDocID, theDocID == "root" ? 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 + myLoadedByDemand.erase(theDocID); // done, don't do it anymore } return myDocs[theDocID]; @@ -37,7 +42,17 @@ const boost::shared_ptr& Model_Application::getDocument(string t void Model_Application::deleteDocument(string theDocID) { - myDocs.erase(theDocID); + if (myDocs.find(theDocID) != myDocs.end()) { + myDocs[theDocID]->close(true); + myDocs.erase(theDocID); + } + myLoadedByDemand.clear(); +} + +void Model_Application::deleteAllDocuments() +{ + myDocs.clear(); + myLoadedByDemand.clear(); } //======================================================================= @@ -52,12 +67,44 @@ 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) { myLoadedByDemand.insert(theID); } +//======================================================================= +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(); + aDoc = myDocs.erase(aDoc); + } else { + aDoc++; + } + } +} + //======================================================================= Model_Application::Model_Application() { @@ -69,7 +116,7 @@ Model_Application::Model_Application() //======================================================================= void Model_Application::Formats(TColStd_SequenceOfExtendedString& theFormats) { - theFormats.Append(TCollection_ExtendedString("BinOcaf")); // standard binary schema + theFormats.Append(TCollection_ExtendedString("BinOcaf")); // standard binary schema } //=======================================================================