Salome HOME
Merge branch 'master' into BR_PYTHON_PLUGIN
[modules/shaper.git] / src / Model / Model_Application.cpp
1 // File:        Model_Application.cxx
2 // Created:     Fri Sep 2 2011
3 // Author:      Mikhail PONIKAROV
4
5 #include <Model_Application.h>
6 #include <Model_Document.h>
7
8 IMPLEMENT_STANDARD_HANDLE(Model_Application, TDocStd_Application)
9 IMPLEMENT_STANDARD_RTTIEXT(Model_Application, TDocStd_Application)
10
11 using namespace std;
12
13 static Handle_Model_Application TheApplication = new Model_Application;
14
15 //=======================================================================
16 Handle(Model_Application) Model_Application::getApplication()
17 {
18   return TheApplication;
19 }
20
21 //=======================================================================
22 const boost::shared_ptr<Model_Document>& Model_Application::getDocument(string theDocID)
23 {
24   if (myDocs.find(theDocID) != myDocs.end())
25     return myDocs[theDocID];
26
27   static const std::string thePartSetKind("PartSet");
28   static const std::string thePartKind("Part");
29   boost::shared_ptr<Model_Document> aNew(
30     new Model_Document(theDocID, theDocID == "root" ? thePartSetKind : thePartKind));
31   myDocs[theDocID] = aNew;
32   // load it if it must be loaded by demand
33   if (myLoadedByDemand.find(theDocID) != myLoadedByDemand.end() && !myPath.empty()) {
34     aNew->load(myPath.c_str());
35     myLoadedByDemand.erase(theDocID);  // done, don't do it anymore
36   }
37
38   return myDocs[theDocID];
39 }
40
41 void Model_Application::deleteDocument(string theDocID)
42 {
43   if (myDocs.find(theDocID) != myDocs.end()) {
44     myDocs[theDocID]->close(true);
45     myDocs.erase(theDocID);
46   }
47   myLoadedByDemand.clear();
48 }
49
50 void Model_Application::deleteAllDocuments()
51 {
52   myDocs.clear();
53   myLoadedByDemand.clear();
54 }
55
56 //=======================================================================
57 bool Model_Application::hasDocument(std::string theDocID)
58 {
59   return myDocs.find(theDocID) != myDocs.end();
60 }
61
62 //=======================================================================
63 void Model_Application::setLoadPath(std::string thePath)
64 {
65   myPath = thePath;
66 }
67
68 //=======================================================================
69 void Model_Application::setLoadByDemand(std::string theID)
70 {
71   myLoadedByDemand.insert(theID);
72 }
73
74 //=======================================================================
75 bool Model_Application::isLoadByDemand(std::string theID)
76 {
77   return myLoadedByDemand.find(theID) != myLoadedByDemand.end();
78 }
79
80 //=======================================================================
81 Model_Application::Model_Application()
82 {
83   // store handle to the application to avoid nullification
84   static Handle(Model_Application) TheKeepHandle;
85   TheKeepHandle = this;
86 }
87
88 //=======================================================================
89 void Model_Application::Formats(TColStd_SequenceOfExtendedString& theFormats)
90 {
91   theFormats.Append(TCollection_ExtendedString("BinOcaf"));  // standard binary schema
92 }
93
94 //=======================================================================
95 Standard_CString Model_Application::ResourcesName()
96 {
97   return Standard_CString("Standard");
98 }