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)
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->currentIndex() == 0) // Euclidean norm
131 return _ui.comboBoxCompo->currentText().toStdString();
135 WidgetPresentationParameters::setComponents(vector<string> compos, int selecIndex)
140 _ui.labelCompo->show();
141 _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);
153 WidgetPresentationParameters::setNbContour(int nbContour)
160 STDLOG("WidgetPresentationParameters::setNbContour(): invalid number of contours!");
164 _ui.labelSpinBox->setText(tr("LAB_NB_CONTOURS"));
165 _ui.labelSpinBox->show();
167 _ui.spinBox->setValue(nbContour);
173 WidgetPresentationParameters::setNbSlices(int nbSlices)
180 STDLOG("WidgetPresentationParameters::setNbSlices(): invalid number of slices!");
184 _ui.labelSpinBox->setText(tr("LAB_NB_SLICES"));
185 _ui.labelSpinBox->show();
187 _ui.spinBox->setValue(nbSlices);
192 int WidgetPresentationParameters::getNbContour() const
194 return _ui.spinBox->value();
197 int WidgetPresentationParameters::getNbSlices() const
199 return _ui.spinBox->value();
204 WidgetPresentationParameters::setScalarBarRange(MEDCALC::ScalarBarRangeType sbrange)
209 if (sbrange == MEDCALC::SCALAR_BAR_ALL_TIMESTEPS)
210 idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_ALL_TIMESTEPS"));
211 else if (sbrange == MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP)
212 idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_CURRENT_TIMESTEP"));
215 _ui.comboBoxScalarBarRange->setCurrentIndex(idx);
217 STDLOG("Strange!! No matching found - unable to set scalar bar range in GUI.");
223 WidgetPresentationParameters::setColorMap(MEDCALC::ColorMapType colorMap)
228 if (colorMap == MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW)
229 idx = _ui.comboBoxColorMap->findText(tr("LAB_BLUE_TO_RED"));
230 else if (colorMap == MEDCALC::COLOR_MAP_COOL_TO_WARM)
231 idx = _ui.comboBoxColorMap->findText(tr("LAB_COOL_TO_WARM"));
234 _ui.comboBoxColorMap->setCurrentIndex(idx);
236 STDLOG("Strange!! No matching found - unable to set color map in GUI.");
242 WidgetPresentationParameters::setMeshMode(MEDCALC::MeshModeType mode)
247 _ui.labelMeshMode->show();
248 _ui.comboBoxMesh->show();
253 case MEDCALC::MESH_MODE_WIREFRAME:
254 idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_WIREFRAME"));
256 case MEDCALC::MESH_MODE_SURFACE:
257 idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_SURFACE"));
259 case MEDCALC::MESH_MODE_SURFACE_EDGES:
260 idx = _ui.comboBoxMesh->findText(tr("LAB_MESH_SURF_EDGES"));
266 _ui.comboBoxMesh->setCurrentIndex(idx);
268 STDLOG("Strange!! No matching found - unable to set mesh mode in GUI.");
274 WidgetPresentationParameters::setSliceOrientation(MEDCALC::SliceOrientationType orient)
279 _ui.labelSliceOrient->show();
280 _ui.comboBoxSliceOrient->show();
285 case MEDCALC::SLICE_NORMAL_TO_X:
286 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_X"));
288 case MEDCALC::SLICE_NORMAL_TO_Y:
289 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_Y"));
291 case MEDCALC::SLICE_NORMAL_TO_Z:
292 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_Z"));
294 case MEDCALC::SLICE_NORMAL_TO_XY:
295 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XY"));
297 case MEDCALC::SLICE_NORMAL_TO_XZ:
298 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XZ"));
300 case MEDCALC::SLICE_NORMAL_TO_YZ:
301 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_YZ"));
303 case MEDCALC::SLICE_NORMAL_TO_XYZ:
304 idx = _ui.comboBoxSliceOrient->findText(tr("LAB_SLICE_NORMAL_TO_XYZ"));
310 _ui.comboBoxSliceOrient->setCurrentIndex(idx);
312 STDLOG("Strange!! No matching found - unable to set slice orientation in GUI.");
318 MEDCALC::SliceOrientationType
319 WidgetPresentationParameters::getSliceOrientation() const
321 QString sbrange = _ui.comboBoxSliceOrient->currentText();
322 if (sbrange == tr("LAB_SLICE_NORMAL_TO_X")) {
323 return MEDCALC::SLICE_NORMAL_TO_X;
325 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_Y")) {
326 return MEDCALC::SLICE_NORMAL_TO_Y;
328 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_Z")) {
329 return MEDCALC::SLICE_NORMAL_TO_Z;
331 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XY")) {
332 return MEDCALC::SLICE_NORMAL_TO_XY;
334 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XZ")) {
335 return MEDCALC::SLICE_NORMAL_TO_XZ;
337 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_YZ")) {
338 return MEDCALC::SLICE_NORMAL_TO_YZ;
340 else if (sbrange == tr("LAB_SLICE_NORMAL_TO_XYZ")) {
341 return MEDCALC::SLICE_NORMAL_TO_XYZ;
344 STDLOG("Strange!! No matching found - returning SLICE_NORMAL_TO_X.");
345 return MEDCALC::SLICE_NORMAL_TO_X;
348 MEDCALC::MeshModeType
349 WidgetPresentationParameters::getMeshMode() const
351 QString mesm = _ui.comboBoxMesh->currentText();
352 if (mesm == tr("LAB_MESH_WIREFRAME")) {
353 return MEDCALC::MESH_MODE_WIREFRAME;
355 else if (mesm == tr("LAB_MESH_SURFACE")) {
356 return MEDCALC::MESH_MODE_SURFACE;
358 else if (mesm == tr("LAB_MESH_SURF_EDGES")) {
359 return MEDCALC::MESH_MODE_SURFACE_EDGES;
362 STDLOG("Strange!! No matching found - returning MESH_MODE_WIREFRAME.");
363 return MEDCALC::MESH_MODE_WIREFRAME;
367 MEDCALC::ScalarBarRangeType
368 WidgetPresentationParameters::getScalarBarRange() const
370 QString sbrange = _ui.comboBoxScalarBarRange->currentText();
371 if (sbrange == tr("LAB_ALL_TIMESTEPS")) {
372 return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
374 else if (sbrange == tr("LAB_CURRENT_TIMESTEP")) {
375 return MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP;
378 STDLOG("Strange!! No matching found - returning SCALAR_BAR_ALL_TIMESTEPS.");
379 return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
383 //WidgetPresentationParameters::getScalarBarTimestep() const
385 // return _ui.doubleSpinBoxTimeStep->value();
389 //WidgetPresentationParameters::getScalarBarMinVal() const
391 // return _ui.doubleSpinBoxMinVal->value();
395 //WidgetPresentationParameters::getScalarBarMaxVal() const
397 // return _ui.doubleSpinBoxMaxVal->value();
400 MEDCALC::ColorMapType
401 WidgetPresentationParameters::getColorMap() const
403 QString colorMap = _ui.comboBoxColorMap->currentText();
404 if (colorMap == tr("LAB_BLUE_TO_RED")) {
405 return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
407 else if (colorMap == tr("LAB_COOL_TO_WARM")) {
408 return MEDCALC::COLOR_MAP_COOL_TO_WARM;
411 STDLOG("Strange!! No matching color map found - returning blue to red.");
412 return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
416 WidgetPresentationParameters::setPresName(const std::string& name)
418 _ui.labelPresName->setText(QString::fromStdString(name));
419 QFont f(_ui.labelPresName->font());
421 _ui.labelPresName->setFont(f);