1 // Copyright (C) 2011-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Authors: A Bruneton (CEA), C Aguerre (EdF)
21 #ifndef SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_
22 #define SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_
25 #include "MEDCouplingRefCountObject.hxx"
26 #include "MEDCALC.hxx"
28 #include <SALOMEconfig.h>
29 #include CORBA_SERVER_HEADER(MEDDataManager)
30 #include CORBA_SERVER_HEADER(MEDPresentationManager)
36 class MEDCALC_EXPORT MEDPresentation
38 friend class MEDPresentationManager_i;
41 typedef ::CORBA::Long TypeID;
43 virtual void initFieldMeshInfos();
45 virtual ~MEDPresentation();
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
54 virtual void setStringProperty(const std::string& propName, const std::string& propValue);
55 const std::string getStringProperty(const std::string& propName) const;
57 virtual void setIntProperty(const std::string& propName, const int propValue);
58 int getIntProperty(const std::string& propName) const;
60 // returns True if the view was still alive, False if it must have been recreated
61 // because the user closed it.
63 virtual void recreateViewSetup();
65 void dumpIntProperties() const;
66 void dumpStringProperties() const;
68 std::string paravisDump() const;
70 long getPyViewID() const { return _renderViewPyId; }
71 void setPyViewID(long id) { _renderViewPyId = id; }
74 typedef std::pair<int, PyObject *> PyObjectId;
75 static int GeneratePythonId();
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;
83 // The most common elements of the ParaView pipeline:
84 void setOrCreateRenderView();
86 void selectFieldComponent();
90 void rescaleTransferFunction();
91 void selectColorMap();
92 void scalarBarTitle();
93 void resetCameraAndRender();
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);
100 MEDPresentation::TypeID getID() const { return _handlerId; }
102 void fillAvailableFieldComponents();
103 void applyCellToPointIfNeeded();
104 void extractFileName(const std::string& name);
105 // void convertTo3DVectorField();
107 template<typename PresentationType, typename PresentationParameters>
108 void updateComponent(const std::string& newCompo);
110 template<typename PresentationType, typename PresentationParameters>
111 void updateColorMap(MEDCALC::ColorMapType colorMap);
113 template<typename PresentationType, typename PresentationParameters>
114 void updateScalarBarRange(MEDCALC::ScalarBarRangeType sbRange);
116 template<typename PresentationType, typename PresentationParameters>
117 void getParameters(PresentationParameters& params) const;
119 template<typename PresentationType, typename PresentationParameters>
120 void setParameters(const PresentationParameters& params);
123 std::string getPVFieldTypeString(MEDCoupling::TypeOfField fieldType) const;
125 // The following functions are reserved to friend class MEDPresentationManager
126 void generatePipeline();
128 template<typename PresentationType, typename PresentationParameters>
129 void updatePipeline(const PresentationParameters& params);
132 std::string _meshName;
133 std::string _fileName;
134 std::string _fieldName;
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;
143 MEDPresentation::TypeID _handlerId; // either a field or a mesh id (a field ID though, most of the time)
145 int _selectedComponentIndex;
146 MEDCALC::ViewModeType _viewMode;
147 MEDCALC::ColorMapType _colorMap;
148 MEDCALC::ScalarBarRangeType _sbRange;
150 ///! Identifier (in the Python dump) of the render view
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)
156 ///! ParaView display variable in the Python scripting commands
157 std::string _dispVar;
158 ///! ParaView LUT variable in the Python scripting commands
160 ///! ParaView variable in Python holding the data range
161 std::string _rangeVar;
164 ///! Presentation properties <key,value>
165 std::map<std::string, std::string> _propertiesStr;
166 std::map<std::string, int> _propertiesInt;
168 std::vector<std::string> _pythonCmds;
170 mutable PyObject* _globalDict;
173 #include "MEDPresentation.txx"
175 #endif /* SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_ */