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);
42 MEDPresentationSlices::generateSlices()
44 std::ostringstream oss;
45 int nbSlices = getIntProperty(MEDPresentationSlices::PROP_NB_SLICES);
46 std::string normal = getNormalVector();
48 oss << "__origins = medcalc.GetSliceOrigins(" << _srcObjVar << ", " << nbSlices << ", " << normal << ");";
49 pushAndExecPyLine(oss.str()); oss.str("");
50 pushAndExecPyLine("__objLst = [];");
51 oss << "for sliceNum in range(" << nbSlices << "):\n";
52 oss << " obj = pvs.Slice(Input=" << _srcObjVar << ")\n";
53 oss << " obj.SliceType = 'Plane'\n";
54 oss << " obj.SliceType.Normal = " << normal << "\n";
55 oss << " obj.SliceType.Origin = __origins[sliceNum]\n";
56 oss << " __objLst.append(obj)\n\n";
57 pushAndExecPyLine(oss.str()); oss.str("");
59 oss << _objVar << " = pvs.GroupDatasets(Input=__objLst);";
60 pushAndExecPyLine(oss.str()); oss.str("");
64 MEDPresentationSlices::generateAndDisplay()
69 colorBy(_pvFieldType);
72 rescaleTransferFunction();
73 resetCameraAndRender();
78 MEDPresentationSlices::clearPreviousSlices()
80 std::ostringstream oss;
82 pushAndExecPyLine("for sliceNum, _ in enumerate(__objLst):\n pvs.Delete(__objLst[sliceNum]);");
83 oss << "pvs.Delete(" << _objVar << ");";
84 pushAndExecPyLine(oss.str()); oss.str("");
88 MEDPresentationSlices::getNormalVector() const
90 switch(_params.orientation)
92 case MEDCALC::SLICE_NORMAL_TO_X:
93 return "[1.0, 0.0, 0.0]";
94 case MEDCALC::SLICE_NORMAL_TO_Y:
95 return "[0.0, 1.0, 0.0]";
96 case MEDCALC::SLICE_NORMAL_TO_Z:
97 return "[0.0, 0.0, 1.0]";
98 case MEDCALC::SLICE_NORMAL_TO_XY:
99 return "[1.0, 1.0, 0.0]";
100 case MEDCALC::SLICE_NORMAL_TO_XZ:
101 return "[1.0, 0.0, 1.0]";
102 case MEDCALC::SLICE_NORMAL_TO_YZ:
103 return "[0.0, 1.0, 1.0]";
104 case MEDCALC::SLICE_NORMAL_TO_XYZ:
105 return "[1.0, 1.0, 1.0]";
107 const char * mes = "Unexpected getSliceOrientationCommand() error!";
109 throw KERNEL::createSalomeException(mes);
111 return ""; // never happens
115 MEDPresentationSlices::selectSliceOrientation(const std::string & obj)
117 std::ostringstream oss1;
118 oss1 << obj << ".SliceType.Normal = " << getNormalVector() << ";";
119 pushAndExecPyLine(oss1.str()); oss1.str("");
123 MEDPresentationSlices::internalGeneratePipeline()
125 MEDPresentation::internalGeneratePipeline();
127 MEDPyLockWrapper lock;
129 std::ostringstream oss_o, oss;
133 // Populate internal array of available components:
134 fillAvailableFieldComponents();
135 setOrCreateRenderView(); // instanciate __viewXXX
137 // Now create the initial number of slices
138 generateAndDisplay();
142 MEDPresentationSlices::updatePipeline(const MEDCALC::SlicesParameters& params)
144 if (params.fieldHandlerId != _params.fieldHandlerId)
145 throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
147 if (std::string(params.displayedComponent) != std::string(_params.displayedComponent))
148 updateComponent<MEDPresentationSlices, MEDCALC::SlicesParameters>(std::string(params.displayedComponent));
149 if (params.scalarBarRange != _params.scalarBarRange)
150 updateScalarBarRange<MEDPresentationSlices, MEDCALC::SlicesParameters>(params.scalarBarRange);
151 if (params.colorMap != _params.colorMap)
152 updateColorMap<MEDPresentationSlices, MEDCALC::SlicesParameters>(params.colorMap);
154 if (params.orientation != _params.orientation)
155 updateOrientation(params.orientation);
156 if (params.nbSlices != _params.nbSlices)
157 updateNbSlices(params.nbSlices);
161 MEDPresentationSlices::updateNbSlices(const int nbSlices)
163 _params.nbSlices = nbSlices;
166 setIntProperty(MEDPresentationSlices::PROP_NB_SLICES, nbSlices);
168 // Update the pipeline:
170 MEDPyLockWrapper lock;
171 clearPreviousSlices();
172 generateAndDisplay();
177 MEDPresentationSlices::updateOrientation(const MEDCALC::SliceOrientationType orientation)
179 _params.orientation = orientation;
182 setIntProperty(MEDPresentationSlices::PROP_SLICE_ORIENTATION, static_cast<int>(orientation));
184 // Update the pipeline:
186 MEDPyLockWrapper lock;
188 clearPreviousSlices();
189 generateAndDisplay();