From f01e5fd5ec5d0e9011141dd45fdcc9a74672632f Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 10 Jun 2021 18:07:52 +0200 Subject: [PATCH] moved counters in gui from data output tab to settings tab --- slsDetectorGui/forms/form_tab_dataoutput.ui | 55 --- slsDetectorGui/forms/form_tab_settings.ui | 354 ++++++++++++-------- slsDetectorGui/include/qTabDataOutput.h | 2 - slsDetectorGui/include/qTabSettings.h | 2 + slsDetectorGui/src/qTabDataOutput.cpp | 76 ----- slsDetectorGui/src/qTabSettings.cpp | 88 ++++- 6 files changed, 304 insertions(+), 273 deletions(-) diff --git a/slsDetectorGui/forms/form_tab_dataoutput.ui b/slsDetectorGui/forms/form_tab_dataoutput.ui index c102d8c49..a7b0bb707 100755 --- a/slsDetectorGui/forms/form_tab_dataoutput.ui +++ b/slsDetectorGui/forms/form_tab_dataoutput.ui @@ -533,61 +533,6 @@ Directory where one saves the data. - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 10 - 20 - - - - - - - - false - - - Counter 1 - - - true - - - - - - - false - - - Counter 2 - - - true - - - - - - - false - - - Counter 3 - - - true - - - diff --git a/slsDetectorGui/forms/form_tab_settings.ui b/slsDetectorGui/forms/form_tab_settings.ui index 7f44f601a..2f20a5edb 100755 --- a/slsDetectorGui/forms/form_tab_settings.ui +++ b/slsDetectorGui/forms/form_tab_settings.ui @@ -32,8 +32,85 @@ Form - - + + + + false + + + + 50 + 16777215 + + + + 2 + + + true + + + + + + + false + + + + 50 + 16777215 + + + + 3 + + + true + + + + + + + false + + + + 140 + 25 + + + + + 140 + 16777215 + + + + + 1.67772e+07 + + + + + 65535 + + + + + 255 + + + + + 7 + + + + + + false @@ -69,8 +146,8 @@ - - + + false @@ -128,7 +205,7 @@ - + Qt::Vertical @@ -144,46 +221,7 @@ - - - - false - - - - 140 - 25 - - - - - 140 - 16777215 - - - - - 1.67772e+07 - - - - - 65535 - - - - - 255 - - - - - 7 - - - - - + true @@ -280,7 +318,139 @@ - + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + false + + + + 110 + 0 + + + + + 110 + 16777215 + + + + Threshold: + + + + + + + false + + + + 140 + 25 + + + + + 140 + 16777215 + + + + false + + + eV + + + -100000 + + + 100000 + + + 100 + + + -1 + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 20 + 20 + + + + + + + + false + + + + 110 + 0 + + + + + 110 + 16777215 + + + + Counters: + + + + + + + false + + + + 50 + 16777215 + + + + 1 + + + true + + + + true @@ -424,97 +594,6 @@ - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - false - - - - 110 - 0 - - - - - 110 - 16777215 - - - - Threshold: - - - - - - - false - - - - 140 - 25 - - - - - 140 - 16777215 - - - - false - - - eV - - - -100000 - - - 100000 - - - 100 - - - -1 - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - @@ -523,7 +602,6 @@ spinThreshold2 spinThreshold3 btnSetThreshold - comboDynamicRange diff --git a/slsDetectorGui/include/qTabDataOutput.h b/slsDetectorGui/include/qTabDataOutput.h index 35d088268..8f753a6db 100644 --- a/slsDetectorGui/include/qTabDataOutput.h +++ b/slsDetectorGui/include/qTabDataOutput.h @@ -22,7 +22,6 @@ class qTabDataOutput : public QWidget, private Ui::TabDataOutputObject { void SetRateCorrection(); void SetSpeed(int speed); void SetParallel(bool enable); - void SetCounterMask(); private: void SetupWidgetWindow(); @@ -37,7 +36,6 @@ class qTabDataOutput : public QWidget, private Ui::TabDataOutputObject { void GetRateCorrection(); void GetSpeed(); void GetParallel(); - void GetCounterMask(); sls::Detector *det; // Button group for radiobuttons for rate diff --git a/slsDetectorGui/include/qTabSettings.h b/slsDetectorGui/include/qTabSettings.h index 2effd00bb..abd3389d5 100644 --- a/slsDetectorGui/include/qTabSettings.h +++ b/slsDetectorGui/include/qTabSettings.h @@ -15,6 +15,7 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { void SetDynamicRange(int index); void SetThresholdEnergy(int index); void SetThresholdEnergies(); + void SetCounterMask(); private: void SetupWidgetWindow(); @@ -25,6 +26,7 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { void GetDynamicRange(); void GetThresholdEnergy(); void GetThresholdEnergies(); + void GetCounterMask(); sls::Detector *det; enum { diff --git a/slsDetectorGui/src/qTabDataOutput.cpp b/slsDetectorGui/src/qTabDataOutput.cpp index cc095753e..f750b7cba 100644 --- a/slsDetectorGui/src/qTabDataOutput.cpp +++ b/slsDetectorGui/src/qTabDataOutput.cpp @@ -1,9 +1,7 @@ #include "qTabDataOutput.h" #include "qDefs.h" -#include "sls/bit_utils.h" #include -#include #include #include #include @@ -25,12 +23,6 @@ void qTabDataOutput::SetupWidgetWindow() { btnGroupRate = new QButtonGroup(this); btnGroupRate->addButton(radioDefaultDeadtime, 0); btnGroupRate->addButton(radioCustomDeadtime, 1); - chkCounter1->setEnabled(false); - chkCounter2->setEnabled(false); - chkCounter3->setEnabled(false); - chkCounter1->hide(); - chkCounter2->hide(); - chkCounter3->hide(); // enabling according to det type switch (det->getDetectorType().squash()) { @@ -49,12 +41,6 @@ void qTabDataOutput::SetupWidgetWindow() { break; case slsDetectorDefs::MYTHEN3: chkParallel->setEnabled(true); - chkCounter1->setEnabled(true); - chkCounter2->setEnabled(true); - chkCounter3->setEnabled(true); - chkCounter1->show(); - chkCounter2->show(); - chkCounter3->show(); break; case slsDetectorDefs::JUNGFRAU: lblClkDivider->setEnabled(true); @@ -101,14 +87,6 @@ void qTabDataOutput::Initialization() { connect(chkParallel, SIGNAL(toggled(bool)), this, SLOT(SetParallel(bool))); } - if (chkCounter1->isEnabled()) { - connect(chkCounter1, SIGNAL(toggled(bool)), this, - SLOT(SetCounterMask())); - connect(chkCounter2, SIGNAL(toggled(bool)), this, - SLOT(SetCounterMask())); - connect(chkCounter3, SIGNAL(toggled(bool)), this, - SLOT(SetCounterMask())); - } // speed if (comboClkDivider->isEnabled()) { connect(comboClkDivider, SIGNAL(currentIndexChanged(int)), this, @@ -438,57 +416,6 @@ void qTabDataOutput::SetParallel(bool enable) { &qTabDataOutput::GetParallel) } -void qTabDataOutput::GetCounterMask() { - LOG(logDEBUG) << "Getting counter mask"; - disconnect(chkCounter1, SIGNAL(toggled(bool)), this, - SLOT(SetCounterMask())); - disconnect(chkCounter2, SIGNAL(toggled(bool)), this, - SLOT(SetCounterMask())); - disconnect(chkCounter3, SIGNAL(toggled(bool)), this, - SLOT(SetCounterMask())); - try { - auto retval = sls::getSetBits(det->getCounterMask().tsquash( - "Counter mask is inconsistent for all detectors.")); - std::vector counters = {chkCounter1, chkCounter2, - chkCounter3}; - // default to unchecked - for (unsigned int i = 0; i < counters.size(); ++i) { - counters[i]->setChecked(false); - } - // if retva[i] = 2, chkCounter2 is checked - for (unsigned int i = 0; i < retval.size(); ++i) { - if (retval[i] > 3) { - throw sls::RuntimeError( - std::string("Unknown counter index : ") + - std::to_string(static_cast(retval[i]))); - } - counters[retval[i]]->setChecked(true); - } - } - CATCH_DISPLAY("Could not get parallel readout.", - "qTabDataOutput::GetParallel") - connect(chkCounter1, SIGNAL(toggled(bool)), this, SLOT(SetCounterMask())); - connect(chkCounter2, SIGNAL(toggled(bool)), this, SLOT(SetCounterMask())); - connect(chkCounter3, SIGNAL(toggled(bool)), this, SLOT(SetCounterMask())); -} - -void qTabDataOutput::SetCounterMask() { - std::vector counters = {chkCounter1, chkCounter2, chkCounter3}; - uint32_t mask = 0; - for (unsigned int i = 0; i < counters.size(); ++i) { - if (counters[i]->isChecked()) { - mask |= (1 << i); - } - } - LOG(logINFO) << "Setting counter mask to " << mask; - try { - det->setCounterMask(mask); - } - CATCH_HANDLE("Could not set counter mask.", - "qTabDataOutput::SetCounterMask", this, - &qTabDataOutput::GetCounterMask) -} - void qTabDataOutput::Refresh() { LOG(logDEBUG) << "**Updating DataOutput Tab"; @@ -507,9 +434,6 @@ void qTabDataOutput::Refresh() { if (chkParallel->isEnabled()) { GetParallel(); } - if (chkCounter1->isEnabled()) { - GetCounterMask(); - } if (comboClkDivider->isEnabled()) { GetSpeed(); } diff --git a/slsDetectorGui/src/qTabSettings.cpp b/slsDetectorGui/src/qTabSettings.cpp index 504f80b71..008f11133 100644 --- a/slsDetectorGui/src/qTabSettings.cpp +++ b/slsDetectorGui/src/qTabSettings.cpp @@ -1,6 +1,8 @@ #include "qTabSettings.h" #include "qDefs.h" #include "sls/ToString.h" +#include "sls/bit_utils.h" +#include #include qTabSettings::qTabSettings(QWidget *parent, sls::Detector *detector) @@ -18,6 +20,15 @@ void qTabSettings::SetupWidgetWindow() { spinThreshold3->hide(); btnSetThreshold->hide(); btnSetThreshold->setEnabled(false); + lblCounter->hide(); + lblCounter->setEnabled(false); + chkCounter1->setEnabled(false); + chkCounter2->setEnabled(false); + chkCounter3->setEnabled(false); + chkCounter1->hide(); + chkCounter2->hide(); + chkCounter3->hide(); + // enabling according to det type slsDetectorDefs::detectorType detType = det->getDetectorType().squash(); if (detType == slsDetectorDefs::MYTHEN3) { @@ -32,6 +43,16 @@ void qTabSettings::SetupWidgetWindow() { spinThreshold3->setEnabled(true); btnSetThreshold->setEnabled(true); btnSetThreshold->show(); + + lblCounter->show(); + lblCounter->setEnabled(true); + chkCounter1->setEnabled(true); + chkCounter2->setEnabled(true); + chkCounter3->setEnabled(true); + chkCounter1->show(); + chkCounter2->show(); + chkCounter3->show(); + // disable dr QStandardItemModel *model = qobject_cast(comboDynamicRange->model()); @@ -153,6 +174,16 @@ void qTabSettings::Initialization() { else if (spinThreshold->isEnabled()) connect(spinThreshold, SIGNAL(valueChanged(int)), this, SLOT(SetThresholdEnergy(int))); + + // counters + if (lblCounter->isEnabled()) { + connect(chkCounter1, SIGNAL(toggled(bool)), this, + SLOT(SetCounterMask())); + connect(chkCounter2, SIGNAL(toggled(bool)), this, + SLOT(SetCounterMask())); + connect(chkCounter3, SIGNAL(toggled(bool)), this, + SLOT(SetCounterMask())); + } } void qTabSettings::GetSettings() { @@ -269,7 +300,7 @@ void qTabSettings::GetThresholdEnergies() { spinThreshold3->setValue(retval[2]); } CATCH_DISPLAY("Could not get threshold energy.", - "qTabDataOutput::GetThresholdEnergies") + "qTabSettings::GetThresholdEnergies") connect(btnSetThreshold, SIGNAL(clicked()), this, SLOT(SetThresholdEnergies())); } @@ -284,7 +315,7 @@ void qTabSettings::GetThresholdEnergy() { spinThreshold->setValue(retval); } CATCH_DISPLAY("Could not get threshold energy.", - "qTabDataOutput::GetThresholdEnergy") + "qTabSettings::GetThresholdEnergy") connect(spinThreshold, SIGNAL(valueChanged(int)), this, SLOT(SetThresholdEnergy(int))); } @@ -317,6 +348,55 @@ void qTabSettings::SetThresholdEnergy(int index) { GetThresholdEnergy(); } +void qTabSettings::GetCounterMask() { + LOG(logDEBUG) << "Getting counter mask"; + disconnect(chkCounter1, SIGNAL(toggled(bool)), this, + SLOT(SetCounterMask())); + disconnect(chkCounter2, SIGNAL(toggled(bool)), this, + SLOT(SetCounterMask())); + disconnect(chkCounter3, SIGNAL(toggled(bool)), this, + SLOT(SetCounterMask())); + try { + auto retval = sls::getSetBits(det->getCounterMask().tsquash( + "Counter mask is inconsistent for all detectors.")); + std::vector counters = {chkCounter1, chkCounter2, + chkCounter3}; + // default to unchecked + for (unsigned int i = 0; i < counters.size(); ++i) { + counters[i]->setChecked(false); + } + // if retva[i] = 2, chkCounter2 is checked + for (unsigned int i = 0; i < retval.size(); ++i) { + if (retval[i] > 3) { + throw sls::RuntimeError( + std::string("Unknown counter index : ") + + std::to_string(static_cast(retval[i]))); + } + counters[retval[i]]->setChecked(true); + } + } + CATCH_DISPLAY("Could not get counter mask.", "qTabSettings::GetCounterMask") + connect(chkCounter1, SIGNAL(toggled(bool)), this, SLOT(SetCounterMask())); + connect(chkCounter2, SIGNAL(toggled(bool)), this, SLOT(SetCounterMask())); + connect(chkCounter3, SIGNAL(toggled(bool)), this, SLOT(SetCounterMask())); +} + +void qTabSettings::SetCounterMask() { + std::vector counters = {chkCounter1, chkCounter2, chkCounter3}; + uint32_t mask = 0; + for (unsigned int i = 0; i < counters.size(); ++i) { + if (counters[i]->isChecked()) { + mask |= (1 << i); + } + } + LOG(logINFO) << "Setting counter mask to " << mask; + try { + det->setCounterMask(mask); + } + CATCH_HANDLE("Could not set counter mask.", "qTabSettings::SetCounterMask", + this, &qTabSettings::GetCounterMask) +} + void qTabSettings::Refresh() { LOG(logDEBUG) << "**Updating Settings Tab"; @@ -337,5 +417,9 @@ void qTabSettings::Refresh() { GetThresholdEnergy(); } + if (lblCounter->isEnabled()) { + GetCounterMask(); + } + LOG(logDEBUG) << "**Updated Settings Tab"; }