]> SALOME platform Git repositories - modules/med.git/blob - src/MEDCalc/cmp/MEDPresentationManager_i.cxx
Salome HOME
[MEDCalc] Contour presentation
[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 "MEDPresentationSlices.hxx"
28 //#include "MEDPresentationVectorField.hxx"
29 //#include "MEDPresentationDeflectionShape.hxx"
30 //#include "MEDPresentationPointSprite.hxx"
31
32 #include <SALOME_KernelServices.hxx>
33
34 #include <iostream>
35 #include <sstream>
36
37 MEDPresentationManager_i* MEDPresentationManager_i::_instance = NULL;
38
39 MEDPresentationManager_i*
40 MEDPresentationManager_i::getInstance() {
41   if ( _instance == NULL )
42     _instance = new MEDPresentationManager_i();
43   return _instance;
44 }
45
46 MEDPresentationManager_i::MEDPresentationManager_i() :
47     _presentations(),
48     _activeViewPythonId(-1)
49 {
50 }
51
52 MEDPresentationManager_i::~MEDPresentationManager_i()
53 {
54   /*
55   std::vector<MEDPresentation*>::iterator itr = this->_presentations.begin();
56   for ( ; itr != this->_presentations.end(); ++itr) {
57     delete *itr;
58     *itr = NULL;
59   }
60   this->_presentations.clear();
61   */
62 }
63
64 MEDPresentation::TypeID
65 MEDPresentationManager_i::GenerateID()
66 {
67   static MEDPresentation::TypeID START_ID = -1;
68   START_ID++;
69   return START_ID;
70 }
71
72 MEDPresentation*
73 MEDPresentationManager_i::_getPresentation(MEDPresentation::TypeID presentationID) const
74 {
75   std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
76   if (citr == _presentations.end())
77     return NULL;
78   return (*citr).second;
79 }
80
81 void
82 MEDPresentationManager_i::setPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue)
83 {
84   MEDPresentation* pres = _getPresentation(presentationID);
85   if (pres)
86     pres->setStringProperty(propName, propValue);
87   else
88     throw KERNEL::createSalomeException("setPresentationStringProperty(): presentation not found!!");
89 }
90
91 char*
92 MEDPresentationManager_i::getPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName)
93 {
94   MEDPresentation* pres = _getPresentation(presentationID);
95   if (pres) {
96     return (char*) pres->getStringProperty(propName).c_str();
97   }
98   else
99     throw KERNEL::createSalomeException("getPresentationStringProperty(): presentation not found!!");
100 }
101
102 void
103 MEDPresentationManager_i::setPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName,
104                                                      const CORBA::Long propValue)
105 {
106   MEDPresentation* pres = _getPresentation(presentationID);
107   if (pres)
108     pres->setIntProperty(propName, propValue);
109   else
110     throw KERNEL::createSalomeException("setPresentationIntProperty(): presentation not found!!");
111 }
112
113 CORBA::Long
114 MEDPresentationManager_i::getPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName)
115 {
116   MEDPresentation* pres = _getPresentation(presentationID);
117   if (pres) {
118     return (CORBA::Long) pres->getIntProperty(propName);
119   }
120   else
121     throw KERNEL::createSalomeException("getPresentationIntProperty(): presentation not found!!");
122
123 }
124
125 MEDPresentation::TypeID
126 MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& params, const MEDCALC::MEDPresentationViewMode viewMode)
127 {
128   return _makePresentation<MEDPresentationScalarMap>(params, viewMode);
129 }
130
131 MEDPresentation::TypeID
132 MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params, const MEDCALC::MEDPresentationViewMode viewMode)
133 {
134   return _makePresentation<MEDPresentationContour>(params, viewMode);
135 }
136
137 //MEDPresentation::TypeID
138 //MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params)
139 //{
140 //  return _makePresentation<MEDPresentationVectorField>(params);
141 //}
142 //
143 //MEDPresentation::TypeID
144 //MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params)
145 //{
146 //  return _makePresentation<MEDPresentationSlices>(params);
147 //}
148 //
149 //MEDPresentation::TypeID
150 //MEDPresentationManager_i::makeDeflectionShape(const MEDCALC::DeflectionShapeParameters& params)
151 //{
152 //  return _makePresentation<MEDPresentationDeflectionShape>(params);
153 //}
154 //
155 //MEDPresentation::TypeID
156 //MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params)
157 //{
158 //  return _makePresentation<MEDPresentationPointSprite>(params);
159 //}
160
161 MEDCALC::ScalarMapParameters*
162 MEDPresentationManager_i::getScalarMapParameters(MEDPresentation::TypeID presentationID)
163 {
164   MEDCALC::ScalarMapParameters* p = new MEDCALC::ScalarMapParameters();
165   _getParameters<MEDPresentationScalarMap>(presentationID, *p);
166   MEDCALC::ScalarMapParameters_var tmp(p);
167   return tmp._retn();
168 }
169
170 MEDCALC::ContourParameters
171 MEDPresentationManager_i::getContourParameters(MEDPresentation::TypeID presentationID)
172 {
173   MEDCALC::ContourParameters p;
174   _getParameters<MEDPresentationContour>(presentationID, p);
175   return p;
176 }
177
178 void
179 MEDPresentationManager_i::updateScalarMap(MEDPresentation::TypeID presentationID, const MEDCALC::ScalarMapParameters& params)
180 {
181   return _updatePresentation<MEDPresentationScalarMap>(presentationID, params);
182 }
183
184 void
185 MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters& params)
186 {
187   return _updatePresentation<MEDPresentationContour>(presentationID, params);
188 }
189
190 //void
191 //MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params)
192 //{
193 //  return _updatePresentation<MEDPresentationVectorField>(presentationID, params);
194 //}
195 //
196 //void
197 //MEDPresentationManager_i::updateSlices(MEDPresentation::TypeID presentationID, const MEDCALC::SlicesParameters& params)
198 //{
199 //  return _updatePresentation<MEDPresentationSlices>(presentationID, params);
200 //}
201 //
202 //void
203 //MEDPresentationManager_i::updateDeflectionShape(MEDPresentation::TypeID presentationID, const MEDCALC::DeflectionShapeParameters& params)
204 //{
205 //  return _updatePresentation<MEDPresentationDeflectionShape>(presentationID, params);
206 //}
207 //
208 //void
209 //MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters& params)
210 //{
211 //  return _updatePresentation<MEDPresentationPointSprite>(presentationID, params);
212 //}
213
214 CORBA::Boolean
215 MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentationID)
216 {
217   std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
218   if (citr == _presentations.end()) {
219     std::cerr << "removePresentation(): presentation not found!!" << std::endl;
220     return false;
221   }
222   MEDPresentation* presentation = (*citr).second;
223   if (presentation)
224     delete presentation;
225   _presentations.erase(presentationID);
226
227   STDLOG("Presentation " << presentationID << " has been removed.");
228   return true;
229 }
230
231 CORBA::Boolean
232 MEDPresentationManager_i::activateView(MEDPresentation::TypeID presentationID)
233 {
234   std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
235   if (citr == _presentations.end()) {
236     std::cerr << "activateView(): presentation not found!!" << std::endl;
237     return false;
238   }
239   MEDPresentation* presentation = (*citr).second;
240
241   presentation->activateView();
242   _activeViewPythonId = presentation->getPyViewID();
243   STDLOG("Activated view " << _activeViewPythonId);
244   return true;
245 }
246
247 CORBA::Long
248 MEDPresentationManager_i::getActiveViewPythonId()
249 {
250   //TODO: should be more elaborate to re-identify the active ParaView view when another
251   //mechanism than MED module has activated another view.
252   // Idea: 1/ call Python to current active view
253   //       2/ compare with all id(__viewX) from currently existing presentations
254   return _activeViewPythonId;
255 }
256
257
258 //MEDCALC::MEDPresentationViewMode
259 //MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presentationID)
260 //{
261 //  MEDPresentation* pres = _getPresentation(presentationID);
262 //  if (pres) {
263 //    return pres->getViewMode();
264 //  } else {
265 //    std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
266 //    return MEDCALC::VIEW_MODE_DEFAULT;
267 //  }
268 //}
269
270 char*
271 MEDPresentationManager_i::getParavisDump(MEDPresentation::TypeID presentationID)
272 {
273   MEDPresentation* pres = _getPresentation(presentationID);
274   if (pres) {
275     return (char*) pres->paravisDump().c_str();
276   }
277   else
278     throw KERNEL::createSalomeException("getParavisDump(): presentation not found!!");
279 }
280
281 MEDCALC::PresentationsList*
282 MEDPresentationManager_i::getAllPresentations()
283 {
284   MEDCALC::PresentationsList* presList = new MEDCALC::PresentationsList;
285   presList->length(_presentations.size());
286   std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator it;
287   int i;
288   for (i = 0, it = _presentations.begin(); it != _presentations.end(); ++it, ++i)
289     (*presList)[i] = it->first;
290   return presList;
291 }