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 "MEDPresentationSlices.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 MEDPresentationSlices::TYPE_NAME = "MEDPresentationSlices";
29 const std::string MEDPresentationSlices::PROP_NB_SLICES = "nbSlices";
30 const std::string MEDPresentationSlices::PROP_SLICE_ORIENTATION = "slicesOrientation";
32 MEDPresentationSlices::MEDPresentationSlices(const MEDCALC::SlicesParameters& params,
33 const MEDCALC::MEDPresentationViewMode viewMode) :
34 MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange),
37 setIntProperty(MEDPresentationSlices::PROP_NB_SLICES, params.nbSlices);
38 setIntProperty(MEDPresentationSlices::PROP_SLICE_ORIENTATION, params.orientation);
42 MEDPresentationSlices::getNbSlicesCommand() const
44 std::ostringstream oss1;
46 // oss1 << _objVar << ".SliceType.Normal = " << norm << ";";
51 MEDPresentationSlices::getOrientationCommand() const
53 std::ostringstream oss1;
56 switch(_params.orientation)
58 case MEDCALC::SLICE_NORMAL_TO_X:
59 norm = "[1.0, 0.0, 0.0]";
61 case MEDCALC::SLICE_NORMAL_TO_Y:
62 norm = "[0.0, 1.0, 0.0]";
64 case MEDCALC::SLICE_NORMAL_TO_Z:
65 norm = "[0.0, 0.0, 1.0]";
67 case MEDCALC::SLICE_NORMAL_TO_XY:
68 norm = "[1.0, 1.0, 0.0]";
70 case MEDCALC::SLICE_NORMAL_TO_XZ:
71 norm = "[1.0, 0.0, 1.0]";
73 case MEDCALC::SLICE_NORMAL_TO_YZ:
74 norm = "[0.0, 1.0, 1.0]";
76 case MEDCALC::SLICE_NORMAL_TO_XYZ:
77 norm = "[1.0, 1.0, 1.0]";
80 const char * mes = "Unexpected getSliceOrientationCommand() error!";
82 throw KERNEL::createSalomeException(mes);
85 oss1 << _objVar << ".SliceType.Normal = " << norm << ";";
91 MEDPresentationSlices::internalGeneratePipeline()
93 MEDPresentation::internalGeneratePipeline();
95 MEDPyLockWrapper lock;
97 std::ostringstream oss_o, oss;
98 std::string view(getRenderViewVar());
100 oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');";
101 pushAndExecPyLine(oss.str()); oss.str("");
103 // Populate internal array of available components:
104 fillAvailableFieldComponents();
105 pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX
106 oss << _objVar << " = pvs.Slice(Input=" << _srcObjVar << ");";
107 pushAndExecPyLine(oss.str()); oss.str("");
108 oss << _objVar << ".SliceType = 'Plane';";
109 pushAndExecPyLine(oss.str()); oss.str("");
111 // Set slice orientation
112 pushAndExecPyLine(getOrientationCommand());
114 oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");";
115 pushAndExecPyLine(oss.str()); oss.str("");
116 oss << "pvs.ColorBy(" << _dispVar << ", ('" << _fieldType << "', '" << _fieldName << "'));";
117 pushAndExecPyLine(oss.str()); oss.str("");
118 oss << _dispVar << ".SetScalarBarVisibility(" << view << ", True);";
119 pushAndExecPyLine(oss.str()); oss.str("");
120 oss << getRescaleCommand();
121 pushAndExecPyLine(oss.str()); oss.str("");
122 oss << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');";
123 pushAndExecPyLine(oss.str()); oss.str("");
124 pushAndExecPyLine(getColorMapCommand()); oss.str("");
125 pushAndExecPyLine(getResetCameraCommand());
126 pushAndExecPyLine("pvs.Render();");
130 MEDPresentationSlices::updatePipeline(const MEDCALC::SlicesParameters& params)
132 if (params.fieldHandlerId != _params.fieldHandlerId)
133 throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
135 if (std::string(params.displayedComponent) != std::string(_params.displayedComponent))
136 updateComponent<MEDPresentationSlices, MEDCALC::SlicesParameters>(std::string(params.displayedComponent));
137 if (params.scalarBarRange != _params.scalarBarRange)
138 updateScalarBarRange<MEDPresentationSlices, MEDCALC::SlicesParameters>(params.scalarBarRange);
139 if (params.colorMap != _params.colorMap)
140 updateColorMap<MEDPresentationSlices, MEDCALC::SlicesParameters>(params.colorMap);
142 if (params.orientation != _params.orientation)
143 updateOrientation(params.orientation);
144 if (params.nbSlices != _params.nbSlices)
145 updateNbSlices(params.nbSlices);
149 MEDPresentationSlices::updateNbSlices(const int nbSlices)
151 _params.nbSlices = nbSlices;
154 setIntProperty(MEDPresentationSlices::PROP_NB_SLICES, nbSlices);
156 // Update the pipeline:
158 MEDPyLockWrapper lock;
159 std::string cmd = getNbSlicesCommand();
160 pushAndExecPyLine(cmd);
161 pushAndExecPyLine("pvs.Render();");
166 MEDPresentationSlices::updateOrientation(const MEDCALC::MEDPresentationSliceOrientation orientation)
168 _params.orientation = orientation;
171 setIntProperty(MEDPresentationSlices::PROP_SLICE_ORIENTATION, orientation);
173 // Update the pipeline:
175 MEDPyLockWrapper lock;
176 std::string cmd = getOrientationCommand();
177 pushAndExecPyLine(cmd);
178 pushAndExecPyLine("pvs.Render();");