Salome HOME
[MEDCalc]: replace mode now targets the current view only.
[modules/med.git] / src / MEDCalc / cmp / MEDPresentationManager_i.cxx
1 // Copyright (C) 2011-2016  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "MEDPresentationManager_i.hxx"
21 #include "MEDFactoryClient.hxx"
22 #include "Basics_Utils.hxx"
23
24 // presentations
25 #include "MEDPresentationScalarMap.hxx"
26 //#include "MEDPresentationContour.hxx"
27 //#include "MEDPresentationVectorField.hxx"
28 //#include "MEDPresentationSlices.hxx"
29 //#include "MEDPresentationDeflectionShape.hxx"
30 //#include "MEDPresentationPointSprite.hxx"
31
32 #include <SALOME_KernelServices.hxx>
33
34 #include <iostream>
35 #include <sstream>
36
37 MEDPresentationManager_i* MEDPresentationManager_i::_instance = NULL;
38
39 MEDPresentationManager_i*
40 MEDPresentationManager_i::getInstance() {
41   if ( _instance == NULL )
42     _instance = new MEDPresentationManager_i();
43   return _instance;
44 }
45
46 MEDPresentationManager_i::MEDPresentationManager_i() :
47     _presentations(),
48     _activeViewPythonId(-1)
49 {
50 }
51
52 MEDPresentationManager_i::~MEDPresentationManager_i()
53 {
54   /*
55   std::vector<MEDPresentation*>::iterator itr = this->_presentations.begin();
56   for ( ; itr != this->_presentations.end(); ++itr) {
57     delete *itr;
58     *itr = NULL;
59   }
60   this->_presentations.clear();
61   */
62 }
63
64 MEDPresentation::TypeID
65 MEDPresentationManager_i::GenerateID()
66 {
67   static MEDPresentation::TypeID START_ID = -1;
68   START_ID++;
69   return START_ID;
70 }
71
72 MEDPresentation*
73 MEDPresentationManager_i::_getPresentation(MEDPresentation::TypeID presentationID) const
74 {
75   std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
76   if (citr == _presentations.end())
77     return NULL;
78   return (*citr).second;
79 }
80
81 void
82 MEDPresentationManager_i::setPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue)
83 {
84   MEDPresentation* pres = _getPresentation(presentationID);
85   if (pres)
86     pres->setStringProperty(propName, propValue);
87   else
88     throw KERNEL::createSalomeException("setPresentationStringProperty(): presentation not found!!");
89 }
90
91 char*
92 MEDPresentationManager_i::getPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName)
93 {
94   MEDPresentation* pres = _getPresentation(presentationID);
95   if (pres) {
96     return (char*) pres->getStringProperty(propName).c_str();
97   }
98   else
99     throw KERNEL::createSalomeException("getPresentationStringProperty(): presentation not found!!");
100 }
101
102 void
103 MEDPresentationManager_i::setPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName,
104                                                      const CORBA::Long propValue)
105 {
106   MEDPresentation* pres = _getPresentation(presentationID);
107   if (pres)
108     pres->setIntProperty(propName, propValue);
109   else
110     throw KERNEL::createSalomeException("setPresentationIntProperty(): presentation not found!!");
111 }
112
113 CORBA::Long
114 MEDPresentationManager_i::getPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName)
115 {
116   MEDPresentation* pres = _getPresentation(presentationID);
117   if (pres) {
118     return (CORBA::Long) pres->getIntProperty(propName);
119   }
120   else
121     throw KERNEL::createSalomeException("getPresentationIntProperty(): presentation not found!!");
122
123 }
124
125 MEDPresentation::TypeID
126 MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& params, const MEDCALC::MEDPresentationViewMode viewMode)
127 {
128   return _makePresentation<MEDPresentationScalarMap>(params, viewMode);
129 }
130
131 //MEDPresentation::TypeID
132 //MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params)
133 //{
134 //  return _makePresentation<MEDPresentationContour>(params);
135 //}
136 //
137 //MEDPresentation::TypeID
138 //MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params)
139 //{
140 //  return _makePresentation<MEDPresentationVectorField>(params);
141 //}
142 //
143 //MEDPresentation::TypeID
144 //MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params)
145 //{
146 //  return _makePresentation<MEDPresentationSlices>(params);
147 //}
148 //
149 //MEDPresentation::TypeID
150 //MEDPresentationManager_i::makeDeflectionShape(const MEDCALC::DeflectionShapeParameters& params)
151 //{
152 //  return _makePresentation<MEDPresentationDeflectionShape>(params);
153 //}
154 //
155 //MEDPresentation::TypeID
156 //MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params)
157 //{
158 //  return _makePresentation<MEDPresentationPointSprite>(params);
159 //}
160
161 MEDCALC::ScalarMapParameters*
162 MEDPresentationManager_i::getScalarMapParameters(MEDPresentation::TypeID presentationID)
163 {
164   MEDCALC::ScalarMapParameters* p = new MEDCALC::ScalarMapParameters();
165   _getParameters<MEDPresentationScalarMap>(presentationID, *p);
166   MEDCALC::ScalarMapParameters_var tmp(p);
167   return tmp._retn();
168 }
169
170 void
171 MEDPresentationManager_i::updateScalarMap(MEDPresentation::TypeID presentationID, const MEDCALC::ScalarMapParameters& params)
172 {
173   return _updatePresentation<MEDPresentationScalarMap>(presentationID, params);
174 }
175
176 //void
177 //MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters& params)
178 //{
179 //  return _updatePresentation<MEDPresentationContour>(presentationID, params);
180 //}
181 //
182 //void
183 //MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params)
184 //{
185 //  return _updatePresentation<MEDPresentationVectorField>(presentationID, params);
186 //}
187 //
188 //void
189 //MEDPresentationManager_i::updateSlices(MEDPresentation::TypeID presentationID, const MEDCALC::SlicesParameters& params)
190 //{
191 //  return _updatePresentation<MEDPresentationSlices>(presentationID, params);
192 //}
193 //
194 //void
195 //MEDPresentationManager_i::updateDeflectionShape(MEDPresentation::TypeID presentationID, const MEDCALC::DeflectionShapeParameters& params)
196 //{
197 //  return _updatePresentation<MEDPresentationDeflectionShape>(presentationID, params);
198 //}
199 //
200 //void
201 //MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters& params)
202 //{
203 //  return _updatePresentation<MEDPresentationPointSprite>(presentationID, params);
204 //}
205
206 CORBA::Boolean
207 MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentationID)
208 {
209   std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
210   if (citr == _presentations.end()) {
211     std::cerr << "removePresentation(): presentation not found!!" << std::endl;
212     return false;
213   }
214   MEDPresentation* presentation = (*citr).second;
215   if (presentation)
216     delete presentation;
217   _presentations.erase(presentationID);
218
219   STDLOG("Presentation " << presentationID << " has been removed.");
220   return true;
221 }
222
223 CORBA::Boolean
224 MEDPresentationManager_i::activateView(MEDPresentation::TypeID presentationID)
225 {
226   std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
227   if (citr == _presentations.end()) {
228     std::cerr << "activateView(): presentation not found!!" << std::endl;
229     return false;
230   }
231   MEDPresentation* presentation = (*citr).second;
232
233   presentation->activateView();
234   _activeViewPythonId = presentation->getPyViewID();
235   return true;
236 }
237
238 CORBA::Long
239 MEDPresentationManager_i::getActiveViewPythonId()
240 {
241   //TODO: should be more elaborate to re-identify the active ParaView view when another
242   //mechanism than MED module has activated another view.
243   // Idea: 1/ call Python to current active view
244   //       2/ compare with all id(__viewX) from currently existing presentations
245   return _activeViewPythonId;
246 }
247
248
249 //MEDCALC::MEDPresentationViewMode
250 //MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presentationID)
251 //{
252 //  MEDPresentation* pres = _getPresentation(presentationID);
253 //  if (pres) {
254 //    return pres->getViewMode();
255 //  } else {
256 //    std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
257 //    return MEDCALC::VIEW_MODE_DEFAULT;
258 //  }
259 //}
260
261 char*
262 MEDPresentationManager_i::getParavisDump(MEDPresentation::TypeID presentationID)
263 {
264   MEDPresentation* pres = _getPresentation(presentationID);
265   if (pres) {
266     return (char*) pres->paravisDump().c_str();
267   }
268   else
269     throw KERNEL::createSalomeException("getParavisDump(): presentation not found!!");
270 }
271