Salome HOME
updated copyright message
[modules/kernel.git] / src / DF / DF_Application.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, 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_Application.hxx"
22
23 //Constructor
24 DF_Application::DF_Application()
25 {
26   _currentID = 0;
27 }
28   
29 DF_Application::~DF_Application()
30 {
31   _documents.clear();
32 }
33
34 //Creates a new document with given type, returns a smart pointer to
35 //newly created document.
36 DF_Document* DF_Application::NewDocument(const std::string& theDocumentType) 
37 {
38   DF_Document* aDoc = new DF_Document(theDocumentType);
39   aDoc->_id = ++_currentID;
40   _documents[aDoc->_id] = aDoc;
41   aDoc->_appli = this; 
42   return aDoc;
43 }
44
45 //Closes and removes the given Document
46 void DF_Application::Close(const DF_Document* theDocument)
47 {
48   int id = -1;
49   if(theDocument) id = theDocument->GetDocumentID();
50
51   if(_documents.find(id) != _documents.end()) {
52     _documents[id]->Clear();
53     _documents.erase(id);
54     delete theDocument;
55   }
56 }
57
58 //Returns a Document by Document's ID
59 DF_Document* DF_Application::GetDocument(int theDocumentID)
60 {
61   if(_documents.find(theDocumentID) == _documents.end()) return NULL;
62
63   return _documents[theDocumentID];
64 }
65
66 //Returns a list of IDs of all currently opened documents
67 std::vector<int> DF_Application::GetDocumentIDs()
68 {
69   std::vector<int> ids;
70   typedef std::map<int, DF_Document*>::const_iterator DI;
71   for(DI p = _documents.begin(); p!=_documents.end(); p++)
72     ids.push_back(p->first);
73   return ids;
74 }
75
76 //Returns a number of existent documents
77 int DF_Application::NbDocuments()
78 {
79   return (int)_documents.size() ;
80 }
81
82
83 //Restores a Document from the given file, returns a smart 
84 //pointer to opened document.
85 DF_Document* DF_Application::Open(const std::string& /*theFileName*/)
86 {
87   //Not implemented
88   return NULL;
89 }
90
91
92 //Saves a Document in a given file with name theFileName
93 void DF_Application::SaveAs(const DF_Document* /*theDocument*/, const std::string& /*theFileName*/)
94 {
95   //Not implemented
96 }