Salome HOME
Copyright update 2020
[modules/med.git] / src / MEDCalc / gui / dialogs / WidgetPresentationParameters.cxx
index 8d7a3e1be906e779978c5b8e1b211b3d928b5445..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>
 
@@ -28,18 +32,18 @@ WidgetPresentationParameters::WidgetPresentationParameters(QWidget* parent)
   _ui.setupUi(this); // To be done first
 
   toggleWidget(false);
-  QObject::connect(_ui.comboBoxCompo,          SIGNAL(currentIndexChanged(int)),
+  QObject::connect(_ui.comboBoxCompo,          SIGNAL(activated(int)),
                    this,                       SLOT(onComboCompoIndexChanged(int)) );
-  QObject::connect(_ui.comboBoxMesh,          SIGNAL(currentIndexChanged(int)),
+  QObject::connect(_ui.comboBoxMesh,          SIGNAL(activated(int)),
                      this,                       SLOT(onComboMeshIndexChanged(int)) );
-  QObject::connect(_ui.comboBoxScalarBarRange, SIGNAL(currentIndexChanged(int)),
+  QObject::connect(_ui.comboBoxScalarBarRange, SIGNAL(activated(int)),
                    this,                       SLOT(onComboScalarBarRangeIndexChanged(int)) );
-  QObject::connect(_ui.comboBoxColorMap,       SIGNAL(currentIndexChanged(int)),
+  QObject::connect(_ui.comboBoxColorMap,       SIGNAL(activated(int)),
                    this,                       SLOT(onComboColorMapIndexChanged(int)) );
-  QObject::connect(_ui.comboBoxSliceOrient,       SIGNAL(currentIndexChanged(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
@@ -90,13 +94,12 @@ WidgetPresentationParameters::toggleCommonFieldWidget(bool show)
 void
 WidgetPresentationParameters::toggleWidget(bool show)
 {
+  toggleCommonFieldWidget(true);
   if (!show)
     {
-      toggleCommonFieldWidget(true);
-
       _blockSig = true;
       _ui.widgetDynamic->hide();
-      setPresName("Choose a presentation");
+      setPresName(tr("LAB_DEFAULT_DYN_TITLE").toStdString());
       // reset colorMap and scalarBarRange:
       setColorMap(MEDCALC::COLOR_MAP_DEFAULT);
       setScalarBarRange(MEDCALC::SCALAR_BAR_RANGE_DEFAULT);
@@ -104,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();
@@ -126,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();
@@ -135,22 +139,31 @@ WidgetPresentationParameters::getComponent() const
 void
 WidgetPresentationParameters::setComponents(vector<string> compos, int selecIndex)
 {
+  _blockSig = true;
+
   // Show the widget:
   _ui.labelCompo->show();
   _ui.comboBoxCompo->show();
 
-  _blockSig = true;
   _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;
 }
 
 void
 WidgetPresentationParameters::setNbContour(int nbContour)
 {
+  _blockSig = true;
+
   if (nbContour <= 0)
     {
       //TODO throw?
@@ -158,18 +171,21 @@ 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();
-
-  _blockSig = true;
+  _ui.spinBox->setRange(1, MEDCALC::NB_CONTOURS_MAX);
   _ui.spinBox->setValue(nbContour);
+
   _blockSig = false;
 }
 
 void
 WidgetPresentationParameters::setNbSlices(int nbSlices)
 {
+  _blockSig = true;
+
   if (nbSlices <= 0)
     {
       //TODO throw?
@@ -177,12 +193,12 @@ 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();
-
-  _blockSig = true;
+  _ui.spinBox->setRange(1, MEDCALC::NB_SLICES_MAX);
   _ui.spinBox->setValue(nbSlices);
+
   _blockSig = false;
 }
 
@@ -200,6 +216,8 @@ int WidgetPresentationParameters::getNbSlices() const
 void
 WidgetPresentationParameters::setScalarBarRange(MEDCALC::ScalarBarRangeType sbrange)
 {
+  _blockSig = true;
+
   int idx;
   if (sbrange == MEDCALC::SCALAR_BAR_ALL_TIMESTEPS)
     idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_ALL_TIMESTEPS"));
@@ -207,18 +225,18 @@ WidgetPresentationParameters::setScalarBarRange(MEDCALC::ScalarBarRangeType sbra
     idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_CURRENT_TIMESTEP"));
 
   if (idx >= 0)
-    {
-      _blockSig = true;
       _ui.comboBoxScalarBarRange->setCurrentIndex(idx);
-      _blockSig = false;
-    }
   else
     STDLOG("Strange!! No matching found - unable to set scalar bar range in GUI.");
+
+  _blockSig = false;
 }
 
 void
 WidgetPresentationParameters::setColorMap(MEDCALC::ColorMapType colorMap)
 {
+  _blockSig = true;
+
   int idx = -1;
   if (colorMap == MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW)
     idx = _ui.comboBoxColorMap->findText(tr("LAB_BLUE_TO_RED"));
@@ -226,19 +244,18 @@ WidgetPresentationParameters::setColorMap(MEDCALC::ColorMapType colorMap)
     idx = _ui.comboBoxColorMap->findText(tr("LAB_COOL_TO_WARM"));
 
   if (idx >= 0)
-    {
-      _blockSig = true;
       _ui.comboBoxColorMap->setCurrentIndex(idx);
-      _blockSig = false;
-    }
-
   else
     STDLOG("Strange!! No matching found - unable to set color map in GUI.");
+
+  _blockSig = false;
 }
 
 void
 WidgetPresentationParameters::setMeshMode(MEDCALC::MeshModeType mode)
 {
+  _blockSig = true;
+
   // Show the widget:
   _ui.labelMeshMode->show();
   _ui.comboBoxMesh->show();
@@ -259,18 +276,18 @@ WidgetPresentationParameters::setMeshMode(MEDCALC::MeshModeType mode)
       idx = -1;
   }
   if (idx >= 0)
-    {
-      _blockSig = true;
       _ui.comboBoxMesh->setCurrentIndex(idx);
-      _blockSig = false;
-    }
   else
     STDLOG("Strange!! No matching found - unable to set mesh mode in GUI.");
+
+  _blockSig = false;
 }
 
 void
 WidgetPresentationParameters::setSliceOrientation(MEDCALC::SliceOrientationType orient)
 {
+  _blockSig = true;
+
   // Show the widget:
   _ui.labelSliceOrient->show();
   _ui.comboBoxSliceOrient->show();
@@ -303,13 +320,11 @@ WidgetPresentationParameters::setSliceOrientation(MEDCALC::SliceOrientationType
       idx = -1;
   }
   if (idx >= 0)
-    {
-      _blockSig = true;
-      _ui.comboBoxSliceOrient->setCurrentIndex(idx);
-      _blockSig = false;
-    }
+    _ui.comboBoxSliceOrient->setCurrentIndex(idx);
   else
     STDLOG("Strange!! No matching found - unable to set slice orientation in GUI.");
+
+  _blockSig = false;
 }