1 // Copyright (C) 2011-2023 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 struct ComponentThresold {
41 _thresholdDispVar = "";
42 _thresholdLutVar = "";
43 _thresholdInitialized = false;
47 ///! ParaView Threshold filter variable to hide data outside custom range in Python scripting
48 std::string _thresholdVar;
49 ///! ParaView Threshold display variable to hide data outside custom range in Python scripting
50 std::string _thresholdDispVar;
51 ///! ParaView Threshold LUT variable in the Python scripting commands
52 std::string _thresholdLutVar;
54 ///! Initialization flag
55 bool _thresholdInitialized;
60 _thresholdInitialized = false;
65 typedef std::vector<ComponentThresold> PresentationThresolds;
67 class MEDCALC_EXPORT MEDPresentation
69 friend class MEDPresentationManager_i;
72 typedef ::CORBA::Long TypeID;
74 virtual void initFieldMeshInfos();
76 virtual ~MEDPresentation();
78 static const std::string PROP_NAME; // name of the presentation
79 static const std::string PROP_NB_COMPONENTS; // number of field components
80 static const std::string PROP_SELECTED_COMPONENT; // index of the selected component - 0 means Euclidean norm
81 static const std::string PROP_COMPONENT; // string prefix for all properties storing component names
82 static const std::string PROP_COLOR_MAP; // color map - TODO: arch fix - should be in params only
83 static const std::string PROP_SCALAR_BAR_RANGE; // scalar bar range - TODO: arch fix - should be in params only
84 static const std::string PROP_VISIBILITY; // presentation visibility
85 static const std::string PROP_SCALAR_BAR_VISIBILITY; // scalar bar visiblity
86 static const std::string PROP_SCALAR_BAR_MIN_VALUE; // min value of scalar bar range
87 static const std::string PROP_SCALAR_BAR_MAX_VALUE; // max value of scalar bar range
88 static const std::string PROP_HIDE_DATA_OUTSIDE_CUSTOM_RANGE; // Hide data outside custom range
91 virtual void setStringProperty(const std::string& propName, const std::string& propValue);
92 const std::string getStringProperty(const std::string& propName) const;
94 virtual void setIntProperty(const std::string& propName, const int propValue);
95 int getIntProperty(const std::string& propName) const;
97 virtual void setDoubleProperty(const std::string& propName, const double propValue);
98 double getDoubleProperty(const std::string& propName) const;
100 // returns True if the view was still alive, False if it must have been recreated
101 // because the user closed it.
102 virtual bool activateView();
103 virtual void recreateViewSetup();
105 void dumpIntProperties() const;
106 void dumpStringProperties() const;
107 void dumpDoubleProperties() const;
109 std::string paravisDump() const;
111 long getPyViewID() const { return _renderViewPyId; }
112 void setPyViewID(long id) { _renderViewPyId = id; }
114 static std::string toScriptCellType(const std::string&);
117 typedef std::pair<int, PyObject *> PyObjectId;
118 static int GeneratePythonId();
120 MEDPresentation(MEDPresentation::TypeID handlerId, const std::string& name,
121 const MEDCALC::ViewModeType viewMode,
122 const MEDCALC::ColorMapType colorMap,
123 const MEDCALC::ScalarBarRangeType sbRange);
124 std::string getRenderViewVar() const;
126 // The most common elements of the ParaView pipeline:
127 void setOrCreateRenderView();
130 void selectFieldComponent();
131 void virtual showObject();
132 void virtual hideObject();
134 virtual void showScalarBar();
135 virtual void hideScalarBar();
136 void scalarBarVisibility();
137 void rescaleTransferFunction();
138 void selectColorMap(const bool updateFieldComponent=true);
139 virtual void scalarBarTitle();
140 void resetCameraAndRender();
141 virtual void visibility();
143 void thresholdPresentation();
144 void unThresholdPresentation();
145 void thresholdValues();
146 virtual void additionalThresholdActions() {};
147 virtual std::string additionalThresholdVisualizationActions() { return ""; };
148 virtual std::string additionalThresholdInitializationActions() { return ""; };
149 virtual void additionalUnThresholdActions() {};
150 virtual std::string getFieldName() const;
151 virtual std::string getThresholdFieldName() const;
153 std::string getScriptCellType() const;
154 bool isThresoldActive() const;
156 virtual void internalGeneratePipeline();
157 virtual void internalGenerateThreshold();
158 const std::string& getDispVar();
159 const std::string& getLutVar();
160 PyObject* getPythonObjectFromMain(const char* var) const;
161 void execPyLine(const std::string & lin);
162 void pushAndExecPyLine(const std::string & lin);
164 MEDPresentation::TypeID getID() const { return _handlerId; }
166 void fillAvailableFieldComponents();
167 void applyCellToPointIfNeeded();
168 void extractFileName(const std::string& name);
169 // void convertTo3DVectorField();
171 virtual MEDCALC::PresentationVisibility presentationStateInActiveView();
173 template<typename PresentationType, typename PresentationParameters>
174 void updateComponent(const std::string& newCompo);
176 template<typename PresentationType, typename PresentationParameters>
177 void updateColorMap(MEDCALC::ColorMapType colorMap);
179 template<typename PresentationType, typename PresentationParameters>
180 void updateScalarBarRange(MEDCALC::ScalarBarRangeType sbRange,
181 bool hideDataoutsideCustomRange,
182 double minValue, double maxValue);
184 template<typename PresentationType, typename PresentationParameters>
185 void updateVisibility(const bool theVisibility);
187 template<typename PresentationType, typename PresentationParameters>
188 void updateScalarBarVisibility(const bool theVisibility);
190 template<typename PresentationType, typename PresentationParameters>
191 void getParameters(PresentationParameters& params) const;
193 template<typename PresentationType, typename PresentationParameters>
194 void setParameters(const PresentationParameters& params);
196 int getThresholdIndex() const;
198 void deleteThresholds();
201 std::string getPVFieldTypeString(MEDCoupling::TypeOfField fieldType) const;
203 // The following functions are reserved to friend class MEDPresentationManager
204 void generatePipeline();
206 template<typename PresentationType, typename PresentationParameters>
207 void updatePipeline(const PresentationParameters& params);
210 std::string _meshName;
211 std::string _fileName;
212 std::string _fieldName;
214 ///! MEDCoupling field type (ON_NODES, ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE
215 MEDCoupling::TypeOfField _mcFieldType;
216 ///! ParaView field type: "CELLS" or "POINTS"
217 std::string _pvFieldType;
218 ///! ParaView field type: "CELLS" or "POINTS" used in the ColorBy method. Not necessarily equal to _pvFieldType.
219 std::string _colorByType;
221 MEDPresentation::TypeID _handlerId; // either a field or a mesh id (a field ID though, most of the time)
223 int _selectedComponentIndex;
225 int _nbComponentsInThresholdInput;
226 MEDCALC::ViewModeType _viewMode;
227 MEDCALC::ColorMapType _colorMap;
228 MEDCALC::ScalarBarRangeType _sbRange;
229 bool _presentationVisibility;
230 bool _scalarBarVisibility;
231 bool _hideDataOutsideCustomRange;
232 double _scalarBarRangeArray[2];
234 ///! Identifier (in the Python dump) of the render view
236 ///! ParaView object variable in the Python scripting commands (source object)
237 std::string _srcObjVar;
238 ///! ParaView object variable in the Python scripting commands (final object on which all display commands are done)
240 ///! ParaView display variable in the Python scripting commands
241 std::string _dispVar;
242 ///! ParaView LUT variable in the Python scripting commands
244 ///! ParaView variable in Python holding the data range
245 std::string _rangeVar;
246 ///! Prorgammable variable in the Python scripting commands
247 std::string _programmableVar;
248 bool _programmableInitialized;
251 PresentationThresolds _presentationThresolds;
255 ///! Presentation properties <key,value>
256 std::map<std::string, std::string> _propertiesStr;
257 std::map<std::string, int> _propertiesInt;
258 std::map<std::string, double> _propertiesDouble;
260 std::vector<std::string> _pythonCmds;
262 mutable PyObject* _globalDict;
265 #include "MEDPresentation.txx"
267 #endif /* SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_ */