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
commit 621bb6cbfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 304 additions and 140 deletions

View File

@ -32,8 +32,85 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="4">
<widget class="QSpinBox" name="spinThreshold3">
<item row="3" column="3">
<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">
<bool>false</bool>
</property>
@ -69,8 +146,8 @@
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="spinThreshold">
<item row="1" column="6">
<widget class="QSpinBox" name="spinThreshold3">
<property name="enabled">
<bool>false</bool>
</property>
@ -128,7 +205,7 @@
</property>
</widget>
</item>
<item row="3" column="2">
<item row="4" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -144,46 +221,7 @@
</property>
</spacer>
</item>
<item row="2" column="2">
<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">
<item row="1" column="8">
<widget class="QPushButton" name="btnSetThreshold">
<property name="enabled">
<bool>true</bool>
@ -280,7 +318,139 @@
</property>
</widget>
</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">
<property name="enabled">
<bool>true</bool>
@ -424,97 +594,6 @@
</item>
</widget>
</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>
</widget>
<tabstops>
@ -523,7 +602,6 @@
<tabstop>spinThreshold2</tabstop>
<tabstop>spinThreshold3</tabstop>
<tabstop>btnSetThreshold</tabstop>
<tabstop>comboDynamicRange</tabstop>
</tabstops>
<resources>
<include location="../include/icons.qrc"/>

View File

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

View File

@ -1,6 +1,7 @@
#include "qTabSettings.h"
#include "qDefs.h"
#include "sls/ToString.h"
#include "sls/bit_utils.h"
#include <QStandardItemModel>
qTabSettings::qTabSettings(QWidget *parent, sls::Detector *detector)
@ -14,10 +15,21 @@ qTabSettings::~qTabSettings() {}
void qTabSettings::SetupWidgetWindow() {
counters = std::vector<QCheckBox *>{chkCounter1, chkCounter2, chkCounter3};
spinThreshold2->hide();
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 +44,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<QStandardItemModel *>(comboDynamicRange->model());
@ -153,6 +175,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 +301,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 +316,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 +349,51 @@ 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."));
// 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() {
LOG(logDEBUG) << "**Updating Settings Tab";
@ -337,5 +414,9 @@ void qTabSettings::Refresh() {
GetThresholdEnergy();
}
if (lblCounter->isEnabled()) {
GetCounterMask();
}
LOG(logDEBUG) << "**Updated Settings Tab";
}