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 "MEDPresentationScalarMap.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 MEDPresentationScalarMap::TYPE_NAME = "MEDPresentationScalarMap";
33 MEDPresentationScalarMap::MEDPresentationScalarMap(const MEDCALC::ScalarMapParameters& params,
34 const MEDCALC::MEDPresentationViewMode viewMode) :
35 MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), _params(params)
40 MEDPresentationScalarMap::internalGeneratePipeline()
42 MEDPresentation::internalGeneratePipeline();
44 MEDPyLockWrapper lock;
46 std::ostringstream oss_o, oss_d,oss_l, oss, oss_v;
47 oss_o << "__obj" << _objId; std::string obj(oss_o.str());
48 oss_d << "__disp" << _dispId; std::string disp(oss_d.str());
49 oss_l << "__lut" << _lutId; std::string lut(oss_l.str());
50 oss_v << "__view" << _renderViewPyId; std::string view(oss_v.str());
52 pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX
54 oss << obj << " = pvs.MEDReader(FileName='" << _fileName << "');";
55 pushAndExecPyLine(oss.str()); oss.str("");
57 // Populate internal array of available components:
58 fillAvailableFieldComponents();
59 // dumpIntProperties();
60 // dumpStringProperties();
62 oss << disp << " = pvs.Show(" << obj << ", " << view << ");";
63 pushAndExecPyLine(oss.str()); oss.str("");
64 oss << "pvs.ColorBy(" << disp << ", ('" << _fieldType << "', '" << _fieldName << "'));";
65 pushAndExecPyLine(oss.str()); oss.str("");
66 oss << disp << ".SetScalarBarVisibility(" << view << ", True);";
67 pushAndExecPyLine(oss.str()); oss.str("");
68 oss << getRescaleCommand();
69 pushAndExecPyLine(oss.str()); oss.str("");
70 oss << lut << " = pvs.GetColorTransferFunction('" << _fieldName << "');";
71 pushAndExecPyLine(oss.str()); oss.str("");
72 pushAndExecPyLine(getColorMapCommand()); oss.str("");
73 pushAndExecPyLine(getResetCameraCommand());
74 pushAndExecPyLine("pvs.Render();");
76 // Retrieve Python object for internal storage:
77 // PyObject* p_obj = getPythonObjectFromMain(obj.c_str());
78 // PyObject* p_disp = getPythonObjectFromMain(disp.c_str());
79 // pushPyObjects(std::make_pair(_objId, p_obj), std::make_pair(disp_id, p_disp));
83 MEDPresentationScalarMap::updatePipeline(const MEDCALC::ScalarMapParameters& params)
85 if (params.fieldHandlerId != _params.fieldHandlerId)
86 throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
88 if (params.displayedComponent != _params.displayedComponent)
89 updateComponent<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(std::string(params.displayedComponent));
90 if (params.scalarBarRange != _params.scalarBarRange)
91 updateScalarBarRange<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(params.scalarBarRange);
92 if (params.colorMap != _params.colorMap)
93 updateColorMap<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(params.colorMap);