Salome HOME
Merge remote-tracking branch 'origin/agr/fix_tests'
[modules/med.git] / src / MEDCalc / cmp / MEDPresentationManager_i.cxx
1 // Copyright (C) 2011-2016  CEA/DEN, EDF R&D
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 "MEDPresentationManager_i.hxx"
21 #include "MEDFactoryClient.hxx"
22 #include "Basics_Utils.hxx"
23
24 // presentations
25 #include "MEDPresentationScalarMap.hxx"
26 #include "MEDPresentationContour.hxx"
27 #include "MEDPresentationVectorField.hxx"
28 #include "MEDPresentationSlices.hxx"
29 #include "MEDPresentationDeflectionShape.hxx"
30 #include "MEDPresentationPointSprite.hxx"
31
32 #include <iostream>
33 #include <sstream>
34
35 MEDPresentationManager_i* MEDPresentationManager_i::_instance = NULL;
36
37 MEDPresentationManager_i*
38 MEDPresentationManager_i::getInstance() {
39   if ( _instance == NULL )
40     _instance = new MEDPresentationManager_i();
41   return _instance;
42 }
43
44 MEDPresentationManager_i::MEDPresentationManager_i()
45 {
46 }
47
48 MEDPresentationManager_i::~MEDPresentationManager_i()
49 {
50   /*
51   std::vector<MEDPresentation*>::iterator itr = this->_presentations.begin();
52   for ( ; itr != this->_presentations.end(); ++itr) {
53     delete *itr;
54     *itr = NULL;
55   }
56   this->_presentations.clear();
57   */
58 }
59
60 MEDPresentation::TypeID
61 MEDPresentationManager_i::GenerateID()
62 {
63   static MEDPresentation::TypeID START_ID = -1;
64   START_ID++;
65   return START_ID;
66 }
67
68 MEDPresentation*
69 MEDPresentationManager_i::_getPresentation(MEDPresentation::TypeID presentationID) const
70 {
71   std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
72   if (citr == _presentations.end())
73     return NULL;
74   return (*citr).second;
75 }
76
77 void
78 MEDPresentationManager_i::setPresentationProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue)
79 {
80   MEDPresentation* pres = _getPresentation(presentationID);
81   if (pres)
82     pres->setProperty(propName, propValue);
83   else
84     std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
85 }
86
87 char*
88 MEDPresentationManager_i::getPresentationProperty(MEDPresentation::TypeID presentationID, const char* propName)
89 {
90   MEDPresentation* pres = _getPresentation(presentationID);
91   if (pres) {
92     return (char*) pres->getProperty(propName).c_str();
93   }
94   else {
95     std::cerr << "getPresentationProperty(): presentation not found!!" << std::endl;
96     return (char*) "";
97   }
98 }
99
100 MEDPresentation::TypeID
101 MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& params)
102 {
103   return _makePresentation<MEDPresentationScalarMap>(params);
104 }
105
106 MEDPresentation::TypeID
107 MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params)
108 {
109   return _makePresentation<MEDPresentationContour>(params);
110 }
111
112 MEDPresentation::TypeID
113 MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params)
114 {
115   return _makePresentation<MEDPresentationVectorField>(params);
116 }
117
118 MEDPresentation::TypeID
119 MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params)
120 {
121   return _makePresentation<MEDPresentationSlices>(params);
122 }
123
124 MEDPresentation::TypeID
125 MEDPresentationManager_i::makeDeflectionShape(const MEDCALC::DeflectionShapeParameters& params)
126 {
127   return _makePresentation<MEDPresentationDeflectionShape>(params);
128 }
129
130 MEDPresentation::TypeID
131 MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params)
132 {
133   return _makePresentation<MEDPresentationPointSprite>(params);
134 }
135
136 void
137 MEDPresentationManager_i::updateScalarMap(MEDPresentation::TypeID presentationID, const MEDCALC::ScalarMapParameters& params)
138 {
139   return _updatePresentation<MEDPresentationScalarMap>(presentationID, params);
140 }
141
142 void
143 MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters& params)
144 {
145   return _updatePresentation<MEDPresentationContour>(presentationID, params);
146 }
147
148 void
149 MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params)
150 {
151   return _updatePresentation<MEDPresentationVectorField>(presentationID, params);
152 }
153
154 void
155 MEDPresentationManager_i::updateSlices(MEDPresentation::TypeID presentationID, const MEDCALC::SlicesParameters& params)
156 {
157   return _updatePresentation<MEDPresentationSlices>(presentationID, params);
158 }
159
160 void
161 MEDPresentationManager_i::updateDeflectionShape(MEDPresentation::TypeID presentationID, const MEDCALC::DeflectionShapeParameters& params)
162 {
163   return _updatePresentation<MEDPresentationDeflectionShape>(presentationID, params);
164 }
165
166 void
167 MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters& params)
168 {
169   return _updatePresentation<MEDPresentationPointSprite>(presentationID, params);
170 }
171
172 CORBA::Boolean
173 MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentationID)
174 {
175   std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
176   if (citr == _presentations.end()) {
177     std::cerr << "removePresentation(): presentation not found!!" << std::endl;
178     return false;
179   }
180   MEDPresentation* presentation = (*citr).second;
181   if (presentation)
182     delete presentation;
183   _presentations.erase(presentationID);
184
185   std::stringstream sstm;
186   sstm << "Presentation " << presentationID << " has been removed.\n";
187   STDLOG(sstm.str());
188
189   return true;
190 }
191
192 CORBA::Boolean
193 MEDPresentationManager_i::activateView(MEDPresentation::TypeID presentationID)
194 {
195   std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
196   if (citr == _presentations.end()) {
197     std::cerr << "getPresentationPyViewId(): presentation not found!!" << std::endl;
198     return false;
199   }
200   MEDPresentation* presentation = (*citr).second;
201
202   presentation->activateView();
203   return true;
204 }
205
206 MEDCALC::MEDPresentationViewMode
207 MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presentationID)
208 {
209   MEDPresentation* pres = _getPresentation(presentationID);
210   if (pres) {
211     return pres->getViewMode();
212   } else {
213     std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
214     return MEDCALC::VIEW_MODE_DEFAULT;
215   }
216 }