1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_Application.cxx
4 // Created: Fri Sep 2 2011
5 // Author: Mikhail PONIKAROV
7 #include <Model_Application.h>
8 #include <Model_Document.h>
10 #include <ModelAPI_Events.h>
12 IMPLEMENT_STANDARD_HANDLE(Model_Application, TDocStd_Application)
13 IMPLEMENT_STANDARD_RTTIEXT(Model_Application, TDocStd_Application)
17 static Handle_Model_Application TheApplication = new Model_Application;
19 //=======================================================================
20 Handle(Model_Application) Model_Application::getApplication()
22 return TheApplication;
25 //=======================================================================
26 const std::shared_ptr<Model_Document>& Model_Application::getDocument(string theDocID)
28 if (myDocs.find(theDocID) != myDocs.end())
29 return myDocs[theDocID];
31 static const std::string thePartSetKind("PartSet");
32 static const std::string thePartKind("Part");
33 bool isRoot = theDocID == "root"; // the document is root
34 std::shared_ptr<Model_Document> aNew(
35 new Model_Document(theDocID, isRoot ? thePartSetKind : thePartKind));
36 myDocs[theDocID] = aNew;
38 // load it if it must be loaded by demand
39 if (myLoadedByDemand.find(theDocID) != myLoadedByDemand.end() && !myPath.empty()) {
40 aNew->load(myPath.c_str());
41 myLoadedByDemand.erase(theDocID); // done, don't do it anymore
43 static Events_ID anId = ModelAPI_DocumentCreatedMessage::eventId();
44 std::shared_ptr<ModelAPI_DocumentCreatedMessage> aMessage = std::shared_ptr
45 <ModelAPI_DocumentCreatedMessage>(new ModelAPI_DocumentCreatedMessage(anId, this));
46 aMessage->setDocument(aNew);
47 Events_Loop::loop()->send(aMessage);
50 return myDocs[theDocID];
53 void Model_Application::deleteDocument(string theDocID)
55 if (myDocs.find(theDocID) != myDocs.end()) {
56 myDocs[theDocID]->close(true);
57 myDocs.erase(theDocID);
59 myLoadedByDemand.clear();
62 void Model_Application::deleteAllDocuments()
64 std::map<std::string, std::shared_ptr<Model_Document> >::iterator aDoc = myDocs.begin();
65 for(; aDoc != myDocs.end(); aDoc++) {
66 aDoc->second->close();
69 myLoadedByDemand.clear();
72 //=======================================================================
73 bool Model_Application::hasDocument(std::string theDocID)
75 return myDocs.find(theDocID) != myDocs.end();
78 //=======================================================================
79 void Model_Application::setLoadPath(std::string thePath)
84 //=======================================================================
85 const std::string& Model_Application::loadPath() const
90 //=======================================================================
91 void Model_Application::setLoadByDemand(std::string theID)
93 myLoadedByDemand.insert(theID);
96 //=======================================================================
97 bool Model_Application::isLoadByDemand(std::string theID)
99 return myLoadedByDemand.find(theID) != myLoadedByDemand.end();
102 //=======================================================================
103 void Model_Application::removeUselessDocuments(
104 std::list<std::shared_ptr<ModelAPI_Document> > theUsedDocs)
106 std::map<std::string, std::shared_ptr<Model_Document> >::iterator aDoc = myDocs.begin();
107 while(aDoc != myDocs.end()) {
109 std::list<std::shared_ptr<ModelAPI_Document> >::iterator aUsed = theUsedDocs.begin();
110 for(; !aFound && aUsed != theUsedDocs.end(); aUsed++) {
111 aFound = aDoc->second == *aUsed;
113 if (!aFound) { // remove the useless
114 aDoc->second->close();
116 aDoc = myDocs.begin();
123 //=======================================================================
124 Model_Application::Model_Application()
126 // store handle to the application to avoid nullification
127 static Handle(Model_Application) TheKeepHandle;
128 TheKeepHandle = this;
131 //=======================================================================
132 void Model_Application::Formats(TColStd_SequenceOfExtendedString& theFormats)
134 theFormats.Append(TCollection_ExtendedString("BinOcaf")); // standard binary schema
137 //=======================================================================
138 Standard_CString Model_Application::ResourcesName()
140 return Standard_CString("Standard");