1 // Copyright (C) 2011-2020 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDPresentationManager_i.hxx"
21 #include "MEDFactoryClient.hxx"
22 #include "Basics_Utils.hxx"
25 #include "MEDPresentationMeshView.hxx"
26 #include "MEDPresentationScalarMap.hxx"
27 #include "MEDPresentationContour.hxx"
28 #include "MEDPresentationSlices.hxx"
29 #include "MEDPresentationVectorField.hxx"
30 #include "MEDPresentationDeflectionShape.hxx"
31 #include "MEDPresentationPointSprite.hxx"
33 #include <SALOME_KernelServices.hxx>
38 MEDPresentationManager_i* MEDPresentationManager_i::_instance = NULL;
40 MEDPresentationManager_i*
41 MEDPresentationManager_i::getInstance() {
42 if ( _instance == NULL )
43 _instance = new MEDPresentationManager_i();
47 MEDPresentationManager_i::MEDPresentationManager_i() :
49 _activeViewPythonId(-1)
53 MEDPresentationManager_i::~MEDPresentationManager_i()
56 std::vector<MEDPresentation*>::iterator itr = this->_presentations.begin();
57 for ( ; itr != this->_presentations.end(); ++itr) {
61 this->_presentations.clear();
65 MEDPresentation::TypeID
66 MEDPresentationManager_i::GenerateID()
68 static MEDPresentation::TypeID START_ID = -1;
74 MEDPresentationManager_i::_getPresentation(MEDPresentation::TypeID presentationID) const
76 STDLOG("Get presentation " << presentationID);
77 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
78 if (citr == _presentations.end())
80 return (*citr).second;
84 MEDPresentationManager_i::setPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue)
86 MEDPresentation* pres = _getPresentation(presentationID);
88 pres->setStringProperty(propName, propValue);
90 throw KERNEL::createSalomeException("setPresentationStringProperty(): presentation not found!!");
94 MEDPresentationManager_i::getPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName)
96 MEDPresentation* pres = _getPresentation(presentationID);
98 return CORBA::string_dup(pres->getStringProperty(propName).c_str());
101 throw KERNEL::createSalomeException("getPresentationStringProperty(): presentation not found!!");
105 MEDPresentationManager_i::setPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName,
106 const CORBA::Long propValue)
108 MEDPresentation* pres = _getPresentation(presentationID);
110 pres->setIntProperty(propName, propValue);
112 throw KERNEL::createSalomeException("setPresentationIntProperty(): presentation not found!!");
116 MEDPresentationManager_i::getPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName)
118 MEDPresentation* pres = _getPresentation(presentationID);
120 return (CORBA::Long) pres->getIntProperty(propName);
123 throw KERNEL::createSalomeException("getPresentationIntProperty(): presentation not found!!");
127 MEDPresentation::TypeID
128 MEDPresentationManager_i::makeMeshView(const MEDCALC::MeshViewParameters& params, const MEDCALC::ViewModeType viewMode)
130 return _makePresentation<MEDPresentationMeshView>(params, viewMode);
133 MEDPresentation::TypeID
134 MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& params, const MEDCALC::ViewModeType viewMode)
136 return _makePresentation<MEDPresentationScalarMap>(params, viewMode);
139 MEDPresentation::TypeID
140 MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params, const MEDCALC::ViewModeType viewMode)
142 return _makePresentation<MEDPresentationContour>(params, viewMode);
145 MEDPresentation::TypeID
146 MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params, const MEDCALC::ViewModeType viewMode)
148 return _makePresentation<MEDPresentationVectorField>(params, viewMode);
151 MEDPresentation::TypeID
152 MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params, const MEDCALC::ViewModeType viewMode)
154 return _makePresentation<MEDPresentationSlices>(params, viewMode);
157 MEDPresentation::TypeID
158 MEDPresentationManager_i::makeDeflectionShape(const MEDCALC::DeflectionShapeParameters& params, const MEDCALC::ViewModeType viewMode)
160 return _makePresentation<MEDPresentationDeflectionShape>(params, viewMode);
163 MEDPresentation::TypeID
164 MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params, const MEDCALC::ViewModeType viewMode)
166 return _makePresentation<MEDPresentationPointSprite>(params, viewMode);
169 MEDCALC::MeshViewParameters
170 MEDPresentationManager_i::getMeshViewParameters(MEDPresentation::TypeID presentationID)
172 MEDCALC::MeshViewParameters* p = new MEDCALC::MeshViewParameters();
173 _getParameters<MEDPresentationMeshView>(presentationID, *p);
174 MEDCALC::MeshViewParameters_var tmp(p);
179 MEDCALC::ScalarMapParameters*
180 MEDPresentationManager_i::getScalarMapParameters(MEDPresentation::TypeID presentationID)
182 MEDCALC::ScalarMapParameters* p = new MEDCALC::ScalarMapParameters();
183 _getParameters<MEDPresentationScalarMap>(presentationID, *p);
184 MEDCALC::ScalarMapParameters_var tmp(p);
188 MEDCALC::ContourParameters
189 MEDPresentationManager_i::getContourParameters(MEDPresentation::TypeID presentationID)
191 MEDCALC::ContourParameters* p = new MEDCALC::ContourParameters();
192 _getParameters<MEDPresentationContour>(presentationID, *p);
193 MEDCALC::ContourParameters_var tmp(p);
197 MEDCALC::SlicesParameters*
198 MEDPresentationManager_i::getSlicesParameters(MEDPresentation::TypeID presentationID)
200 MEDCALC::SlicesParameters* p = new MEDCALC::SlicesParameters();
201 _getParameters<MEDPresentationSlices>(presentationID, *p);
202 MEDCALC::SlicesParameters_var tmp(p);
206 MEDCALC::VectorFieldParameters
207 MEDPresentationManager_i::getVectorFieldParameters(MEDPresentation::TypeID presentationID)
209 MEDCALC::VectorFieldParameters* p = new MEDCALC::VectorFieldParameters();
210 _getParameters<MEDPresentationVectorField>(presentationID, *p);
211 MEDCALC::VectorFieldParameters_var tmp(p);
215 MEDCALC::PointSpriteParameters*
216 MEDPresentationManager_i::getPointSpriteParameters(MEDPresentation::TypeID presentationID)
218 MEDCALC::PointSpriteParameters* p = new MEDCALC::PointSpriteParameters();
219 _getParameters<MEDPresentationPointSprite>(presentationID, *p);
220 MEDCALC::PointSpriteParameters_var tmp(p);
224 MEDCALC::DeflectionShapeParameters
225 MEDPresentationManager_i::getDeflectionShapeParameters(MEDPresentation::TypeID presentationID)
227 MEDCALC::DeflectionShapeParameters* p = new MEDCALC::DeflectionShapeParameters();
228 _getParameters<MEDPresentationDeflectionShape>(presentationID, *p);
229 MEDCALC::DeflectionShapeParameters_var tmp(p);
235 MEDPresentationManager_i::updateMeshView(MEDPresentation::TypeID presentationID, const MEDCALC::MeshViewParameters& params)
237 return _updatePresentation<MEDPresentationMeshView>(presentationID, params);
241 MEDPresentationManager_i::updateScalarMap(MEDPresentation::TypeID presentationID, const MEDCALC::ScalarMapParameters& params)
243 return _updatePresentation<MEDPresentationScalarMap>(presentationID, params);
247 MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters& params)
249 return _updatePresentation<MEDPresentationContour>(presentationID, params);
253 MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params)
255 return _updatePresentation<MEDPresentationVectorField>(presentationID, params);
259 MEDPresentationManager_i::updateSlices(MEDPresentation::TypeID presentationID, const MEDCALC::SlicesParameters& params)
261 return _updatePresentation<MEDPresentationSlices>(presentationID, params);
265 MEDPresentationManager_i::updateDeflectionShape(MEDPresentation::TypeID presentationID, const MEDCALC::DeflectionShapeParameters& params)
267 return _updatePresentation<MEDPresentationDeflectionShape>(presentationID, params);
271 MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters& params)
273 return _updatePresentation<MEDPresentationPointSprite>(presentationID, params);
277 MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentationID)
279 STDLOG("Remove presentation " << presentationID);
280 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
281 if (citr == _presentations.end()) {
282 std::cerr << "removePresentation(): presentation not found!!" << std::endl;
285 MEDPresentation* presentation = (*citr).second;
288 _presentations.erase(presentationID);
290 STDLOG("Presentation " << presentationID << " has been removed.");
295 MEDPresentationManager_i::activateView(MEDPresentation::TypeID presentationID)
297 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
298 if (citr == _presentations.end()) {
299 std::cerr << "activateView(): presentation not found!!" << std::endl;
302 MEDPresentation* presentation = (*citr).second;
304 if (!presentation->activateView())
306 // The view has been recreated - transfer all presentations that were in the deleted view to this new one
307 int viewId = presentation->getPyViewID();
308 std::map<MEDPresentation::TypeID, MEDPresentation*>::iterator citr = _presentations.begin();
309 for (; citr != _presentations.end(); ++citr)
311 if(citr->second->getPyViewID() == viewId)
312 citr->second->recreateViewSetup();
315 _activeViewPythonId = presentation->getPyViewID();
316 STDLOG("Activated view " << _activeViewPythonId);
321 MEDPresentationManager_i::getActiveViewPythonId()
323 //TODO: should be more elaborate to re-identify the active ParaView view when another
324 //mechanism than MED module has activated another view.
325 // Idea: 1/ call Python to current active view
326 // 2/ compare with all id(__viewX) from currently existing presentations
327 return _activeViewPythonId;
331 //MEDCALC::ViewModeType
332 //MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presentationID)
334 // MEDPresentation* pres = _getPresentation(presentationID);
336 // return pres->getViewMode();
338 // std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
339 // return MEDCALC::VIEW_MODE_DEFAULT;
344 MEDPresentationManager_i::getParavisDump(MEDPresentation::TypeID presentationID)
346 MEDPresentation* pres = _getPresentation(presentationID);
348 return CORBA::string_dup(pres->paravisDump().c_str());
351 throw KERNEL::createSalomeException("getParavisDump(): presentation not found!!");
354 MEDCALC::PresentationsList*
355 MEDPresentationManager_i::getAllPresentations()
357 MEDCALC::PresentationsList* presList = new MEDCALC::PresentationsList;
358 presList->length(_presentations.size());
359 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator it;
361 for (i = 0, it = _presentations.begin(); it != _presentations.end(); ++it, ++i)
362 (*presList)[i] = it->first;
367 MEDPresentationManager_i::cleanUp()
370 _activeViewPythonId = -1;
371 std::map<MEDPresentation::TypeID, MEDPresentation*>::iterator it;
372 for (it = _presentations.begin(); it != _presentations.end(); ++it)
374 _presentations.clear();