Salome HOME
[MEDCalc] Fully functional scalar map (other pres deactivated)
[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 "MEDPresentationScalarMap.hxx"
21 #include "MEDPresentationException.hxx"
22
23 #include <PyInterp_Utils.h>
24 #include <SALOME_KernelServices.hxx>
25 #undef LOG  // should be fixed in KERNEL - double definition
26 #include <Basics_Utils.hxx>
27
28 #include <sstream>
29
30 const std::string MEDPresentationScalarMap::TYPE_NAME = "MEDPresentationScalarMap";
31
32 MEDPresentationScalarMap::MEDPresentationScalarMap(const MEDCALC::ScalarMapParameters& params,
33                                                    const MEDCALC::MEDPresentationViewMode viewMode) :
34     MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap), _params(params)
35 {
36 }
37
38 void
39 MEDPresentationScalarMap::internalGeneratePipeline()
40 {
41   PyLockWrapper lock;
42
43   std::ostringstream oss_o, oss_d,oss_l, oss, oss_v;
44   oss_o << "__obj" << _objId;      std::string obj(oss_o.str());
45   oss_d << "__disp" << _dispId;    std::string disp(oss_d.str());
46   oss_l << "__lut" << _lutId;    std::string lut(oss_l.str());
47
48   pushAndExecPyLine( "import pvsimple as pvs;");
49   pushAndExecPyLine( getRenderViewCommand() ); // define __viewXXX
50
51   oss_v << "__view" << _renderViewPyId;    std::string view(oss_v.str());
52
53   oss << obj << " = pvs.MEDReader(FileName='" << _fileName << "');";
54   pushAndExecPyLine(oss.str()); oss.str("");
55
56   // Populate internal array of available components:
57   fillAvailableFieldComponents();
58 //  dumpIntProperties();
59 //  dumpStringProperties();
60
61   oss << disp << " = pvs.Show(" << obj << ", " << view << ");";
62   pushAndExecPyLine(oss.str()); oss.str("");
63   oss << "pvs.ColorBy(" << disp << ", ('" << _fieldType << "', '" << _fieldName << "'));";
64   pushAndExecPyLine(oss.str()); oss.str("");
65   oss << disp <<  ".SetScalarBarVisibility(" << view << ", True);";
66   pushAndExecPyLine(oss.str()); oss.str("");
67   oss << getRescaleCommand();
68   pushAndExecPyLine(oss.str()); oss.str("");
69   oss << lut << " = pvs.GetColorTransferFunction('" << _fieldName << "');";
70   pushAndExecPyLine(oss.str()); oss.str("");
71   pushAndExecPyLine(getColorMapCommand()); oss.str("");
72   pushAndExecPyLine(getResetCameraCommand());
73   pushAndExecPyLine("pvs.Render();");
74
75   // Retrieve Python object for internal storage:
76 //  PyObject* p_obj = getPythonObjectFromMain(obj.c_str());
77 //  PyObject* p_disp = getPythonObjectFromMain(disp.c_str());
78 //  pushPyObjects(std::make_pair(_objId, p_obj), std::make_pair(disp_id, p_disp));
79 }
80
81 void
82 MEDPresentationScalarMap::updatePipeline(const MEDCALC::ScalarMapParameters& params)
83 {
84   if (params.fieldHandlerId != _params.fieldHandlerId)
85     throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
86
87   if (params.displayedComponent != _params.displayedComponent)
88     updateComponent<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(std::string(params.displayedComponent));
89   if (params.scalarBarRange != _params.scalarBarRange)
90     updateScalarBarRange<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(params.scalarBarRange);
91   if (params.colorMap != _params.colorMap)
92     updateColorMap<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(params.colorMap);
93 }
94