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::ViewModeType 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);
40 int id = GeneratePythonId();
41 std::ostringstream oss;
42 oss << "__objLst" << id;
43 _sliceListVar = oss.str();
47 MEDPresentationSlices::setSliceParametersAndGroup()
49 std::ostringstream oss;
50 int nbSlices = getIntProperty(MEDPresentationSlices::PROP_NB_SLICES);
51 std::string normal = getNormalVector();
53 oss << "__origins = medcalc.GetSliceOrigins(" << _srcObjVar << ", " << nbSlices << ", " << normal << ");";
54 pushAndExecPyLine(oss.str()); oss.str("");
56 oss << "for sliceNum in range(" << nbSlices << "):\n";
57 oss << " " << _sliceListVar << "[sliceNum].SliceType.Normal = " << normal << ";\n";
58 oss << " " << _sliceListVar << "[sliceNum].SliceType.Origin = __origins[sliceNum];\n";
59 pushAndExecPyLine(oss.str()); oss.str("");
61 oss << _objVar << " = pvs.GroupDatasets(Input=" << _sliceListVar << ");";
62 pushAndExecPyLine(oss.str()); oss.str("");
66 MEDPresentationSlices::deleteGroup()
68 std::ostringstream oss;
69 oss << "pvs.Delete(" << _objVar << ");";
70 pushAndExecPyLine(oss.str()); oss.str("");
74 MEDPresentationSlices::adaptNumberOfSlices()
76 std::ostringstream oss;
77 int nbSlices = getIntProperty(MEDPresentationSlices::PROP_NB_SLICES);
79 oss << "for _ in range(max(len(" << _sliceListVar << ")-" << nbSlices << ", 0)):\n";
80 oss << " pvs.Delete(" << _sliceListVar << ".pop());\n";
81 pushAndExecPyLine(oss.str()); oss.str("");
83 oss << "for _ in range(" << nbSlices << "-max(len(" << _sliceListVar << "), 0)):\n";
84 oss << " obj = pvs.Slice(Input=" << _srcObjVar << ");\n";
85 oss << " obj.SliceType = 'Plane';\n";
86 oss << " " << _sliceListVar << ".append(obj);\n";
87 pushAndExecPyLine(oss.str()); oss.str("");
91 MEDPresentationSlices::generateAndDisplay()
93 adaptNumberOfSlices();
94 setSliceParametersAndGroup();
98 colorBy(_pvFieldType);
101 rescaleTransferFunction();
102 resetCameraAndRender();
106 MEDPresentationSlices::getNormalVector() const
108 switch(_params.orientation)
110 case MEDCALC::SLICE_NORMAL_TO_X:
111 return "[1.0, 0.0, 0.0]";
112 case MEDCALC::SLICE_NORMAL_TO_Y:
113 return "[0.0, 1.0, 0.0]";
114 case MEDCALC::SLICE_NORMAL_TO_Z:
115 return "[0.0, 0.0, 1.0]";
116 case MEDCALC::SLICE_NORMAL_TO_XY:
117 return "[1.0, 1.0, 0.0]";
118 case MEDCALC::SLICE_NORMAL_TO_XZ:
119 return "[1.0, 0.0, 1.0]";
120 case MEDCALC::SLICE_NORMAL_TO_YZ:
121 return "[0.0, 1.0, 1.0]";
122 case MEDCALC::SLICE_NORMAL_TO_XYZ:
123 return "[1.0, 1.0, 1.0]";
125 const char * mes = "Unexpected getSliceOrientationCommand() error!";
127 throw KERNEL::createSalomeException(mes);
129 return ""; // never happens
133 MEDPresentationSlices::selectSliceOrientation(const std::string & obj)
135 std::ostringstream oss1;
136 oss1 << obj << ".SliceType.Normal = " << getNormalVector() << ";";
137 pushAndExecPyLine(oss1.str()); oss1.str("");
141 MEDPresentationSlices::internalGeneratePipeline()
143 MEDPresentation::internalGeneratePipeline();
145 MEDPyLockWrapper lock;
147 std::ostringstream oss;
151 // Populate internal array of available components:
152 fillAvailableFieldComponents();
153 if (_params.nbSlices < 1)
155 const char * mes = "Invalid number of slices!";
157 throw KERNEL::createSalomeException(mes);
160 setOrCreateRenderView(); // instanciate __viewXXX
162 // Now create the initial slices list
163 oss << _sliceListVar << " = [];";
164 pushAndExecPyLine(oss.str()); oss.str("");
166 generateAndDisplay();
170 MEDPresentationSlices::updatePipeline(const MEDCALC::SlicesParameters& params)
172 if (params.fieldHandlerId != _params.fieldHandlerId)
173 throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
175 if (std::string(params.displayedComponent) != std::string(_params.displayedComponent))
176 updateComponent<MEDPresentationSlices, MEDCALC::SlicesParameters>(std::string(params.displayedComponent));
177 if (params.scalarBarRange != _params.scalarBarRange)
178 updateScalarBarRange<MEDPresentationSlices, MEDCALC::SlicesParameters>(params.scalarBarRange);
179 if (params.colorMap != _params.colorMap)
180 updateColorMap<MEDPresentationSlices, MEDCALC::SlicesParameters>(params.colorMap);
182 if (params.orientation != _params.orientation)
183 updateOrientation(params.orientation);
184 if (params.nbSlices != _params.nbSlices)
186 if (params.nbSlices < 1)
188 const char * mes = "Invalid number of slices!";
190 throw KERNEL::createSalomeException(mes);
192 updateNbSlices(params.nbSlices);
197 MEDPresentationSlices::updateNbSlices(const int nbSlices)
199 _params.nbSlices = nbSlices;
202 setIntProperty(MEDPresentationSlices::PROP_NB_SLICES, nbSlices);
204 // Update the pipeline:
206 MEDPyLockWrapper lock;
208 generateAndDisplay();
213 MEDPresentationSlices::updateOrientation(const MEDCALC::SliceOrientationType orientation)
215 _params.orientation = orientation;
218 setIntProperty(MEDPresentationSlices::PROP_SLICE_ORIENTATION, static_cast<int>(orientation));
220 // Update the pipeline:
222 MEDPyLockWrapper lock;
225 generateAndDisplay();