Back to index

salome-kernel  6.5.0
DF_Application.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_Application.hxx"
00022 
00023 //Constructor
00024 DF_Application::DF_Application()
00025 {
00026   _currentID = 0;
00027 }
00028   
00029 DF_Application::~DF_Application()
00030 {
00031   _documents.clear();
00032 }
00033 
00034 //Creates a new document with given type, returns a smart pointer to
00035 //newly created document.
00036 DF_Document* DF_Application::NewDocument(const std::string& theDocumentType) 
00037 {
00038   DF_Document* aDoc = new DF_Document(theDocumentType);
00039   aDoc->_id = ++_currentID;
00040   _documents[aDoc->_id] = aDoc;
00041   aDoc->_appli = this; 
00042   return aDoc;
00043 }
00044 
00045 //Closes and removes the given Document
00046 void DF_Application::Close(const DF_Document* theDocument)
00047 {
00048   int id = -1;
00049   if(theDocument) id = theDocument->GetDocumentID();
00050 
00051   if(_documents.find(id) != _documents.end()) {
00052     _documents[id]->Clear();
00053     _documents.erase(id);
00054     delete theDocument;
00055   }
00056 }
00057 
00058 //Returns a Document by Document's ID
00059 DF_Document* DF_Application::GetDocument(int theDocumentID)
00060 {
00061   if(_documents.find(theDocumentID) == _documents.end()) return NULL;
00062 
00063   return _documents[theDocumentID];
00064 }
00065 
00066 //Returns a list of IDs of all currently opened documents
00067 std::vector<int> DF_Application::GetDocumentIDs()
00068 {
00069   std::vector<int> ids;
00070   typedef std::map<int, DF_Document*>::const_iterator DI;
00071   for(DI p = _documents.begin(); p!=_documents.end(); p++)
00072     ids.push_back(p->first);
00073   return ids;
00074 }
00075 
00076 //Returns a number of existent documents
00077 int DF_Application::NbDocuments()
00078 {
00079   return _documents.size();
00080 }
00081 
00082 
00083 //Restores a Document from the given file, returns a smart 
00084 //pointer to opened document.
00085 DF_Document* DF_Application::Open(const std::string& theFileName)
00086 {
00087   //Not implemented
00088   return NULL;
00089 }
00090 
00091 
00092 //Saves a Document in a given file with name theFileName
00093 void DF_Application::SaveAs(const DF_Document* theDocument, const std::string& theFileName)
00094 {
00095   //Not implemented
00096 }