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 "MEDPresentationScalarMap.hxx"
26 #include "MEDPresentationContour.hxx"
27 //#include "MEDPresentationSlices.hxx"
28 //#include "MEDPresentationVectorField.hxx"
29 //#include "MEDPresentationDeflectionShape.hxx"
30 //#include "MEDPresentationPointSprite.hxx"
32 #include <SALOME_KernelServices.hxx>
37 MEDPresentationManager_i* MEDPresentationManager_i::_instance = NULL;
39 MEDPresentationManager_i*
40 MEDPresentationManager_i::getInstance() {
41 if ( _instance == NULL )
42 _instance = new MEDPresentationManager_i();
46 MEDPresentationManager_i::MEDPresentationManager_i() :
48 _activeViewPythonId(-1)
52 MEDPresentationManager_i::~MEDPresentationManager_i()
55 std::vector<MEDPresentation*>::iterator itr = this->_presentations.begin();
56 for ( ; itr != this->_presentations.end(); ++itr) {
60 this->_presentations.clear();
64 MEDPresentation::TypeID
65 MEDPresentationManager_i::GenerateID()
67 static MEDPresentation::TypeID START_ID = -1;
73 MEDPresentationManager_i::_getPresentation(MEDPresentation::TypeID presentationID) const
75 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
76 if (citr == _presentations.end())
78 return (*citr).second;
82 MEDPresentationManager_i::setPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue)
84 MEDPresentation* pres = _getPresentation(presentationID);
86 pres->setStringProperty(propName, propValue);
88 throw KERNEL::createSalomeException("setPresentationStringProperty(): presentation not found!!");
92 MEDPresentationManager_i::getPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName)
94 MEDPresentation* pres = _getPresentation(presentationID);
96 return (char*) pres->getStringProperty(propName).c_str();
99 throw KERNEL::createSalomeException("getPresentationStringProperty(): presentation not found!!");
103 MEDPresentationManager_i::setPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName,
104 const CORBA::Long propValue)
106 MEDPresentation* pres = _getPresentation(presentationID);
108 pres->setIntProperty(propName, propValue);
110 throw KERNEL::createSalomeException("setPresentationIntProperty(): presentation not found!!");
114 MEDPresentationManager_i::getPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName)
116 MEDPresentation* pres = _getPresentation(presentationID);
118 return (CORBA::Long) pres->getIntProperty(propName);
121 throw KERNEL::createSalomeException("getPresentationIntProperty(): presentation not found!!");
125 MEDPresentation::TypeID
126 MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& params, const MEDCALC::MEDPresentationViewMode viewMode)
128 return _makePresentation<MEDPresentationScalarMap>(params, viewMode);
131 MEDPresentation::TypeID
132 MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params, const MEDCALC::MEDPresentationViewMode viewMode)
134 return _makePresentation<MEDPresentationContour>(params, viewMode);
137 //MEDPresentation::TypeID
138 //MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params)
140 // return _makePresentation<MEDPresentationVectorField>(params);
143 //MEDPresentation::TypeID
144 //MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params)
146 // return _makePresentation<MEDPresentationSlices>(params);
149 //MEDPresentation::TypeID
150 //MEDPresentationManager_i::makeDeflectionShape(const MEDCALC::DeflectionShapeParameters& params)
152 // return _makePresentation<MEDPresentationDeflectionShape>(params);
155 //MEDPresentation::TypeID
156 //MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params)
158 // return _makePresentation<MEDPresentationPointSprite>(params);
161 MEDCALC::ScalarMapParameters*
162 MEDPresentationManager_i::getScalarMapParameters(MEDPresentation::TypeID presentationID)
164 MEDCALC::ScalarMapParameters* p = new MEDCALC::ScalarMapParameters();
165 _getParameters<MEDPresentationScalarMap>(presentationID, *p);
166 MEDCALC::ScalarMapParameters_var tmp(p);
170 MEDCALC::ContourParameters
171 MEDPresentationManager_i::getContourParameters(MEDPresentation::TypeID presentationID)
173 MEDCALC::ContourParameters p;
174 _getParameters<MEDPresentationContour>(presentationID, p);
179 MEDPresentationManager_i::updateScalarMap(MEDPresentation::TypeID presentationID, const MEDCALC::ScalarMapParameters& params)
181 return _updatePresentation<MEDPresentationScalarMap>(presentationID, params);
185 MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters& params)
187 return _updatePresentation<MEDPresentationContour>(presentationID, params);
191 //MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params)
193 // return _updatePresentation<MEDPresentationVectorField>(presentationID, params);
197 //MEDPresentationManager_i::updateSlices(MEDPresentation::TypeID presentationID, const MEDCALC::SlicesParameters& params)
199 // return _updatePresentation<MEDPresentationSlices>(presentationID, params);
203 //MEDPresentationManager_i::updateDeflectionShape(MEDPresentation::TypeID presentationID, const MEDCALC::DeflectionShapeParameters& params)
205 // return _updatePresentation<MEDPresentationDeflectionShape>(presentationID, params);
209 //MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters& params)
211 // return _updatePresentation<MEDPresentationPointSprite>(presentationID, params);
215 MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentationID)
217 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
218 if (citr == _presentations.end()) {
219 std::cerr << "removePresentation(): presentation not found!!" << std::endl;
222 MEDPresentation* presentation = (*citr).second;
225 _presentations.erase(presentationID);
227 STDLOG("Presentation " << presentationID << " has been removed.");
232 MEDPresentationManager_i::activateView(MEDPresentation::TypeID presentationID)
234 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
235 if (citr == _presentations.end()) {
236 std::cerr << "activateView(): presentation not found!!" << std::endl;
239 MEDPresentation* presentation = (*citr).second;
241 presentation->activateView();
242 _activeViewPythonId = presentation->getPyViewID();
243 STDLOG("Activated view " << _activeViewPythonId);
248 MEDPresentationManager_i::getActiveViewPythonId()
250 //TODO: should be more elaborate to re-identify the active ParaView view when another
251 //mechanism than MED module has activated another view.
252 // Idea: 1/ call Python to current active view
253 // 2/ compare with all id(__viewX) from currently existing presentations
254 return _activeViewPythonId;
258 //MEDCALC::MEDPresentationViewMode
259 //MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presentationID)
261 // MEDPresentation* pres = _getPresentation(presentationID);
263 // return pres->getViewMode();
265 // std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
266 // return MEDCALC::VIEW_MODE_DEFAULT;
271 MEDPresentationManager_i::getParavisDump(MEDPresentation::TypeID presentationID)
273 MEDPresentation* pres = _getPresentation(presentationID);
275 return (char*) pres->paravisDump().c_str();
278 throw KERNEL::createSalomeException("getParavisDump(): presentation not found!!");
281 MEDCALC::PresentationsList*
282 MEDPresentationManager_i::getAllPresentations()
284 MEDCALC::PresentationsList* presList = new MEDCALC::PresentationsList;
285 presList->length(_presentations.size());
286 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator it;
288 for (i = 0, it = _presentations.begin(); it != _presentations.end(); ++it, ++i)
289 (*presList)[i] = it->first;