1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "DF_definitions.hxx"
23 #include "DF_Document.hxx"
24 #include "DF_Label.hxx"
25 #include "DF_ChildIterator.hxx"
29 //Class DF_Document is container for user's data stored as a tree of Labels
30 //with assigned Attributes
32 DF_Document::DF_Document(const string& theDocumentType)
35 _type = theDocumentType;
39 DF_Document::~DF_Document()
44 DF_Application* DF_Document::GetApplication()
49 //Returns a Label of this Document with entry "0:1"
50 DF_Label DF_Document::Main()
52 if(!_main.IsNull()) return _main;
55 _root = DF_Label(new DF_LabelNode());
56 _root._node->_document = this;
59 _main = _root.FindChild(1, true);
64 //Returns a Label of this Document with entry "0:"
65 DF_Label DF_Document::Root()
67 if(!_root.IsNull()) return _root;
70 _root = DF_Label(new DF_LabelNode());
71 _root._node->_document = this;
78 //Returns an ID of this
79 int DF_Document::GetDocumentID() const
84 //Returns a type of the Document
85 string DF_Document::GetDocumentType()
90 //Clears the content of this Document
91 void DF_Document::Clear()
93 if(_root.IsNull()) return;
95 vector<DF_LabelNode*> vn;
96 DF_ChildIterator CI(_root, true);
97 for(; CI.More(); CI.Next()) {
98 DF_LabelNode* node = CI.Value()._node;
99 if(node) vn.push_back(node);
102 for(int i = 0, len = vn.size(); i<len; i++)
105 _root._node->Reset();
108 //Returns true if this document is empty
109 bool DF_Document::IsEmpty()
111 if(_root.IsNull()) return true;
113 DF_ChildIterator CI(_root, true);
114 for(; CI.More(); CI.Next()) {
115 DF_LabelNode* node = CI.Value()._node;
116 if(node->_attributes.size()) return false;
122 //Returns true if this document is modified
123 bool DF_Document::IsModified()
128 //Sets whether a document is modified
129 void DF_Document::SetModified(bool isModified)
131 _modified = isModified;
135 //Restores a content of the Document from the std::string theData
136 void DF_Document::Load(const std::string& theData)
141 //Converts a content of the Document into the std::string
142 string DF_Document::Save()