diff --git a/slsDetectorGui/forms/form_tab_settings.ui b/slsDetectorGui/forms/form_tab_settings.ui index 1948a50dd..32890e2d0 100755 --- a/slsDetectorGui/forms/form_tab_settings.ui +++ b/slsDetectorGui/forms/form_tab_settings.ui @@ -7,7 +7,7 @@ 0 0 775 - 345 + 380 @@ -635,9 +635,38 @@ - Settings of the detector. - #settings# + <html><head/><body><p>Gain Mode of the detector</p><p> #gainmode#</p><p><br/></p><p>Fix G0 is to be used with utmost caution. Can damage the detector!</p></body></html> + + + Dynamic Gain + + + + + Force Switch G1 + + + + + Force Switch G2 + + + + + Fix G1 + + + + + Fix G2 + + + + + Fix G0 + + diff --git a/slsDetectorGui/include/qTabSettings.h b/slsDetectorGui/include/qTabSettings.h index a78dbeb97..927cd8436 100644 --- a/slsDetectorGui/include/qTabSettings.h +++ b/slsDetectorGui/include/qTabSettings.h @@ -10,9 +10,12 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { qTabSettings(QWidget *parent, sls::Detector *detector); ~qTabSettings(); void Refresh(); + public slots: + void SetExportMode(bool exportMode); private slots: void SetSettings(int index); + void SetGainMode(int index); void SetDynamicRange(int index); void SetThresholdEnergy(int index); void SetThresholdEnergies(); @@ -22,9 +25,11 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { void SetupWidgetWindow(); void SetupDetectorSettings(); void SetupGainMode(); + void ShowFixG0(bool expertMode); void Initialization(); void GetSettings(); + void GetGainMode(); void GetDynamicRange(); void GetThresholdEnergy(); void GetThresholdEnergies(); @@ -58,5 +63,16 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { UNINITIALIZED, NUMSETTINGS }; + + enum { + DYNAMIC_GAIN_MODE, + FORCE_SWITCH_G1, + FORCE_SWITCH_G2, + FIX_G1, + FIX_G2, + FIX_G0 + }; + bool isVisibleFixG0{false}; + enum { DYNAMICRANGE_32, DYNAMICRANGE_16, DYNAMICRANGE_8, DYNAMICRANGE_4 }; }; diff --git a/slsDetectorGui/src/qDetectorMain.cpp b/slsDetectorGui/src/qDetectorMain.cpp index 2ca2c1291..634def39e 100644 --- a/slsDetectorGui/src/qDetectorMain.cpp +++ b/slsDetectorGui/src/qDetectorMain.cpp @@ -340,6 +340,7 @@ void qDetectorMain::EnableModes(QAction *action) { actionLoadTrimbits->setVisible(enable && (detType == slsDetectorDefs::EIGER || detType == slsDetectorDefs::MYTHEN3)); + tabSettings->SetExportMode(enable); LOG(logINFO) << "Expert Mode: " << qDefs::stringEnable(enable); } diff --git a/slsDetectorGui/src/qTabSettings.cpp b/slsDetectorGui/src/qTabSettings.cpp index dd9753083..0181667b7 100644 --- a/slsDetectorGui/src/qTabSettings.cpp +++ b/slsDetectorGui/src/qTabSettings.cpp @@ -98,7 +98,16 @@ void qTabSettings::SetupWidgetWindow() { Refresh(); } +void qTabSettings::SetExportMode(bool exportMode) { + if (comboGainMode->isVisible()) { + ShowFixG0(exportMode); + } +} + void qTabSettings::SetupDetectorSettings() { + comboSettings->setCurrentIndex(UNINITIALIZED); + + // enable only those available to detector QStandardItemModel *model = qobject_cast(comboSettings->model()); const int numSettings = comboSettings->count(); @@ -123,14 +132,26 @@ void qTabSettings::SetupDetectorSettings() { } void qTabSettings::SetupGainMode() { - try { - auto list = det->getGainModeList(); - for (auto it : list) { - comboGainMode->addItem(sls::ToString(it).c_str()); - } + comboGainMode->setCurrentIndex(DYNAMIC_GAIN_MODE); + ShowFixG0(false); +} + +void qTabSettings::ShowFixG0(bool expertMode) { + LOG(logINFO) << (expertMode ? "Showing" : "Hiding") << " FIX_G0"; + + // enable.disable Fix G0 + QStandardItemModel *model = + qobject_cast(comboGainMode->model()); + const int numSettings = comboGainMode->count(); + if (model) { + std::vector index(numSettings); + std::vector item(numSettings); + index[FIX_G0] = model->index(FIX_G0, comboGainMode->modelColumn(), + comboGainMode->rootModelIndex()); + item[FIX_G0] = model->itemFromIndex(index[FIX_G0]); + item[FIX_G0]->setEnabled(expertMode); } - CATCH_DISPLAY(std::string("Could not setup gain mode"), - "qTabSettings::SetupGainMode") + isVisibleFixG0 = expertMode; } void qTabSettings::Initialization() { @@ -138,6 +159,10 @@ void qTabSettings::Initialization() { if (comboSettings->isEnabled()) connect(comboSettings, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSettings(int))); + // Gain mode + if (comboGainMode->isEnabled()) + connect(comboGainMode, SIGNAL(currentIndexChanged(int)), this, + SLOT(SetGainMode(int))); // Dynamic Range if (comboDynamicRange->isEnabled()) @@ -209,6 +234,60 @@ void qTabSettings::SetSettings(int index) { } } +void qTabSettings::GetGainMode() { + LOG(logDEBUG) << "Getting gain mode"; + disconnect(comboGainMode, SIGNAL(currentIndexChanged(int)), this, + SLOT(SetGainMode(int))); + try { + auto retval = det->getGainMode().tsquash( + "Inconsistent gain mode for all detectors."); + if ((int)retval < 0 || (int)retval >= comboGainMode->count()) { + throw sls::RuntimeError(std::string("Unknown gain mode: ") + + std::to_string(retval)); + } + // warning when using fix_g0 and not in export mode + if ((int)retval == FIX_G0 && !isVisibleFixG0) { + std::string message = + "You are not in Expert Mode and Gain Mode is in FIX_G0. " + "
Could damage the detector when used without " + "caution! "; + qDefs::Message(qDefs::WARNING, message, + "qTabSettings::GetGainMode"); + LOG(logWARNING) << message; + } + comboGainMode->setCurrentIndex((int)retval); + } + CATCH_DISPLAY("Could not get gain mode.", "qTabSettings::GetGainMode") + connect(comboGainMode, SIGNAL(currentIndexChanged(int)), this, + SLOT(SetGainMode(int))); +} + +void qTabSettings::SetGainMode(int index) { + // warning for fix_G0 even in export mode + if (index == FIX_G0) { + if (qDefs::Message( + qDefs::QUESTION, + "You are in Export mode, " + "
but setting Gain Mode to FIX_G0 could " + "damage the detector!
Proceed and set " + "gainmode to FIX_G0 anyway?", + "qTabSettings::SetGainMode") == slsDetectorDefs::FAIL) { + GetGainMode(); + return; + } + } + + LOG(logINFO) << "Setting Gain Mode to " + << comboGainMode->currentText().toAscii().data(); + auto val = static_cast(index); + try { + + det->setGainMode(val); + } + CATCH_HANDLE("Could not set gain mode.", "qTabSettings::SetGainMode", this, + &qTabSettings::GetGainMode) +} + void qTabSettings::GetDynamicRange() { LOG(logDEBUG) << "Getting dynamic range"; disconnect(comboDynamicRange, SIGNAL(activated(int)), this, @@ -381,6 +460,10 @@ void qTabSettings::Refresh() { GetSettings(); } + if (comboGainMode->isEnabled()) { + GetGainMode(); + } + if (comboDynamicRange->isEnabled()) { GetDynamicRange(); }