Salome HOME
Removed CASCatch
[modules/kernel.git] / src / DF / DF_Application.cxx
1 #include "DF_definitions.hxx"
2 #include "DF_Application.hxx"
3
4 using namespace std;
5
6 //Constructor
7 DF_Application::DF_Application()
8 {
9   _currentID = 0;
10 }
11   
12 DF_Application::~DF_Application()
13 {
14   _documents.clear();
15 }
16
17 //Creates a new document with given type, returns a smart pointer to
18 //newly created document.
19 DF_Document* DF_Application::NewDocument(const string& theDocumentType) 
20 {
21   DF_Document* aDoc = new DF_Document(theDocumentType);
22   aDoc->_id = ++_currentID;
23   _documents[aDoc->_id] = aDoc;
24   aDoc->_appli = this; 
25   return aDoc;
26 }
27
28 //Closes and removes the given Document
29 void DF_Application::Close(const DF_Document* theDocument)
30 {
31   int id = -1;
32   if(theDocument) id = theDocument->GetDocumentID();
33
34   if(_documents.find(id) != _documents.end()) {
35     _documents[id]->Clear();
36     _documents.erase(id);
37     delete theDocument;
38   }
39 }
40
41 //Returns a Document by Document's ID
42 DF_Document* DF_Application::GetDocument(int theDocumentID)
43 {
44   if(_documents.find(theDocumentID) == _documents.end()) return NULL;
45
46   return _documents[theDocumentID];
47 }
48
49 //Returns a list of IDs of all currently opened documents
50 vector<int> DF_Application::GetDocumentIDs()
51 {
52   vector<int> ids;
53  typedef map<int, DF_Document*>::const_iterator DI;
54   for(DI p = _documents.begin(); p!=_documents.end(); p++)
55     ids.push_back(p->first);
56   return ids;
57 }
58
59 //Returns a number of existent documents
60 int DF_Application::NbDocuments()
61 {
62   return _documents.size();
63 }
64
65
66 //Restores a Document from the given file, returns a smart 
67 //pointer to opened document.
68 DF_Document* DF_Application::Open(const string& theFileName)
69 {
70   //Not implemented
71   return NULL;
72 }
73
74
75 //Saves a Document in a given file with name theFileName
76 void DF_Application::SaveAs(const DF_Document* theDocument, const string& theFileName)
77 {
78   //Not implemented
79 }