1 // Copyright (C) 2011-2019 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;
173 _getParameters<MEDPresentationMeshView>(presentationID, p);
178 MEDCALC::ScalarMapParameters*
179 MEDPresentationManager_i::getScalarMapParameters(MEDPresentation::TypeID presentationID)
181 MEDCALC::ScalarMapParameters* p = new MEDCALC::ScalarMapParameters();
182 _getParameters<MEDPresentationScalarMap>(presentationID, *p);
183 MEDCALC::ScalarMapParameters_var tmp(p);
187 MEDCALC::ContourParameters
188 MEDPresentationManager_i::getContourParameters(MEDPresentation::TypeID presentationID)
190 MEDCALC::ContourParameters p;
191 _getParameters<MEDPresentationContour>(presentationID, p);
195 MEDCALC::SlicesParameters*
196 MEDPresentationManager_i::getSlicesParameters(MEDPresentation::TypeID presentationID)
198 MEDCALC::SlicesParameters* p = new MEDCALC::SlicesParameters();
199 _getParameters<MEDPresentationSlices>(presentationID, *p);
200 MEDCALC::SlicesParameters_var tmp(p);
204 MEDCALC::VectorFieldParameters
205 MEDPresentationManager_i::getVectorFieldParameters(MEDPresentation::TypeID presentationID)
207 MEDCALC::VectorFieldParameters p;
208 _getParameters<MEDPresentationVectorField>(presentationID, p);
212 MEDCALC::PointSpriteParameters*
213 MEDPresentationManager_i::getPointSpriteParameters(MEDPresentation::TypeID presentationID)
215 MEDCALC::PointSpriteParameters* p = new MEDCALC::PointSpriteParameters();
216 _getParameters<MEDPresentationPointSprite>(presentationID, *p);
217 MEDCALC::PointSpriteParameters_var tmp(p);
221 MEDCALC::DeflectionShapeParameters
222 MEDPresentationManager_i::getDeflectionShapeParameters(MEDPresentation::TypeID presentationID)
224 MEDCALC::DeflectionShapeParameters p;
225 _getParameters<MEDPresentationDeflectionShape>(presentationID, p);
231 MEDPresentationManager_i::updateMeshView(MEDPresentation::TypeID presentationID, const MEDCALC::MeshViewParameters& params)
233 return _updatePresentation<MEDPresentationMeshView>(presentationID, params);
237 MEDPresentationManager_i::updateScalarMap(MEDPresentation::TypeID presentationID, const MEDCALC::ScalarMapParameters& params)
239 return _updatePresentation<MEDPresentationScalarMap>(presentationID, params);
243 MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters& params)
245 return _updatePresentation<MEDPresentationContour>(presentationID, params);
249 MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params)
251 return _updatePresentation<MEDPresentationVectorField>(presentationID, params);
255 MEDPresentationManager_i::updateSlices(MEDPresentation::TypeID presentationID, const MEDCALC::SlicesParameters& params)
257 return _updatePresentation<MEDPresentationSlices>(presentationID, params);
261 MEDPresentationManager_i::updateDeflectionShape(MEDPresentation::TypeID presentationID, const MEDCALC::DeflectionShapeParameters& params)
263 return _updatePresentation<MEDPresentationDeflectionShape>(presentationID, params);
267 MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters& params)
269 return _updatePresentation<MEDPresentationPointSprite>(presentationID, params);
273 MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentationID)
275 STDLOG("Remove presentation " << presentationID);
276 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
277 if (citr == _presentations.end()) {
278 std::cerr << "removePresentation(): presentation not found!!" << std::endl;
281 MEDPresentation* presentation = (*citr).second;
284 _presentations.erase(presentationID);
286 STDLOG("Presentation " << presentationID << " has been removed.");
291 MEDPresentationManager_i::activateView(MEDPresentation::TypeID presentationID)
293 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
294 if (citr == _presentations.end()) {
295 std::cerr << "activateView(): presentation not found!!" << std::endl;
298 MEDPresentation* presentation = (*citr).second;
300 if (!presentation->activateView())
302 // The view has been recreated - transfer all presentations that were in the deleted view to this new one
303 int viewId = presentation->getPyViewID();
304 std::map<MEDPresentation::TypeID, MEDPresentation*>::iterator citr = _presentations.begin();
305 for (; citr != _presentations.end(); ++citr)
307 if(citr->second->getPyViewID() == viewId)
308 citr->second->recreateViewSetup();
311 _activeViewPythonId = presentation->getPyViewID();
312 STDLOG("Activated view " << _activeViewPythonId);
317 MEDPresentationManager_i::getActiveViewPythonId()
319 //TODO: should be more elaborate to re-identify the active ParaView view when another
320 //mechanism than MED module has activated another view.
321 // Idea: 1/ call Python to current active view
322 // 2/ compare with all id(__viewX) from currently existing presentations
323 return _activeViewPythonId;
327 //MEDCALC::ViewModeType
328 //MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presentationID)
330 // MEDPresentation* pres = _getPresentation(presentationID);
332 // return pres->getViewMode();
334 // std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
335 // return MEDCALC::VIEW_MODE_DEFAULT;
340 MEDPresentationManager_i::getParavisDump(MEDPresentation::TypeID presentationID)
342 MEDPresentation* pres = _getPresentation(presentationID);
344 return CORBA::string_dup(pres->paravisDump().c_str());
347 throw KERNEL::createSalomeException("getParavisDump(): presentation not found!!");
350 MEDCALC::PresentationsList*
351 MEDPresentationManager_i::getAllPresentations()
353 MEDCALC::PresentationsList* presList = new MEDCALC::PresentationsList;
354 presList->length(_presentations.size());
355 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator it;
357 for (i = 0, it = _presentations.begin(); it != _presentations.end(); ++it, ++i)
358 (*presList)[i] = it->first;
363 MEDPresentationManager_i::cleanUp()
366 _activeViewPythonId = -1;
367 std::map<MEDPresentation::TypeID, MEDPresentation*>::iterator it;
368 for (it = _presentations.begin(); it != _presentations.end(); ++it)
370 _presentations.clear();