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 IMPLEMENT_STANDARD_HANDLE(Model_Application, TDocStd_Application)
11 IMPLEMENT_STANDARD_RTTIEXT(Model_Application, TDocStd_Application)
15 static Handle_Model_Application TheApplication = new Model_Application;
17 //=======================================================================
18 Handle(Model_Application) Model_Application::getApplication()
20 return TheApplication;
23 //=======================================================================
24 const std::shared_ptr<Model_Document>& Model_Application::getDocument(string theDocID)
26 if (myDocs.find(theDocID) != myDocs.end())
27 return myDocs[theDocID];
29 static const std::string thePartSetKind("PartSet");
30 static const std::string thePartKind("Part");
31 std::shared_ptr<Model_Document> aNew(
32 new Model_Document(theDocID, theDocID == "root" ? thePartSetKind : thePartKind));
33 myDocs[theDocID] = aNew;
34 // load it if it must be loaded by demand
35 if (myLoadedByDemand.find(theDocID) != myLoadedByDemand.end() && !myPath.empty()) {
36 aNew->load(myPath.c_str());
37 myLoadedByDemand.erase(theDocID); // done, don't do it anymore
40 return myDocs[theDocID];
43 void Model_Application::deleteDocument(string theDocID)
45 if (myDocs.find(theDocID) != myDocs.end()) {
46 myDocs[theDocID]->close(true);
47 myDocs.erase(theDocID);
49 myLoadedByDemand.clear();
52 void Model_Application::deleteAllDocuments()
55 myLoadedByDemand.clear();
58 //=======================================================================
59 bool Model_Application::hasDocument(std::string theDocID)
61 return myDocs.find(theDocID) != myDocs.end();
64 //=======================================================================
65 void Model_Application::setLoadPath(std::string thePath)
70 //=======================================================================
71 const std::string& Model_Application::loadPath() const
76 //=======================================================================
77 void Model_Application::setLoadByDemand(std::string theID)
79 myLoadedByDemand.insert(theID);
82 //=======================================================================
83 bool Model_Application::isLoadByDemand(std::string theID)
85 return myLoadedByDemand.find(theID) != myLoadedByDemand.end();
88 //=======================================================================
89 void Model_Application::removeUselessDocuments(
90 std::list<std::shared_ptr<ModelAPI_Document> > theUsedDocs)
92 std::map<std::string, std::shared_ptr<Model_Document> >::iterator aDoc = myDocs.begin();
93 while(aDoc != myDocs.end()) {
95 std::list<std::shared_ptr<ModelAPI_Document> >::iterator aUsed = theUsedDocs.begin();
96 for(; !aFound && aUsed != theUsedDocs.end(); aUsed++) {
97 aFound = aDoc->second == *aUsed;
99 if (!aFound) { // remove the useless
100 aDoc->second->close();
102 aDoc = myDocs.begin();
109 //=======================================================================
110 Model_Application::Model_Application()
112 // store handle to the application to avoid nullification
113 static Handle(Model_Application) TheKeepHandle;
114 TheKeepHandle = this;
117 //=======================================================================
118 void Model_Application::Formats(TColStd_SequenceOfExtendedString& theFormats)
120 theFormats.Append(TCollection_ExtendedString("BinOcaf")); // standard binary schema
123 //=======================================================================
124 Standard_CString Model_Application::ResourcesName()
126 return Standard_CString("Standard");