Salome HOME
[MEDCalc] Fully functional scalar map (other pres deactivated)
[modules/med.git] / src / MEDCalc / gui / dialogs / WidgetPresentationParameters.cxx
index 380784b0200829cb8cc3d519c9e4fa3105abc5ca..05765430e1fe840a71a8134dad4cbeb8dcd6ef36 100644 (file)
 #include "WidgetPresentationParameters.hxx"
 #include <Basics_Utils.hxx>
 
+using namespace std;
+
 WidgetPresentationParameters::WidgetPresentationParameters(QWidget* parent)
-  : QWidget(parent)
+  : QWidget(parent), _blockSig(false)
+{
+  _ui.setupUi(this); // To be done first
+
+  toggleWidget(false);
+  QObject::connect(_ui.comboBoxCompo,          SIGNAL(currentIndexChanged(int)),
+                   this,                       SLOT(onComboCompoIndexChanged(int)) );
+  QObject::connect(_ui.comboBoxScalarBarRange, SIGNAL(currentIndexChanged(int)),
+                   this,                       SLOT(onComboScalarBarRangeIndexChanged(int)) );
+  QObject::connect(_ui.comboBoxColorMap,       SIGNAL(currentIndexChanged(int)),
+                   this,                       SLOT(onComboColorMapIndexChanged(int)) );
+}
+
+void
+WidgetPresentationParameters::onComboCompoIndexChanged(int idx)
+{
+  if (!_blockSig) emit comboCompoIndexChanged(idx);
+}
+
+void
+WidgetPresentationParameters::onComboColorMapIndexChanged(int idx)
+{
+  if (!_blockSig) emit comboColorMapIndexChanged(idx);
+}
+
+void
+WidgetPresentationParameters::onComboScalarBarRangeIndexChanged(int idx)
+{
+  if (!_blockSig) emit comboScalarBarRangeIndexChanged(idx);
+}
+
+
+void
+WidgetPresentationParameters::toggleWidget(bool show)
+{
+  if (!show)
+    {
+      _blockSig = true;
+      _ui.widgetDynamic->hide();
+      setPresName("Choose a presentation");
+      // reset colorMap and scalarBarRange:
+      setColorMap(MEDCALC::COLOR_MAP_DEFAULT);
+      setScalarBarRange(MEDCALC::SCALAR_BAR_RANGE_DEFAULT);
+    }
+  else
+    {
+      _ui.widgetDynamic->show();
+      // It is the WidgetHelper responsability to re-show the widgets it needs
+      _ui.labelCompo->hide();
+      _ui.comboBoxCompo->hide();
+      _ui.labelSpinBox->hide();
+      _ui.spinBox->hide();
+      _ui.labelSliceOrient->hide();
+      _ui.comboBoxSliceOrient->hide();
+      _blockSig = false;
+    }
+}
+
+bool
+WidgetPresentationParameters::isShown() const
 {
-  ui.setupUi(this); // To be done first
+  return _ui.widgetDynamic->isVisible();
 }
 
-std::string
-WidgetPresentationParameters::getField()
+string
+WidgetPresentationParameters::getComponent() const
 {
-  return this->ui.comboBoxField->currentText().toStdString();
+  if (_ui.comboBoxCompo->currentIndex() == 0) // Euclidean norm
+      return "";
+
+  return _ui.comboBoxCompo->currentText().toStdString();
 }
 
-std::string
-WidgetPresentationParameters::getScalarBarRange()
+void
+WidgetPresentationParameters::setComponents(vector<string> compos, int selecIndex)
 {
-  return this->ui.comboBoxScalarBarRange->currentText().toStdString();
+  // Show the widget:
+  _ui.labelCompo->show();
+  _ui.comboBoxCompo->show();
+
+  _blockSig = true;
+  _ui.comboBoxCompo->clear();
+  _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);
+  _blockSig = false;
 }
 
-double
-WidgetPresentationParameters::getScalarBarTimestep()
+void
+WidgetPresentationParameters::setScalarBarRange(MEDCALC::MEDPresentationScalarBarRange sbrange)
 {
-  return this->ui.doubleSpinBoxTimeStep->value();
+  int idx;
+  if (sbrange == MEDCALC::SCALAR_BAR_ALL_TIMESTEPS)
+    idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_ALL_TIMESTEPS"));
+  else if (sbrange == MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP)
+    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.");
 }
 
-double
-WidgetPresentationParameters::getScalarBarMinVal()
+void
+WidgetPresentationParameters::setColorMap(MEDCALC::MEDPresentationColorMap colorMap)
 {
-  return this->ui.doubleSpinBoxMinVal->value();
+  int idx;
+  if (colorMap == MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW)
+    idx = _ui.comboBoxColorMap->findText(tr("LAB_BLUE_TO_RED"));
+  else if (colorMap == MEDCALC::COLOR_MAP_COOL_TO_WARM)
+    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.");
 }
 
-double
-WidgetPresentationParameters::getScalarBarMaxVal()
+
+MEDCALC::MEDPresentationScalarBarRange
+WidgetPresentationParameters::getScalarBarRange() const
 {
-  return this->ui.doubleSpinBoxMaxVal->value();
+  QString sbrange = _ui.comboBoxScalarBarRange->currentText();
+  if (sbrange == tr("LAB_ALL_TIMESTEPS")) {
+    return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
+  }
+  else if (sbrange == tr("LAB_CURRENT_TIMESTEP")) {
+    return MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP;
+  }
+  // Should not happen
+  STDLOG("Strange!! No matching found - returning SCALAR_BAR_ALL_TIMESTEPS.");
+  return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS;
 }
 
+//double
+//WidgetPresentationParameters::getScalarBarTimestep() const
+//{
+//  return _ui.doubleSpinBoxTimeStep->value();
+//}
+//
+//double
+//WidgetPresentationParameters::getScalarBarMinVal() const
+//{
+//  return _ui.doubleSpinBoxMinVal->value();
+//}
+//
+//double
+//WidgetPresentationParameters::getScalarBarMaxVal() const
+//{
+//  return _ui.doubleSpinBoxMaxVal->value();
+//}
+
 MEDCALC::MEDPresentationColorMap
-WidgetPresentationParameters::getColorMap()
+WidgetPresentationParameters::getColorMap() const
 {
-  QString colorMap = this->ui.comboBoxColorMap->currentText();
+  QString colorMap = _ui.comboBoxColorMap->currentText();
   if (colorMap == tr("LAB_BLUE_TO_RED")) {
     return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
   }
@@ -70,3 +199,18 @@ WidgetPresentationParameters::getColorMap()
   STDLOG("Strange!! No matching color map found - returning blue to red.");
   return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW;
 }
+
+QComboBox *
+WidgetPresentationParameters::getComboBoxCompo()
+{
+  return _ui.comboBoxCompo;
+}
+
+void
+WidgetPresentationParameters::setPresName(const std::string& name)
+{
+  _ui.labelPresName->setText(QString::fromStdString(name));
+  QFont f(_ui.labelPresName->font());
+  f.setItalic(true);
+  _ui.labelPresName->setFont(f);
+}