Salome HOME
Copyright update 2021
[modules/med.git] / src / MEDCalc / cmp / MEDPresentationContour.cxx
index e32b5ff2ced46b3be7f0c1c71d25b4c8e7e01cbc..f04f44f6b2f3de2a8d7910f27c35d3f3a1b98c78 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2016  CEA/DEN, EDF R&D
+// Copyright (C) 2016-2021  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -36,6 +36,13 @@ MEDPresentationContour::MEDPresentationContour(const MEDCALC::ContourParameters&
   setIntProperty(MEDPresentationContour::PROP_NB_CONTOUR, params.nbContours);
 }
 
+void
+MEDPresentationContour::initFieldMeshInfos()
+{
+  MEDPresentation::initFieldMeshInfos();
+  _colorByType = "POINTS";
+}
+
 void
 MEDPresentationContour::setNumberContours()
 {
@@ -57,6 +64,7 @@ MEDPresentationContour::internalGeneratePipeline()
   MEDPyLockWrapper lock;
 
   createSource();
+  setTimestamp();
 
   // Populate internal array of available components:
   fillAvailableFieldComponents();
@@ -66,8 +74,14 @@ MEDPresentationContour::internalGeneratePipeline()
       STDLOG(msg);
       throw KERNEL::createSalomeException(msg);
     }
+  if (_params.nbContours < 1)
+    {
+      const char * mes = "Invalid number of contours!";
+      STDLOG(mes);
+      throw KERNEL::createSalomeException(mes);
+    }
 
-  setOrCreateRenderView(); // instanciate __viewXXX
+  setOrCreateRenderView(); // instantiate __viewXXX, needs to be after the exception above otherwise previous elements in the view will be hidden.
 
   // Contour needs point data:
   applyCellToPointIfNeeded();
@@ -81,10 +95,14 @@ MEDPresentationContour::internalGeneratePipeline()
   oss << _objVar << ".ContourBy = ['POINTS', '" << _fieldName << "'];";
   pushAndExecPyLine(oss.str()); oss.str("");
 
+  // Colorize contour
+  oss << _objVar << ".ComputeScalars = 1;";
+  pushAndExecPyLine(oss.str()); oss.str("");
+
   // Set number of contours
   setNumberContours();
-  colorBy("POINTS");    // necessarily POINTS because of the conversion above
 
+  colorBy();    // see initFieldInfo() - necessarily POINTS because of the conversion above
   showScalarBar();
   selectColorMap();
   rescaleTransferFunction();
@@ -103,7 +121,15 @@ MEDPresentationContour::updatePipeline(const MEDCALC::ContourParameters& params)
     updateColorMap<MEDPresentationContour, MEDCALC::ContourParameters>(params.colorMap);
 
   if (params.nbContours != _params.nbContours)
-    updateNbContours(params.nbContours);
+    {
+      if (params.nbContours < 1)
+        {
+          const char * mes = "Invalid number of contours!";
+          STDLOG(mes);
+          throw KERNEL::createSalomeException(mes);
+        }
+      updateNbContours(params.nbContours);
+    }
 }
 
 void