Back to index

salome-kernel  6.5.0
DF_Document.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "DF_definitions.hxx"
00021 #include "DF_Document.hxx"
00022 #include "DF_Label.hxx"
00023 #include "DF_ChildIterator.hxx"
00024 
00025 //Class DF_Document is container for user's data stored as a tree of Labels
00026 //with assigned Attributes
00027 
00028 DF_Document::DF_Document(const std::string& theDocumentType)
00029 {
00030   _id = -1;
00031   _type = theDocumentType;
00032   _modified = true;
00033 }
00034 
00035 DF_Document::~DF_Document()
00036 {
00037   Clear();
00038 }
00039 
00040 DF_Application* DF_Document::GetApplication()
00041 {
00042    return _appli;
00043 }
00044 
00045 //Returns a Label of this Document with entry "0:1"
00046 DF_Label DF_Document::Main()
00047 {
00048   if(!_main.IsNull()) return _main;
00049 
00050   if(_root.IsNull()) {
00051     _root = DF_Label(new DF_LabelNode());
00052     _root._node->_document = this;
00053   }
00054 
00055   _main = _root.FindChild(1, true);
00056 
00057   return _main;
00058 }
00059 
00060 //Returns a Label of this Document with entry "0:"
00061 DF_Label DF_Document::Root()
00062 {
00063   if(!_root.IsNull()) return _root;
00064   
00065   if(_root.IsNull()) {
00066     _root = DF_Label(new DF_LabelNode());
00067     _root._node->_document = this;
00068   }
00069 
00070   return _root;
00071 }
00072 
00073 
00074 //Returns an ID of this 
00075 int DF_Document::GetDocumentID() const
00076 {
00077   return _id;
00078 }
00079 
00080 //Returns a type of the Document
00081 std::string DF_Document::GetDocumentType()
00082 {
00083   return _type;
00084 }
00085 
00086 //Clears the content of this Document
00087 void DF_Document::Clear()
00088 {
00089   if(_root.IsNull()) return;
00090 
00091   std::vector<DF_LabelNode*> vn;
00092   DF_ChildIterator CI(_root, true);
00093   for(; CI.More(); CI.Next()) {
00094     DF_LabelNode* node =  CI.Value()._node; 
00095     if(node) vn.push_back(node);
00096   }
00097 
00098   for(int i = 0, len = vn.size(); i<len; i++)
00099     delete vn[i];
00100 
00101   _root._node->Reset();
00102   _root.Nullify();
00103 }
00104 
00105 //Returns true if this document is empty
00106 bool DF_Document::IsEmpty()
00107 {
00108   if(_root.IsNull()) return true;
00109 
00110   DF_ChildIterator CI(_root, true);
00111   for(; CI.More(); CI.Next()) {
00112     DF_LabelNode* node =  CI.Value()._node; 
00113     if(node->_attributes.size()) return false;
00114   }
00115 
00116   return true;
00117 }
00118 
00119 //Returns true if this document is modified
00120 bool DF_Document::IsModified()
00121 {
00122   return _modified;
00123 }
00124 
00125 //Sets whether a document is modified
00126 void DF_Document::SetModified(bool isModified)
00127 {
00128   _modified = isModified;
00129 }
00130 
00131 
00132 //Restores a content of the Document from the std::string theData
00133 void DF_Document::Load(const std::string& theData)
00134 {
00135    //Not implemented
00136 }
00137 
00138 //Converts a content of the Document into the std::string
00139 std::string DF_Document::Save()
00140 {
00141    //Not implemented
00142    return "";
00143 }