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 "MEDPresentationContour.hxx"
22 #include <SALOME_KernelServices.hxx>
23 #undef LOG // should be fixed in KERNEL - double definition
24 #include <Basics_Utils.hxx>
28 const std::string MEDPresentationContour::TYPE_NAME = "MEDPresentationContour";
29 const std::string MEDPresentationContour::PROP_NB_CONTOUR = "nbContour";
31 MEDPresentationContour::MEDPresentationContour(const MEDCALC::ContourParameters& params,
32 const MEDCALC::ViewModeType viewMode) :
33 MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange),
36 setIntProperty(MEDPresentationContour::PROP_NB_CONTOUR, params.nbContours);
40 MEDPresentationContour::getContourCommand() const
42 std::ostringstream oss1;
44 oss1 << "min_max = " << _srcObjVar << ".PointData.GetArray('" << _fieldName << "').GetRange();\n";
45 oss1 << "delta = (min_max[1]-min_max[0])/float(" << _params.nbContours << ");\n";
46 oss1 << _objVar << ".Isosurfaces = [min_max[0]+0.5*delta+i*delta for i in range(" << _params.nbContours << ")];\n";
51 MEDPresentationContour::internalGeneratePipeline()
53 MEDPresentation::internalGeneratePipeline();
55 MEDPyLockWrapper lock;
57 std::ostringstream oss_o, oss;
58 std::string view(getRenderViewVar());
60 oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');";
61 pushAndExecPyLine(oss.str()); oss.str("");
63 // Populate internal array of available components:
64 fillAvailableFieldComponents();
65 if (getIntProperty(MEDPresentation::PROP_NB_COMPONENTS) > 1)
67 const char * msg = "Contour presentation only works for scalar field!"; // this message will appear in GUI too
69 throw KERNEL::createSalomeException(msg);
72 pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX
74 if(_fieldType == "CELLS")
76 // In case of a CELLS field need to convert to POINT field, and update source
77 STDLOG("Applying CellDatatoPointData filter");
78 std::ostringstream oss2, oss4;
79 // Apply Cell data to point data:
80 oss2 << "__obj" << GeneratePythonId();
81 oss << oss2.str() << " = pvs.CellDatatoPointData(Input=" << _srcObjVar << ");";
82 pushAndExecPyLine(oss.str()); oss.str("");
83 // Now the source becomes the result of the CellDatatoPointData:
84 _srcObjVar = oss2.str();
86 oss << _objVar << " = pvs.Contour(Input=" << _srcObjVar << ");";
87 pushAndExecPyLine(oss.str()); oss.str("");
88 oss << _objVar << ".ContourBy = ['POINTS', '" << _fieldName << "'];";
89 pushAndExecPyLine(oss.str()); oss.str("");
91 // Set number of contours
92 pushAndExecPyLine(getContourCommand());
94 oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");";
95 pushAndExecPyLine(oss.str()); oss.str("");
96 oss << "pvs.ColorBy(" << _dispVar << ", ('POINTS', '" << _fieldName << "'));"; // necessarily POINTS
97 pushAndExecPyLine(oss.str()); oss.str("");
98 oss << _dispVar << ".SetScalarBarVisibility(" << view << ", True);";
99 pushAndExecPyLine(oss.str()); oss.str("");
100 oss << getRescaleCommand();
101 pushAndExecPyLine(oss.str()); oss.str("");
102 oss << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');";
103 pushAndExecPyLine(oss.str()); oss.str("");
104 pushAndExecPyLine(getColorMapCommand()); oss.str("");
105 pushAndExecPyLine(getResetCameraCommand());
106 pushAndExecPyLine("pvs.Render();");
110 MEDPresentationContour::updatePipeline(const MEDCALC::ContourParameters& params)
112 if (params.fieldHandlerId != _params.fieldHandlerId)
113 throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
115 if (params.scalarBarRange != _params.scalarBarRange)
116 updateScalarBarRange<MEDPresentationContour, MEDCALC::ContourParameters>(params.scalarBarRange);
117 if (params.colorMap != _params.colorMap)
118 updateColorMap<MEDPresentationContour, MEDCALC::ContourParameters>(params.colorMap);
120 if (params.nbContours != _params.nbContours)
121 updateNbContours(params.nbContours);
125 MEDPresentationContour::updateNbContours(const int nbContours)
127 _params.nbContours = nbContours;
130 setIntProperty(MEDPresentationContour::PROP_NB_CONTOUR, nbContours);
132 // Update the pipeline:
134 MEDPyLockWrapper lock;
135 std::string cmd = getContourCommand();
136 pushAndExecPyLine(cmd);
137 pushAndExecPyLine("pvs.Render();");