Salome HOME
[MEDCalcl] PointSprite and VectorField presentations.
[modules/med.git] / src / MEDCalc / cmp / MEDPresentation.hxx
index d67971dbed4236e2d3c43efa12d569b161309871..55999b0e1fbd4f1d45e727fa6d4d46db16263a25 100644 (file)
@@ -21,8 +21,8 @@
 #ifndef SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_
 #define SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_
 
-#include "MEDCouplingRefCountObject.hxx"
 #include <Python.h>
+#include "MEDCouplingRefCountObject.hxx"
 #include "MEDCALC.hxx"
 
 #include <SALOMEconfig.h>
@@ -38,65 +38,132 @@ class MEDCALC_EXPORT MEDPresentation
   friend class MEDPresentationManager_i;
 
 public:
-
   typedef ::CORBA::Long TypeID;
 
   virtual ~MEDPresentation();
 
-  void setProperty(const std::string& propName, const std::string& propValue);
-  const std::string getProperty(const std::string& propName) const;
+  static const std::string PROP_NAME;                 // name of the presentation
+  static const std::string PROP_NB_COMPONENTS;        // number of field components
+  static const std::string PROP_SELECTED_COMPONENT;   // index of the selected component - 0 means Euclidean norm
+  static const std::string PROP_COMPONENT;            // string prefix for all properties storing component names
+  static const std::string PROP_COLOR_MAP;            // color map - TODO: arch fix - should be in params only
+  static const std::string PROP_SCALAR_BAR_RANGE;     // scalar bar range - TODO: arch fix - should be in params only
+
+  virtual void setStringProperty(const std::string& propName, const std::string& propValue);
+  const std::string getStringProperty(const std::string& propName) const;
+
+  virtual void setIntProperty(const std::string& propName, const int propValue);
+  int getIntProperty(const std::string& propName) const;
+
+  void activateView();  // non const because generates a Python trace
+
+  void dumpIntProperties() const;
+  void dumpStringProperties() const;
+
+  std::string paravisDump() const;
 
-  void activateView() const;
+  long getPyViewID() const { return _renderViewPyId; }
+  void setPyViewID(long id) { _renderViewPyId = id; }
 
 protected:
   typedef std::pair<int, PyObject *> PyObjectId;
+  static int GeneratePythonId();
 
-  MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name);
-  std::string getRenderViewCommand(MEDCALC::MEDPresentationViewMode viewMode) const;
-  std::string getResetCameraCommand() const;
-  std::string getColorMapCommand(MEDCALC::MEDPresentationColorMap colorMap) const;
-
-  virtual void internalGeneratePipeline() = 0;
+  MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name,
+                  const MEDCALC::ViewModeType viewMode,
+                  const MEDCALC::ColorMapType colorMap,
+                  const MEDCALC::ScalarBarRangeType sbRange);
+  std::string getRenderViewVar() 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;
-  void pushPyObjects(PyObjectId obj, PyObjectId disp);
+//  void pushPyObjects(PyObjectId obj, PyObjectId disp);
+  void execPyLine(const std::string & lin);
   void pushAndExecPyLine(const std::string & lin);
 
   MEDPresentation::TypeID getID() const { return _fieldHandlerId; }
-  long getPyViewID() const { return _renderViewPyId; }
 
-  static int GeneratePythonId();
+  void fillAvailableFieldComponents();
+  void applyCellToPointIfNeeded();
+  void convertTo3DVectorField();
+//  double computeCellAverageSize();
+  //void computeFieldRange
 
-  virtual MEDCALC::MEDPresentationViewMode getViewMode() = 0;
+//  virtual MEDCALC::ViewModeType getViewMode() = 0;
 
-private:
+  template<typename PresentationType, typename PresentationParameters>
+  void updateComponent(const std::string& newCompo);
 
+  template<typename PresentationType, typename PresentationParameters>
+  void updateColorMap(MEDCALC::ColorMapType colorMap);
+
+  template<typename PresentationType, typename PresentationParameters>
+  void updateScalarBarRange(MEDCALC::ScalarBarRangeType sbRange);
+
+  template<typename PresentationType, typename PresentationParameters>
+  void getParameters(PresentationParameters& params) const;
+
+  template<typename PresentationType, typename PresentationParameters>
+  void setParameters(const PresentationParameters& params);
+
+private:
   std::string getFieldTypeString(MEDCoupling::TypeOfField fieldType) const;
 
   // The following functions are reserved to friend class MEDPresentationManager
   void generatePipeline();
 
   template<typename PresentationType, typename PresentationParameters>
-  void updatePipeline(PresentationParameters params);
+  void updatePipeline(const PresentationParameters& params);
 
 protected:
+  std::string _meshName;
   std::string _fileName;
   std::string _fieldName;
   std::string _fieldType;
 
+  MEDPresentation::TypeID _fieldHandlerId;
+
+  int _selectedComponentIndex;
+  MEDCALC::ViewModeType _viewMode;
+  MEDCALC::ColorMapType _colorMap;
+  MEDCALC::ScalarBarRangeType _sbRange;
+
   ///! Identifier (in the Python dump) of the render view
   int _renderViewPyId;
+  ///! 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:
-  MEDPresentation::TypeID _fieldHandlerId;
-
   ///! Pipeline elements
-  std::vector<PyObjectId> _pipeline;
+//  std::vector<PyObjectId> _pipeline;
 
   ///! Corresponding display object, if any:
-  std::vector<PyObjectId> _display;
+//  std::vector<PyObjectId> _display;
 
   ///! Presentation properties <key,value>
-  std::map<std::string, std::string> _properties;
+  std::map<std::string, std::string> _propertiesStr;
+  std::map<std::string, int> _propertiesInt;
+
+  std::vector<std::string> _pythonCmds;
+
+  mutable PyObject* _globalDict;
 };
 
 #include "MEDPresentation.txx"