Salome HOME
[MEDCalcl] PointSprite and VectorField presentations.
[modules/med.git] / src / MEDCalc / cmp / MEDPresentation.hxx
1 // Copyright (C) 2011-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Authors: A Bruneton (CEA), C Aguerre (EdF)
20
21 #ifndef SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_
22 #define SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_
23
24 #include <Python.h>
25 #include "MEDCouplingRefCountObject.hxx"
26 #include "MEDCALC.hxx"
27
28 #include <SALOMEconfig.h>
29 #include CORBA_SERVER_HEADER(MEDDataManager)
30 #include CORBA_SERVER_HEADER(MEDPresentationManager)
31
32 #include <vector>
33 #include <map>
34 #include <string>
35
36 class MEDCALC_EXPORT MEDPresentation
37 {
38   friend class MEDPresentationManager_i;
39
40 public:
41   typedef ::CORBA::Long TypeID;
42
43   virtual ~MEDPresentation();
44
45   static const std::string PROP_NAME;                 // name of the presentation
46   static const std::string PROP_NB_COMPONENTS;        // number of field components
47   static const std::string PROP_SELECTED_COMPONENT;   // index of the selected component - 0 means Euclidean norm
48   static const std::string PROP_COMPONENT;            // string prefix for all properties storing component names
49   static const std::string PROP_COLOR_MAP;            // color map - TODO: arch fix - should be in params only
50   static const std::string PROP_SCALAR_BAR_RANGE;     // scalar bar range - TODO: arch fix - should be in params only
51
52   virtual void setStringProperty(const std::string& propName, const std::string& propValue);
53   const std::string getStringProperty(const std::string& propName) const;
54
55   virtual void setIntProperty(const std::string& propName, const int propValue);
56   int getIntProperty(const std::string& propName) const;
57
58   void activateView();  // non const because generates a Python trace
59
60   void dumpIntProperties() const;
61   void dumpStringProperties() const;
62
63   std::string paravisDump() const;
64
65   long getPyViewID() const { return _renderViewPyId; }
66   void setPyViewID(long id) { _renderViewPyId = id; }
67
68 protected:
69   typedef std::pair<int, PyObject *> PyObjectId;
70   static int GeneratePythonId();
71
72   MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name,
73                   const MEDCALC::ViewModeType viewMode,
74                   const MEDCALC::ColorMapType colorMap,
75                   const MEDCALC::ScalarBarRangeType sbRange);
76   std::string getRenderViewVar() const;
77
78   // The most common elements of the ParaView pipeline:
79   void setOrCreateRenderView();
80   void createSource();
81   void selectFieldComponent();
82   void showObject();
83   void colorBy(const std::string & fieldType);
84   void showScalarBar();
85   void rescaleTransferFunction();
86   void selectColorMap();
87   void resetCameraAndRender();
88
89   virtual void internalGeneratePipeline();
90   PyObject* getPythonObjectFromMain(const char* var) const;
91 //  void pushPyObjects(PyObjectId obj, PyObjectId disp);
92   void execPyLine(const std::string & lin);
93   void pushAndExecPyLine(const std::string & lin);
94
95   MEDPresentation::TypeID getID() const { return _fieldHandlerId; }
96
97   void fillAvailableFieldComponents();
98   void applyCellToPointIfNeeded();
99   void convertTo3DVectorField();
100 //  double computeCellAverageSize();
101   //void computeFieldRange
102
103 //  virtual MEDCALC::ViewModeType getViewMode() = 0;
104
105   template<typename PresentationType, typename PresentationParameters>
106   void updateComponent(const std::string& newCompo);
107
108   template<typename PresentationType, typename PresentationParameters>
109   void updateColorMap(MEDCALC::ColorMapType colorMap);
110
111   template<typename PresentationType, typename PresentationParameters>
112   void updateScalarBarRange(MEDCALC::ScalarBarRangeType sbRange);
113
114   template<typename PresentationType, typename PresentationParameters>
115   void getParameters(PresentationParameters& params) const;
116
117   template<typename PresentationType, typename PresentationParameters>
118   void setParameters(const PresentationParameters& params);
119
120 private:
121   std::string getFieldTypeString(MEDCoupling::TypeOfField fieldType) const;
122
123   // The following functions are reserved to friend class MEDPresentationManager
124   void generatePipeline();
125
126   template<typename PresentationType, typename PresentationParameters>
127   void updatePipeline(const PresentationParameters& params);
128
129 protected:
130   std::string _meshName;
131   std::string _fileName;
132   std::string _fieldName;
133   std::string _fieldType;
134
135   MEDPresentation::TypeID _fieldHandlerId;
136
137   int _selectedComponentIndex;
138   MEDCALC::ViewModeType _viewMode;
139   MEDCALC::ColorMapType _colorMap;
140   MEDCALC::ScalarBarRangeType _sbRange;
141
142   ///! Identifier (in the Python dump) of the render view
143   int _renderViewPyId;
144   ///! ParaView object variable in the Python scripting commands (source object)
145   std::string _srcObjVar;
146   ///! ParaView object variable in the Python scripting commands (final object on which all display commands are done)
147   std::string _objVar;
148   ///! ParaView display variable in the Python scripting commands
149   std::string _dispVar;
150   ///! ParaView LUT variable in the Python scripting commands
151   std::string _lutVar;
152
153 private:
154   ///! Pipeline elements
155 //  std::vector<PyObjectId> _pipeline;
156
157   ///! Corresponding display object, if any:
158 //  std::vector<PyObjectId> _display;
159
160   ///! Presentation properties <key,value>
161   std::map<std::string, std::string> _propertiesStr;
162   std::map<std::string, int> _propertiesInt;
163
164   std::vector<std::string> _pythonCmds;
165
166   mutable PyObject* _globalDict;
167 };
168
169 #include "MEDPresentation.txx"
170
171 #endif /* SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_ */