Salome HOME
4307e356fcd1b51214bd4013234cbca0b35bee4a
[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 "MEDCouplingRefCountObject.hxx"
25 #include <Python.h>
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
50   static const std::string PROP_COLOR_MAP;            // color map - TODO: arch fix - should be in params only
51   static const std::string PROP_SCALAR_BAR_RANGE;     // scalar bar range - TODO: arch fix - should be in params only
52
53   virtual void setStringProperty(const std::string& propName, const std::string& propValue);
54   const std::string getStringProperty(const std::string& propName) const;
55
56   virtual void setIntProperty(const std::string& propName, const int propValue);
57   int getIntProperty(const std::string& propName) const;
58
59   void activateView();  // non const because generates a Python trace
60
61   void dumpIntProperties() const;
62   void dumpStringProperties() const;
63
64   std::string paravisDump() const;
65
66 protected:
67   typedef std::pair<int, PyObject *> PyObjectId;
68   static int GeneratePythonId();
69
70   MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name,
71                   const MEDCALC::MEDPresentationViewMode viewMode,
72                   const MEDCALC::MEDPresentationColorMap colorMap);
73   std::string getRenderViewCommand() const;
74   std::string getResetCameraCommand() const;
75
76   std::string getComponentSelectionCommand() const;
77   std::string getColorMapCommand() const;
78   std::string getRescaleCommand() const;
79
80   virtual void internalGeneratePipeline() = 0;
81   PyObject* getPythonObjectFromMain(const char* var) const;
82 //  void pushPyObjects(PyObjectId obj, PyObjectId disp);
83   void pushAndExecPyLine(const std::string & lin);
84
85   MEDPresentation::TypeID getID() const { return _fieldHandlerId; }
86   long getPyViewID() const { return _renderViewPyId; }
87
88   void fillAvailableFieldComponents();
89
90   // TODO: follow the pattern of the others methods: template!
91   virtual MEDCALC::MEDPresentationViewMode getViewMode() = 0;
92
93   template<typename PresentationType, typename PresentationParameters>
94   void updateComponent(const std::string& newCompo);
95
96   template<typename PresentationType, typename PresentationParameters>
97   void updateColorMap(MEDCALC::MEDPresentationColorMap colorMap);
98
99   template<typename PresentationType, typename PresentationParameters>
100   void updateScalarBarRange(MEDCALC::MEDPresentationScalarBarRange sbRange);
101
102   template<typename PresentationType, typename PresentationParameters>
103   void getParameters(PresentationParameters& params) const;
104
105   template<typename PresentationType, typename PresentationParameters>
106   void setParameters(const PresentationParameters& params);
107
108 private:
109   std::string getFieldTypeString(MEDCoupling::TypeOfField fieldType) const;
110
111   // The following functions are reserved to friend class MEDPresentationManager
112   void generatePipeline();
113
114   template<typename PresentationType, typename PresentationParameters>
115   void updatePipeline(const PresentationParameters& params);
116
117 protected:
118   std::string _fileName;
119   std::string _fieldName;
120   std::string _fieldType;
121
122   MEDPresentation::TypeID _fieldHandlerId;
123
124   int _selectedComponentIndex;
125   MEDCALC::MEDPresentationViewMode _viewMode;
126   MEDCALC::MEDPresentationColorMap _colorMap;
127   MEDCALC::MEDPresentationScalarBarRange _sbRange;
128
129   ///! Identifier (in the Python dump) of the render view
130   int _renderViewPyId;
131   ///! ParaView object ID in the Python scripting commands
132   int _objId;
133   ///! ParaView display ID in the Python scripting commands
134   int _dispId;
135   ///! ParaView LUT ID in the Python scripting commands
136   int _lutId;
137
138 private:
139   ///! Pipeline elements
140 //  std::vector<PyObjectId> _pipeline;
141
142   ///! Corresponding display object, if any:
143 //  std::vector<PyObjectId> _display;
144
145   ///! Presentation properties <key,value>
146   std::map<std::string, std::string> _propertiesStr;
147   std::map<std::string, int> _propertiesInt;
148
149   std::vector<std::string> _pythonCmds;
150
151   mutable PyObject* _globalDict;
152 };
153
154 #include "MEDPresentation.txx"
155
156 #endif /* SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_ */