]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
[MEDCalcl] PointSprite and VectorField presentations.
authorabn <adrien.bruneton@cea.fr>
Wed, 3 Aug 2016 15:05:00 +0000 (17:05 +0200)
committerabn <adrien.bruneton@cea.fr>
Wed, 3 Aug 2016 15:05:00 +0000 (17:05 +0200)
+ also some refactoring to group common pipelines commands
+ still some work to be done on the scaling factor for VectorField

33 files changed:
idl/MEDPresentationManager.idl
src/MEDCalc/cmp/CMakeLists.txt
src/MEDCalc/cmp/MEDPresentation.cxx
src/MEDCalc/cmp/MEDPresentation.hxx
src/MEDCalc/cmp/MEDPresentation.txx
src/MEDCalc/cmp/MEDPresentationContour.cxx
src/MEDCalc/cmp/MEDPresentationContour.hxx
src/MEDCalc/cmp/MEDPresentationManager_i.cxx
src/MEDCalc/cmp/MEDPresentationManager_i.hxx
src/MEDCalc/cmp/MEDPresentationMeshView.cxx
src/MEDCalc/cmp/MEDPresentationMeshView.hxx
src/MEDCalc/cmp/MEDPresentationPointSprite.cxx
src/MEDCalc/cmp/MEDPresentationPointSprite.hxx
src/MEDCalc/cmp/MEDPresentationScalarMap.cxx
src/MEDCalc/cmp/MEDPresentationSlices.cxx
src/MEDCalc/cmp/MEDPresentationSlices.hxx
src/MEDCalc/cmp/MEDPresentationVectorField.cxx
src/MEDCalc/cmp/MEDPresentationVectorField.hxx
src/MEDCalc/gui/CMakeLists.txt
src/MEDCalc/gui/MEDWidgetHelperComponent.cxx [new file with mode: 0644]
src/MEDCalc/gui/MEDWidgetHelperComponent.hxx [new file with mode: 0644]
src/MEDCalc/gui/MEDWidgetHelperPointSprite.hxx [new file with mode: 0644]
src/MEDCalc/gui/MEDWidgetHelperScalarMap.cxx [deleted file]
src/MEDCalc/gui/MEDWidgetHelperScalarMap.hxx
src/MEDCalc/gui/MEDWidgetHelperVectorField.hxx [new file with mode: 0644]
src/MEDCalc/gui/PresentationController.cxx
src/MEDCalc/gui/PresentationEvent.hxx
src/MEDCalc/test/tui/point_sprite.py [new file with mode: 0644]
src/MEDCalc/test/tui/slices.py
src/MEDCalc/test/tui/tests.set
src/MEDCalc/test/tui/vector_field.py [new file with mode: 0644]
src/MEDCalc/tui/__init__.py
src/MEDCalc/tui/medpresentation.py

index 09689a92d87f26e59627941bd5674f4fe4c91044..c045eec36857c214ad0430e73b0ed59f61755264 100644 (file)
@@ -111,13 +111,13 @@ module MEDCALC
     long nbContours;
   };
 
-//  struct VectorFieldParameters {
-//    long fieldHandlerId;
-//    string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name
-//    ScalarBarRangeType scalarBarRange;
-//    ColorMapType colorMap;
-//  };
-//
+  struct VectorFieldParameters {
+    long fieldHandlerId;
+    string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name - only used to color the glyphs
+    ScalarBarRangeType scalarBarRange;
+    ColorMapType colorMap;
+  };
+
   struct SlicesParameters {
     long fieldHandlerId;
     string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name
@@ -131,12 +131,12 @@ module MEDCALC
 //    long fieldHandlerId;
 //  };
 //
-//  struct PointSpriteParameters {
-//    long fieldHandlerId;
-//    string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name
-//    ScalarBarRangeType scalarBarRange;
-//    ColorMapType colorMap;
-//  };
+  struct PointSpriteParameters {
+    long fieldHandlerId;
+    string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name
+    ScalarBarRangeType scalarBarRange;
+    ColorMapType colorMap;
+  };
 
   typedef sequence<long> PresentationsList;
 
@@ -144,14 +144,13 @@ module MEDCALC
 
   interface MEDPresentationManager : SALOME::GenericObj
   {
-    long makeMeshView(in MeshViewParameters params, in ViewModeType viewMode);
-    long makeScalarMap(in ScalarMapParameters params, in ViewModeType viewMode);
-    long makeContour(in ContourParameters params, in ViewModeType viewMode)
-      raises (SALOME::SALOME_Exception);
-//    long makeVectorField(in VectorFieldParameters params, in ViewModeType viewMode);
-    long makeSlices(in SlicesParameters params, in ViewModeType viewMode);
+    long makeMeshView(in MeshViewParameters params, in ViewModeType viewMode)   raises (SALOME::SALOME_Exception);
+    long makeScalarMap(in ScalarMapParameters params, in ViewModeType viewMode) raises (SALOME::SALOME_Exception);
+    long makeContour(in ContourParameters params, in ViewModeType viewMode)     raises (SALOME::SALOME_Exception);
+    long makeVectorField(in VectorFieldParameters params, in ViewModeType viewMode)  raises (SALOME::SALOME_Exception);
+    long makeSlices(in SlicesParameters params, in ViewModeType viewMode)  raises (SALOME::SALOME_Exception);
 //    long makeDeflectionShape(in DeflectionShapeParameters params, in ViewModeType viewMode);
-//    long makePointSprite(in PointSpriteParameters params, in ViewModeType viewMode);
+    long makePointSprite(in PointSpriteParameters params, in ViewModeType viewMode);
 
     void setPresentationStringProperty(in long presId, in string propName, in string propValue);
     string getPresentationStringProperty(in long presId, in string propName);
@@ -162,14 +161,16 @@ module MEDCALC
     ScalarMapParameters getScalarMapParameters(in long presId);
     ContourParameters   getContourParameters(in long presId);
     SlicesParameters     getSlicesParameters(in long presId);
+    VectorFieldParameters     getVectorFieldParameters(in long presId);
+    PointSpriteParameters     getPointSpriteParameters(in long presId);
 
     void updateMeshView(in long presId, in MeshViewParameters params);
     void updateScalarMap(in long presId, in ScalarMapParameters params);
     void updateContour(in long presId, in ContourParameters params);
-//    void updateVectorField(in long presId, in VectorFieldParameters params);
+    void updateVectorField(in long presId, in VectorFieldParameters params);
     void updateSlices(in long presId, in SlicesParameters params);
 //    void updateDeflectionShape(in long presId, in DeflectionShapeParameters params);
-//    void updatePointSprite(in long presId, in PointSpriteParameters params);
+    void updatePointSprite(in long presId, in PointSpriteParameters params);
 
     boolean removePresentation(in long presId);
 
index 3a443934c72719b3f0c38829c9b343846d70f4ce..c735141c4d9229485f71e2df059cf4d1618f8878 100644 (file)
@@ -42,10 +42,10 @@ SET(COMMON_SOURCES
   MEDPresentationMeshView.cxx
   MEDPresentationScalarMap.cxx
   MEDPresentationContour.cxx
-#  MEDPresentationVectorField.cxx
+  MEDPresentationVectorField.cxx
   MEDPresentationSlices.cxx
-#  MEDPresentationDeflectionShape.cxx
-#  MEDPresentationPointSprite.cxx
+  MEDPresentationPointSprite.cxx
+#  MEDPresentationDeflectionShape.cxx  
 )
 
 SET(MEDFactoryEngine_SOURCES
index c82f3076575c6f9540bd1ac4ba1c4b1a9fcb2dc8..a11077b64108d0ae80aa25e376bf4916e343a4e2 100644 (file)
@@ -57,6 +57,7 @@ MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const s
   _fileName = dataSHandler->uri;
   _fieldName = fieldHandler->fieldname;
   _fieldType = getFieldTypeString((MEDCoupling::TypeOfField) fieldHandler->type);
+  _meshName = meshHandler->name;
 
   if (_fileName.substr(0, 7) != std::string("file://")) {
     const char* msg = "MEDPresentation(): Data source is not a file! Can not proceed.";
@@ -209,6 +210,9 @@ MEDPresentation::getIntProperty(const std::string& propName) const
  }
 
 
+/**
+* @return a borrowed reference. Do not DECRREF!
+*/
 PyObject*
 MEDPresentation::getPythonObjectFromMain(const char* python_var) const
 {
@@ -244,74 +248,123 @@ MEDPresentation::getRenderViewVar() const
   return oss.str();
 }
 
-std::string
-MEDPresentation::getRenderViewCommand() const
+void
+MEDPresentation::createSource()
 {
-  std::ostringstream oss, oss2;
+  std::ostringstream oss;
+  oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  oss << _srcObjVar << ".GenerateVectors = 1;";
+  pushAndExecPyLine(oss.str()); oss.str("");
+}
+
+void
+MEDPresentation::setOrCreateRenderView()
+{
+  std::ostringstream oss2;
 
   std::string view(getRenderViewVar());
-  oss2 << "pvs._DisableFirstRenderCameraReset();" << std::endl;
+  oss2 << "pvs._DisableFirstRenderCameraReset();";
+  pushAndExecPyLine(oss2.str()); oss2.str("");
   if (_viewMode == MEDCALC::VIEW_MODE_OVERLAP) {
       // this might potentially re-assign to an existing view variable, but this is OK, we
       // normally reassign exaclty the same RenderView object.
-      oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');" << std::endl;
+      oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');";
+      pushAndExecPyLine(oss2.str()); oss2.str("");
   } else if (_viewMode == MEDCALC::VIEW_MODE_REPLACE) {
       // same as above
-      oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');" << std::endl;
-      oss2 << "pvs.active_objects.source and pvs.Hide(view=" << view << ");" << std::endl;
-      oss2 << "pvs.Render();" << std::endl;
+      oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');";
+      pushAndExecPyLine(oss2.str()); oss2.str("");
+      oss2 << "pvs.active_objects.source and pvs.Hide(view=" << view << ");";
+      pushAndExecPyLine(oss2.str()); oss2.str("");
+      oss2 << "pvs.Render();";
+      pushAndExecPyLine(oss2.str()); oss2.str("");
   } else if (_viewMode == MEDCALC::VIEW_MODE_NEW_LAYOUT) {
-      oss2 <<  "__layout1 = pvs.servermanager.misc.ViewLayout(registrationGroup='layouts');" << std::endl;
-      oss2 << view << " = pvs.CreateView('RenderView');" << std::endl;
+      oss2 <<  "__layout1 = pvs.servermanager.misc.ViewLayout(registrationGroup='layouts');";
+      pushAndExecPyLine(oss2.str()); oss2.str("");
+      oss2 << view << " = pvs.CreateView('RenderView');";
+      pushAndExecPyLine(oss2.str()); oss2.str("");
   } else if (_viewMode == MEDCALC::VIEW_MODE_SPLIT_VIEW) {
-      oss2 << view << " = pvs.CreateView('RenderView');" << std::endl;
+      oss2 << view << " = pvs.CreateView('RenderView');";
+      pushAndExecPyLine(oss2.str()); oss2.str("");
   }
-  return oss2.str();
 }
 
-std::string
-MEDPresentation::getResetCameraCommand() const
+void
+MEDPresentation::resetCameraAndRender()
 {
-  return getRenderViewVar() + ".ResetCamera();";
+  pushAndExecPyLine(getRenderViewVar() + ".ResetCamera();");
+  pushAndExecPyLine("pvs.Render();");
 }
 
-std::string
-MEDPresentation::getComponentSelectionCommand() const
+void
+MEDPresentation::selectFieldComponent()
 {
   std::ostringstream oss, oss_l;
   std::string ret;
 
   if (_selectedComponentIndex != -1)
     {
-      oss << _lutVar << ".VectorMode = 'Component';\n";
+      oss << _lutVar << ".VectorMode = 'Component';";
+      pushAndExecPyLine(oss.str()); oss.str("");
       oss << _lutVar << ".VectorComponent = " << _selectedComponentIndex << ";";
+      pushAndExecPyLine(oss.str()); oss.str("");
     }
   else  // Euclidean norm
     {
       oss << _lutVar << ".VectorMode = 'Magnitude';";
+      pushAndExecPyLine(oss.str()); oss.str("");
     }
-  return oss.str();
 }
 
-std::string
-MEDPresentation::getColorMapCommand() const
+void
+MEDPresentation::selectColorMap()
 {
-  std::string ret;
+  std::ostringstream oss, oss2;
+
+  oss2 << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');";
+  pushAndExecPyLine(oss2.str());
+
   switch (_colorMap) {
   case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW:
-    ret = _lutVar + ".ApplyPreset('Blue to Red Rainbow',True);";
+    oss << _lutVar << ".ApplyPreset('Blue to Red Rainbow',True);";
     break;
   case MEDCALC::COLOR_MAP_COOL_TO_WARM:
-    ret = _lutVar + ".ApplyPreset('Cool to Warm',True);";
+    oss << _lutVar << ".ApplyPreset('Cool to Warm',True);";
     break;
   default:
     STDLOG("MEDPresentation::getColorMapCommand(): invalid colormap!");
     throw KERNEL::createSalomeException("MEDPresentation::getColorMapCommand(): invalid colormap!");
   }
-  return ret;
+  pushAndExecPyLine(oss.str());
 }
-std::string
-MEDPresentation::getRescaleCommand() const
+
+void
+MEDPresentation::showObject()
+{
+  std::ostringstream oss;
+  oss << _dispVar << " = pvs.Show(" << _objVar << ", " << getRenderViewVar() << ");";
+  pushAndExecPyLine(oss.str());
+}
+
+void
+MEDPresentation::showScalarBar()
+{
+  std::ostringstream oss;
+  oss << _dispVar <<  ".SetScalarBarVisibility(" << getRenderViewVar() << ", True);";
+  pushAndExecPyLine(oss.str());
+}
+
+void
+MEDPresentation::colorBy(const std::string & fieldType)
+{
+  std::ostringstream oss;
+  oss << "pvs.ColorBy(" << _dispVar << ", ('" << fieldType << "', '" << _fieldName << "'));";
+  pushAndExecPyLine(oss.str());
+}
+
+void
+MEDPresentation::rescaleTransferFunction()
 {
   std::string ret;
   switch(_sbRange)
@@ -326,7 +379,7 @@ MEDPresentation::getRescaleCommand() const
       STDLOG("MEDPresentation::getRescaleCommand(): invalid range!");
       throw KERNEL::createSalomeException("MEDPresentation::getRescaleCommand(): invalid range!");
   }
-  return ret;
+  pushAndExecPyLine(ret);
 }
 
 int
@@ -416,3 +469,97 @@ MEDPresentation::fillAvailableFieldComponents()
     }
 }
 
+/**
+ * In case where a CELLS field needs to be converted to POINT field.
+ * This updates the source object to become the result of the CellDatatoPointData filter.
+ */
+void
+MEDPresentation::applyCellToPointIfNeeded()
+{
+  std::ostringstream oss, oss2;
+  // Apply Cell data to point data:
+  oss2 << "__srcObj" << GeneratePythonId();
+  oss << oss2.str() << " = pvs.CellDatatoPointData(Input=" << _srcObjVar << ");";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  // Now the source becomes the result of the CellDatatoPointData:
+  _srcObjVar = oss2.str();
+}
+
+/**
+ * Convert a vector field into a 3D vector field:
+ *  - if the vector field is already 3D, nothing to do
+ *  - if it is 2D, then add a null component
+ *  - otherwise (tensor field, scalar field) throw
+ */
+void
+MEDPresentation::convertTo3DVectorField()
+{
+  std::ostringstream oss, oss1, oss2, oss3;
+
+  int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS);
+  if (nbCompo < 2 || nbCompo > 3)
+    {
+      oss << "The field '" << _fieldName << "' must have 2 or 3 components for this presentation!";
+      STDLOG(oss.str());
+      throw KERNEL::createSalomeException(oss.str().c_str());
+    }
+  if (nbCompo == 3)
+    return;
+
+  // Apply calculator:
+  oss2 << "__srcObj" << GeneratePythonId();
+  oss << oss2.str() << " = pvs.Calculator(Input=" << _srcObjVar << ");";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  // Now the source becomes the result of the CellDatatoPointData:
+  _srcObjVar = oss2.str();
+  std::string typ;
+  if(_fieldType == "CELLS")
+    typ = "Cell Data";
+  else if(_fieldType == "POINTS")
+    typ = "Point Data";
+  else
+    {
+      oss3 << "Field '" << _fieldName << "' has invalid field type";
+      STDLOG(oss3.str());
+      throw KERNEL::createSalomeException(oss3.str().c_str());
+    }
+  oss << _srcObjVar << ".AttributeMode = '" <<  typ << "';";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  oss << _srcObjVar << ".ResultArrayName = '" <<  _fieldName << "_CALC';";  // will never be needed I think
+  pushAndExecPyLine(oss.str()); oss.str("");
+  oss << _srcObjVar << ".Function = '" <<  _fieldName << "_0*iHat + " << _fieldName << "_1*jHat + 0.0*zHat';";
+  pushAndExecPyLine(oss.str()); oss.str("");
+}
+
+//double
+//MEDPresentation::computeCellAverageSize()
+//{
+//  std::ostringstream oss;
+//  oss << "import MEDLoader;";
+//  pushAndExecPyLine(oss.str()); oss.str("");
+//  oss << "__mesh = MEDLoader.ReadMeshFromFile('" << _fileName << "', '" << _meshName << "');";
+//  pushAndExecPyLine(oss.str()); oss.str("");
+//
+//  oss << "__bb = __mesh.getBoundingBox()";
+//  pushAndExecPyLine(oss.str()); oss.str("");
+//  oss << "__deltas = [x[1]-x[0] for x in __bb];";
+//  pushAndExecPyLine(oss.str()); oss.str("");
+//  oss << "__vol = reduce(lambda x,y:x*y, __deltas, 1.0);";
+//  pushAndExecPyLine(oss.str()); oss.str("");
+//  // Average cell size is the the n-th root of average volume of a cell, with n being the space dimension
+//  oss << "__cellSize = (__vol/__mesh.getNumberOfCells())**(1.0/len(__bb));";
+//  pushAndExecPyLine(oss.str()); oss.str("");
+//
+//  PyObject * pyObj = getPythonObjectFromMain("__cellSize");
+//  bool err = false;
+//  if (!pyObj || !PyFloat_Check(pyObj)) {  /* nothing to do, err handler below */}
+//  else {
+//      double ret= PyFloat_AsDouble(pyObj);
+//      if(!PyErr_Occurred())
+//        return ret;
+//    }
+//  // From here, an error for sure.
+//  const char * msg = "MEDPresentation::computeCellAverageSize(): Python error.";
+//  STDLOG(msg);
+//  throw KERNEL::createSalomeException(msg);
+//}
index bfcdd2fccd2a68af110fc812181ddf641a2ec4c3..55999b0e1fbd4f1d45e727fa6d4d46db16263a25 100644 (file)
@@ -73,13 +73,18 @@ protected:
                   const MEDCALC::ViewModeType viewMode,
                   const MEDCALC::ColorMapType colorMap,
                   const MEDCALC::ScalarBarRangeType sbRange);
-  std::string getRenderViewCommand() const;
   std::string getRenderViewVar() const;
-  std::string getResetCameraCommand() const;
 
-  std::string getComponentSelectionCommand() const;
-  std::string getColorMapCommand() const;
-  std::string getRescaleCommand() const;
+  // The most common elements of the ParaView pipeline:
+  void setOrCreateRenderView();
+  void createSource();
+  void selectFieldComponent();
+  void showObject();
+  void colorBy(const std::string & fieldType);
+  void showScalarBar();
+  void rescaleTransferFunction();
+  void selectColorMap();
+  void resetCameraAndRender();
 
   virtual void internalGeneratePipeline();
   PyObject* getPythonObjectFromMain(const char* var) const;
@@ -90,6 +95,10 @@ protected:
   MEDPresentation::TypeID getID() const { return _fieldHandlerId; }
 
   void fillAvailableFieldComponents();
+  void applyCellToPointIfNeeded();
+  void convertTo3DVectorField();
+//  double computeCellAverageSize();
+  //void computeFieldRange
 
 //  virtual MEDCALC::ViewModeType getViewMode() = 0;
 
@@ -118,6 +127,7 @@ private:
   void updatePipeline(const PresentationParameters& params);
 
 protected:
+  std::string _meshName;
   std::string _fileName;
   std::string _fieldName;
   std::string _fieldType;
index dc99dcdc522b111732d6eebc6b84db36f3ca031e..59b09181c3c0d4acad60ac8de0c61c5227316736 100644 (file)
@@ -89,8 +89,7 @@ MEDPresentation::updateComponent(const std::string& newCompo)
     MEDPyLockWrapper lock;
 
     std::ostringstream oss;
-    std::string cmd = getComponentSelectionCommand();
-    pushAndExecPyLine(cmd);
+    selectFieldComponent();
     pushAndExecPyLine("pvs.Render();");
   }
 
@@ -115,8 +114,7 @@ MEDPresentation::updateColorMap(MEDCALC::ColorMapType colorMap)
   // Update the pipeline:
   {
     MEDPyLockWrapper lock;
-    std::string cmd = getColorMapCommand();
-    pushAndExecPyLine(cmd);
+    selectColorMap();
     pushAndExecPyLine("pvs.Render();");
   }
 }
@@ -140,8 +138,7 @@ MEDPresentation::updateScalarBarRange(MEDCALC::ScalarBarRangeType sbRange)
   // Update the pipeline:
   {
     MEDPyLockWrapper lock;
-    std::string cmd = getRescaleCommand();
-    pushAndExecPyLine(cmd);
+    rescaleTransferFunction();
     pushAndExecPyLine("pvs.Render();");
   }
 }
index fee4659e59a133cb89f096b5503117c35bfa34e8..f08493b3088ad13553f1608a801d5ddbb530d17c 100644 (file)
@@ -36,15 +36,17 @@ MEDPresentationContour::MEDPresentationContour(const MEDCALC::ContourParameters&
   setIntProperty(MEDPresentationContour::PROP_NB_CONTOUR, params.nbContours);
 }
 
-std::string
-MEDPresentationContour::getContourCommand() const
+void
+MEDPresentationContour::setNumberContours()
 {
-  std::ostringstream oss1;
+  std::ostringstream oss;
 
-  oss1 << "min_max = " << _srcObjVar << ".PointData.GetArray('" << _fieldName << "').GetRange();\n";
-  oss1 << "delta = (min_max[1]-min_max[0])/float(" << _params.nbContours << ");\n";
-  oss1 << _objVar << ".Isosurfaces = [min_max[0]+0.5*delta+i*delta for i in range(" << _params.nbContours << ")];\n";
-  return oss1.str();
+  oss << "min_max = " << _srcObjVar << ".PointData.GetArray('" << _fieldName << "').GetRange();";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  oss << "delta = (min_max[1]-min_max[0])/float(" << _params.nbContours << ");";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  oss << _objVar << ".Isosurfaces = [min_max[0]+0.5*delta+i*delta for i in range(" << _params.nbContours << ")];";
+  pushAndExecPyLine(oss.str()); oss.str("");
 }
 
 void
@@ -54,11 +56,7 @@ MEDPresentationContour::internalGeneratePipeline()
 
   MEDPyLockWrapper lock;
 
-  std::ostringstream oss_o, oss;
-  std::string view(getRenderViewVar());
-
-  oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');";
-  pushAndExecPyLine(oss.str()); oss.str("");
+  createSource();
 
   // Populate internal array of available components:
   fillAvailableFieldComponents();
@@ -69,41 +67,27 @@ MEDPresentationContour::internalGeneratePipeline()
       throw KERNEL::createSalomeException(msg);
     }
 
-  pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX
+  setOrCreateRenderView(); // instanciate __viewXXX
 
-  if(_fieldType == "CELLS")
-    {
-      // In case of a CELLS field need to convert to POINT field, and update source
-      STDLOG("Applying CellDatatoPointData filter");
-      std::ostringstream oss2, oss4;
-      // Apply Cell data to point data:
-      oss2 << "__obj" << GeneratePythonId();
-      oss << oss2.str() << " = pvs.CellDatatoPointData(Input=" << _srcObjVar << ");";
-      pushAndExecPyLine(oss.str()); oss.str("");
-      // Now the source becomes the result of the CellDatatoPointData:
-      _srcObjVar = oss2.str();
-    }
+  // Contour needs point data:
+  applyCellToPointIfNeeded();
+
+  std::ostringstream oss;
   oss << _objVar << " = pvs.Contour(Input=" << _srcObjVar << ");";
   pushAndExecPyLine(oss.str()); oss.str("");
+
+  showObject();
+
   oss << _objVar << ".ContourBy = ['POINTS', '" << _fieldName << "'];";
   pushAndExecPyLine(oss.str()); oss.str("");
 
   // Set number of contours
-  pushAndExecPyLine(getContourCommand());
-
-  oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");";
-  pushAndExecPyLine(oss.str()); oss.str("");
-  oss << "pvs.ColorBy(" << _dispVar << ", ('POINTS', '" << _fieldName << "'));";  // necessarily POINTS
-  pushAndExecPyLine(oss.str()); oss.str("");
-  oss << _dispVar <<  ".SetScalarBarVisibility(" << view << ", True);";
-  pushAndExecPyLine(oss.str()); oss.str("");
-  oss << getRescaleCommand();
-  pushAndExecPyLine(oss.str()); oss.str("");
-  oss << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');";
-  pushAndExecPyLine(oss.str()); oss.str("");
-  pushAndExecPyLine(getColorMapCommand()); oss.str("");
-  pushAndExecPyLine(getResetCameraCommand());
-  pushAndExecPyLine("pvs.Render();");
+  setNumberContours();
+  colorBy("POINTS");    // necessarily POINTS because of the conversion above
+  showScalarBar();
+  rescaleTransferFunction();
+  selectColorMap();
+  resetCameraAndRender();
 }
 
 void
@@ -132,8 +116,7 @@ MEDPresentationContour::updateNbContours(const int nbContours)
   // Update the pipeline:
   {
     MEDPyLockWrapper lock;
-    std::string cmd = getContourCommand();
-    pushAndExecPyLine(cmd);
+    setNumberContours();
     pushAndExecPyLine("pvs.Render();");
   }
 }
index bf36fee8c3a4eaa2f73cbf5e84c8faf10c968576..d7fbc19defb74583d06ce790ed3ececcd72237de 100644 (file)
@@ -41,7 +41,7 @@ protected:
   void updateNbContours(const int nbContours);
   virtual void internalGeneratePipeline();
 
-  std::string getContourCommand() const;
+  void setNumberContours();
 
 private:
   MEDCALC::ContourParameters _params;
index 09b2f57265fd6b6e55b8393385ac4cdc962b6082..876b3ec1ceb5ed730cee66e130148d6eec25d589 100644 (file)
@@ -26,9 +26,9 @@
 #include "MEDPresentationScalarMap.hxx"
 #include "MEDPresentationContour.hxx"
 #include "MEDPresentationSlices.hxx"
-//#include "MEDPresentationVectorField.hxx"
+#include "MEDPresentationVectorField.hxx"
 //#include "MEDPresentationDeflectionShape.hxx"
-//#include "MEDPresentationPointSprite.hxx"
+#include "MEDPresentationPointSprite.hxx"
 
 #include <SALOME_KernelServices.hxx>
 
@@ -141,12 +141,12 @@ MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params,
   return _makePresentation<MEDPresentationContour>(params, viewMode);
 }
 
-//MEDPresentation::TypeID
-//MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params)
-//{
-//  return _makePresentation<MEDPresentationVectorField>(params);
-//}
-//
+MEDPresentation::TypeID
+MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params, const MEDCALC::ViewModeType viewMode)
+{
+  return _makePresentation<MEDPresentationVectorField>(params, viewMode);
+}
+
 MEDPresentation::TypeID
 MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params, const MEDCALC::ViewModeType viewMode)
 {
@@ -158,12 +158,12 @@ MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params, co
 //{
 //  return _makePresentation<MEDPresentationDeflectionShape>(params);
 //}
-//
-//MEDPresentation::TypeID
-//MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params)
-//{
-//  return _makePresentation<MEDPresentationPointSprite>(params);
-//}
+
+MEDPresentation::TypeID
+MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params, const MEDCALC::ViewModeType viewMode)
+{
+  return _makePresentation<MEDPresentationPointSprite>(params, viewMode);
+}
 
 MEDCALC::MeshViewParameters
 MEDPresentationManager_i::getMeshViewParameters(MEDPresentation::TypeID presentationID)
@@ -200,6 +200,23 @@ MEDPresentationManager_i::getSlicesParameters(MEDPresentation::TypeID presentati
   return tmp._retn();
 }
 
+MEDCALC::VectorFieldParameters*
+MEDPresentationManager_i::getVectorFieldParameters(MEDPresentation::TypeID presentationID)
+{
+  MEDCALC::VectorFieldParameters* p = new MEDCALC::VectorFieldParameters();
+  _getParameters<MEDPresentationVectorField>(presentationID, *p);
+  MEDCALC::VectorFieldParameters_var tmp(p);
+  return tmp._retn();
+}
+
+MEDCALC::PointSpriteParameters*
+MEDPresentationManager_i::getPointSpriteParameters(MEDPresentation::TypeID presentationID)
+{
+  MEDCALC::PointSpriteParameters* p = new MEDCALC::PointSpriteParameters();
+  _getParameters<MEDPresentationPointSprite>(presentationID, *p);
+  MEDCALC::PointSpriteParameters_var tmp(p);
+  return tmp._retn();
+}
 
 void
 MEDPresentationManager_i::updateMeshView(MEDPresentation::TypeID presentationID, const MEDCALC::MeshViewParameters& params)
@@ -219,12 +236,12 @@ MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID,
   return _updatePresentation<MEDPresentationContour>(presentationID, params);
 }
 
-//void
-//MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params)
-//{
-//  return _updatePresentation<MEDPresentationVectorField>(presentationID, params);
-//}
-//
+void
+MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params)
+{
+  return _updatePresentation<MEDPresentationVectorField>(presentationID, params);
+}
+
 void
 MEDPresentationManager_i::updateSlices(MEDPresentation::TypeID presentationID, const MEDCALC::SlicesParameters& params)
 {
@@ -236,12 +253,12 @@ MEDPresentationManager_i::updateSlices(MEDPresentation::TypeID presentationID, c
 //{
 //  return _updatePresentation<MEDPresentationDeflectionShape>(presentationID, params);
 //}
-//
-//void
-//MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters& params)
-//{
-//  return _updatePresentation<MEDPresentationPointSprite>(presentationID, params);
-//}
+
+void
+MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters& params)
+{
+  return _updatePresentation<MEDPresentationPointSprite>(presentationID, params);
+}
 
 CORBA::Boolean
 MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentationID)
index c2c17873a2a73d0b5e69c24def524928412bcfc5..9f89afcc1ce95bbcbb7dd63e5dddef1aab5ad764 100644 (file)
@@ -42,10 +42,10 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager,
   MEDCALC_EXPORT MEDPresentation::TypeID makeMeshView(const MEDCALC::MeshViewParameters&, const MEDCALC::ViewModeType);
   MEDCALC_EXPORT MEDPresentation::TypeID makeScalarMap(const MEDCALC::ScalarMapParameters&, const MEDCALC::ViewModeType);
   MEDCALC_EXPORT MEDPresentation::TypeID makeContour(const MEDCALC::ContourParameters&, const MEDCALC::ViewModeType);
-//  MEDCALC_EXPORT MEDPresentation::TypeID makeVectorField(const MEDCALC::VectorFieldParameters&, const MEDCALC::ViewModeType);
+  MEDCALC_EXPORT MEDPresentation::TypeID makeVectorField(const MEDCALC::VectorFieldParameters&, const MEDCALC::ViewModeType);
   MEDCALC_EXPORT MEDPresentation::TypeID makeSlices(const MEDCALC::SlicesParameters&, const MEDCALC::ViewModeType);
 //  MEDCALC_EXPORT MEDPresentation::TypeID makeDeflectionShape(const MEDCALC::DeflectionShapeParameters&, const MEDCALC::ViewModeType);
-//  MEDCALC_EXPORT MEDPresentation::TypeID makePointSprite(const MEDCALC::PointSpriteParameters&, const MEDCALC::ViewModeType);
+  MEDCALC_EXPORT MEDPresentation::TypeID makePointSprite(const MEDCALC::PointSpriteParameters&, const MEDCALC::ViewModeType);
 
   MEDCALC_EXPORT void setPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue);
   MEDCALC_EXPORT char* getPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName);
@@ -57,14 +57,16 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager,
   MEDCALC_EXPORT MEDCALC::ScalarMapParameters* getScalarMapParameters(MEDPresentation::TypeID presentationID);
   MEDCALC_EXPORT MEDCALC::ContourParameters    getContourParameters(MEDPresentation::TypeID presentationID);
   MEDCALC_EXPORT MEDCALC::SlicesParameters*    getSlicesParameters(MEDPresentation::TypeID presentationID);
+  MEDCALC_EXPORT MEDCALC::VectorFieldParameters*    getVectorFieldParameters(MEDPresentation::TypeID presentationID);
+  MEDCALC_EXPORT MEDCALC::PointSpriteParameters*    getPointSpriteParameters(MEDPresentation::TypeID presentationID);
 
   MEDCALC_EXPORT void updateMeshView(MEDPresentation::TypeID, const MEDCALC::MeshViewParameters&);
   MEDCALC_EXPORT void updateScalarMap(MEDPresentation::TypeID, const MEDCALC::ScalarMapParameters&);
   MEDCALC_EXPORT void updateContour(MEDPresentation::TypeID, const MEDCALC::ContourParameters&);
-//  MEDCALC_EXPORT void updateVectorField(MEDPresentation::TypeID, const MEDCALC::VectorFieldParameters&);
+  MEDCALC_EXPORT void updateVectorField(MEDPresentation::TypeID, const MEDCALC::VectorFieldParameters&);
   MEDCALC_EXPORT void updateSlices(MEDPresentation::TypeID, const MEDCALC::SlicesParameters&);
 //  MEDCALC_EXPORT void updateDeflectionShape(MEDPresentation::TypeID, const MEDCALC::DeflectionShapeParameters&);
-//  MEDCALC_EXPORT void updatePointSprite(MEDPresentation::TypeID, const MEDCALC::PointSpriteParameters&);
+  MEDCALC_EXPORT void updatePointSprite(MEDPresentation::TypeID, const MEDCALC::PointSpriteParameters&);
 
   MEDCALC_EXPORT CORBA::Boolean removePresentation(MEDPresentation::TypeID);
   MEDCALC_EXPORT CORBA::Boolean activateView(MEDPresentation::TypeID);
index 83678f19bffd2a1b69b4aa2a7def0710ac2103d8..60ce767e6a3e2b15bd160134b53d9e6d3614b6b2 100644 (file)
@@ -38,8 +38,8 @@ MEDPresentationMeshView::MEDPresentationMeshView(const MEDCALC::MeshViewParamete
   setIntProperty(MEDPresentationMeshView::PROP_MESH_MODE, params.mode);
 }
 
-std::string
-MEDPresentationMeshView::getMeshViewCommand() const
+void
+MEDPresentationMeshView::representationType()
 {
   std::ostringstream oss1;
 
@@ -59,8 +59,7 @@ MEDPresentationMeshView::getMeshViewCommand() const
       STDLOG(mes);
       throw KERNEL::createSalomeException(mes);
   }
-
-  return oss1.str();
+  pushAndExecPyLine(oss1.str());
 }
 
 void
@@ -70,19 +69,16 @@ MEDPresentationMeshView::internalGeneratePipeline()
 
   MEDPyLockWrapper lock;
 
-  std::ostringstream oss;
-  std::string view(getRenderViewVar());
+  createSource();
+  setOrCreateRenderView();
 
-  oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');";
-  pushAndExecPyLine(oss.str()); oss.str("");
-  pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX
+  std::ostringstream oss;
   oss << _objVar << " = " << _srcObjVar << ";";
   pushAndExecPyLine(oss.str()); oss.str("");
-  oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");";
-  pushAndExecPyLine(oss.str()); oss.str("");
-  pushAndExecPyLine(getMeshViewCommand());
-  pushAndExecPyLine(getResetCameraCommand());
-  pushAndExecPyLine("pvs.Render();");
+
+  showObject();
+  representationType();
+  resetCameraAndRender();
 }
 
 void
@@ -106,8 +102,7 @@ MEDPresentationMeshView::updateMeshMode(const MEDCALC::MeshModeType mode)
   // Update the pipeline:
   {
     MEDPyLockWrapper lock;
-    std::string cmd = getMeshViewCommand();
-    pushAndExecPyLine(cmd);
+    representationType();
     pushAndExecPyLine("pvs.Render();");
   }
 }
index 30c6d8bcaa77b0b9862005270fb0e7c83cec51ab..9eb9ecede68f48611603db2fa7a8b6092343e983 100644 (file)
@@ -41,7 +41,7 @@ protected:
   void updateMeshMode(const MEDCALC::MeshModeType mode);
   virtual void internalGeneratePipeline();
 
-  std::string getMeshViewCommand() const;
+  void representationType();
 
 private:
   MEDCALC::MeshViewParameters _params;
index 18fdff4d37e6f17f3cbcb5c434a839904a2f88bc..9dbc17ff884ae5846ea4a384e1e3be06fe850c10 100644 (file)
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
+#include "MEDPyLockWrapper.hxx"
+
 #include "MEDPresentationPointSprite.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 MEDPresentationPointSprite::TYPE_NAME = "MEDPresentationPointSprite";
+
+MEDPresentationPointSprite::MEDPresentationPointSprite(const MEDCALC::PointSpriteParameters& params,
+                                                   const MEDCALC::ViewModeType viewMode) :
+    MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), _params(params)
+{
+}
 
 void
 MEDPresentationPointSprite::internalGeneratePipeline()
 {
-//  PyGILState_STATE _gil_state = PyGILState_Ensure();
-//
-//  std::string cmd = std::string("import pvsimple as pvs;");
-//  cmd += getRenderViewCommand(_params.viewMode); // define __view1
-//
-//  cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
-//  cmd += std::string("__disp1 = pvs.Show(__obj1, __view1);");
-//  cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
-//  cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);");
-//  cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
-//  cmd += std::string("__disp1.SetRepresentationType('Point Sprite');");
-//  cmd += std::string("pvs.Render();");
-//
-//  cmd += getResetCameraCommand();
-//
-//  //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(); // instanciate __viewXXX
+  createSource();
+
+  // Populate internal array of available components:
+  fillAvailableFieldComponents();
+  int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS);
+
+  // Point sprite needs point data:
+  applyCellToPointIfNeeded();
+
+  pushAndExecPyLine(_objVar + " = " + _srcObjVar);
+
+  showObject(); // needs to be done before cell size computation to be sure ParaView has computed bounds, etc ...
+
+  // Compute cell average size in the mesh to have a nice scaling ratio:
+  std::ostringstream oss;
+  oss << "import medcalc; __avgSize=medcalc.ComputeCellAverageSize(" << _srcObjVar << ");";
+  pushAndExecPyLine(oss.str()); oss.str("");
+
+  colorBy("POINTS");  // like in Contour
+
+  // Set point sprite:
+  oss << _dispVar << ".SetRepresentationType('Point Sprite');";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  oss << _dispVar << ".PointSpriteDefaultsInitialized = 1;";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  oss << _dispVar << ".RadiusArray = ['POINTS', '" << _fieldName << "'];";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  oss << _dispVar << ".RadiusMode = 'Scalar';";
+  pushAndExecPyLine(oss.str()); oss.str("");
+
+  oss << _dispVar << ".RadiusVectorComponent = " << _selectedComponentIndex << ";";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  oss << _dispVar << ".RadiusIsProportional = 0 ;";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  oss << _dispVar << ".RadiusTransferFunctionEnabled = 1 ;";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  oss << _dispVar << ".MaxPixelSize = 30 ;";   // Avoid too big balls
+  pushAndExecPyLine(oss.str()); oss.str("");
+  oss << _dispVar << ".RadiusRange = [0.0, __avgSize];";
+  pushAndExecPyLine(oss.str()); oss.str("");
+
+  showScalarBar();
+  rescaleTransferFunction();
+  selectColorMap();
+  resetCameraAndRender();
 }
 
 void
 MEDPresentationPointSprite::updatePipeline(const MEDCALC::PointSpriteParameters& params)
 {
-  // :TODO:
+  if (params.fieldHandlerId != _params.fieldHandlerId)
+    throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
+
+  if (std::string(params.displayedComponent) != std::string(_params.displayedComponent))
+    updateComponent<MEDPresentationPointSprite, MEDCALC::PointSpriteParameters>(std::string(params.displayedComponent));
+  if (params.scalarBarRange != _params.scalarBarRange)
+    updateScalarBarRange<MEDPresentationPointSprite, MEDCALC::PointSpriteParameters>(params.scalarBarRange);
+  if (params.colorMap != _params.colorMap)
+    updateColorMap<MEDPresentationPointSprite, MEDCALC::PointSpriteParameters>(params.colorMap);
 }
index 56d83e27b1fa2d0e7b946c53f7973d9d6529aae1..e38b9ea1f5c668b1458c5e027c072804b4635a01 100644 (file)
 class MEDCALC_EXPORT MEDPresentationPointSprite : public MEDPresentation
 {
 public:
-  MEDPresentationPointSprite(const MEDCALC::PointSpriteParameters& params) :
-    MEDPresentation(params.fieldHandlerId, "MEDPresentationPointSprite"), _params(params)
-  {}
+  static const std::string TYPE_NAME;
+
+  MEDPresentationPointSprite(const MEDCALC::PointSpriteParameters& params, const MEDCALC::ViewModeType viewMode);
   virtual ~MEDPresentationPointSprite() {}
 
   void updatePipeline(const MEDCALC::PointSpriteParameters& params);
-  MEDCALC::ViewModeType getViewMode() { return _params.viewMode; }
+
+  void getParameters(MEDCALC::PointSpriteParameters & params) const { params = _params; } ;
+  void setParameters(const MEDCALC::PointSpriteParameters & params) { _params = params; } ;
 
 protected:
   virtual void internalGeneratePipeline();
index 79af31efd47fbaca5c9ac5b976425f6833be7b13..7c0c21a84365b49710434ba7b8b0b9d7d1043dcd 100644 (file)
@@ -43,34 +43,21 @@ MEDPresentationScalarMap::internalGeneratePipeline()
 
   MEDPyLockWrapper lock;
 
-  std::ostringstream oss;
-  std::string view(getRenderViewVar());
-
-  pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX
-
-  oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');";
-  pushAndExecPyLine(oss.str()); oss.str("");
+  setOrCreateRenderView(); // instanciate __viewXXX
+  createSource();
 
   // Populate internal array of available components:
   fillAvailableFieldComponents();
-//  dumpIntProperties();
-//  dumpStringProperties();
 
+  // Nothing to do in a scalar map, obj = source:
   pushAndExecPyLine(_objVar + " = " + _srcObjVar);
 
-  oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");";
-  pushAndExecPyLine(oss.str()); oss.str("");
-  oss << "pvs.ColorBy(" << _dispVar << ", ('" << _fieldType << "', '" << _fieldName << "'));";
-  pushAndExecPyLine(oss.str()); oss.str("");
-  oss << _dispVar <<  ".SetScalarBarVisibility(" << view << ", True);";
-  pushAndExecPyLine(oss.str()); oss.str("");
-  oss << getRescaleCommand();
-  pushAndExecPyLine(oss.str()); oss.str("");
-  oss << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');";
-  pushAndExecPyLine(oss.str()); oss.str("");
-  pushAndExecPyLine(getColorMapCommand()); oss.str("");
-  pushAndExecPyLine(getResetCameraCommand());
-  pushAndExecPyLine("pvs.Render();");
+  showObject();
+  colorBy(_fieldType);
+  showScalarBar();
+  rescaleTransferFunction();
+  selectColorMap();
+  resetCameraAndRender();
 
   // Retrieve Python object for internal storage:
 //  PyObject* p_obj = getPythonObjectFromMain(obj.c_str());
index 3e51ee28fd601c1af2ce3b92eb92451fb80d04a2..16dbf4fad256bf69bdb5b2da793c2b019e8c9a8e 100644 (file)
@@ -38,17 +38,16 @@ MEDPresentationSlices::MEDPresentationSlices(const MEDCALC::SlicesParameters& pa
   setIntProperty(MEDPresentationSlices::PROP_SLICE_ORIENTATION, params.orientation);
 }
 
-std::string
-MEDPresentationSlices::getNbSlicesCommand() const
+void
+MEDPresentationSlices::setNumberOfSlices()
 {
   std::ostringstream oss1;
   // TODO
 //  oss1 << _objVar << ".SliceType.Normal = " << norm << ";";
-  return oss1.str();
 }
 
-std::string
-MEDPresentationSlices::getOrientationCommand() const
+void
+MEDPresentationSlices::selectSliceOrientation()
 {
   std::ostringstream oss1;
   std::string norm;
@@ -83,7 +82,7 @@ MEDPresentationSlices::getOrientationCommand() const
   }
 
   oss1 << _objVar << ".SliceType.Normal = " << norm << ";";
-  return oss1.str();
+  pushAndExecPyLine(oss1.str()); oss1.str("");
 }
 
 
@@ -95,35 +94,28 @@ MEDPresentationSlices::internalGeneratePipeline()
   MEDPyLockWrapper lock;
 
   std::ostringstream oss_o, oss;
-  std::string view(getRenderViewVar());
 
-  oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');";
-  pushAndExecPyLine(oss.str()); oss.str("");
+  createSource();
 
   // Populate internal array of available components:
   fillAvailableFieldComponents();
-  pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX
+  setOrCreateRenderView(); // instanciate __viewXXX
+
   oss << _objVar << " = pvs.Slice(Input=" << _srcObjVar << ");";
   pushAndExecPyLine(oss.str()); oss.str("");
+
+  showObject();
+
   oss << _objVar << ".SliceType = 'Plane';";
   pushAndExecPyLine(oss.str()); oss.str("");
 
   // Set slice orientation
-  pushAndExecPyLine(getOrientationCommand());
-
-  oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");";
-  pushAndExecPyLine(oss.str()); oss.str("");
-  oss << "pvs.ColorBy(" << _dispVar << ", ('" << _fieldType << "', '" << _fieldName << "'));";
-  pushAndExecPyLine(oss.str()); oss.str("");
-  oss << _dispVar <<  ".SetScalarBarVisibility(" << view << ", True);";
-  pushAndExecPyLine(oss.str()); oss.str("");
-  oss << getRescaleCommand();
-  pushAndExecPyLine(oss.str()); oss.str("");
-  oss << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');";
-  pushAndExecPyLine(oss.str()); oss.str("");
-  pushAndExecPyLine(getColorMapCommand()); oss.str("");
-  pushAndExecPyLine(getResetCameraCommand());
-  pushAndExecPyLine("pvs.Render();");
+  selectSliceOrientation();
+  colorBy(_fieldType);
+  showScalarBar();
+  rescaleTransferFunction();
+  selectColorMap();
+  resetCameraAndRender();
 }
 
 void
@@ -156,8 +148,7 @@ MEDPresentationSlices::updateNbSlices(const int nbSlices)
   // Update the pipeline:
   {
     MEDPyLockWrapper lock;
-    std::string cmd = getNbSlicesCommand();
-    pushAndExecPyLine(cmd);
+    setNumberOfSlices();
     pushAndExecPyLine("pvs.Render();");
   }
 }
@@ -173,8 +164,7 @@ MEDPresentationSlices::updateOrientation(const MEDCALC::SliceOrientationType ori
   // Update the pipeline:
   {
     MEDPyLockWrapper lock;
-    std::string cmd = getOrientationCommand();
-    pushAndExecPyLine(cmd);
+    selectSliceOrientation();
     pushAndExecPyLine("pvs.Render();");
   }
 }
index 9237475342c1aa40c27082f0d2733ea4f59d7d30..81d5ae7e8ac117c1f9a879afcecadc1b290dffd1 100644 (file)
@@ -43,8 +43,8 @@ protected:
   void updateOrientation(const MEDCALC::SliceOrientationType orientation);
   virtual void internalGeneratePipeline();
 
-  std::string getNbSlicesCommand() const;
-  std::string getOrientationCommand() const;
+  void setNumberOfSlices();
+  void selectSliceOrientation();
 
 private:
   MEDCALC::SlicesParameters _params;
index 979f8ed8cfa258e55a11271c642c5495c135d032..f922e29df090cd3953909a8bbffbdb710f1cd343 100644 (file)
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
+#include "MEDPyLockWrapper.hxx"
+
 #include "MEDPresentationVectorField.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 MEDPresentationVectorField::TYPE_NAME = "MEDPresentationVectorField";
+
+MEDPresentationVectorField::MEDPresentationVectorField(const MEDCALC::VectorFieldParameters& params,
+                                                   const MEDCALC::ViewModeType viewMode) :
+    MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), _params(params)
+{
+}
 
 void
 MEDPresentationVectorField::internalGeneratePipeline()
 {
-//  PyGILState_STATE _gil_state = PyGILState_Ensure();
-//
-//  std::string cmd = std::string("import pvsimple as pvs;");
-//  cmd += getRenderViewCommand(_params.viewMode); // define __view1
-//
-//  cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
-//  cmd += std::string("__disp1 = pvs.Show(__obj1, __view1);");
-//  cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
-//  cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);");
-//  cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
-//  cmd += std::string("__disp1.SetRepresentationType('3D Glyphs');");
-//  cmd += std::string("pvs.Render();");
-//
-//  cmd += getResetCameraCommand();
-//
-//  //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();
+  createSource();
+
+  // Populate internal array of available components:
+  fillAvailableFieldComponents();
+  if (getIntProperty(MEDPresentation::PROP_NB_COMPONENTS) <= 1)
+    {
+      const char * msg = "Vector field presentation does not work for scalar  field!"; // this message will appear in GUI too
+      STDLOG(msg);
+      throw KERNEL::createSalomeException(msg);
+    }
+
+  std::ostringstream oss;
+  oss << _objVar << " = pvs.Glyph(Input=" << _srcObjVar << ", GlyphType='Arrow');";
+  pushAndExecPyLine(oss.str()); oss.str("");
+
+  showObject(); // to be done first so that the scale factor computation properly works
+
+  oss << _objVar << ".Scalars = ['"<< _fieldType << "', 'None'];";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  oss << _objVar << ".Vectors = ['"<< _fieldType << "', '" << _fieldName << "'];";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  oss << _objVar << ".ScaleMode = 'vector';";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  oss << _objVar << ".GlyphMode = 'All Points';";
+  pushAndExecPyLine(oss.str()); oss.str("");
+//  oss << _objVar << "GlyphTransform = 'Transform2';";  // not sure this is really needed?
+//  pushAndExecPyLine(oss.str()); oss.str("");
+  oss << _objVar << ".ScaleFactor = 0.1;";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  // Auto-tuning of the scale factor:
+//  oss << "import medcalc; medcalc.SetDefaultScaleFactor(active=" << _objVar << ");";
+//  pushAndExecPyLine(oss.str()); oss.str("");
+
+  colorBy("POINTS");
+  showScalarBar();
+  rescaleTransferFunction();
+  selectColorMap();
+  resetCameraAndRender();
 }
 
 void
 MEDPresentationVectorField::updatePipeline(const MEDCALC::VectorFieldParameters& params)
 {
-  // :TODO:
+  if (params.fieldHandlerId != _params.fieldHandlerId)
+    throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
+
+  if (std::string(params.displayedComponent) != std::string(_params.displayedComponent))
+    updateComponent<MEDPresentationVectorField, MEDCALC::VectorFieldParameters>(std::string(params.displayedComponent));
+  if (params.scalarBarRange != _params.scalarBarRange)
+    updateScalarBarRange<MEDPresentationVectorField, MEDCALC::VectorFieldParameters>(params.scalarBarRange);
+  if (params.colorMap != _params.colorMap)
+    updateColorMap<MEDPresentationVectorField, MEDCALC::VectorFieldParameters>(params.colorMap);
 }
index 758cb152e1edb189ff7e9897dabd5564295589c6..3c37fba534285bb066527b136f260663bedbe427 100644 (file)
 class MEDCALC_EXPORT MEDPresentationVectorField : public MEDPresentation
 {
 public:
-  MEDPresentationVectorField(const MEDCALC::VectorFieldParameters& params) :
-    MEDPresentation(params.fieldHandlerId, "MEDPresentationVectorField"), _params(params)
-  {}
+  static const std::string TYPE_NAME;
+
+  MEDPresentationVectorField(const MEDCALC::VectorFieldParameters& params, const MEDCALC::ViewModeType viewMode);
   virtual ~MEDPresentationVectorField() {}
 
   void updatePipeline(const MEDCALC::VectorFieldParameters& params);
-  MEDCALC::ViewModeType getViewMode() { return _params.viewMode; }
+
+  void getParameters(MEDCALC::VectorFieldParameters & params) const { params = _params; } ;
+  void setParameters(const MEDCALC::VectorFieldParameters & params) { _params = params; } ;
 
 protected:
   virtual void internalGeneratePipeline();
 
 private:
   MEDCALC::VectorFieldParameters _params;
+
 };
 
 #endif
index 0ff4b8f455e80f4fc46480cf507814e002a42fc9..f968a83811126e84c143e5409da79bb73c6d88dc 100644 (file)
@@ -39,7 +39,7 @@ SET(MEDCALCGUI_SOURCES
     XmedDataModel.cxx
     MEDWidgetHelper.cxx
     MEDWidgetHelperMeshView.cxx
-    MEDWidgetHelperScalarMap.cxx
+    MEDWidgetHelperComponent.cxx
     MEDWidgetHelperContour.cxx
     MEDWidgetHelperSlices.cxx
 )
@@ -57,9 +57,12 @@ SET(MEDCALCGUI_HEADERS
   ProcessingController.hxx
   MEDWidgetHelper.hxx
   MEDWidgetHelperMeshView.hxx
+  MEDWidgetHelperComponent.hxx
   MEDWidgetHelperScalarMap.hxx
   MEDWidgetHelperContour.hxx
   MEDWidgetHelperSlices.hxx
+  MEDWidgetHelperPointSprite.hxx
+  MEDWidgetHelperVectorField.hxx
   )
  
 IF(SALOME_MED_WITH_QTTESTING)
diff --git a/src/MEDCalc/gui/MEDWidgetHelperComponent.cxx b/src/MEDCalc/gui/MEDWidgetHelperComponent.cxx
new file mode 100644 (file)
index 0000000..947fc34
--- /dev/null
@@ -0,0 +1,50 @@
+// Copyright (C) 2016  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 "MEDWidgetHelperComponent.hxx"
+#include "PresentationController.hxx"
+
+MEDWidgetHelperComponent::MEDWidgetHelperComponent(const PresentationController * presController, MEDCALC::MEDPresentationManager_ptr presManager, int presId,
+                                                   const std::string & presName, WidgetPresentationParameters * paramW):
+  MEDWidgetHelper(presController, presManager, presId, presName, paramW)
+{}
+
+MEDWidgetHelperComponent::~MEDWidgetHelperComponent()
+{}
+
+void MEDWidgetHelperComponent::udpateWidget()
+{
+  MEDWidgetHelper::udpateWidget();
+
+  _paramWidget->setComponents(_allCompos, _selectedCompo);
+
+  // Connect combo box changes
+  QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
+                    _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
+  QObject::connect( _paramWidget, SIGNAL(comboCompoIndexChanged(int)), this, SLOT(onComponentChanged(int)) );
+}
+
+void MEDWidgetHelperComponent::releaseWidget()
+{
+  MEDWidgetHelper::releaseWidget();
+
+  QObject::disconnect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
+                       _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
+  QObject::disconnect( _paramWidget, SIGNAL(comboCompoIndexChanged(int)), this, SLOT(onComponentChanged(int)) );
+}
diff --git a/src/MEDCalc/gui/MEDWidgetHelperComponent.hxx b/src/MEDCalc/gui/MEDWidgetHelperComponent.hxx
new file mode 100644 (file)
index 0000000..58c774f
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright (C) 2016  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
+//
+
+#ifndef SRC_MEDCALC_GUI_MEDWIDGETHELPERCOMPONENT_HXX_
+#define SRC_MEDCALC_GUI_MEDWIDGETHELPERCOMPONENT_HXX_
+
+#include "MEDWidgetHelper.hxx"
+
+class PresentationController;
+
+/**
+ * Abstract class to manage all presentations having only the component name to change.
+ */
+class MEDWidgetHelperComponent: public MEDWidgetHelper
+{
+  Q_OBJECT
+
+public:
+  MEDWidgetHelperComponent(const PresentationController* presController,
+                           MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName,
+                           WidgetPresentationParameters * paramW);
+  virtual ~MEDWidgetHelperComponent();
+
+  virtual void udpateWidget();
+  virtual void releaseWidget();
+
+  virtual std::string getPythonTag() const = 0;
+};
+
+#endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERCOMPONENT_HXX_ */
diff --git a/src/MEDCalc/gui/MEDWidgetHelperPointSprite.hxx b/src/MEDCalc/gui/MEDWidgetHelperPointSprite.hxx
new file mode 100644 (file)
index 0000000..0ad72e4
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) 2016  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
+//
+
+#ifndef SRC_MEDCALC_GUI_MEDWIDGETHELPERPOINTSPRITE_HXX_
+#define SRC_MEDCALC_GUI_MEDWIDGETHELPERPOINTSPRITE_HXX_
+
+#include "MEDWidgetHelperComponent.hxx"
+
+class PresentationController;
+
+class MEDWidgetHelperPointSprite: public MEDWidgetHelperComponent
+{
+  Q_OBJECT
+
+public:
+  MEDWidgetHelperPointSprite(const PresentationController* presController,
+                           MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName,
+                           WidgetPresentationParameters * paramW):
+     MEDWidgetHelperComponent(presController, presManager, presId, presName, paramW)
+  {}
+
+  virtual ~MEDWidgetHelperPointSprite() {}
+
+  virtual std::string getPythonTag() const { return "PointSprite"; }
+};
+
+#endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERPOINTSPRITE_HXX_ */
diff --git a/src/MEDCalc/gui/MEDWidgetHelperScalarMap.cxx b/src/MEDCalc/gui/MEDWidgetHelperScalarMap.cxx
deleted file mode 100644 (file)
index 755bf80..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright (C) 2016  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 "MEDWidgetHelperScalarMap.hxx"
-#include "MEDPresentationScalarMap.hxx"  // from component side.
-#include "PresentationController.hxx"
-
-#include <sstream>
-
-MEDWidgetHelperScalarMap::MEDWidgetHelperScalarMap(const PresentationController * presController, MEDCALC::MEDPresentationManager_ptr presManager, int presId,
-                                                   const std::string & presName, WidgetPresentationParameters * paramW):
-  MEDWidgetHelper(presController, presManager, presId, presName, paramW)
-{
-}
-
-MEDWidgetHelperScalarMap::~MEDWidgetHelperScalarMap()
-{}
-
-void MEDWidgetHelperScalarMap::udpateWidget()
-{
-  MEDWidgetHelper::udpateWidget();
-
-  // Scalar map presentation needs the component name, that's all.
-  _paramWidget->setComponents(_allCompos, _selectedCompo);
-
-  // Connect combo box changes
-  QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
-                    _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
-  QObject::connect( _paramWidget, SIGNAL(comboCompoIndexChanged(int)), this, SLOT(onComponentChanged(int)) );
-}
-
-void MEDWidgetHelperScalarMap::releaseWidget()
-{
-  MEDWidgetHelper::releaseWidget();
-
-  QObject::disconnect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
-                       _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
-  QObject::disconnect( _paramWidget, SIGNAL(comboCompoIndexChanged(int)), this, SLOT(onComponentChanged(int)) );
-}
index ee17a53076ace9f58ecfc74c89bae211c8289602..d3ba5c056d7be3a424bb3eac59a8cdfd9c11673a 100644 (file)
 #ifndef SRC_MEDCALC_GUI_MEDWIDGETHELPERSCALARMAP_HXX_
 #define SRC_MEDCALC_GUI_MEDWIDGETHELPERSCALARMAP_HXX_
 
-#include "MEDWidgetHelper.hxx"
+#include "MEDWidgetHelperComponent.hxx"
 
 class PresentationController;
 
-class MEDWidgetHelperScalarMap: public MEDWidgetHelper
+class MEDWidgetHelperScalarMap: public MEDWidgetHelperComponent
 {
   Q_OBJECT
 
 public:
   MEDWidgetHelperScalarMap(const PresentationController* presController,
                            MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName,
-                           WidgetPresentationParameters * paramW);
-  virtual ~MEDWidgetHelperScalarMap();
+                           WidgetPresentationParameters * paramW):
+      MEDWidgetHelperComponent(presController, presManager, presId, presName, paramW)
+  {}
 
-  virtual void udpateWidget();
-  virtual void releaseWidget();
+  virtual ~MEDWidgetHelperScalarMap() {}
 
   virtual std::string getPythonTag() const { return "ScalarMap"; }
 };
diff --git a/src/MEDCalc/gui/MEDWidgetHelperVectorField.hxx b/src/MEDCalc/gui/MEDWidgetHelperVectorField.hxx
new file mode 100644 (file)
index 0000000..daca5df
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) 2016  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
+//
+
+#ifndef SRC_MEDCALC_GUI_MEDWIDGETHELPERVECTORFIELD_HXX_
+#define SRC_MEDCALC_GUI_MEDWIDGETHELPERVECTORFIELD_HXX_
+
+#include "MEDWidgetHelperComponent.hxx"
+
+class PresentationController;
+
+class MEDWidgetHelperVectorField: public MEDWidgetHelperComponent
+{
+  Q_OBJECT
+
+public:
+  MEDWidgetHelperVectorField(const PresentationController* presController,
+                           MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName,
+                           WidgetPresentationParameters * paramW):
+     MEDWidgetHelperComponent(presController, presManager, presId, presName, paramW)
+  {}
+
+  virtual ~MEDWidgetHelperVectorField() {}
+
+  virtual std::string getPythonTag() const { return "VectorField"; }
+};
+
+#endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERVECTORFIELD_HXX_ */
index ffd9bab25867669160df4cd6d93aeaed4afd0bda..359ed79ce77031aeb7e88d5cbee090e02d23a7d9 100644 (file)
 #include "MEDPresentationScalarMap.hxx"
 #include "MEDPresentationContour.hxx"
 #include "MEDPresentationSlices.hxx"
+#include "MEDPresentationPointSprite.hxx"
+#include "MEDPresentationVectorField.hxx"
+//#include "MEDPresentationDeflectionShape.hxx"
 
 #include "MEDWidgetHelperMeshView.hxx"
 #include "MEDWidgetHelperScalarMap.hxx"
 #include "MEDWidgetHelperContour.hxx"
 #include "MEDWidgetHelperSlices.hxx"
+#include "MEDWidgetHelperPointSprite.hxx"
+#include "MEDWidgetHelperVectorField.hxx"
+//#include "MEDWidgetHelperDeflectionShape.hxx"
 
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
@@ -489,26 +495,28 @@ PresentationController::processPresentationEvent(const PresentationEvent* event)
   }
   else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) {
       commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
-        .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
+            .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
       commands += QString("presentation_id");
   }
-  //  else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) {
-  //    commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
-  //    commands += QString("presentation_id");
-  //  }
-    else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
+  else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
       commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
-        .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
+            .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
       commands += QString("presentation_id");
-    }
+  }
+  else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) {
+      commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
+          .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
+      commands += QString("presentation_id");
+  }
+  else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
+      commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
+              .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
+      commands += QString("presentation_id");
+  }
+
   //  else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) {
   //    commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
   //    commands += QString("presentation_id");
-  //  }
-  //  else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
-  //    commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
-  //    commands += QString("presentation_id");
-  //  }
 
   // [ABN] using event mechanism for this is awkward? TODO: direct implementation in each
   // dedicated widget helper class?
@@ -571,7 +579,7 @@ PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager
   std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
   if (it != _presHelperMap.end())
     return (*it).second;
-  MEDWidgetHelper * wh;
+  MEDWidgetHelper * wh = 0;
   if (type == MEDPresentationMeshView::TYPE_NAME)
     wh = new MEDWidgetHelperMeshView(this, _presManager, presId, name, _widgetPresentationParameters);
   else if (type == MEDPresentationScalarMap::TYPE_NAME)
@@ -579,10 +587,15 @@ PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager
   else if (type == MEDPresentationContour::TYPE_NAME)
     wh = new MEDWidgetHelperContour(this, _presManager, presId, name, _widgetPresentationParameters);
   else if (type == MEDPresentationSlices::TYPE_NAME)
-      wh = new MEDWidgetHelperSlices(this, _presManager, presId, name, _widgetPresentationParameters);
+    wh = new MEDWidgetHelperSlices(this, _presManager, presId, name, _widgetPresentationParameters);
+  else if (type == MEDPresentationVectorField::TYPE_NAME)
+    wh = new MEDWidgetHelperVectorField(this, _presManager, presId, name, _widgetPresentationParameters);
+  else if (type == MEDPresentationPointSprite::TYPE_NAME)
+    wh = new MEDWidgetHelperPointSprite(this, _presManager, presId, name, _widgetPresentationParameters);
   else
     {
-      STDLOG("findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!");
+      const char * msg ="findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!";
+      STDLOG(msg);
     }
   _presHelperMap[presId] = wh;
   return wh;
index 648ebf102144c7553a6b88cfd1d10e3976abbc46..92b8dc4f9691e997c7f985f9b8fb564cca4b9750 100644 (file)
@@ -12,6 +12,7 @@ typedef struct {
     EVENT_VIEW_OBJECT_SCALAR_MAP,
     EVENT_VIEW_OBJECT_SLICES,
     EVENT_VIEW_OBJECT_VECTOR_FIELD,
+
     EVENT_DELETE_PRESENTATION,
 
     EVENT_CHANGE_COMPONENT,
@@ -19,7 +20,9 @@ typedef struct {
     EVENT_CHANGE_TIME_RANGE,
 
     EVENT_CHANGE_MESH_MODE,
+
     EVENT_CHANGE_NB_CONTOUR,
+
     EVENT_CHANGE_SLICE_ORIENTATION,
     EVENT_CHANGE_NB_SLICES
   };
diff --git a/src/MEDCalc/test/tui/point_sprite.py b/src/MEDCalc/test/tui/point_sprite.py
new file mode 100644 (file)
index 0000000..5a86b51
--- /dev/null
@@ -0,0 +1,40 @@
+# Copyright (C) 2016  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
+#
+
+import os
+from time import sleep
+
+import medcalc
+medcalc.medconsole.setConsoleGlobals(globals())
+import MEDCALC
+from medcalc.medconsole import accessField
+
+from medcalc_testutils import GetMEDFileDirTUI
+
+if 1:
+  datafile = os.path.join(GetMEDFileDirTUI(), "smooth_surface_and_field.med")
+  source_id = medcalc.LoadDataSource(datafile)
+  presentation_id = medcalc.MakePointSprite(accessField(0), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW)
+else:
+  datafile = os.path.join(GetMEDFileDirTUI(), "agitateur.med")
+  source_id = medcalc.LoadDataSource(datafile)
+  presentation_id = medcalc.MakePointSprite(accessField(55), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW)
+  
+sleep(1)
+medcalc.RemovePresentation(presentation_id)
index 413a3d11854d655747fa437a51d11a7b8670dde7..e3edd10ba2475b489068267c044325fcd311c6f1 100644 (file)
@@ -30,7 +30,9 @@ from medcalc_testutils import GetMEDFileDirTUI
 datafile = os.path.join(GetMEDFileDirTUI(), "agitateur.med")
 source_id = medcalc.LoadDataSource(datafile)
 
-presentation_id = medcalc.MakeSlices(accessField(0), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW)
+presentation_id = medcalc.MakeSlices(accessField(0), MEDCALC.VIEW_MODE_REPLACE, 
+                                     colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW,
+                                     sliceOrientation=MEDCALC.SLICE_NORMAL_TO_Z)  # normal to Z to see something!
 sleep(1)
 medcalc.RemovePresentation(presentation_id)
 sleep(1)
index e2cad1b1ebb314b092fd81af716cf5bc2667f8b8..06c61c4d6795a114740de473236bf6ea989ba7c1 100644 (file)
@@ -25,4 +25,7 @@ SET(TEST_NAMES
 #  contour
 #  slices
 #  mesh_view
+#  point_sprite
+#  vector_field
+#  deflection_shape
 )
diff --git a/src/MEDCalc/test/tui/vector_field.py b/src/MEDCalc/test/tui/vector_field.py
new file mode 100644 (file)
index 0000000..de17aa5
--- /dev/null
@@ -0,0 +1,40 @@
+# Copyright (C) 2016  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
+#
+
+import os
+from time import sleep
+
+import medcalc
+medcalc.medconsole.setConsoleGlobals(globals())
+import MEDCALC
+from medcalc.medconsole import accessField
+
+from medcalc_testutils import GetMEDFileDirTUI
+
+datafile = os.path.join(GetMEDFileDirTUI(), "agitateur.med")
+source_id = medcalc.LoadDataSource(datafile)
+
+# Field 55 = VITESSE_ELEM_DOM (ON_CELLS)
+presentation_id = medcalc.MakeVectorField(accessField(57), viewMode=MEDCALC.VIEW_MODE_REPLACE, 
+                                          colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW,
+                                          scalarBarRange=MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP
+                                          )
+sleep(1)
+medcalc.RemovePresentation(presentation_id)
+sleep(1)
index a409f477b50f80ee420c702f8a5e31dbb558562f..ee461af8a9484f37c35a75f6a9df2dbe44ffb7ff 100644 (file)
@@ -42,21 +42,29 @@ from medio import LoadImageAsDataSource
 from medpresentation import MakeMeshView
 from medpresentation import MakeScalarMap
 from medpresentation import MakeContour
-#from medpresentation import MakeVectorField
+from medpresentation import MakeVectorField
 from medpresentation import MakeSlices
-#from medpresentation import MakeDeflectionShape
-#from medpresentation import MakePointSprite
+from medpresentation import MakePointSprite
 from medpresentation import RemovePresentation
+#from medpresentation import MakeDeflectionShape
 
 from medpresentation import GetMeshViewParameters
 from medpresentation import GetScalarMapParameters
 from medpresentation import GetContourParameters
 from medpresentation import GetSlicesParameters
+from medpresentation import GetPointSpriteParameters
+from medpresentation import GetVectorFieldParameters
+#from medpresentation import GetDeflectionShapeParameters
 
 from medpresentation import UpdateMeshView
 from medpresentation import UpdateScalarMap
 from medpresentation import UpdateContour
 from medpresentation import UpdateSlices
+from medpresentation import UpdateVectorField
+from medpresentation import UpdatePointSprite
+#from medpresentation import UpdateDeflectionShape
+
+from medpresentation import SetDefaultScaleFactor, ComputeCellAverageSize, GetDomainCenter
 
 # Console commands
 import medconsole
index c1da528a41086963d91bab10b69523680ea5a985..40cad1ece84c9a55666e9f646b1c24e239430c07 100644 (file)
@@ -70,17 +70,25 @@ def MakeContour(proxy,
     notifyGui_error("An error occured while creating the contour:\n" + e.details.text)
     raise Exception(e.details.text)
 
-##
-#
-#def MakeVectorField(proxy,
-#                    viewMode=MEDCALC.VIEW_MODE_DEFAULT
-#                    ):
-#  params = MEDCALC.VectorFieldParameters(proxy.id, viewMode)
-#  presentation_id = __manager.makeVectorField(params)
-#  notifyGui_addPresentation(proxy.id, presentation_id)
-#  return presentation_id
-##
 #
+
+def MakeVectorField(proxy,
+                  viewMode=MEDCALC.VIEW_MODE_DEFAULT,
+                  displayedComponent=MEDCALC.DISPLAY_DEFAULT,
+                  scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT,
+                  colorMap=MEDCALC.COLOR_MAP_DEFAULT
+                  ):
+  # Create the presentation instance in CORBA engine
+  # The engine in turn creates the ParaView pipeline elements
+  params = MEDCALC.VectorFieldParameters(proxy.id, displayedComponent, scalarBarRange, colorMap)
+  try:
+    presentation_id = __manager.makeVectorField(params, viewMode)
+    notifyGui_addPresentation(proxy.id, presentation_id)
+    return presentation_id
+  except SALOME.SALOME_Exception as e:
+    notifyGui_error("An error occured while creating the vector field:\n" + e.details.text)
+    raise Exception(e.details.text)
+
 def MakeSlices(proxy,
                 viewMode=MEDCALC.VIEW_MODE_DEFAULT,
                 displayedComponent=MEDCALC.DISPLAY_DEFAULT,
@@ -110,17 +118,22 @@ def MakeSlices(proxy,
 #  return presentation_id
 ##
 #
-#def MakePointSprite(proxy,
-#                    viewMode=MEDCALC.VIEW_MODE_DEFAULT,
-#                    displayedComponent=MEDCALC.DISPLAY_DEFAULT,
-#                    scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT,
-#                    colorMap=MEDCALC.COLOR_MAP_DEFAULT,
-#                    ):
-#  params = MEDCALC.PointSpriteParameters(proxy.id, viewMode, displayedComponent, scalarBarRange, colorMap)
-#  presentation_id = __manager.makePointSprite(params)
-#  notifyGui_addPresentation(proxy.id, presentation_id)
-#  return presentation_id
-#
+def MakePointSprite(proxy,
+                  viewMode=MEDCALC.VIEW_MODE_DEFAULT,
+                  displayedComponent=MEDCALC.DISPLAY_DEFAULT,
+                  scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT,
+                  colorMap=MEDCALC.COLOR_MAP_DEFAULT
+                  ):
+  # Create the presentation instance in CORBA engine
+  # The engine in turn creates the ParaView pipeline elements
+  params = MEDCALC.PointSpriteParameters(proxy.id, displayedComponent, scalarBarRange, colorMap)
+  try:
+    presentation_id = __manager.makePointSprite(params, viewMode)
+    notifyGui_addPresentation(proxy.id, presentation_id)
+    return presentation_id
+  except SALOME.SALOME_Exception as e:
+    notifyGui_error("An error occured while creating the point sprite:\n" + e.details.text)
+    raise Exception(e.details.text)
 
 def RemovePresentation(presentation_id):
   ok = __manager.removePresentation(presentation_id)
@@ -128,20 +141,131 @@ def RemovePresentation(presentation_id):
     notifyGui_removePresentation(presentation_id)
 #
 
-def GetGENERICParameters(tag, presentation_id):
+def __GetGENERICParameters(tag, presentation_id):
   exec "params = __manager.get%sParameters(presentation_id)" % tag
   return params
 
-GetMeshViewParameters = lambda pres_id: GetGENERICParameters("MeshView", pres_id)
-GetScalarMapParameters = lambda pres_id: GetGENERICParameters("ScalarMap", pres_id)
-GetContourParameters = lambda pres_id: GetGENERICParameters("Contour", pres_id)
-GetSlicesParameters = lambda pres_id: GetGENERICParameters("Slices", pres_id)
+GetMeshViewParameters = lambda pres_id: __GetGENERICParameters("MeshView", pres_id)
+GetScalarMapParameters = lambda pres_id: __GetGENERICParameters("ScalarMap", pres_id)
+GetContourParameters = lambda pres_id: __GetGENERICParameters("Contour", pres_id)
+GetSlicesParameters = lambda pres_id: __GetGENERICParameters("Slices", pres_id)
+GetPointSpriteParameters = lambda pres_id: __GetGENERICParameters("PointSprite", pres_id)
+GetVectorFieldParameters = lambda pres_id: __GetGENERICParameters("VectorField", pres_id)
+#GetDeflectionShapeParameters = lambda pres_id: __GetGENERICParameters("DeflectionShape", pres_id)
 
 
-def UpdateGENERIC(tag, presentation_id, params):
+def __UpdateGENERIC(tag, presentation_id, params):
   exec "__manager.update%s(presentation_id, params)" % tag
 
-UpdateMeshView = lambda pres_id, params: UpdateGENERIC("MeshView", pres_id, params)
-UpdateScalarMap = lambda pres_id, params: UpdateGENERIC("ScalarMap", pres_id, params)
-UpdateContour = lambda pres_id, params: UpdateGENERIC("Contour", pres_id, params)
-UpdateSlices = lambda pres_id, params: UpdateGENERIC("Slices", pres_id, params)
+UpdateMeshView = lambda pres_id, params: __UpdateGENERIC("MeshView", pres_id, params)
+UpdateScalarMap = lambda pres_id, params: __UpdateGENERIC("ScalarMap", pres_id, params)
+UpdateContour = lambda pres_id, params: __UpdateGENERIC("Contour", pres_id, params)
+UpdateSlices = lambda pres_id, params: __UpdateGENERIC("Slices", pres_id, params)
+UpdateVectorField = lambda pres_id, params: __UpdateGENERIC("VectorField", pres_id, params)
+UpdatePointSprite = lambda pres_id, params: __UpdateGENERIC("PointSprite", pres_id, params)
+#UpdateDeflectionShape = lambda pres_id, params: __UpdateGENERIC("DeflectionShape", pres_id, params)
+
+def ComputeCellAverageSize(obj):
+  """
+  @return the average cell size
+  """
+  bb, nCells = obj.GetDataInformation().GetBounds(), obj.GetDataInformation().GetNumberOfCells()
+  bb = zip(bb[::2], bb[1::2])
+  deltas = [x[1]-x[0] for x in bb]
+  vol = reduce(lambda x,y:x*y, deltas, 1.0) 
+  cellSize = (vol/nCells)**(1.0/3.0)  # necessarily 3D in ParaView
+  return cellSize
+
+def GetDomainCenter(obj):
+  """
+  @return the center of the domain as the central point of the bounding box
+  """
+  bb = obj.GetDataInformation().GetBounds()
+  bb = zip(bb[::2], bb[1::2])
+  mids = [x[0] + 0.5*(x[1]-x[0]) for x in bb]
+  return mids
+
+# Taken from paraview.simple from CEA ParaView's version:
+def SetDefaultScaleFactor(active=None):
+    """Provides a good display to the bounding box of the mesh and min / max of the field.
+    This method available for filters: Warp By Vector, Glyph and Tensor Glyph"""
+    if not active:
+        active = GetActiveSource()
+    if not active:
+        return
+    name = active.__class__.__name__
+    if (name == 'WarpByVector'  or name == 'TensorGlyph') and hasattr(active, 'ScaleFactor'):
+      import math
+      datainfo = active.GetProperty("Input").SMProperty.GetProxy(0).GetDataInformation()
+      if not datainfo:
+          active.ScaleFactor = 1.0
+          return
+      nbcells = datainfo.GetNumberOfCells()
+      nbpoints = datainfo.GetNumberOfPoints()
+      nbelem = nbcells
+      if nbelem == 0:
+          nbelem = nbpoints
+      abounds = datainfo.GetBounds()
+      volume = 1
+      vol = 0
+      idim = 0
+      i = 0
+      eps = 1.0e-38
+      while i < 6 :
+          vol = math.fabs( abounds[i+1] - abounds[i] )
+          if vol > 0:
+            idim += 1
+            volume *= vol
+          i += 2
+      if nbelem == 0 or math.fabs(idim) < eps:
+          active.ScaleFactor = 0.0
+          return
+      volume /= nbelem
+      scalefactor = pow( volume, 1.0 / idim )
+      maximum = 1.0
+      property = active.GetProperty('ScaleFactor')
+      domain = None
+      if property.GetDomain('vector_range').__class__.__name__ == 'vtkSMArrayRangeDomain':
+          domain = property.GetDomain('vector_range')
+      if property.GetDomain('tensor_range').__class__.__name__ == 'vtkSMArrayRangeDomain':
+          domain = property.GetDomain('tensor_range')
+      if not domain is None:
+          if domain.GetMaximumExists(3):
+            maximum = domain.GetMaximum(3)
+      if math.fabs(maximum) > eps:
+          scalefactor /= maximum
+      active.ScaleFactor = scalefactor
+      return
+    if name == 'Glyph' and hasattr(active, 'ScaleFactor') and hasattr(active, 'UseCellsCenter') and hasattr(active, 'ScaleMode'):
+      import math
+      scaledextent = 1.0
+      property = active.GetProperty('ScaleFactor')
+      bounds_domain = property.GetDomain('bounds')
+      if bounds_domain.__class__.__name__ == 'vtkSMBoundsDomain':
+          if bounds_domain.GetMaximumExists(0):
+            scaledextent = bounds_domain.GetMaximum(0)
+      usecellscenter = active.GetProperty('UseCellsCenter').GetData()
+      sdomain = "cells_"
+      if usecellscenter == 0:
+          sdomain = "points_"
+      divisor = 1.0
+      scalemode_domain = active.GetProperty('ScaleMode')
+      scalemode = scalemode_domain.ConvertValue(scalemode_domain.GetData())
+      if scalemode == 0:
+          sdomain += "scalar_range"
+          domain = property.GetDomain(sdomain)
+          if domain.__class__.__name__ == 'vtkSMArrayRangeDomain':
+            if domain.GetMaximumExists(0):
+                divisor = domain.GetMaximum(0)
+      if scalemode == 1 or scalemode == 2:
+          sdomain += "vector_range"
+          domain = property.GetDomain(sdomain)
+          if domain.__class__.__name__ == 'vtkSMArrayRangeDomain':
+            if domain.GetMaximumExists(3):
+                divisor = domain.GetMaximum(3)
+      divisor = math.fabs(divisor)
+      if divisor < 0.000000001:
+          divisor = 1
+      scalefactor = scaledextent / divisor 
+      active.ScaleFactor = scalefactor
+      return