X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_Application.cpp;h=875e1537fb6ab1c98ae51fb527b518952bf9dd5e;hb=b912c517a85602b2e6e2045262d4ac1d7152fbfd;hp=797d00e19a6f3ae380a4c380a89da407529384c5;hpb=b501b9b003ec4f01c5369b4c281280269b596889;p=modules%2Fshaper.git diff --git a/src/Model/Model_Application.cpp b/src/Model/Model_Application.cpp index 797d00e19..875e1537f 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,11 +7,11 @@ #include #include +#include + IMPLEMENT_STANDARD_HANDLE(Model_Application, TDocStd_Application) IMPLEMENT_STANDARD_RTTIEXT(Model_Application, TDocStd_Application) -using namespace std; - static Handle_Model_Application TheApplication = new Model_Application; //======================================================================= @@ -19,48 +21,141 @@ Handle(Model_Application) Model_Application::getApplication() } //======================================================================= -const boost::shared_ptr& Model_Application::getDocument(string theDocID) +std::shared_ptr Model_Application::document(const int theDocID) { if (myDocs.find(theDocID) != myDocs.end()) return myDocs[theDocID]; + return std::shared_ptr(); // not loaded, so return null +} +//======================================================================= +void Model_Application::createDocument(const int 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)); + std::shared_ptr aNew( + new Model_Document(theDocID, theDocID == 0 ? thePartSetKind : thePartKind)); + myDocs[theDocID] = aNew; + + 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); +} + +//======================================================================= +bool Model_Application::loadDocument(const std::string theDocName, const int theDocID) +{ + static const std::string thePartKind("Part"); // root document is never loaded here + std::shared_ptr aNew(new Model_Document(theDocID, thePartKind)); myDocs[theDocID] = aNew; + + bool aRes = true; // 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 + if (myLoadedByDemand.find(theDocName) != myLoadedByDemand.end() && !myPath.empty()) { + aRes = aNew->load(myPath.c_str(), theDocName.c_str(), aNew); + myLoadedByDemand.erase(theDocName); // done, don't do it anymore + } else { // error + aRes = false; } - return myDocs[theDocID]; + return aRes; } -void Model_Application::deleteDocument(string theDocID) +//======================================================================= +void Model_Application::deleteDocument(const int theDocID) { - myDocs.erase(theDocID); + if (myDocs.find(theDocID) != myDocs.end()) { + myDocs[theDocID]->close(true); + myDocs.erase(theDocID); + } + myLoadedByDemand.clear(); } //======================================================================= -bool Model_Application::hasDocument(std::string theDocID) +void Model_Application::deleteAllDocuments() +{ + std::map >::iterator aDoc = myDocs.begin(); + for(; aDoc != myDocs.end(); aDoc++) { + if (aDoc->second->isOpened()) // here is main document was closed before subs and closed subs + aDoc->second->close(true); + } + myDocs.clear(); + myLoadedByDemand.clear(); +} + +//======================================================================= +bool Model_Application::hasDocument(const int theDocID) { return myDocs.find(theDocID) != myDocs.end(); } +//======================================================================= +bool Model_Application::hasRoot() +{ + return !myDocs.empty(); +} + +//======================================================================= +std::shared_ptr Model_Application::rootDocument() +{ + return myDocs[0]; +} + //======================================================================= 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(); + myDocs.erase(aDoc); + aDoc = myDocs.begin(); + } else { + aDoc++; + } + } +} + +int Model_Application::generateDocumentId() +{ + int aResult = int(myDocs.size()); + for(; myDocs.find(aResult) != myDocs.end(); aResult++) {} // count until the result id is unique + return aResult; +} + //======================================================================= Model_Application::Model_Application() {