1 // Copyright (C) 2016-2024 CEA, EDF
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 <<
134 ", SeedType='Point Cloud' if not medcalc.IsPlanarObj(" << _objVar <<
136 pushAndExecPyLine(oss.str()); oss.str("");
137 oss << _objVar << ".IntegrationDirection = '" << dirType << "';";
138 pushAndExecPyLine(oss.str()); oss.str("");
142 oss << "pvs.ColorBy(" << getDispVar() << ", ('" << "POINTS" << "', '" << getFieldName() << "'), separate=True);";
143 pushAndExecPyLine(oss.str()); oss.str("");
147 rescaleTransferFunction();
149 resetCameraAndRender();
153 MEDPresentationStreamLines::updatePipeline(const MEDCALC::StreamLinesParameters& params)
155 if (params.fieldHandlerId != _params.fieldHandlerId)
156 throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
158 if (params.colorMap != _params.colorMap)
159 updateColorMap<MEDPresentationStreamLines, MEDCALC::StreamLinesParameters>(params.colorMap);
161 if (params.scalarBarRange != _params.scalarBarRange ||
162 params.hideDataOutsideCustomRange != _params.hideDataOutsideCustomRange ||
163 params.scalarBarRangeArray[0] != _params.scalarBarRangeArray[0] ||
164 params.scalarBarRangeArray[1] != _params.scalarBarRangeArray[1])
165 updateScalarBarRange<MEDPresentationStreamLines, MEDCALC::StreamLinesParameters>(params.scalarBarRange,
166 params.hideDataOutsideCustomRange,
167 params.scalarBarRangeArray[0],
168 params.scalarBarRangeArray[1]);
170 if (params.integrDir != _params.integrDir)
171 updateIntegrDir(params.integrDir);
173 if (params.visibility != _params.visibility)
174 updateVisibility<MEDPresentationStreamLines, MEDCALC::StreamLinesParameters>(params.visibility);
175 if (params.scalarBarVisibility != _params.scalarBarVisibility)
176 updateScalarBarVisibility<MEDPresentationStreamLines, MEDCALC::StreamLinesParameters>(params.scalarBarVisibility);
180 MEDPresentationStreamLines::updateIntegrDir(const MEDCALC::IntegrationDirType integrDir)
182 _params.integrDir = integrDir;
185 setIntProperty(MEDPresentationStreamLines::PROP_INTEGR_DIR_TYPE, integrDir);
187 // Update the pipeline:
189 MEDPyLockWrapper lock;
190 std::ostringstream oss;
191 std::string dirType = getIntegrDirType();
192 oss << _objVar << ".IntegrationDirection = '" << dirType << "'";
193 pushAndExecPyLine(oss.str()); oss.str("");
194 pushAndExecPyLine("pvs.Render();");
199 MEDPresentationStreamLines::initFieldMeshInfos()
201 MEDPresentation::initFieldMeshInfos();
202 _colorByType = "POINTS";
205 std::string MEDPresentationStreamLines::additionalThresholdInitializationActions() {
206 if (_hideDataOutsideCustomRange) {
207 std::ostringstream oss;
208 ComponentThresold& currentThreshold = _presentationThresolds[getThresholdIndex()];
209 oss << currentThreshold._thresholdVar << ".AllScalars = 0;";
215 std::string MEDPresentationStreamLines::getFieldName() const {
216 std::ostringstream oss;
218 if (_nbComponents == 2) {
225 MEDPresentationStreamLines::scalarBarTitle()
227 if (_nbComponents == 2 && !_hideDataOutsideCustomRange) {
228 std::ostringstream oss;
229 oss << "pvs.GetScalarBar(" << getLutVar() << ").Title = '" << _fieldName << "';";
230 pushAndExecPyLine(oss.str());
232 MEDPresentation::scalarBarTitle();