Salome HOME
Make MEDCouplingCorba and MEDCouplingClient importable.
[modules/med.git] / src / MEDCalc / cmp / MEDPresentation.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 // Authors: A Bruneton (CEA), C Aguerre (EdF)
20
21 #include "MEDPyLockWrapper.hxx"
22 #include "MEDFactoryClient.hxx"
23 #include "MEDPresentation.hxx"
24 #include "MEDPresentationException.hxx"
25 #include "MEDCouplingRefCountObject.hxx"
26 #include <SALOME_KernelServices.hxx>
27 #undef LOG
28 #include <Basics_Utils.hxx>
29
30 #include <sstream>
31
32 const std::string MEDPresentation::PROP_NAME  = "name";
33 const std::string MEDPresentation::PROP_NB_COMPONENTS = "nbComponents";
34 const std::string MEDPresentation::PROP_SELECTED_COMPONENT = "selectedComponent";
35 const std::string MEDPresentation::PROP_COMPONENT = "component_";
36 const std::string MEDPresentation::PROP_COLOR_MAP = "colorMap";
37 const std::string MEDPresentation::PROP_SCALAR_BAR_RANGE = "scalarBarRange";
38
39 MEDPresentation::MEDPresentation(MEDPresentation::TypeID handlerId, const std::string& name,
40                                  const MEDCALC::ViewModeType viewMode,
41                                  const MEDCALC::ColorMapType colorMap,
42                                  const MEDCALC::ScalarBarRangeType sbRange)
43     : _handlerId(handlerId), _propertiesStr(),
44       _mcFieldType(MEDCoupling::ON_CELLS),
45       _pvFieldType(""), _meshName(""), _fieldName(""), _fileName(""),
46       _selectedComponentIndex(-1),
47       _viewMode(viewMode),
48       _colorMap(colorMap),
49       _sbRange(sbRange),
50       _renderViewPyId(-1),  // will be set by MEDPresentationManager_i::_makePresentation()
51       _globalDict(0)
52 {
53   setStringProperty(MEDPresentation::PROP_NAME, name);
54
55   setIntProperty(MEDPresentation::PROP_NB_COMPONENTS, 0);
56   setIntProperty(MEDPresentation::PROP_SELECTED_COMPONENT, 0);
57
58   setIntProperty(MEDPresentation::PROP_COLOR_MAP, static_cast<int>(colorMap));
59   setIntProperty(MEDPresentation::PROP_SCALAR_BAR_RANGE, static_cast<int>(sbRange));
60
61   // Python variables:
62   int id = GeneratePythonId();
63   std::ostringstream oss_o, oss_d, oss_l, oss_s, oss_r;
64   oss_o << "__obj" << id;
65   oss_s << "__srcObj" << id;
66   oss_d << "__disp" << id;
67   oss_l << "__lut" << id;
68   oss_r << "__range" << id;
69   _objVar = oss_o.str();
70   _srcObjVar = oss_s.str();
71   _dispVar = oss_d.str();
72   _lutVar = oss_l.str();
73   _rangeVar = oss_r.str();
74 }
75
76 /**
77  * For most of the presentations the field name etc is required.
78  * For the MEDPresentationMeshView however, the handler ID is a mesh handler ID, not a field, and the
79  * treatment is specific.
80  */
81 void
82 MEDPresentation::initFieldMeshInfos()
83 {
84   MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
85   MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(_handlerId);
86   MEDCALC::MeshHandler* meshHandler = dataManager->getMeshHandler(fieldHandler->meshid);
87   MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
88
89   extractFileName(std::string(dataSHandler->uri));
90
91   _fieldName = fieldHandler->fieldname;
92   _mcFieldType = (MEDCoupling::TypeOfField) fieldHandler->type;
93   _pvFieldType = getPVFieldTypeString(_mcFieldType);
94   _colorByType = _pvFieldType;  // by default the same; overridden in DeflectionShape, VectorField, PointSprite and Contour
95   _meshName = meshHandler->name;
96 }
97
98 void
99 MEDPresentation::extractFileName(const std::string& name)
100 {
101   _fileName = name;
102   if (_fileName.substr(0, 7) != std::string("file://")) {
103     const char* msg = "MEDPresentation(): Data source is not a file! Can not proceed.";
104     STDLOG(msg);
105     throw MEDPresentationException(msg);
106   }
107   _fileName = _fileName.substr(7, _fileName.size());
108 }
109
110 MEDPresentation::~MEDPresentation()
111 {
112   STDLOG("~MEDPresentation(): clear display");
113   {
114     MEDPyLockWrapper lock;
115     std::ostringstream oss;
116
117     oss << "pvs.Hide(" << _objVar <<  ", view=" << getRenderViewVar() << ");";
118     execPyLine(oss.str());
119     // :TRICKY: The two following lines raise an exception when closing MED module
120     //          after sequence: MED - load file - PARAVIS - MED - close SALOME
121     //          (see Mantis #23461)
122     //execPyLine(getRenderViewVar() + ".ResetCamera();");
123     //execPyLine("pvs.Render();");
124   }
125 }
126
127 void
128 MEDPresentation::generatePipeline()
129 {
130   // Might be more complicated in the future:
131
132   this->internalGeneratePipeline();
133 }
134
135 //void
136 //MEDPresentation::pushPyObjects(PyObjectId obj, PyObjectId disp)
137 //{
138 //  _pipeline.push_back(obj);
139 //  _display.push_back(disp);
140 //}
141
142 void
143 MEDPresentation::pushAndExecPyLine(const std::string & lin)
144 {
145   execPyLine(lin);
146   _pythonCmds.push_back(lin);
147 }
148
149 void
150 MEDPresentation::execPyLine(const std::string & lin)
151 {
152   MEDPyLockWrapper lock;
153   STDLOG("@@@@ MEDPresentation::execPyLine() about to exec >> " << lin);
154   if(PyRun_SimpleString(lin.c_str()))
155     {
156       std::ostringstream oss;
157       oss << "MEDPresentation::execPyLine(): following Python command failed!\n";
158       oss << ">> " << lin;
159       STDLOG(oss.str());
160       throw KERNEL::createSalomeException(oss.str().c_str());
161     }
162 }
163
164 void
165 MEDPresentation::setStringProperty(const std::string& propName, const std::string& propValue)
166 {
167   _propertiesStr[propName] = propValue;
168 }
169
170 const std::string
171 MEDPresentation::getStringProperty(const std::string& propName) const
172 {
173   std::map<std::string, std::string>::const_iterator it = _propertiesStr.find(propName);
174   if (it != _propertiesStr.end()) {
175       return (*it).second;
176   }
177   else {
178       STDLOG("MEDPresentation::getStringProperty(): no property named " + propName);
179       throw MEDPresentationException("MEDPresentation::getStringProperty(): no property named " + propName);
180   }
181 }
182
183 void
184 MEDPresentation::setIntProperty(const std::string& propName, const int propValue)
185 {
186   _propertiesInt[propName] = propValue;
187 }
188
189 int
190 MEDPresentation::getIntProperty(const std::string& propName) const
191 {
192   std::map<std::string, int>::const_iterator it = _propertiesInt.find(propName);
193   if (it != _propertiesInt.end()) {
194       return (*it).second;
195   }
196   else {
197       STDLOG("MEDPresentation::getIntProperty(): no property named " + propName);
198       throw MEDPresentationException("MEDPresentation::getIntProperty(): no property named " + propName);
199   }
200 }
201
202  void
203  MEDPresentation::dumpIntProperties() const
204  {
205    std::map<std::string, int>::const_iterator it = _propertiesInt.begin();
206    STDLOG("@@@ Dumping INT properties");
207    for(; it != _propertiesInt.end(); ++it)
208      {
209        std::ostringstream oss;
210        oss << (*it).first << "  ->   " << (*it).second;
211        STDLOG(oss.str());
212      }
213  }
214
215  void
216  MEDPresentation::dumpStringProperties() const
217  {
218    std::map<std::string, std::string>::const_iterator it = _propertiesStr.begin();
219    STDLOG("@@@ Dumping STR properties");
220    for(; it != _propertiesStr.end(); ++it)
221      {
222        std::ostringstream oss;
223        oss << (*it).first << "  ->   " << (*it).second;
224        STDLOG(oss.str());
225      }
226  }
227
228  void
229  MEDPresentation::internalGeneratePipeline()
230  {
231    MEDPyLockWrapper lock;
232    pushAndExecPyLine( "import pvsimple as pvs;");
233    pushAndExecPyLine( "import medcalc");
234  }
235
236
237 /**
238 * @return a borrowed reference. Do not DECRREF!
239 */
240 PyObject*
241 MEDPresentation::getPythonObjectFromMain(const char* python_var) const
242 {
243   if (! _globalDict)
244     {
245       // All the calls below returns *borrowed* references
246       PyObject* main_module = PyImport_AddModule((char*)"__main__");
247       _globalDict = PyModule_GetDict(main_module);
248     }
249   return PyDict_GetItemString(_globalDict, python_var);
250 }
251
252 std::string
253 MEDPresentation::getPVFieldTypeString(MEDCoupling::TypeOfField fieldType) const
254 {
255   switch(fieldType)
256   {
257     case MEDCoupling::ON_CELLS:
258       return "CELLS";
259     case MEDCoupling::ON_NODES:
260       return "POINTS";
261     case MEDCoupling::ON_GAUSS_PT:
262       return "POINTS"; // because internally after application of the ELGA filter, the field will appear as a POINT field
263     case MEDCoupling::ON_GAUSS_NE:
264       return "POINTS"; // because internally after application of the ELNO mesh filter, the field will appear as a POINT field
265     default:
266       STDLOG("MEDPresentation::getPVFieldTypeString() -- Not implemented ! ELNO field?");
267       return "";
268   }
269 }
270
271 std::string
272 MEDPresentation::getRenderViewVar() const
273 {
274   std::ostringstream oss;
275   oss << "__view" << _renderViewPyId;
276   return oss.str();
277 }
278
279 /*!
280  * Creates the MEDReader source in the pipeline, and potentially apply GAUSS/ELNO filters.
281  */
282 void
283 MEDPresentation::createSource()
284 {
285   std::string typ;
286   switch(_mcFieldType) {
287     case MEDCoupling::ON_CELLS: typ = "P0"; break;
288     case MEDCoupling::ON_NODES: typ = "P1"; break;
289     case MEDCoupling::ON_GAUSS_PT: typ = "GAUSS"; break;
290     case MEDCoupling::ON_GAUSS_NE: typ = "GSSNE"; break;
291     default:
292       const char * msg ="MEDPresentation::createSource(): field type not impl. yet!";
293       STDLOG(msg);
294       throw KERNEL::createSalomeException(msg);
295   }
296
297   std::ostringstream oss;
298   oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');";
299   pushAndExecPyLine(oss.str()); oss.str("");
300   oss << "medcalc.SelectSourceField(" << _srcObjVar << ", '" << _meshName << "', '"
301       << _fieldName << "', '" << typ << "');";
302   pushAndExecPyLine(oss.str()); oss.str("");
303   // Generate complete vector fields: fields with 2 components will copied into <name>_vector and
304   // have a third null component added.
305   oss << _srcObjVar << ".GenerateVectors = 1;";
306   pushAndExecPyLine(oss.str()); oss.str("");
307
308   // Make sure this is set so we stick to time steps:
309   pushAndExecPyLine("pvs.GetAnimationScene().PlayMode = 'Snap To TimeSteps'");
310
311   // Deal with GAUSS fields:
312   if(_mcFieldType == MEDCoupling::ON_GAUSS_PT)
313     {
314       std::ostringstream oss, oss2;
315       oss2 << "__srcObj" << GeneratePythonId();
316       oss << oss2.str() << " = pvs.GaussPoints(Input=" << _srcObjVar << ");";
317       pushAndExecPyLine(oss.str()); oss.str("");
318       // Now the source becomes the result of the CellDatatoPointData:
319       _srcObjVar = oss2.str();
320       oss << _srcObjVar << ".SelectSourceArray = ['CELLS', 'ELGA@0'];";
321       pushAndExecPyLine(oss.str()); oss.str("");
322     }
323   if(_mcFieldType == MEDCoupling::ON_GAUSS_NE)
324     {
325       std::ostringstream oss, oss2;
326       oss2 << "__srcObj" << GeneratePythonId();
327       oss << oss2.str() << " = pvs.ELNOMesh(Input=" << _srcObjVar << ");";
328       pushAndExecPyLine(oss.str()); oss.str("");
329       // Now the source becomes the result of the CellDatatoPointData:
330       _srcObjVar = oss2.str();
331     }
332 }
333
334 void
335 MEDPresentation::setOrCreateRenderView()
336 {
337   std::ostringstream oss2;
338
339   std::string view(getRenderViewVar());
340   oss2 << "pvs._DisableFirstRenderCameraReset();";
341   pushAndExecPyLine(oss2.str()); oss2.str("");
342   if (_viewMode == MEDCALC::VIEW_MODE_OVERLAP) {
343       // this might potentially re-assign to an existing view variable, but this is OK, we
344       // normally reassign exactly the same RenderView object.
345       oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');";
346       pushAndExecPyLine(oss2.str()); oss2.str("");
347   } else if (_viewMode == MEDCALC::VIEW_MODE_REPLACE) {
348       // same as above
349       oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');";
350       pushAndExecPyLine(oss2.str()); oss2.str("");
351       oss2 << "pvs.active_objects.source and pvs.Hide(view=" << view << ");";
352       pushAndExecPyLine(oss2.str()); oss2.str("");
353       oss2 << "pvs.Render();";
354       pushAndExecPyLine(oss2.str()); oss2.str("");
355   } else if (_viewMode == MEDCALC::VIEW_MODE_NEW_LAYOUT) {
356       oss2 <<  "__layout1 = pvs.servermanager.misc.ViewLayout(registrationGroup='layouts');";
357       pushAndExecPyLine(oss2.str()); oss2.str("");
358       oss2 << view << " = pvs.CreateView('RenderView');";
359       pushAndExecPyLine(oss2.str()); oss2.str("");
360   } else if (_viewMode == MEDCALC::VIEW_MODE_SPLIT_VIEW) {
361       oss2 << view << " = pvs.CreateView('RenderView');";
362       pushAndExecPyLine(oss2.str()); oss2.str("");
363   }
364 }
365
366 void
367 MEDPresentation::resetCameraAndRender()
368 {
369   pushAndExecPyLine(getRenderViewVar() + ".ResetCamera();");
370   pushAndExecPyLine("pvs.Render();");
371 }
372
373 void
374 MEDPresentation::selectFieldComponent()
375 {
376   std::ostringstream oss, oss_l;
377   std::string ret;
378
379   if (_selectedComponentIndex != -1)
380     {
381       oss << _lutVar << ".VectorMode = 'Component';";
382       pushAndExecPyLine(oss.str()); oss.str("");
383       oss << _lutVar << ".VectorComponent = " << _selectedComponentIndex << ";";
384       pushAndExecPyLine(oss.str()); oss.str("");
385     }
386   else  // Euclidean norm
387     {
388       oss << _lutVar << ".VectorMode = 'Magnitude';";
389       pushAndExecPyLine(oss.str()); oss.str("");
390     }
391 }
392
393 /**
394  * Needs the LUT, so to be called after selectColorMap for the first time.
395  */
396 void
397 MEDPresentation::scalarBarTitle()
398 {
399   // get selected component name:
400   std::string compoName;
401   if (_selectedComponentIndex != -1)
402     {
403       std::ostringstream oss1;
404       oss1 << MEDPresentation::PROP_COMPONENT << _selectedComponentIndex;
405       compoName = getStringProperty(oss1.str());
406     }
407   else
408     {
409       if (getIntProperty(MEDPresentation::PROP_NB_COMPONENTS) == 1)
410         compoName = "";
411       else
412         compoName = "Magnitude";
413     }
414   std::ostringstream oss;
415   oss << "pvs.GetScalarBar(" << _lutVar << ").ComponentTitle = '" << compoName << "';";
416   pushAndExecPyLine(oss.str()); oss.str("");
417 }
418
419 void
420 MEDPresentation::selectColorMap()
421 {
422   std::ostringstream oss, oss2;
423
424   oss2 << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');";
425   pushAndExecPyLine(oss2.str());
426
427   switch (_colorMap) {
428   case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW:
429     oss << _lutVar << ".ApplyPreset('Blue to Red Rainbow',True);";
430     break;
431   case MEDCALC::COLOR_MAP_COOL_TO_WARM:
432     oss << _lutVar << ".ApplyPreset('Cool to Warm',True);";
433     break;
434   default:
435     STDLOG("MEDPresentation::getColorMapCommand(): invalid colormap!");
436     throw KERNEL::createSalomeException("MEDPresentation::getColorMapCommand(): invalid colormap!");
437   }
438   pushAndExecPyLine(oss.str());
439
440   selectFieldComponent(); // somehow PV keeps the LUT parameters of the previous presentation, so better reset this.
441 }
442
443 void
444 MEDPresentation::showObject()
445 {
446   std::ostringstream oss;
447   oss << _dispVar << " = pvs.Show(" << _objVar << ", " << getRenderViewVar() << ");";
448   pushAndExecPyLine(oss.str());
449 }
450
451 void
452 MEDPresentation::showScalarBar()
453 {
454   std::ostringstream oss;
455   oss << _dispVar <<  ".SetScalarBarVisibility(" << getRenderViewVar() << ", True);";
456   pushAndExecPyLine(oss.str());
457 }
458
459 void
460 MEDPresentation::colorBy()
461 {
462   std::ostringstream oss;
463   oss << "pvs.ColorBy(" << _dispVar << ", ('" << _colorByType << "', '" << _fieldName << "'));";
464   pushAndExecPyLine(oss.str());
465 }
466
467 void
468 MEDPresentation::rescaleTransferFunction()
469 {
470   std::ostringstream oss;
471   switch(_sbRange)
472   {
473     case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS:
474       oss << _dispVar << ".RescaleTransferFunctionToDataRangeOverTime();";
475       break;
476     case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP:
477       oss << _dispVar << ".RescaleTransferFunctionToDataRange(False);";
478       break;
479     default:
480       STDLOG("MEDPresentation::getRescaleCommand(): invalid range!");
481       throw KERNEL::createSalomeException("MEDPresentation::getRescaleCommand(): invalid range!");
482   }
483   pushAndExecPyLine(oss.str()); oss.str("");
484   // Get min-max
485   oss << _rangeVar << " = [" << _dispVar << ".LookupTable.RGBPoints[0], " << _dispVar << ".LookupTable.RGBPoints[-4]];";
486   pushAndExecPyLine(oss.str());
487
488   // Adapt scalar bar title
489   scalarBarTitle();
490 }
491
492
493
494 int
495 MEDPresentation::GeneratePythonId()
496 {
497   static int INIT_ID = 0;
498   return INIT_ID++;
499 }
500
501 bool
502 MEDPresentation::activateView()
503 {
504   MEDPyLockWrapper lock;
505
506   execPyLine("__alive = " + getRenderViewVar() + " in pvs.GetRenderViews()");
507   PyObject * obj = getPythonObjectFromMain("__alive");
508   bool alive = true;
509   if (obj && PyBool_Check(obj))
510     alive = (obj == Py_True);
511
512   if (alive)
513     // The view is still there,just activate it:
514     pushAndExecPyLine("pvs.SetActiveView(" + getRenderViewVar() + ");");
515   else
516     {
517       // The view disappeared, recreate it in a new layout. The transfer of the objects is to be done by the caller.
518       std::ostringstream oss;
519       oss <<  "pvs.servermanager.misc.ViewLayout(registrationGroup='layouts');";
520       pushAndExecPyLine(oss.str()); oss.str("");
521       oss << getRenderViewVar() << " = pvs.CreateView('RenderView');";
522       pushAndExecPyLine(oss.str()); oss.str("");
523     }
524   return alive;
525 }
526
527 /**!
528  * Called when the view has been recreated (because the user closed it).
529  * All the objects and set up are re-shown in the new view (which is stored in the same Python variable).
530  */
531 void
532 MEDPresentation::recreateViewSetup()
533 {
534   showObject();
535   colorBy();
536   showScalarBar();
537   selectColorMap();
538   rescaleTransferFunction();
539   resetCameraAndRender();
540 }
541
542 std::string
543 MEDPresentation::paravisDump() const
544 {
545   using namespace std;
546   ostringstream oss;
547   for (vector<string>::const_iterator it=_pythonCmds.begin(); it != _pythonCmds.end(); ++it)
548     {
549       oss << (*it);
550       oss << "\n";
551     }
552   return oss.str();
553 }
554
555 /**
556  * Query all available component names for the field associated with this presentation.
557  * Fills in all the corresponding string properties:
558  *  - PROP_COMPONENT1
559  *  - PROP_COMPONENT2
560  *    etc...
561  *  and the number of components.
562  */
563 void
564 MEDPresentation::fillAvailableFieldComponents()
565 {
566   MEDPyLockWrapper lock;  // GIL!
567   std::string typ;
568
569   if(_pvFieldType == "CELLS") {
570       typ = "CellData";
571   }
572   else if (_pvFieldType == "POINTS") {
573       typ = "PointData";
574   }
575   else {
576       std::string msg("Unsupported spatial discretisation: " + _pvFieldType);
577       STDLOG(msg);
578       throw KERNEL::createSalomeException(msg.c_str());
579   }
580
581   std::ostringstream oss;
582   oss << "__nbCompo = " << _srcObjVar << "." << typ << ".GetArray('" <<  _fieldName << "').GetNumberOfComponents();";
583   execPyLine(oss.str());
584   PyObject* p_obj = getPythonObjectFromMain("__nbCompo");
585   long nbCompo;
586   if (p_obj && PyInt_Check(p_obj))
587     nbCompo = PyInt_AS_LONG(p_obj);
588   else
589     {
590       STDLOG("Unexpected Python error");
591       throw KERNEL::createSalomeException("Unexpected Python error");
592     }
593   setIntProperty(MEDPresentation::PROP_NB_COMPONENTS, nbCompo);
594   for (long i = 0; i<nbCompo; i++)
595     {
596       std::ostringstream oss2;
597       oss2 << "__compo = " << _srcObjVar << "." << typ << ".GetArray('" <<  _fieldName << "').GetComponentName(" << i << ");";
598       execPyLine(oss2.str());
599       PyObject* p_obj = getPythonObjectFromMain("__compo");
600       std::string compo;
601       if (p_obj && PyString_Check(p_obj))
602         compo = std::string(PyString_AsString(p_obj));  // pointing to internal Python memory, so make a copy!!
603       else
604         {
605           STDLOG("Unexpected Python error");
606           throw KERNEL::createSalomeException("Unexpected Python error");
607         }
608       std::ostringstream oss_p;
609       oss_p << MEDPresentation::PROP_COMPONENT << i;
610       setStringProperty(oss_p.str(), compo);
611     }
612 }
613
614 /**
615  * In case where a CELLS field needs to be converted to POINT field.
616  * This updates the source object to become the result of the CellDatatoPointData filter.
617  */
618 void
619 MEDPresentation::applyCellToPointIfNeeded()
620 {
621   if (_pvFieldType == "CELLS")
622     {
623       std::ostringstream oss, oss2;
624       // Apply Cell data to point data:
625       oss2 << "__srcObj" << GeneratePythonId();
626       oss << oss2.str() << " = pvs.CellDatatoPointData(Input=" << _srcObjVar << ");";
627       pushAndExecPyLine(oss.str()); oss.str("");
628       // Now the source becomes the result of the CellDatatoPointData:
629       _srcObjVar = oss2.str();
630     }
631 }
632
633 ///**
634 // * Convert a vector field into a 3D vector field:
635 // *  - if the vector field is already 3D, nothing to do
636 // *  - if it is 2D, then add a null component
637 // *  - otherwise (tensor field, scalar field) throw
638 // */
639 //void
640 //MEDPresentation::convertTo3DVectorField()
641 //{
642 //  std::ostringstream oss, oss1, oss2, oss3;
643 //
644 //  int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS);
645 //  if (nbCompo < 2 || nbCompo > 3)
646 //    {
647 //      oss << "The field '" << _fieldName << "' must have 2 or 3 components for this presentation!";
648 //      STDLOG(oss.str());
649 //      throw KERNEL::createSalomeException(oss.str().c_str());
650 //    }
651 //  if (nbCompo == 3)
652 //    return;
653 //
654 //  // Apply calculator:
655 //  oss2 << "__srcObj" << GeneratePythonId();
656 //  oss << oss2.str() << " = pvs.Calculator(Input=" << _srcObjVar << ");";
657 //  pushAndExecPyLine(oss.str()); oss.str("");
658 //  // Now the source becomes the result of the CellDatatoPointData:
659 //  _srcObjVar = oss2.str();
660 //  std::string typ;
661 //  if(_pvFieldType == "CELLS")
662 //    typ = "Cell Data";
663 //  else if(_pvFieldType == "POINTS")
664 //    typ = "Point Data";
665 //  else
666 //    {
667 //      oss3 << "Field '" << _fieldName << "' has invalid field type";
668 //      STDLOG(oss3.str());
669 //      throw KERNEL::createSalomeException(oss3.str().c_str());
670 //    }
671 //  oss << _srcObjVar << ".AttributeMode = '" <<  typ << "';";
672 //  pushAndExecPyLine(oss.str()); oss.str("");
673 //  oss << _srcObjVar << ".ResultArrayName = '" <<  _fieldName << "_CALC';";  // will never be needed I think
674 //  pushAndExecPyLine(oss.str()); oss.str("");
675 //  oss << _srcObjVar << ".Function = '" <<  _fieldName << "_0*iHat + " << _fieldName << "_1*jHat + 0.0*zHat';";
676 //  pushAndExecPyLine(oss.str()); oss.str("");
677 //}