clang format on gui

This commit is contained in:
Erik Frojdh
2020-03-10 10:18:52 +01:00
parent bd6529a64c
commit 9ede0629ef
34 changed files with 3813 additions and 3060 deletions

91
slsDetectorGui/src/qCloneWidget.cpp Executable file → Normal file
View File

@ -1,7 +1,7 @@
#include "qCloneWidget.h"
#include "qDefs.h"
#include "SlsQt1DPlot.h"
#include "SlsQt2DPlot.h"
#include "qDefs.h"
#include <QCloseEvent>
#include <QFileDialog>
@ -11,35 +11,39 @@
int qCloneWidget::NumClones{0};
qCloneWidget::qCloneWidget(QWidget *parent, SlsQt1DPlot* p1, SlsQt2DPlot* p2, SlsQt1DPlot *gp1, SlsQt2DPlot* gp,
QString title, QString fPath, QString fName, int64_t aIndex,
bool displayStats, QString min, QString max, QString sum):
QMainWindow(parent), plot1d(p1), plot2d(p2), gainplot1d(gp1), gainplot2d(gp), filePath(fPath), fileName(fName), acqIndex(aIndex) {
setupUi(this);
id = qCloneWidget::NumClones++;
qCloneWidget::qCloneWidget(QWidget *parent, SlsQt1DPlot *p1, SlsQt2DPlot *p2,
SlsQt1DPlot *gp1, SlsQt2DPlot *gp, QString title,
QString fPath, QString fName, int64_t aIndex,
bool displayStats, QString min, QString max,
QString sum)
: QMainWindow(parent), plot1d(p1), plot2d(p2), gainplot1d(gp1),
gainplot2d(gp), filePath(fPath), fileName(fName), acqIndex(aIndex) {
setupUi(this);
id = qCloneWidget::NumClones++;
SetupWidgetWindow(title);
DisplayStats(displayStats, min, max, sum);
}
qCloneWidget::~qCloneWidget() {
delete plot1d;
delete plot2d;
delete gainplot1d;
delete gainplot2d;
delete plot1d;
delete plot2d;
delete gainplot1d;
delete gainplot2d;
}
void qCloneWidget::SetupWidgetWindow(QString title) {
std::string winTitle = std::string("Snapshot:") + std::to_string(id) + std::string(" - ") + NowTime();
std::string winTitle = std::string("Snapshot:") + std::to_string(id) +
std::string(" - ") + NowTime();
setWindowTitle(QString(winTitle.c_str()));
boxPlot->setFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
boxPlot->setTitle(title);
// 1d
if (plot1d != nullptr) {
if (gainplot1d == nullptr) {
@ -49,7 +53,7 @@ void qCloneWidget::SetupWidgetWindow(QString title) {
plotLayout->addWidget(plot1d, 0, 0, ratio, ratio);
plotLayout->addWidget(gainplot1d, ratio, 0, 1, ratio, Qt::AlignTop);
}
}
}
// 2d
else {
if (gainplot2d == nullptr) {
@ -57,7 +61,8 @@ void qCloneWidget::SetupWidgetWindow(QString title) {
} else {
int ratio = qDefs::DATA_GAIN_PLOT_RATIO - 1;
plotLayout->addWidget(plot2d, 0, 0, ratio, ratio);
plotLayout->addWidget(gainplot2d, 0, ratio, 1, 1, Qt::AlignRight | Qt::AlignTop);
plotLayout->addWidget(gainplot2d, 0, ratio, 1, 1,
Qt::AlignRight | Qt::AlignTop);
}
}
connect(actionSaveClone, SIGNAL(triggered()), this, SLOT(SavePlot()));
@ -65,15 +70,19 @@ void qCloneWidget::SetupWidgetWindow(QString title) {
if (gainplot1d != nullptr) {
gainplot1d->setMinimumHeight(qDefs::MIN_HEIGHT_GAIN_PLOT_1D);
gainplot1d->setFixedWidth(plot1d->width());
// gainplot1d->setFixedHeight(plot1d->height() / qDefs::DATA_GAIN_PLOT_RATIO - 1);
// gainplot1d->setFixedHeight(plot1d->height() /
// qDefs::DATA_GAIN_PLOT_RATIO - 1);
}
if (gainplot2d != nullptr) {
gainplot2d->setFixedWidth(plot2d->width() / qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedHeight(plot2d->height() / qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedWidth(plot2d->width() /
qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedHeight(plot2d->height() /
qDefs::DATA_GAIN_PLOT_RATIO);
}
}
void qCloneWidget::DisplayStats(bool enable, QString min, QString max, QString sum) {
void qCloneWidget::DisplayStats(bool enable, QString min, QString max,
QString sum) {
if (enable) {
lblMinDisp->setText(QString("%1").arg(min));
lblMaxDisp->setText(QString("%1").arg(max));
@ -87,21 +96,32 @@ void qCloneWidget::DisplayStats(bool enable, QString min, QString max, QString s
void qCloneWidget::SavePlot() {
char cID[10];
sprintf(cID, "%d", id);
//title
QString fName = filePath + QString('/') + fileName + QString("_clone") + QString("%1").arg(id) + QString("_acq") + QString("%1").arg(acqIndex) + QString(".png");
// title
QString fName = filePath + QString('/') + fileName + QString("_clone") +
QString("%1").arg(id) + QString("_acq") +
QString("%1").arg(acqIndex) + QString(".png");
FILE_LOG(logINFO) << "Saving Clone:" << fName.toAscii().constData();
//save
QImage img(centralwidget->size().width(), centralwidget->size().height(), QImage::Format_RGB32);
// save
QImage img(centralwidget->size().width(), centralwidget->size().height(),
QImage::Format_RGB32);
QPainter painter(&img);
centralwidget->render(&painter);
fName = QFileDialog::getSaveFileName(this, tr("Save Snapshot "), fName, tr("PNG Files (*.png);;XPM Files(*.xpm);;JPEG Files(*.jpg)"), 0, QFileDialog::ShowDirsOnly);
fName = QFileDialog::getSaveFileName(
this, tr("Save Snapshot "), fName,
tr("PNG Files (*.png);;XPM Files(*.xpm);;JPEG Files(*.jpg)"), 0,
QFileDialog::ShowDirsOnly);
if (!fName.isEmpty()) {
if ((img.save(fName))) {
qDefs::Message(qDefs::INFORMATION, "The SnapShot has been successfully saved", "qCloneWidget::SavePlot");
qDefs::Message(qDefs::INFORMATION,
"The SnapShot has been successfully saved",
"qCloneWidget::SavePlot");
FILE_LOG(logINFO) << "The SnapShot has been successfully saved";
} else {
qDefs::Message(qDefs::WARNING, "Attempt to save snapshot failed.\n Formats: .png, .jpg, .xpm.", "qCloneWidget::SavePlot");
qDefs::Message(
qDefs::WARNING,
"Attempt to save snapshot failed.\n Formats: .png, .jpg, .xpm.",
"qCloneWidget::SavePlot");
FILE_LOG(logWARNING) << "Attempt to save snapshot failed";
}
}
@ -110,11 +130,14 @@ void qCloneWidget::SavePlot() {
void qCloneWidget::resizeEvent(QResizeEvent *event) {
if (gainplot1d != nullptr) {
gainplot1d->setFixedWidth(plot1d->width());
gainplot1d->setFixedHeight(plot1d->height() / qDefs::DATA_GAIN_PLOT_RATIO);
gainplot1d->setFixedHeight(plot1d->height() /
qDefs::DATA_GAIN_PLOT_RATIO);
}
if (gainplot2d != nullptr) {
gainplot2d->setFixedWidth(plot2d->width() / qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedHeight(plot2d->height() / qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedWidth(plot2d->width() /
qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedHeight(plot2d->height() /
qDefs::DATA_GAIN_PLOT_RATIO);
}
event->accept();
}

116
slsDetectorGui/src/qDacWidget.cpp Executable file → Normal file
View File

@ -3,88 +3,92 @@
#include <iostream>
qDacWidget::qDacWidget(QWidget *parent, sls::Detector *detector, bool d, std::string n, slsDetectorDefs::dacIndex i) :
QWidget(parent), det(detector), isDac(d), index(i){
setupUi(this);
SetupWidgetWindow(n);
qDacWidget::qDacWidget(QWidget *parent, sls::Detector *detector, bool d,
std::string n, slsDetectorDefs::dacIndex i)
: QWidget(parent), det(detector), isDac(d), index(i) {
setupUi(this);
SetupWidgetWindow(n);
}
qDacWidget::~qDacWidget() {}
void qDacWidget::SetupWidgetWindow(std::string name) {
lblDac->setText(name.c_str());
if (isDac) {
spinDac->setDecimals(0);
} else {
spinDac->setSuffix(0x00b0 + QString("C"));
spinDac->setReadOnly(true);
lblDacmV->setMinimumWidth(0);
lblDacmV->setMaximumWidth(0);
}
Initialization();
Refresh();
lblDac->setText(name.c_str());
if (isDac) {
spinDac->setDecimals(0);
} else {
spinDac->setSuffix(0x00b0 + QString("C"));
spinDac->setReadOnly(true);
lblDacmV->setMinimumWidth(0);
lblDacmV->setMaximumWidth(0);
}
Initialization();
Refresh();
}
void qDacWidget::Initialization() {
if (isDac) {
connect(spinDac, SIGNAL(editingFinished()), this, SLOT(SetDac()));
}
if (isDac) {
connect(spinDac, SIGNAL(editingFinished()), this, SLOT(SetDac()));
}
}
void qDacWidget::SetDetectorIndex(int id) {
detectorIndex = id;
Refresh();
detectorIndex = id;
Refresh();
}
void qDacWidget::GetDac() {
FILE_LOG(logDEBUG) << "Getting Dac " << index;
FILE_LOG(logDEBUG) << "Getting Dac " << index;
disconnect(spinDac, SIGNAL(editingFinished()), this, SLOT(SetDac()));
try {
// dac units
auto retval = det->getDAC(index, 0, {detectorIndex}).squash(-1);
spinDac->setValue(retval);
// mv
retval = det->getDAC(index, 1, {detectorIndex}).squash(-1);
lblDacmV->setText(QString("%1mV").arg(retval -10));
} CATCH_DISPLAY(std::string("Could not get dac ") + std::to_string(index), "qDacWidget::GetDac")
disconnect(spinDac, SIGNAL(editingFinished()), this, SLOT(SetDac()));
try {
// dac units
auto retval = det->getDAC(index, 0, {detectorIndex}).squash(-1);
spinDac->setValue(retval);
// mv
retval = det->getDAC(index, 1, {detectorIndex}).squash(-1);
lblDacmV->setText(QString("%1mV").arg(retval - 10));
}
CATCH_DISPLAY(std::string("Could not get dac ") + std::to_string(index),
"qDacWidget::GetDac")
connect(spinDac, SIGNAL(editingFinished()), this, SLOT(SetDac()));
connect(spinDac, SIGNAL(editingFinished()), this, SLOT(SetDac()));
}
void qDacWidget::SetDac() {
int val = (int)spinDac->value();
FILE_LOG(logINFO) << "Setting dac:" << lblDac->text().toAscii().data() << " : " << val;
int val = (int)spinDac->value();
FILE_LOG(logINFO) << "Setting dac:" << lblDac->text().toAscii().data()
<< " : " << val;
try {
det->setDAC(index, val, 0, {detectorIndex});
} CATCH_DISPLAY (std::string("Could not set dac ") + std::to_string(index), "qDacWidget::SetDac")
// update mV anyway
try {
det->setDAC(index, val, 0, {detectorIndex});
}
CATCH_DISPLAY(std::string("Could not set dac ") + std::to_string(index),
"qDacWidget::SetDac")
// update mV anyway
GetDac();
}
void qDacWidget::GetAdc() {
FILE_LOG(logDEBUG) << "Getting ADC " << index;
try {
auto retval = det->getTemperature(index, {detectorIndex}).squash(-1);
if (retval == -1 && detectorIndex == -1) {
spinDac->setValue(-1);
} else {
spinDac->setValue(retval);
}
} CATCH_DISPLAY (std::string("Could not get adc ") + std::to_string(index), "qDacWidget::GetAdc")
FILE_LOG(logDEBUG) << "Getting ADC " << index;
try {
auto retval = det->getTemperature(index, {detectorIndex}).squash(-1);
if (retval == -1 && detectorIndex == -1) {
spinDac->setValue(-1);
} else {
spinDac->setValue(retval);
}
}
CATCH_DISPLAY(std::string("Could not get adc ") + std::to_string(index),
"qDacWidget::GetAdc")
}
void qDacWidget::Refresh() {
if (isDac) {
GetDac();
} else {
GetAdc();
}
if (isDac) {
GetDac();
} else {
GetAdc();
}
}

126
slsDetectorGui/src/qDetectorMain.cpp Executable file → Normal file
View File

@ -1,25 +1,24 @@
#include "qDetectorMain.h"
#include "qDefs.h"
#include "qDrawPlot.h"
#include "qTabMeasurement.h"
#include "qTabDataOutput.h"
#include "qTabPlot.h"
#include "qTabAdvanced.h"
#include "qTabSettings.h"
#include "qTabDataOutput.h"
#include "qTabDebugging.h"
#include "qTabDeveloper.h"
#include "qTabMeasurement.h"
#include "qTabMessages.h"
#include "qTabPlot.h"
#include "qTabSettings.h"
#include "versionAPI.h"
#include "ToString.h"
#include "versionAPI.h"
#include <QResizeEvent>
#include <QScrollArea>
#include <QFileDialog>
#include <QPlastiqueStyle>
#include <QResizeEvent>
#include <QScrollArea>
#include <QSizePolicy>
#include <iostream>
#include <getopt.h>
#include <iostream>
#include <string>
@ -94,10 +93,9 @@ int main(int argc, char **argv) {
}
}
QApplication app(argc, argv);
app.setStyle(new QPlastiqueStyle);
//app.setWindowIcon(QIcon(":/icons/images/mountain.png"));
// app.setWindowIcon(QIcon(":/icons/images/mountain.png"));
try {
qDetectorMain det(multiId, fname, isDeveloper);
det.show();
@ -133,7 +131,8 @@ void qDetectorMain::SetUpWidgetWindow() {
layoutTabs->addWidget(tabs.get());
// creating all the other tab widgets
tabMeasurement = sls::make_unique<qTabMeasurement>(this, det.get(), plot.get());
tabMeasurement =
sls::make_unique<qTabMeasurement>(this, det.get(), plot.get());
tabDataOutput = sls::make_unique<qTabDataOutput>(this, det.get());
tabPlot = sls::make_unique<qTabPlot>(this, det.get(), plot.get());
tabSettings = sls::make_unique<qTabSettings>(this, det.get());
@ -219,7 +218,8 @@ void qDetectorMain::SetUpDetector(const std::string fName, int multiID) {
LoadConfigFile(fName);
// validate detector type (for GUI) and update menu
detType = det->getDetectorType().tsquash("Different detector type for all modules.");
detType = det->getDetectorType().tsquash(
"Different detector type for all modules.");
actionLoadTrimbits->setEnabled(false);
switch (detType) {
case slsDetectorDefs::EIGER:
@ -230,18 +230,20 @@ void qDetectorMain::SetUpDetector(const std::string fName, int multiID) {
case slsDetectorDefs::MOENCH:
case slsDetectorDefs::MYTHEN3:
case slsDetectorDefs::GOTTHARD2:
break;
break;
default:
std::ostringstream os;
os << det->getHostname() << " has " <<
sls::ToString(det->getDetectorType().squash()) << " detector type (" <<
std::to_string(detType) << "). Exiting GUI.";
os << det->getHostname() << " has "
<< sls::ToString(det->getDetectorType().squash())
<< " detector type (" << std::to_string(detType)
<< "). Exiting GUI.";
std::string errorMess = os.str();
throw sls::RuntimeError(errorMess.c_str());
}
std::ostringstream os;
os << "SLS Detector GUI : " << sls::ToString(det->getDetectorType().squash())
<< " - " << det->getHostname();
os << "SLS Detector GUI : "
<< sls::ToString(det->getDetectorType().squash()) << " - "
<< det->getHostname();
std::string title = os.str();
FILE_LOG(logINFO) << title;
setWindowTitle(QString(title.c_str()));
@ -249,27 +251,36 @@ void qDetectorMain::SetUpDetector(const std::string fName, int multiID) {
void qDetectorMain::Initialization() {
// Dockable Plot
connect(dockWidgetPlot, SIGNAL(topLevelChanged(bool)), this, SLOT(ResizeMainWindow(bool)));
connect(dockWidgetPlot, SIGNAL(topLevelChanged(bool)), this,
SLOT(ResizeMainWindow(bool)));
// tabs
connect(tabs.get(),SIGNAL(currentChanged(int)), this, SLOT(Refresh(int)));//( QWidget*)));
connect(tabs.get(), SIGNAL(currentChanged(int)), this,
SLOT(Refresh(int))); //( QWidget*)));
// Measurement tab
connect(tabMeasurement.get(), SIGNAL(EnableTabsSignal(bool)), this, SLOT(EnableTabs(bool)));
connect(tabMeasurement.get(), SIGNAL(FileNameChangedSignal(QString)), plot.get(), SLOT(SetSaveFileName(QString)));
connect(tabMeasurement.get(), SIGNAL(EnableTabsSignal(bool)), this,
SLOT(EnableTabs(bool)));
connect(tabMeasurement.get(), SIGNAL(FileNameChangedSignal(QString)),
plot.get(), SLOT(SetSaveFileName(QString)));
// Plot tab
connect(tabPlot.get(), SIGNAL(DisableZoomSignal(bool)), this, SLOT(SetZoomToolTip(bool)));
connect(tabPlot.get(), SIGNAL(DisableZoomSignal(bool)), this,
SLOT(SetZoomToolTip(bool)));
// Plotting
connect(plot.get(), SIGNAL(AcquireFinishedSignal()), tabMeasurement.get(), SLOT(AcquireFinished()));
connect(plot.get(), SIGNAL(AbortSignal()), tabMeasurement.get(), SLOT(AbortAcquire()));
connect(plot.get(), SIGNAL(AcquireFinishedSignal()), tabMeasurement.get(),
SLOT(AcquireFinished()));
connect(plot.get(), SIGNAL(AbortSignal()), tabMeasurement.get(),
SLOT(AbortAcquire()));
// menubar
// Modes Menu
connect(menuModes, SIGNAL(triggered(QAction *)), this, SLOT(EnableModes(QAction *)));
connect(menuModes, SIGNAL(triggered(QAction *)), this,
SLOT(EnableModes(QAction *)));
// Utilities Menu
connect(menuUtilities, SIGNAL(triggered(QAction *)), this, SLOT(ExecuteUtilities(QAction *)));
connect(menuUtilities, SIGNAL(triggered(QAction *)), this,
SLOT(ExecuteUtilities(QAction *)));
// Help Menu
connect(menuHelp, SIGNAL(triggered(QAction *)), this, SLOT(ExecuteHelp(QAction *)));
connect(menuHelp, SIGNAL(triggered(QAction *)), this,
SLOT(ExecuteHelp(QAction *)));
}
void qDetectorMain::LoadConfigFile(const std::string fName) {
@ -302,7 +313,9 @@ void qDetectorMain::LoadConfigFile(const std::string fName) {
} else {
try {
det->loadConfig(fName);
} CATCH_DISPLAY ("Could not load config file.", "qDetectorMain::LoadConfigFile")
}
CATCH_DISPLAY("Could not load config file.",
"qDetectorMain::LoadConfigFile")
}
}
@ -313,8 +326,7 @@ void qDetectorMain::EnableModes(QAction *action) {
if (action == actionDebug) {
enable = actionDebug->isChecked();
tabs->setTabEnabled(DEBUGGING, enable);
FILE_LOG(logINFO) << "Debug Mode: "
<< qDefs::stringEnable(enable);
FILE_LOG(logINFO) << "Debug Mode: " << qDefs::stringEnable(enable);
}
@ -323,9 +335,9 @@ void qDetectorMain::EnableModes(QAction *action) {
enable = actionExpert->isChecked();
tabs->setTabEnabled(ADVANCED, enable);
actionLoadTrimbits->setVisible(enable && detType == slsDetectorDefs::EIGER);
FILE_LOG(logINFO) << "Expert Mode: "
<< qDefs::stringEnable(enable);
actionLoadTrimbits->setVisible(enable &&
detType == slsDetectorDefs::EIGER);
FILE_LOG(logINFO) << "Expert Mode: " << qDefs::stringEnable(enable);
}
// Set DockableMode
@ -337,8 +349,7 @@ void qDetectorMain::EnableModes(QAction *action) {
dockWidgetPlot->setFloating(false);
dockWidgetPlot->setFeatures(QDockWidget::NoDockWidgetFeatures);
}
FILE_LOG(logINFO) << "Dockable Mode: "
<< qDefs::stringEnable(enable);
FILE_LOG(logINFO) << "Dockable Mode: " << qDefs::stringEnable(enable);
}
}
@ -355,8 +366,7 @@ void qDetectorMain::ExecuteUtilities(QAction *action) {
// Gets called when cancelled as well
if (!fName.isEmpty()) {
refreshTabs = true;
det->loadConfig(
std::string(fName.toAscii().constData()));
det->loadConfig(std::string(fName.toAscii().constData()));
qDefs::Message(qDefs::INFORMATION,
"The Configuration Parameters have been "
"configured successfully.",
@ -375,19 +385,18 @@ void qDetectorMain::ExecuteUtilities(QAction *action) {
// Gets called when cancelled as well
if (!fName.isEmpty()) {
refreshTabs = true;
det->loadParameters(
std::string(fName.toAscii().constData()));
det->loadParameters(std::string(fName.toAscii().constData()));
qDefs::Message(qDefs::INFORMATION,
"The Detector Parameters have been "
"configured successfully.",
"qDetectorMain::ExecuteUtilities");
FILE_LOG(logINFO)
<< "Parameters loaded successfully";
FILE_LOG(logINFO) << "Parameters loaded successfully";
}
}
else if (action == actionLoadTrimbits) {
QString fName = QString((det->getSettingsPath().squash("/tmp/")).c_str());
QString fName =
QString((det->getSettingsPath().squash("/tmp/")).c_str());
FILE_LOG(logDEBUG) << "Loading Trimbits";
// so that even nonexisting files can be selected
QFileDialog *fileDialog = new QFileDialog(
@ -399,18 +408,16 @@ void qDetectorMain::ExecuteUtilities(QAction *action) {
// Gets called when cancelled as well
if (!fName.isEmpty()) {
det->loadTrimbits(
std::string(fName.toAscii().constData()));
qDefs::Message(
qDefs::INFORMATION,
"The Trimbits have been loaded successfully.",
"qDetectorMain::ExecuteUtilities");
det->loadTrimbits(std::string(fName.toAscii().constData()));
qDefs::Message(qDefs::INFORMATION,
"The Trimbits have been loaded successfully.",
"qDetectorMain::ExecuteUtilities");
FILE_LOG(logINFO) << "Trimbits loaded successfully";
}
}
} CATCH_DISPLAY ("Could not execute utilities.", "qDetectorMain::ExecuteUtilities")
}
CATCH_DISPLAY("Could not execute utilities.",
"qDetectorMain::ExecuteUtilities")
Refresh(tabs->currentIndex());
if (refreshTabs) {
@ -429,13 +436,16 @@ void qDetectorMain::ExecuteUtilities(QAction *action) {
void qDetectorMain::ExecuteHelp(QAction *action) {
if (action == actionAbout) {
FILE_LOG(logINFO) << "About Common GUI for Jungfrau, Eiger, Mythen3, Gotthard, Gotthard2 and Moench detectors";
FILE_LOG(logINFO) << "About Common GUI for Jungfrau, Eiger, Mythen3, "
"Gotthard, Gotthard2 and Moench detectors";
std::string guiVersion = std::to_string(APIGUI);
std::string clientVersion = "unknown";
try {
clientVersion = std::to_string(det->getClientVersion());
} CATCH_DISPLAY ("Could not get client version.", "qDetectorMain::ExecuteHelp")
}
CATCH_DISPLAY("Could not get client version.",
"qDetectorMain::ExecuteHelp")
qDefs::Message(qDefs::INFORMATION,
"<p style=\"font-family:verdana;\">"
@ -446,7 +456,8 @@ void qDetectorMain::ExecuteHelp(QAction *action) {
clientVersion +
"<br><br>"
"Common GUI to control the SLS Detectors: "
"Jungfrau, Eiger, Mythen3, Gotthard, Gotthard2 and Moench.<br><br>"
"Jungfrau, Eiger, Mythen3, Gotthard, Gotthard2 and "
"Moench.<br><br>"
"It can be operated in parallel with the command "
"line interface:<br>"
"sls_detector_put,<br>sls_detector_get,<br>sls_"
@ -553,7 +564,8 @@ void qDetectorMain::EnableTabs(bool enable) {
// expert
bool expertTab = enable && (actionExpert->isChecked());
tabs->setTabEnabled(ADVANCED, expertTab);
actionLoadTrimbits->setVisible(expertTab && detType == slsDetectorDefs::EIGER);
actionLoadTrimbits->setVisible(expertTab &&
detType == slsDetectorDefs::EIGER);
// moved to here, so that its all in order, instead of signals and different
// threads

587
slsDetectorGui/src/qDrawPlot.cpp Executable file → Normal file

File diff suppressed because it is too large Load Diff

256
slsDetectorGui/src/qTabAdvanced.cpp Executable file → Normal file
View File

@ -1,11 +1,12 @@
#include "qTabAdvanced.h"
#include "network_utils.h"
#include "qDefs.h"
#include "qDrawPlot.h"
#include "network_utils.h"
#include <iostream>
qTabAdvanced::qTabAdvanced(QWidget *parent, sls::Detector *detector, qDrawPlot *p)
qTabAdvanced::qTabAdvanced(QWidget *parent, sls::Detector *detector,
qDrawPlot *p)
: QWidget(parent), det(detector), plot(p) {
setupUi(this);
SetupWidgetWindow();
@ -88,7 +89,8 @@ void qTabAdvanced::Initialization() {
// roi
if (tab_roi->isEnabled()) {
connect(comboReadout, SIGNAL(currentIndexChanged(int)), this, SLOT(GetROI()));
connect(comboReadout, SIGNAL(currentIndexChanged(int)), this,
SLOT(GetROI()));
connect(btnSetRoi, SIGNAL(clicked()), this, SLOT(SetROI()));
connect(btnClearRoi, SIGNAL(clicked()), this, SLOT(ClearROI()));
}
@ -114,7 +116,7 @@ void qTabAdvanced::Initialization() {
// throw bits
if (lblDiscardBits->isEnabled()) {
connect(spinDiscardBits, SIGNAL(valueChanged(int)), plot,
SLOT(SetNumDiscardBits(int)));
SLOT(SetNumDiscardBits(int)));
}
}
@ -122,7 +124,8 @@ void qTabAdvanced::PopulateDetectors() {
FILE_LOG(logDEBUG) << "Populating detectors";
disconnect(comboDetector, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetDetector()));
disconnect(comboReadout, SIGNAL(currentIndexChanged(int)), this, SLOT(GetROI()));
disconnect(comboReadout, SIGNAL(currentIndexChanged(int)), this,
SLOT(GetROI()));
comboDetector->clear();
comboReadout->clear();
@ -132,11 +135,12 @@ void qTabAdvanced::PopulateDetectors() {
comboReadout->addItem(QString(it.c_str()));
}
comboDetector->setCurrentIndex(0);
comboReadout->setCurrentIndex(0);
comboReadout->setCurrentIndex(0);
connect(comboDetector, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetDetector()));
connect(comboReadout, SIGNAL(currentIndexChanged(int)), this, SLOT(GetROI()));
connect(comboReadout, SIGNAL(currentIndexChanged(int)), this,
SLOT(GetROI()));
}
void qTabAdvanced::GetControlPort() {
@ -147,7 +151,9 @@ void qTabAdvanced::GetControlPort() {
try {
int retval = det->getControlPort({comboDetector->currentIndex()})[0];
spinControlPort->setValue(retval);
} CATCH_DISPLAY ("Could not get detector control port.", "qTabAdvanced::GetControlPort")
}
CATCH_DISPLAY("Could not get detector control port.",
"qTabAdvanced::GetControlPort")
connect(spinControlPort, SIGNAL(valueChanged(int)), this,
SLOT(SetControlPort(int)));
@ -161,7 +167,9 @@ void qTabAdvanced::GetStopPort() {
try {
int retval = det->getStopPort({comboDetector->currentIndex()})[0];
spinStopPort->setValue(retval);
} CATCH_DISPLAY ("Could not get detector stop port.", "qTabAdvanced::GetStopPort")
}
CATCH_DISPLAY("Could not get detector stop port.",
"qTabAdvanced::GetStopPort")
connect(spinStopPort, SIGNAL(valueChanged(int)), this,
SLOT(SetStopPort(int)));
@ -173,9 +181,12 @@ void qTabAdvanced::GetDetectorUDPIP() {
SLOT(SetDetectorUDPIP()));
try {
auto retval = det->getSourceUDPIP({comboDetector->currentIndex()})[0].str();
auto retval =
det->getSourceUDPIP({comboDetector->currentIndex()})[0].str();
dispDetectorUDPIP->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get detector UDP IP.", "qTabAdvanced::GetDetectorUDPIP")
}
CATCH_DISPLAY("Could not get detector UDP IP.",
"qTabAdvanced::GetDetectorUDPIP")
connect(dispDetectorUDPIP, SIGNAL(editingFinished()), this,
SLOT(SetDetectorUDPIP()));
@ -187,9 +198,12 @@ void qTabAdvanced::GetDetectorUDPMAC() {
SLOT(SetDetectorUDPMAC()));
try {
auto retval = det->getSourceUDPMAC({comboDetector->currentIndex()})[0].str();
auto retval =
det->getSourceUDPMAC({comboDetector->currentIndex()})[0].str();
dispDetectorUDPMAC->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get detector UDP MAC.", "qTabAdvanced::GetDetectorUDPMAC")
}
CATCH_DISPLAY("Could not get detector UDP MAC.",
"qTabAdvanced::GetDetectorUDPMAC")
connect(dispDetectorUDPMAC, SIGNAL(editingFinished()), this,
SLOT(SetDetectorUDPMAC()));
@ -201,10 +215,11 @@ void qTabAdvanced::GetCltZMQPort() {
SLOT(SetCltZMQPort(int)));
try {
int retval =
det->getClientZmqPort({comboDetector->currentIndex()})[0];
int retval = det->getClientZmqPort({comboDetector->currentIndex()})[0];
spinZMQPort->setValue(retval);
} CATCH_DISPLAY ("Could not get client zmq port.", "qTabAdvanced::GetCltZMQPort")
}
CATCH_DISPLAY("Could not get client zmq port.",
"qTabAdvanced::GetCltZMQPort")
connect(spinZMQPort, SIGNAL(valueChanged(int)), this,
SLOT(SetCltZMQPort(int)));
@ -218,7 +233,8 @@ void qTabAdvanced::GetCltZMQIP() {
auto retval =
det->getClientZmqIp({comboDetector->currentIndex()})[0].str();
dispZMQIP->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get client zmq ip.", "qTabAdvanced::GetCltZMQIP")
}
CATCH_DISPLAY("Could not get client zmq ip.", "qTabAdvanced::GetCltZMQIP")
connect(dispZMQIP, SIGNAL(editingFinished()), this, SLOT(SetCltZMQIP()));
}
@ -231,7 +247,9 @@ void qTabAdvanced::GetRxrHostname() {
try {
auto retval = det->getRxHostname({comboDetector->currentIndex()})[0];
dispRxrHostname->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get receiver hostname.", "qTabAdvanced::GetRxrHostname")
}
CATCH_DISPLAY("Could not get receiver hostname.",
"qTabAdvanced::GetRxrHostname")
connect(dispRxrHostname, SIGNAL(editingFinished()), this,
SLOT(SetRxrHostname()));
@ -245,7 +263,9 @@ void qTabAdvanced::GetRxrTCPPort() {
try {
int retval = det->getRxPort({comboDetector->currentIndex()})[0];
spinRxrTCPPort->setValue(retval);
} CATCH_DISPLAY ("Could not get receiver tcp port.", "qTabAdvanced::GetRxrTCPPort")
}
CATCH_DISPLAY("Could not get receiver tcp port.",
"qTabAdvanced::GetRxrTCPPort")
connect(spinRxrTCPPort, SIGNAL(valueChanged(int)), this,
SLOT(SetRxrTCPPort(int)));
@ -257,9 +277,12 @@ void qTabAdvanced::GetRxrUDPPort() {
SLOT(SetRxrUDPPort(int)));
try {
int retval = det->getDestinationUDPPort({comboDetector->currentIndex()})[0];
int retval =
det->getDestinationUDPPort({comboDetector->currentIndex()})[0];
spinRxrUDPPort->setValue(retval);
} CATCH_DISPLAY ("Could not get receiver udp port.", "qTabAdvanced::GetRxrUDPPort")
}
CATCH_DISPLAY("Could not get receiver udp port.",
"qTabAdvanced::GetRxrUDPPort")
connect(spinRxrUDPPort, SIGNAL(valueChanged(int)), this,
SLOT(SetRxrUDPPort(int)));
@ -271,9 +294,11 @@ void qTabAdvanced::GetRxrUDPIP() {
SLOT(SetRxrUDPIP()));
try {
auto retval = det->getDestinationUDPIP({comboDetector->currentIndex()})[0].str();
auto retval =
det->getDestinationUDPIP({comboDetector->currentIndex()})[0].str();
dispRxrUDPIP->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get receiver udp ip.", "qTabAdvanced::GetRxrUDPIP")
}
CATCH_DISPLAY("Could not get receiver udp ip.", "qTabAdvanced::GetRxrUDPIP")
connect(dispRxrUDPIP, SIGNAL(editingFinished()), this, SLOT(SetRxrUDPIP()));
}
@ -284,9 +309,12 @@ void qTabAdvanced::GetRxrUDPMAC() {
SLOT(SetRxrUDPMAC()));
try {
auto retval = det->getDestinationUDPMAC({comboDetector->currentIndex()})[0].str();
auto retval =
det->getDestinationUDPMAC({comboDetector->currentIndex()})[0].str();
dispRxrUDPMAC->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get receiver udp mac.", "qTabAdvanced::GetRxrUDPMAC")
}
CATCH_DISPLAY("Could not get receiver udp mac.",
"qTabAdvanced::GetRxrUDPMAC")
connect(dispRxrUDPMAC, SIGNAL(editingFinished()), this,
SLOT(SetRxrUDPMAC()));
@ -298,10 +326,11 @@ void qTabAdvanced::GetRxrZMQPort() {
SLOT(SetRxrZMQPort(int)));
try {
int retval =
det->getRxZmqPort({comboDetector->currentIndex()})[0];
int retval = det->getRxZmqPort({comboDetector->currentIndex()})[0];
spinRxrZMQPort->setValue(retval);
} CATCH_DISPLAY ("Could not get receiver zmq port.", "qTabAdvanced::GetRxrZMQPort")
}
CATCH_DISPLAY("Could not get receiver zmq port.",
"qTabAdvanced::GetRxrZMQPort")
connect(spinRxrZMQPort, SIGNAL(valueChanged(int)), this,
SLOT(SetRxrZMQPort(int)));
@ -313,10 +342,10 @@ void qTabAdvanced::GetRxrZMQIP() {
SLOT(SetRxrZMQIP()));
try {
auto retval =
det->getRxZmqIP({comboDetector->currentIndex()})[0].str();
auto retval = det->getRxZmqIP({comboDetector->currentIndex()})[0].str();
dispRxrZMQIP->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get receiver zmq ip.", "qTabAdvanced::GetRxrZMQIP")
}
CATCH_DISPLAY("Could not get receiver zmq ip.", "qTabAdvanced::GetRxrZMQIP")
connect(dispRxrZMQIP, SIGNAL(editingFinished()), this, SLOT(SetRxrZMQIP()));
}
@ -346,7 +375,8 @@ void qTabAdvanced::SetControlPort(int port) {
FILE_LOG(logINFO) << "Setting Control Port:" << port;
try {
det->setControlPort(port, {comboDetector->currentIndex()});
} CATCH_HANDLE("Could not set control port.", "qTabAdvanced::SetControlPort",
}
CATCH_HANDLE("Could not set control port.", "qTabAdvanced::SetControlPort",
this, &qTabAdvanced::GetControlPort)
}
@ -354,8 +384,9 @@ void qTabAdvanced::SetStopPort(int port) {
FILE_LOG(logINFO) << "Setting Stop Port:" << port;
try {
det->setStopPort(port, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set stop port.", "qTabAdvanced::SetStopPort", this,
&qTabAdvanced::GetStopPort)
}
CATCH_HANDLE("Could not set stop port.", "qTabAdvanced::SetStopPort", this,
&qTabAdvanced::GetStopPort)
}
void qTabAdvanced::SetDetectorUDPIP() {
@ -363,9 +394,10 @@ void qTabAdvanced::SetDetectorUDPIP() {
FILE_LOG(logINFO) << "Setting Detector UDP IP:" << s;
try {
det->setSourceUDPIP(sls::IpAddr{s}, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Detector UDP IP.",
"qTabAdvanced::SetDetectorUDPIP", this,
&qTabAdvanced::GetDetectorUDPIP)
}
CATCH_HANDLE("Could not set Detector UDP IP.",
"qTabAdvanced::SetDetectorUDPIP", this,
&qTabAdvanced::GetDetectorUDPIP)
}
void qTabAdvanced::SetDetectorUDPMAC() {
@ -373,18 +405,20 @@ void qTabAdvanced::SetDetectorUDPMAC() {
FILE_LOG(logINFO) << "Setting Detector UDP MAC:" << s;
try {
det->setSourceUDPMAC(sls::MacAddr{s}, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Detector UDP MAC.",
"qTabAdvanced::SetDetectorUDPMAC", this,
&qTabAdvanced::GetDetectorUDPMAC)
}
CATCH_HANDLE("Could not set Detector UDP MAC.",
"qTabAdvanced::SetDetectorUDPMAC", this,
&qTabAdvanced::GetDetectorUDPMAC)
}
void qTabAdvanced::SetCltZMQPort(int port) {
FILE_LOG(logINFO) << "Setting Client ZMQ Port:" << port;
try {
det->setClientZmqPort(port, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Client ZMQ port.",
"qTabAdvanced::SetCltZMQPort", this,
&qTabAdvanced::GetCltZMQPort)
}
CATCH_HANDLE("Could not set Client ZMQ port.",
"qTabAdvanced::SetCltZMQPort", this,
&qTabAdvanced::GetCltZMQPort)
}
void qTabAdvanced::SetCltZMQIP() {
@ -392,9 +426,9 @@ void qTabAdvanced::SetCltZMQIP() {
FILE_LOG(logINFO) << "Setting Client ZMQ IP:" << s;
try {
det->setClientZmqIp(sls::IpAddr{s}, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Client ZMQ IP.",
"qTabAdvanced::SetCltZMQIP", this,
&qTabAdvanced::GetCltZMQIP)
}
CATCH_HANDLE("Could not set Client ZMQ IP.", "qTabAdvanced::SetCltZMQIP",
this, &qTabAdvanced::GetCltZMQIP)
}
void qTabAdvanced::SetRxrHostname() {
@ -402,9 +436,9 @@ void qTabAdvanced::SetRxrHostname() {
FILE_LOG(logINFO) << "Setting Receiver Hostname:" << s;
try {
det->setRxHostname(s, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Client ZMQ IP.",
"qTabAdvanced::SetRxrHostname", this,
&qTabAdvanced::GetRxrHostname)
}
CATCH_HANDLE("Could not set Client ZMQ IP.", "qTabAdvanced::SetRxrHostname",
this, &qTabAdvanced::GetRxrHostname)
// update all network widgets (receiver mainly)
SetDetector();
@ -414,47 +448,53 @@ void qTabAdvanced::SetRxrTCPPort(int port) {
FILE_LOG(logINFO) << "Setting Receiver TCP Port:" << port;
try {
det->setRxPort(port, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Receiver TCP port.",
"qTabAdvanced::SetRxrTCPPort", this,
&qTabAdvanced::GetRxrTCPPort)
}
CATCH_HANDLE("Could not set Receiver TCP port.",
"qTabAdvanced::SetRxrTCPPort", this,
&qTabAdvanced::GetRxrTCPPort)
}
void qTabAdvanced::SetRxrUDPPort(int port) {
FILE_LOG(logINFO) << "Setting Receiver UDP Port:" << port;
try {
det->setRxPort(port, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Receiver UDP port.",
"qTabAdvanced::SetRxrUDPPort", this,
&qTabAdvanced::GetRxrUDPPort)
}
CATCH_HANDLE("Could not set Receiver UDP port.",
"qTabAdvanced::SetRxrUDPPort", this,
&qTabAdvanced::GetRxrUDPPort)
}
void qTabAdvanced::SetRxrUDPIP() {
std::string s = dispRxrUDPIP->text().toAscii().constData();
FILE_LOG(logINFO) << "Setting Receiver UDP IP:" << s;
try {
det->setDestinationUDPIP(sls::IpAddr{s}, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Receiver UDP IP.",
"qTabAdvanced::SetRxrUDPIP", this,
&qTabAdvanced::GetRxrUDPIP)
det->setDestinationUDPIP(sls::IpAddr{s},
{comboDetector->currentIndex()});
}
CATCH_HANDLE("Could not set Receiver UDP IP.", "qTabAdvanced::SetRxrUDPIP",
this, &qTabAdvanced::GetRxrUDPIP)
}
void qTabAdvanced::SetRxrUDPMAC() {
std::string s = dispRxrUDPMAC->text().toAscii().constData();
FILE_LOG(logINFO) << "Setting Receiver UDP MAC:" << s;
try {
det->setDestinationUDPMAC(sls::MacAddr{s}, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Receiver UDP MAC.",
"qTabAdvanced::SetRxrUDPMAC", this,
&qTabAdvanced::GetRxrUDPMAC)
det->setDestinationUDPMAC(sls::MacAddr{s},
{comboDetector->currentIndex()});
}
CATCH_HANDLE("Could not set Receiver UDP MAC.",
"qTabAdvanced::SetRxrUDPMAC", this,
&qTabAdvanced::GetRxrUDPMAC)
}
void qTabAdvanced::SetRxrZMQPort(int port) {
FILE_LOG(logINFO) << "Setting Receiver ZMQ Port:" << port;
try {
det->setRxZmqPort(port, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Receiver ZMQ port.",
"qTabAdvanced::SetRxrZMQPort", this,
&qTabAdvanced::GetRxrZMQPort)
}
CATCH_HANDLE("Could not set Receiver ZMQ port.",
"qTabAdvanced::SetRxrZMQPort", this,
&qTabAdvanced::GetRxrZMQPort)
}
void qTabAdvanced::SetRxrZMQIP() {
@ -462,24 +502,26 @@ void qTabAdvanced::SetRxrZMQIP() {
FILE_LOG(logINFO) << "Setting Receiver ZMQ IP:" << s;
try {
det->setRxZmqIP(sls::IpAddr{s}, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Receiver ZMQ IP.",
"qTabAdvanced::SetRxrZMQIP", this,
&qTabAdvanced::GetRxrZMQIP)
}
CATCH_HANDLE("Could not set Receiver ZMQ IP.", "qTabAdvanced::SetRxrZMQIP",
this, &qTabAdvanced::GetRxrZMQIP)
}
void qTabAdvanced::GetROI() {
FILE_LOG(logDEBUG) << "Getting ROI";
try {
slsDetectorDefs::ROI roi = det->getROI({comboReadout->currentIndex()})[0];
slsDetectorDefs::ROI roi =
det->getROI({comboReadout->currentIndex()})[0];
spinXmin->setValue(roi.xmin);
spinXmax->setValue(roi.xmax);
} CATCH_DISPLAY ("Could not get ROI.", "qTabAdvanced::GetROI")
spinXmax->setValue(roi.xmax);
}
CATCH_DISPLAY("Could not get ROI.", "qTabAdvanced::GetROI")
}
void qTabAdvanced::ClearROI() {
FILE_LOG(logINFO) << "Clearing ROI";
spinXmin->setValue(-1);
spinXmax->setValue(-1);
spinXmax->setValue(-1);
SetROI();
FILE_LOG(logDEBUG) << "ROIs cleared";
}
@ -491,11 +533,12 @@ void qTabAdvanced::SetROI() {
roi.xmax = spinXmax->value();
// set roi
FILE_LOG(logINFO) << "Setting ROI: [" << roi.xmin << ", " << roi.xmax << "]";
FILE_LOG(logINFO) << "Setting ROI: [" << roi.xmin << ", " << roi.xmax
<< "]";
try {
det->setROI(roi, {comboReadout->currentIndex()});
} CATCH_DISPLAY ("Could not set these ROIs.",
"qTabAdvanced::SetROI")
}
CATCH_DISPLAY("Could not set these ROIs.", "qTabAdvanced::SetROI")
// update corrected list
GetROI();
@ -509,7 +552,8 @@ void qTabAdvanced::GetAllTrimbits() {
try {
int retval = det->getAllTrimbits().squash(-1);
spinSetAllTrimbits->setValue(retval);
} CATCH_DISPLAY ("Could not get all trimbits.", "qTabAdvanced::GetAllTrimbits")
}
CATCH_DISPLAY("Could not get all trimbits.", "qTabAdvanced::GetAllTrimbits")
connect(spinSetAllTrimbits, SIGNAL(editingFinished()), this,
SLOT(SetAllTrimbits()));
@ -521,7 +565,8 @@ void qTabAdvanced::SetAllTrimbits() {
try {
det->setAllTrimbits(value);
} CATCH_HANDLE("Could not set all trimbits.", "qTabAdvanced::SetAllTrimbits",
}
CATCH_HANDLE("Could not set all trimbits.", "qTabAdvanced::SetAllTrimbits",
this, &qTabAdvanced::GetAllTrimbits)
}
@ -531,11 +576,12 @@ void qTabAdvanced::GetNumStoragecells() {
SLOT(SetNumStoragecells(int)));
try {
auto retval = det->getNumberOfAdditionalStorageCells().tsquash("Inconsistent values for number of addditional storage cells.");
auto retval = det->getNumberOfAdditionalStorageCells().tsquash(
"Inconsistent values for number of addditional storage cells.");
spinNumStoragecells->setValue(retval);
} CATCH_DISPLAY (
"Could not get number of additional storage cells.",
"qTabAdvanced::GetNumStoragecells")
}
CATCH_DISPLAY("Could not get number of additional storage cells.",
"qTabAdvanced::GetNumStoragecells")
connect(spinNumStoragecells, SIGNAL(valueChanged(int)), this,
SLOT(SetNumStoragecells(int)));
@ -546,10 +592,10 @@ void qTabAdvanced::SetNumStoragecells(int value) {
<< value;
try {
det->setNumberOfAdditionalStorageCells(value);
} CATCH_HANDLE (
"Could not set number of additional storage cells.",
"qTabAdvanced::SetNumStoragecells", this,
&qTabAdvanced::GetNumStoragecells)
}
CATCH_HANDLE("Could not set number of additional storage cells.",
"qTabAdvanced::SetNumStoragecells", this,
&qTabAdvanced::GetNumStoragecells)
}
void qTabAdvanced::GetSubExposureTime() {
@ -559,13 +605,14 @@ void qTabAdvanced::GetSubExposureTime() {
disconnect(comboSubExpTimeUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetSubExposureTime()));
try {
auto retval =
det->getSubExptime().tsquash("Subexptime is inconsistent for all detectors.");
auto retval = det->getSubExptime().tsquash(
"Subexptime is inconsistent for all detectors.");
auto time = qDefs::getUserFriendlyTime(retval);
spinSubExpTime->setValue(time.first);
comboSubExpTimeUnit->setCurrentIndex(static_cast<int>(time.second));
} CATCH_DISPLAY ("Could not get sub exposure time.",
"qTabSettings::GetSubExposureTime")
}
CATCH_DISPLAY("Could not get sub exposure time.",
"qTabSettings::GetSubExposureTime")
connect(spinSubExpTime, SIGNAL(valueChanged(double)), this,
SLOT(SetSubExposureTime()));
connect(comboSubExpTimeUnit, SIGNAL(currentIndexChanged(int)), this,
@ -573,7 +620,9 @@ void qTabAdvanced::GetSubExposureTime() {
}
void qTabAdvanced::SetSubExposureTime() {
auto timeNS = qDefs::getNSTime(std::make_pair(spinSubExpTime->value(), static_cast<qDefs::timeUnit>(comboSubExpTimeUnit->currentIndex())));
auto timeNS = qDefs::getNSTime(std::make_pair(
spinSubExpTime->value(),
static_cast<qDefs::timeUnit>(comboSubExpTimeUnit->currentIndex())));
FILE_LOG(logINFO)
<< "Setting sub frame acquisition time to " << timeNS.count() << " ns"
<< "/" << spinSubExpTime->value()
@ -581,8 +630,9 @@ void qTabAdvanced::SetSubExposureTime() {
(qDefs::timeUnit)comboSubExpTimeUnit->currentIndex());
try {
det->setSubExptime(timeNS);
} CATCH_DISPLAY ("Could not set sub exposure time.",
"qTabAdvanced::SetSubExposureTime")
}
CATCH_DISPLAY("Could not set sub exposure time.",
"qTabAdvanced::SetSubExposureTime")
GetSubExposureTime();
}
@ -594,13 +644,14 @@ void qTabAdvanced::GetSubDeadTime() {
disconnect(comboSubDeadTimeUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetSubDeadTime()));
try {
auto retval = det->getSubDeadTime().tsquash("Sub dead time is inconsistent for all detectors.");
auto retval = det->getSubDeadTime().tsquash(
"Sub dead time is inconsistent for all detectors.");
auto time = qDefs::getUserFriendlyTime(retval);
spinSubDeadTime->setValue(time.first);
comboSubDeadTimeUnit->setCurrentIndex(
static_cast<int>(time.second));
} CATCH_DISPLAY ("Could not get sub dead time.",
"qTabSettings::GetSubDeadTime")
comboSubDeadTimeUnit->setCurrentIndex(static_cast<int>(time.second));
}
CATCH_DISPLAY("Could not get sub dead time.",
"qTabSettings::GetSubDeadTime")
connect(spinSubDeadTime, SIGNAL(valueChanged(double)), this,
SLOT(SetSubDeadTime()));
connect(comboSubDeadTimeUnit, SIGNAL(currentIndexChanged(int)), this,
@ -608,7 +659,9 @@ void qTabAdvanced::GetSubDeadTime() {
}
void qTabAdvanced::SetSubDeadTime() {
auto timeNS = qDefs::getNSTime(std::make_pair(spinSubDeadTime->value(), static_cast<qDefs::timeUnit>(comboSubDeadTimeUnit->currentIndex())));
auto timeNS = qDefs::getNSTime(std::make_pair(
spinSubDeadTime->value(),
static_cast<qDefs::timeUnit>(comboSubDeadTimeUnit->currentIndex())));
FILE_LOG(logINFO)
<< "Setting sub frame dead time to " << timeNS.count() << " ns"
@ -617,8 +670,9 @@ void qTabAdvanced::SetSubDeadTime() {
(qDefs::timeUnit)comboSubDeadTimeUnit->currentIndex());
try {
det->setSubDeadTime(timeNS);
} CATCH_DISPLAY ("Could not set sub dead time.",
"qTabAdvanced::SetSubDeadTime")
}
CATCH_DISPLAY("Could not set sub dead time.",
"qTabAdvanced::SetSubDeadTime")
GetSubDeadTime();
}

587
slsDetectorGui/src/qTabDataOutput.cpp Executable file → Normal file
View File

@ -1,342 +1,431 @@
#include "qTabDataOutput.h"
#include "qDefs.h"
#include <QButtonGroup>
#include <QFileDialog>
#include <QStandardItemModel>
#include <QButtonGroup>
#include <QString>
#include <iostream>
#include <string>
qTabDataOutput::qTabDataOutput(QWidget *parent, sls::Detector *detector) : QWidget(parent), det(detector), btnGroupRate(nullptr) {
setupUi(this);
SetupWidgetWindow();
FILE_LOG(logDEBUG) << "DataOutput ready";
qTabDataOutput::qTabDataOutput(QWidget *parent, sls::Detector *detector)
: QWidget(parent), det(detector), btnGroupRate(nullptr) {
setupUi(this);
SetupWidgetWindow();
FILE_LOG(logDEBUG) << "DataOutput ready";
}
qTabDataOutput::~qTabDataOutput() {
delete btnGroupRate;
}
qTabDataOutput::~qTabDataOutput() { delete btnGroupRate; }
void qTabDataOutput::SetupWidgetWindow() {
// button group for rate
btnGroupRate = new QButtonGroup(this);
btnGroupRate->addButton(radioDefaultDeadtime, 0);
btnGroupRate->addButton(radioCustomDeadtime, 1);
// button group for rate
btnGroupRate = new QButtonGroup(this);
btnGroupRate->addButton(radioDefaultDeadtime, 0);
btnGroupRate->addButton(radioCustomDeadtime, 1);
// enabling according to det type
switch(det->getDetectorType().squash()) {
case slsDetectorDefs::EIGER:
chkTenGiga->setEnabled(true);
chkRate->setEnabled(true);
radioDefaultDeadtime->setEnabled(true);
radioCustomDeadtime->setEnabled(true);
// flags and speed
widgetEiger->setVisible(true);
widgetEiger->setEnabled(true);
break;
case slsDetectorDefs::MOENCH:
chkTenGiga->setEnabled(true);
break;
default:
break;
}
PopulateDetectors();
// enabling according to det type
switch (det->getDetectorType().squash()) {
case slsDetectorDefs::EIGER:
chkTenGiga->setEnabled(true);
chkRate->setEnabled(true);
radioDefaultDeadtime->setEnabled(true);
radioCustomDeadtime->setEnabled(true);
// flags and speed
widgetEiger->setVisible(true);
widgetEiger->setEnabled(true);
break;
case slsDetectorDefs::MOENCH:
chkTenGiga->setEnabled(true);
break;
default:
break;
}
PopulateDetectors();
Initialization();
Initialization();
Refresh();
Refresh();
}
void qTabDataOutput::Initialization() {
// ourdir, fileformat, overwrite enable
connect(comboDetector, SIGNAL(currentIndexChanged(int)), this, SLOT(GetOutputDir()));
connect(dispOutputDir, SIGNAL(editingFinished()), this, SLOT(SetOutputDir()));
connect(btnOutputBrowse, SIGNAL(clicked()), this, SLOT(BrowseOutputDir()));
connect(comboFileFormat, SIGNAL(currentIndexChanged(int)), this, SLOT(SetFileFormat(int)));
connect(chkOverwriteEnable, SIGNAL(toggled(bool)), this, SLOT(SetOverwriteEnable(bool)));
if (chkTenGiga->isEnabled()) {
connect(chkTenGiga, SIGNAL(toggled(bool)), this, SLOT(SetTenGigaEnable(bool)));
}
// rate
if (chkRate->isEnabled()) {
connect(chkRate, SIGNAL(toggled(bool)), this, SLOT(EnableRateCorrection()));
connect(btnGroupRate, SIGNAL(buttonClicked(int)), this, SLOT(SetRateCorrection()));
connect(spinCustomDeadTime, SIGNAL(editingFinished()), this, SLOT(SetRateCorrection()));
}
// flags, speed
if (widgetEiger->isEnabled()) {
connect(comboEigerClkDivider, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSpeed(int)));
connect(comboEigerParallelFlag, SIGNAL(currentIndexChanged(int)), this, SLOT(SetFlags()));
}
// ourdir, fileformat, overwrite enable
connect(comboDetector, SIGNAL(currentIndexChanged(int)), this,
SLOT(GetOutputDir()));
connect(dispOutputDir, SIGNAL(editingFinished()), this,
SLOT(SetOutputDir()));
connect(btnOutputBrowse, SIGNAL(clicked()), this, SLOT(BrowseOutputDir()));
connect(comboFileFormat, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetFileFormat(int)));
connect(chkOverwriteEnable, SIGNAL(toggled(bool)), this,
SLOT(SetOverwriteEnable(bool)));
if (chkTenGiga->isEnabled()) {
connect(chkTenGiga, SIGNAL(toggled(bool)), this,
SLOT(SetTenGigaEnable(bool)));
}
// rate
if (chkRate->isEnabled()) {
connect(chkRate, SIGNAL(toggled(bool)), this,
SLOT(EnableRateCorrection()));
connect(btnGroupRate, SIGNAL(buttonClicked(int)), this,
SLOT(SetRateCorrection()));
connect(spinCustomDeadTime, SIGNAL(editingFinished()), this,
SLOT(SetRateCorrection()));
}
// flags, speed
if (widgetEiger->isEnabled()) {
connect(comboEigerClkDivider, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetSpeed(int)));
connect(comboEigerParallelFlag, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetFlags()));
}
}
void qTabDataOutput::PopulateDetectors() {
FILE_LOG(logDEBUG) << "Populating detectors";
FILE_LOG(logDEBUG) << "Populating detectors";
comboDetector->clear();
comboDetector->addItem("All");
if (det->size() > 1) {
auto res = det->getHostname();
for (auto &it : res) {
comboDetector->addItem(QString(it.c_str()));
}
}
comboDetector->clear();
comboDetector->addItem("All");
if (det->size() > 1) {
auto res = det->getHostname();
for (auto &it : res) {
comboDetector->addItem(QString(it.c_str()));
}
}
}
void qTabDataOutput::EnableBrowse() {
FILE_LOG(logDEBUG) << "Getting browse enable";
try {
btnOutputBrowse->setEnabled(false); // exception default
std::string rxHostname = det->getRxHostname({comboDetector->currentIndex() - 1}).squash("none");
if (rxHostname == "none") {
btnOutputBrowse->setEnabled(false);
} else if (rxHostname == "localhost") {
btnOutputBrowse->setEnabled(true);
} else {
std::string hostname;
const size_t len = 15;
char host[len]{};
if (gethostname(host, len) == 0) {
hostname.assign(host);
}
// client pc (hostname) same as reciever hostname
if (hostname == rxHostname) {
btnOutputBrowse->setEnabled(true);
} else {
btnOutputBrowse->setEnabled(false);
}
}
} CATCH_DISPLAY ("Could not get receiver hostname.", "qTabDataOutput::EnableBrowse")
FILE_LOG(logDEBUG) << "Getting browse enable";
try {
btnOutputBrowse->setEnabled(false); // exception default
std::string rxHostname =
det->getRxHostname({comboDetector->currentIndex() - 1})
.squash("none");
if (rxHostname == "none") {
btnOutputBrowse->setEnabled(false);
} else if (rxHostname == "localhost") {
btnOutputBrowse->setEnabled(true);
} else {
std::string hostname;
const size_t len = 15;
char host[len]{};
if (gethostname(host, len) == 0) {
hostname.assign(host);
}
// client pc (hostname) same as reciever hostname
if (hostname == rxHostname) {
btnOutputBrowse->setEnabled(true);
} else {
btnOutputBrowse->setEnabled(false);
}
}
}
CATCH_DISPLAY("Could not get receiver hostname.",
"qTabDataOutput::EnableBrowse")
}
void qTabDataOutput::GetFileWrite() {
FILE_LOG(logDEBUG) << "Getting file write enable";
try {
boxFileWriteEnabled->setEnabled(true); // exception default
auto retval = det->getFileWrite().tsquash("File write is inconsistent for all detectors.");
boxFileWriteEnabled->setEnabled(retval);
} CATCH_DISPLAY("Could not get file enable.", "qTabDataOutput::GetFileWrite")
FILE_LOG(logDEBUG) << "Getting file write enable";
try {
boxFileWriteEnabled->setEnabled(true); // exception default
auto retval = det->getFileWrite().tsquash(
"File write is inconsistent for all detectors.");
boxFileWriteEnabled->setEnabled(retval);
}
CATCH_DISPLAY("Could not get file enable.", "qTabDataOutput::GetFileWrite")
}
void qTabDataOutput::GetFileName() {
FILE_LOG(logDEBUG) << "Getting file name";
try {
auto retval = det->getFileNamePrefix().tsquash("File name is inconsistent for all detectors.");
dispFileName->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get file name prefix.", "qTabDataOutput::GetFileName")
FILE_LOG(logDEBUG) << "Getting file name";
try {
auto retval = det->getFileNamePrefix().tsquash(
"File name is inconsistent for all detectors.");
dispFileName->setText(QString(retval.c_str()));
}
CATCH_DISPLAY("Could not get file name prefix.",
"qTabDataOutput::GetFileName")
}
void qTabDataOutput::GetOutputDir() {
FILE_LOG(logDEBUG) << "Getting file path";
disconnect(dispOutputDir, SIGNAL(editingFinished()), this, SLOT(SetOutputDir()));
try {
std::string path = det->getFilePath({comboDetector->currentIndex() - 1}).tsquash("File path is different for all detectors.");
dispOutputDir->setText(QString(path.c_str()));
} CATCH_DISPLAY ("Could not get file path.", "qTabDataOutput::GetOutputDir")
connect(dispOutputDir, SIGNAL(editingFinished()), this, SLOT(SetOutputDir()));
FILE_LOG(logDEBUG) << "Getting file path";
disconnect(dispOutputDir, SIGNAL(editingFinished()), this,
SLOT(SetOutputDir()));
try {
std::string path =
det->getFilePath({comboDetector->currentIndex() - 1})
.tsquash("File path is different for all detectors.");
dispOutputDir->setText(QString(path.c_str()));
}
CATCH_DISPLAY("Could not get file path.", "qTabDataOutput::GetOutputDir")
connect(dispOutputDir, SIGNAL(editingFinished()), this,
SLOT(SetOutputDir()));
}
void qTabDataOutput::BrowseOutputDir() {
FILE_LOG(logDEBUG) << "Browsing output directory";
QString directory = QFileDialog::getExistingDirectory(this, tr("Choose Output Directory "), dispOutputDir->text());
if (!directory.isEmpty())
dispOutputDir->setText(directory);
FILE_LOG(logDEBUG) << "Browsing output directory";
QString directory = QFileDialog::getExistingDirectory(
this, tr("Choose Output Directory "), dispOutputDir->text());
if (!directory.isEmpty())
dispOutputDir->setText(directory);
}
void qTabDataOutput::SetOutputDir() {
QString path = dispOutputDir->text();
FILE_LOG(logDEBUG) << "Setting output directory to " << path.toAscii().constData();
QString path = dispOutputDir->text();
FILE_LOG(logDEBUG) << "Setting output directory to "
<< path.toAscii().constData();
// empty
if (path.isEmpty()) {
qDefs::Message(qDefs::WARNING, "Invalid Output Path. Must not be empty.", "qTabDataOutput::SetOutputDir");
FILE_LOG(logWARNING) << "Invalid Output Path. Must not be empty.";
GetOutputDir();
} else {
// chop off trailing '/'
if (path.endsWith('/')) {
while (path.endsWith('/')) {
path.chop(1);
}
}
std::string spath = std::string(path.toAscii().constData());
try {
det->setFilePath(spath, {comboDetector->currentIndex() - 1});
} CATCH_HANDLE ("Could not set output file path.", "qTabDataOutput::SetOutputDir", this, &qTabDataOutput::GetOutputDir)
}
// empty
if (path.isEmpty()) {
qDefs::Message(qDefs::WARNING,
"Invalid Output Path. Must not be empty.",
"qTabDataOutput::SetOutputDir");
FILE_LOG(logWARNING) << "Invalid Output Path. Must not be empty.";
GetOutputDir();
} else {
// chop off trailing '/'
if (path.endsWith('/')) {
while (path.endsWith('/')) {
path.chop(1);
}
}
std::string spath = std::string(path.toAscii().constData());
try {
det->setFilePath(spath, {comboDetector->currentIndex() - 1});
}
CATCH_HANDLE("Could not set output file path.",
"qTabDataOutput::SetOutputDir", this,
&qTabDataOutput::GetOutputDir)
}
}
void qTabDataOutput::GetFileFormat() {
FILE_LOG(logDEBUG) << "Getting File Format";
disconnect(comboFileFormat, SIGNAL(currentIndexChanged(int)), this, SLOT(SetFileFormat(int)));
try {
auto retval = det->getFileFormat().tsquash("File format is inconsistent for all detectors.");
switch(retval) {
case slsDetectorDefs::BINARY:
case slsDetectorDefs::HDF5:
comboFileFormat->setCurrentIndex(static_cast<int>(retval));
break;
default:
throw sls::RuntimeError(std::string("Unknown file format: ") + std::to_string(static_cast<int>(retval)));
FILE_LOG(logDEBUG) << "Getting File Format";
disconnect(comboFileFormat, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetFileFormat(int)));
try {
auto retval = det->getFileFormat().tsquash(
"File format is inconsistent for all detectors.");
switch (retval) {
case slsDetectorDefs::BINARY:
case slsDetectorDefs::HDF5:
comboFileFormat->setCurrentIndex(static_cast<int>(retval));
break;
default:
throw sls::RuntimeError(std::string("Unknown file format: ") +
std::to_string(static_cast<int>(retval)));
}
} CATCH_DISPLAY("Could not get file format.", "qTabDataOutput::GetFileFormat")
connect(comboFileFormat, SIGNAL(currentIndexChanged(int)), this, SLOT(SetFileFormat(int)));
}
CATCH_DISPLAY("Could not get file format.", "qTabDataOutput::GetFileFormat")
connect(comboFileFormat, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetFileFormat(int)));
}
void qTabDataOutput::SetFileFormat(int format) {
FILE_LOG(logINFO) << "Setting File Format to " << comboFileFormat->currentText().toAscii().data();
try {
det->setFileFormat(static_cast<slsDetectorDefs::fileFormat>(comboFileFormat->currentIndex()));
} CATCH_HANDLE ("Could not set file format.", "qTabDataOutput::SetFileFormat", this, &qTabDataOutput::GetFileFormat)
FILE_LOG(logINFO) << "Setting File Format to "
<< comboFileFormat->currentText().toAscii().data();
try {
det->setFileFormat(static_cast<slsDetectorDefs::fileFormat>(
comboFileFormat->currentIndex()));
}
CATCH_HANDLE("Could not set file format.", "qTabDataOutput::SetFileFormat",
this, &qTabDataOutput::GetFileFormat)
}
void qTabDataOutput::GetFileOverwrite() {
FILE_LOG(logDEBUG) << "Getting File Over Write Enable";
disconnect(chkOverwriteEnable, SIGNAL(toggled(bool)), this, SLOT(SetOverwriteEnable(bool)));
try {
auto retval = det->getFileOverWrite().tsquash("File over write is inconsistent for all detectors.");
chkOverwriteEnable->setChecked(retval);
} CATCH_DISPLAY ("Could not get file over write enable.", "qTabDataOutput::GetFileOverwrite")
FILE_LOG(logDEBUG) << "Getting File Over Write Enable";
disconnect(chkOverwriteEnable, SIGNAL(toggled(bool)), this,
SLOT(SetOverwriteEnable(bool)));
try {
auto retval = det->getFileOverWrite().tsquash(
"File over write is inconsistent for all detectors.");
chkOverwriteEnable->setChecked(retval);
}
CATCH_DISPLAY("Could not get file over write enable.",
"qTabDataOutput::GetFileOverwrite")
connect(chkOverwriteEnable, SIGNAL(toggled(bool)), this, SLOT(SetOverwriteEnable(bool)));
connect(chkOverwriteEnable, SIGNAL(toggled(bool)), this,
SLOT(SetOverwriteEnable(bool)));
}
void qTabDataOutput::SetOverwriteEnable(bool enable) {
FILE_LOG(logINFO) << "Setting File Over Write Enable to " << enable;
try {
FILE_LOG(logINFO) << "Setting File Over Write Enable to " << enable;
try {
det->setFileOverWrite(enable);
} CATCH_HANDLE ("Could not set file over write enable.", "qTabDataOutput::SetOverwriteEnable", this, &qTabDataOutput::GetFileOverwrite)
}
CATCH_HANDLE("Could not set file over write enable.",
"qTabDataOutput::SetOverwriteEnable", this,
&qTabDataOutput::GetFileOverwrite)
}
void qTabDataOutput::GetTenGigaEnable() {
FILE_LOG(logDEBUG) << "Getting 10GbE enable";
disconnect(chkTenGiga, SIGNAL(toggled(bool)), this, SLOT(SetTenGigaEnable(bool)));
try {
auto retval = det->getTenGiga().tsquash("10GbE enable is inconsistent for all detectors.");
chkTenGiga->setChecked(retval);
} CATCH_DISPLAY ("Could not get 10GbE enable.", "qTabDataOutput::GetTenGigaEnable")
connect(chkTenGiga, SIGNAL(toggled(bool)), this, SLOT(SetTenGigaEnable(bool)));
FILE_LOG(logDEBUG) << "Getting 10GbE enable";
disconnect(chkTenGiga, SIGNAL(toggled(bool)), this,
SLOT(SetTenGigaEnable(bool)));
try {
auto retval = det->getTenGiga().tsquash(
"10GbE enable is inconsistent for all detectors.");
chkTenGiga->setChecked(retval);
}
CATCH_DISPLAY("Could not get 10GbE enable.",
"qTabDataOutput::GetTenGigaEnable")
connect(chkTenGiga, SIGNAL(toggled(bool)), this,
SLOT(SetTenGigaEnable(bool)));
}
void qTabDataOutput::SetTenGigaEnable(bool enable) {
FILE_LOG(logINFO) << "Setting 10GbE to " << enable;
try {
FILE_LOG(logINFO) << "Setting 10GbE to " << enable;
try {
det->setTenGiga(enable);
} CATCH_HANDLE ("Could not set 10GbE enable.", "qTabDataOutput::SetTenGigaEnable", this, &qTabDataOutput::GetTenGigaEnable)
}
CATCH_HANDLE("Could not set 10GbE enable.",
"qTabDataOutput::SetTenGigaEnable", this,
&qTabDataOutput::GetTenGigaEnable)
}
void qTabDataOutput::GetRateCorrection() {
FILE_LOG(logDEBUG) << "Getting Rate Correction";
disconnect(chkRate, SIGNAL(toggled(bool)), this, SLOT(EnableRateCorrection()));
disconnect(btnGroupRate, SIGNAL(buttonClicked(int)), this, SLOT(SetRateCorrection()));
disconnect(spinCustomDeadTime, SIGNAL(editingFinished()), this, SLOT(SetRateCorrection()));
try {
spinCustomDeadTime->setValue(-1);
int64_t retval = det->getRateCorrection().tsquash("Rate correction (enable/tau) is inconsistent for all detectors.").count();
chkRate->setChecked(retval == 0 ? false : true);
if (retval != 0)
spinCustomDeadTime->setValue(retval);
} CATCH_DISPLAY("Could not get rate correction.", "qTabDataOutput::GetRateCorrection")
connect(chkRate, SIGNAL(toggled(bool)), this, SLOT(EnableRateCorrection()));
connect(btnGroupRate, SIGNAL(buttonClicked(int)), this, SLOT(SetRateCorrection()));
connect(spinCustomDeadTime, SIGNAL(editingFinished()), this, SLOT(SetRateCorrection()));
FILE_LOG(logDEBUG) << "Getting Rate Correction";
disconnect(chkRate, SIGNAL(toggled(bool)), this,
SLOT(EnableRateCorrection()));
disconnect(btnGroupRate, SIGNAL(buttonClicked(int)), this,
SLOT(SetRateCorrection()));
disconnect(spinCustomDeadTime, SIGNAL(editingFinished()), this,
SLOT(SetRateCorrection()));
try {
spinCustomDeadTime->setValue(-1);
int64_t retval = det->getRateCorrection()
.tsquash("Rate correction (enable/tau) is "
"inconsistent for all detectors.")
.count();
chkRate->setChecked(retval == 0 ? false : true);
if (retval != 0)
spinCustomDeadTime->setValue(retval);
}
CATCH_DISPLAY("Could not get rate correction.",
"qTabDataOutput::GetRateCorrection")
connect(chkRate, SIGNAL(toggled(bool)), this, SLOT(EnableRateCorrection()));
connect(btnGroupRate, SIGNAL(buttonClicked(int)), this,
SLOT(SetRateCorrection()));
connect(spinCustomDeadTime, SIGNAL(editingFinished()), this,
SLOT(SetRateCorrection()));
}
void qTabDataOutput::EnableRateCorrection() {
// enable
if (chkRate->isChecked()) {
SetRateCorrection();
return;
}
FILE_LOG(logINFO) << "Disabling Rate correction";
// disable
try {
det->setRateCorrection(sls::ns(0));
} CATCH_HANDLE ("Could not switch off rate correction.", "qTabDataOutput::EnableRateCorrection", this, &qTabDataOutput::GetRateCorrection)
// enable
if (chkRate->isChecked()) {
SetRateCorrection();
return;
}
FILE_LOG(logINFO) << "Disabling Rate correction";
// disable
try {
det->setRateCorrection(sls::ns(0));
}
CATCH_HANDLE("Could not switch off rate correction.",
"qTabDataOutput::EnableRateCorrection", this,
&qTabDataOutput::GetRateCorrection)
}
void qTabDataOutput::SetRateCorrection() {
// do nothing if rate correction is disabled
if (!chkRate->isChecked()) {
return;
}
try {
// custom dead time
if (radioCustomDeadtime->isChecked()) {
int64_t deadtime = spinCustomDeadTime->value();
FILE_LOG(logINFO) << "Setting Rate Correction with custom dead time: " << deadtime;
det->setRateCorrection(sls::ns(deadtime));
}
// default dead time
else {
FILE_LOG(logINFO) << "Setting Rate Correction with default dead time";
det->setDefaultRateCorrection();
}
} CATCH_HANDLE ("Could not set rate correction.", "qTabDataOutput::SetRateCorrection", this, &qTabDataOutput::GetRateCorrection)
// do nothing if rate correction is disabled
if (!chkRate->isChecked()) {
return;
}
try {
// custom dead time
if (radioCustomDeadtime->isChecked()) {
int64_t deadtime = spinCustomDeadTime->value();
FILE_LOG(logINFO)
<< "Setting Rate Correction with custom dead time: "
<< deadtime;
det->setRateCorrection(sls::ns(deadtime));
}
// default dead time
else {
FILE_LOG(logINFO)
<< "Setting Rate Correction with default dead time";
det->setDefaultRateCorrection();
}
}
CATCH_HANDLE("Could not set rate correction.",
"qTabDataOutput::SetRateCorrection", this,
&qTabDataOutput::GetRateCorrection)
}
void qTabDataOutput::GetSpeed() {
FILE_LOG(logDEBUG) << "Getting Speed";
disconnect(comboEigerClkDivider, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSpeed(int)));
try {
auto retval = det->getSpeed().tsquash("Speed is inconsistent for all detectors.");
comboEigerClkDivider->setCurrentIndex(static_cast<int>(retval));
} CATCH_DISPLAY ("Could not get speed.", "qTabDataOutput::GetSpeed")
connect(comboEigerClkDivider, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSpeed(int)));
FILE_LOG(logDEBUG) << "Getting Speed";
disconnect(comboEigerClkDivider, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetSpeed(int)));
try {
auto retval =
det->getSpeed().tsquash("Speed is inconsistent for all detectors.");
comboEigerClkDivider->setCurrentIndex(static_cast<int>(retval));
}
CATCH_DISPLAY("Could not get speed.", "qTabDataOutput::GetSpeed")
connect(comboEigerClkDivider, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetSpeed(int)));
}
void qTabDataOutput::SetSpeed(int speed) {
FILE_LOG(logINFO) << "Setting Speed to " << comboEigerClkDivider->currentText().toAscii().data();;
try {
FILE_LOG(logINFO) << "Setting Speed to "
<< comboEigerClkDivider->currentText().toAscii().data();
;
try {
det->setSpeed(static_cast<slsDetectorDefs::speedLevel>(speed));
} CATCH_HANDLE ("Could not set speed.", "qTabDataOutput::SetSpeed", this, &qTabDataOutput::GetSpeed)
}
CATCH_HANDLE("Could not set speed.", "qTabDataOutput::SetSpeed", this,
&qTabDataOutput::GetSpeed)
}
void qTabDataOutput::GetFlags() {
FILE_LOG(logDEBUG) << "Getting readout flags";
disconnect(comboEigerParallelFlag, SIGNAL(currentIndexChanged(int)), this, SLOT(SetFlags()));
try {
auto retval = det->getParallelMode().tsquash("Parallel Flag is inconsistent for all detectors.");
// parallel or non parallel
if (retval)
comboEigerParallelFlag->setCurrentIndex(PARALLEL);
else
comboEigerParallelFlag->setCurrentIndex(NONPARALLEL);
} CATCH_DISPLAY ("Could not get flags.", "qTabDataOutput::GetFlags")
connect(comboEigerParallelFlag, SIGNAL(currentIndexChanged(int)), this, SLOT(SetFlags()));
FILE_LOG(logDEBUG) << "Getting readout flags";
disconnect(comboEigerParallelFlag, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetFlags()));
try {
auto retval = det->getParallelMode().tsquash(
"Parallel Flag is inconsistent for all detectors.");
// parallel or non parallel
if (retval)
comboEigerParallelFlag->setCurrentIndex(PARALLEL);
else
comboEigerParallelFlag->setCurrentIndex(NONPARALLEL);
}
CATCH_DISPLAY("Could not get flags.", "qTabDataOutput::GetFlags")
connect(comboEigerParallelFlag, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetFlags()));
}
void qTabDataOutput::SetFlags() {
auto mode = comboEigerParallelFlag->currentIndex() == PARALLEL ? true : false;
try {
FILE_LOG(logINFO) << "Setting Readout Flags to " << comboEigerParallelFlag->currentText().toAscii().data();
det->setParallelMode(mode);
} CATCH_HANDLE ("Could not set readout flags.", "qTabDataOutput::SetFlags", this, &qTabDataOutput::GetFlags)
auto mode =
comboEigerParallelFlag->currentIndex() == PARALLEL ? true : false;
try {
FILE_LOG(logINFO)
<< "Setting Readout Flags to "
<< comboEigerParallelFlag->currentText().toAscii().data();
det->setParallelMode(mode);
}
CATCH_HANDLE("Could not set readout flags.", "qTabDataOutput::SetFlags",
this, &qTabDataOutput::GetFlags)
}
void qTabDataOutput::Refresh() {
FILE_LOG(logDEBUG) << "**Updating DataOutput Tab";
FILE_LOG(logDEBUG) << "**Updating DataOutput Tab";
EnableBrowse();
GetFileWrite();
GetFileName();
GetOutputDir();
GetFileOverwrite();
GetFileFormat();
if (chkRate->isEnabled()) {
GetRateCorrection();
}
if (chkTenGiga->isEnabled()) {
GetTenGigaEnable();
}
if (widgetEiger->isEnabled()) {
GetSpeed();
GetFlags();
}
EnableBrowse();
GetFileWrite();
GetFileName();
GetOutputDir();
GetFileOverwrite();
GetFileFormat();
if (chkRate->isEnabled()) {
GetRateCorrection();
}
if (chkTenGiga->isEnabled()) {
GetTenGigaEnable();
}
if (widgetEiger->isEnabled()) {
GetSpeed();
GetFlags();
}
FILE_LOG(logDEBUG) << "**Updated DataOutput Tab";
FILE_LOG(logDEBUG) << "**Updated DataOutput Tab";
}

134
slsDetectorGui/src/qTabDebugging.cpp Executable file → Normal file
View File

@ -9,23 +9,24 @@
#include <iostream>
qTabDebugging::qTabDebugging(QWidget *parent, sls::Detector *detector) :
QWidget(parent), det(detector), treeDet(nullptr), lblDetectorHostname(nullptr), lblDetectorFirmware(nullptr), lblDetectorSoftware(nullptr) {
qTabDebugging::qTabDebugging(QWidget *parent, sls::Detector *detector)
: QWidget(parent), det(detector), treeDet(nullptr),
lblDetectorHostname(nullptr), lblDetectorFirmware(nullptr),
lblDetectorSoftware(nullptr) {
setupUi(this);
SetupWidgetWindow();
FILE_LOG(logDEBUG) << "Debugging ready";
}
qTabDebugging::~qTabDebugging() {
delete treeDet;
delete lblDetectorHostname;
delete lblDetectorFirmware;
delete lblDetectorSoftware;
delete treeDet;
delete lblDetectorHostname;
delete lblDetectorFirmware;
delete lblDetectorSoftware;
}
void qTabDebugging::SetupWidgetWindow() {
// enabling according to det type
// enabling according to det type
if (det->getDetectorType().squash() == slsDetectorDefs::EIGER) {
lblDetector->setText("Half Module:");
chkDetectorFirmware->setEnabled(false);
@ -40,19 +41,19 @@ void qTabDebugging::SetupWidgetWindow() {
Refresh();
}
void qTabDebugging::Initialization() {
connect(comboDetector, SIGNAL(currentIndexChanged(int)), this, SLOT(GetDetectorStatus()));
connect(comboDetector, SIGNAL(currentIndexChanged(int)), this,
SLOT(GetDetectorStatus()));
connect(btnGetInfo, SIGNAL(clicked()), this, SLOT(GetInfo()));
if (btnTest ->isEnabled()) {
connect(btnTest, SIGNAL(clicked()), this, SLOT(TestDetector()));
if (btnTest->isEnabled()) {
connect(btnTest, SIGNAL(clicked()), this, SLOT(TestDetector()));
}
}
void qTabDebugging::PopulateDetectors() {
FILE_LOG(logDEBUG) << "Populating detectors";
FILE_LOG(logDEBUG) << "Populating detectors";
comboDetector->clear();
comboDetector->clear();
auto res = det->getHostname();
for (auto &it : res) {
comboDetector->addItem(QString(it.c_str()));
@ -62,13 +63,15 @@ void qTabDebugging::PopulateDetectors() {
void qTabDebugging::GetDetectorStatus() {
FILE_LOG(logDEBUG) << "Getting Status";
try {
std::string status = sls::ToString(det->getDetectorStatus({comboDetector->currentIndex()})[0]);
try {
std::string status = sls::ToString(
det->getDetectorStatus({comboDetector->currentIndex()})[0]);
lblStatus->setText(QString(status.c_str()).toUpper());
} CATCH_DISPLAY ("Could not get detector status.", "qTabDebugging::GetDetectorStatus")
}
CATCH_DISPLAY("Could not get detector status.",
"qTabDebugging::GetDetectorStatus")
}
void qTabDebugging::GetInfo() {
FILE_LOG(logDEBUG) << "Getting Readout Info";
@ -83,67 +86,83 @@ void qTabDebugging::GetInfo() {
lblDetectorHostname = new QLabel("");
lblDetectorFirmware = new QLabel("");
lblDetectorSoftware = new QLabel("");
//to make sure the size is constant
// to make sure the size is constant
lblDetectorFirmware->setFixedWidth(100);
layout->addWidget(dispFrame, 0, 1);
QString detName = QString(sls::ToString(det->getDetectorType().squash()).c_str());
QString detName =
QString(sls::ToString(det->getDetectorType().squash()).c_str());
switch (det->getDetectorType().squash()) {
case slsDetectorDefs::EIGER:
formLayout->addWidget(new QLabel("Half Module:"), 0, 0);
formLayout->addItem(new QSpacerItem(15, 20, QSizePolicy::Fixed, QSizePolicy::Fixed), 0, 1);
formLayout->addItem(
new QSpacerItem(15, 20, QSizePolicy::Fixed, QSizePolicy::Fixed), 0,
1);
formLayout->addWidget(lblDetectorHostname, 0, 2);
formLayout->addWidget(new QLabel("Half Module Firmware Version:"), 1, 0);
formLayout->addWidget(new QLabel("Half Module Firmware Version:"), 1,
0);
formLayout->addWidget(lblDetectorFirmware, 1, 2);
formLayout->addWidget(new QLabel("Half Module Software Version:"), 2, 0);
formLayout->addWidget(new QLabel("Half Module Software Version:"), 2,
0);
formLayout->addWidget(lblDetectorSoftware, 2, 2);
treeDet->setHeaderLabel("Eiger Detector");
//get num modules
// get num modules
for (int i = 0; i < comboDetector->count() / 2; ++i)
items.append(new QTreeWidgetItem((QTreeWidget *)0, QStringList(QString("Module %1").arg(i))));
items.append(new QTreeWidgetItem(
(QTreeWidget *)0, QStringList(QString("Module %1").arg(i))));
treeDet->insertTopLevelItems(0, items);
//gets det names
// gets det names
for (int i = 0; i < comboDetector->count(); ++i) {
QList<QTreeWidgetItem *> childItems;
childItems.append(new QTreeWidgetItem((QTreeWidget *)0, QStringList(QString("Half Module (%1)").arg(comboDetector->itemText(i)))));
childItems.append(new QTreeWidgetItem(
(QTreeWidget *)0,
QStringList(QString("Half Module (%1)")
.arg(comboDetector->itemText(i)))));
treeDet->topLevelItem(i * 2)->insertChildren(0, childItems);
}
break;
default:
formLayout->addWidget(new QLabel("Module:"), 0, 0);
formLayout->addItem(new QSpacerItem(15, 20, QSizePolicy::Fixed, QSizePolicy::Fixed), 0, 1);
formLayout->addItem(
new QSpacerItem(15, 20, QSizePolicy::Fixed, QSizePolicy::Fixed), 0,
1);
formLayout->addWidget(lblDetectorHostname, 0, 2);
formLayout->addWidget(new QLabel("Module Firmware Version:"), 1, 0);
formLayout->addWidget(lblDetectorFirmware, 1, 2);
formLayout->addWidget(new QLabel("Module Software Version:"), 2, 0);
formLayout->addWidget(lblDetectorSoftware, 2, 2);
treeDet->setHeaderLabel(QString(detName + " Detector"));
//gets det names
// gets det names
for (int i = 0; i < comboDetector->count(); ++i)
items.append(new QTreeWidgetItem((QTreeWidget *)0, QStringList(QString("Module (%1)").arg(comboDetector->itemText(i)))));
items.append(new QTreeWidgetItem(
(QTreeWidget *)0,
QStringList(
QString("Module (%1)").arg(comboDetector->itemText(i)))));
treeDet->insertTopLevelItems(0, items);
break;
}
//show and center widget
// show and center widget
int x = ((parentWidget()->width()) - (popup1->frameGeometry().width())) / 2;
int y = ((parentWidget()->height()) - (popup1->frameGeometry().height())) / 2;
int y =
((parentWidget()->height()) - (popup1->frameGeometry().height())) / 2;
QDesktopWidget *desktop = QApplication::desktop();
int screen = desktop->screenNumber(this);
popup1->setWindowModality(Qt::WindowModal);
popup1->move((desktop->screenGeometry(screen).x()) + x, (desktop->screenGeometry(screen).y()) + y);
popup1->move((desktop->screenGeometry(screen).x()) + x,
(desktop->screenGeometry(screen).y()) + y);
popup1->show();
//put the first parameters
// put the first parameters
SetParameters(treeDet->topLevelItem(0));
// connect to slots
connect(treeDet, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(SetParameters(QTreeWidgetItem *)));
connect(treeDet, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
SLOT(SetParameters(QTreeWidgetItem *)));
}
void qTabDebugging::SetParameters(QTreeWidgetItem *item) {
// eiger: if half module clicked, others: true always
bool ignoreOrHalfModuleClicked = true;
@ -160,11 +179,17 @@ void qTabDebugging::SetParameters(QTreeWidgetItem *item) {
break;
}
try {
auto retval = std::string("0x") + std::to_string((unsigned long)det->getFirmwareVersion({comboDetector->currentIndex()})[0]);
auto retval = std::string("0x") +
std::to_string((unsigned long)det->getFirmwareVersion(
{comboDetector->currentIndex()})[0]);
lblDetectorFirmware->setText(QString(retval.c_str()));
retval = std::string("0x") + std::to_string((unsigned long)det->getDetectorServerVersion({comboDetector->currentIndex()})[0]);
retval =
std::string("0x") +
std::to_string((unsigned long)det->getDetectorServerVersion(
{comboDetector->currentIndex()})[0]);
lblDetectorSoftware->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get versions.", "qTabDebugging::SetParameters")
}
CATCH_DISPLAY("Could not get versions.", "qTabDebugging::SetParameters")
}
}
@ -178,35 +203,42 @@ void qTabDebugging::TestDetector() {
}
// construct message
QString message = QString("<nobr>Test Results for %1:</nobr><br><br>").arg(comboDetector->currentText());
QString message = QString("<nobr>Test Results for %1:</nobr><br><br>")
.arg(comboDetector->currentText());
//detector firmware
// detector firmware
if (chkDetectorFirmware->isChecked()) {
try {
det->executeFirmwareTest({comboDetector->currentIndex()});
message.append(QString("<nobr>%1 Firmware: PASS</nobr><br>").arg(moduleName));
message.append(QString("<nobr>%1 Firmware: PASS</nobr><br>")
.arg(moduleName));
FILE_LOG(logINFO) << "Detector Firmware Test: Pass";
} CATCH_DISPLAY ("Firmware test failed.", "qTabDebugging::TestDetector")
}
CATCH_DISPLAY("Firmware test failed.",
"qTabDebugging::TestDetector")
}
//detector CPU-FPGA bus
// detector CPU-FPGA bus
if (chkDetectorBus->isChecked()) {
try {
det->executeBusTest({comboDetector->currentIndex()});
message.append(QString("<nobr>%1 Bus: PASS</nobr><br>").arg(moduleName));
message.append(
QString("<nobr>%1 Bus: PASS</nobr><br>").arg(moduleName));
FILE_LOG(logINFO) << "Detector Bus Test: Pass";
} CATCH_DISPLAY ("Bus test failed.", "qTabDebugging::TestDetector")
}
CATCH_DISPLAY("Bus test failed.", "qTabDebugging::TestDetector")
}
//display message
qDefs::Message(qDefs::INFORMATION, message.toAscii().constData(), "qTabDebugging::TestDetector");
} CATCH_DISPLAY ("Could not execute digital test.", "qTabDebugging::TestDetector")
// display message
qDefs::Message(qDefs::INFORMATION, message.toAscii().constData(),
"qTabDebugging::TestDetector");
}
CATCH_DISPLAY("Could not execute digital test.",
"qTabDebugging::TestDetector")
}
void qTabDebugging::Refresh() {
FILE_LOG(logDEBUG) << "**Updating Debugging Tab";
GetDetectorStatus();
FILE_LOG(logDEBUG) << "**Updated Debugging Tab";
}

976
slsDetectorGui/src/qTabDeveloper.cpp Executable file → Normal file

File diff suppressed because it is too large Load Diff

1209
slsDetectorGui/src/qTabMeasurement.cpp Executable file → Normal file

File diff suppressed because it is too large Load Diff

72
slsDetectorGui/src/qTabMessages.cpp Executable file → Normal file
View File

@ -1,12 +1,12 @@
#include "qTabMessages.h"
#include "qDefs.h"
#include <QDir>
#include <QFile>
#include <QFileDialog>
#include <QTextStream>
#include <QDir>
#include <QProcess>
#include <QKeyEvent>
#include <QProcess>
#include <QTextStream>
#include <iostream>
#include <string>
@ -37,32 +37,32 @@ void qTabMessages::Initialization() {
connect(dispCommand, SIGNAL(returnPressed()), this, SLOT(ExecuteCommand()));
}
void qTabMessages::keyPressEvent(QKeyEvent* event) {
//cout<<"inside KeyPressEvent()\n";
if (event->key() == Qt::Key_Up) {
void qTabMessages::keyPressEvent(QKeyEvent *event) {
// cout<<"inside KeyPressEvent()\n";
if (event->key() == Qt::Key_Up) {
GetLastCommand();
}
else if (event->key() == Qt::Key_Down) {
} else if (event->key() == Qt::Key_Down) {
ClearCommand();
}
/* else if((event->key() == Qt::Key_Return) ||(event->key() == Qt::Key_Enter)) {
ExecuteCommand();
}*/ else {
event->ignore();
}
/* else if((event->key() == Qt::Key_Return) ||(event->key() ==
Qt::Key_Enter)) { ExecuteCommand();
}*/
else {
event->ignore();
}
}
void qTabMessages::PrintNextLine() {
dispLog->append(QString("<font color = \"DarkGrey\">") + QDir::current().dirName() + QString("$ ") + QString("</font>"));
dispLog->append(QString("<font color = \"DarkGrey\">") +
QDir::current().dirName() + QString("$ ") +
QString("</font>"));
}
void qTabMessages::GetLastCommand() {
dispCommand->setText(lastCommand.join(" "));
dispCommand->setText(lastCommand.join(" "));
}
void qTabMessages::ClearCommand() {
dispCommand->setText("");
}
void qTabMessages::ClearCommand() { dispCommand->setText(""); }
void qTabMessages::ExecuteCommand() {
QStringList param = dispCommand->text().split(" ");
@ -70,16 +70,19 @@ void qTabMessages::ExecuteCommand() {
lastCommand += param;
dispCommand->clear();
// appending command to log without newline
dispLog->moveCursor (QTextCursor::End);
dispLog->insertHtml(QString("<font color = \"DarkBlue\">") + param.join(" ") + QString("</font>"));
dispLog->moveCursor(QTextCursor::End);
dispLog->insertHtml(QString("<font color = \"DarkBlue\">") +
param.join(" ") + QString("</font>"));
QString command = param.at(0);
param.removeFirst();
FILE_LOG(logINFO) << "Executing Command:[" << command.toAscii().constData() << "] with Arguments:[" << param.join(" ").toAscii().constData() << "]";
FILE_LOG(logINFO) << "Executing Command:[" << command.toAscii().constData()
<< "] with Arguments:["
<< param.join(" ").toAscii().constData() << "]";
process->setProcessChannelMode(QProcess::MergedChannels);
process->start(command, param);
if(!process->waitForFinished()) {
if (!process->waitForFinished()) {
AppendError();
} else {
AppendOutput();
@ -89,34 +92,40 @@ void qTabMessages::ExecuteCommand() {
void qTabMessages::AppendOutput() {
QByteArray result = process->readAll();
result.replace("\n", "<br>");
dispLog->append(QString("<font color = \"DarkBlue\">") + result + QString("</font>"));
dispLog->append(QString("<font color = \"DarkBlue\">") + result +
QString("</font>"));
FILE_LOG(logDEBUG) << "Command executed successfully";
PrintNextLine();
}
void qTabMessages::AppendError() {
dispLog->append(QString("<font color = \"Red\">") + process->errorString() + QString("</font>"));
dispLog->append(QString("<font color = \"Red\">") + process->errorString() +
QString("</font>"));
FILE_LOG(logERROR) << "Error executing command";
PrintNextLine();
}
void qTabMessages::SaveLog() {
QString fName = QDir::cleanPath(QDir::currentPath()) + "/LogFile.txt";
fName = QFileDialog::getSaveFileName(this, tr("Save Snapshot "),
fName, tr("Text files (*.txt);;All Files(*)"));
fName =
QFileDialog::getSaveFileName(this, tr("Save Snapshot "), fName,
tr("Text files (*.txt);;All Files(*)"));
if (!fName.isEmpty()) {
QFile outfile;
outfile.setFileName(fName);
if (outfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&outfile);
out << dispLog->toPlainText() << endl;
std::string mess = std::string("The Log has been successfully saved to ") + fName.toAscii().constData();
std::string mess =
std::string("The Log has been successfully saved to ") +
fName.toAscii().constData();
qDefs::Message(qDefs::INFORMATION, mess, "TabMessages::SaveLog");
FILE_LOG(logINFO) << mess;
} else {
FILE_LOG(logWARNING) << "Attempt to save log file failed: " << fName.toAscii().constData();
qDefs::Message(qDefs::WARNING, "Attempt to save log file failed.", "qTabMessages::SaveLog");
FILE_LOG(logWARNING) << "Attempt to save log file failed: "
<< fName.toAscii().constData();
qDefs::Message(qDefs::WARNING, "Attempt to save log file failed.",
"qTabMessages::SaveLog");
}
}
dispCommand->setFocus();
@ -133,4 +142,3 @@ void qTabMessages::Refresh() {
dispCommand->clear();
dispCommand->setFocus();
}

390
slsDetectorGui/src/qTabPlot.cpp Executable file → Normal file
View File

@ -2,10 +2,10 @@
#include "qDefs.h"
#include "qDrawPlot.h"
#include <QStandardItemModel>
#include <QStackedLayout>
#include <QButtonGroup>
#include <QAbstractButton>
#include <QButtonGroup>
#include <QStackedLayout>
#include <QStandardItemModel>
#include <iostream>
#include <math.h>
@ -18,17 +18,14 @@ QString qTabPlot::defaultImageXAxisTitle("Pixel");
QString qTabPlot::defaultImageYAxisTitle("Pixel");
QString qTabPlot::defaultImageZAxisTitle("Intensity");
qTabPlot::qTabPlot(QWidget *parent, sls::Detector *detector, qDrawPlot *p) :
QWidget(parent), det(detector), plot(p), is1d(false) {
qTabPlot::qTabPlot(QWidget *parent, sls::Detector *detector, qDrawPlot *p)
: QWidget(parent), det(detector), plot(p), is1d(false) {
setupUi(this);
SetupWidgetWindow();
FILE_LOG(logDEBUG) << "Plot ready";
}
qTabPlot::~qTabPlot() {
delete btnGroupPlotType;
}
qTabPlot::~qTabPlot() { delete btnGroupPlotType; }
void qTabPlot::SetupWidgetWindow() {
// button group for plot type
@ -56,27 +53,27 @@ void qTabPlot::SetupWidgetWindow() {
// enabling according to det type
is1d = false;
switch(det->getDetectorType().squash()) {
case slsDetectorDefs::GOTTHARD:
case slsDetectorDefs::MYTHEN3:
is1d = true;
break;
case slsDetectorDefs::GOTTHARD2:
is1d = true;
chkGainPlot1D->setEnabled(true);
chkGainPlot1D->setChecked(true);
plot->EnableGainPlot(true);
break;
case slsDetectorDefs::EIGER:
chkGapPixels->setEnabled(true);
break;
case slsDetectorDefs::JUNGFRAU:
chkGainPlot->setEnabled(true);
chkGainPlot->setChecked(true);
plot->EnableGainPlot(true);
break;
default:
break;
switch (det->getDetectorType().squash()) {
case slsDetectorDefs::GOTTHARD:
case slsDetectorDefs::MYTHEN3:
is1d = true;
break;
case slsDetectorDefs::GOTTHARD2:
is1d = true;
chkGainPlot1D->setEnabled(true);
chkGainPlot1D->setChecked(true);
plot->EnableGainPlot(true);
break;
case slsDetectorDefs::EIGER:
chkGapPixels->setEnabled(true);
break;
case slsDetectorDefs::JUNGFRAU:
chkGainPlot->setEnabled(true);
chkGainPlot->setChecked(true);
plot->EnableGainPlot(true);
break;
default:
break;
}
Select1DPlot(is1d);
@ -86,58 +83,78 @@ void qTabPlot::SetupWidgetWindow() {
void qTabPlot::Initialization() {
// Plot arguments box
connect(btnGroupPlotType, SIGNAL(buttonClicked(int)), this, SLOT(SetPlot()));
connect(btnGroupPlotType, SIGNAL(buttonClicked(int)), this,
SLOT(SetPlot()));
// Plotting frequency box
connect(comboFrequency, SIGNAL(currentIndexChanged(int)), this, SLOT(SetStreamingFrequency()));
connect(comboTimeGapUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetStreamingFrequency()));
connect(spinTimeGap, SIGNAL(editingFinished()), this, SLOT(SetStreamingFrequency()));
connect(spinNthFrame, SIGNAL(editingFinished()), this, SLOT(SetStreamingFrequency()));
connect(comboFrequency, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetStreamingFrequency()));
connect(comboTimeGapUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetStreamingFrequency()));
connect(spinTimeGap, SIGNAL(editingFinished()), this,
SLOT(SetStreamingFrequency()));
connect(spinNthFrame, SIGNAL(editingFinished()), this,
SLOT(SetStreamingFrequency()));
// navigation buttons for options
connect(btnRight1D, SIGNAL(clicked()), this, SLOT(Set1DPlotOptionsRight()));
connect(btnLeft1D, SIGNAL(clicked()), this, SLOT(Set1DPlotOptionsLeft()));
connect(btnRight2D, SIGNAL(clicked()), this, SLOT(Set2DPlotOptionsRight()));
connect(btnLeft2D, SIGNAL(clicked()), this, SLOT(Set2DPlotOptionsLeft()));
// 1D options
connect(chkSuperimpose, SIGNAL(toggled(bool)), this, SLOT(EnablePersistency(bool)));
connect(spinPersistency, SIGNAL(valueChanged(int)), plot, SLOT(SetPersistency(int)));
connect(chkSuperimpose, SIGNAL(toggled(bool)), this,
SLOT(EnablePersistency(bool)));
connect(spinPersistency, SIGNAL(valueChanged(int)), plot,
SLOT(SetPersistency(int)));
connect(chkPoints, SIGNAL(toggled(bool)), plot, SLOT(SetMarkers(bool)));
connect(chkLines, SIGNAL(toggled(bool)), plot, SLOT(SetLines(bool)));
connect(chk1DLog, SIGNAL(toggled(bool)), plot, SLOT(Set1dLogY(bool)));
connect(chkStatistics, SIGNAL(toggled(bool)), plot, SLOT(DisplayStatistics(bool)));
connect(chkStatistics, SIGNAL(toggled(bool)), plot,
SLOT(DisplayStatistics(bool)));
// 2D Plot box
connect(chkInterpolate, SIGNAL(toggled(bool)), plot, SLOT(SetInterpolate(bool)));
connect(chkInterpolate, SIGNAL(toggled(bool)), plot,
SLOT(SetInterpolate(bool)));
connect(chkContour, SIGNAL(toggled(bool)), plot, SLOT(SetContour(bool)));
connect(chkLogz, SIGNAL(toggled(bool)), plot, SLOT(SetLogz(bool)));
connect(chkStatistics_2, SIGNAL(toggled(bool)), plot, SLOT(DisplayStatistics(bool)));
//pedstal
connect(chkStatistics_2, SIGNAL(toggled(bool)), plot,
SLOT(DisplayStatistics(bool)));
// pedstal
connect(chkPedestal, SIGNAL(toggled(bool)), plot, SLOT(SetPedestal(bool)));
connect(btnRecalPedestal, SIGNAL(clicked()), plot, SLOT(RecalculatePedestal()));
connect(chkPedestal_2, SIGNAL(toggled(bool)), plot, SLOT(SetPedestal(bool)));
connect(btnRecalPedestal_2, SIGNAL(clicked()), plot, SLOT(RecalculatePedestal()));
//accumulate
connect(chkAccumulate, SIGNAL(toggled(bool)), plot, SLOT(SetAccumulate(bool)));
connect(btnResetAccumulate, SIGNAL(clicked()), plot, SLOT(ResetAccumulate()));
connect(chkAccumulate_2, SIGNAL(toggled(bool)), plot, SLOT(SetAccumulate(bool)));
connect(btnResetAccumulate_2, SIGNAL(clicked()), plot, SLOT(ResetAccumulate()));
//binary
connect(btnRecalPedestal, SIGNAL(clicked()), plot,
SLOT(RecalculatePedestal()));
connect(chkPedestal_2, SIGNAL(toggled(bool)), plot,
SLOT(SetPedestal(bool)));
connect(btnRecalPedestal_2, SIGNAL(clicked()), plot,
SLOT(RecalculatePedestal()));
// accumulate
connect(chkAccumulate, SIGNAL(toggled(bool)), plot,
SLOT(SetAccumulate(bool)));
connect(btnResetAccumulate, SIGNAL(clicked()), plot,
SLOT(ResetAccumulate()));
connect(chkAccumulate_2, SIGNAL(toggled(bool)), plot,
SLOT(SetAccumulate(bool)));
connect(btnResetAccumulate_2, SIGNAL(clicked()), plot,
SLOT(ResetAccumulate()));
// binary
connect(chkBinary, SIGNAL(toggled(bool)), this, SLOT(SetBinary()));
connect(chkBinary_2, SIGNAL(toggled(bool)), this, SLOT(SetBinary()));
connect(spinFrom, SIGNAL(valueChanged(int)), this, SLOT(SetBinary()));
connect(spinFrom_2, SIGNAL(valueChanged(int)), this, SLOT(SetBinary()));
connect(spinTo, SIGNAL(valueChanged(int)), this, SLOT(SetBinary()));
connect(spinTo_2, SIGNAL(valueChanged(int)), this, SLOT(SetBinary()));
//gainplot
// gainplot
if (chkGainPlot->isEnabled())
connect(chkGainPlot, SIGNAL(toggled(bool)), plot, SLOT(EnableGainPlot(bool)));
connect(chkGainPlot, SIGNAL(toggled(bool)), plot,
SLOT(EnableGainPlot(bool)));
if (chkGainPlot1D->isEnabled())
connect(chkGainPlot1D, SIGNAL(toggled(bool)), plot, SLOT(EnableGainPlot(bool)));
connect(chkGainPlot1D, SIGNAL(toggled(bool)), plot,
SLOT(EnableGainPlot(bool)));
// gap pixels
if (chkGapPixels->isEnabled())
connect(chkGapPixels, SIGNAL(toggled(bool)), this, SLOT(SetGapPixels(bool)));
connect(chkGapPixels, SIGNAL(toggled(bool)), this,
SLOT(SetGapPixels(bool)));
// Save, clone
connect(btnSave, SIGNAL(clicked()), plot, SLOT(SavePlot()));
@ -148,10 +165,14 @@ void qTabPlot::Initialization() {
connect(chkXAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
connect(chkYAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
connect(chkZAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
connect(dispTitle, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
connect(dispXAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
connect(dispYAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
connect(dispZAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
connect(dispTitle, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
connect(dispXAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
connect(dispYAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
connect(dispZAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
connect(chkXMin, SIGNAL(toggled(bool)), this, SLOT(SetXRange()));
connect(chkXMax, SIGNAL(toggled(bool)), this, SLOT(SetXRange()));
@ -161,7 +182,8 @@ void qTabPlot::Initialization() {
connect(dispXMax, SIGNAL(editingFinished()), this, SLOT(SetXRange()));
connect(dispYMin, SIGNAL(editingFinished()), this, SLOT(SetYRange()));
connect(dispYMax, SIGNAL(editingFinished()), this, SLOT(SetYRange()));
connect(chkAspectRatio, SIGNAL(toggled(bool)), this, SLOT(CheckAspectRatio()));
connect(chkAspectRatio, SIGNAL(toggled(bool)), this,
SLOT(CheckAspectRatio()));
connect(chkZMin, SIGNAL(toggled(bool)), this, SLOT(SetZRange()));
connect(chkZMax, SIGNAL(toggled(bool)), this, SLOT(SetZRange()));
@ -209,7 +231,7 @@ void qTabPlot::SetPlot() {
SetZRange();
}
}
plot->SetDataCallBack(plotEnable);
}
@ -220,7 +242,8 @@ void qTabPlot::Set1DPlotOptionsRight() {
stackedWidget1D->setCurrentIndex(0);
else
stackedWidget1D->setCurrentIndex(i + 1);
box1D->setTitle(QString("1D Plot Options %1").arg(stackedWidget1D->currentIndex() + 1));
box1D->setTitle(
QString("1D Plot Options %1").arg(stackedWidget1D->currentIndex() + 1));
}
void qTabPlot::Set1DPlotOptionsLeft() {
@ -230,7 +253,8 @@ void qTabPlot::Set1DPlotOptionsLeft() {
stackedWidget1D->setCurrentIndex(stackedWidget1D->count() - 1);
else
stackedWidget1D->setCurrentIndex(i - 1);
box1D->setTitle(QString("1D Plot Options %1").arg(stackedWidget1D->currentIndex() + 1));
box1D->setTitle(
QString("1D Plot Options %1").arg(stackedWidget1D->currentIndex() + 1));
}
void qTabPlot::Set2DPlotOptionsRight() {
@ -240,7 +264,8 @@ void qTabPlot::Set2DPlotOptionsRight() {
stackedWidget2D->setCurrentIndex(0);
else
stackedWidget2D->setCurrentIndex(i + 1);
box2D->setTitle(QString("2D Plot Options %1").arg(stackedWidget2D->currentIndex() + 1));
box2D->setTitle(
QString("2D Plot Options %1").arg(stackedWidget2D->currentIndex() + 1));
}
void qTabPlot::Set2DPlotOptionsLeft() {
@ -250,7 +275,8 @@ void qTabPlot::Set2DPlotOptionsLeft() {
stackedWidget2D->setCurrentIndex(stackedWidget2D->count() - 1);
else
stackedWidget2D->setCurrentIndex(i - 1);
box2D->setTitle(QString("2D Plot Options %1").arg(stackedWidget2D->currentIndex() + 1));
box2D->setTitle(
QString("2D Plot Options %1").arg(stackedWidget2D->currentIndex() + 1));
}
void qTabPlot::EnablePersistency(bool enable) {
@ -265,16 +291,18 @@ void qTabPlot::EnablePersistency(bool enable) {
void qTabPlot::SetBinary() {
bool binary1D = chkBinary->isChecked();
bool binary2D = chkBinary_2->isChecked();
bool binary2D = chkBinary_2->isChecked();
if (is1d) {
FILE_LOG(logINFO) << "Binary Plot " << (binary1D ? "enabled" : "disabled");
FILE_LOG(logINFO) << "Binary Plot "
<< (binary1D ? "enabled" : "disabled");
lblFrom->setEnabled(binary1D);
lblTo->setEnabled(binary1D);
spinFrom->setEnabled(binary1D);
spinTo->setEnabled(binary1D);
plot->SetBinary(binary1D, spinFrom->value(), spinTo->value());
} else {
FILE_LOG(logINFO) << "Binary Plot " << (binary2D ? "enabled" : "disabled");
FILE_LOG(logINFO) << "Binary Plot "
<< (binary2D ? "enabled" : "disabled");
lblFrom_2->setEnabled(binary2D);
lblTo_2->setEnabled(binary2D);
spinFrom_2->setEnabled(binary2D);
@ -285,19 +313,25 @@ void qTabPlot::SetBinary() {
void qTabPlot::GetGapPixels() {
FILE_LOG(logDEBUG) << "Getting gap pixels";
disconnect(chkGapPixels, SIGNAL(toggled(bool)), this, SLOT(SetGapPixels(bool)));
try {
auto retval = det->getRxAddGapPixels().tsquash("Inconsistent gap pixels enabled for all detectors.");
chkGapPixels->setChecked(retval);
} CATCH_DISPLAY ("Could not get gap pixels enable.", "qTabPlot::GetGapPixels")
connect(chkGapPixels, SIGNAL(toggled(bool)), this, SLOT(SetGapPixels(bool)));
disconnect(chkGapPixels, SIGNAL(toggled(bool)), this,
SLOT(SetGapPixels(bool)));
try {
auto retval = det->getRxAddGapPixels().tsquash(
"Inconsistent gap pixels enabled for all detectors.");
chkGapPixels->setChecked(retval);
}
CATCH_DISPLAY("Could not get gap pixels enable.", "qTabPlot::GetGapPixels")
connect(chkGapPixels, SIGNAL(toggled(bool)), this,
SLOT(SetGapPixels(bool)));
}
void qTabPlot::SetGapPixels(bool enable) {
FILE_LOG(logINFO) << "Setting Gap Pixels Enable to " << enable;
try {
FILE_LOG(logINFO) << "Setting Gap Pixels Enable to " << enable;
try {
det->setRxAddGapPixels(enable);
} CATCH_HANDLE("Could not set gap pixels enable.", "qTabPlot::SetGapPixels", this, &qTabPlot::GetGapPixels)
}
CATCH_HANDLE("Could not set gap pixels enable.", "qTabPlot::SetGapPixels",
this, &qTabPlot::GetGapPixels)
}
void qTabPlot::SetTitles() {
@ -306,32 +340,40 @@ void qTabPlot::SetTitles() {
disconnect(chkXAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
disconnect(chkYAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
disconnect(chkZAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
disconnect(dispTitle, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
disconnect(dispXAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
disconnect(dispYAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
disconnect(dispZAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
disconnect(dispTitle, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
disconnect(dispXAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
disconnect(dispYAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
disconnect(dispZAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
// title
if (!chkTitle->isChecked() || dispTitle->text().isEmpty()) {
plot->SetPlotTitlePrefix("");
dispTitle->setText("");
dispTitle->setText("");
} else {
plot->SetPlotTitlePrefix(dispTitle->text());
}
// x
if (!chkXAxis->isChecked() || dispXAxis->text().isEmpty()) {
dispXAxis->setText(is1d ? defaultHistXAxisTitle : defaultImageXAxisTitle);
plot->SetXAxisTitle(is1d ? defaultHistXAxisTitle : defaultImageXAxisTitle);
dispXAxis->setText(is1d ? defaultHistXAxisTitle
: defaultImageXAxisTitle);
plot->SetXAxisTitle(is1d ? defaultHistXAxisTitle
: defaultImageXAxisTitle);
} else {
plot->SetXAxisTitle(dispXAxis->text());
}
}
// y
if (!chkYAxis->isChecked() || dispYAxis->text().isEmpty()) {
dispYAxis->setText(is1d ? defaultHistYAxisTitle : defaultImageYAxisTitle);
plot->SetYAxisTitle(is1d ? defaultHistYAxisTitle : defaultImageYAxisTitle);
dispYAxis->setText(is1d ? defaultHistYAxisTitle
: defaultImageYAxisTitle);
plot->SetYAxisTitle(is1d ? defaultHistYAxisTitle
: defaultImageYAxisTitle);
} else {
plot->SetYAxisTitle(dispYAxis->text());
}
}
// z
if (!chkZAxis->isChecked() || dispZAxis->text().isEmpty()) {
plot->SetZAxisTitle(defaultImageZAxisTitle);
@ -344,10 +386,14 @@ void qTabPlot::SetTitles() {
connect(chkXAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
connect(chkYAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
connect(chkZAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
connect(dispTitle, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
connect(dispXAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
connect(dispYAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
connect(dispZAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
connect(dispTitle, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
connect(dispXAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
connect(dispYAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
connect(dispZAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
}
void qTabPlot::SetXRange() {
@ -384,13 +430,18 @@ void qTabPlot::SetXYRange() {
bool isRange[4]{false, false, false, false};
double xyRange[4]{0, 0, 0, 0};
QString dispVal[4] {dispXMin->text(), dispXMax->text(), dispYMin->text(), dispYMax->text()};
bool chkVal[4] {chkXMin->isChecked(), chkXMax->isChecked(), chkYMin->isChecked(), chkYMax->isChecked()};
QString dispVal[4]{dispXMin->text(), dispXMax->text(), dispYMin->text(),
dispYMax->text()};
bool chkVal[4]{chkXMin->isChecked(), chkXMax->isChecked(),
chkYMin->isChecked(), chkYMax->isChecked()};
for (int i = 0; i < 4; ++i) {
if (chkVal[i] && !dispVal[i].isEmpty()) {
double val = dispVal[i].toDouble();
FILE_LOG(logDEBUG) << "Setting " << qDefs::getRangeAsString(static_cast<qDefs::range>(i)) << " to " << val;
FILE_LOG(logDEBUG)
<< "Setting "
<< qDefs::getRangeAsString(static_cast<qDefs::range>(i))
<< " to " << val;
xyRange[i] = val;
isRange[i] = true;
disablezoom = true;
@ -418,13 +469,13 @@ void qTabPlot::MaintainAspectRatio(int dimension) {
chkXMax->setChecked(true);
chkYMin->setChecked(true);
chkYMax->setChecked(true);
if (dispXMin->text().isEmpty())
if (dispXMin->text().isEmpty())
dispXMin->setText(QString::number(plot->GetXMinimum()));
if (dispXMax->text().isEmpty())
if (dispXMax->text().isEmpty())
dispXMax->setText(QString::number(plot->GetXMaximum()));
if (dispYMin->text().isEmpty())
if (dispYMin->text().isEmpty())
dispYMin->setText(QString::number(plot->GetYMinimum()));
if (dispYMax->text().isEmpty())
if (dispYMax->text().isEmpty())
dispYMax->setText(QString::number(plot->GetYMaximum()));
// calculate ideal aspect ratio with previous limits
@ -433,49 +484,68 @@ void qTabPlot::MaintainAspectRatio(int dimension) {
ranges[qDefs::XMAX] = plot->GetXMaximum();
ranges[qDefs::YMIN] = plot->GetYMinimum();
ranges[qDefs::YMAX] = plot->GetYMaximum();
double idealAspectratio = (ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) / (ranges[qDefs::YMAX] - ranges[qDefs::YMIN]);
FILE_LOG(logDEBUG) << "Ideal Aspect ratio: " << idealAspectratio << " for x(" << ranges[qDefs::XMIN] << " - " << ranges[qDefs::XMAX] << "), y(" << ranges[qDefs::YMIN] << " - " << ranges[qDefs::YMAX] << ")";
double idealAspectratio = (ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) /
(ranges[qDefs::YMAX] - ranges[qDefs::YMIN]);
FILE_LOG(logDEBUG) << "Ideal Aspect ratio: " << idealAspectratio
<< " for x(" << ranges[qDefs::XMIN] << " - "
<< ranges[qDefs::XMAX] << "), y(" << ranges[qDefs::YMIN]
<< " - " << ranges[qDefs::YMAX] << ")";
// calculate current aspect ratio
ranges[qDefs::XMIN] = dispXMin->text().toDouble();
ranges[qDefs::XMAX] = dispXMax->text().toDouble();
ranges[qDefs::YMIN] = dispYMin->text().toDouble();
ranges[qDefs::YMAX] = dispYMax->text().toDouble();
double currentAspectRatio = (ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) / (ranges[qDefs::YMAX] - ranges[qDefs::YMIN]);
FILE_LOG(logDEBUG) << "Current Aspect ratio: " << currentAspectRatio << " for x(" << ranges[qDefs::XMIN] << " - " << ranges[qDefs::XMAX] << "), y(" << ranges[qDefs::YMIN] << " - " << ranges[qDefs::YMAX] << ")";
double currentAspectRatio = (ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) /
(ranges[qDefs::YMAX] - ranges[qDefs::YMIN]);
FILE_LOG(logDEBUG) << "Current Aspect ratio: " << currentAspectRatio
<< " for x(" << ranges[qDefs::XMIN] << " - "
<< ranges[qDefs::XMAX] << "), y(" << ranges[qDefs::YMIN]
<< " - " << ranges[qDefs::YMAX] << ")";
if (currentAspectRatio != idealAspectratio) {
// dimension: 1(x changed: y adjusted), 0(y changed: x adjusted), -1(aspect ratio clicked: larger one adjusted)
// dimension: 1(x changed: y adjusted), 0(y changed: x adjusted),
// -1(aspect ratio clicked: larger one adjusted)
if (dimension == -1) {
dimension = ((ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) > (ranges[qDefs::YMAX] - ranges[qDefs::YMIN]))
? static_cast<int>(slsDetectorDefs::X) : static_cast<int>(slsDetectorDefs::Y);
dimension = ((ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) >
(ranges[qDefs::YMAX] - ranges[qDefs::YMIN]))
? static_cast<int>(slsDetectorDefs::X)
: static_cast<int>(slsDetectorDefs::Y);
}
// calculate new value to maintain aspect ratio
// adjust x
double newval = 0;
if (dimension == static_cast<int>(slsDetectorDefs::X)) {
newval = idealAspectratio * (ranges[qDefs::YMAX] - ranges[qDefs::YMIN]) + ranges[qDefs::XMIN];
newval =
idealAspectratio * (ranges[qDefs::YMAX] - ranges[qDefs::YMIN]) +
ranges[qDefs::XMIN];
if (newval <= plot->GetXMaximum()) {
ranges[qDefs::XMAX] = newval;
dispXMax->setText(QString::number(newval));
FILE_LOG(logDEBUG) << "New XMax: " << newval;
} else {
newval = ranges[qDefs::XMAX] - (idealAspectratio * (ranges[qDefs::YMAX] - ranges[qDefs::YMIN]));
newval = ranges[qDefs::XMAX] -
(idealAspectratio *
(ranges[qDefs::YMAX] - ranges[qDefs::YMIN]));
ranges[qDefs::XMIN] = newval;
dispXMin->setText(QString::number(newval));
FILE_LOG(logDEBUG) << "New XMin: " << newval;
}
}
// adjust y
else {
newval = ((ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) / idealAspectratio) + ranges[qDefs::YMIN];
else {
newval = ((ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) /
idealAspectratio) +
ranges[qDefs::YMIN];
if (newval <= plot->GetYMaximum()) {
ranges[qDefs::YMAX] = newval;
dispYMax->setText(QString::number(newval));
FILE_LOG(logDEBUG) << "New YMax: " << newval;
} else {
newval = ranges[qDefs::YMAX] - ((ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) / idealAspectratio);
newval = ranges[qDefs::YMAX] -
((ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) /
idealAspectratio);
ranges[qDefs::YMIN] = newval;
dispYMin->setText(QString::number(newval));
FILE_LOG(logDEBUG) << "New YMax: " << newval;
@ -492,14 +562,14 @@ void qTabPlot::MaintainAspectRatio(int dimension) {
connect(dispYMin, SIGNAL(editingFinished()), this, SLOT(SetYRange()));
connect(dispYMax, SIGNAL(editingFinished()), this, SLOT(SetYRange()));
bool isRange[4] {true, true, true, true};
bool isRange[4]{true, true, true, true};
plot->SetXYRangeChanged(true, ranges, isRange);
emit DisableZoomSignal(true);
}
void qTabPlot::SetZRange() {
bool isZRange[2] {chkZMin->isChecked(), chkZMax->isChecked()};
double zRange[2] {0 , 0};
bool isZRange[2]{chkZMin->isChecked(), chkZMax->isChecked()};
double zRange[2]{0, 0};
if (isZRange[0] && !dispZMin->text().isEmpty()) {
double val = dispZMin->text().toDouble();
@ -515,24 +585,35 @@ void qTabPlot::SetZRange() {
}
void qTabPlot::GetStreamingFrequency() {
FILE_LOG(logDEBUG) << "Getting Streaming Frequency";
disconnect(comboFrequency, SIGNAL(currentIndexChanged(int)), this, SLOT(SetStreamingFrequency()));
disconnect(comboTimeGapUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetStreamingFrequency()));
disconnect(spinTimeGap, SIGNAL(editingFinished()), this, SLOT(SetStreamingFrequency()));
disconnect(spinNthFrame, SIGNAL(editingFinished()), this, SLOT(SetStreamingFrequency()));
try {
int freq = det->getRxZmqFrequency().tsquash("Inconsistent receiver zmq streaming frequency for all detectors.");
FILE_LOG(logDEBUG) << "Getting Streaming Frequency";
disconnect(comboFrequency, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetStreamingFrequency()));
disconnect(comboTimeGapUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetStreamingFrequency()));
disconnect(spinTimeGap, SIGNAL(editingFinished()), this,
SLOT(SetStreamingFrequency()));
disconnect(spinNthFrame, SIGNAL(editingFinished()), this,
SLOT(SetStreamingFrequency()));
try {
int freq = det->getRxZmqFrequency().tsquash(
"Inconsistent receiver zmq streaming frequency for all detectors.");
// time interval
if (freq == 0) {
comboFrequency->setCurrentIndex(0);
stackedTimeInterval->setCurrentIndex(0);
try {
int timeMs = det->getRxZmqTimer().tsquash("Inconsistent receiver zmq streaming timer for all detectors.");
auto timeNS = qDefs::getNSTime(std::make_pair(static_cast<double>(timeMs), qDefs::MILLISECONDS));
int timeMs = det->getRxZmqTimer().tsquash(
"Inconsistent receiver zmq streaming timer for all "
"detectors.");
auto timeNS = qDefs::getNSTime(std::make_pair(
static_cast<double>(timeMs), qDefs::MILLISECONDS));
auto time = qDefs::getUserFriendlyTime(timeNS);
spinTimeGap->setValue(time.first);
comboTimeGapUnit->setCurrentIndex(static_cast<int>(time.second));
} CATCH_DISPLAY ("Could not get streaming timer.", "qTabPlot::GetStreamingFrequency")
comboTimeGapUnit->setCurrentIndex(
static_cast<int>(time.second));
}
CATCH_DISPLAY("Could not get streaming timer.",
"qTabPlot::GetStreamingFrequency")
}
// every nth frame
else {
@ -540,29 +621,40 @@ void qTabPlot::GetStreamingFrequency() {
stackedTimeInterval->setCurrentIndex(1);
spinNthFrame->setValue(freq);
}
} CATCH_DISPLAY ("Could not get streaming frequency.", "qTabPlot::GetStreamingFrequency")
connect(comboFrequency, SIGNAL(currentIndexChanged(int)), this, SLOT(SetStreamingFrequency()));
connect(comboTimeGapUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetStreamingFrequency()));
connect(spinTimeGap, SIGNAL(editingFinished()), this, SLOT(SetStreamingFrequency()));
connect(spinNthFrame, SIGNAL(editingFinished()), this, SLOT(SetStreamingFrequency()));
}
CATCH_DISPLAY("Could not get streaming frequency.",
"qTabPlot::GetStreamingFrequency")
connect(comboFrequency, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetStreamingFrequency()));
connect(comboTimeGapUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetStreamingFrequency()));
connect(spinTimeGap, SIGNAL(editingFinished()), this,
SLOT(SetStreamingFrequency()));
connect(spinNthFrame, SIGNAL(editingFinished()), this,
SLOT(SetStreamingFrequency()));
}
void qTabPlot::SetStreamingFrequency() {
bool frequency = (comboFrequency->currentIndex() == 0) ? 0 : 1;
auto freqVal = spinNthFrame->value();
auto timeVal = spinTimeGap->value();
auto timeUnit = static_cast<qDefs::timeUnit>(comboTimeGapUnit->currentIndex());
auto timeUnit =
static_cast<qDefs::timeUnit>(comboTimeGapUnit->currentIndex());
stackedTimeInterval->setCurrentIndex(comboFrequency->currentIndex());
try {
try {
if (frequency) {
FILE_LOG(logINFO) << "Setting Streaming Frequency to " << freqVal;
det->setRxZmqFrequency(freqVal);
} else {
FILE_LOG(logINFO) << "Setting Streaming Timer to " << timeVal << " " << qDefs::getUnitString(timeUnit);
FILE_LOG(logINFO) << "Setting Streaming Timer to " << timeVal << " "
<< qDefs::getUnitString(timeUnit);
auto timeMS = qDefs::getMSTime(std::make_pair(timeVal, timeUnit));
det->setRxZmqTimer(timeMS.count());
}
} CATCH_HANDLE("Could not set streaming frequency/ timer.", "qTabPlot::SetStreamingFrequency", this, &qTabPlot::GetStreamingFrequency)
}
CATCH_HANDLE("Could not set streaming frequency/ timer.",
"qTabPlot::SetStreamingFrequency", this,
&qTabPlot::GetStreamingFrequency)
}
void qTabPlot::Refresh() {
@ -577,19 +669,19 @@ void qTabPlot::Refresh() {
}
GetStreamingFrequency();
// gain plot, gap pixels enable
switch(det->getDetectorType().squash()) {
case slsDetectorDefs::EIGER:
chkGapPixels->setEnabled(true);
GetGapPixels();
break;
case slsDetectorDefs::JUNGFRAU:
chkGainPlot->setEnabled(true);
break;
case slsDetectorDefs::GOTTHARD2:
chkGainPlot1D->setEnabled(true);
break;
default:
break;
switch (det->getDetectorType().squash()) {
case slsDetectorDefs::EIGER:
chkGapPixels->setEnabled(true);
GetGapPixels();
break;
case slsDetectorDefs::JUNGFRAU:
chkGainPlot->setEnabled(true);
break;
case slsDetectorDefs::GOTTHARD2:
chkGainPlot1D->setEnabled(true);
break;
default:
break;
}
} else {
boxPlotType->setEnabled(false);

150
slsDetectorGui/src/qTabSettings.cpp Executable file → Normal file
View File

@ -8,7 +8,8 @@
#include <cmath>
#include <iostream>
qTabSettings::qTabSettings(QWidget *parent, sls::Detector *detector): QWidget(parent), det(detector) {
qTabSettings::qTabSettings(QWidget *parent, sls::Detector *detector)
: QWidget(parent), det(detector) {
setupUi(this);
SetupWidgetWindow();
FILE_LOG(logDEBUG) << "Settings ready";
@ -18,20 +19,20 @@ qTabSettings::~qTabSettings() {}
void qTabSettings::SetupWidgetWindow() {
// enabling according to det type
switch(det->getDetectorType().squash()) {
case slsDetectorDefs::MYTHEN3:
lblSettings->setEnabled(false);
comboSettings->setEnabled(false);
break;
case slsDetectorDefs::EIGER:
lblDynamicRange->setEnabled(true);
comboDynamicRange->setEnabled(true);
lblThreshold->setEnabled(true);
spinThreshold->setEnabled(true);
break;
default:
break;
// enabling according to det type
switch (det->getDetectorType().squash()) {
case slsDetectorDefs::MYTHEN3:
lblSettings->setEnabled(false);
comboSettings->setEnabled(false);
break;
case slsDetectorDefs::EIGER:
lblDynamicRange->setEnabled(true);
comboDynamicRange->setEnabled(true);
lblThreshold->setEnabled(true);
spinThreshold->setEnabled(true);
break;
default:
break;
}
// default settings for the disabled
@ -47,14 +48,16 @@ void qTabSettings::SetupWidgetWindow() {
}
void qTabSettings::SetupDetectorSettings() {
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(comboSettings->model());
QStandardItemModel *model =
qobject_cast<QStandardItemModel *>(comboSettings->model());
if (model) {
QModelIndex index[NUMSETTINGS];
QStandardItem *item[NUMSETTINGS];
for (int i = 0; i < NUMSETTINGS; ++i) {
index[i] = model->index(i, comboSettings->modelColumn(), comboSettings->rootModelIndex());
index[i] = model->index(i, comboSettings->modelColumn(),
comboSettings->rootModelIndex());
item[i] = model->itemFromIndex(index[i]);
item[i]->setEnabled(false);
item[i]->setEnabled(false);
}
switch (det->getDetectorType().squash()) {
case slsDetectorDefs::EIGER:
@ -83,7 +86,7 @@ void qTabSettings::SetupDetectorSettings() {
item[(int)DYNAMICGAIN]->setEnabled(true);
item[(int)FIXGAIN1]->setEnabled(true);
item[(int)FIXGAIN2]->setEnabled(true);
break;
break;
case slsDetectorDefs::MOENCH:
item[(int)G1_HIGHGAIN]->setEnabled(true);
item[(int)G1_LOWGAIN]->setEnabled(true);
@ -93,11 +96,12 @@ void qTabSettings::SetupDetectorSettings() {
item[(int)G2_LOWCAP_LOWGAIN]->setEnabled(true);
item[(int)G4_HIGHGAIN]->setEnabled(true);
item[(int)G4_LOWGAIN]->setEnabled(true);
break;
break;
default:
FILE_LOG(logDEBUG) << "Unknown detector type. Exiting GUI.";
qDefs::Message(qDefs::CRITICAL,
"Unknown detector type. Exiting GUI.", "qTabSettings::SetupDetectorSettings");
"Unknown detector type. Exiting GUI.",
"qTabSettings::SetupDetectorSettings");
exit(-1);
}
}
@ -106,38 +110,46 @@ void qTabSettings::SetupDetectorSettings() {
void qTabSettings::Initialization() {
// Settings
if (comboSettings->isEnabled())
connect(comboSettings, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSettings(int)));
connect(comboSettings, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetSettings(int)));
// Dynamic Range
if (comboDynamicRange->isEnabled())
connect(comboDynamicRange, SIGNAL(activated(int)), this, SLOT(SetDynamicRange(int)));
connect(comboDynamicRange, SIGNAL(activated(int)), this,
SLOT(SetDynamicRange(int)));
// Threshold
if (spinThreshold->isEnabled())
connect(spinThreshold, SIGNAL(valueChanged(int)), this, SLOT(SetThresholdEnergy(int)));
connect(spinThreshold, SIGNAL(valueChanged(int)), this,
SLOT(SetThresholdEnergy(int)));
}
void qTabSettings::GetSettings() {
FILE_LOG(logDEBUG) << "Getting settings";
disconnect(comboSettings, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSettings(int)));
try{
auto retval = det->getSettings().tsquash("Inconsistent settings for all detectors.");
disconnect(comboSettings, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetSettings(int)));
try {
auto retval = det->getSettings().tsquash(
"Inconsistent settings for all detectors.");
switch (retval) {
case slsDetectorDefs::UNDEFINED:
comboSettings->setCurrentIndex(UNDEFINED);
break;
case slsDetectorDefs::UNINITIALIZED:
comboSettings->setCurrentIndex(UNINITIALIZED);
break;
default:
if ((int)retval < -1 || (int)retval >= NUMSETTINGS) {
throw sls::RuntimeError(std::string("Unknown settings: ") + std::to_string(retval));
}
comboSettings->setCurrentIndex(retval);
break;
case slsDetectorDefs::UNDEFINED:
comboSettings->setCurrentIndex(UNDEFINED);
break;
case slsDetectorDefs::UNINITIALIZED:
comboSettings->setCurrentIndex(UNINITIALIZED);
break;
default:
if ((int)retval < -1 || (int)retval >= NUMSETTINGS) {
throw sls::RuntimeError(std::string("Unknown settings: ") +
std::to_string(retval));
}
comboSettings->setCurrentIndex(retval);
break;
}
} CATCH_DISPLAY ("Could not get settings.", "qTabSettings::GetSettings")
connect(comboSettings, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSettings(int)));
}
CATCH_DISPLAY("Could not get settings.", "qTabSettings::GetSettings")
connect(comboSettings, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetSettings(int)));
}
void qTabSettings::SetSettings(int index) {
@ -146,7 +158,9 @@ void qTabSettings::SetSettings(int index) {
try {
FILE_LOG(logINFO) << "Setting Settings to " << sls::ToString(val);
det->setSettings(val);
} CATCH_HANDLE ("Could not set settings.", "qTabSettings::SetSettings", this, &qTabSettings::GetSettings)
}
CATCH_HANDLE("Could not set settings.", "qTabSettings::SetSettings", this,
&qTabSettings::GetSettings)
// threshold
if (spinThreshold->isEnabled()) {
SetThresholdEnergy(spinThreshold->value());
@ -155,9 +169,11 @@ void qTabSettings::SetSettings(int index) {
void qTabSettings::GetDynamicRange() {
FILE_LOG(logDEBUG) << "Getting dynamic range";
disconnect(comboDynamicRange, SIGNAL(activated(int)), this, SLOT(SetDynamicRange(int)));
try {
auto retval = det->getDynamicRange().tsquash("Inconsistent dynamic range for all detectors.");
disconnect(comboDynamicRange, SIGNAL(activated(int)), this,
SLOT(SetDynamicRange(int)));
try {
auto retval = det->getDynamicRange().tsquash(
"Inconsistent dynamic range for all detectors.");
// set the final value on gui
switch (retval) {
case 32:
@ -173,14 +189,19 @@ void qTabSettings::GetDynamicRange() {
comboDynamicRange->setCurrentIndex(DYNAMICRANGE_4);
break;
default:
throw sls::RuntimeError(std::string("Unknown dynamic range: ") + std::to_string(retval));
throw sls::RuntimeError(std::string("Unknown dynamic range: ") +
std::to_string(retval));
}
} CATCH_DISPLAY ("Could not get dynamic range.", "qTabSettings::GetDynamicRange")
connect(comboDynamicRange, SIGNAL(activated(int)), this,SLOT(SetDynamicRange(int)));
}
CATCH_DISPLAY("Could not get dynamic range.",
"qTabSettings::GetDynamicRange")
connect(comboDynamicRange, SIGNAL(activated(int)), this,
SLOT(SetDynamicRange(int)));
}
void qTabSettings::SetDynamicRange(int index) {
FILE_LOG(logINFO) << "Setting dynamic range to " << comboDynamicRange->currentText().toAscii().data();
FILE_LOG(logINFO) << "Setting dynamic range to "
<< comboDynamicRange->currentText().toAscii().data();
try {
switch (index) {
case DYNAMICRANGE_32:
@ -196,28 +217,39 @@ void qTabSettings::SetDynamicRange(int index) {
det->setDynamicRange(4);
break;
default:
throw sls::RuntimeError(std::string("Unknown dynamic range: ") + std::to_string(index));
throw sls::RuntimeError(std::string("Unknown dynamic range: ") +
std::to_string(index));
}
} CATCH_HANDLE ("Could not set dynamic range.", "qTabSettings::SetDynamicRange", this, &qTabSettings::GetDynamicRange)
}
CATCH_HANDLE("Could not set dynamic range.",
"qTabSettings::SetDynamicRange", this,
&qTabSettings::GetDynamicRange)
}
void qTabSettings::GetThresholdEnergy() {
FILE_LOG(logDEBUG) << "Getting theshold energy";
disconnect(spinThreshold, SIGNAL(valueChanged(int)), this, SLOT(SetThresholdEnergy(int)));
disconnect(spinThreshold, SIGNAL(valueChanged(int)), this,
SLOT(SetThresholdEnergy(int)));
try {
auto retval = det->getThresholdEnergy().tsquash("Inconsistent threhsold energy for all detectors.");
auto retval = det->getThresholdEnergy().tsquash(
"Inconsistent threhsold energy for all detectors.");
spinThreshold->setValue(retval);
} CATCH_DISPLAY ("Could not get threshold energy.", "qTabDataOutput::GetThresholdEnergy")
connect(spinThreshold, SIGNAL(valueChanged(int)), this, SLOT(SetThresholdEnergy(int)));
}
CATCH_DISPLAY("Could not get threshold energy.",
"qTabDataOutput::GetThresholdEnergy")
connect(spinThreshold, SIGNAL(valueChanged(int)), this,
SLOT(SetThresholdEnergy(int)));
}
void qTabSettings::SetThresholdEnergy(int index) {
FILE_LOG(logINFO) << "Setting Threshold Energy to " << index << " eV";
try {
det->setThresholdEnergy(index);
} CATCH_DISPLAY ("Could not get threshold energy.", "qTabSettings::SetThresholdEnergy")
}
CATCH_DISPLAY("Could not get threshold energy.",
"qTabSettings::SetThresholdEnergy")
// set the right value anyway (due to tolerance)
GetThresholdEnergy();
GetThresholdEnergy();
}
void qTabSettings::Refresh() {
@ -230,7 +262,7 @@ void qTabSettings::Refresh() {
if (comboDynamicRange->isEnabled()) {
GetDynamicRange();
}
if (spinThreshold->isEnabled())
GetThresholdEnergy();