Salome HOME
97a9028c6fb2a152b8f7129d0069733dcf06ad02
[modules/kernel.git] / src / DF / DF_Document.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "DF_definitions.hxx"
21 #include "DF_Document.hxx"
22 #include "DF_Label.hxx"
23 #include "DF_ChildIterator.hxx"
24
25 //Class DF_Document is container for user's data stored as a tree of Labels
26 //with assigned Attributes
27
28 DF_Document::DF_Document(const std::string& theDocumentType)
29 {
30   _id = -1;
31   _type = theDocumentType;
32   _modified = false;
33 }
34
35 DF_Document::~DF_Document()
36 {
37   Clear();
38 }
39
40 DF_Application* DF_Document::GetApplication()
41 {
42    return _appli;
43 }
44
45 //Returns a Label of this Document with entry "0:1"
46 DF_Label DF_Document::Main()
47 {
48   if(!_main.IsNull()) return _main;
49
50   if(_root.IsNull()) {
51     _root = DF_Label(new DF_LabelNode());
52     _root._node->_document = this;
53   }
54
55   _main = _root.FindChild(1, true);
56
57   return _main;
58 }
59
60 //Returns a Label of this Document with entry "0:"
61 DF_Label DF_Document::Root()
62 {
63   if(!_root.IsNull()) return _root;
64   
65   if(_root.IsNull()) {
66     _root = DF_Label(new DF_LabelNode());
67     _root._node->_document = this;
68   }
69
70   return _root;
71 }
72
73
74 //Returns an ID of this 
75 int DF_Document::GetDocumentID() const
76 {
77   return _id;
78 }
79
80 //Returns a type of the Document
81 std::string DF_Document::GetDocumentType()
82 {
83   return _type;
84 }
85
86 //Clears the content of this Document
87 void DF_Document::Clear()
88 {
89   if(_root.IsNull()) return;
90
91   std::vector<DF_LabelNode*> vn;
92   DF_ChildIterator CI(_root, true);
93   for(; CI.More(); CI.Next()) {
94     DF_LabelNode* node =  CI.Value()._node; 
95     if(node) vn.push_back(node);
96   }
97
98   for(size_t i = 0, len = vn.size(); i<len; i++)
99     delete vn[i];
100
101   _root._node->Reset();
102   _root.Nullify();
103 }
104
105 //Returns true if this document is empty
106 bool DF_Document::IsEmpty()
107 {
108   if(_root.IsNull()) return true;
109
110   DF_ChildIterator CI(_root, true);
111   for(; CI.More(); CI.Next()) {
112     DF_LabelNode* node =  CI.Value()._node; 
113     if(node->_attributes.size()) return false;
114   }
115
116   return true;
117 }
118
119 //Returns true if this document is modified
120 bool DF_Document::IsModified()
121 {
122   return _modified;
123 }
124
125 //Sets whether a document is modified
126 void DF_Document::SetModified(bool isModified)
127 {
128   _modified = isModified;
129 }
130
131
132 //Restores a content of the Document from the std::string theData
133 void DF_Document::Load(const std::string& /*theData*/)
134 {
135    //Not implemented
136 }
137
138 //Converts a content of the Document into the std::string
139 std::string DF_Document::Save()
140 {
141    //Not implemented
142    return "";
143 }