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 "MEDPresentationDeflectionShape.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 MEDPresentationDeflectionShape::TYPE_NAME = "MEDPresentationDeflectionShape";
33 MEDPresentationDeflectionShape::MEDPresentationDeflectionShape(const MEDCALC::DeflectionShapeParameters& params,
34 const MEDCALC::ViewModeType viewMode) :
35 MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), _params(params)
40 MEDPresentationDeflectionShape::initFieldMeshInfos()
42 MEDPresentation::initFieldMeshInfos();
43 _colorByType = "POINTS";
47 MEDPresentationDeflectionShape::autoScale()
49 std::ostringstream oss;
50 oss << "import medcalc;";
51 pushAndExecPyLine(oss.str()); oss.str("");
52 oss << _objVar << ".ScaleFactor = 3.0*medcalc.ComputeCellAverageSize(" << _srcObjVar << ")/(" << _rangeVar
53 << "[1]-" << _rangeVar << "[0]);";
54 pushAndExecPyLine(oss.str()); oss.str("");
58 MEDPresentationDeflectionShape::internalGeneratePipeline()
60 MEDPresentation::internalGeneratePipeline();
62 MEDPyLockWrapper lock;
67 // Populate internal array of available components:
68 fillAvailableFieldComponents();
69 int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS);
72 const char * msg = "Deflection shape presentation does not work for scalar field!"; // this message will appear in GUI too
74 throw KERNEL::createSalomeException(msg);
77 setOrCreateRenderView(); // needs to be after the exception above otherwise previous elements in the view will be hidden.
79 // Warp needs point data:
80 applyCellToPointIfNeeded();
82 std::ostringstream oss;
83 oss << _objVar << " = pvs.WarpByVector(Input=" << _srcObjVar << ");";
84 pushAndExecPyLine(oss.str()); oss.str("");
86 showObject(); // to be done first so that the scale factor computation properly works
88 std::string fieldName = nbCompo <= 2 ? _fieldName + "_Vector" : _fieldName;
89 oss << _objVar << ".Vectors = ['POINTS', '" << fieldName << "'];";
90 pushAndExecPyLine(oss.str()); oss.str("");
92 colorBy(); // see initFieldInfo() - necessarily POINTS
95 rescaleTransferFunction();
97 autoScale(); // to be called after transfer function so we have the range
99 resetCameraAndRender();
103 MEDPresentationDeflectionShape::updatePipeline(const MEDCALC::DeflectionShapeParameters& params)
105 if (params.fieldHandlerId != _params.fieldHandlerId)
106 throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
108 if (params.scalarBarRange != _params.scalarBarRange ||
109 params.hideDataOutsideCustomRange != _params.hideDataOutsideCustomRange ||
110 params.scalarBarRangeArray[0] != _params.scalarBarRangeArray[0] ||
111 params.scalarBarRangeArray[1] != _params.scalarBarRangeArray[1])
113 updateScalarBarRange<MEDPresentationDeflectionShape, MEDCALC::DeflectionShapeParameters>(params.scalarBarRange,
114 params.hideDataOutsideCustomRange,
115 params.scalarBarRangeArray[0],
116 params.scalarBarRangeArray[1]);
118 pushAndExecPyLine("pvs.Render();");
120 if (params.colorMap != _params.colorMap)
121 updateColorMap<MEDPresentationDeflectionShape, MEDCALC::DeflectionShapeParameters>(params.colorMap);
123 if (params.visibility != _params.visibility)
124 updateVisibility<MEDPresentationDeflectionShape, MEDCALC::DeflectionShapeParameters>(params.visibility);
126 if (params.scalarBarVisibility != _params.scalarBarVisibility)
127 updateScalarBarVisibility<MEDPresentationDeflectionShape, MEDCALC::DeflectionShapeParameters>(params.scalarBarVisibility);