Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[modules/shaper.git] / src / Model / Model_Application.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_Application.cxx
4 // Created:     Fri Sep 2 2011
5 // Author:      Mikhail PONIKAROV
6
7 #include <Model_Application.h>
8 #include <Model_Document.h>
9
10 IMPLEMENT_STANDARD_HANDLE(Model_Application, TDocStd_Application)
11 IMPLEMENT_STANDARD_RTTIEXT(Model_Application, TDocStd_Application)
12
13 using namespace std;
14
15 static Handle_Model_Application TheApplication = new Model_Application;
16
17 //=======================================================================
18 Handle(Model_Application) Model_Application::getApplication()
19 {
20   return TheApplication;
21 }
22
23 //=======================================================================
24 const std::shared_ptr<Model_Document>& Model_Application::getDocument(string theDocID)
25 {
26   if (myDocs.find(theDocID) != myDocs.end())
27     return myDocs[theDocID];
28
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
38   }
39
40   return myDocs[theDocID];
41 }
42
43 void Model_Application::deleteDocument(string theDocID)
44 {
45   if (myDocs.find(theDocID) != myDocs.end()) {
46     myDocs[theDocID]->close(true);
47     myDocs.erase(theDocID);
48   }
49   myLoadedByDemand.clear();
50 }
51
52 void Model_Application::deleteAllDocuments()
53 {
54   myDocs.clear();
55   myLoadedByDemand.clear();
56 }
57
58 //=======================================================================
59 bool Model_Application::hasDocument(std::string theDocID)
60 {
61   return myDocs.find(theDocID) != myDocs.end();
62 }
63
64 //=======================================================================
65 void Model_Application::setLoadPath(std::string thePath)
66 {
67   myPath = thePath;
68 }
69
70 //=======================================================================
71 void Model_Application::setLoadByDemand(std::string theID)
72 {
73   myLoadedByDemand.insert(theID);
74 }
75
76 //=======================================================================
77 bool Model_Application::isLoadByDemand(std::string theID)
78 {
79   return myLoadedByDemand.find(theID) != myLoadedByDemand.end();
80 }
81
82 //=======================================================================
83 Model_Application::Model_Application()
84 {
85   // store handle to the application to avoid nullification
86   static Handle(Model_Application) TheKeepHandle;
87   TheKeepHandle = this;
88 }
89
90 //=======================================================================
91 void Model_Application::Formats(TColStd_SequenceOfExtendedString& theFormats)
92 {
93   theFormats.Append(TCollection_ExtendedString("BinOcaf"));  // standard binary schema
94 }
95
96 //=======================================================================
97 Standard_CString Model_Application::ResourcesName()
98 {
99   return Standard_CString("Standard");
100 }