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(activated(int)),
32 this, SLOT(onComboCompoIndexChanged(int)) );
33 QObject::connect(_ui.comboBoxMesh, SIGNAL(activated(int)),
34 this, SLOT(onComboMeshIndexChanged(int)) );
35 QObject::connect(_ui.comboBoxScalarBarRange, SIGNAL(activated(int)),
36 this, SLOT(onComboScalarBarRangeIndexChanged(int)) );
37 QObject::connect(_ui.comboBoxColorMap, SIGNAL(activated(int)),
38 this, SLOT(onComboColorMapIndexChanged(int)) );
39 QObject::connect(_ui.comboBoxSliceOrient, SIGNAL(activated(int)),
40 this, SLOT(onComboOrientIndexChanged(int)) );
41 QObject::connect(_ui.spinBox, SIGNAL(editingFinished()),
42 this, SLOT(onSpinBoxEditingFinished()) );
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::onSpinBoxEditingFinished()
79 if (!_blockSig) emit spinBoxValueChanged(_ui.spinBox->value());
83 WidgetPresentationParameters::toggleCommonFieldWidget(bool show)
86 _ui.commonWidget->setEnabled(show);
91 WidgetPresentationParameters::toggleWidget(bool show)
93 toggleCommonFieldWidget(true);
97 _ui.widgetDynamic->hide();
98 setPresName(tr("LAB_DEFAULT_DYN_TITLE").toStdString());
99 // reset colorMap and scalarBarRange:
100 setColorMap(MEDCALC::COLOR_MAP_DEFAULT);
101 setScalarBarRange(MEDCALC::SCALAR_BAR_RANGE_DEFAULT);
105 _ui.widgetDynamic->show();
106 // It is the WidgetHelper responsability to re-show the widgets it needs
107 _ui.labelCompo->hide();
108 _ui.comboBoxCompo->hide();
109 _ui.labelMeshMode->hide();
110 _ui.comboBoxMesh->hide();
111 _ui.labelSpinBox->hide();
113 _ui.labelSliceOrient->hide();
114 _ui.comboBoxSliceOrient->hide();
120 WidgetPresentationParameters::isShown() const
122 return _ui.widgetDynamic->isVisible();
126 WidgetPresentationParameters::getComponent() const
128 if (_ui.comboBoxCompo->count() > 1 && _ui.comboBoxCompo->count() <= 3)
129 if (_ui.comboBoxCompo->currentIndex() == 0) // Euclidean norm
132 return _ui.comboBoxCompo->currentText().toStdString();
136 WidgetPresentationParameters::setComponents(vector<string> compos, int selecIndex)
141 _ui.labelCompo->show();
142 _ui.comboBoxCompo->show();
144 _ui.comboBoxCompo->clear();
145 bool vectorField = (compos.size() > 1 && compos.size() <= 3);
147 _ui.comboBoxCompo->addItem(tr("LAB_EUCLIDEAN_NORM"));
148 for(vector<string>::const_iterator it = compos.begin(); it != compos.end(); ++it)
149 _ui.comboBoxCompo->addItem(QString::fromStdString(*it));
151 _ui.comboBoxCompo->setCurrentIndex(std::max(0, selecIndex-1));
153 _ui.comboBoxCompo->setCurrentIndex(selecIndex);
159 WidgetPresentationParameters::setNbContour(int nbContour)
166 STDLOG("WidgetPresentationParameters::setNbContour(): invalid number of contours!");
170 _ui.labelSpinBox->setText(tr("LAB_NB_CONTOURS").arg(MEDCALC::NB_CONTOURS_MAX));
172 _ui.labelSpinBox->show();
174 _ui.spinBox->setRange(1, MEDCALC::NB_CONTOURS_MAX);
175 _ui.spinBox->setValue(nbContour);
181 WidgetPresentationParameters::setNbSlices(int nbSlices)
188 STDLOG("WidgetPresentationParameters::setNbSlices(): invalid number of slices!");
192 _ui.labelSpinBox->setText(tr("LAB_NB_SLICES").arg(MEDCALC::NB_SLICES_MAX));
193 _ui.labelSpinBox->show();
195 _ui.spinBox->setRange(1, MEDCALC::NB_SLICES_MAX);
196 _ui.spinBox->setValue(nbSlices);
201 int WidgetPresentationParameters::getNbContour() const
203 return _ui.spinBox->value();
206 int WidgetPresentationParameters::getNbSlices() const
208 return _ui.spinBox->value();
213 WidgetPresentationParameters::setScalarBarRange(MEDCALC::ScalarBarRangeType sbrange)
218 if (sbrange == MEDCALC::SCALAR_BAR_ALL_TIMESTEPS)
219 idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_ALL_TIMESTEPS"));
220 else if (sbrange == MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP)
221 idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_CURRENT_TIMESTEP"));
224 _ui.comboBoxScalarBarRange->setCurrentIndex(idx);
226 STDLOG("Strange!! No matching found - unable to set scalar bar range in GUI.");
232 WidgetPresentationParameters::setColorMap(MEDCALC::ColorMapType colorMap)
237 if (colorMap == MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW)
238 idx = _ui.comboBoxColorMap->findText(tr("LAB_BLUE_TO_RED"));
239 else if (colorMap == MEDCALC::COLOR_MAP_COOL_TO_WARM)
240 idx = _ui.comboBoxColorMap->findText(tr("LAB_COOL_TO_WARM"));
243 _ui.comboBoxColorMap->setCurrentIndex(idx);
245 STDLOG("Strange!! No matching found - unable to set color map in GUI.");
251 WidgetPresentationParameters::setMeshMode(MEDCALC::MeshModeType mode)
256 _ui.labelMeshMode->show();
257 _ui.comboBoxMesh->show();
262 case MEDCALC::MESH_MODE_WIREFRAME:
263 idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_WIREFRAME"));
265 case MEDCALC::MESH_MODE_SURFACE:
266 idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_SURFACE"));
268 case MEDCALC::MESH_MODE_SURFACE_EDGES:
269 idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_SURF_EDGES"));
275 _ui.comboBoxMesh->setCurrentIndex(idx);
277 STDLOG("Strange!! No matching found - unable to set mesh mode in GUI.");
283 WidgetPresentationParameters::setSliceOrientation(MEDCALC::SliceOrientationType orient)
288 _ui.labelSliceOrient->show();
289 _ui.comboBoxSliceOrient->show();
294 case MEDCALC::SLICE_NORMAL_TO_X:
295 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_X"));
297 case MEDCALC::SLICE_NORMAL_TO_Y:
298 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_Y"));
300 case MEDCALC::SLICE_NORMAL_TO_Z:
301 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_Z"));
303 case MEDCALC::SLICE_NORMAL_TO_XY:
304 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XY"));
306 case MEDCALC::SLICE_NORMAL_TO_XZ:
307 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XZ"));
309 case MEDCALC::SLICE_NORMAL_TO_YZ:
310 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_YZ"));
312 case MEDCALC::SLICE_NORMAL_TO_XYZ:
313 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XYZ"));
319 _ui.comboBoxSliceOrient->setCurrentIndex(idx);
321 STDLOG("Strange!! No matching found - unable to set slice orientation in GUI.");
327 MEDCALC::SliceOrientationType
328 WidgetPresentationParameters::getSliceOrientation() const
330 QString sbrange = _ui.comboBoxSliceOrient->currentText();
331 if (sbrange == tr("LAB_SLICE_NORMAL_TO_X")) {
332 return MEDCALC::SLICE_NORMAL_TO_X;
334 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_Y")) {
335 return MEDCALC::SLICE_NORMAL_TO_Y;
337 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_Z")) {
338 return MEDCALC::SLICE_NORMAL_TO_Z;
340 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XY")) {
341 return MEDCALC::SLICE_NORMAL_TO_XY;
343 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XZ")) {
344 return MEDCALC::SLICE_NORMAL_TO_XZ;
346 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_YZ")) {
347 return MEDCALC::SLICE_NORMAL_TO_YZ;
349 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XYZ")) {
350 return MEDCALC::SLICE_NORMAL_TO_XYZ;
353 STDLOG("Strange!! No matching found - returning SLICE_NORMAL_TO_X.");
354 return MEDCALC::SLICE_NORMAL_TO_X;
357 MEDCALC::MeshModeType
358 WidgetPresentationParameters::getMeshMode() const
360 QString mesm = _ui.comboBoxMesh->currentText();
361 if (mesm == tr("LAB_MESH_WIREFRAME")) {
362 return MEDCALC::MESH_MODE_WIREFRAME;
364 else if (mesm == tr("LAB_MESH_SURFACE")) {
365 return MEDCALC::MESH_MODE_SURFACE;
367 else if (mesm == tr("LAB_MESH_SURF_EDGES")) {
368 return MEDCALC::MESH_MODE_SURFACE_EDGES;
371 STDLOG("Strange!! No matching found - returning MESH_MODE_WIREFRAME.");
372 return MEDCALC::MESH_MODE_WIREFRAME;
376 MEDCALC::ScalarBarRangeType
377 WidgetPresentationParameters::getScalarBarRange() const
379 QString sbrange = _ui.comboBoxScalarBarRange->currentText();
380 if (sbrange == tr("LAB_ALL_TIMESTEPS")) {
381 return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
383 else if (sbrange == tr("LAB_CURRENT_TIMESTEP")) {
384 return MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP;
387 STDLOG("Strange!! No matching found - returning SCALAR_BAR_ALL_TIMESTEPS.");
388 return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
392 //WidgetPresentationParameters::getScalarBarTimestep() const
394 // return _ui.doubleSpinBoxTimeStep->value();
398 //WidgetPresentationParameters::getScalarBarMinVal() const
400 // return _ui.doubleSpinBoxMinVal->value();
404 //WidgetPresentationParameters::getScalarBarMaxVal() const
406 // return _ui.doubleSpinBoxMaxVal->value();
409 MEDCALC::ColorMapType
410 WidgetPresentationParameters::getColorMap() const
412 QString colorMap = _ui.comboBoxColorMap->currentText();
413 if (colorMap == tr("LAB_BLUE_TO_RED")) {
414 return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
416 else if (colorMap == tr("LAB_COOL_TO_WARM")) {
417 return MEDCALC::COLOR_MAP_COOL_TO_WARM;
420 STDLOG("Strange!! No matching color map found - returning blue to red.");
421 return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
425 WidgetPresentationParameters::setPresName(const std::string& name)
427 _ui.labelPresName->setText(QString::fromStdString(name));
428 QFont f(_ui.labelPresName->font());
430 _ui.labelPresName->setFont(f);