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 // sphinx doc: begin of makePlot3D
197 MEDPresentation::TypeID
198 MEDPresentationManager_i::makePlot3D(const MEDCALC::Plot3DParameters& params, const MEDCALC::ViewModeType viewMode)
200 return _makePresentation<MEDPresentationPlot3D>(params, viewMode);
202 // sphinx doc: end of makePlot3D
204 MEDPresentation::TypeID
205 MEDPresentationManager_i::makeStreamLines(const MEDCALC::StreamLinesParameters& params, const MEDCALC::ViewModeType viewMode)
207 return _makePresentation<MEDPresentationStreamLines>(params, viewMode);
210 MEDPresentation::TypeID
211 MEDPresentationManager_i::makeCutSegment(const MEDCALC::CutSegmentParameters& params, const MEDCALC::ViewModeType viewMode)
213 return _makePresentation<MEDPresentationCutSegment>(params, viewMode);
216 MEDCALC::MeshViewParameters
217 MEDPresentationManager_i::getMeshViewParameters(MEDPresentation::TypeID presentationID)
219 MEDCALC::MeshViewParameters* p = new MEDCALC::MeshViewParameters();
220 _getParameters<MEDPresentationMeshView>(presentationID, *p);
221 MEDCALC::MeshViewParameters_var tmp(p);
226 MEDCALC::ScalarMapParameters*
227 MEDPresentationManager_i::getScalarMapParameters(MEDPresentation::TypeID presentationID)
229 MEDCALC::ScalarMapParameters* p = new MEDCALC::ScalarMapParameters();
230 _getParameters<MEDPresentationScalarMap>(presentationID, *p);
231 MEDCALC::ScalarMapParameters_var tmp(p);
235 MEDCALC::ContourParameters*
236 MEDPresentationManager_i::getContourParameters(MEDPresentation::TypeID presentationID)
238 MEDCALC::ContourParameters* p = new MEDCALC::ContourParameters();
239 _getParameters<MEDPresentationContour>(presentationID, *p);
240 MEDCALC::ContourParameters_var tmp(p);
244 MEDCALC::SlicesParameters*
245 MEDPresentationManager_i::getSlicesParameters(MEDPresentation::TypeID presentationID)
247 MEDCALC::SlicesParameters* p = new MEDCALC::SlicesParameters();
248 _getParameters<MEDPresentationSlices>(presentationID, *p);
249 MEDCALC::SlicesParameters_var tmp(p);
253 MEDCALC::VectorFieldParameters*
254 MEDPresentationManager_i::getVectorFieldParameters(MEDPresentation::TypeID presentationID)
256 MEDCALC::VectorFieldParameters* p = new MEDCALC::VectorFieldParameters;
257 _getParameters<MEDPresentationVectorField>(presentationID, *p);
258 MEDCALC::VectorFieldParameters_var tmp(p);
262 MEDCALC::PointSpriteParameters*
263 MEDPresentationManager_i::getPointSpriteParameters(MEDPresentation::TypeID presentationID)
265 MEDCALC::PointSpriteParameters* p = new MEDCALC::PointSpriteParameters();
266 _getParameters<MEDPresentationPointSprite>(presentationID, *p);
267 MEDCALC::PointSpriteParameters_var tmp(p);
271 // sphinx doc: begin of getPlot3DParameters
272 MEDCALC::Plot3DParameters*
273 MEDPresentationManager_i::getPlot3DParameters(MEDPresentation::TypeID presentationID)
275 MEDCALC::Plot3DParameters* p = new MEDCALC::Plot3DParameters();
276 _getParameters<MEDPresentationPlot3D>(presentationID, *p);
277 MEDCALC::Plot3DParameters_var tmp(p);
280 // sphinx doc: end of getPlot3DParameters
282 MEDCALC::StreamLinesParameters*
283 MEDPresentationManager_i::getStreamLinesParameters(MEDPresentation::TypeID presentationID)
285 MEDCALC::StreamLinesParameters* p = new MEDCALC::StreamLinesParameters();
286 _getParameters<MEDPresentationStreamLines>(presentationID, *p);
287 MEDCALC::StreamLinesParameters_var tmp(p);
291 MEDCALC::CutSegmentParameters*
292 MEDPresentationManager_i::getCutSegmentParameters(MEDPresentation::TypeID presentationID)
294 MEDCALC::CutSegmentParameters* p = new MEDCALC::CutSegmentParameters();
295 _getParameters<MEDPresentationCutSegment>(presentationID, *p);
296 MEDCALC::CutSegmentParameters_var tmp(p);
300 MEDCALC::DeflectionShapeParameters*
301 MEDPresentationManager_i::getDeflectionShapeParameters(MEDPresentation::TypeID presentationID)
303 MEDCALC::DeflectionShapeParameters* p = new MEDCALC::DeflectionShapeParameters();
304 _getParameters<MEDPresentationDeflectionShape>(presentationID, *p);
305 MEDCALC::DeflectionShapeParameters_var tmp(p);
311 MEDPresentationManager_i::updateMeshView(MEDPresentation::TypeID presentationID, const MEDCALC::MeshViewParameters& params)
313 return _updatePresentation<MEDPresentationMeshView>(presentationID, params);
317 MEDPresentationManager_i::updateScalarMap(MEDPresentation::TypeID presentationID, const MEDCALC::ScalarMapParameters& params)
319 return _updatePresentation<MEDPresentationScalarMap>(presentationID, params);
323 MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters& params)
325 return _updatePresentation<MEDPresentationContour>(presentationID, params);
329 MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params)
331 return _updatePresentation<MEDPresentationVectorField>(presentationID, params);
335 MEDPresentationManager_i::updateSlices(MEDPresentation::TypeID presentationID, const MEDCALC::SlicesParameters& params)
337 return _updatePresentation<MEDPresentationSlices>(presentationID, params);
341 MEDPresentationManager_i::updateDeflectionShape(MEDPresentation::TypeID presentationID, const MEDCALC::DeflectionShapeParameters& params)
343 return _updatePresentation<MEDPresentationDeflectionShape>(presentationID, params);
347 MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters& params)
349 return _updatePresentation<MEDPresentationPointSprite>(presentationID, params);
352 // sphinx doc: begin of updatePlot3D
354 MEDPresentationManager_i::updatePlot3D(MEDPresentation::TypeID presentationID, const MEDCALC::Plot3DParameters& params)
356 return _updatePresentation<MEDPresentationPlot3D>(presentationID, params);
358 // sphinx doc: end of updatePlot3D
361 MEDPresentationManager_i::updateStreamLines(MEDPresentation::TypeID presentationID, const MEDCALC::StreamLinesParameters& params)
363 return _updatePresentation<MEDPresentationStreamLines>(presentationID, params);
367 MEDPresentationManager_i::updateCutSegment(MEDPresentation::TypeID presentationID, const MEDCALC::CutSegmentParameters& params)
369 return _updatePresentation<MEDPresentationCutSegment>(presentationID, params);
373 MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentationID)
375 STDLOG("Remove presentation " << presentationID);
376 MEDPresentation* presentation = _getPresentation(presentationID);
382 _presentations.erase(presentationID);
384 STDLOG("Presentation " << presentationID << " has been removed.");
389 MEDPresentationManager_i::activateView(MEDPresentation::TypeID presentationID)
391 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
392 if (citr == _presentations.end()) {
393 std::cerr << "activateView(): presentation not found!!" << std::endl;
396 MEDPresentation* presentation = (*citr).second;
398 if (!presentation->activateView())
400 // The view has been recreated - transfer all presentations that were in the deleted view to this new one
401 int viewId = presentation->getPyViewID();
402 std::map<MEDPresentation::TypeID, MEDPresentation*>::iterator citr = _presentations.begin();
403 for (; citr != _presentations.end(); ++citr)
405 if(citr->second->getPyViewID() == viewId)
406 citr->second->recreateViewSetup();
409 _activeViewPythonId = presentation->getPyViewID();
410 STDLOG("Activated view " << _activeViewPythonId);
415 MEDPresentationManager_i::getActiveViewPythonId()
417 //TODO: should be more elaborate to re-identify the active ParaView view when another
418 //mechanism than MED module has activated another view.
419 // Idea: 1/ call Python to current active view
420 // 2/ compare with all id(__viewX) from currently existing presentations
421 return _activeViewPythonId;
425 //MEDCALC::ViewModeType
426 //MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presentationID)
428 // MEDPresentation* pres = _getPresentation(presentationID);
430 // return pres->getViewMode();
432 // std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
433 // return MEDCALC::VIEW_MODE_DEFAULT;
438 MEDPresentationManager_i::getParavisDump(MEDPresentation::TypeID presentationID)
440 MEDPresentation* pres = _getPresentation(presentationID);
442 return CORBA::string_dup(pres->paravisDump().c_str());
445 throw KERNEL::createSalomeException("getParavisDump(): presentation not found!!");
448 MEDCALC::PresentationsList*
449 MEDPresentationManager_i::getAllPresentations()
451 MEDCALC::PresentationsList* presList = new MEDCALC::PresentationsList;
452 presList->length(_presentations.size());
453 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator it;
455 for (i = 0, it = _presentations.begin(); it != _presentations.end(); ++it, ++i)
456 (*presList)[i] = it->first;
460 MEDCALC::PresentationVisibility
461 MEDPresentationManager_i::stateInActiveView(MEDPresentation::TypeID presentationID)
463 MEDPresentation* pres = _getPresentation(presentationID);
465 return pres->presentationStateInActiveView();
467 throw KERNEL::createSalomeException("stateInActiveView(): presentation not found!!");
472 MEDPresentationManager_i::cleanUp()
475 _activeViewPythonId = -1;
476 std::map<MEDPresentation::TypeID, MEDPresentation*>::iterator it;
477 for (it = _presentations.begin(); it != _presentations.end(); ++it)
479 _presentations.clear();