1 // Copyright (C) 2016-2022 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 #ifndef _MED_PRESENTATION_TXX_
21 #define _MED_PRESENTATION_TXX_
23 #include "MEDPyLockWrapper.hxx"
25 #include <SALOME_KernelServices.hxx>
27 template<typename PresentationType, typename PresentationParameters>
29 MEDPresentation::updatePipeline(const PresentationParameters& params)
31 static_cast<PresentationType*>(this)->updatePipeline(params);
34 template<typename PresentationType, typename PresentationParameters>
36 MEDPresentation::getParameters(PresentationParameters& params) const
38 const PresentationType * p = static_cast<const PresentationType*>(this);
39 p->getParameters(params);
42 template<typename PresentationType, typename PresentationParameters>
44 MEDPresentation::setParameters(const PresentationParameters& params)
46 PresentationType * p = static_cast<PresentationType*>(this);
47 p->setParameters(params);
51 * Update the ParaVis pipeline so that the given component appears on screen.
52 * Blank means "Euclidean norm"
53 * The property PROP_SELECTED_COMPONENT holding the corresponding index selected is also updated (help for the GUI).
55 template<typename PresentationType, typename PresentationParameters>
57 MEDPresentation::updateComponent(const std::string& newCompo)
59 PresentationType * p = static_cast<PresentationType*>(this);
61 PresentationParameters params;
62 p->getParameters(params);
63 params.displayedComponent = newCompo.c_str();
64 p->setParameters(params);
66 int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS);
68 for (int i=0; i < nbCompo; i++)
70 std::ostringstream oss_p;
71 oss_p << MEDPresentation::PROP_COMPONENT << i;
72 std::string compo = getStringProperty(oss_p.str());
73 if (compo == newCompo)
79 if (idx == -1 && newCompo != "")
81 std::string msg("updateComponent(): internal error - field component not found!");
82 throw KERNEL::createSalomeException(msg.c_str());
84 setIntProperty(MEDPresentation::PROP_SELECTED_COMPONENT, idx+1); // +1 because idx=0 means Euclidean norm
85 p->_selectedComponentIndex = idx;
87 // Update ParaView pipeline:
89 MEDPyLockWrapper lock;
91 std::ostringstream oss;
92 selectFieldComponent();
93 // The component has changed, we need to rescale the scalar bar to adapt:
94 rescaleTransferFunction();
95 pushAndExecPyLine("pvs.Render();");
99 template<typename PresentationType, typename PresentationParameters>
101 MEDPresentation::updateColorMap(MEDCALC::ColorMapType colorMap)
103 PresentationType * p = static_cast<PresentationType*>(this);
105 PresentationParameters params;
106 p->getParameters(params);
107 params.colorMap = colorMap;
108 p->setParameters(params);
110 p->_colorMap = colorMap;
113 setIntProperty(MEDPresentation::PROP_COLOR_MAP, colorMap);
115 // Update the pipeline:
117 MEDPyLockWrapper lock;
119 pushAndExecPyLine("pvs.Render();");
123 template<typename PresentationType, typename PresentationParameters>
125 MEDPresentation::updateScalarBarRange(MEDCALC::ScalarBarRangeType sbRange,
126 bool hideDataOutsideCustomRange,
127 double minValue, double maxValue)
129 PresentationType * p = static_cast<PresentationType*>(this);
130 PresentationParameters params;
131 p->getParameters(params);
132 bool prevHideDataoutsideCustomRange = params.hideDataOutsideCustomRange;
134 params.scalarBarRange = sbRange;
135 params.scalarBarRangeArray[0] = minValue;
136 params.scalarBarRangeArray[1] = maxValue;
137 params.hideDataOutsideCustomRange = hideDataOutsideCustomRange;
138 p->setParameters(params);
140 p->_sbRange = sbRange;
141 p->_scalarBarRangeArray[0] = minValue;
142 p->_scalarBarRangeArray[1] = maxValue;
143 p->_hideDataOutsideCustomRange = hideDataOutsideCustomRange;
146 setIntProperty(MEDPresentation::PROP_SCALAR_BAR_RANGE, sbRange);
147 setDoubleProperty(MEDPresentation::PROP_SCALAR_BAR_MIN_VALUE, minValue);
148 setDoubleProperty(MEDPresentation::PROP_SCALAR_BAR_MAX_VALUE, maxValue);
149 setIntProperty(MEDPresentation::PROP_HIDE_DATA_OUTSIDE_CUSTOM_RANGE, static_cast<int>(hideDataOutsideCustomRange));
151 // Update the pipeline:
152 if (hideDataOutsideCustomRange || hideDataOutsideCustomRange != prevHideDataoutsideCustomRange) {
153 MEDPyLockWrapper lock;
154 threshold(); //Swith on/off threshould or update threshould range
155 pushAndExecPyLine("pvs.Render();");
159 MEDPyLockWrapper lock;
160 rescaleTransferFunction();
161 pushAndExecPyLine("pvs.Render();");
165 template<typename PresentationType, typename PresentationParameters>
167 MEDPresentation::updateVisibility(const bool theVisibility)
169 PresentationType * p = static_cast<PresentationType*>(this);
171 PresentationParameters params;
172 p->getParameters(params);
173 params.visibility = theVisibility;
174 p->setParameters(params);
176 p->_presentationVisibility = theVisibility;
179 setIntProperty(MEDPresentation::PROP_VISIBILITY, theVisibility);
181 // Update the pipeline:
183 MEDPyLockWrapper lock;
185 pushAndExecPyLine("pvs.Render();");
189 template<typename PresentationType, typename PresentationParameters>
191 MEDPresentation::updateScalarBarVisibility(const bool theVisibility)
193 PresentationType * p = static_cast<PresentationType*>(this);
195 PresentationParameters params;
196 p->getParameters(params);
197 params.scalarBarVisibility = theVisibility;
198 p->setParameters(params);
200 p->_scalarBarVisibility = theVisibility;
203 setIntProperty(MEDPresentation::PROP_SCALAR_BAR_VISIBILITY, theVisibility);
205 // Update the pipeline:
207 MEDPyLockWrapper lock;
208 scalarBarVisibility();
209 pushAndExecPyLine("pvs.Render();");
214 #endif // _MED_PRESENTATION_TXX_