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 #include "MEDPyLockWrapper.hxx"
22 #include "MEDPresentationStreamLines.hxx"
23 #include "MEDPresentationException.hxx"
25 #include <SALOME_KernelServices.hxx>
26 #undef LOG // should be fixed in KERNEL - double definition
27 #include <Basics_Utils.hxx>
31 const std::string MEDPresentationStreamLines::TYPE_NAME = "MEDPresentationStreamLines";
32 const std::string MEDPresentationStreamLines::PROP_INTEGR_DIR_TYPE = "intDirType";
34 MEDPresentationStreamLines::MEDPresentationStreamLines(const MEDCALC::StreamLinesParameters& params,
35 const MEDCALC::ViewModeType viewMode) :
36 MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange),
39 setIntProperty(MEDPresentationStreamLines::PROP_INTEGR_DIR_TYPE, params.integrDir);
43 MEDPresentationStreamLines::getIntegrDirType() const
45 switch(_params.integrDir)
47 case MEDCALC::INTEGRATION_DIR_BOTH:
49 case MEDCALC::INTEGRATION_DIR_FORWARD:
51 case MEDCALC::INTEGRATION_DIR_BACKWARD:
54 const char * mes = "Unexpected getIntegrDirType() error!";
56 throw KERNEL::createSalomeException(mes);
58 return ""; // never happens
62 MEDPresentationStreamLines::addThirdZeroComponent()
64 std::ostringstream oss;
66 oss << _objStreamCalc << " = pvs.Calculator(Input=" << _objStreamCalc << ");";
67 pushAndExecPyLine(oss.str()); oss.str("");
68 std::string typ = "Point Data"; // Because CellDatatoPointData filter has been applied erlier
69 oss << _objStreamCalc << ".AttributeType = '" << typ << "';";
70 pushAndExecPyLine(oss.str()); oss.str("");
71 oss << _objStreamCalc << ".ResultArrayName = '" << _fieldName << "_CALC';";
72 pushAndExecPyLine(oss.str()); oss.str("");
73 oss << _objStreamCalc << ".Function = '" << _fieldName << "_X*iHat + " << _fieldName << "_Y*jHat + 0.0*kHat';";
74 pushAndExecPyLine(oss.str()); oss.str("");
76 oss << _dispVar << " = pvs.Show(" << _objStreamCalc << ", " << getRenderViewVar() << ");";
77 oss << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "', " << _dispVar << ", separate=True);";
78 execPyLine(oss.str()); oss.str("");
79 oss << "pvs.ColorBy(" << getDispVar() << ", ('" << "POINTS" << "', '" << _fieldName << "_CALC'), separate=True);";
80 execPyLine(oss.str()); oss.str("");
81 oss << "pvs.Hide(" << _objStreamCalc << ", " << getRenderViewVar() << ");";
82 execPyLine(oss.str()); oss.str("");
87 MEDPresentationStreamLines::internalGeneratePipeline()
89 MEDPresentation::internalGeneratePipeline();
91 MEDPyLockWrapper lock;
96 fillAvailableFieldComponents();
97 int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS);
100 const char * msg = "Stream Lines field presentation does not work for scalar field!";
102 throw KERNEL::createSalomeException(msg);
105 setOrCreateRenderView();
107 std::ostringstream oss;
108 if (_pvFieldType == "CELLS")
110 oss << "__objStreamCalc";
111 _objStreamCalc = oss.str(); oss.str("");
112 oss << _objStreamCalc << " = pvs.CellDatatoPointData(" << _srcObjVar << ");";
113 oss << _objStreamCalc << ".PassCellData = 1;";
114 pushAndExecPyLine(oss.str()); oss.str("");
118 oss << "__objStreamCalc";
119 _objStreamCalc = oss.str(); oss.str("");
120 oss << _objStreamCalc << "=" << _srcObjVar;
121 pushAndExecPyLine(oss.str()); oss.str("");
124 if (_nbComponents == 2)
125 addThirdZeroComponent();
127 std::string dirType = getIntegrDirType();
130 oss << _objVar << " = " << _objStreamCalc << ";";
131 oss << _objVar << ".UpdatePipeline();";
132 pushAndExecPyLine(oss.str()); oss.str("");
133 oss << _objVar << " = pvs.StreamTracer(Input=" << _objVar << ", SeedType='Point Cloud' if pvs.GetParaViewVersion().GetVersion() > 5.8 else 'Point Source');";
134 pushAndExecPyLine(oss.str()); oss.str("");
135 oss << _objVar << ".IntegrationDirection = '" << dirType << "';";
136 pushAndExecPyLine(oss.str()); oss.str("");
140 oss << "pvs.ColorBy(" << getDispVar() << ", ('" << "POINTS" << "', '" << getFieldName() << "'), separate=True);";
141 pushAndExecPyLine(oss.str()); oss.str("");
145 rescaleTransferFunction();
147 resetCameraAndRender();
151 MEDPresentationStreamLines::updatePipeline(const MEDCALC::StreamLinesParameters& params)
153 if (params.fieldHandlerId != _params.fieldHandlerId)
154 throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
156 if (params.colorMap != _params.colorMap)
157 updateColorMap<MEDPresentationStreamLines, MEDCALC::StreamLinesParameters>(params.colorMap);
159 if (params.scalarBarRange != _params.scalarBarRange ||
160 params.hideDataOutsideCustomRange != _params.hideDataOutsideCustomRange ||
161 params.scalarBarRangeArray[0] != _params.scalarBarRangeArray[0] ||
162 params.scalarBarRangeArray[1] != _params.scalarBarRangeArray[1])
163 updateScalarBarRange<MEDPresentationStreamLines, MEDCALC::StreamLinesParameters>(params.scalarBarRange,
164 params.hideDataOutsideCustomRange,
165 params.scalarBarRangeArray[0],
166 params.scalarBarRangeArray[1]);
168 if (params.integrDir != _params.integrDir)
169 updateIntegrDir(params.integrDir);
171 if (params.visibility != _params.visibility)
172 updateVisibility<MEDPresentationStreamLines, MEDCALC::StreamLinesParameters>(params.visibility);
173 if (params.scalarBarVisibility != _params.scalarBarVisibility)
174 updateScalarBarVisibility<MEDPresentationStreamLines, MEDCALC::StreamLinesParameters>(params.scalarBarVisibility);
178 MEDPresentationStreamLines::updateIntegrDir(const MEDCALC::IntegrationDirType integrDir)
180 _params.integrDir = integrDir;
183 setIntProperty(MEDPresentationStreamLines::PROP_INTEGR_DIR_TYPE, integrDir);
185 // Update the pipeline:
187 MEDPyLockWrapper lock;
188 std::ostringstream oss;
189 std::string dirType = getIntegrDirType();
190 oss << _objVar << ".IntegrationDirection = '" << dirType << "'";
191 pushAndExecPyLine(oss.str()); oss.str("");
192 pushAndExecPyLine("pvs.Render();");
197 MEDPresentationStreamLines::initFieldMeshInfos()
199 MEDPresentation::initFieldMeshInfos();
200 _colorByType = "POINTS";
203 std::string MEDPresentationStreamLines::additionalThresholdInitializationActions() {
204 if (_hideDataOutsideCustomRange) {
205 std::ostringstream oss;
206 ComponentThresold& currentThreshold = _presentationThresolds[getThresholdIndex()];
207 oss << currentThreshold._thresholdVar << ".AllScalars = 0;";
213 std::string MEDPresentationStreamLines::getFieldName() const {
214 std::ostringstream oss;
216 if (_nbComponents == 2) {
223 MEDPresentationStreamLines::scalarBarTitle()
225 if (_nbComponents == 2 && !_hideDataOutsideCustomRange) {
226 std::ostringstream oss;
227 oss << "pvs.GetScalarBar(" << getLutVar() << ").Title = '" << _fieldName << "';";
228 pushAndExecPyLine(oss.str());
230 MEDPresentation::scalarBarTitle();