Salome HOME
[MEDCalcl] PointSprite and VectorField presentations.
[modules/med.git] / src / MEDCalc / cmp / MEDPresentation.hxx
index f9abab44bb41f26c5c824d17deea9d3ae7f9b0ba..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,49 +38,134 @@ class MEDCALC_EXPORT MEDPresentation
   friend class MEDPresentationManager_i;
 
 public:
-
   typedef ::CORBA::Long TypeID;
 
-  virtual ~MEDPresentation() {}
+  virtual ~MEDPresentation();
+
+  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 setProperty(const std::string& propName, const std::string& propValue);
-  const std::string getProperty(const std::string& propName);
+  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; }
 
-  MEDPresentation(MEDPresentation::TypeID fieldHandlerId, std::string name);
-  std::string getRenderViewCommand(MEDCALC::MEDPresentationViewMode viewMode);
-  std::string getColorMapCommand(MEDCALC::MEDPresentationColorMap colorMap);
+  void fillAvailableFieldComponents();
+  void applyCellToPointIfNeeded();
+  void convertTo3DVectorField();
+//  double computeCellAverageSize();
+  //void computeFieldRange
 
-  virtual void internalGeneratePipeline() = 0;
-  PyObject * getPythonObjectFromMain(const char * var);
-  void pushInternal(PyObject * obj, PyObject * disp = NULL);
+//  virtual MEDCALC::ViewModeType getViewMode() = 0;
 
-  MEDPresentation::TypeID getID() { return _fieldHandlerId; }
+  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;
 
-  void generatePipeline(); // reserved to friend class MEDPresentationManager
-  std::string getFieldTypeString(MEDCoupling::TypeOfField fieldType);
+  // The following functions are reserved to friend class MEDPresentationManager
+  void generatePipeline();
 
-protected:
+  template<typename PresentationType, typename PresentationParameters>
+  void updatePipeline(const PresentationParameters& params);
 
+protected:
+  std::string _meshName;
   std::string _fileName;
   std::string _fieldName;
   std::string _fieldType;
 
-private:
-
   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;
+
+  std::vector<std::string> _pythonCmds;
+
+  mutable PyObject* _globalDict;
 };
 
+#include "MEDPresentation.txx"
+
 #endif /* SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_ */