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(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(tr("LAB_DEFAULT_DYN_TITLE").toStdString());
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)
141 _ui.labelCompo->show();
142 _ui.comboBoxCompo->show();
144 _ui.comboBoxCompo->clear();
145 _ui.comboBoxCompo->addItem(tr("LAB_EUCLIDEAN_NORM"));
146 for(vector<string>::const_iterator it = compos.begin(); it != compos.end(); ++it)
147 _ui.comboBoxCompo->addItem(QString::fromStdString(*it));
148 _ui.comboBoxCompo->setCurrentIndex(selecIndex);
154 WidgetPresentationParameters::setNbContour(int nbContour)
161 STDLOG("WidgetPresentationParameters::setNbContour(): invalid number of contours!");
165 _ui.labelSpinBox->setText(tr("LAB_NB_CONTOURS"));
166 _ui.labelSpinBox->show();
168 _ui.spinBox->setValue(nbContour);
174 WidgetPresentationParameters::setNbSlices(int nbSlices)
181 STDLOG("WidgetPresentationParameters::setNbSlices(): invalid number of slices!");
185 _ui.labelSpinBox->setText(tr("LAB_NB_SLICES"));
186 _ui.labelSpinBox->show();
188 _ui.spinBox->setValue(nbSlices);
193 int WidgetPresentationParameters::getNbContour() const
195 return _ui.spinBox->value();
198 int WidgetPresentationParameters::getNbSlices() const
200 return _ui.spinBox->value();
205 WidgetPresentationParameters::setScalarBarRange(MEDCALC::ScalarBarRangeType sbrange)
210 if (sbrange == MEDCALC::SCALAR_BAR_ALL_TIMESTEPS)
211 idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_ALL_TIMESTEPS"));
212 else if (sbrange == MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP)
213 idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_CURRENT_TIMESTEP"));
216 _ui.comboBoxScalarBarRange->setCurrentIndex(idx);
218 STDLOG("Strange!! No matching found - unable to set scalar bar range in GUI.");
224 WidgetPresentationParameters::setColorMap(MEDCALC::ColorMapType colorMap)
229 if (colorMap == MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW)
230 idx = _ui.comboBoxColorMap->findText(tr("LAB_BLUE_TO_RED"));
231 else if (colorMap == MEDCALC::COLOR_MAP_COOL_TO_WARM)
232 idx = _ui.comboBoxColorMap->findText(tr("LAB_COOL_TO_WARM"));
235 _ui.comboBoxColorMap->setCurrentIndex(idx);
237 STDLOG("Strange!! No matching found - unable to set color map in GUI.");
243 WidgetPresentationParameters::setMeshMode(MEDCALC::MeshModeType mode)
248 _ui.labelMeshMode->show();
249 _ui.comboBoxMesh->show();
254 case MEDCALC::MESH_MODE_WIREFRAME:
255 idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_WIREFRAME"));
257 case MEDCALC::MESH_MODE_SURFACE:
258 idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_SURFACE"));
260 case MEDCALC::MESH_MODE_SURFACE_EDGES:
261 idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_SURF_EDGES"));
267 _ui.comboBoxMesh->setCurrentIndex(idx);
269 STDLOG("Strange!! No matching found - unable to set mesh mode in GUI.");
275 WidgetPresentationParameters::setSliceOrientation(MEDCALC::SliceOrientationType orient)
280 _ui.labelSliceOrient->show();
281 _ui.comboBoxSliceOrient->show();
286 case MEDCALC::SLICE_NORMAL_TO_X:
287 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_X"));
289 case MEDCALC::SLICE_NORMAL_TO_Y:
290 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_Y"));
292 case MEDCALC::SLICE_NORMAL_TO_Z:
293 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_Z"));
295 case MEDCALC::SLICE_NORMAL_TO_XY:
296 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XY"));
298 case MEDCALC::SLICE_NORMAL_TO_XZ:
299 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XZ"));
301 case MEDCALC::SLICE_NORMAL_TO_YZ:
302 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_YZ"));
304 case MEDCALC::SLICE_NORMAL_TO_XYZ:
305 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XYZ"));
311 _ui.comboBoxSliceOrient->setCurrentIndex(idx);
313 STDLOG("Strange!! No matching found - unable to set slice orientation in GUI.");
319 MEDCALC::SliceOrientationType
320 WidgetPresentationParameters::getSliceOrientation() const
322 QString sbrange = _ui.comboBoxSliceOrient->currentText();
323 if (sbrange == tr("LAB_SLICE_NORMAL_TO_X")) {
324 return MEDCALC::SLICE_NORMAL_TO_X;
326 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_Y")) {
327 return MEDCALC::SLICE_NORMAL_TO_Y;
329 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_Z")) {
330 return MEDCALC::SLICE_NORMAL_TO_Z;
332 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XY")) {
333 return MEDCALC::SLICE_NORMAL_TO_XY;
335 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XZ")) {
336 return MEDCALC::SLICE_NORMAL_TO_XZ;
338 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_YZ")) {
339 return MEDCALC::SLICE_NORMAL_TO_YZ;
341 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XYZ")) {
342 return MEDCALC::SLICE_NORMAL_TO_XYZ;
345 STDLOG("Strange!! No matching found - returning SLICE_NORMAL_TO_X.");
346 return MEDCALC::SLICE_NORMAL_TO_X;
349 MEDCALC::MeshModeType
350 WidgetPresentationParameters::getMeshMode() const
352 QString mesm = _ui.comboBoxMesh->currentText();
353 if (mesm == tr("LAB_MESH_WIREFRAME")) {
354 return MEDCALC::MESH_MODE_WIREFRAME;
356 else if (mesm == tr("LAB_MESH_SURFACE")) {
357 return MEDCALC::MESH_MODE_SURFACE;
359 else if (mesm == tr("LAB_MESH_SURF_EDGES")) {
360 return MEDCALC::MESH_MODE_SURFACE_EDGES;
363 STDLOG("Strange!! No matching found - returning MESH_MODE_WIREFRAME.");
364 return MEDCALC::MESH_MODE_WIREFRAME;
368 MEDCALC::ScalarBarRangeType
369 WidgetPresentationParameters::getScalarBarRange() const
371 QString sbrange = _ui.comboBoxScalarBarRange->currentText();
372 if (sbrange == tr("LAB_ALL_TIMESTEPS")) {
373 return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
375 else if (sbrange == tr("LAB_CURRENT_TIMESTEP")) {
376 return MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP;
379 STDLOG("Strange!! No matching found - returning SCALAR_BAR_ALL_TIMESTEPS.");
380 return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
384 //WidgetPresentationParameters::getScalarBarTimestep() const
386 // return _ui.doubleSpinBoxTimeStep->value();
390 //WidgetPresentationParameters::getScalarBarMinVal() const
392 // return _ui.doubleSpinBoxMinVal->value();
396 //WidgetPresentationParameters::getScalarBarMaxVal() const
398 // return _ui.doubleSpinBoxMaxVal->value();
401 MEDCALC::ColorMapType
402 WidgetPresentationParameters::getColorMap() const
404 QString colorMap = _ui.comboBoxColorMap->currentText();
405 if (colorMap == tr("LAB_BLUE_TO_RED")) {
406 return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
408 else if (colorMap == tr("LAB_COOL_TO_WARM")) {
409 return MEDCALC::COLOR_MAP_COOL_TO_WARM;
412 STDLOG("Strange!! No matching color map found - returning blue to red.");
413 return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
417 WidgetPresentationParameters::setPresName(const std::string& name)
419 _ui.labelPresName->setText(QString::fromStdString(name));
420 QFont f(_ui.labelPresName->font());
422 _ui.labelPresName->setFont(f);