1 // Copyright (C) 2011-2021 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"
32 #include "MEDPresentationPlot3D.hxx"
33 #include "MEDPresentationStreamLines.hxx"
34 #include "MEDPresentationCutSegment.hxx"
36 #include <SALOME_KernelServices.hxx>
41 MEDPresentationManager_i* MEDPresentationManager_i::_instance = NULL;
43 MEDPresentationManager_i*
44 MEDPresentationManager_i::getInstance() {
45 if ( _instance == NULL )
46 _instance = new MEDPresentationManager_i();
50 MEDPresentationManager_i::MEDPresentationManager_i() :
52 _activeViewPythonId(-1)
56 MEDPresentationManager_i::~MEDPresentationManager_i()
59 std::vector<MEDPresentation*>::iterator itr = this->_presentations.begin();
60 for ( ; itr != this->_presentations.end(); ++itr) {
64 this->_presentations.clear();
68 MEDPresentation::TypeID
69 MEDPresentationManager_i::GenerateID()
71 static MEDPresentation::TypeID START_ID = -1;
77 MEDPresentationManager_i::_getPresentation(MEDPresentation::TypeID presentationID) const
79 STDLOG("Get presentation " << presentationID);
80 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
81 if (citr == _presentations.end())
83 return (*citr).second;
87 MEDPresentationManager_i::setPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue)
89 MEDPresentation* pres = _getPresentation(presentationID);
91 pres->setStringProperty(propName, propValue);
93 throw KERNEL::createSalomeException("setPresentationStringProperty(): presentation not found!!");
97 MEDPresentationManager_i::getPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName)
99 MEDPresentation* pres = _getPresentation(presentationID);
101 return CORBA::string_dup(pres->getStringProperty(propName).c_str());
104 throw KERNEL::createSalomeException("getPresentationStringProperty(): presentation not found!!");
108 MEDPresentationManager_i::setPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName,
109 const CORBA::Long propValue)
111 MEDPresentation* pres = _getPresentation(presentationID);
113 pres->setIntProperty(propName, propValue);
115 throw KERNEL::createSalomeException("setPresentationIntProperty(): presentation not found!!");
119 MEDPresentationManager_i::getPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName)
121 MEDPresentation* pres = _getPresentation(presentationID);
123 return (CORBA::Long) pres->getIntProperty(propName);
126 throw KERNEL::createSalomeException("getPresentationIntProperty(): presentation not found!!");
131 MEDPresentationManager_i::setPresentationDoubleProperty(MEDPresentation::TypeID presentationID, const char* propName,
132 const CORBA::Double propValue)
134 MEDPresentation* pres = _getPresentation(presentationID);
136 pres->setDoubleProperty(propName, propValue);
138 throw KERNEL::createSalomeException("setPresentationDoubleProperty(): presentation not found!!");
142 MEDPresentationManager_i::getPresentationDoubleProperty(MEDPresentation::TypeID presentationID, const char* propName)
144 MEDPresentation* pres = _getPresentation(presentationID);
146 return (CORBA::Double) pres->getDoubleProperty(propName);
149 throw KERNEL::createSalomeException("getPresentationIntProperty(): presentation not found!!");
154 MEDPresentation::TypeID
155 MEDPresentationManager_i::makeMeshView(const MEDCALC::MeshViewParameters& params, const MEDCALC::ViewModeType viewMode)
157 return _makePresentation<MEDPresentationMeshView>(params, viewMode);
160 MEDPresentation::TypeID
161 MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& params, const MEDCALC::ViewModeType viewMode)
163 return _makePresentation<MEDPresentationScalarMap>(params, viewMode);
166 MEDPresentation::TypeID
167 MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params, const MEDCALC::ViewModeType viewMode)
169 return _makePresentation<MEDPresentationContour>(params, viewMode);
172 MEDPresentation::TypeID
173 MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params, const MEDCALC::ViewModeType viewMode)
175 return _makePresentation<MEDPresentationVectorField>(params, viewMode);
178 MEDPresentation::TypeID
179 MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params, const MEDCALC::ViewModeType viewMode)
181 return _makePresentation<MEDPresentationSlices>(params, viewMode);
184 MEDPresentation::TypeID
185 MEDPresentationManager_i::makeDeflectionShape(const MEDCALC::DeflectionShapeParameters& params, const MEDCALC::ViewModeType viewMode)
187 return _makePresentation<MEDPresentationDeflectionShape>(params, viewMode);
190 MEDPresentation::TypeID
191 MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params, const MEDCALC::ViewModeType viewMode)
193 return _makePresentation<MEDPresentationPointSprite>(params, viewMode);
196 MEDPresentation::TypeID
197 MEDPresentationManager_i::makePlot3D(const MEDCALC::Plot3DParameters& params, const MEDCALC::ViewModeType viewMode)
199 return _makePresentation<MEDPresentationPlot3D>(params, viewMode);
202 MEDPresentation::TypeID
203 MEDPresentationManager_i::makeStreamLines(const MEDCALC::StreamLinesParameters& params, const MEDCALC::ViewModeType viewMode)
205 return _makePresentation<MEDPresentationStreamLines>(params, viewMode);
208 MEDPresentation::TypeID
209 MEDPresentationManager_i::makeCutSegment(const MEDCALC::CutSegmentParameters& params, const MEDCALC::ViewModeType viewMode)
211 return _makePresentation<MEDPresentationCutSegment>(params, viewMode);
214 MEDCALC::MeshViewParameters
215 MEDPresentationManager_i::getMeshViewParameters(MEDPresentation::TypeID presentationID)
217 MEDCALC::MeshViewParameters* p = new MEDCALC::MeshViewParameters();
218 _getParameters<MEDPresentationMeshView>(presentationID, *p);
219 MEDCALC::MeshViewParameters_var tmp(p);
224 MEDCALC::ScalarMapParameters*
225 MEDPresentationManager_i::getScalarMapParameters(MEDPresentation::TypeID presentationID)
227 MEDCALC::ScalarMapParameters* p = new MEDCALC::ScalarMapParameters();
228 _getParameters<MEDPresentationScalarMap>(presentationID, *p);
229 MEDCALC::ScalarMapParameters_var tmp(p);
233 MEDCALC::ContourParameters*
234 MEDPresentationManager_i::getContourParameters(MEDPresentation::TypeID presentationID)
236 MEDCALC::ContourParameters* p = new MEDCALC::ContourParameters();
237 _getParameters<MEDPresentationContour>(presentationID, *p);
238 MEDCALC::ContourParameters_var tmp(p);
242 MEDCALC::SlicesParameters*
243 MEDPresentationManager_i::getSlicesParameters(MEDPresentation::TypeID presentationID)
245 MEDCALC::SlicesParameters* p = new MEDCALC::SlicesParameters();
246 _getParameters<MEDPresentationSlices>(presentationID, *p);
247 MEDCALC::SlicesParameters_var tmp(p);
251 MEDCALC::VectorFieldParameters*
252 MEDPresentationManager_i::getVectorFieldParameters(MEDPresentation::TypeID presentationID)
254 MEDCALC::VectorFieldParameters* p = new MEDCALC::VectorFieldParameters;
255 _getParameters<MEDPresentationVectorField>(presentationID, *p);
256 MEDCALC::VectorFieldParameters_var tmp(p);
260 MEDCALC::PointSpriteParameters*
261 MEDPresentationManager_i::getPointSpriteParameters(MEDPresentation::TypeID presentationID)
263 MEDCALC::PointSpriteParameters* p = new MEDCALC::PointSpriteParameters();
264 _getParameters<MEDPresentationPointSprite>(presentationID, *p);
265 MEDCALC::PointSpriteParameters_var tmp(p);
269 MEDCALC::Plot3DParameters*
270 MEDPresentationManager_i::getPlot3DParameters(MEDPresentation::TypeID presentationID)
272 MEDCALC::Plot3DParameters* p = new MEDCALC::Plot3DParameters();
273 _getParameters<MEDPresentationPlot3D>(presentationID, *p);
274 MEDCALC::Plot3DParameters_var tmp(p);
278 MEDCALC::StreamLinesParameters*
279 MEDPresentationManager_i::getStreamLinesParameters(MEDPresentation::TypeID presentationID)
281 MEDCALC::StreamLinesParameters* p = new MEDCALC::StreamLinesParameters();
282 _getParameters<MEDPresentationStreamLines>(presentationID, *p);
283 MEDCALC::StreamLinesParameters_var tmp(p);
287 MEDCALC::CutSegmentParameters*
288 MEDPresentationManager_i::getCutSegmentParameters(MEDPresentation::TypeID presentationID)
290 MEDCALC::CutSegmentParameters* p = new MEDCALC::CutSegmentParameters();
291 _getParameters<MEDPresentationCutSegment>(presentationID, *p);
292 MEDCALC::CutSegmentParameters_var tmp(p);
296 MEDCALC::DeflectionShapeParameters*
297 MEDPresentationManager_i::getDeflectionShapeParameters(MEDPresentation::TypeID presentationID)
299 MEDCALC::DeflectionShapeParameters* p = new MEDCALC::DeflectionShapeParameters();
300 _getParameters<MEDPresentationDeflectionShape>(presentationID, *p);
301 MEDCALC::DeflectionShapeParameters_var tmp(p);
307 MEDPresentationManager_i::updateMeshView(MEDPresentation::TypeID presentationID, const MEDCALC::MeshViewParameters& params)
309 return _updatePresentation<MEDPresentationMeshView>(presentationID, params);
313 MEDPresentationManager_i::updateScalarMap(MEDPresentation::TypeID presentationID, const MEDCALC::ScalarMapParameters& params)
315 return _updatePresentation<MEDPresentationScalarMap>(presentationID, params);
319 MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters& params)
321 return _updatePresentation<MEDPresentationContour>(presentationID, params);
325 MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params)
327 return _updatePresentation<MEDPresentationVectorField>(presentationID, params);
331 MEDPresentationManager_i::updateSlices(MEDPresentation::TypeID presentationID, const MEDCALC::SlicesParameters& params)
333 return _updatePresentation<MEDPresentationSlices>(presentationID, params);
337 MEDPresentationManager_i::updateDeflectionShape(MEDPresentation::TypeID presentationID, const MEDCALC::DeflectionShapeParameters& params)
339 return _updatePresentation<MEDPresentationDeflectionShape>(presentationID, params);
343 MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters& params)
345 return _updatePresentation<MEDPresentationPointSprite>(presentationID, params);
349 MEDPresentationManager_i::updatePlot3D(MEDPresentation::TypeID presentationID, const MEDCALC::Plot3DParameters& params)
351 return _updatePresentation<MEDPresentationPlot3D>(presentationID, params);
355 MEDPresentationManager_i::updateStreamLines(MEDPresentation::TypeID presentationID, const MEDCALC::StreamLinesParameters& params)
357 return _updatePresentation<MEDPresentationStreamLines>(presentationID, params);
361 MEDPresentationManager_i::updateCutSegment(MEDPresentation::TypeID presentationID, const MEDCALC::CutSegmentParameters& params)
363 return _updatePresentation<MEDPresentationCutSegment>(presentationID, params);
367 MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentationID)
369 STDLOG("Remove presentation " << presentationID);
370 MEDPresentation* presentation = _getPresentation(presentationID);
376 _presentations.erase(presentationID);
378 STDLOG("Presentation " << presentationID << " has been removed.");
383 MEDPresentationManager_i::activateView(MEDPresentation::TypeID presentationID)
385 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
386 if (citr == _presentations.end()) {
387 std::cerr << "activateView(): presentation not found!!" << std::endl;
390 MEDPresentation* presentation = (*citr).second;
392 if (!presentation->activateView())
394 // The view has been recreated - transfer all presentations that were in the deleted view to this new one
395 int viewId = presentation->getPyViewID();
396 std::map<MEDPresentation::TypeID, MEDPresentation*>::iterator citr = _presentations.begin();
397 for (; citr != _presentations.end(); ++citr)
399 if(citr->second->getPyViewID() == viewId)
400 citr->second->recreateViewSetup();
403 _activeViewPythonId = presentation->getPyViewID();
404 STDLOG("Activated view " << _activeViewPythonId);
409 MEDPresentationManager_i::getActiveViewPythonId()
411 //TODO: should be more elaborate to re-identify the active ParaView view when another
412 //mechanism than MED module has activated another view.
413 // Idea: 1/ call Python to current active view
414 // 2/ compare with all id(__viewX) from currently existing presentations
415 return _activeViewPythonId;
419 //MEDCALC::ViewModeType
420 //MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presentationID)
422 // MEDPresentation* pres = _getPresentation(presentationID);
424 // return pres->getViewMode();
426 // std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
427 // return MEDCALC::VIEW_MODE_DEFAULT;
432 MEDPresentationManager_i::getParavisDump(MEDPresentation::TypeID presentationID)
434 MEDPresentation* pres = _getPresentation(presentationID);
436 return CORBA::string_dup(pres->paravisDump().c_str());
439 throw KERNEL::createSalomeException("getParavisDump(): presentation not found!!");
442 MEDCALC::PresentationsList*
443 MEDPresentationManager_i::getAllPresentations()
445 MEDCALC::PresentationsList* presList = new MEDCALC::PresentationsList;
446 presList->length(_presentations.size());
447 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator it;
449 for (i = 0, it = _presentations.begin(); it != _presentations.end(); ++it, ++i)
450 (*presList)[i] = it->first;
454 MEDCALC::PresentationVisibility
455 MEDPresentationManager_i::stateInActiveView(MEDPresentation::TypeID presentationID)
457 MEDPresentation* pres = _getPresentation(presentationID);
459 return pres->presentationStateInActiveView();
461 throw KERNEL::createSalomeException("stateInActiveView(): presentation not found!!");
466 MEDPresentationManager_i::cleanUp()
469 _activeViewPythonId = -1;
470 std::map<MEDPresentation::TypeID, MEDPresentation*>::iterator it;
471 for (it = _presentations.begin(); it != _presentations.end(); ++it)
473 _presentations.clear();