Salome HOME
Copyright update 2020
[modules/med.git] / src / MEDCalc / gui / dialogs / WidgetPresentationParameters.cxx
index 3114be35edb16faa3d31144fd636863d37d37c68..440e5b455f97d1b22b9c3b1fd99f4b696f214637 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2016  CEA/DEN, EDF R&D
+// Copyright (C) 2016-2020  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
+#ifdef WIN32
+#define NOMINMAX
+#endif
+
 #include "WidgetPresentationParameters.hxx"
 #include <Basics_Utils.hxx>
 
@@ -38,8 +42,8 @@ WidgetPresentationParameters::WidgetPresentationParameters(QWidget* parent)
                    this,                       SLOT(onComboColorMapIndexChanged(int)) );
   QObject::connect(_ui.comboBoxSliceOrient,       SIGNAL(activated(int)),
                    this,                       SLOT(onComboOrientIndexChanged(int)) );
-  QObject::connect(_ui.spinBox,                SIGNAL(valueChanged(int)),
-                     this,                     SLOT(onSpinBoxValueChanged(int)) );
+  QObject::connect(_ui.spinBox,                SIGNAL(editingFinished()),
+                     this,                     SLOT(onSpinBoxEditingFinished()) );
 }
 
 void
@@ -74,9 +78,9 @@ WidgetPresentationParameters::onComboScalarBarRangeIndexChanged(int idx)
 }
 
 void
-WidgetPresentationParameters::onSpinBoxValueChanged(int val)
+WidgetPresentationParameters::onSpinBoxEditingFinished()
 {
-  if (!_blockSig) emit spinBoxValueChanged(val);
+  if (!_blockSig) emit spinBoxValueChanged(_ui.spinBox->value());
 }
 
 void
@@ -103,7 +107,7 @@ WidgetPresentationParameters::toggleWidget(bool show)
   else
     {
       _ui.widgetDynamic->show();
-      // It is the WidgetHelper responsability to re-show the widgets it needs
+      // It is the WidgetHelper responsibility to re-show the widgets it needs
       _ui.labelCompo->hide();
       _ui.comboBoxCompo->hide();
       _ui.labelMeshMode->hide();
@@ -125,7 +129,8 @@ WidgetPresentationParameters::isShown() const
 string
 WidgetPresentationParameters::getComponent() const
 {
-  if (_ui.comboBoxCompo->currentIndex() == 0) // Euclidean norm
+  if (_ui.comboBoxCompo->count() > 1 && _ui.comboBoxCompo->count() <= 3)
+    if (_ui.comboBoxCompo->currentIndex() == 0) // Euclidean norm
       return "";
 
   return _ui.comboBoxCompo->currentText().toStdString();
@@ -141,10 +146,15 @@ WidgetPresentationParameters::setComponents(vector<string> compos, int selecInde
   _ui.comboBoxCompo->show();
 
   _ui.comboBoxCompo->clear();
-  _ui.comboBoxCompo->addItem(tr("LAB_EUCLIDEAN_NORM"));
+  bool vectorField = (compos.size() > 1 && compos.size() <= 3);
+  if (vectorField)
+    _ui.comboBoxCompo->addItem(tr("LAB_EUCLIDEAN_NORM"));
   for(vector<string>::const_iterator it = compos.begin(); it != compos.end(); ++it)
     _ui.comboBoxCompo->addItem(QString::fromStdString(*it));
-  _ui.comboBoxCompo->setCurrentIndex(selecIndex);
+  if (!vectorField)
+    _ui.comboBoxCompo->setCurrentIndex(std::max(0, selecIndex-1));
+  else
+    _ui.comboBoxCompo->setCurrentIndex(selecIndex);
 
   _blockSig = false;
 }
@@ -161,9 +171,11 @@ WidgetPresentationParameters::setNbContour(int nbContour)
     }
 
   // Show the widget:
-  _ui.labelSpinBox->setText(tr("LAB_NB_CONTOURS"));
+  _ui.labelSpinBox->setText(tr("LAB_NB_CONTOURS").arg(MEDCALC::NB_CONTOURS_MAX));
+
   _ui.labelSpinBox->show();
   _ui.spinBox->show();
+  _ui.spinBox->setRange(1, MEDCALC::NB_CONTOURS_MAX);
   _ui.spinBox->setValue(nbContour);
 
   _blockSig = false;
@@ -181,9 +193,10 @@ WidgetPresentationParameters::setNbSlices(int nbSlices)
     }
 
   // Show the widget:
-  _ui.labelSpinBox->setText(tr("LAB_NB_SLICES"));
+  _ui.labelSpinBox->setText(tr("LAB_NB_SLICES").arg(MEDCALC::NB_SLICES_MAX));
   _ui.labelSpinBox->show();
   _ui.spinBox->show();
+  _ui.spinBox->setRange(1, MEDCALC::NB_SLICES_MAX);
   _ui.spinBox->setValue(nbSlices);
 
   _blockSig = false;