Merge pull request #252 from slsdetectorgroup/guicounters

added counters for m3 gui
This commit is contained in:
Dhanya Thattil
2021-06-11 09:24:58 +02:00
committed by GitHub
3 changed files with 304 additions and 140 deletions

View File

@ -32,8 +32,85 @@
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="4"> <item row="3" column="3">
<widget class="QSpinBox" name="spinThreshold3"> <widget class="QCheckBox" name="chkCounter2">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>2</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="4">
<widget class="QCheckBox" name="chkCounter3">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>3</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="2" colspan="3">
<widget class="QComboBox" name="comboDynamicRange">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>140</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>140</width>
<height>16777215</height>
</size>
</property>
<item>
<property name="text">
<string>1.67772e+07</string>
</property>
</item>
<item>
<property name="text">
<string>65535</string>
</property>
</item>
<item>
<property name="text">
<string>255</string>
</property>
</item>
<item>
<property name="text">
<string>7</string>
</property>
</item>
</widget>
</item>
<item row="1" column="2" colspan="3">
<widget class="QSpinBox" name="spinThreshold">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -69,8 +146,8 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="2"> <item row="1" column="6">
<widget class="QSpinBox" name="spinThreshold"> <widget class="QSpinBox" name="spinThreshold3">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -128,7 +205,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="2"> <item row="4" column="2">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -144,46 +221,7 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="2" column="2"> <item row="1" column="8">
<widget class="QComboBox" name="comboDynamicRange">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>140</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>140</width>
<height>16777215</height>
</size>
</property>
<item>
<property name="text">
<string>1.67772e+07</string>
</property>
</item>
<item>
<property name="text">
<string>65535</string>
</property>
</item>
<item>
<property name="text">
<string>255</string>
</property>
</item>
<item>
<property name="text">
<string>7</string>
</property>
</item>
</widget>
</item>
<item row="1" column="6">
<widget class="QPushButton" name="btnSetThreshold"> <widget class="QPushButton" name="btnSetThreshold">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
@ -280,7 +318,139 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblThreshold">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>110</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Threshold:</string>
</property>
</widget>
</item>
<item row="1" column="5">
<widget class="QSpinBox" name="spinThreshold2">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>140</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>140</width>
<height>16777215</height>
</size>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
<property name="suffix">
<string> eV</string>
</property>
<property name="minimum">
<number>-100000</number>
</property>
<property name="maximum">
<number>100000</number>
</property>
<property name="singleStep">
<number>100</number>
</property>
<property name="value">
<number>-1</number>
</property>
</widget>
</item>
<item row="1" column="9">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lblCounter">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>110</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Counters:</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QCheckBox" name="chkCounter1">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>1</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="2" colspan="3">
<widget class="QComboBox" name="comboSettings"> <widget class="QComboBox" name="comboSettings">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
@ -424,97 +594,6 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblThreshold">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>110</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Threshold:</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QSpinBox" name="spinThreshold2">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>140</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>140</width>
<height>16777215</height>
</size>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
<property name="suffix">
<string> eV</string>
</property>
<property name="minimum">
<number>-100000</number>
</property>
<property name="maximum">
<number>100000</number>
</property>
<property name="singleStep">
<number>100</number>
</property>
<property name="value">
<number>-1</number>
</property>
</widget>
</item>
<item row="1" column="7">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
<tabstops> <tabstops>
@ -523,7 +602,6 @@
<tabstop>spinThreshold2</tabstop> <tabstop>spinThreshold2</tabstop>
<tabstop>spinThreshold3</tabstop> <tabstop>spinThreshold3</tabstop>
<tabstop>btnSetThreshold</tabstop> <tabstop>btnSetThreshold</tabstop>
<tabstop>comboDynamicRange</tabstop>
</tabstops> </tabstops>
<resources> <resources>
<include location="../include/icons.qrc"/> <include location="../include/icons.qrc"/>

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "sls/Detector.h" #include "sls/Detector.h"
#include "ui_form_tab_settings.h" #include "ui_form_tab_settings.h"
#include <QCheckBox>
class qTabSettings : public QWidget, private Ui::TabSettingsObject { class qTabSettings : public QWidget, private Ui::TabSettingsObject {
Q_OBJECT Q_OBJECT
@ -15,6 +16,7 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject {
void SetDynamicRange(int index); void SetDynamicRange(int index);
void SetThresholdEnergy(int index); void SetThresholdEnergy(int index);
void SetThresholdEnergies(); void SetThresholdEnergies();
void SetCounterMask();
private: private:
void SetupWidgetWindow(); void SetupWidgetWindow();
@ -25,8 +27,11 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject {
void GetDynamicRange(); void GetDynamicRange();
void GetThresholdEnergy(); void GetThresholdEnergy();
void GetThresholdEnergies(); void GetThresholdEnergies();
void GetCounterMask();
sls::Detector *det; sls::Detector *det;
std::vector<QCheckBox *> counters;
enum { enum {
STANDARD, STANDARD,
FAST, FAST,

View File

@ -1,6 +1,7 @@
#include "qTabSettings.h" #include "qTabSettings.h"
#include "qDefs.h" #include "qDefs.h"
#include "sls/ToString.h" #include "sls/ToString.h"
#include "sls/bit_utils.h"
#include <QStandardItemModel> #include <QStandardItemModel>
qTabSettings::qTabSettings(QWidget *parent, sls::Detector *detector) qTabSettings::qTabSettings(QWidget *parent, sls::Detector *detector)
@ -14,10 +15,21 @@ qTabSettings::~qTabSettings() {}
void qTabSettings::SetupWidgetWindow() { void qTabSettings::SetupWidgetWindow() {
counters = std::vector<QCheckBox *>{chkCounter1, chkCounter2, chkCounter3};
spinThreshold2->hide(); spinThreshold2->hide();
spinThreshold3->hide(); spinThreshold3->hide();
btnSetThreshold->hide(); btnSetThreshold->hide();
btnSetThreshold->setEnabled(false); 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 // enabling according to det type
slsDetectorDefs::detectorType detType = det->getDetectorType().squash(); slsDetectorDefs::detectorType detType = det->getDetectorType().squash();
if (detType == slsDetectorDefs::MYTHEN3) { if (detType == slsDetectorDefs::MYTHEN3) {
@ -32,6 +44,16 @@ void qTabSettings::SetupWidgetWindow() {
spinThreshold3->setEnabled(true); spinThreshold3->setEnabled(true);
btnSetThreshold->setEnabled(true); btnSetThreshold->setEnabled(true);
btnSetThreshold->show(); btnSetThreshold->show();
lblCounter->show();
lblCounter->setEnabled(true);
chkCounter1->setEnabled(true);
chkCounter2->setEnabled(true);
chkCounter3->setEnabled(true);
chkCounter1->show();
chkCounter2->show();
chkCounter3->show();
// disable dr // disable dr
QStandardItemModel *model = QStandardItemModel *model =
qobject_cast<QStandardItemModel *>(comboDynamicRange->model()); qobject_cast<QStandardItemModel *>(comboDynamicRange->model());
@ -153,6 +175,16 @@ void qTabSettings::Initialization() {
else if (spinThreshold->isEnabled()) else if (spinThreshold->isEnabled())
connect(spinThreshold, SIGNAL(valueChanged(int)), this, connect(spinThreshold, SIGNAL(valueChanged(int)), this,
SLOT(SetThresholdEnergy(int))); 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() { void qTabSettings::GetSettings() {
@ -269,7 +301,7 @@ void qTabSettings::GetThresholdEnergies() {
spinThreshold3->setValue(retval[2]); spinThreshold3->setValue(retval[2]);
} }
CATCH_DISPLAY("Could not get threshold energy.", CATCH_DISPLAY("Could not get threshold energy.",
"qTabDataOutput::GetThresholdEnergies") "qTabSettings::GetThresholdEnergies")
connect(btnSetThreshold, SIGNAL(clicked()), this, connect(btnSetThreshold, SIGNAL(clicked()), this,
SLOT(SetThresholdEnergies())); SLOT(SetThresholdEnergies()));
} }
@ -284,7 +316,7 @@ void qTabSettings::GetThresholdEnergy() {
spinThreshold->setValue(retval); spinThreshold->setValue(retval);
} }
CATCH_DISPLAY("Could not get threshold energy.", CATCH_DISPLAY("Could not get threshold energy.",
"qTabDataOutput::GetThresholdEnergy") "qTabSettings::GetThresholdEnergy")
connect(spinThreshold, SIGNAL(valueChanged(int)), this, connect(spinThreshold, SIGNAL(valueChanged(int)), this,
SLOT(SetThresholdEnergy(int))); SLOT(SetThresholdEnergy(int)));
} }
@ -317,6 +349,51 @@ void qTabSettings::SetThresholdEnergy(int index) {
GetThresholdEnergy(); 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."));
// default to unchecked
std::for_each(counters, [](auto &i) { i.setChecked(false); });
// std::for_each(counters.begin(), counters.end(), )
// if retval[i] = 2, chkCounter2 is checked
for (auto i : retval) {
if (i > 3) {
throw sls::RuntimeError(
std::string("Unknown counter index : ") +
std::to_string(static_cast<int>(i)));
}
counters[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() {
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() { void qTabSettings::Refresh() {
LOG(logDEBUG) << "**Updating Settings Tab"; LOG(logDEBUG) << "**Updating Settings Tab";
@ -337,5 +414,9 @@ void qTabSettings::Refresh() {
GetThresholdEnergy(); GetThresholdEnergy();
} }
if (lblCounter->isEnabled()) {
GetCounterMask();
}
LOG(logDEBUG) << "**Updated Settings Tab"; LOG(logDEBUG) << "**Updated Settings Tab";
} }