Salome HOME
[MEDCalc] avoiding use of PyLockWrapper in MED component ...
[modules/med.git] / src / MEDCalc / cmp / MEDPresentationScalarMap.cxx
1 // Copyright (C) 2016  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "MEDPyLockWrapper.hxx"
21
22 #include "MEDPresentationScalarMap.hxx"
23 #include "MEDPresentationException.hxx"
24
25 #include <SALOME_KernelServices.hxx>
26 #undef LOG  // should be fixed in KERNEL - double definition
27 #include <Basics_Utils.hxx>
28
29 #include <sstream>
30
31 const std::string MEDPresentationScalarMap::TYPE_NAME = "MEDPresentationScalarMap";
32
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)
36 {
37 }
38
39 void
40 MEDPresentationScalarMap::internalGeneratePipeline()
41 {
42   MEDPresentation::internalGeneratePipeline();
43
44   MEDPyLockWrapper lock;
45
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());
51
52   pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX
53
54   oss << obj << " = pvs.MEDReader(FileName='" << _fileName << "');";
55   pushAndExecPyLine(oss.str()); oss.str("");
56
57   // Populate internal array of available components:
58   fillAvailableFieldComponents();
59 //  dumpIntProperties();
60 //  dumpStringProperties();
61
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();");
75
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));
80 }
81
82 void
83 MEDPresentationScalarMap::updatePipeline(const MEDCALC::ScalarMapParameters& params)
84 {
85   if (params.fieldHandlerId != _params.fieldHandlerId)
86     throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
87
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);
94 }
95