Salome HOME
bos #20430 [CEA 20428] FIELDS : improvement of simplified visualisations
[modules/med.git] / src / MEDCalc / cmp / MEDPresentationScalarMap.cxx
index 17caf4366d6b9d7f8fb2b0e76315e6f58bdf017c..2f969abb07d160a53deb49248d8f8f5f9f76aa6d 100644 (file)
@@ -1,48 +1,90 @@
+// Copyright (C) 2016-2021  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "MEDPyLockWrapper.hxx"
+
 #include "MEDPresentationScalarMap.hxx"
-#include "MEDFactoryClient.hxx"
+#include "MEDPresentationException.hxx"
+
+#include <SALOME_KernelServices.hxx>
+#undef LOG  // should be fixed in KERNEL - double definition
+#include <Basics_Utils.hxx>
+
+#include <sstream>
+
+const std::string MEDPresentationScalarMap::TYPE_NAME = "MEDPresentationScalarMap";
 
-#include <iostream>
+MEDPresentationScalarMap::MEDPresentationScalarMap(const MEDCALC::ScalarMapParameters& params,
+                                                   const MEDCALC::ViewModeType viewMode) :
+    MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), _params(params)
+{
+}
 
 void
 MEDPresentationScalarMap::internalGeneratePipeline()
 {
-  MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
-
-  MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(_fieldHandler->meshid);
-  MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
-
-  std::string fileName(dataSHandler->uri);
-  std::string fieldName(_fieldHandler->fieldname);
-  std::string fieldType = getFieldTypeString();
-
-  std::cout << "Generating pipeline for SCALAR MAP:" <<std::endl;
-  std::cout << "\tfileName: " <<  fileName << std::endl;
-  std::cout << "\tfiedName: " << fieldName << std::endl;
-  if (fileName.substr(0, 7) != std::string("file://"))
-    {
-      std::cerr << "\tData source is not a file! Can not proceed." << std::endl;
-      return;
-    }
-
-  fileName = fileName.substr(7, fileName.size());
-  std::cout << "\tfileName: " <<  fileName << std::endl;
-
-  PyGILState_STATE _gil_state = PyGILState_Ensure();
-
-  std::string cmd = std::string("import pvsimple as pvs;");
-  cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + fileName + std::string("');");
-  cmd += std::string("__disp1 = pvs.Show(__obj1);");
-  cmd += std::string("pvs.ColorBy(__disp1, ('") + fieldType + std::string("', '") + fieldName + std::string("'));");
-  cmd += std::string("pvs.GetActiveViewOrCreate('RenderView').ResetCamera();");
-  cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
-
-  //std::cerr << "Python command:" << std::endl;
-  //std::cerr << cmd << std::endl;
-  PyRun_SimpleString(cmd.c_str());
-  // Retrieve Python object for internal storage:
-  PyObject * obj = getPythonObjectFromMain("__obj1");
-  PyObject * disp = getPythonObjectFromMain("__disp1");
-  pushInternal(obj, disp);
-
-  PyGILState_Release(_gil_state);
+  MEDPresentation::internalGeneratePipeline();
+
+  MEDPyLockWrapper lock;
+
+  setOrCreateRenderView(); // instantiate __viewXXX
+  createSource();
+  setTimestamp();
+
+  // Populate internal array of available components:
+  fillAvailableFieldComponents();
+
+  // Nothing to do in a scalar map, obj = source:
+  pushAndExecPyLine(_objVar + " = " + _srcObjVar);
+
+  showObject();
+
+  colorBy();
+  showScalarBar();
+  selectColorMap();
+  rescaleTransferFunction();
+  resetCameraAndRender();
+  pushAndExecPyLine(_dispVar+".SetRepresentationType('Surface')");
+}
+
+void
+MEDPresentationScalarMap::updatePipeline(const MEDCALC::ScalarMapParameters& params)
+{
+  if (params.fieldHandlerId != _params.fieldHandlerId)
+    throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
+
+  if (params.colorMap != _params.colorMap)
+    updateColorMap<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(params.colorMap);
+
+  if (std::string(params.displayedComponent) != std::string(_params.displayedComponent))
+    updateComponent<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(std::string(params.displayedComponent));
+  if (params.scalarBarRange != _params.scalarBarRange ||
+      params.hideDataOutsideCustomRange != _params.hideDataOutsideCustomRange ||
+      params.scalarBarRangeArray[0] != _params.scalarBarRangeArray[0] ||
+      params.scalarBarRangeArray[1] != _params.scalarBarRangeArray[1] )
+    updateScalarBarRange<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(params.scalarBarRange,
+                                                                                 params.hideDataOutsideCustomRange,
+                                                                                 params.scalarBarRangeArray[0],
+                                                                                 params.scalarBarRangeArray[1]);
+  if (params.visibility != _params.visibility)
+    updateVisibility<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(params.visibility);
+  if (params.scalarBarVisibility != _params.scalarBarVisibility)
+    updateScalarBarVisibility<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(params.scalarBarVisibility);
 }
+