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();
100 MEDPresentationSlices::getNormalVector() const
102 switch(_params.orientation)
104 case MEDCALC::SLICE_NORMAL_TO_X:
105 return "[1.0, 0.0, 0.0]";
106 case MEDCALC::SLICE_NORMAL_TO_Y:
107 return "[0.0, 1.0, 0.0]";
108 case MEDCALC::SLICE_NORMAL_TO_Z:
109 return "[0.0, 0.0, 1.0]";
110 case MEDCALC::SLICE_NORMAL_TO_XY:
111 return "[1.0, 1.0, 0.0]";
112 case MEDCALC::SLICE_NORMAL_TO_XZ:
113 return "[1.0, 0.0, 1.0]";
114 case MEDCALC::SLICE_NORMAL_TO_YZ:
115 return "[0.0, 1.0, 1.0]";
116 case MEDCALC::SLICE_NORMAL_TO_XYZ:
117 return "[1.0, 1.0, 1.0]";
119 const char * mes = "Unexpected getSliceOrientationCommand() error!";
121 throw KERNEL::createSalomeException(mes);
123 return ""; // never happens
127 MEDPresentationSlices::selectSliceOrientation(const std::string & obj)
129 std::ostringstream oss1;
130 oss1 << obj << ".SliceType.Normal = " << getNormalVector() << ";";
131 pushAndExecPyLine(oss1.str()); oss1.str("");
135 MEDPresentationSlices::internalGeneratePipeline()
137 MEDPresentation::internalGeneratePipeline();
139 MEDPyLockWrapper lock;
141 std::ostringstream oss;
145 // Populate internal array of available components:
146 fillAvailableFieldComponents();
147 if (_params.nbSlices < 1)
149 const char * mes = "Invalid number of slices!";
151 throw KERNEL::createSalomeException(mes);
154 setOrCreateRenderView(); // instanciate __viewXXX
156 // Now create the initial slices list
157 oss << _sliceListVar << " = [];";
158 pushAndExecPyLine(oss.str()); oss.str("");
160 generateAndDisplay();
164 MEDPresentationSlices::updatePipeline(const MEDCALC::SlicesParameters& params)
166 if (params.fieldHandlerId != _params.fieldHandlerId)
167 throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
169 if (std::string(params.displayedComponent) != std::string(_params.displayedComponent))
170 updateComponent<MEDPresentationSlices, MEDCALC::SlicesParameters>(std::string(params.displayedComponent));
171 if (params.scalarBarRange != _params.scalarBarRange)
172 updateScalarBarRange<MEDPresentationSlices, MEDCALC::SlicesParameters>(params.scalarBarRange);
173 if (params.colorMap != _params.colorMap)
174 updateColorMap<MEDPresentationSlices, MEDCALC::SlicesParameters>(params.colorMap);
176 if (params.orientation != _params.orientation)
177 updateOrientation(params.orientation);
178 if (params.nbSlices != _params.nbSlices)
180 if (params.nbSlices < 1)
182 const char * mes = "Invalid number of slices!";
184 throw KERNEL::createSalomeException(mes);
186 updateNbSlices(params.nbSlices);
191 MEDPresentationSlices::updateNbSlices(const int nbSlices)
193 _params.nbSlices = nbSlices;
196 setIntProperty(MEDPresentationSlices::PROP_NB_SLICES, nbSlices);
198 // Update the pipeline:
200 MEDPyLockWrapper lock;
202 generateAndDisplay();
207 MEDPresentationSlices::updateOrientation(const MEDCALC::SliceOrientationType orientation)
209 _params.orientation = orientation;
212 setIntProperty(MEDPresentationSlices::PROP_SLICE_ORIENTATION, static_cast<int>(orientation));
214 // Update the pipeline:
216 MEDPyLockWrapper lock;
219 generateAndDisplay();