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