Salome HOME
Removed CASCatch
[modules/kernel.git] / src / DF / DF_Document.cxx
1 #include "DF_definitions.hxx"
2 #include "DF_Document.hxx"
3 #include "DF_Label.hxx"
4 #include "DF_ChildIterator.hxx"
5
6 using namespace std;
7
8 //Class DF_Document is container for user's data stored as a tree of Labels
9 //with assigned Attributes
10
11 DF_Document::DF_Document(const string& theDocumentType)
12 {
13   _id = -1;
14   _type = theDocumentType;
15   _modified = true;
16 }
17
18 DF_Document::~DF_Document()
19 {
20   Clear();
21 }
22
23 DF_Application* DF_Document::GetApplication()
24 {
25    return _appli;
26 }
27
28 //Returns a Label of this Document with entry "0:1"
29 DF_Label DF_Document::Main()
30 {
31   if(!_main.IsNull()) return _main;
32
33   if(_root.IsNull()) {
34     _root = DF_Label(new DF_LabelNode());
35     _root._node->_document = this;
36   }
37
38   _main = _root.FindChild(1, true);
39
40   return _main;
41 }
42
43 //Returns a Label of this Document with entry "0:"
44 DF_Label DF_Document::Root()
45 {
46   if(!_root.IsNull()) return _root;
47   
48   if(_root.IsNull()) {
49     _root = DF_Label(new DF_LabelNode());
50     _root._node->_document = this;
51   }
52
53   return _root;
54 }
55
56
57 //Returns an ID of this 
58 int DF_Document::GetDocumentID() const
59 {
60   return _id;
61 }
62
63 //Returns a type of the Document
64 string DF_Document::GetDocumentType()
65 {
66   return _type;
67 }
68
69 //Clears the content of this Document
70 void DF_Document::Clear()
71 {
72   if(_root.IsNull()) return;
73
74   vector<DF_LabelNode*> vn;
75   DF_ChildIterator CI(_root, true);
76   for(; CI.More(); CI.Next()) {
77     DF_LabelNode* node =  CI.Value()._node; 
78     if(node) vn.push_back(node);
79   }
80
81   for(int i = 0, len = vn.size(); i<len; i++)
82     delete vn[i];
83
84   _root._node->Reset();
85 }
86
87 //Returns true if this document is empty
88 bool DF_Document::IsEmpty()
89 {
90   if(_root.IsNull()) return true;
91
92   DF_ChildIterator CI(_root, true);
93   for(; CI.More(); CI.Next()) {
94     DF_LabelNode* node =  CI.Value()._node; 
95     if(node->_attributes.size()) return false;
96   }
97
98   return true;
99 }
100
101 //Returns true if this document is modified
102 bool DF_Document::IsModified()
103 {
104   return _modified;
105 }
106
107 //Sets whether a document is modified
108 void DF_Document::SetModified(bool isModified)
109 {
110   _modified = isModified;
111 }
112
113
114 //Restores a content of the Document from the std::string theData
115 void DF_Document::Load(const std::string& theData)
116 {
117    //Not implemented
118 }
119
120 //Converts a content of the Document into the std::string
121 string DF_Document::Save()
122 {
123    //Not implemented
124    return "";
125 }