Salome HOME
[MEDCalc] Contour presentation
authorabn <adrien.bruneton@cea.fr>
Mon, 1 Aug 2016 07:55:17 +0000 (09:55 +0200)
committerabn <adrien.bruneton@cea.fr>
Mon, 1 Aug 2016 07:55:17 +0000 (09:55 +0200)
26 files changed:
idl/MEDEventListener.idl
idl/MEDPresentationManager.idl
src/MEDCalc/cmp/CMakeLists.txt
src/MEDCalc/cmp/MEDPresentation.cxx
src/MEDCalc/cmp/MEDPresentation.hxx
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/MEDPresentationManager_i.txx
src/MEDCalc/cmp/MEDPresentationScalarMap.cxx
src/MEDCalc/gui/CMakeLists.txt
src/MEDCalc/gui/MEDWidgetHelperContour.cxx [new file with mode: 0644]
src/MEDCalc/gui/MEDWidgetHelperContour.hxx [new file with mode: 0644]
src/MEDCalc/gui/MEDWidgetHelperScalarMap.hxx
src/MEDCalc/gui/PresentationController.cxx
src/MEDCalc/gui/PresentationEvent.hxx
src/MEDCalc/gui/WorkspaceController.cxx
src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx
src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx
src/MEDCalc/test/tui/contour.py [new file with mode: 0644]
src/MEDCalc/test/tui/medfiles/agitateur.med [new file with mode: 0644]
src/MEDCalc/test/tui/scalar_map.py
src/MEDCalc/tui/__init__.py
src/MEDCalc/tui/medevents.py
src/MEDCalc/tui/medpresentation.py

index 97a84d6f1e178ec826efd2711d3e1836eb99dd89..60c6b11e7d3a17ba909456d4672e6c6f9da21310 100644 (file)
@@ -37,6 +37,7 @@ module MEDCALC
     EVENT_REMOVE_PRESENTATION,
     EVENT_PLAY_TEST,
     EVENT_QUIT_SALOME,
+    EVENT_ERROR,
     EVENT_UNKNOWN
   };
 
@@ -45,6 +46,7 @@ module MEDCALC
     long          dataId;
     string        filename;
     long          presentationId;
+    string        msg;
   };
 
   interface MEDEventListener: SALOME::GenericObj {
index a62aaa241646623d4e735a2423410dff45dbe172..d95aca9bc028b471bc8b53ea1e1d3a9d50b7f84b 100644 (file)
@@ -72,7 +72,6 @@ module MEDCALC
   const MEDPresentationViewMode VIEW_MODE_DEFAULT = VIEW_MODE_REPLACE;
   const MEDPresentationColorMap COLOR_MAP_DEFAULT = COLOR_MAP_BLUE_TO_RED_RAINBOW;
   const MEDPresentationScalarBarRange SCALAR_BAR_RANGE_DEFAULT = SCALAR_BAR_ALL_TIMESTEPS;
-  //const ScalarBarRange SCALAR_BAR_RANGE_DEFAULT = ;
   const long SCALAR_BAR_RANGE_VAL_MIN_DEFAULT = -1;
   const long SCALAR_BAR_RANGE_VAL_MAX_DEFAULT = -1;
   const string DISPLAY_DEFAULT = DISPLAY_EUCLIDEAN_NORM;
@@ -90,20 +89,25 @@ module MEDCALC
   };
 
   // A contour is an isoline in 2D and an isosurface in 3D
-//  struct ContourParameters {
+  struct ContourParameters {   // Contour are only for scalar fields
+    long fieldHandlerId;
+    MEDPresentationScalarBarRange scalarBarRange;
+    MEDPresentationColorMap colorMap;
+    long nbContours;
+  };
+
+//  struct VectorFieldParameters {
 //    long fieldHandlerId;
 //    string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name
-//    ScalarBarRange scalarBarRange;
+//    MEDPresentationScalarBarRange scalarBarRange;
 //    MEDPresentationColorMap colorMap;
-//    long nbContours;
-//  };
-//
-//  struct VectorFieldParameters {
-//    long fieldHandlerId;
 //  };
 //
 //  struct SlicesParameters {
 //    long fieldHandlerId;
+//    string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name
+//    MEDPresentationScalarBarRange scalarBarRange;
+//    MEDPresentationColorMap colorMap;
 //    SliceOrientation orientation;
 //    long nbSlices;
 //  };
@@ -115,7 +119,7 @@ module MEDCALC
 //  struct PointSpriteParameters {
 //    long fieldHandlerId;
 //    string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name
-//    ScalarBarRange scalarBarRange;
+//    MEDPresentationScalarBarRange scalarBarRange;
 //    MEDPresentationColorMap colorMap;
 //  };
 
@@ -126,7 +130,8 @@ module MEDCALC
   interface MEDPresentationManager : SALOME::GenericObj
   {
     long makeScalarMap(in ScalarMapParameters params, in MEDPresentationViewMode viewMode);
-//    long makeContour(in ContourParameters params, in MEDPresentationViewMode viewMode);
+    long makeContour(in ContourParameters params, in MEDPresentationViewMode viewMode)
+      raises (SALOME::SALOME_Exception);
 //    long makeVectorField(in VectorFieldParameters params, in MEDPresentationViewMode viewMode);
 //    long makeSlices(in SlicesParameters params, in MEDPresentationViewMode viewMode);
 //    long makeDeflectionShape(in DeflectionShapeParameters params, in MEDPresentationViewMode viewMode);
@@ -138,9 +143,10 @@ module MEDCALC
     long getPresentationIntProperty(in long presId, in string propName);
 
     ScalarMapParameters getScalarMapParameters(in long presId);
+    ContourParameters getContourParameters(in long presId);
 
     void updateScalarMap(in long presId, in ScalarMapParameters params);
-//    void updateContour(in long presId, in ContourParameters params);
+    void updateContour(in long presId, in ContourParameters 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);
@@ -153,7 +159,7 @@ module MEDCALC
 
     // Low level ParaVis dump
     string getParavisDump(in long presId);
-    
+
 //    MEDPresentationViewMode getPresentationViewMode(in long presId);
     
     PresentationsList getAllPresentations();
index 22657a8ea12336aa7305166de93ed13293226c65..edad94b6116f3de25f7485108000a6d20f0eef0c 100644 (file)
@@ -40,7 +40,7 @@ SET(COMMON_SOURCES
   MEDPresentation.cxx
   # presentations
   MEDPresentationScalarMap.cxx
-#  MEDPresentationContour.cxx
+  MEDPresentationContour.cxx
 #  MEDPresentationVectorField.cxx
 #  MEDPresentationSlices.cxx
 #  MEDPresentationDeflectionShape.cxx
index 88c4a2fcff981335ea8813bd997e9bbcdd1163e3..04e618dabbc4f57ca1c77c29c7f2cbeea811cd49 100644 (file)
@@ -47,8 +47,6 @@ MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const s
       _colorMap(colorMap),
       _sbRange(sbRange),
       _renderViewPyId(-1),  // will be set by getRenderViewCommand()
-      _objId(GeneratePythonId()),
-      _dispId(_objId), _lutId(_objId),
       _globalDict(0)
 {
   MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
@@ -72,8 +70,20 @@ MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const s
   setIntProperty(MEDPresentation::PROP_NB_COMPONENTS, 0);
   setIntProperty(MEDPresentation::PROP_SELECTED_COMPONENT, 0);
 
-  setIntProperty(MEDPresentation::PROP_COLOR_MAP, static_cast<int>(MEDCALC::COLOR_MAP_DEFAULT));
-  setIntProperty(MEDPresentation::PROP_SCALAR_BAR_RANGE, static_cast<int>(MEDCALC::SCALAR_BAR_RANGE_DEFAULT));
+  setIntProperty(MEDPresentation::PROP_COLOR_MAP, static_cast<int>(colorMap));
+  setIntProperty(MEDPresentation::PROP_SCALAR_BAR_RANGE, static_cast<int>(sbRange));
+
+  // Python variables:
+  int id = GeneratePythonId();
+  std::ostringstream oss_o, oss_d, oss_l, oss_s;
+  oss_o << "__obj" << id;
+  oss_s << "__srcObj" << id;
+  oss_d << "__disp" << id;
+  oss_l << "__lut" << id;
+  _objVar = oss_o.str();
+  _srcObjVar = oss_s.str();
+  _dispVar = oss_d.str();
+  _lutVar = oss_l.str();
 }
 
 MEDPresentation::~MEDPresentation()
@@ -81,10 +91,9 @@ MEDPresentation::~MEDPresentation()
   STDLOG("~MEDPresentation(): clear display");
   {
     MEDPyLockWrapper lock;
-    std::ostringstream oss_o, oss_v, oss;
-    oss_o << "__obj" << _objId;
+    std::ostringstream oss_v, oss;
     oss_v << "__view" << _renderViewPyId;
-    oss << "pvs.Hide(" << oss_o.str() <<  ", view=" << oss_v.str() << ");";
+    oss << "pvs.Hide(" << _objVar <<  ", view=" << oss_v.str() << ");";
     oss << "pvs.Render();";
 
     PyRun_SimpleString(oss.str().c_str());
@@ -117,7 +126,7 @@ void
 MEDPresentation::execPyLine(const std::string & lin)
 {
   MEDPyLockWrapper lock;
-//  STDLOG("@@@@ MEDPresentation::execPyLine() about to exec >> " << lin);
+  STDLOG("@@@@ MEDPresentation::execPyLine() about to exec >> " << lin);
   if(PyRun_SimpleString(lin.c_str()))
     {
       std::ostringstream oss;
@@ -126,7 +135,6 @@ MEDPresentation::execPyLine(const std::string & lin)
       STDLOG(oss.str());
       throw KERNEL::createSalomeException(oss.str().c_str());
     }
-
 }
 
 void
@@ -228,13 +236,20 @@ MEDPresentation::getFieldTypeString(MEDCoupling::TypeOfField fieldType) const
   }
 }
 
+std::string
+MEDPresentation::getRenderViewVar() const
+{
+  std::ostringstream oss;
+  oss << "__view" << _renderViewPyId;
+  return oss.str();
+}
+
 std::string
 MEDPresentation::getRenderViewCommand() const
 {
   std::ostringstream oss, oss2;
 
-  oss << "__view" << _renderViewPyId;
-  std::string view(oss.str());
+  std::string view(getRenderViewVar());
   oss2 << "pvs._DisableFirstRenderCameraReset();" << std::endl;
   if (_viewMode == MEDCALC::VIEW_MODE_OVERLAP) {
       // this might potentially re-assign to an existing view variable, but this is OK, we
@@ -257,25 +272,23 @@ MEDPresentation::getRenderViewCommand() const
 std::string
 MEDPresentation::getResetCameraCommand() const
 {
-  std::ostringstream oss;
-  oss << "__view" << _renderViewPyId << ".ResetCamera();";
-  return oss.str();
+  return getRenderViewVar() + ".ResetCamera();";
 }
 
 std::string
 MEDPresentation::getComponentSelectionCommand() const
 {
   std::ostringstream oss, oss_l;
-  oss_l << "__lut" << _lutId;    std::string lut(oss_l.str());
+  std::string ret;
 
   if (_selectedComponentIndex != -1)
     {
-      oss << lut << ".VectorMode = 'Component';\n";
-      oss << lut << ".VectorComponent = " << _selectedComponentIndex << ";";
+      oss << _lutVar << ".VectorMode = 'Component';\n";
+      oss << _lutVar << ".VectorComponent = " << _selectedComponentIndex << ";";
     }
   else  // Euclidean norm
     {
-      oss << lut << ".VectorMode = 'Magnitude';";
+      oss << _lutVar << ".VectorMode = 'Magnitude';";
     }
   return oss.str();
 }
@@ -283,39 +296,37 @@ MEDPresentation::getComponentSelectionCommand() const
 std::string
 MEDPresentation::getColorMapCommand() const
 {
-  std::ostringstream oss, oss_l;
-  oss_l << "__lut" << _lutId;    std::string lut(oss_l.str());
+  std::string ret;
   switch (_colorMap) {
   case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW:
-    oss << lut << ".ApplyPreset('Blue to Red Rainbow',True);";
+    ret = _lutVar + ".ApplyPreset('Blue to Red Rainbow',True);";
     break;
   case MEDCALC::COLOR_MAP_COOL_TO_WARM:
-    oss << lut << ".ApplyPreset('Cool to Warm',True);";
+    ret = _lutVar + ".ApplyPreset('Cool to Warm',True);";
     break;
   default:
     STDLOG("MEDPresentation::getColorMapCommand(): invalid colormap!");
     throw KERNEL::createSalomeException("MEDPresentation::getColorMapCommand(): invalid colormap!");
   }
-  return oss.str();
+  return ret;
 }
 std::string
 MEDPresentation::getRescaleCommand() const
 {
-  std::ostringstream oss, oss_d;
-  oss_d << "__disp" << _dispId;    std::string disp(oss_d.str());
+  std::string ret;
   switch(_sbRange)
   {
     case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS:
-      oss << disp <<  ".RescaleTransferFunctionToDataRangeOverTime();";
+      ret = _dispVar + ".RescaleTransferFunctionToDataRangeOverTime();";
       break;
     case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP:
-      oss << disp <<  ".RescaleTransferFunctionToDataRange(False);";
+      ret = _dispVar + ".RescaleTransferFunctionToDataRange(False);";
       break;
     default:
       STDLOG("MEDPresentation::getRescaleCommand(): invalid range!");
       throw KERNEL::createSalomeException("MEDPresentation::getRescaleCommand(): invalid range!");
   }
-  return oss.str();
+  return ret;
 }
 
 int
@@ -329,10 +340,7 @@ void
 MEDPresentation::activateView()
 {
   MEDPyLockWrapper lock;
-
-  std::ostringstream oss;
-  oss << "pvs.SetActiveView(__view" << _renderViewPyId << ");";
-  pushAndExecPyLine(oss.str());
+  pushAndExecPyLine("pvs.SetActiveView(" + getRenderViewVar() + ");");
 }
 
 
@@ -361,9 +369,6 @@ void
 MEDPresentation::fillAvailableFieldComponents()
 {
   MEDPyLockWrapper lock;  // GIL!
-
-  std::ostringstream oss_o;
-  oss_o << "__obj" << _objId;      std::string obj(oss_o.str());
   std::string typ;
 
   if(_fieldType == "CELLS") {
@@ -379,7 +384,7 @@ MEDPresentation::fillAvailableFieldComponents()
   }
 
   std::ostringstream oss;
-  oss << "__nbCompo = " << obj << "." << typ << ".GetArray('" <<  _fieldName << "').GetNumberOfComponents();";
+  oss << "__nbCompo = " << _srcObjVar << "." << typ << ".GetArray('" <<  _fieldName << "').GetNumberOfComponents();";
   execPyLine(oss.str());
   PyObject* p_obj = getPythonObjectFromMain("__nbCompo");
   long nbCompo;
@@ -394,7 +399,7 @@ MEDPresentation::fillAvailableFieldComponents()
   for (long i = 0; i<nbCompo; i++)
     {
       std::ostringstream oss2;
-      oss2 << "__compo = " << obj << "." << typ << ".GetArray('" <<  _fieldName << "').GetComponentName(" << i << ");";
+      oss2 << "__compo = " << _srcObjVar << "." << typ << ".GetArray('" <<  _fieldName << "').GetComponentName(" << i << ");";
       execPyLine(oss2.str());
       PyObject* p_obj = getPythonObjectFromMain("__compo");
       std::string compo;
index cfb974a4b868c3de8e31964f837c1b3aef0601c2..4b75c4f48659d1672647d316eb92c2207cb834cc 100644 (file)
@@ -75,6 +75,7 @@ protected:
                   const MEDCALC::MEDPresentationColorMap colorMap,
                   const MEDCALC::MEDPresentationScalarBarRange sbRange);
   std::string getRenderViewCommand() const;
+  std::string getRenderViewVar() const;
   std::string getResetCameraCommand() const;
 
   std::string getComponentSelectionCommand() const;
@@ -131,12 +132,14 @@ protected:
 
   ///! Identifier (in the Python dump) of the render view
   int _renderViewPyId;
-  ///! ParaView object ID in the Python scripting commands
-  int _objId;
-  ///! ParaView display ID in the Python scripting commands
-  int _dispId;
-  ///! ParaView LUT ID in the Python scripting commands
-  int _lutId;
+  ///! ParaView object variable in the Python scripting commands (source object)
+  std::string _srcObjVar;
+  ///! ParaView object variable in the Python scripting commands (final object on which all display commands are done)
+  std::string _objVar;
+  ///! ParaView display variable in the Python scripting commands
+  std::string _dispVar;
+  ///! ParaView LUT variable in the Python scripting commands
+  std::string _lutVar;
 
 private:
   ///! Pipeline elements
index a0f14a272cff8a35f3d7f4058e8b0faa26fdd18b..591f73ceea3d841725fdd21676edbb259807ffa5 100644 (file)
 
 #include "MEDPresentationContour.hxx"
 
+#include <SALOME_KernelServices.hxx>
+#undef LOG  // should be fixed in KERNEL - double definition
+#include <Basics_Utils.hxx>
+
+#include <sstream>
+
+const std::string MEDPresentationContour::TYPE_NAME = "MEDPresentationContour";
 const std::string MEDPresentationContour::PROP_NB_CONTOUR = "nbContour";
 
+MEDPresentationContour::MEDPresentationContour(const MEDCALC::ContourParameters& params,
+                                               const MEDCALC::MEDPresentationViewMode viewMode) :
+        MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange),
+        _params(params)
+{
+  setIntProperty(MEDPresentationContour::PROP_NB_CONTOUR, params.nbContours);
+}
+
+std::string
+MEDPresentationContour::getContourCommand() const
+{
+  std::ostringstream oss1;
+
+  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();
+}
+
 void
 MEDPresentationContour::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("__isovolume1 = pvs.IsoVolume(Input=__obj1);");
-//  cmd += std::string("__disp1 = pvs.Show(__isovolume1, __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("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("__isovolume1");
-//  PyObject* disp = getPythonObjectFromMain("__disp1");
-//  pushInternal(obj, disp);
-//
-//  PyGILState_Release(_gil_state);
+  MEDPresentation::internalGeneratePipeline();
+
+  MEDPyLockWrapper lock;
+
+  std::ostringstream oss_o, oss;
+  std::string view(getRenderViewVar());
+
+  oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');";
+  pushAndExecPyLine(oss.str()); oss.str("");
+
+  // Populate internal array of available components:
+  fillAvailableFieldComponents();
+  if (getIntProperty(MEDPresentation::PROP_NB_COMPONENTS) > 1)
+    {
+      const char * msg = "Contour presentation only works for scalar field!"; // this message will appear in GUI too
+      STDLOG(msg);
+      throw KERNEL::createSalomeException(msg);
+    }
+
+  pushAndExecPyLine( getRenderViewCommand() ); // 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();
+    }
+  oss << _objVar << " = pvs.Contour(Input=" << _srcObjVar << ");";
+  pushAndExecPyLine(oss.str()); oss.str("");
+  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();");
 }
 
 void
 MEDPresentationContour::updatePipeline(const MEDCALC::ContourParameters& params)
 {
-  // :TODO:
+  if (params.fieldHandlerId != _params.fieldHandlerId)
+    throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
+
+  if (params.scalarBarRange != _params.scalarBarRange)
+    updateScalarBarRange<MEDPresentationContour, MEDCALC::ContourParameters>(params.scalarBarRange);
+  if (params.colorMap != _params.colorMap)
+    updateColorMap<MEDPresentationContour, MEDCALC::ContourParameters>(params.colorMap);
+
+  if (params.nbContours != _params.nbContours)
+    updateNbContours(params.nbContours);
+}
+
+void
+MEDPresentationContour::updateNbContours(const int nbContours)
+{
+  _params.nbContours = nbContours;
+
+  // GUI helper:
+  setIntProperty(MEDPresentationContour::PROP_NB_CONTOUR, nbContours);
+
+  // Update the pipeline:
+  {
+    MEDPyLockWrapper lock;
+    std::string cmd = getContourCommand();
+    pushAndExecPyLine(cmd);
+    pushAndExecPyLine("pvs.Render();");
+  }
 }
index 36acc6f728e8affc07e748ee5ad4148f8b54e0ac..4fb42ab2885224fc07a7784a77793d41b0eff135 100644 (file)
 class MEDCALC_EXPORT MEDPresentationContour : public MEDPresentation
 {
 public:
+  static const std::string TYPE_NAME;
   static const std::string PROP_NB_CONTOUR;
 
-  MEDPresentationContour(const MEDCALC::ContourParameters& params) :
-    MEDPresentation(params.fieldHandlerId, "MEDPresentationContour"), _params(params)
-  {}
+  MEDPresentationContour(const MEDCALC::ContourParameters& params, const MEDCALC::MEDPresentationViewMode viewMode);
   virtual ~MEDPresentationContour() {}
 
   void updatePipeline(const MEDCALC::ContourParameters& params);
-  MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; }
+//  MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; }
+
+  void getParameters(MEDCALC::ContourParameters & params) const { params = _params; } ;
+  void setParameters(const MEDCALC::ContourParameters & params) { _params = params; } ;
 
 protected:
+  void updateNbContours(const int nbContours);
   virtual void internalGeneratePipeline();
 
+  std::string getContourCommand() const;
+
 private:
   MEDCALC::ContourParameters _params;
 };
index 8fc47d514e86d9bdba045ffcecb2bbd6186e7de5..fc758a1616c3bc42e53133185c7eab7e901a2344 100644 (file)
@@ -23,9 +23,9 @@
 
 // presentations
 #include "MEDPresentationScalarMap.hxx"
-//#include "MEDPresentationContour.hxx"
-//#include "MEDPresentationVectorField.hxx"
+#include "MEDPresentationContour.hxx"
 //#include "MEDPresentationSlices.hxx"
+//#include "MEDPresentationVectorField.hxx"
 //#include "MEDPresentationDeflectionShape.hxx"
 //#include "MEDPresentationPointSprite.hxx"
 
@@ -128,12 +128,12 @@ MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& para
   return _makePresentation<MEDPresentationScalarMap>(params, viewMode);
 }
 
-//MEDPresentation::TypeID
-//MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params)
-//{
-//  return _makePresentation<MEDPresentationContour>(params);
-//}
-//
+MEDPresentation::TypeID
+MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params, const MEDCALC::MEDPresentationViewMode viewMode)
+{
+  return _makePresentation<MEDPresentationContour>(params, viewMode);
+}
+
 //MEDPresentation::TypeID
 //MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params)
 //{
@@ -167,18 +167,26 @@ MEDPresentationManager_i::getScalarMapParameters(MEDPresentation::TypeID present
   return tmp._retn();
 }
 
+MEDCALC::ContourParameters
+MEDPresentationManager_i::getContourParameters(MEDPresentation::TypeID presentationID)
+{
+  MEDCALC::ContourParameters p;
+  _getParameters<MEDPresentationContour>(presentationID, p);
+  return p;
+}
+
 void
 MEDPresentationManager_i::updateScalarMap(MEDPresentation::TypeID presentationID, const MEDCALC::ScalarMapParameters& params)
 {
   return _updatePresentation<MEDPresentationScalarMap>(presentationID, params);
 }
 
-//void
-//MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters& params)
-//{
-//  return _updatePresentation<MEDPresentationContour>(presentationID, params);
-//}
-//
+void
+MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters& params)
+{
+  return _updatePresentation<MEDPresentationContour>(presentationID, params);
+}
+
 //void
 //MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params)
 //{
@@ -232,6 +240,7 @@ MEDPresentationManager_i::activateView(MEDPresentation::TypeID presentationID)
 
   presentation->activateView();
   _activeViewPythonId = presentation->getPyViewID();
+  STDLOG("Activated view " << _activeViewPythonId);
   return true;
 }
 
index 82fabe186084493f29768ac68e0c4200e4d1e0ae..1016968e8e8f4dd0177b6eaa93b951fb537ac61a 100644 (file)
@@ -40,7 +40,7 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager,
   static MEDPresentationManager_i* getInstance();
 
   MEDCALC_EXPORT MEDPresentation::TypeID makeScalarMap(const MEDCALC::ScalarMapParameters&, const MEDCALC::MEDPresentationViewMode);
-//  MEDCALC_EXPORT MEDPresentation::TypeID makeContour(const MEDCALC::ContourParameters&, const MEDCALC::MEDPresentationViewMode);
+  MEDCALC_EXPORT MEDPresentation::TypeID makeContour(const MEDCALC::ContourParameters&, const MEDCALC::MEDPresentationViewMode);
 //  MEDCALC_EXPORT MEDPresentation::TypeID makeVectorField(const MEDCALC::VectorFieldParameters&);
 //  MEDCALC_EXPORT MEDPresentation::TypeID makeSlices(const MEDCALC::SlicesParameters&);
 //  MEDCALC_EXPORT MEDPresentation::TypeID makeDeflectionShape(const MEDCALC::DeflectionShapeParameters&);
@@ -53,9 +53,10 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager,
   MEDCALC_EXPORT CORBA::Long getPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName);
 
   MEDCALC_EXPORT MEDCALC::ScalarMapParameters* getScalarMapParameters(MEDPresentation::TypeID presentationID);
+  MEDCALC_EXPORT MEDCALC::ContourParameters    getContourParameters(MEDPresentation::TypeID presentationID);
 
   MEDCALC_EXPORT void updateScalarMap(MEDPresentation::TypeID, const MEDCALC::ScalarMapParameters&);
-//  MEDCALC_EXPORT void updateContour(MEDPresentation::TypeID, const MEDCALC::ContourParameters&);
+  MEDCALC_EXPORT void updateContour(MEDPresentation::TypeID, const MEDCALC::ContourParameters&);
 //  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&);
index 3ae7c49860861dfa5d541d02c9d40b5853227448..8981408956d1c24339c96258464c379853fed6b8 100644 (file)
@@ -29,19 +29,18 @@ MEDPresentationManager_i::_makePresentation(const PresentationParameters params,
   int activeViewId = getActiveViewPythonId();
 
   // Replace = Remove then add
+  std::vector<int> to_del;
   if (viewMode == MEDCALC::VIEW_MODE_REPLACE)
     {
       // Remove all presentations from this view:
+      STDLOG("About to remove all presentations from view " << activeViewId);
       std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator it;
-      std::vector<int> to_del;
       for (it = _presentations.begin(); it != _presentations.end(); ++it)
         {
           int viewId2 = (*it).second->getPyViewID();
           if (viewId2 == activeViewId)
             to_del.push_back((*it).first);
         }
-      for (std::vector<int>::const_iterator it2 = to_del.begin(); it2 != to_del.end(); ++it2)
-        removePresentation(*it2);
   }
 
   // Create a new presentation instance
@@ -64,6 +63,11 @@ MEDPresentationManager_i::_makePresentation(const PresentationParameters params,
 
   _presentations.insert( std::pair<MEDPresentation::TypeID, MEDPresentation *>(newID, presentation) );
   presentation->generatePipeline();
+
+  // If generatePipeline didn't throw, we can actually remove presentations to be deleted:
+  for (std::vector<int>::const_iterator it2 = to_del.begin(); it2 != to_del.end(); ++it2)
+    removePresentation(*it2);
+
   // Make the view holding the newly created presentation the active one:
   activateView(newID);
   return newID;
index 573a34b39a6717385d0138a8c32700c6b390f8a6..50d6ebbdcfc6f400a6fde263764d5742931830fd 100644 (file)
@@ -43,15 +43,12 @@ MEDPresentationScalarMap::internalGeneratePipeline()
 
   MEDPyLockWrapper lock;
 
-  std::ostringstream oss_o, oss_d,oss_l, oss, oss_v;
-  oss_o << "__obj" << _objId;      std::string obj(oss_o.str());
-  oss_d << "__disp" << _dispId;    std::string disp(oss_d.str());
-  oss_l << "__lut" << _lutId;    std::string lut(oss_l.str());
-  oss_v << "__view" << _renderViewPyId;    std::string view(oss_v.str());
+  std::ostringstream oss;
+  std::string view(getRenderViewVar());
 
   pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX
 
-  oss << obj << " = pvs.MEDReader(FileName='" << _fileName << "');";
+  oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');";
   pushAndExecPyLine(oss.str()); oss.str("");
 
   // Populate internal array of available components:
@@ -59,15 +56,17 @@ MEDPresentationScalarMap::internalGeneratePipeline()
 //  dumpIntProperties();
 //  dumpStringProperties();
 
-  oss << disp << " = pvs.Show(" << obj << ", " << view << ");";
+  pushAndExecPyLine(_objVar + " = " + _srcObjVar);
+
+  oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");";
   pushAndExecPyLine(oss.str()); oss.str("");
-  oss << "pvs.ColorBy(" << disp << ", ('" << _fieldType << "', '" << _fieldName << "'));";
+  oss << "pvs.ColorBy(" << _dispVar << ", ('" << _fieldType << "', '" << _fieldName << "'));";
   pushAndExecPyLine(oss.str()); oss.str("");
-  oss << disp <<  ".SetScalarBarVisibility(" << view << ", True);";
+  oss << _dispVar <<  ".SetScalarBarVisibility(" << view << ", True);";
   pushAndExecPyLine(oss.str()); oss.str("");
   oss << getRescaleCommand();
   pushAndExecPyLine(oss.str()); oss.str("");
-  oss << lut << " = pvs.GetColorTransferFunction('" << _fieldName << "');";
+  oss << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');";
   pushAndExecPyLine(oss.str()); oss.str("");
   pushAndExecPyLine(getColorMapCommand()); oss.str("");
   pushAndExecPyLine(getResetCameraCommand());
@@ -85,8 +84,13 @@ MEDPresentationScalarMap::updatePipeline(const MEDCALC::ScalarMapParameters& par
   if (params.fieldHandlerId != _params.fieldHandlerId)
     throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
 
-  if (params.displayedComponent != _params.displayedComponent)
-    updateComponent<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(std::string(params.displayedComponent));
+  if (std::string(params.displayedComponent) != std::string(_params.displayedComponent))
+    {
+      STDLOG("about to updateCompo in scalar map");
+      STDLOG("from param " << params.displayedComponent);
+      STDLOG("from intern " << _params.displayedComponent);
+      updateComponent<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(std::string(params.displayedComponent));
+    }
   if (params.scalarBarRange != _params.scalarBarRange)
     updateScalarBarRange<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(params.scalarBarRange);
   if (params.colorMap != _params.colorMap)
index 66c91bb245acf275a381b5fac32486aa614c24d7..f0398bb01bd5b86c07c06e58aad48839723d83ec 100644 (file)
@@ -39,6 +39,7 @@ SET(MEDCALCGUI_SOURCES
     XmedDataModel.cxx
     MEDWidgetHelper.cxx
     MEDWidgetHelperScalarMap.cxx
+    MEDWidgetHelperContour.cxx
 )
 
 IF(SALOME_MED_WITH_QTTESTING)
@@ -54,6 +55,7 @@ SET(MEDCALCGUI_HEADERS
   ProcessingController.hxx
   MEDWidgetHelper.hxx
   MEDWidgetHelperScalarMap.hxx
+  MEDWidgetHelperContour.hxx
   )
  
 IF(SALOME_MED_WITH_QTTESTING)
diff --git a/src/MEDCalc/gui/MEDWidgetHelperContour.cxx b/src/MEDCalc/gui/MEDWidgetHelperContour.cxx
new file mode 100644 (file)
index 0000000..40ded91
--- /dev/null
@@ -0,0 +1,80 @@
+// 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 "MEDWidgetHelperContour.hxx"
+#include "MEDPresentationContour.hxx"  // from component side.
+#include "PresentationController.hxx"
+
+#include <Basics_Utils.hxx>
+
+#include <sstream>
+
+MEDWidgetHelperContour::MEDWidgetHelperContour(const PresentationController * presController,
+                                               MEDCALC::MEDPresentationManager_ptr presManager, int presId,
+                                               const std::string & presName, WidgetPresentationParameters * paramW):
+  MEDWidgetHelper(presController, presManager, presId, presName, paramW),
+  _nbContours(-1)
+{}
+
+MEDWidgetHelperContour::~MEDWidgetHelperContour()
+{}
+
+void MEDWidgetHelperContour::loadParametersFromEngine()
+{
+  MEDWidgetHelper::loadParametersFromEngine();
+  _nbContours = _presManager->getPresentationIntProperty(_presId, MEDPresentationContour::PROP_NB_CONTOUR.c_str());
+}
+
+void MEDWidgetHelperContour::udpateWidget()
+{
+  MEDWidgetHelper::udpateWidget();
+  STDLOG("MEDWidgetHelperContour::udpateWidget() nbContour is " << _nbContours);
+
+  // Contour presentation needs the number of contours
+//  _paramWidget->setComponents(_allCompos, _selectedCompo);
+  _paramWidget->setNbContour(_nbContours);
+
+  // 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)) );
+  QObject::connect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbContourChanged(int)) );
+}
+
+void MEDWidgetHelperContour::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)) );
+  QObject::disconnect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbContourChanged(int)) );
+}
+
+void MEDWidgetHelperContour::onNbContourChanged(int nbContour)
+{
+  STDLOG("MEDWidgetHelperContour::onNbContourChanged");
+  PresentationEvent* event = new PresentationEvent();
+  event->eventtype = PresentationEvent::EVENT_CHANGE_NB_CONTOUR;
+  event->presentationId = _presId;
+  event->anInteger = nbContour;
+
+  emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent
+}
+
diff --git a/src/MEDCalc/gui/MEDWidgetHelperContour.hxx b/src/MEDCalc/gui/MEDWidgetHelperContour.hxx
new file mode 100644 (file)
index 0000000..0e545fe
--- /dev/null
@@ -0,0 +1,52 @@
+// 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_MEDWIDGETHELPERCONTOUR_HXX_
+#define SRC_MEDCALC_GUI_MEDWIDGETHELPERCONTOUR_HXX_
+
+#include "MEDWidgetHelper.hxx"
+
+class PresentationController;
+
+class MEDWidgetHelperContour: public MEDWidgetHelper
+{
+  Q_OBJECT
+
+public:
+  MEDWidgetHelperContour(const PresentationController* presController,
+                           MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName,
+                           WidgetPresentationParameters * paramW);
+  virtual ~MEDWidgetHelperContour();
+
+  virtual void udpateWidget();
+  virtual void releaseWidget();
+
+  virtual std::string getPythonTag() const { return "Contour"; }
+
+protected slots:
+  void onNbContourChanged(int nbContour);
+
+protected:
+  virtual void loadParametersFromEngine();
+
+private:
+  int _nbContours;
+};
+
+#endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERCONTOUR_HXX_ */
index c068705edeb9af9cfbad7c2b59a653df65acb982..ee17a53076ace9f58ecfc74c89bae211c8289602 100644 (file)
@@ -21,7 +21,6 @@
 #define SRC_MEDCALC_GUI_MEDWIDGETHELPERSCALARMAP_HXX_
 
 #include "MEDWidgetHelper.hxx"
-#include <QComboBox>
 
 class PresentationController;
 
@@ -39,10 +38,6 @@ public:
   virtual void releaseWidget();
 
   virtual std::string getPythonTag() const { return "ScalarMap"; }
-
-protected:
-
-
 };
 
 #endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERSCALARMAP_HXX_ */
index a845c48f8c3d6ae2e213e467d47db05ba52f2717..9d9b7c0ba64e11fb1ca4f469746156ff6170f201 100644 (file)
 #include "MEDPresentationManager_i.hxx"
 #include "XmedConsoleDriver.hxx"
 
-#include "MEDWidgetHelperScalarMap.hxx"
 #include "MEDPresentationScalarMap.hxx"
+#include "MEDPresentationContour.hxx"
+
+#include "MEDWidgetHelperScalarMap.hxx"
+#include "MEDWidgetHelperContour.hxx"
 
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
@@ -55,11 +58,11 @@ static const int OPTIONS_VIEW_MODE_SPLIT_VIEW_ID = 947;
 MEDCALC::MEDPresentationManager_ptr PresentationController::_presManager;
 
 PresentationController::PresentationController(MEDModule* salomeModule) :
-    _salomeModule(salomeModule),
-    _consoleDriver(0),
-    _studyEditor(salomeModule->getStudyEditor()),
-    _presHelperMap(),
-    _currentWidgetHelper(0)
+        _salomeModule(salomeModule),
+        _consoleDriver(0),
+        _studyEditor(salomeModule->getStudyEditor()),
+        _presHelperMap(),
+        _currentWidgetHelper(0)
 {
   STDLOG("Creating a PresentationController");
 
@@ -79,11 +82,11 @@ PresentationController::PresentationController(MEDModule* salomeModule) :
   // Retrieve MEDFactory to get MEDPresentationManager (sometimes GUI needs to talk to the engine directly)
   if ( ! _presManager ) {
       _presManager = MEDFactoryClient::getFactory()->getPresentationManager();
-    }
+  }
 
   // Connect to the click in the object browser
   connect(salomeModule, SIGNAL( presentationSelected(int , const QString&, const QString&) ),
-             this, SLOT(onPresentationSelected(int , const QString&, const QString&) )     );
+          this, SLOT(onPresentationSelected(int , const QString&, const QString&) )     );
 }
 
 PresentationController::~PresentationController()
@@ -119,9 +122,9 @@ PresentationController::_getIconName(const std::string& name)
   // Read value from preferences and suffix name to select icon theme
   int theme = mgr->integerValue("MEDCalc", "icons");
   if (theme == 0) {
-    return name + "_MODERN";
+      return name + "_MODERN";
   } else if (theme == 1) {
-    return name + "_CLASSIC";
+      return name + "_CLASSIC";
   }
   return name + "_DEFAULT";
 }
@@ -223,8 +226,8 @@ PresentationController::createActions()
   tooltip = tr("TIP_DELETE_PRESENTATION");
   icon    = tr(_getIconName("ICO_DELETE_PRESENTATION").c_str());
   actionId = _salomeModule->createStandardAction(label,this, SLOT(onDeletePresentation()),icon,tooltip);
-//  _salomeModule->createTool(actionId, presentationToolbarId);
-//  _salomeModule->action(actionId)->setIconVisibleInMenu(true);
+  //  _salomeModule->createTool(actionId, presentationToolbarId);
+  //  _salomeModule->action(actionId)->setIconVisibleInMenu(true);
   _salomeModule->createMenu(actionId, presentationMenuId);
 
   //
@@ -243,16 +246,16 @@ MEDCALC::MEDPresentationViewMode
 PresentationController::getSelectedViewMode() const
 {
   if (_salomeModule->action(OPTIONS_VIEW_MODE_REPLACE_ID)->isChecked()) {
-    return MEDCALC::VIEW_MODE_REPLACE;
+      return MEDCALC::VIEW_MODE_REPLACE;
   }
   else if (_salomeModule->action(OPTIONS_VIEW_MODE_OVERLAP_ID)->isChecked()) {
-    return MEDCALC::VIEW_MODE_OVERLAP;
+      return MEDCALC::VIEW_MODE_OVERLAP;
   }
   else if (_salomeModule->action(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID)->isChecked()) {
-    return MEDCALC::VIEW_MODE_NEW_LAYOUT;
+      return MEDCALC::VIEW_MODE_NEW_LAYOUT;
   }
   else if (_salomeModule->action(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID)->isChecked()) {
-    return MEDCALC::VIEW_MODE_SPLIT_VIEW;
+      return MEDCALC::VIEW_MODE_SPLIT_VIEW;
   }
   // Should not happen
   STDLOG("Strange!! No matching view mode found - returning VIEW_MODE_REPLACE.");
@@ -284,35 +287,35 @@ PresentationController::visualize(PresentationEvent::EventType eventType)
   // visualisation using the tui command (so that the user can see how
   // to make a view of an object from the tui console).
   for (int i=0; i<listOfSObject->size(); i++) {
-    SALOMEDS::SObject_var soField = listOfSObject->at(i);
-    int fieldId = getIntParamFromStudyEditor(soField, FIELD_ID);
-    if (fieldId < 0)  // is it a field serie ?
-      {
-        int fieldSeriesId = getIntParamFromStudyEditor(soField, FIELD_SERIES_ID);
-        // If fieldId and fieldSeriesId equals -1, then it means that it is not a field
-        // managed by the MED module, and we stop this function process.
-        if ( fieldSeriesId < 0)
-          continue;
-        MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId);
-        if (fieldHandlerList->length() < 0)
-          continue;
-        // For a field series, get the first real field entry:
-        MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0];
-        fieldId = fieldHandler.id;
-      }
+      SALOMEDS::SObject_var soField = listOfSObject->at(i);
+      int fieldId = getIntParamFromStudyEditor(soField, FIELD_ID);
+      if (fieldId < 0)  // is it a field serie ?
+        {
+          int fieldSeriesId = getIntParamFromStudyEditor(soField, FIELD_SERIES_ID);
+          // If fieldId and fieldSeriesId equals -1, then it means that it is not a field
+          // managed by the MED module, and we stop this function process.
+          if ( fieldSeriesId < 0)
+            continue;
+          MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId);
+          if (fieldHandlerList->length() < 0)
+            continue;
+          // For a field series, get the first real field entry:
+          MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0];
+          fieldId = fieldHandler.id;
+        }
 
-    MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
-    if (! fieldHandler) {
-      QMessageBox::warning(_salomeModule->getApp()->desktop(),
-         tr("Operation not allowed"),
-         tr("No field is defined"));
-      return;
-    }
+      MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
+      if (! fieldHandler) {
+          QMessageBox::warning(_salomeModule->getApp()->desktop(),
+                               tr("Operation not allowed"),
+                               tr("No field is defined"));
+          return;
+      }
 
-    PresentationEvent* event = new PresentationEvent();
-    event->eventtype = eventType;
-    event->fieldHandler = fieldHandler;
-    emit presentationSignal(event); // --> processPresentationEvent()
+      PresentationEvent* event = new PresentationEvent();
+      event->eventtype = eventType;
+      event->fieldHandler = fieldHandler;
+      emit presentationSignal(event); // --> processPresentationEvent()
   }
 }
 
@@ -363,17 +366,17 @@ PresentationController::onDeletePresentation()
 
   // For each object, emit a signal to the workspace to request pres deletion
   for (int i=0; i<listOfSObject->size(); i++) {
-    SALOMEDS::SObject_var soPres = listOfSObject->at(i);
-    int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
-    // If fieldId equals -1, then it means that it is not a field
-    // managed by the MED module, and we stop this function process.
-    if ( presId < 0 )
-      continue;
-
-    PresentationEvent* event = new PresentationEvent();
-    event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
-    event->presentationId = presId;
-    emit presentationSignal(event); // --> processPresentationEvent()
+      SALOMEDS::SObject_var soPres = listOfSObject->at(i);
+      int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
+      // If fieldId equals -1, then it means that it is not a field
+      // managed by the MED module, and we stop this function process.
+      if ( presId < 0 )
+        continue;
+
+      PresentationEvent* event = new PresentationEvent();
+      event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
+      event->presentationId = presId;
+      emit presentationSignal(event); // --> processPresentationEvent()
   }
 }
 
@@ -382,10 +385,10 @@ PresentationController::getViewModePython() const
 {
   MEDCALC::MEDPresentationViewMode viewMode = getSelectedViewMode();
   switch(viewMode) {
-  case MEDCALC::VIEW_MODE_REPLACE: return "MEDCALC.VIEW_MODE_REPLACE";
-  case MEDCALC::VIEW_MODE_OVERLAP: return "MEDCALC.VIEW_MODE_OVERLAP";
-  case MEDCALC::VIEW_MODE_NEW_LAYOUT: return "MEDCALC.VIEW_MODE_NEW_LAYOUT";
-  case MEDCALC::VIEW_MODE_SPLIT_VIEW: return "MEDCALC.VIEW_MODE_SPLIT_VIEW";
+    case MEDCALC::VIEW_MODE_REPLACE: return "MEDCALC.VIEW_MODE_REPLACE";
+    case MEDCALC::VIEW_MODE_OVERLAP: return "MEDCALC.VIEW_MODE_OVERLAP";
+    case MEDCALC::VIEW_MODE_NEW_LAYOUT: return "MEDCALC.VIEW_MODE_NEW_LAYOUT";
+    case MEDCALC::VIEW_MODE_SPLIT_VIEW: return "MEDCALC.VIEW_MODE_SPLIT_VIEW";
   }
   return QString();
 }
@@ -395,8 +398,8 @@ PresentationController::getColorMapPython() const
 {
   MEDCALC::MEDPresentationColorMap colorMap = getSelectedColorMap();
   switch(colorMap) {
-  case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW";
-  case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "MEDCALC.COLOR_MAP_COOL_TO_WARM";
+    case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW";
+    case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "MEDCALC.COLOR_MAP_COOL_TO_WARM";
   }
   return QString();
 }
@@ -405,11 +408,11 @@ QString
 PresentationController::getScalarBarRangePython() const
 {
   MEDCALC::MEDPresentationScalarBarRange colorMap = getSelectedScalarBarRange();
-   switch(colorMap) {
-   case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS: return "MEDCALC.SCALAR_BAR_ALL_TIMESTEPS";
-   case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: return "MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP";
-   }
-   return QString();
+  switch(colorMap) {
+    case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS: return "MEDCALC.SCALAR_BAR_ALL_TIMESTEPS";
+    case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: return "MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP";
+  }
+  return QString();
 }
 
 std::string
@@ -417,99 +420,78 @@ PresentationController::getPresTypeFromWidgetHelper(int presId) const
 {
   std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
   if (it != _presHelperMap.end())
-      return (*it).second->getPythonTag();
+    return (*it).second->getPythonTag();
   return "UNKNOWN";
 }
 
 void
 PresentationController::processPresentationEvent(const PresentationEvent* event) {
   // --> Send commands to SALOME Python console
+  QString viewMode = getViewModePython();
+  QString colorMap = getColorMapPython();
+  QString scalarBarRange = getScalarBarRangePython();
+  MEDCALC::FieldHandler* fieldHandler = event->fieldHandler;
+  QStringList commands;
   if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) {
-    QString viewMode = getViewModePython();
-    //QString displayedComponent = ; // from PresentationController combobox
-    //QString scalarBarRange = ; // from PresentationController spinbox
-    QString colorMap = getColorMapPython();
-    MEDCALC::FieldHandler* fieldHandler = event->fieldHandler;
-    QStringList commands;
-    commands += QString("presentation_id = medcalc.MakeScalarMap(accessField(%1), %2, colorMap=%3)").arg(fieldHandler->id).arg(viewMode).arg(colorMap);
-    commands += QString("presentation_id");
-    _consoleDriver->exec(commands);
+      commands += QString("presentation_id = medcalc.MakeScalarMap(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_CONTOUR ) {
+      commands += QString("presentation_id = medcalc.MakeContour(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_CONTOUR ) {
-//    QString viewMode = getViewModePython();
-//    MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler;
-//    QStringList commands;
-//    commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
-//    commands += QString("presentation_id");
-//    _consoleDriver->exec(commands);
-//  }
-//  else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) {
-//    QString viewMode = getViewModePython();
-//    MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler;
-//    QStringList commands;
-//    commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
-//    commands += QString("presentation_id");
-//    _consoleDriver->exec(commands);
-//  }
-//  else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
-//    QString viewMode = getViewModePython();
-//    MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler;
-//    QStringList commands;
-//    commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
-//    commands += QString("presentation_id");
-//    _consoleDriver->exec(commands);
-//  }
-//  else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) {
-//    QString viewMode = getViewModePython();
-//    MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler;
-//    QStringList commands;
-//    commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
-//    commands += QString("presentation_id");
-//    _consoleDriver->exec(commands);
-//  }
-//  else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
-//    QString viewMode = getViewModePython();
-//    MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler;
-//    QStringList commands;
-//    commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
-//    commands += QString("presentation_id");
-//    _consoleDriver->exec(commands);
-//  }
+  //  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 ) {
+  //    commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
+  //    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?
   else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COMPONENT ) {
       std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
-      QStringList commands;
       commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
       commands += QString("params.displayedComponent = '%1'").arg(QString::fromStdString(event->aString));
       commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
-      _consoleDriver->exec(commands);
   }
   else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COLORMAP ) {
       std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
-      QStringList commands;
       commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
       commands += QString("params.colorMap = %1").arg(getColorMapPython());
       commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
-      _consoleDriver->exec(commands);
-    }
+  }
   else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_TIME_RANGE ) {
       std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
-      QStringList commands;
       commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
       commands += QString("params.scalarBarRange = %1").arg(getScalarBarRangePython());
       commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
-      _consoleDriver->exec(commands);
+  }
+  else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_CONTOUR ) {
+      std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
+      commands += QString("params = medcalc.GetContourParameters(%2)").arg(event->presentationId);
+      commands += QString("params.nbContours = %1").arg(event->anInteger);
+      commands += QString("medcalc.UpdateContour(%1, params)").arg(event->presentationId);
   }
   else if ( event->eventtype == PresentationEvent::EVENT_DELETE_PRESENTATION ) {
-      QStringList commands;
       commands += QString("medcalc.RemovePresentation(%1)").arg(event->presentationId);
-      _consoleDriver->exec(commands);
   }
   else {
-    STDLOG("The event "<<event->eventtype<<" is not implemented yet");
+      STDLOG("The event "<<event->eventtype<<" is not implemented yet");
   }
+  _consoleDriver->exec(commands);
 }
 
 MEDWidgetHelper *
@@ -522,22 +504,24 @@ PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager
   MEDWidgetHelper * wh;
   if (type == MEDPresentationScalarMap::TYPE_NAME)
     wh = new MEDWidgetHelperScalarMap(this, _presManager, presId, name, _widgetPresentationParameters);
+  else if (type == MEDPresentationContour::TYPE_NAME)
+    wh = new MEDWidgetHelperContour(this, _presManager, presId, name, _widgetPresentationParameters);
   else
     {
-//    case PRES_CONTOUR:
-//// break;
-//    case PRES_DEFLECTION:
-////          break;
-//    case PRES_VECTOR_FIELD:
-//  //        break;
-//    case PRES_POINT_SPRITE:
-//    //      break;
-//    case PRES_POINT_SPRITE:
-//      //    break;
-//    default:
+      //    case PRES_CONTOUR:
+      //// break;
+      //    case PRES_DEFLECTION:
+      ////          break;
+      //    case PRES_VECTOR_FIELD:
+      //  //        break;
+      //    case PRES_POINT_SPRITE:
+      //    //      break;
+      //    case PRES_POINT_SPRITE:
+      //      //    break;
+      //    default:
       STDLOG("findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!");
 
-  }
+    }
   _presHelperMap[presId] = wh;
   return wh;
 }
@@ -575,19 +559,19 @@ PresentationController::onParavisDump()
 
   // For the first object only, request the dump
   for (int i=0; i<listOfSObject->size(); i++) {
-    SALOMEDS::SObject_var soPres = listOfSObject->at(i);
-    int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
-    // If fieldId equals -1, then it means that it is not a field
-    // managed by the MED module, and we stop this function process.
-    if ( presId < 0 )
-      continue;
-
-    std::string dump(_presManager->getParavisDump(presId));
-    std::cerr << "#====== ParaVis dump =============== " << std::endl;
-    std::cerr << dump;
-    std::cerr << "#====== End of ParaVis dump ======== " << std::endl;
-
-    break; // stop at the first one
+      SALOMEDS::SObject_var soPres = listOfSObject->at(i);
+      int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
+      // If fieldId equals -1, then it means that it is not a field
+      // managed by the MED module, and we stop this function process.
+      if ( presId < 0 )
+        continue;
+
+      std::string dump(_presManager->getParavisDump(presId));
+      std::cerr << "#====== ParaVis dump =============== " << std::endl;
+      std::cerr << dump;
+      std::cerr << "#====== End of ParaVis dump ======== " << std::endl;
+
+      break; // stop at the first one
   }
 }
 
@@ -595,8 +579,8 @@ void
 PresentationController::updateTreeViewWithNewPresentation(long fieldId, long presentationId)
 {
   if (presentationId < 0) {
-    std::cerr << "Unknown presentation\n";
-    return;
+      std::cerr << "Unknown presentation\n";
+      return;
   }
 
   std::string name(_presManager->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str()));
@@ -617,30 +601,30 @@ PresentationController::updateTreeViewWithNewPresentation(long fieldId, long pre
       oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
 
 
-//  MEDCALC::MEDPresentationViewMode viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId);
-//
-//  // Remove sibling presentations if view mode is set to REPLACE
-//  if (viewMode == MEDCALC::VIEW_MODE_REPLACE) {
-//    MED_ORB::PresentationsList* presList = _salomeModule->engine()->getSiblingPresentations(_CAST(Study, studyDS)->GetStudy(), presentationId);
-//    CORBA::ULong size = presList->length();
-//
-//    std::stringstream sstm;
-//    sstm << "Removing sibling presentation(s): ";
-//    for (int i = 0; i < size; ++i)
-//      sstm << (*presList)[i] << "  ";
-//    STDLOG(sstm.str());
-//
-//    for (int i = 0; i < size; ++i) {
-//      PresentationEvent* event = new PresentationEvent();
-//      event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
-//      XmedDataObject* dataObject = new XmedDataObject();
-//      dataObject->setPresentationId((*presList)[i]);
-//      event->objectdata = dataObject;
-//      emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
-//    }
-//
-//    delete presList;
-//  }
+  //  MEDCALC::MEDPresentationViewMode viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId);
+  //
+  //  // Remove sibling presentations if view mode is set to REPLACE
+  //  if (viewMode == MEDCALC::VIEW_MODE_REPLACE) {
+  //    MED_ORB::PresentationsList* presList = _salomeModule->engine()->getSiblingPresentations(_CAST(Study, studyDS)->GetStudy(), presentationId);
+  //    CORBA::ULong size = presList->length();
+  //
+  //    std::stringstream sstm;
+  //    sstm << "Removing sibling presentation(s): ";
+  //    for (int i = 0; i < size; ++i)
+  //      sstm << (*presList)[i] << "  ";
+  //    STDLOG(sstm.str());
+  //
+  //    for (int i = 0; i < size; ++i) {
+  //      PresentationEvent* event = new PresentationEvent();
+  //      event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
+  //      XmedDataObject* dataObject = new XmedDataObject();
+  //      dataObject->setPresentationId((*presList)[i]);
+  //      event->objectdata = dataObject;
+  //      emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
+  //    }
+  //
+  //    delete presList;
+  //  }
 
   // update Object browser
   _salomeModule->getApp()->updateObjectBrowser(true);
@@ -650,8 +634,8 @@ void
 PresentationController::updateTreeViewForPresentationRemoval(long presentationId)
 {
   if (presentationId < 0) {
-    std::cerr << "Unknown presentation\n";
-    return;
+      std::cerr << "Unknown presentation\n";
+      return;
   }
 
   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
@@ -688,7 +672,7 @@ PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
       }
   }
   else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
-    updateTreeViewForPresentationRemoval(event->presentationId);
+      updateTreeViewForPresentationRemoval(event->presentationId);
   }
 }
 
index 536631af94e3a56f0201484a20856cd690bdb3ff..784fbb314ec4916228c2884968d0e93603284f60 100644 (file)
@@ -15,7 +15,9 @@ typedef struct {
 
     EVENT_CHANGE_COMPONENT,
     EVENT_CHANGE_COLORMAP,
-    EVENT_CHANGE_TIME_RANGE
+    EVENT_CHANGE_TIME_RANGE,
+
+    EVENT_CHANGE_NB_CONTOUR
   };
 
   EventType eventtype;
index ad2c1e231383e3ccc724931b834ac07099c3bf4b..f135d38fcf99ef9e1509e0f8d856731e384275fa 100644 (file)
@@ -36,6 +36,7 @@
 #include <SUIT_ResourceMgr.h>
 
 #include <QTimer>
+#include <QMessageBox>
 
 /*!
  * This class defines a DockWidget plugged in the SALOME application,
@@ -319,6 +320,10 @@ void WorkspaceController::processMedEvent(const MEDCALC::MedEvent* event) {
   else if ( event->type == MEDCALC::EVENT_QUIT_SALOME ) {
     emit workspaceSignal(event); // forward to TestController
   }
+  else if ( event->type == MEDCALC::EVENT_ERROR ) {
+      std::string msg(event->msg);
+      QMessageBox::warning(_salomeModule->getApp()->desktop(), "Error", QString::fromStdString(msg));
+    }
 }
 
 /*!
index 05765430e1fe840a71a8134dad4cbeb8dcd6ef36..4e7231b114f1a76d5227c91dccf3c4f04430eec1 100644 (file)
@@ -34,6 +34,8 @@ WidgetPresentationParameters::WidgetPresentationParameters(QWidget* parent)
                    this,                       SLOT(onComboScalarBarRangeIndexChanged(int)) );
   QObject::connect(_ui.comboBoxColorMap,       SIGNAL(currentIndexChanged(int)),
                    this,                       SLOT(onComboColorMapIndexChanged(int)) );
+  QObject::connect(_ui.spinBox,                SIGNAL(valueChanged(int)),
+                     this,                     SLOT(onSpinBoxValueChanged(int)) );
 }
 
 void
@@ -54,6 +56,11 @@ WidgetPresentationParameters::onComboScalarBarRangeIndexChanged(int idx)
   if (!_blockSig) emit comboScalarBarRangeIndexChanged(idx);
 }
 
+void
+WidgetPresentationParameters::onSpinBoxValueChanged(int val)
+{
+  if (!_blockSig) emit spinBoxValueChanged(val);
+}
 
 void
 WidgetPresentationParameters::toggleWidget(bool show)
@@ -112,6 +119,30 @@ WidgetPresentationParameters::setComponents(vector<string> compos, int selecInde
   _blockSig = false;
 }
 
+void
+WidgetPresentationParameters::setNbContour(int nbContour)
+{
+  if (nbContour <= 0)
+    {
+      //TODO throw?
+      STDLOG("WidgetPresentationParameters::setNbContour(): invalid number of contours!");
+    }
+
+  // Show the widget:
+  _ui.labelSpinBox->setText(tr("LAB_NB_CONTOUR"));
+  _ui.labelSpinBox->show();
+  _ui.spinBox->show();
+
+  _blockSig = true;
+  _ui.spinBox->setValue(nbContour);
+  _blockSig = false;
+}
+
+int WidgetPresentationParameters::getNbContour() const
+{
+  return _ui.spinBox->value();
+}
+
 void
 WidgetPresentationParameters::setScalarBarRange(MEDCALC::MEDPresentationScalarBarRange sbrange)
 {
index 03f70bdb016ff4d67428932dda2fca67e378063d..42888a65a0a15cc9d97825916eb84c3231cbbb7f 100644 (file)
@@ -53,6 +53,9 @@ public:
 
   void setPresName(const std::string& name);
 
+  int getNbContour() const;
+  void setNbContour(int nbContour);
+
   void toggleWidget(bool show);
   bool isShown() const;
   QComboBox * getComboBoxCompo();
@@ -61,11 +64,13 @@ signals:
   void comboScalarBarRangeIndexChanged(int);
   void comboColorMapIndexChanged(int);
   void comboCompoIndexChanged(int);
+  void spinBoxValueChanged(int);
 
 private slots:
   void onComboScalarBarRangeIndexChanged(int);
   void onComboColorMapIndexChanged(int);
   void onComboCompoIndexChanged(int);
+  void onSpinBoxValueChanged(int);
 
 private:
   Ui_WidgetPresentationParameters _ui; // instance of the class defined in ui_WidgetPresentationParameters.h
diff --git a/src/MEDCalc/test/tui/contour.py b/src/MEDCalc/test/tui/contour.py
new file mode 100644 (file)
index 0000000..b1e47e4
--- /dev/null
@@ -0,0 +1,45 @@
+# 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 0 = CONCENTRATION_ELEM_DOM (ON_CELLS) -> scalar
+presentation_id = medcalc.MakeContour(accessField(0), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW)
+sleep(2)
+medcalc.RemovePresentation(presentation_id)
+sleep(2)
+
+# Field 55 = VITESSE_ELEM_DOM (ON_CELLS) -> vector field, contour should fail.
+try:
+  presentation_id = medcalc.MakeContour(accessField(55), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW)
+  sys.exit(-1);
+except:
+  print "Contour failed as expected."
+sleep(2)
diff --git a/src/MEDCalc/test/tui/medfiles/agitateur.med b/src/MEDCalc/test/tui/medfiles/agitateur.med
new file mode 100644 (file)
index 0000000..73c62e1
Binary files /dev/null and b/src/MEDCalc/test/tui/medfiles/agitateur.med differ
index 54541ad23f3d8faea5432135c74b2e884992e4ce..343aa051d18e217c40bb3081a11e00fce9654d70 100644 (file)
 # 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 saveWorkspace, cleanWorkspace
-from medcalc.medconsole import putInWorkspace, removeFromWorkspace
 from medcalc.medconsole import accessField
-from medcalc.medconsole import getEnvironment, ls, la
-
-import os
 
 from medcalc_testutils import GetMEDFileDirTUI
 
 datafile = os.path.join(GetMEDFileDirTUI(), "smooth_surface_and_field.med")
 source_id = medcalc.LoadDataSource(datafile)
 
-presentation_id = medcalc.MakeScalarMap(accessField(source_id), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW)
-
+presentation_id = medcalc.MakeScalarMap(accessField(0), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW)
+sleep(2)
 medcalc.RemovePresentation(presentation_id)
+sleep(2)
index 1bf752c9e587d148a1c196fa2b5203061afdb741..cf4dd4ea9634de5d0b6ac46998c21af1eaa23d2e 100644 (file)
@@ -40,7 +40,7 @@ from medio import LoadImageAsDataSource
 
 # Presentations
 from medpresentation import MakeScalarMap
-#from medpresentation import MakeContour
+from medpresentation import MakeContour
 #from medpresentation import MakeVectorField
 #from medpresentation import MakeSlices
 #from medpresentation import MakeDeflectionShape
@@ -48,8 +48,10 @@ from medpresentation import MakeScalarMap
 from medpresentation import RemovePresentation
 
 from medpresentation import GetScalarMapParameters
+from medpresentation import GetContourParameters
 
 from medpresentation import UpdateScalarMap
+from medpresentation import UpdateContour
 
 # Console commands
 import medconsole
index 2c819f6b3a38a86524c9cc4fb800394825b5b543..42a3f55c166da4e93675fb88c1993e2c86b8d312 100644 (file)
@@ -83,8 +83,8 @@ connectEventListener()
 # that they could be used in another context than the FieldProxy instances
 import MEDCALC
 
-def __notifyGui(eventType, dataId=-1, filename="", presentationId=-1):
-  medEvent = MEDCALC.MedEvent(eventType, dataId, filename, presentationId)
+def __notifyGui(eventType, dataId=-1, filename="", presentationId=-1, msg=""):
+  medEvent = MEDCALC.MedEvent(eventType, dataId, filename, presentationId, msg)
   if not eventListenerIsRunning(): return
 
   # Notify the GUI of the update event
@@ -123,3 +123,6 @@ def notifyGui_playQtTestingScenario(filename):
 #
 def notifyGui_termination():
   __notifyGui(MEDCALC.EVENT_QUIT_SALOME)
+  
+def notifyGui_error(msg):
+  __notifyGui(MEDCALC.EVENT_ERROR, msg=msg)
index 8762d9a02213a1497208e94496717a56aba2ed7c..b59490093a0bfe213589067826999f416b713757 100644 (file)
@@ -18,8 +18,8 @@
 #
 
 import medcalc
-import MEDCALC
-from medcalc.medevents import notifyGui_addPresentation, notifyGui_removePresentation
+import MEDCALC, SALOME
+from medcalc.medevents import notifyGui_addPresentation, notifyGui_removePresentation, notifyGui_error
 
 __manager = medcalc.medcorba.factory.getPresentationManager()
 
@@ -32,22 +32,30 @@ def MakeScalarMap(proxy,
   # Create the presentation instance in CORBA engine
   # The engine in turn creates the ParaView pipeline elements
   params = MEDCALC.ScalarMapParameters(proxy.id, displayedComponent, scalarBarRange, colorMap)
-  presentation_id = __manager.makeScalarMap(params, viewMode)
-  notifyGui_addPresentation(proxy.id, presentation_id)
-  return presentation_id
-#
+  try:
+    presentation_id = __manager.makeScalarMap(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 scalar map:\n" + e.details.text)
+    raise Exception(e.details.text)
+
+def MakeContour(proxy,
+                viewMode=MEDCALC.VIEW_MODE_DEFAULT,
+                displayedComponent=MEDCALC.DISPLAY_DEFAULT,
+                scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT,
+                colorMap=MEDCALC.COLOR_MAP_DEFAULT,
+                nbContours=MEDCALC.NB_CONTOURS_DEFAULT
+                ):
+  params = MEDCALC.ContourParameters(proxy.id, scalarBarRange, colorMap, nbContours)
+  try:
+    presentation_id = __manager.makeContour(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 contour:\n" + e.details.text)
+    raise Exception(e.details.text)
 
-#def MakeContour(proxy,
-#                viewMode=MEDCALC.VIEW_MODE_DEFAULT,
-#                displayedComponent=MEDCALC.DISPLAY_DEFAULT,
-#                scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT,
-#                colorMap=MEDCALC.COLOR_MAP_DEFAULT,
-#                nbContours=MEDCALC.NB_CONTOURS_DEFAULT
-#                ):
-#  params = MEDCALC.ContourParameters(proxy.id, viewMode, displayedComponent, scalarBarRange, colorMap, nbContours)
-#  presentation_id = __manager.makeContour(params)
-#  notifyGui_addPresentation(proxy.id, presentation_id)
-#  return presentation_id
 ##
 #
 #def MakeVectorField(proxy,
@@ -102,5 +110,14 @@ def GetScalarMapParameters(presentation_id):
   params = __manager.getScalarMapParameters(presentation_id)
   return params
 
+def GetContourParameters(presentation_id):
+  # TODO: check that pres id is really a ScalarMap ...
+  params = __manager.getContourParameters(presentation_id)
+  return params
+
 def UpdateScalarMap(presentation_id, params):
   __manager.updateScalarMap(presentation_id, params)
+
+def UpdateContour(presentation_id, params):
+  __manager.updateContour(presentation_id, params)
+