Salome HOME
Merge remote-tracking branch 'origin/BR_IMPROVEMENTS' into BR_v14_rc
[modules/hydro.git] / src / HYDROData / HYDROData_Application.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <HYDROData_Application.h>
20
21 #include <TColStd_SequenceOfExtendedString.hxx>
22
23 IMPLEMENT_STANDARD_HANDLE(HYDROData_Application,TDocStd_Application)
24 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Application,TDocStd_Application)
25
26 static HYDROData_Application* TheApplication = new HYDROData_Application;
27
28 //=======================================================================
29 //function : getApplication
30 //purpose  : 
31 //=======================================================================
32 HYDROData_Application* HYDROData_Application::GetApplication() 
33 {
34   return TheApplication;
35 }
36
37 //=======================================================================
38 //function : GetDocument
39 //purpose  : 
40 //=======================================================================
41 bool HYDROData_Application::GetDocumentId(const Handle(HYDROData_Document)& theDocument,
42                                           int&                              theDocId) const
43 {
44   DataMapOfStudyIDDocument::Iterator aMapit( myDocuments );
45   for ( ; aMapit.More(); aMapit.Next() )
46   {
47     if ( aMapit.Value() != theDocument )
48       continue;
49
50     theDocId = aMapit.Key();
51     return true;
52   }
53
54   return false;
55 }
56
57 //=======================================================================
58 //function : GetDocument
59 //purpose  : 
60 //=======================================================================
61 Handle(HYDROData_Document) HYDROData_Application::GetDocument(int theStudyID) const
62 {
63   if (myDocuments.IsBound(theStudyID)) {
64     return myDocuments.Find(theStudyID);
65   }
66   // document not found => create the new one
67   return Handle(HYDROData_Document)();
68 }
69
70 //=======================================================================
71 //function : OCAFApp_Application
72 //purpose  : 
73 //=======================================================================
74 HYDROData_Application::HYDROData_Application ()
75 {
76   // store handle to the application to avoid nullification
77   static Handle(HYDROData_Application) TheKeepHandle;
78   TheKeepHandle = this;
79 }
80
81 //=======================================================================
82 //function : addDocument
83 //purpose  : 
84 //=======================================================================
85 void HYDROData_Application::AddDocument(int theStudyID, const Handle(HYDROData_Document)& theDocument)
86 {
87   myDocuments.Bind(theStudyID, theDocument);
88 }
89
90 //=======================================================================
91 //function : removeDocument
92 //purpose  : 
93 //=======================================================================
94 void HYDROData_Application::RemoveDocument(const Handle(HYDROData_Document)& theDocument)
95 {
96   DataMapOfStudyIDDocument::Iterator anIter(myDocuments);
97   for(; anIter.More(); anIter.Next())
98     if (anIter.Value() == theDocument) {
99       myDocuments.UnBind(anIter.Key());
100       break;
101     }
102 }
103
104 //=======================================================================
105 //function : Formats
106 //purpose  : 
107 //=======================================================================
108 void HYDROData_Application::Formats(TColStd_SequenceOfExtendedString& theFormats) 
109 {
110   theFormats.Append(TCollection_ExtendedString ("BinOcaf")); // standard binary schema
111 }
112
113 //=======================================================================
114 //function : ResourcesName
115 //purpose  : 
116 //=======================================================================
117 Standard_CString HYDROData_Application::ResourcesName()
118 {
119   return Standard_CString("Standard");
120 }