1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "DF_definitions.hxx"
21 #include "DF_Document.hxx"
22 #include "DF_Label.hxx"
23 #include "DF_ChildIterator.hxx"
25 //Class DF_Document is container for user's data stored as a tree of Labels
26 //with assigned Attributes
28 DF_Document::DF_Document(const std::string& theDocumentType)
31 _type = theDocumentType;
35 DF_Document::~DF_Document()
40 DF_Application* DF_Document::GetApplication()
45 //Returns a Label of this Document with entry "0:1"
46 DF_Label DF_Document::Main()
48 if(!_main.IsNull()) return _main;
51 _root = DF_Label(new DF_LabelNode());
52 _root._node->_document = this;
55 _main = _root.FindChild(1, true);
60 //Returns a Label of this Document with entry "0:"
61 DF_Label DF_Document::Root()
63 if(!_root.IsNull()) return _root;
66 _root = DF_Label(new DF_LabelNode());
67 _root._node->_document = this;
74 //Returns an ID of this
75 int DF_Document::GetDocumentID() const
80 //Returns a type of the Document
81 std::string DF_Document::GetDocumentType()
86 //Clears the content of this Document
87 void DF_Document::Clear()
89 if(_root.IsNull()) return;
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);
98 for(size_t i = 0, len = vn.size(); i<len; i++)
101 _root._node->Reset();
105 //Returns true if this document is empty
106 bool DF_Document::IsEmpty()
108 if(_root.IsNull()) return true;
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;
119 //Returns true if this document is modified
120 bool DF_Document::IsModified()
125 //Sets whether a document is modified
126 void DF_Document::SetModified(bool isModified)
128 _modified = isModified;
132 //Restores a content of the Document from the std::string theData
133 void DF_Document::Load(const std::string& /*theData*/)
138 //Converts a content of the Document into the std::string
139 std::string DF_Document::Save()