Salome HOME
[MEDCalcl] PointSprite and VectorField presentations.
[modules/med.git] / src / MEDCalc / cmp / MEDPresentation.hxx
index 6fb01555a9545924ab4bc3476331976bf1f7ed25..55999b0e1fbd4f1d45e727fa6d4d46db16263a25 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2015  CEA/DEN, EDF R&D
+// Copyright (C) 2011-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
@@ -22,6 +22,7 @@
 #define SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_
 
 #include <Python.h>
+#include "MEDCouplingRefCountObject.hxx"
 #include "MEDCALC.hxx"
 
 #include <SALOMEconfig.h>
@@ -37,51 +38,134 @@ class MEDCALC_EXPORT MEDPresentation
   friend class MEDPresentationManager_i;
 
 public:
+  typedef ::CORBA::Long TypeID;
 
-  virtual ~MEDPresentation() {}
+  virtual ~MEDPresentation();
 
-  void setProperty(const std::string& propName, const std::string& propValue);
-  const std::string getProperty(const std::string& propName);
-  std::string getFieldTypeString();
+  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;
+
+  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,
+                  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 execPyLine(const std::string & lin);
+  void pushAndExecPyLine(const std::string & lin);
+
+  MEDPresentation::TypeID getID() const { return _fieldHandlerId; }
+
+  void fillAvailableFieldComponents();
+  void applyCellToPointIfNeeded();
+  void convertTo3DVectorField();
+//  double computeCellAverageSize();
+  //void computeFieldRange
+
+//  virtual MEDCALC::ViewModeType getViewMode() = 0;
+
+  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);
 
-  MEDPresentation(MEDCALC::FieldHandler* fieldHdl, std::string name);
+  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();
-  virtual void internalGeneratePipeline() = 0;
-  PyObject * getPythonObjectFromMain(const char * var);
-  void pushInternal(PyObject * obj, PyObject * disp = NULL);
 
-protected:
+  template<typename PresentationType, typename PresentationParameters>
+  void updatePipeline(const PresentationParameters& params);
 
-  ///! field reference - borrowed.
-  MEDCALC::FieldHandler* _fieldHandler;
+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:
   ///! Pipeline elements
-  std::vector< PyObject * > _pipeline;
+//  std::vector<PyObjectId> _pipeline;
 
   ///! Corresponding display object, if any:
-  std::vector< PyObject * > _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;
 
-class MEDCALC_EXPORT MEDPresentationScalarMap :  public MEDPresentation
-{
-public:
-  MEDPresentationScalarMap(MEDCALC::FieldHandler* fieldHdl, bool wireframe) :
-    MEDPresentation(fieldHdl, "MEDPresentationScalarMap"),
-    _isWireframe(wireframe)
-  {}
-  virtual ~MEDPresentationScalarMap() {}
+  std::vector<std::string> _pythonCmds;
 
-protected:
-  virtual void internalGeneratePipeline();
-
-private:
-  bool _isWireframe;
+  mutable PyObject* _globalDict;
 };
 
+#include "MEDPresentation.txx"
+
 #endif /* SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_ */