Salome HOME
23582: [CEA] Rename MED module to FIELDS
[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 void initFieldMeshInfos();
44
45   virtual ~MEDPresentation();
46
47   static const std::string PROP_NAME;                 // name of the presentation
48   static const std::string PROP_NB_COMPONENTS;        // number of field components
49   static const std::string PROP_SELECTED_COMPONENT;   // index of the selected component - 0 means Euclidean norm
50   static const std::string PROP_COMPONENT;            // string prefix for all properties storing component names
51   static const std::string PROP_COLOR_MAP;            // color map - TODO: arch fix - should be in params only
52   static const std::string PROP_SCALAR_BAR_RANGE;     // scalar bar range - TODO: arch fix - should be in params only
53
54   virtual void setStringProperty(const std::string& propName, const std::string& propValue);
55   const std::string getStringProperty(const std::string& propName) const;
56
57   virtual void setIntProperty(const std::string& propName, const int propValue);
58   int getIntProperty(const std::string& propName) const;
59
60   // returns True if the view was still alive, False if it must have been recreated
61   // because the user closed it.
62   bool activateView();
63   virtual void recreateViewSetup();
64
65   void dumpIntProperties() const;
66   void dumpStringProperties() const;
67
68   std::string paravisDump() const;
69
70   long getPyViewID() const { return _renderViewPyId; }
71   void setPyViewID(long id) { _renderViewPyId = id; }
72
73 protected:
74   typedef std::pair<int, PyObject *> PyObjectId;
75   static int GeneratePythonId();
76
77   MEDPresentation(MEDPresentation::TypeID handlerId, const std::string& name,
78                   const MEDCALC::ViewModeType viewMode,
79                   const MEDCALC::ColorMapType colorMap,
80                   const MEDCALC::ScalarBarRangeType sbRange);
81   std::string getRenderViewVar() const;
82
83   // The most common elements of the ParaView pipeline:
84   void setOrCreateRenderView();
85   void createSource();
86   void selectFieldComponent();
87   void showObject();
88   void colorBy();
89   void showScalarBar();
90   void rescaleTransferFunction();
91   void selectColorMap();
92   void scalarBarTitle();
93   void resetCameraAndRender();
94
95   virtual void internalGeneratePipeline();
96   PyObject* getPythonObjectFromMain(const char* var) const;
97   void execPyLine(const std::string & lin);
98   void pushAndExecPyLine(const std::string & lin);
99
100   MEDPresentation::TypeID getID() const { return _handlerId; }
101
102   void fillAvailableFieldComponents();
103   void applyCellToPointIfNeeded();
104   void extractFileName(const std::string& name);
105 //  void convertTo3DVectorField();
106
107   template<typename PresentationType, typename PresentationParameters>
108   void updateComponent(const std::string& newCompo);
109
110   template<typename PresentationType, typename PresentationParameters>
111   void updateColorMap(MEDCALC::ColorMapType colorMap);
112
113   template<typename PresentationType, typename PresentationParameters>
114   void updateScalarBarRange(MEDCALC::ScalarBarRangeType sbRange);
115
116   template<typename PresentationType, typename PresentationParameters>
117   void getParameters(PresentationParameters& params) const;
118
119   template<typename PresentationType, typename PresentationParameters>
120   void setParameters(const PresentationParameters& params);
121
122 private:
123   std::string getPVFieldTypeString(MEDCoupling::TypeOfField fieldType) const;
124
125   // The following functions are reserved to friend class MEDPresentationManager
126   void generatePipeline();
127
128   template<typename PresentationType, typename PresentationParameters>
129   void updatePipeline(const PresentationParameters& params);
130
131 protected:
132   std::string _meshName;
133   std::string _fileName;
134   std::string _fieldName;
135
136   ///! MEDCoupling field type (ON_NODES, ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE
137   MEDCoupling::TypeOfField _mcFieldType;
138   ///! ParaView field type: "CELLS" or "POINTS"
139   std::string _pvFieldType;
140   ///! ParaView field type: "CELLS" or "POINTS" used in the ColorBy method. Not necessarily equal to _pvFieldType.
141   std::string _colorByType;
142
143   MEDPresentation::TypeID _handlerId;  // either a field or a mesh id (a field ID though, most of the time)
144
145   int _selectedComponentIndex;
146   MEDCALC::ViewModeType _viewMode;
147   MEDCALC::ColorMapType _colorMap;
148   MEDCALC::ScalarBarRangeType _sbRange;
149
150   ///! Identifier (in the Python dump) of the render view
151   int _renderViewPyId;
152   ///! ParaView object variable in the Python scripting commands (source object)
153   std::string _srcObjVar;
154   ///! ParaView object variable in the Python scripting commands (final object on which all display commands are done)
155   std::string _objVar;
156   ///! ParaView display variable in the Python scripting commands
157   std::string _dispVar;
158   ///! ParaView LUT variable in the Python scripting commands
159   std::string _lutVar;
160   ///! ParaView variable in Python holding the data range
161   std::string _rangeVar;
162
163 private:
164   ///! Presentation properties <key,value>
165   std::map<std::string, std::string> _propertiesStr;
166   std::map<std::string, int> _propertiesInt;
167
168   std::vector<std::string> _pythonCmds;
169
170   mutable PyObject* _globalDict;
171 };
172
173 #include "MEDPresentation.txx"
174
175 #endif /* SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_ */