1 // Copyright (C) 2011-2021 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
20 // Authors: A Bruneton (CEA), C Aguerre (EdF)
22 #ifndef SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_
23 #define SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_
26 #include "MEDCouplingRefCountObject.hxx"
27 #include "MEDCALC.hxx"
29 #include <SALOMEconfig.h>
30 #include CORBA_SERVER_HEADER(MEDDataManager)
31 #include CORBA_SERVER_HEADER(MEDPresentationManager)
37 class MEDCALC_EXPORT MEDPresentation
39 friend class MEDPresentationManager_i;
42 typedef ::CORBA::Long TypeID;
44 virtual void initFieldMeshInfos();
46 virtual ~MEDPresentation();
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
55 virtual void setStringProperty(const std::string& propName, const std::string& propValue);
56 const std::string getStringProperty(const std::string& propName) const;
58 virtual void setIntProperty(const std::string& propName, const int propValue);
59 int getIntProperty(const std::string& propName) const;
61 // returns True if the view was still alive, False if it must have been recreated
62 // because the user closed it.
64 virtual void recreateViewSetup();
66 void dumpIntProperties() const;
67 void dumpStringProperties() const;
69 std::string paravisDump() const;
71 long getPyViewID() const { return _renderViewPyId; }
72 void setPyViewID(long id) { _renderViewPyId = id; }
75 typedef std::pair<int, PyObject *> PyObjectId;
76 static int GeneratePythonId();
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;
84 // The most common elements of the ParaView pipeline:
85 void setOrCreateRenderView();
88 void selectFieldComponent();
92 void rescaleTransferFunction();
93 void selectColorMap();
94 void scalarBarTitle();
95 void resetCameraAndRender();
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);
102 MEDPresentation::TypeID getID() const { return _handlerId; }
104 void fillAvailableFieldComponents();
105 void applyCellToPointIfNeeded();
106 void extractFileName(const std::string& name);
107 // void convertTo3DVectorField();
109 template<typename PresentationType, typename PresentationParameters>
110 void updateComponent(const std::string& newCompo);
112 template<typename PresentationType, typename PresentationParameters>
113 void updateColorMap(MEDCALC::ColorMapType colorMap);
115 template<typename PresentationType, typename PresentationParameters>
116 void updateScalarBarRange(MEDCALC::ScalarBarRangeType sbRange);
118 template<typename PresentationType, typename PresentationParameters>
119 void getParameters(PresentationParameters& params) const;
121 template<typename PresentationType, typename PresentationParameters>
122 void setParameters(const PresentationParameters& params);
125 std::string getPVFieldTypeString(MEDCoupling::TypeOfField fieldType) const;
127 // The following functions are reserved to friend class MEDPresentationManager
128 void generatePipeline();
130 template<typename PresentationType, typename PresentationParameters>
131 void updatePipeline(const PresentationParameters& params);
134 std::string _meshName;
135 std::string _fileName;
136 std::string _fieldName;
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;
145 MEDPresentation::TypeID _handlerId; // either a field or a mesh id (a field ID though, most of the time)
147 int _selectedComponentIndex;
148 MEDCALC::ViewModeType _viewMode;
149 MEDCALC::ColorMapType _colorMap;
150 MEDCALC::ScalarBarRangeType _sbRange;
152 ///! Identifier (in the Python dump) of the render view
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)
158 ///! ParaView display variable in the Python scripting commands
159 std::string _dispVar;
160 ///! ParaView LUT variable in the Python scripting commands
162 ///! ParaView variable in Python holding the data range
163 std::string _rangeVar;
166 ///! Presentation properties <key,value>
167 std::map<std::string, std::string> _propertiesStr;
168 std::map<std::string, int> _propertiesInt;
170 std::vector<std::string> _pythonCmds;
172 mutable PyObject* _globalDict;
175 #include "MEDPresentation.txx"
177 #endif /* SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_ */