1 // Copyright (C) 2016 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 "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::autoScale()
42 std::ostringstream oss;
43 oss << "import medcalc;";
44 pushAndExecPyLine(oss.str()); oss.str("");
45 oss << _objVar << ".ScaleFactor = 3.0*medcalc.ComputeCellAverageSize(" << _srcObjVar << ")/(" << _rangeVar
46 << "[1]-" << _rangeVar << "[0]);";
47 pushAndExecPyLine(oss.str()); oss.str("");
51 MEDPresentationDeflectionShape::internalGeneratePipeline()
53 MEDPresentation::internalGeneratePipeline();
55 MEDPyLockWrapper lock;
57 setOrCreateRenderView();
60 // Populate internal array of available components:
61 fillAvailableFieldComponents();
62 if (getIntProperty(MEDPresentation::PROP_NB_COMPONENTS) <= 1)
64 const char * msg = "Deflection shape presentation does not work for scalar field!"; // this message will appear in GUI too
66 throw KERNEL::createSalomeException(msg);
69 // Warp needs point data:
70 applyCellToPointIfNeeded();
72 std::ostringstream oss;
73 oss << _objVar << " = pvs.WarpByVector(Input=" << _srcObjVar << ");";
74 pushAndExecPyLine(oss.str()); oss.str("");
76 showObject(); // to be done first so that the scale factor computation properly works
78 oss << _objVar << ".Vectors = ['POINTS', '" << _fieldName << "'];";
79 pushAndExecPyLine(oss.str()); oss.str("");
84 rescaleTransferFunction();
86 autoScale(); // to be called after transfer function so we have the range
88 resetCameraAndRender();
92 MEDPresentationDeflectionShape::updatePipeline(const MEDCALC::DeflectionShapeParameters& params)
94 if (params.fieldHandlerId != _params.fieldHandlerId)
95 throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
97 if (params.scalarBarRange != _params.scalarBarRange)
99 updateScalarBarRange<MEDPresentationDeflectionShape, MEDCALC::DeflectionShapeParameters>(params.scalarBarRange);
101 pushAndExecPyLine("pvs.Render();");
103 if (params.colorMap != _params.colorMap)
104 updateColorMap<MEDPresentationDeflectionShape, MEDCALC::DeflectionShapeParameters>(params.colorMap);