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