1 // Copyright (C) 2011-2016 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 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
77 if (citr == _presentations.end())
79 return (*citr).second;
83 MEDPresentationManager_i::setPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue)
85 MEDPresentation* pres = _getPresentation(presentationID);
87 pres->setStringProperty(propName, propValue);
89 throw KERNEL::createSalomeException("setPresentationStringProperty(): presentation not found!!");
93 MEDPresentationManager_i::getPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName)
95 MEDPresentation* pres = _getPresentation(presentationID);
97 return (char*) pres->getStringProperty(propName).c_str();
100 throw KERNEL::createSalomeException("getPresentationStringProperty(): presentation not found!!");
104 MEDPresentationManager_i::setPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName,
105 const CORBA::Long propValue)
107 MEDPresentation* pres = _getPresentation(presentationID);
109 pres->setIntProperty(propName, propValue);
111 throw KERNEL::createSalomeException("setPresentationIntProperty(): presentation not found!!");
115 MEDPresentationManager_i::getPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName)
117 MEDPresentation* pres = _getPresentation(presentationID);
119 return (CORBA::Long) pres->getIntProperty(propName);
122 throw KERNEL::createSalomeException("getPresentationIntProperty(): presentation not found!!");
126 MEDPresentation::TypeID
127 MEDPresentationManager_i::makeMeshView(const MEDCALC::MeshViewParameters& params, const MEDCALC::MEDPresentationViewMode viewMode)
129 return _makePresentation<MEDPresentationMeshView>(params, viewMode);
132 MEDPresentation::TypeID
133 MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& params, const MEDCALC::MEDPresentationViewMode viewMode)
135 return _makePresentation<MEDPresentationScalarMap>(params, viewMode);
138 MEDPresentation::TypeID
139 MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params, const MEDCALC::MEDPresentationViewMode viewMode)
141 return _makePresentation<MEDPresentationContour>(params, viewMode);
144 //MEDPresentation::TypeID
145 //MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params)
147 // return _makePresentation<MEDPresentationVectorField>(params);
150 MEDPresentation::TypeID
151 MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params, const MEDCALC::MEDPresentationViewMode viewMode)
153 return _makePresentation<MEDPresentationSlices>(params, viewMode);
156 //MEDPresentation::TypeID
157 //MEDPresentationManager_i::makeDeflectionShape(const MEDCALC::DeflectionShapeParameters& params)
159 // return _makePresentation<MEDPresentationDeflectionShape>(params);
162 //MEDPresentation::TypeID
163 //MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params)
165 // return _makePresentation<MEDPresentationPointSprite>(params);
168 MEDCALC::MeshViewParameters
169 MEDPresentationManager_i::getMeshViewParameters(MEDPresentation::TypeID presentationID)
171 MEDCALC::MeshViewParameters p;
172 _getParameters<MEDPresentationMeshView>(presentationID, p);
177 MEDCALC::ScalarMapParameters*
178 MEDPresentationManager_i::getScalarMapParameters(MEDPresentation::TypeID presentationID)
180 MEDCALC::ScalarMapParameters* p = new MEDCALC::ScalarMapParameters();
181 _getParameters<MEDPresentationScalarMap>(presentationID, *p);
182 MEDCALC::ScalarMapParameters_var tmp(p);
186 MEDCALC::ContourParameters
187 MEDPresentationManager_i::getContourParameters(MEDPresentation::TypeID presentationID)
189 MEDCALC::ContourParameters p;
190 _getParameters<MEDPresentationContour>(presentationID, p);
194 MEDCALC::SlicesParameters*
195 MEDPresentationManager_i::getSlicesParameters(MEDPresentation::TypeID presentationID)
197 MEDCALC::SlicesParameters* p = new MEDCALC::SlicesParameters();
198 _getParameters<MEDPresentationSlices>(presentationID, *p);
199 MEDCALC::SlicesParameters_var tmp(p);
205 MEDPresentationManager_i::updateMeshView(MEDPresentation::TypeID presentationID, const MEDCALC::MeshViewParameters& params)
207 return _updatePresentation<MEDPresentationMeshView>(presentationID, params);
211 MEDPresentationManager_i::updateScalarMap(MEDPresentation::TypeID presentationID, const MEDCALC::ScalarMapParameters& params)
213 return _updatePresentation<MEDPresentationScalarMap>(presentationID, params);
217 MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters& params)
219 return _updatePresentation<MEDPresentationContour>(presentationID, params);
223 //MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params)
225 // return _updatePresentation<MEDPresentationVectorField>(presentationID, params);
229 MEDPresentationManager_i::updateSlices(MEDPresentation::TypeID presentationID, const MEDCALC::SlicesParameters& params)
231 return _updatePresentation<MEDPresentationSlices>(presentationID, params);
235 //MEDPresentationManager_i::updateDeflectionShape(MEDPresentation::TypeID presentationID, const MEDCALC::DeflectionShapeParameters& params)
237 // return _updatePresentation<MEDPresentationDeflectionShape>(presentationID, params);
241 //MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters& params)
243 // return _updatePresentation<MEDPresentationPointSprite>(presentationID, params);
247 MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentationID)
249 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
250 if (citr == _presentations.end()) {
251 std::cerr << "removePresentation(): presentation not found!!" << std::endl;
254 MEDPresentation* presentation = (*citr).second;
257 _presentations.erase(presentationID);
259 STDLOG("Presentation " << presentationID << " has been removed.");
264 MEDPresentationManager_i::activateView(MEDPresentation::TypeID presentationID)
266 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
267 if (citr == _presentations.end()) {
268 std::cerr << "activateView(): presentation not found!!" << std::endl;
271 MEDPresentation* presentation = (*citr).second;
273 presentation->activateView();
274 _activeViewPythonId = presentation->getPyViewID();
275 STDLOG("Activated view " << _activeViewPythonId);
280 MEDPresentationManager_i::getActiveViewPythonId()
282 //TODO: should be more elaborate to re-identify the active ParaView view when another
283 //mechanism than MED module has activated another view.
284 // Idea: 1/ call Python to current active view
285 // 2/ compare with all id(__viewX) from currently existing presentations
286 return _activeViewPythonId;
290 //MEDCALC::MEDPresentationViewMode
291 //MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presentationID)
293 // MEDPresentation* pres = _getPresentation(presentationID);
295 // return pres->getViewMode();
297 // std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
298 // return MEDCALC::VIEW_MODE_DEFAULT;
303 MEDPresentationManager_i::getParavisDump(MEDPresentation::TypeID presentationID)
305 MEDPresentation* pres = _getPresentation(presentationID);
307 return (char*) pres->paravisDump().c_str();
310 throw KERNEL::createSalomeException("getParavisDump(): presentation not found!!");
313 MEDCALC::PresentationsList*
314 MEDPresentationManager_i::getAllPresentations()
316 MEDCALC::PresentationsList* presList = new MEDCALC::PresentationsList;
317 presList->length(_presentations.size());
318 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator it;
320 for (i = 0, it = _presentations.begin(); it != _presentations.end(); ++it, ++i)
321 (*presList)[i] = it->first;