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 "WidgetPresentationParameters.hxx"
21 #include <Basics_Utils.hxx>
25 WidgetPresentationParameters::WidgetPresentationParameters(QWidget* parent)
26 : QWidget(parent), _blockSig(false)
28 _ui.setupUi(this); // To be done first
31 QObject::connect(_ui.comboBoxCompo, SIGNAL(currentIndexChanged(int)),
32 this, SLOT(onComboCompoIndexChanged(int)) );
33 QObject::connect(_ui.comboBoxMesh, SIGNAL(currentIndexChanged(int)),
34 this, SLOT(onComboMeshIndexChanged(int)) );
35 QObject::connect(_ui.comboBoxScalarBarRange, SIGNAL(currentIndexChanged(int)),
36 this, SLOT(onComboScalarBarRangeIndexChanged(int)) );
37 QObject::connect(_ui.comboBoxColorMap, SIGNAL(currentIndexChanged(int)),
38 this, SLOT(onComboColorMapIndexChanged(int)) );
39 QObject::connect(_ui.comboBoxSliceOrient, SIGNAL(currentIndexChanged(int)),
40 this, SLOT(onComboOrientIndexChanged(int)) );
41 QObject::connect(_ui.spinBox, SIGNAL(valueChanged(int)),
42 this, SLOT(onSpinBoxValueChanged(int)) );
46 WidgetPresentationParameters::onComboCompoIndexChanged(int idx)
48 if (!_blockSig) emit comboCompoIndexChanged(idx);
52 WidgetPresentationParameters::onComboOrientIndexChanged(int idx)
54 if (!_blockSig) emit comboOrientIndexChanged(idx);
59 WidgetPresentationParameters::onComboMeshIndexChanged(int idx)
61 if (!_blockSig) emit comboMeshIndexChanged(idx);
65 WidgetPresentationParameters::onComboColorMapIndexChanged(int idx)
67 if (!_blockSig) emit comboColorMapIndexChanged(idx);
71 WidgetPresentationParameters::onComboScalarBarRangeIndexChanged(int idx)
73 if (!_blockSig) emit comboScalarBarRangeIndexChanged(idx);
77 WidgetPresentationParameters::onSpinBoxValueChanged(int val)
79 if (!_blockSig) emit spinBoxValueChanged(val);
83 WidgetPresentationParameters::toggleCommonFieldWidget(bool show)
86 _ui.commonWidget->setEnabled(show);
91 WidgetPresentationParameters::toggleWidget(bool show)
95 toggleCommonFieldWidget(true);
98 _ui.widgetDynamic->hide();
99 setPresName("Choose a presentation");
100 // reset colorMap and scalarBarRange:
101 setColorMap(MEDCALC::COLOR_MAP_DEFAULT);
102 setScalarBarRange(MEDCALC::SCALAR_BAR_RANGE_DEFAULT);
106 _ui.widgetDynamic->show();
107 // It is the WidgetHelper responsability to re-show the widgets it needs
108 _ui.labelCompo->hide();
109 _ui.comboBoxCompo->hide();
110 _ui.labelMeshMode->hide();
111 _ui.comboBoxMesh->hide();
112 _ui.labelSpinBox->hide();
114 _ui.labelSliceOrient->hide();
115 _ui.comboBoxSliceOrient->hide();
121 WidgetPresentationParameters::isShown() const
123 return _ui.widgetDynamic->isVisible();
127 WidgetPresentationParameters::getComponent() const
129 if (_ui.comboBoxCompo->currentIndex() == 0) // Euclidean norm
132 return _ui.comboBoxCompo->currentText().toStdString();
136 WidgetPresentationParameters::setComponents(vector<string> compos, int selecIndex)
139 _ui.labelCompo->show();
140 _ui.comboBoxCompo->show();
143 _ui.comboBoxCompo->clear();
144 _ui.comboBoxCompo->addItem(tr("LAB_EUCLIDEAN_NORM"));
145 for(vector<string>::const_iterator it = compos.begin(); it != compos.end(); ++it)
146 _ui.comboBoxCompo->addItem(QString::fromStdString(*it));
147 _ui.comboBoxCompo->setCurrentIndex(selecIndex);
152 WidgetPresentationParameters::setNbContour(int nbContour)
157 STDLOG("WidgetPresentationParameters::setNbContour(): invalid number of contours!");
161 _ui.labelSpinBox->setText(tr("LAB_NB_CONTOURS"));
162 _ui.labelSpinBox->show();
166 _ui.spinBox->setValue(nbContour);
171 WidgetPresentationParameters::setNbSlices(int nbSlices)
176 STDLOG("WidgetPresentationParameters::setNbSlices(): invalid number of slices!");
180 _ui.labelSpinBox->setText(tr("LAB_NB_SLICES"));
181 _ui.labelSpinBox->show();
185 _ui.spinBox->setValue(nbSlices);
189 int WidgetPresentationParameters::getNbContour() const
191 return _ui.spinBox->value();
194 int WidgetPresentationParameters::getNbSlices() const
196 return _ui.spinBox->value();
201 WidgetPresentationParameters::setScalarBarRange(MEDCALC::MEDPresentationScalarBarRange sbrange)
204 if (sbrange == MEDCALC::SCALAR_BAR_ALL_TIMESTEPS)
205 idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_ALL_TIMESTEPS"));
206 else if (sbrange == MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP)
207 idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_CURRENT_TIMESTEP"));
212 _ui.comboBoxScalarBarRange->setCurrentIndex(idx);
216 STDLOG("Strange!! No matching found - unable to set scalar bar range in GUI.");
220 WidgetPresentationParameters::setColorMap(MEDCALC::MEDPresentationColorMap colorMap)
223 if (colorMap == MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW)
224 idx = _ui.comboBoxColorMap->findText(tr("LAB_BLUE_TO_RED"));
225 else if (colorMap == MEDCALC::COLOR_MAP_COOL_TO_WARM)
226 idx = _ui.comboBoxColorMap->findText(tr("LAB_COOL_TO_WARM"));
231 _ui.comboBoxColorMap->setCurrentIndex(idx);
236 STDLOG("Strange!! No matching found - unable to set color map in GUI.");
240 WidgetPresentationParameters::setMeshMode(MEDCALC::MEDPresentationMeshMode mode)
243 _ui.labelMeshMode->show();
244 _ui.comboBoxMesh->show();
249 case MEDCALC::MESH_MODE_WIREFRAME:
250 idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_WIREFRAME"));
252 case MEDCALC::MESH_MODE_SURFACE:
253 idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_SURFACE"));
255 case MEDCALC::MESH_MODE_SURFACE_EDGES:
256 idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_SURF_EDGES"));
264 _ui.comboBoxMesh->setCurrentIndex(idx);
268 STDLOG("Strange!! No matching found - unable to set mesh mode in GUI.");
272 WidgetPresentationParameters::setSliceOrientation(MEDCALC::MEDPresentationSliceOrientation orient)
275 _ui.labelSliceOrient->show();
276 _ui.comboBoxSliceOrient->show();
281 case MEDCALC::SLICE_NORMAL_TO_X:
282 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_X"));
284 case MEDCALC::SLICE_NORMAL_TO_Y:
285 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_Y"));
287 case MEDCALC::SLICE_NORMAL_TO_Z:
288 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_Z"));
290 case MEDCALC::SLICE_NORMAL_TO_XY:
291 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XY"));
293 case MEDCALC::SLICE_NORMAL_TO_XZ:
294 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XZ"));
296 case MEDCALC::SLICE_NORMAL_TO_YZ:
297 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_YZ"));
299 case MEDCALC::SLICE_NORMAL_TO_XYZ:
300 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XYZ"));
308 _ui.comboBoxSliceOrient->setCurrentIndex(idx);
312 STDLOG("Strange!! No matching found - unable to set slice orientation in GUI.");
316 MEDCALC::MEDPresentationSliceOrientation
317 WidgetPresentationParameters::getSliceOrientation() const
319 QString sbrange = _ui.comboBoxSliceOrient->currentText();
320 if (sbrange == tr("LAB_SLICE_NORMAL_TO_X")) {
321 return MEDCALC::SLICE_NORMAL_TO_X;
323 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_Y")) {
324 return MEDCALC::SLICE_NORMAL_TO_Y;
326 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_Z")) {
327 return MEDCALC::SLICE_NORMAL_TO_Z;
329 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XY")) {
330 return MEDCALC::SLICE_NORMAL_TO_XY;
332 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XZ")) {
333 return MEDCALC::SLICE_NORMAL_TO_XZ;
335 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_YZ")) {
336 return MEDCALC::SLICE_NORMAL_TO_YZ;
338 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XYZ")) {
339 return MEDCALC::SLICE_NORMAL_TO_XYZ;
342 STDLOG("Strange!! No matching found - returning SLICE_NORMAL_TO_X.");
343 return MEDCALC::SLICE_NORMAL_TO_X;
346 MEDCALC::MEDPresentationMeshMode
347 WidgetPresentationParameters::getMeshMode() const
349 QString mesm = _ui.comboBoxMesh->currentText();
350 if (mesm == tr("LAB_MESH_WIREFRAME")) {
351 return MEDCALC::MESH_MODE_WIREFRAME;
353 else if (mesm == tr("LAB_MESH_SURFACE")) {
354 return MEDCALC::MESH_MODE_SURFACE;
356 else if (mesm == tr("LAB_MESH_SURF_EDGES")) {
357 return MEDCALC::MESH_MODE_SURFACE_EDGES;
360 STDLOG("Strange!! No matching found - returning MESH_MODE_WIREFRAME.");
361 return MEDCALC::MESH_MODE_WIREFRAME;
365 MEDCALC::MEDPresentationScalarBarRange
366 WidgetPresentationParameters::getScalarBarRange() const
368 QString sbrange = _ui.comboBoxScalarBarRange->currentText();
369 if (sbrange == tr("LAB_ALL_TIMESTEPS")) {
370 return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
372 else if (sbrange == tr("LAB_CURRENT_TIMESTEP")) {
373 return MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP;
376 STDLOG("Strange!! No matching found - returning SCALAR_BAR_ALL_TIMESTEPS.");
377 return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
381 //WidgetPresentationParameters::getScalarBarTimestep() const
383 // return _ui.doubleSpinBoxTimeStep->value();
387 //WidgetPresentationParameters::getScalarBarMinVal() const
389 // return _ui.doubleSpinBoxMinVal->value();
393 //WidgetPresentationParameters::getScalarBarMaxVal() const
395 // return _ui.doubleSpinBoxMaxVal->value();
398 MEDCALC::MEDPresentationColorMap
399 WidgetPresentationParameters::getColorMap() const
401 QString colorMap = _ui.comboBoxColorMap->currentText();
402 if (colorMap == tr("LAB_BLUE_TO_RED")) {
403 return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
405 else if (colorMap == tr("LAB_COOL_TO_WARM")) {
406 return MEDCALC::COLOR_MAP_COOL_TO_WARM;
409 STDLOG("Strange!! No matching color map found - returning blue to red.");
410 return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
414 WidgetPresentationParameters::setPresName(const std::string& name)
416 _ui.labelPresName->setText(QString::fromStdString(name));
417 QFont f(_ui.labelPresName->font());
419 _ui.labelPresName->setFont(f);