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
24 #include "WidgetPresentationParameters.hxx"
25 #include <Basics_Utils.hxx>
29 WidgetPresentationParameters::WidgetPresentationParameters(QWidget* parent)
30 : QWidget(parent), _blockSig(false)
32 _ui.setupUi(this); // To be done first
35 QObject::connect(_ui.comboBoxCompo, SIGNAL(activated(int)),
36 this, SLOT(onComboCompoIndexChanged(int)) );
37 QObject::connect(_ui.comboBoxMesh, SIGNAL(activated(int)),
38 this, SLOT(onComboMeshIndexChanged(int)) );
39 QObject::connect(_ui.comboBoxScalarBarRange, SIGNAL(activated(int)),
40 this, SLOT(onComboScalarBarRangeIndexChanged(int)) );
41 QObject::connect(_ui.comboBoxColorMap, SIGNAL(activated(int)),
42 this, SLOT(onComboColorMapIndexChanged(int)) );
43 QObject::connect(_ui.comboBoxSliceOrient, SIGNAL(activated(int)),
44 this, SLOT(onComboOrientIndexChanged(int)) );
45 QObject::connect(_ui.spinBox, SIGNAL(editingFinished()),
46 this, SLOT(onSpinBoxEditingFinished()) );
50 WidgetPresentationParameters::onComboCompoIndexChanged(int idx)
52 if (!_blockSig) emit comboCompoIndexChanged(idx);
56 WidgetPresentationParameters::onComboOrientIndexChanged(int idx)
58 if (!_blockSig) emit comboOrientIndexChanged(idx);
63 WidgetPresentationParameters::onComboMeshIndexChanged(int idx)
65 if (!_blockSig) emit comboMeshIndexChanged(idx);
69 WidgetPresentationParameters::onComboColorMapIndexChanged(int idx)
71 if (!_blockSig) emit comboColorMapIndexChanged(idx);
75 WidgetPresentationParameters::onComboScalarBarRangeIndexChanged(int idx)
77 if (!_blockSig) emit comboScalarBarRangeIndexChanged(idx);
81 WidgetPresentationParameters::onSpinBoxEditingFinished()
83 if (!_blockSig) emit spinBoxValueChanged(_ui.spinBox->value());
87 WidgetPresentationParameters::toggleCommonFieldWidget(bool show)
90 _ui.commonWidget->setEnabled(show);
95 WidgetPresentationParameters::toggleWidget(bool show)
97 toggleCommonFieldWidget(true);
101 _ui.widgetDynamic->hide();
102 setPresName(tr("LAB_DEFAULT_DYN_TITLE").toStdString());
103 // reset colorMap and scalarBarRange:
104 setColorMap(MEDCALC::COLOR_MAP_DEFAULT);
105 setScalarBarRange(MEDCALC::SCALAR_BAR_RANGE_DEFAULT);
109 _ui.widgetDynamic->show();
110 // It is the WidgetHelper responsibility to re-show the widgets it needs
111 _ui.labelCompo->hide();
112 _ui.comboBoxCompo->hide();
113 _ui.labelMeshMode->hide();
114 _ui.comboBoxMesh->hide();
115 _ui.labelSpinBox->hide();
117 _ui.labelSliceOrient->hide();
118 _ui.comboBoxSliceOrient->hide();
124 WidgetPresentationParameters::isShown() const
126 return _ui.widgetDynamic->isVisible();
130 WidgetPresentationParameters::getComponent() const
132 if (_ui.comboBoxCompo->count() > 1 && _ui.comboBoxCompo->count() <= 3)
133 if (_ui.comboBoxCompo->currentIndex() == 0) // Euclidean norm
136 return _ui.comboBoxCompo->currentText().toStdString();
140 WidgetPresentationParameters::setComponents(vector<string> compos, int selecIndex)
145 _ui.labelCompo->show();
146 _ui.comboBoxCompo->show();
148 _ui.comboBoxCompo->clear();
149 bool vectorField = (compos.size() > 1 && compos.size() <= 3);
151 _ui.comboBoxCompo->addItem(tr("LAB_EUCLIDEAN_NORM"));
152 for(vector<string>::const_iterator it = compos.begin(); it != compos.end(); ++it)
153 _ui.comboBoxCompo->addItem(QString::fromStdString(*it));
155 _ui.comboBoxCompo->setCurrentIndex(std::max(0, selecIndex-1));
157 _ui.comboBoxCompo->setCurrentIndex(selecIndex);
163 WidgetPresentationParameters::setNbContour(int nbContour)
170 STDLOG("WidgetPresentationParameters::setNbContour(): invalid number of contours!");
174 _ui.labelSpinBox->setText(tr("LAB_NB_CONTOURS").arg(MEDCALC::NB_CONTOURS_MAX));
176 _ui.labelSpinBox->show();
178 _ui.spinBox->setRange(1, MEDCALC::NB_CONTOURS_MAX);
179 _ui.spinBox->setValue(nbContour);
185 WidgetPresentationParameters::setNbSlices(int nbSlices)
192 STDLOG("WidgetPresentationParameters::setNbSlices(): invalid number of slices!");
196 _ui.labelSpinBox->setText(tr("LAB_NB_SLICES").arg(MEDCALC::NB_SLICES_MAX));
197 _ui.labelSpinBox->show();
199 _ui.spinBox->setRange(1, MEDCALC::NB_SLICES_MAX);
200 _ui.spinBox->setValue(nbSlices);
205 int WidgetPresentationParameters::getNbContour() const
207 return _ui.spinBox->value();
210 int WidgetPresentationParameters::getNbSlices() const
212 return _ui.spinBox->value();
217 WidgetPresentationParameters::setScalarBarRange(MEDCALC::ScalarBarRangeType sbrange)
222 if (sbrange == MEDCALC::SCALAR_BAR_ALL_TIMESTEPS)
223 idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_ALL_TIMESTEPS"));
224 else if (sbrange == MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP)
225 idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_CURRENT_TIMESTEP"));
228 _ui.comboBoxScalarBarRange->setCurrentIndex(idx);
230 STDLOG("Strange!! No matching found - unable to set scalar bar range in GUI.");
236 WidgetPresentationParameters::setColorMap(MEDCALC::ColorMapType colorMap)
241 if (colorMap == MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW)
242 idx = _ui.comboBoxColorMap->findText(tr("LAB_BLUE_TO_RED"));
243 else if (colorMap == MEDCALC::COLOR_MAP_COOL_TO_WARM)
244 idx = _ui.comboBoxColorMap->findText(tr("LAB_COOL_TO_WARM"));
247 _ui.comboBoxColorMap->setCurrentIndex(idx);
249 STDLOG("Strange!! No matching found - unable to set color map in GUI.");
255 WidgetPresentationParameters::setMeshMode(MEDCALC::MeshModeType mode)
260 _ui.labelMeshMode->show();
261 _ui.comboBoxMesh->show();
266 case MEDCALC::MESH_MODE_WIREFRAME:
267 idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_WIREFRAME"));
269 case MEDCALC::MESH_MODE_SURFACE:
270 idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_SURFACE"));
272 case MEDCALC::MESH_MODE_SURFACE_EDGES:
273 idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_SURF_EDGES"));
279 _ui.comboBoxMesh->setCurrentIndex(idx);
281 STDLOG("Strange!! No matching found - unable to set mesh mode in GUI.");
287 WidgetPresentationParameters::setSliceOrientation(MEDCALC::SliceOrientationType orient)
292 _ui.labelSliceOrient->show();
293 _ui.comboBoxSliceOrient->show();
298 case MEDCALC::SLICE_NORMAL_TO_X:
299 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_X"));
301 case MEDCALC::SLICE_NORMAL_TO_Y:
302 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_Y"));
304 case MEDCALC::SLICE_NORMAL_TO_Z:
305 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_Z"));
307 case MEDCALC::SLICE_NORMAL_TO_XY:
308 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XY"));
310 case MEDCALC::SLICE_NORMAL_TO_XZ:
311 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XZ"));
313 case MEDCALC::SLICE_NORMAL_TO_YZ:
314 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_YZ"));
316 case MEDCALC::SLICE_NORMAL_TO_XYZ:
317 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XYZ"));
323 _ui.comboBoxSliceOrient->setCurrentIndex(idx);
325 STDLOG("Strange!! No matching found - unable to set slice orientation in GUI.");
331 MEDCALC::SliceOrientationType
332 WidgetPresentationParameters::getSliceOrientation() const
334 QString sbrange = _ui.comboBoxSliceOrient->currentText();
335 if (sbrange == tr("LAB_SLICE_NORMAL_TO_X")) {
336 return MEDCALC::SLICE_NORMAL_TO_X;
338 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_Y")) {
339 return MEDCALC::SLICE_NORMAL_TO_Y;
341 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_Z")) {
342 return MEDCALC::SLICE_NORMAL_TO_Z;
344 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XY")) {
345 return MEDCALC::SLICE_NORMAL_TO_XY;
347 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XZ")) {
348 return MEDCALC::SLICE_NORMAL_TO_XZ;
350 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_YZ")) {
351 return MEDCALC::SLICE_NORMAL_TO_YZ;
353 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XYZ")) {
354 return MEDCALC::SLICE_NORMAL_TO_XYZ;
357 STDLOG("Strange!! No matching found - returning SLICE_NORMAL_TO_X.");
358 return MEDCALC::SLICE_NORMAL_TO_X;
361 MEDCALC::MeshModeType
362 WidgetPresentationParameters::getMeshMode() const
364 QString mesm = _ui.comboBoxMesh->currentText();
365 if (mesm == tr("LAB_MESH_WIREFRAME")) {
366 return MEDCALC::MESH_MODE_WIREFRAME;
368 else if (mesm == tr("LAB_MESH_SURFACE")) {
369 return MEDCALC::MESH_MODE_SURFACE;
371 else if (mesm == tr("LAB_MESH_SURF_EDGES")) {
372 return MEDCALC::MESH_MODE_SURFACE_EDGES;
375 STDLOG("Strange!! No matching found - returning MESH_MODE_WIREFRAME.");
376 return MEDCALC::MESH_MODE_WIREFRAME;
380 MEDCALC::ScalarBarRangeType
381 WidgetPresentationParameters::getScalarBarRange() const
383 QString sbrange = _ui.comboBoxScalarBarRange->currentText();
384 if (sbrange == tr("LAB_ALL_TIMESTEPS")) {
385 return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
387 else if (sbrange == tr("LAB_CURRENT_TIMESTEP")) {
388 return MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP;
391 STDLOG("Strange!! No matching found - returning SCALAR_BAR_ALL_TIMESTEPS.");
392 return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
396 //WidgetPresentationParameters::getScalarBarTimestep() const
398 // return _ui.doubleSpinBoxTimeStep->value();
402 //WidgetPresentationParameters::getScalarBarMinVal() const
404 // return _ui.doubleSpinBoxMinVal->value();
408 //WidgetPresentationParameters::getScalarBarMaxVal() const
410 // return _ui.doubleSpinBoxMaxVal->value();
413 MEDCALC::ColorMapType
414 WidgetPresentationParameters::getColorMap() const
416 QString colorMap = _ui.comboBoxColorMap->currentText();
417 if (colorMap == tr("LAB_BLUE_TO_RED")) {
418 return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
420 else if (colorMap == tr("LAB_COOL_TO_WARM")) {
421 return MEDCALC::COLOR_MAP_COOL_TO_WARM;
424 STDLOG("Strange!! No matching color map found - returning blue to red.");
425 return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
429 WidgetPresentationParameters::setPresName(const std::string& name)
431 _ui.labelPresName->setText(QString::fromStdString(name));
432 QFont f(_ui.labelPresName->font());
434 _ui.labelPresName->setFont(f);