From f0872174cfe6b788d836bf57fd717fc79c947937 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 7 Jun 2019 18:53:57 +0200 Subject: [PATCH] WIP --- slsDetectorGui/forms/form_tab_measurement.ui | 158 ++- slsDetectorGui/include/qDrawPlot.h | 2 +- slsDetectorGui/include/qTabAdvanced.h | 213 ---- slsDetectorGui/include/qTabDataOutput.h | 119 +- slsDetectorGui/include/qTabMeasurement.h | 210 +--- slsDetectorGui/include/qTabSettings.h | 60 - slsDetectorGui/src/qDetectorMain.cpp | 14 +- slsDetectorGui/src/qTabAdvanced.cpp | 12 +- slsDetectorGui/src/qTabDataOutput.cpp | 49 +- slsDetectorGui/src/qTabMeasurement.cpp | 1067 +++++++++--------- slsDetectorGui/src/qTabSettings.cpp | 94 +- 11 files changed, 771 insertions(+), 1227 deletions(-) diff --git a/slsDetectorGui/forms/form_tab_measurement.ui b/slsDetectorGui/forms/form_tab_measurement.ui index 034dcb733..79488a7f2 100755 --- a/slsDetectorGui/forms/form_tab_measurement.ui +++ b/slsDetectorGui/forms/form_tab_measurement.ui @@ -34,10 +34,10 @@ - 30 - 153 + 21 + 130 319 - 116 + 103 @@ -55,9 +55,9 @@ - 10 - 75 - 300 + -2 + 67 + 319 23 @@ -68,9 +68,9 @@ - 10 + 1 25 - 91 + 96 16 @@ -78,10 +78,10 @@ Current Frame: - + - 101 + 99 25 101 16 @@ -94,7 +94,7 @@ - 150 + 145 45 76 16 @@ -122,9 +122,9 @@ - 10 + 1 45 - 136 + 146 16 @@ -136,10 +136,10 @@ - 390 + 368 8 - 362 - 281 + 403 + 332 @@ -151,14 +151,14 @@ - 0 + 3 10 - 357 - 264 + 390 + 314 - + Qt::Horizontal @@ -174,7 +174,7 @@ - + false @@ -230,7 +230,7 @@ Frame period between exposures. - + @@ -242,11 +242,6 @@ Frame period between exposures. Timing Mode of the detector. #timing# - - - None - - Auto @@ -259,7 +254,7 @@ Frame period between exposures. - Gated with fixed number + Gated with fixed number @@ -269,7 +264,7 @@ Frame period between exposures. - + false @@ -283,7 +278,7 @@ Frame period between exposures. - + false @@ -324,7 +319,7 @@ Frame period between exposures. - + false @@ -338,7 +333,7 @@ Frame period between exposures. - + false @@ -373,7 +368,7 @@ Frame period between exposures. - + false @@ -426,7 +421,7 @@ Frame period between exposures. - + false @@ -436,7 +431,7 @@ Frame period between exposures. - + false @@ -477,7 +472,7 @@ Frame period between exposures. - + true @@ -494,7 +489,7 @@ Exposure Time of a frame. - + true @@ -532,7 +527,7 @@ Exposure Time of a frame. - + true @@ -588,7 +583,7 @@ Exposure Time of a frame. - + false @@ -605,7 +600,7 @@ Frame period between exposures. - + false @@ -643,14 +638,14 @@ Frame period between exposures. - + Timing Mode: - + false @@ -664,7 +659,7 @@ Frame period between exposures. - + false @@ -705,47 +700,14 @@ Frame period between exposures. - - - gridLayoutWidget - spinNumSamples - - - - - 20 - 5 - 336 - 159 - - - - QFrame::NoFrame - - - QFrame::Plain - - - - - 10 - 13 - 321 - 130 - - - - - 6 - - + Number of Measurements: - + @@ -773,7 +735,7 @@ Frame period between exposures. - 1 + -1 2000000000 @@ -783,6 +745,37 @@ Frame period between exposures. + + + + + + + 10 + 5 + 336 + 96 + + + + QFrame::NoFrame + + + QFrame::Plain + + + + + 10 + 13 + 321 + 76 + + + + + 6 + @@ -865,8 +858,8 @@ Frame period between exposures. - 30 - 298 + 20 + 270 318 34 @@ -933,7 +926,7 @@ Frame period between exposures. - 70 + 90 16777215 @@ -962,7 +955,6 @@ Frame period between exposures. - spinNumMeasurements chkFile dispFileName spinIndex diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index dc32c2630..e898563e1 100755 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -65,7 +65,7 @@ public: int GetFrameIndex(){return currentFrameIndex;}; /** sets file write enable , if not enabled, * file index wont increase and so you need secondary titles to differentitate between plots*/ - void SetEnableFileWrite(bool enable){fileSaveEnable = enable;}; + void SetFileWriteEnable(bool enable){fileSaveEnable = enable;}; /** sets plot Title prefix*/ void SetPlotTitlePrefix(QString title) {plotTitle_prefix = title;} diff --git a/slsDetectorGui/include/qTabAdvanced.h b/slsDetectorGui/include/qTabAdvanced.h index 47084f057..76414eb70 100755 --- a/slsDetectorGui/include/qTabAdvanced.h +++ b/slsDetectorGui/include/qTabAdvanced.h @@ -1,288 +1,75 @@ #pragma once -#include "qDefs.h" -#include "sls_detector_defs.h" - #include "ui_form_tab_advanced.h" class multiSlsDetector; -#include -#include -/** - *@short sets up the advanced parameters - */ class qTabAdvanced:public QWidget, private Ui::TabAdvancedObject{ Q_OBJECT public: - /** - * The constructor - * @param parent is the parent tab widget - * @param detector is the detector returned from the detector tab - */ qTabAdvanced(QWidget *parent, multiSlsDetector* detector); - - /** - * Destructor - */ ~qTabAdvanced(); public slots: - /** - * To refresh and update widgets - */ void Refresh(); private slots: - - /** - * Select Readout - * @param index position index of readout - */ void SetDetector(int index); - - /** - * Sets control port - * @param port control port - */ void SetControlPort(int port); - - /** - * Sets stop port - * @param port stop port - */ void SetStopPort(int port); - - /** - * Sets detector udp ip - */ void SetDetectorUDPIP(); - - /** - * Sets detector udp mac - */ void SetDetectorUDPMAC(); - - /** - * Sets client zmq port - * @param port client zmq port - */ void SetCltZMQPort(int port); - - /** - * Sets client zmq ip to listen to - */ void SetCltZMQIP(); - - /** - * Sets the receiver hostname - */ void SetRxrHostname(); - - /** - * Sets receiver tcp port - * @param port receiver tcp port - */ void SetRxrTCPPort(int port); - - /** - * Sets receiver udp port - * @param port receiver udp port - */ void SetRxrUDPPort(int port); - - /** - * Sets receiver ip - */ void SetRxrUDPIP(); - - /** - * Sets reciever mac - */ void SetRxrUDPMAC(); - - /** - * Sets receiver zmq port - * @param port receiver zmq port - */ void SetRxrZMQPort(int port); - - /** - * Sets receiver zmq ip to stream from - */ void SetRxrZMQIP(); - - /** - * Add ROI - */ void AddROISlot(); - - /** - * Gets ROIs from detector and updates it - */ void GetROI(); - - /** - * Clears ROI in detector - */ void ClearROI(); - - /** - * Sets ROI in detector - */ void SetROI(); - - /** - * Set all trimbits to a value - */ void SetAllTrimbits(); - - - /** - * Set number of additional storage cells - * @param value value to set to - */ void SetNumStoragecells(int value); - - /** - * Set sub frame exposure time - */ void SetSubExposureTime(); - - /** - * Set sub frame dead time - */ void SetSubDeadTime(); - private: - - /** - * Sets up the widget - */ void SetupWidgetWindow(); - - /** - * Sets up all the slots and signals - */ void Initialization(); - - /** - * Populate detectors - */ void PopulateDetectors(); - /** - * Gets detector online - */ void GetOnline(); - - /** - * Gets control port - */ void GetControlPort(); - - /** - * Gets stop port - */ void GetStopPort(); - - /** - * Gets detector udp ip - */ void GetDetectorUDPIP(); - - /** - * Gets detector udp mac - */ void GetDetectorUDPMAC(); - - /** - * Gets client zmq receiver port - */ void GetCltZMQPort(); - - /** - * Gets client zmq ip to listen to - */ void GetCltZMQIP(); - - /** - * Gets receiver hostname - */ void GetRxrHostname(); - - /** - * Sets receiver online - */ void GetReceiverOnline(); - - /** - * Gets receiver tcp port - */ void GetRxrTCPPort(); - - /** - * Gets receiver udp port - */ void GetRxrUDPPort(); - - /** - * Gets receiver udp ip - */ void GetRxrUDPIP(); - - /** - * Gets receiver udp mac - */ void GetRxrUDPMAC(); - - /** - * Gets receiver zmq transmitting port - */ void GetRxrZMQPort(); - - /** - * Gets receiver zmq transmitting ip - */ void GetRxrZMQIP(); - - /** - * Clears all the ROI widgets - */ void ClearROIWidgets(); - - /** - * Get all trimbits - */ void GetAllTrimbits(); - - /** - * Get number of additional storage cells - */ void GetNumStoragecells(); - - /** - * Get sub frame exposure time - */ void GetSubExposureTime(); - - /** - * Get sub frame dead time - */ void GetSubDeadTime(); - - /** The multi detector object */ multiSlsDetector *myDet; - /** Tool Tip */ QString errOnlineTip; QString detOnlineTip; QString rxrOnlineTip; QPalette red; - /** ROI */ std::vector lblFromX; std::vector spinFromX; diff --git a/slsDetectorGui/include/qTabDataOutput.h b/slsDetectorGui/include/qTabDataOutput.h index 315dc390a..e434ccc5c 100755 --- a/slsDetectorGui/include/qTabDataOutput.h +++ b/slsDetectorGui/include/qTabDataOutput.h @@ -1,167 +1,60 @@ #pragma once -#include "qDefs.h" - #include "ui_form_tab_dataoutput.h" class multiSlsDetector; -#include -#include - -/** - *@short sets up the DataOutput parameters - */ class qTabDataOutput:public QWidget, private Ui::TabDataOutputObject{ Q_OBJECT public: - /** - * The constructor - * @param parent is the parent tab widget - * @param detector is the detector returned from the detector tab - */ qTabDataOutput(QWidget *parent,multiSlsDetector* detector); - - /** - * Destructor - */ ~qTabDataOutput(); - - /** - * To refresh and update widgets - */ void Refresh(); private slots: - - /** - * Get output directory - */ void GetOutputDir(); - - /** - * Open dialog to choose the output directory - */ void BrowseOutputDir(); - - /** - * Set output directory - */ void SetOutputDir(); - - /** - * Set file format - * @param format file format - */ void SetFileFormat(int format); - - /** - * Set overwrite enable - * @param enable enable - */ void SetOverwriteEnable(bool enable); - - /** - * Enable/Disable 10GbE - * @param enable enable - */ void SetTenGigaEnable(bool enable); - - /** - * Enable rate correction - */ void EnableRateCorrection(); - - /** - * Set rate correction - */ void SetRateCorrection(); - - /** - * Set speed - * @param speed speed chosen - */ void SetSpeed(int speed); - - /** - * Set flags - */ void SetFlags(); private: - - /** - * Sets up the widget - */ void SetupWidgetWindow(); - - /** - * Sets up all the slots and signals - */ void Initialization(); - - /** - * Populate the readouts - */ void PopulateDetectors(); - - /** - * Enable browse - */ void EnableBrowse(); + void GetFileEnable(); + void GetFileName(); - /** - * Get file format - */ void GetFileFormat(); - - /** - * Get overwrite enable - */ void GetFileOverwrite(); - - /** - * Get Ten Giga Enable - */ void GetTenGigaEnable(); - - /** - * Set Get rate correction - */ void GetRateCorrection(); - - /** - * Get speed - */ void GetSpeed(); - - /** - * Get flags - */ void GetFlags(); - /** The sls detector object */ multiSlsDetector *myDet; - - /** Button group for radiobuttons for rate*/ + // Button group for radiobuttons for rate QButtonGroup *btnGroupRate; - - /** enum for the Eiger clock divider */ + // enum for the Eiger clock divider enum { FULLSPEED, HALFSPEED, QUARTERSPEED, NUMBEROFSPEEDS }; - - /** enum for the Eiger readout flags1 */ + // enum for the Eiger readout flags1 enum { CONTINUOUS, STOREINRAM }; - - /** enum for the Eiger readout flags2 */ + // enum for the Eiger readout flags2 enum { PARALLEL, NONPARALLEL diff --git a/slsDetectorGui/include/qTabMeasurement.h b/slsDetectorGui/include/qTabMeasurement.h index bd7f6553e..fd73021bc 100755 --- a/slsDetectorGui/include/qTabMeasurement.h +++ b/slsDetectorGui/include/qTabMeasurement.h @@ -1,204 +1,86 @@ #pragma once -#include "qDefs.h" - #include "ui_form_tab_measurement.h" +class qDrawPlot; + class multiSlsDetector; -#include -#include "qDrawPlot.h" -class qDetectorMain; +class QStandardItemModel; -/** - *@short sets up the measurement parameters - */ class qTabMeasurement:public QWidget, private Ui::TabMeasurementObject{ Q_OBJECT public: - /** - * The constructor - * This tab allows to change measurement parameters and to start/stop an acquisition - * @param parent is the parent tab widget - * @param detector is the detector returned from the detector tab - * @param plot plot object reference - */ - qTabMeasurement(QWidget *parent,multiSlsDetector* detector, qDrawPlot* plot); - - /** - * Destructor - */ + qTabMeasurement(QWidget *parent, multiSlsDetector* detector, qDrawPlot* plot); ~qTabMeasurement(); - /** - * Returns the status of the acquisition in gui - */ bool GetStartStatus(); - - /** - * Click the Start/Stop Acquisition button - * This is used if this command came from gui client - */ - void ClickStartStop(); - - /** - * Returns progress bar value - */ + void ClentStartAcquisition(); int GetProgress(); - - /** - * Refresh and update widgets - */ void Refresh(); - public slots: - - /** - * Update plot is finished, - * changes start/stop text and enables/disables all widgets - */ - void UpdateFinished(); - - /** - * Updates the current measurement - * @param val the value to be updated - */ void SetCurrentMeasurement(int val); + void UpdateFinished(); + void StopAcquisition(); private slots: - - /** - * Set number of measurements - * @param num number of measurements to be set - */ - void setNumMeasurements(int num); - - /** - * Set number of frames - * @param val number of frames to be set - */ - void setNumFrames(int val); - - /** - * Set acquisition time - */ - void setExposureTime(); - - /** - * Set frame period between exposures - */ - void setAcquisitionPeriod(); - - /** - * Set number of triggers - * @param val number of triggers to be set - */ - void setNumTriggers(int val); - - /** - * Set delay - */ - void setDelay(); - - /** - * Set number of samples - * @param val number of samples to be set - */ - void setNumSamples(int val); - - /** - * Set file name - */ - void setFileName(); - - /** - * Enable write to file - */ - void EnableFileWrite(bool enable); - - /** - * Set index of file name - * @param index index of selection - */ - void setRunIndex(int index); - - /** - * Update progress - */ - void UpdateProgress(); - - /** - * starts Acquisition - */ - void startAcquisition(); - - /** - * stops Acquisition - */ - void stopAcquisition(); - - /** - * Sets the timing mode - * @param mode timing mode - */ void SetTimingMode(int mode); + void SetNumMeasurements(int num); + void SetNumFrames(int val); + void SetNumTriggers(int val); + void SetNumSamples(int val); + void SetExposureTime(); + void SetAcquisitionPeriod(); + void SetDelay(); + void SetFileWriteEnable(bool enable); + void SetFileName(); + void SetRunIndex(int val); + void UpdateProgress(); + void StartAcquisition(); private: - /** - * Sets up the widget - */ void SetupWidgetWindow(); - - /** - * Sets up the timing mode - */ - void SetupTimingMode(); - - /** - * Sets up all the slots and signals - */ void Initialization(); + void SetupTimingMode(); + void EnableWidgetsforTimingMode(); - /** - * Get timing mode from detector - * @param startup is true when gui has just started up - */ - void GetTimingModeFromDetector(bool startup = false); - - /** - * Enables/Disables widgetframes to avoid setting measurement during an acquisition - */ - void Enable(bool enable); - - /** - * Checks if acquisition period is greater than exposure time - */ + void GetTimingMode(); + void GetNumMeasurements(); + void GetNumFrames(); + void GetNumTriggers(); + void GetNumSamples(); + void GetExposureTime(); + void GetAcquisitionPeriod(); void CheckAcqPeriodGreaterThanExp(); + void GetDelay(); + void GetFileWriteEnable(); + void GetFileName(); + void GetRunIndex(); - /** - * Verify if output directory existing error is set - * @returns OK or FAIL - */ + void ResetProgress(); + + void Enable(bool enable); int VerifyOutputDirectoryError(); - /** The sls detector object */ multiSlsDetector *myDet; - /** The Plot widget */ qDrawPlot *myPlot; - /** detector type */ - slsDetectorDefs::detectorType detType; - /** enum for the timing mode */ - enum{AUTO, TRIGGER, GATED, BURST_TRIGGER, NUM_TIMING_MODES}; - /** timer to update the progress*/ + // enum for the timing mode + enum{ + AUTO, + TRIGGER, + GATED, + BURST_TRIGGER, + NUMTIMINGMODES + }; QTimer *progressTimer; - /** tool tip variables*/ + //tool tip variables QString acqPeriodTip; QString errPeriodTip; QPalette red; - /** to access items in settings combobox */ - QStandardItemModel* model; + bool delayImplemented; + bool sampleImplemented; signals: void StartSignal(); diff --git a/slsDetectorGui/include/qTabSettings.h b/slsDetectorGui/include/qTabSettings.h index 97e198649..7e981e3ea 100755 --- a/slsDetectorGui/include/qTabSettings.h +++ b/slsDetectorGui/include/qTabSettings.h @@ -1,91 +1,32 @@ #pragma once -#include "qDefs.h" - #include "ui_form_tab_settings.h" class multiSlsDetector; -/** - *@short sets up the Settings parameters - */ class qTabSettings: public QWidget, private Ui::TabSettingsObject{ Q_OBJECT public: - /** - * The constructor - * @param parent is the parent tab widget - * @param detector is the detector returned from the detector tab - */ qTabSettings(QWidget *parent, multiSlsDetector* detector); - - /** - * Destructor - */ ~qTabSettings(); - - /** - * Refresh and update widgets - */ void Refresh(); - private slots: - /** - * Set settings according to selection - * @param index index of selection - */ void SetSettings(int index); - - /** - * Set dynamic range if possible - * @param index selection - */ void SetDynamicRange(int index); - - /** - * Set threshold energy - * @param index selection - */ void SetThresholdEnergy(int index); - private: - - /** - * Sets up the widget - */ void SetupWidgetWindow(); - - /** - * Sets up the detector settings - */ void SetupDetectorSettings(); - - /** - * Sets up all the slots and signals - */ void Initialization(); - /** - * Get Settings - */ void GetSettings(); - - /** - * Gets the dynamic range and sets it on the gui - */ void GetDynamicRange(); - - /** - * Gets the threshold energy and update widget - */ void GetThresholdEnergy(); - /** The sls detector object */ multiSlsDetector *myDet; - enum { STANDARD, FAST, @@ -104,7 +45,6 @@ private: UNINITIALIZED, NUMSETTINGS }; - enum { DYNAMICRANGE_32, DYNAMICRANGE_16, diff --git a/slsDetectorGui/src/qDetectorMain.cpp b/slsDetectorGui/src/qDetectorMain.cpp index 228d5d0cb..53bb9a539 100755 --- a/slsDetectorGui/src/qDetectorMain.cpp +++ b/slsDetectorGui/src/qDetectorMain.cpp @@ -753,12 +753,16 @@ void qDetectorMain::SetZoomToolTip(bool disable) { int qDetectorMain::StartStopAcquisitionFromClient(bool start) { FILE_LOG(logINFO) << (start ? "Start" : "Stop") - << " Acquisition From Clien"; + << " Acquisition From Client"; - if (tabMeasurement->GetStartStatus() != start) { - tabMeasurement->ClickStartStop(); - while (myPlot->GetClientInitiated()) - ; + if (start) { + if (tabMeasurement->GetStartStatus() != start) { + tabMeasurement->ClentStartAcquisition(); + while (myPlot->GetClientInitiated()) + usleep(500); + } + } else { + tabMeasurement->StopAcquisition(); } return slsDetectorDefs::OK; diff --git a/slsDetectorGui/src/qTabAdvanced.cpp b/slsDetectorGui/src/qTabAdvanced.cpp index be05b73c8..b9d0ba1cf 100755 --- a/slsDetectorGui/src/qTabAdvanced.cpp +++ b/slsDetectorGui/src/qTabAdvanced.cpp @@ -1,7 +1,5 @@ #include "qTabAdvanced.h" -#include "qDrawPlot.h" - -#include "multiSlsDetector.h" +#include "qDefs.h" #include @@ -366,7 +364,7 @@ void qTabAdvanced::GetRxrZMQIP() { } void qTabAdvanced::SetDetector(int index) { - FILE_LOG(logDEBUG) << "Set Detector: " << index; + FILE_LOG(logDEBUG) << "Set Detector: " << comboDetector->currentText().toAscii().data(); GetOnline(); GetControlPort(); @@ -776,7 +774,7 @@ void qTabAdvanced::GetSubExposureTime() { void qTabAdvanced::SetSubExposureTime() { double timeNS = qDefs::getNSTime((qDefs::timeUnit)comboSubExpTimeUnit->currentIndex(), spinSubExpTime->value()); - FILE_LOG(logINFO) << "Setting sub frame acquisition time to " << timeNS << " clocks" << + FILE_LOG(logINFO) << "Setting sub frame acquisition time to " << timeNS << " ns" << "/" << spinSubExpTime->value() << qDefs::getUnitString((qDefs::timeUnit)comboSubExpTimeUnit->currentIndex()); try { myDet->setTimer(slsDetectorDefs::SUBFRAME_ACQUISITION_TIME, (int64_t)timeNS, -1); @@ -813,7 +811,7 @@ void qTabAdvanced::GetSubDeadTime() { void qTabAdvanced::SetSubDeadTime() { double timeNS = qDefs::getNSTime((qDefs::timeUnit)comboSubDeadTimeUnit->currentIndex(), spinSubDeadTime->value()); - FILE_LOG(logINFO) << "Setting sub frame dead time to " << timeNS << " clocks" << + FILE_LOG(logINFO) << "Setting sub frame dead time to " << timeNS << " ns" << "/" << spinSubDeadTime->value() << qDefs::getUnitString((qDefs::timeUnit)comboSubDeadTimeUnit->currentIndex()); try { myDet->setTimer(slsDetectorDefs::SUBFRAME_DEADTIME, (int64_t)timeNS, -1); @@ -825,7 +823,7 @@ void qTabAdvanced::SetSubDeadTime() { void qTabAdvanced::Refresh(){ - FILE_LOG(logDEBUG) << endl << "**Updating Advanced Tab"; + FILE_LOG(logDEBUG) << "**Updating Advanced Tab"; // trimming if (tab_trimming->isEnabled()) { diff --git a/slsDetectorGui/src/qTabDataOutput.cpp b/slsDetectorGui/src/qTabDataOutput.cpp index 1167f290a..169070f3f 100755 --- a/slsDetectorGui/src/qTabDataOutput.cpp +++ b/slsDetectorGui/src/qTabDataOutput.cpp @@ -1,9 +1,10 @@ #include "qTabDataOutput.h" - -#include "multiSlsDetector.h" +#include "qDefs.h" #include #include +#include +#include #include #include @@ -83,6 +84,7 @@ void qTabDataOutput::PopulateDetectors() { } void qTabDataOutput::EnableBrowse() { + FILE_LOG(logDEBUG) << "Getting browse enable"; try { std::string receiverHostname = myDet->getReceiverHostname(comboDetector->currentIndex() - 1); if (receiverHostname == "localhost") { @@ -107,6 +109,32 @@ void qTabDataOutput::EnableBrowse() { } } +void qTabDataOutput::GetFileWriteEnable() { + FILE_LOG(logDEBUG) << "Getting file write enable"; + try { + int retval = myDet->getFileWrite(); + if (retval == -1) { + qDefs::Message(qDefs::WARNING, "File write is inconsistent for all detectors.", "qTabDataOutput::GetFileWriteEnable"); + boxFileWriteEnabled->setEnabled(true); + } else { + boxFileWriteEnabled->setEnabled(retval == 0 ? false : true); + } + } catch (const sls::RuntimeError &e) { + qDefs::ExceptionMessage("Could not get file enable.", e.what(), "qTabDataOutput::GetFileWriteEnable"); + boxFileWriteEnabled->setEnabled(true); + } +} + +void qTabDataOutput::GetFileName() { + FILE_LOG(logDEBUG) << "Getting file name"; + try { + auto retval = myDet->getFileName(); + dispFileName->setText(QString(retval.c_str())); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not get file name prefix.", e.what(), "qTabDataOutput::GetFileName"); + } + +} void qTabDataOutput::GetOutputDir() { FILE_LOG(logDEBUG) << "Getting file path"; @@ -182,7 +210,7 @@ void qTabDataOutput::GetFileFormat() { } void qTabDataOutput::SetFileFormat(int format) { - FILE_LOG(logINFO) << "Setting File Format to " << slsDetectorDefs::getFileFormatType((slsDetectorDefs::fileFormat)format); + FILE_LOG(logINFO) << "Setting File Format to " << comboFileFormat->currentText().toAscii().data(); try { myDet->setFileFormat((slsDetectorDefs::fileFormat)comboFileFormat->currentIndex()); } catch (const sls::NonCriticalError &e) { @@ -337,7 +365,7 @@ void qTabDataOutput::GetSpeed() { } void qTabDataOutput::SetSpeed(int speed) { - FILE_LOG(logINFO) << "Setting Speed to " << ((speed = FULLSPEED) ? "full" : ((speed == HALFSPEED) ? "half" : "quarter")) << " speed"; + FILE_LOG(logINFO) << "Setting Speed to " << comboEigerClkDivider->currentText().toAscii().data();; try { myDet->setSpeed(slsDetectorDefs::CLOCK_DIVIDER, speed); } catch (const sls::NonCriticalError &e) { @@ -386,33 +414,31 @@ void qTabDataOutput::GetFlags() { void qTabDataOutput::SetFlags() { auto flag1 = slsDetectorDefs::GET_READOUT_FLAGS; auto flag2 = slsDetectorDefs::GET_READOUT_FLAGS; - + //set to continous or storeinram switch (comboEigerFlags1->currentIndex()) { case STOREINRAM: - FILE_LOG(logINFO) << "Setting Readout Flags to Store in Ram"; flag1 = slsDetectorDefs::STORE_IN_RAM; break; default: - FILE_LOG(logINFO) << "Setting Readout Flags to Continuous"; flag1 = slsDetectorDefs::CONTINOUS_RO; break; } - //set to parallel, nonparallel or safe + //set to parallel or nonparallel switch (comboEigerFlags2->currentIndex()) { case PARALLEL: - FILE_LOG(logINFO) << "Setting Readout Flags to Parallel"; flag2 = slsDetectorDefs::PARALLEL; break; default: - FILE_LOG(logINFO) << "Setting Readout Flags to Non Parallel"; flag2 = slsDetectorDefs::NONPARALLEL; break; } try { + FILE_LOG(logINFO) << "Setting Readout Flags to " << comboEigerFlags1->currentText().toAscii().data(); myDet->setReadOutFlags(flag1); + FILE_LOG(logINFO) << "Setting Readout Flags to " << comboEigerFlags2->currentText().toAscii().data(); myDet->setReadOutFlags(flag2); } catch (const sls::NonCriticalError &e) { qDefs::ExceptionMessage("Could not set readout flags.", e.what(), "qTabDataOutput::SetFlags"); @@ -430,7 +456,8 @@ void qTabDataOutput::Refresh() { FILE_LOG(logDEBUG) << "**Updating DataOutput Tab"; EnableBrowse(); - dispFileName->setText(QString(myDet->getFileName().c_str())); + GetFileWriteEnable(); + GetFileName(); GetOutputDir(); GetFileOverwrite(); GetFileFormat(); diff --git a/slsDetectorGui/src/qTabMeasurement.cpp b/slsDetectorGui/src/qTabMeasurement.cpp index 9a08a113c..ee1df0126 100755 --- a/slsDetectorGui/src/qTabMeasurement.cpp +++ b/slsDetectorGui/src/qTabMeasurement.cpp @@ -1,95 +1,34 @@ #include "qTabMeasurement.h" -#include "qDetectorMain.h" +#include "qDefs.h" +#include "qDrawPlot.h" -#include "multiSlsDetector.h" +#include #include - qTabMeasurement::qTabMeasurement(QWidget *parent, multiSlsDetector *detector, qDrawPlot *plot) : QWidget(parent), myDet(detector), myPlot(plot) { setupUi(this); SetupWidgetWindow(); - Initialization(); - - // updated after slots to enable/disable widgets - GetTimingModeFromDetector(true); - FILE_LOG(logDEBUG) << "Measurement ready"; } - -qTabMeasurement::~qTabMeasurement() { - delete myDet; -} - +qTabMeasurement::~qTabMeasurement() {} bool qTabMeasurement::GetStartStatus(){ return (!btnStart->isEnabled()); } - -void qTabMeasurement::ClickStartStop(){ - startAcquisition(); +void qTabMeasurement::ClentStartAcquisition(){ + StartAcquisition(); myPlot->SetClientInitiated(); } - int qTabMeasurement::GetProgress(){ return progressBar->value(); } - void qTabMeasurement::SetupWidgetWindow() { - - detType = myDet->getDetectorTypeAsEnum(); - - //measurements - spinNumMeasurements->setValue((int)myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER, -1)); - //frames - spinNumFrames->setValue((int)myDet->setTimer(slsDetectorDefs::FRAME_NUMBER, -1)); - //Exp Time - qDefs::timeUnit unit; - double time = qDefs::getCorrectTime(unit, ((double)(myDet->setTimer(slsDetectorDefs::ACQUISITION_TIME, -1) * (1E-9)))); - spinExpTime->setValue(time); - comboExpUnit->setCurrentIndex((int)unit); - //period - time = qDefs::getCorrectTime(unit, ((double)(myDet->setTimer(slsDetectorDefs::FRAME_PERIOD, -1) * (1E-9)))); - spinPeriod->setValue(time); - comboPeriodUnit->setCurrentIndex((int)unit); - //triggers - spinNumTriggers->setValue((int)myDet->setTimer(slsDetectorDefs::CYCLES_NUMBER, -1)); - //delay - if (detType == slsDetectorDefs::EIGER) { - lblDelay->setEnabled(false); - spinDelay->setEnabled(false); - comboDelayUnit->setEnabled(false); - } else { - time = qDefs::getCorrectTime(unit, ((double)(myDet->setTimer(slsDetectorDefs::DELAY_AFTER_TRIGGER, -1) * (1E-9)))); - spinDelay->setValue(time); - comboDelayUnit->setCurrentIndex((int)unit); - } - //samples - if (detType != slsDetectorDefs::MOENCH) { - lblNumSamples->setEnabled(false); - spinNumSamples->setEnabled(false); - } else { - spinNumSamples->setValue((int)myDet->setTimer(slsDetectorDefs::SAMPLES, -1)); - } - //file name - dispFileName->setText(QString(myDet->getFileName().c_str())); - //file write enable - chkFile->setChecked(myDet->enableWriteToFile()); - dispFileName->setEnabled(chkFile->isChecked()); - //file index - spinIndex->setValue(myDet->getFileIndex()); - //only initially - lblProgressIndex->setText(QString::number(0)); - progressBar->setValue(0); - - //Timer to update the progress bar - progressTimer = new QTimer(this); - - //Hide the error message + // palette red = QPalette(); red.setColor(QPalette::Active, QPalette::WindowText, Qt::red); acqPeriodTip = spinPeriod->toolTip(); @@ -98,278 +37,599 @@ void qTabMeasurement::SetupWidgetWindow() { QString("Acquisition Period should be" " greater than or equal to Exposure Time."); - SetupTimingMode(); - // update timing mode after enabling slots to enable/disable widgets + // timer to update the progress bar + progressTimer = new QTimer(this); - qDefs::checkErrorMessage(myDet, "qTabMeasurement::SetupWidgetWindow"); + delayImplemented = false; + sampleImplemented = false; + // enabling according to det type + switch(myDet->getDetectorTypeAsEnum()) { + case slsDetectorDefs::MOENCH: + lblNumSamples->setEnabled(false); + spinNumSamples->setEnabled(false); + sampleImplemented = true; + break; + case slsDetectorDefs::EIGER: + lblDelay->setEnabled(false); + spinDelay->setEnabled(false); + comboDelayUnit->setEnabled(false); + delayImplemented = true; + break; + default: + break; + } + + SetupTimingMode(); + + Initialization(); + + Refresh(); + // normally called only if different + EnableWidgetsforTimingMode(); } +void qTabMeasurement::Initialization() { + connect(comboTimingMode, SIGNAL(currentIndexChanged(int)), this, SLOT(SetTimingMode(int))); + connect(spinNumMeasurements, SIGNAL(valueChanged(int)), this, SLOT(SetNumMeasurements(int))); + connect(spinNumFrames, SIGNAL(valueChanged(int)), this, SLOT(SetNumFrames(int))); + connect(spinNumTriggers, SIGNAL(valueChanged(int)), this, SLOT(SetNumTriggers(int))); + if (spinSamples->isEnabled()) { + connect(spinNumSamples, SIGNAL(valueChanged(int)), this, SLOT(SetNumSamples(int))); + } + connect(spinExpTime, SIGNAL(valueChanged(double)), this, SLOT(SetExposureTime())); + connect(comboExpUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetExposureTime())); + connect(spinPeriod, SIGNAL(valueChanged(double)), this, SLOT(SetAcquisitionPeriod())); + connect(comboPeriodUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetAcquisitionPeriod())); + if (spinDelay->isEnabled()) { + connect(spinDelay, SIGNAL(valueChanged(double)), this, SLOT(SetDelay())); + connect(comboDelayUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetDelay())); + } + connect(chkFile, SIGNAL(toggled(bool)), this, SLOT(SetFileWriteEnable(bool))); + connect(dispFileName, SIGNAL(editingFinished()), this, SLOT(SetFileName())); + connect(spinIndex, SIGNAL(valueChanged(int)), this, SLOT(SetRunIndex(int))); + connect(progressTimer, SIGNAL(timeout()), this, SLOT(UpdateProgress())); + connect(btnStart, SIGNAL(clicked()), this, SLOT(StartAcquisition())); + connect(btnStop, SIGNAL(clicked()), this, SLOT(StopAcquisition())); + +} void qTabMeasurement::SetupTimingMode() { - //To be able to index items on a combo box - model = qobject_cast(comboTimingMode->model()); - QModelIndex index[NUM_TIMING_MODES]; - QStandardItem *item[NUM_TIMING_MODES]; + QStandardItemModel* model = qobject_cast(comboTimingMode->model()); + QModelIndex index[NUMTIMINGMODES]; + QStandardItem *item[NUMTIMINGMODES]; if (model) { - for (int i = 0; i < NUM_TIMING_MODES; i++) { + for (int i = 0; i < NUMTIMINGMODES; i++) { index[i] = model->index(i, comboTimingMode->modelColumn(), comboTimingMode->rootModelIndex()); item[i] = model->itemFromIndex(index[i]); } - if (detType != slsDetectorDefs::EIGER) { + if (myDet->getDetectorTypeAsEnum() != slsDetectorDefs::EIGER) { item[(int)GATED]->setEnabled(false); item[(int)BURST_TRIGGER]->setEnabled(false); } } } +void qTabMeasurement::EnableWidgetsforTimingMode() { + FILE_LOG(logDEBUG) << "Enabling Widgets for Timing Mode"; -void qTabMeasurement::Initialization() { - //measurements - connect(spinNumMeasurements, SIGNAL(valueChanged(int)), this, SLOT(setNumMeasurements(int))); - //frames - connect(spinNumFrames, SIGNAL(valueChanged(int)), this, SLOT(setNumFrames(int))); - //exposure time - connect(spinExpTime, SIGNAL(valueChanged(double)), this, SLOT(setExposureTime())); - connect(comboExpUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(setExposureTime())); - //frame period between exposures - connect(spinPeriod, SIGNAL(valueChanged(double)), this, SLOT(setAcquisitionPeriod())); - connect(comboPeriodUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(setAcquisitionPeriod())); - //triggers - connect(spinNumTriggers, SIGNAL(valueChanged(int)), this, SLOT(setNumTriggers(int))); - //Delay After Trigger - if (spinDelay->isEnabled()) { - connect(spinDelay, SIGNAL(valueChanged(double)), this, SLOT(setDelay())); - connect(comboDelayUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(setDelay())); + // default + lblNumFrames->setEnabled(false); + spinNumFrames->setEnabled(false); + lblNumTriggers->setEnabled(false); + spinNumTriggers->setEnabled(false); + lblExpTime->setEnabled(false); + spinExpTime->setEnabled(false); + comboExpUnit->setEnabled(false); + lblPeriod->setEnabled(false); + spinPeriod->setEnabled(false); + comboPeriodUnit->setEnabled(false); + lblDelay->setEnabled(false); + spinDelay->setEnabled(false); + comboDelayUnit->setEnabled(false); + + switch(comboTimingMode->currentIndex()) { + case AUTO: + // #frames, exptime, period + spinNumTriggers->setValue(1); + lblNumFrames->setEnabled(true); + spinNumFrames->setEnabled(true); + lblExpTime->setEnabled(true); + spinExpTime->setEnabled(true); + comboExpUnit->setEnabled(true); + lblPeriod->setEnabled(true); + spinPeriod->setEnabled(true); + comboPeriodUnit->setEnabled(true); + break; + case TRIGGER: + // #triggers, exptime + lblNumTriggers->setEnabled(true); + spinNumTriggers->setEnabled(true); + lblExpTime->setEnabled(true); + spinExpTime->setEnabled(true); + comboExpUnit->setEnabled(true); + if (myDet->getDetectorTypeAsEnum() == slsDetectorDefs::EIGER) { + spinNumFrames->setValue(1); + } else { + // #frames, period, delay + lblNumFrames->setEnabled(true); + spinNumFrames->setEnabled(true); + lblPeriod->setEnabled(true); + spinPeriod->setEnabled(true); + comboPeriodUnit->setEnabled(true); + lblDelay->setEnabled(true); + spinDelay->setEnabled(true); + comboDelayUnit->setEnabled(true); + } + break; + case GATED: + // #frames + spinNumTriggers->setValue(1); + lblNumFrames->setEnabled(true); + spinNumFrames->setEnabled(true); + break; + case BURST_TRIGGER: + // #frames, exptime, period + spinNumTriggers->setValue(1); + lblNumFrames->setEnabled(true); + spinNumFrames->setEnabled(true); + lblExpTime->setEnabled(true); + spinExpTime->setEnabled(true); + comboExpUnit->setEnabled(true); + lblPeriod->setEnabled(true); + spinPeriod->setEnabled(true); + comboPeriodUnit->setEnabled(true); + break; + default: + break; } - //samples - if (spinSamples->isEnabled()) - connect(spinNumSamples, SIGNAL(valueChanged(int)), this, SLOT(setNumSamples(int))); - //file name - connect(dispFileName, SIGNAL(editingFinished()), this, SLOT(setFileName())); - //file write enable - connect(chkFile, SIGNAL(toggled(bool)), this, SLOT(EnableFileWrite(bool))); - //file index - connect(spinIndex, SIGNAL(valueChanged(int)), this, SLOT(setRunIndex(int))); - //progress bar - connect(progressTimer, SIGNAL(timeout()), this, SLOT(UpdateProgress())); - //start acquisition - connect(btnStart, SIGNAL(clicked()), this, SLOT(startAcquisition())); - //stop acquisition - connect(btnStop, SIGNAL(clicked()), this, SLOT(stopAcquisition())); - //timing mode - connect(comboTimingMode, SIGNAL(currentIndexChanged(int)), this, SLOT(SetTimingMode(int))); + + // to let qdrawplot know that triggers or frames are used + myPlot->setFrameEnabled(lblNumFrames->isEnabled()); + myPlot->setTriggerEnabled(lblNumTriggers->isEnabled()); + + CheckAcqPeriodGreaterThanExp(); } - - -void qTabMeasurement::GetTimingModeFromDetector(bool startup) { +void qTabMeasurement::GetTimingMode(bool startup) { FILE_LOG(logDEBUG) << "Getting timing mode"; + connect(comboTimingMode, SIGNAL(currentIndexChanged(int)), this, SLOT(SetTimingMode(int))); - //Get timing mode from detector - slsDetectorDefs::externalCommunicationMode mode = myDet->setExternalCommunicationMode(); - qDefs::checkErrorMessage(myDet, "qTabMeasurement::GetTimingModeFromDetector"); - - //if the mode is enabled - if (model && model->itemFromIndex(model->index(mode, comboTimingMode->modelColumn(), comboTimingMode->rootModelIndex()))->isEnabled()) { - - // first time - if (startup) { - // explicitly call SetTimingMode first time - disconnect(comboTimingMode, SIGNAL(currentIndexChanged(int)), this, SLOT(SetTimingMode(int))); - comboTimingMode->setCurrentIndex((int)mode); - SetTimingMode((int)mode); - connect(comboTimingMode, SIGNAL(currentIndexChanged(int)), this, SLOT(SetTimingMode(int))); - return; + try { + auto oldMode = comboTimingMode->currentIndex(); + auto retval = myDet->setExternalCommunicationMode(); + switch(retval) { + case GET_EXTERNAL_COMMUNICATION_MODE: + qDefs::Message(qDefs::WARNING, "Timing Mode is inconsistent for all detectors.", "qTabMeasurement::GetTimingMode"); + break; + case AUTO: + case TRIGGER: + case GATED: + case BURST_TRIGGER: + comboTimingMode->setCurrentIndex((int)retval); + // update widget enable only if different + if (oldMode != comboTimingMode->currentIndex()) { + EnableWidgetsforTimingMode(); + } + break; + default: + qDefs::ExceptionMessage("Could not get timing mode.", e.what(), "qTabMeasurement::GetTimingMode"); + break; } + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not get timing mode.", e.what(), "qTabMeasurement::GetTimingMode"); + } - // mode is the different from current (from refresh), - if (comboTimingMode->currentIndex() != mode) { - comboTimingMode->setCurrentIndex((int)mode); - } + disconnect(comboTimingMode, SIGNAL(currentIndexChanged(int)), this, SLOT(SetTimingMode(int))); +} - } - // Mode not enabled - else { - //check if the detector is not even connected - std::string offline = myDet->checkOnline(); - qDefs::checkErrorMessage(myDet, "qTabMeasurement::GetTimingModeFromDetector"); - if (!offline.empty()) { - qDefs::Message(qDefs::CRITICAL, std::string("The detector(s) ") + offline + std::string(" is/are not connected. Exiting GUI."), "Main"); - FILE_LOG(logERROR) << "The detector(s) " << offline << " is/are not connected. Exiting GUI."; - exit(-1); - } - - // onlne but mismatch in timing mode - FILE_LOG(logWARNING) << "Unknown Timing Mode " << mode << " from detector"; - qDefs::Message(qDefs::WARNING, "Unknown Timing Mode from detector.\n\nSetting timing mode to Auto.", - "qTabMeasurement::GetTimingModeFromDetector"); - comboTimingMode->setCurrentIndex((int)AUTO); - SetTimingMode((int)AUTO); +void qTabMeasurement::SetTimingMode(int mode) { + FILE_LOG(logINFO) << "Setting timing mode:" << comboTimingMode->currentText().toAscii().data(); + + try { + myDet->setExternalCommunicationMode(static_cast(value)); + EnableWidgetsforTimingMode(); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not set timing mode.", e.what(), "qTabMeasurement::SetTimingMode"); + GetTimingMode(); } } +void qTabMeasurement::GetNumMeasurements() { + FILE_LOG(logDEBUG) << "Getting number of measurements"; + disconnect(spinNumMeasurements, SIGNAL(valueChanged(int)), this, SLOT(SetNumMeasurements(int))); -void qTabMeasurement::setNumMeasurements(int val) { + try { + auto retval = myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER); + if (retval == -1) { + qDefs::Message(qDefs::WARNING, "Number of measurements is inconsistent for all detectors.", "qTabMeasurement::GetNumMeasurements"); + } + spinNumMeasurements->seValue(retval); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not get number of measurements.", e.what(), "qTabMeasurement::GetNumMeasurements"); + } + + connect(spinNumMeasurements, SIGNAL(valueChanged(int)), this, SLOT(SetNumMeasurements(int))); +} + +void qTabMeasurement::SetNumMeasurements(int val) { FILE_LOG(logINFO) << "Setting Number of Measurements to " << val; - myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER, val); - - disconnect(spinNumMeasurements, SIGNAL(valueChanged(int)), this, SLOT(setNumMeasurements(int))); - spinNumMeasurements->setValue((int)myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER, -1)); - connect(spinNumMeasurements, SIGNAL(valueChanged(int)), this, SLOT(setNumMeasurements(int))); - - qDefs::checkErrorMessage(myDet, "qTabMeasurement::setNumMeasurements"); + try { + myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER, val); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not set number of measurements.", e.what(), "qTabMeasurement::SetNumMeasurements"); + GetNumMeasurements(); + } } +void qTabMeasurement::GetNumFrames() { + FILE_LOG(logDEBUG) << "Getting number of frames"; + disconnect(spinNumFrames, SIGNAL(valueChanged(int)), this, SLOT(SetNumFrames(int))); -void qTabMeasurement::setNumFrames(int val) { + try { + auto retval = myDet->setTimer(slsDetectorDefs::FRAME_NUMBER); + if (retval == -1) { + qDefs::Message(qDefs::WARNING, "Number of frames is inconsistent for all detectors.", "qTabMeasurement::GetNumFrames"); + } + spinNumFrames->seValue(retval); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not get number of frames.", e.what(), "qTabMeasurement::GetNumFrames"); + } + + connect(spinNumFrames, SIGNAL(valueChanged(int)), this, SLOT(SetNumFrames(int))); +} + +void qTabMeasurement::SetNumFrames(int val) { FILE_LOG(logINFO) << "Setting number of frames to " << val; - myDet->setTimer(slsDetectorDefs::FRAME_NUMBER, val); - - disconnect(spinNumFrames, SIGNAL(valueChanged(int)), this, SLOT(setNumFrames(int))); - spinNumFrames->setValue((int)myDet->setTimer(slsDetectorDefs::FRAME_NUMBER, -1)); - connect(spinNumFrames, SIGNAL(valueChanged(int)), this, SLOT(setNumFrames(int))); - - qDefs::checkErrorMessage(myDet, "qTabMeasurement::setNumFrames"); + try { + myDet->setTimer(slsDetectorDefs::FRAME_NUMBER, val); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not set number of frames.", e.what(), "qTabMeasurement::SetNumFrames"); + GetNumFrames(); + } } +void qTabMeasurement::GetNumTriggers() { + FILE_LOG(logDEBUG) << "Getting number of triggers"; + disconnect(spinNumTriggers, SIGNAL(valueChanged(int)), this, SLOT(SetNumTriggers(int))); -void qTabMeasurement::setExposureTime() { - //Get the value of timer in ns - double exptimeNS = qDefs::getNSTime((qDefs::timeUnit)comboExpUnit->currentIndex(), spinExpTime->value()); - FILE_LOG(logINFO) << "Setting acquisition time to " << exptimeNS << " ns" - << "/" << spinExpTime->value() << qDefs::getUnitString((qDefs::timeUnit)comboExpUnit->currentIndex()); + try { + auto retval = myDet->setTimer(slsDetectorDefs::CYCLES_NUMBER); + if (retval == -1) { + qDefs::Message(qDefs::WARNING, "Number of triggers is inconsistent for all detectors.", "qTabMeasurement::GetNumTriggers"); + } + spinNumTriggers->seValue(retval); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not get number of frames.", e.what(), "qTabMeasurement::GetNumTriggers"); + } - myDet->setTimer(slsDetectorDefs::ACQUISITION_TIME, (int64_t)exptimeNS); - qDefs::checkErrorMessage(myDet, "qTabMeasurement::setExposureTime"); - - CheckAcqPeriodGreaterThanExp(); - - //Check if the interval between plots is ok - emit CheckPlotIntervalSignal(); + connect(spinNumTriggers, SIGNAL(valueChanged(int)), this, SLOT(SetNumTriggers(int))); } - -void qTabMeasurement::setAcquisitionPeriod() { - //Get the value of timer in ns - double acqtimeNS = qDefs::getNSTime((qDefs::timeUnit)comboPeriodUnit->currentIndex(), spinPeriod->value()); - FILE_LOG(logINFO) << "Setting frame period between exposures to " << acqtimeNS << " ns" - << "/" << spinPeriod->value() << qDefs::getUnitString((qDefs::timeUnit)comboPeriodUnit->currentIndex()); - - myDet->setTimer(slsDetectorDefs::FRAME_PERIOD, (int64_t)acqtimeNS); - qDefs::checkErrorMessage(myDet, "qTabMeasurement::setAcquisitionPeriod"); - - CheckAcqPeriodGreaterThanExp(); - //Check if the interval between plots is ok - emit CheckPlotIntervalSignal(); -} - - -void qTabMeasurement::setNumTriggers(int val) { +void qTabMeasurement::SetNumTriggers(int val) { FILE_LOG(logINFO) << "Setting number of triggers to " << val; - myDet->setTimer(slsDetectorDefs::CYCLES_NUMBER, val); - - disconnect(spinNumTriggers, SIGNAL(valueChanged(int)), this, SLOT(setNumTriggers(int))); - spinNumTriggers->setValue((int)myDet->setTimer(slsDetectorDefs::CYCLES_NUMBER, -1)); - connect(spinNumTriggers, SIGNAL(valueChanged(int)), this, SLOT(setNumTriggers(int))); - - qDefs::checkErrorMessage(myDet, "qTabMeasurement::setNumTriggers"); + try { + myDet->setTimer(slsDetectorDefs::CYCLES_NUMBER, val); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not set number of triggers.", e.what(), "qTabMeasurement::SetNumTriggers"); + GetNumTriggers(); + } } +void qTabMeasurement::GetNumSamples() { + FILE_LOG(logDEBUG) << "Getting number of samples"; + disconnect(spinNumSamples, SIGNAL(valueChanged(int)), this, SLOT(SetNumSamples(int))); -void qTabMeasurement::setDelay() { - //Get the value of timer in ns - double exptimeNS = qDefs::getNSTime((qDefs::timeUnit)comboDelayUnit->currentIndex(), spinDelay->value()); - FILE_LOG(logINFO) << "Setting delay after trigger to " << exptimeNS << " ns" - << "/" << spinDelay->value() << qDefs::getUnitString((qDefs::timeUnit)comboDelayUnit->currentIndex()); + try { + auto retval = myDet->setTimer(slsDetectorDefs::SAMPLES); + if (retval == -1) { + qDefs::Message(qDefs::WARNING, "Number of samples is inconsistent for all detectors.", "qTabMeasurement::GetNumSamples"); + } + spinNumSamples->seValue(retval); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not get number of samples.", e.what(), "qTabMeasurement::GetNumSamples"); + } - myDet->setTimer(slsDetectorDefs::DELAY_AFTER_TRIGGER, (int64_t)exptimeNS); - - qDefs::checkErrorMessage(myDet, "qTabMeasurement::setDelay"); + connect(spinNumSamples, SIGNAL(valueChanged(int)), this, SLOT(SetNumSamples(int))); } - -void qTabMeasurement::setNumSamples(int val) { +void qTabMeasurement::SetNumSamples(int val) { FILE_LOG(logINFO) << "Setting number of samples to " << val; - myDet->setTimer(slsDetectorDefs::SAMPLES, val); - - disconnect(spinNumSamples, SIGNAL(valueChanged(int)), this, SLOT(setNumSamples(int))); - spinNumSamples->setValue((int)myDet->setTimer(slsDetectorDefs::SAMPLES, -1)); - connect(spinNumSamples, SIGNAL(valueChanged(int)), this, SLOT(setNumSamples(int))); - - qDefs::checkErrorMessage(myDet, "qTabMeasurement::setNumSamples"); + try { + myDet->setTimer(slsDetectorDefs::SAMPLES, val); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not set number of samples.", e.what(), "qTabMeasurement::SetNumSamples"); + GetNumSamples(); + } } +void qTabMeasurement::GetExposureTime() { + FILE_LOG(logDEBUG) << "Getting exposure time"; + disconnect(spinExpTime, SIGNAL(valueChanged(double)), this, SLOT(SetExposureTime())); + disconnect(comboExpUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetExposureTime())); -void qTabMeasurement::setFileName() { - QString fName = dispFileName->text(); - FILE_LOG(logINFO) << "Setting File name to " << fName.toAscii().constData(); + try { + auto retval = myDet->setTimer(slsDetectorDefs::ACQUISITION_TIME); + if (retval == -1) { + qDefs::Message(qDefs::WARNING, "Exposure Time is inconsistent for all detectors.", "qTabMeasurement::GetExposureTime"); + spinExpTime->setValue(-1); + } else { + qDefs::timeUnit unit; + auto time = qDefs::getCorrectTime(unit, (static_cast(retval) * (1E-9)); + spinExpTime->setValue(time); + comboExpUnit->setCurrentIndex(static_cast(unit)); - myDet->setFileName(fName.toAscii().data()); + CheckAcqPeriodGreaterThanExp(); + } + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not get exposure time.", e.what(), "qTabMeasurement::GetExposureTime"); + } - disconnect(dispFileName, SIGNAL(editingFinished()), this, SLOT(setFileName())); - dispFileName->setText(QString(myDet->getFileName().c_str())); - connect(dispFileName, SIGNAL(editingFinished()), this, SLOT(setFileName())); - - qDefs::checkErrorMessage(myDet, "qTabMeasurement::setFileName"); + connect(spinExpTime, SIGNAL(valueChanged(double)), this, SLOT(SetExposureTime())); + connect(comboExpUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetExposureTime())); } - -void qTabMeasurement::EnableFileWrite(bool enable) { - FILE_LOG(logINFO) << "Enable File Write:" << enable; - - myDet->enableWriteToFile(enable); - disconnect(chkFile, SIGNAL(toggled(bool)), this, SLOT(EnableFileWrite(bool))); - chkFile->setChecked(myDet->enableWriteToFile()); - connect(chkFile, SIGNAL(toggled(bool)), this, SLOT(EnableFileWrite(bool))); - - bool ret = chkFile->isChecked(); - dispFileName->setEnabled(ret); - if (ret) - setFileName(); - myPlot->SetEnableFileWrite(ret); - qDefs::checkErrorMessage(myDet, "qTabMeasurement::EnableFileWrite"); +void qTabMeasurement::SetExposureTime() { + auto val = spinExpTime->value(); + auto unit = static_cast(comboExpUnit->currentIndex()); + FILE_LOG(logINFO) << "Setting exposure time to " << val << " " << qDefs::getUnitString(unit); + + try { + double timeNS = qDefs::getNSTime(unit, val); + myDet->setTimer(slsDetectorDefs::ACQUISITION_TIME, std::lround(timeNS)); + CheckAcqPeriodGreaterThanExp(); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not set exposure time.", e.what(), "qTabMeasurement::SetExposureTime"); + GetExposureTime(); + } } +void qTabMeasurement::GetAcquisitionPeriod() { + FILE_LOG(logDEBUG) << "Getting acquisition period"; + disconnect(spinPeriod, SIGNAL(valueChanged(double)), this, SLOT(SetAcquisitionPeriod())); + disconnect(comboPeriodUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetAcquisitionPeriod())); -void qTabMeasurement::setRunIndex(int index) { - FILE_LOG(logINFO) << "Setting File Index to " << index; + try { + auto retval = myDet->setTimer(slsDetectorDefs::FRAME_PERIOD); + if (retval == -1) { + qDefs::Message(qDefs::WARNING, "Acquisition Period is inconsistent for all detectors.", "qTabMeasurement::GetAcquisitionPeriod"); + spinPeriod->setValue(-1); + } else { + qDefs::timeUnit unit; + auto time = qDefs::getCorrectTime(unit, (static_cast(retval) * (1E-9)); + spinPeriod->setValue(time); + comboPeriodUnit->setCurrentIndex(static_cast(unit)); + CheckAcqPeriodGreaterThanExp(); + } + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not get acquisition period.", e.what(), "qTabMeasurement::GetAcquisitionPeriod"); + } + + connect(spinPeriod, SIGNAL(valueChanged(double)), this, SLOT(SetAcquisitionPeriod())); + connect(comboPeriodUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetAcquisitionPeriod())); +} + +void qTabMeasurement::SetAcquisitionPeriod() { + auto val = spinPeriod->value(); + auto unit = static_cast(comboPeriodUnit->currentIndex()); + FILE_LOG(logINFO) << "Setting acquisition period to " << val << " " << qDefs::getUnitString(unit); + + try { + double timeNS = qDefs::getNSTime(unit, val); + myDet->setTimer(slsDetectorDefs::FRAME_PERIOD, std::lround(timeNS)); + CheckAcqPeriodGreaterThanExp(); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not set acquisition period.", e.what(), "qTabMeasurement::SetAcquisitionPeriod"); + GetAcquisitionPeriod(); + } +} + +void qTabMeasurement::CheckAcqPeriodGreaterThanExp() { + FILE_LOG(logDEBUG) << "Checking period >= exptime"; + bool error = false; + if (lblPeriod->isEnabled()) { + double exptimeNS = qDefs::getNSTime(static_cast(comboExpUnit->currentIndex()), spinExpTime->value()); + double acqtimeNS = qDefs::getNSTime(static_cast(comboPeriodUnit->currentIndex()), spinPeriod->value()); + if (exptimeNS > acqtimeNS) { + error = true; + spinPeriod->setToolTip(errPeriodTip); + lblPeriod->setToolTip(errPeriodTip); + lblPeriod->setPalette(red); + lblPeriod->setText("Acquisition Period:*"); + } + } + + if (!error) { + spinPeriod->setToolTip(acqPeriodTip); + lblPeriod->setToolTip(acqPeriodTip); + lblPeriod->setPalette(lblTimingMode->palette()); + lblPeriod->setText("Acquisition Period:"); + } + + emit CheckPlotIntervalSignal(); +} + +void qTabMeasurement::GetDelay() { + FILE_LOG(logDEBUG) << "Getting delay"; + disconnect(spinDelay, SIGNAL(valueChanged(double)), this, SLOT(SetDelay())); + disconnect(comboDelayUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetDelay())); + + try { + auto retval = myDet->setTimer(slsDetectorDefs::DELAY_AFTER_TRIGGER); + if (retval == -1) { + qDefs::Message(qDefs::WARNING, "Delay is inconsistent for all detectors.", "qTabMeasurement::GetDelay"); + spinDelay->setValue(-1); + } else { + qDefs::timeUnit unit; + auto time = qDefs::getCorrectTime(unit, (static_cast(retval) * (1E-9)); + spinDelay->setValue(time); + comboDelayUnit->setCurrentIndex(static_cast(unit)); + + CheckAcqPeriodGreaterThanExp(); + } + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not get delay.", e.what(), "qTabMeasurement::GetDelay"); + } + + connect(spinDelay, SIGNAL(valueChanged(double)), this, SLOT(SetDelay())); + connect(comboDelayUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetDelay())); +} + +void qTabMeasurement::SetDelay() { + auto val = spinDelay->value(); + auto unit = static_cast(comboDelayUnit->currentIndex()); + FILE_LOG(logINFO) << "Setting delay to " << val << " " << qDefs::getUnitString(unit); + + try { + double timeNS = qDefs::getNSTime(unit, val); + myDet->setTimer(slsDetectorDefs::DELAY_AFTER_TRIGGER, std::lround(timeNS)); + CheckAcqPeriodGreaterThanExp(); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not set delay.", e.what(), "qTabMeasurement::SetDelay"); + GetDelay(); + } +} + +void qTabMeasurement::GetFileWriteEnable() { + FILE_LOG(logDEBUG) << "Getting File Write Enable"; + disconnect(chkFile, SIGNAL(toggled(bool)), this, SLOT(SetFileWriteEnable(bool))); + + try { + int retval = myDet->getFileWrite(); + if (retval == -1) { + qDefs::Message(qDefs::WARNING, "File write is inconsistent for all detectors.", "qTabMeasurement::GetFileWriteEnable"); + dispFileName->setEnabled(true); + } else { + chkFile->setChecked(retval == 0 ? false : true); + dispFileName->setEnabled(chkFile->isChecked()); + } + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not get file over write enable.", e.what(), "qTabMeasurement::GetFileWriteEnable"); + dispFileName->setEnabled(true); + } + + connect(chkFile, SIGNAL(toggled(bool)), this, SLOT(SetFileWriteEnable(bool))); +} + +void qTabMeasurement::SetFileWriteEnable(bool enable) { + FILE_LOG(logINFO) << "Set File Write to " << enable; + + try { + myDet->setFileWrite(enable); + // for file save enable + myPlot->SetFileWriteEnable(enable); + dispFileName->setEnabled(chkFile->isChecked()); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not set file write enable.", e.what(), "qTabMeasurement::SetFileWriteEnable"); + GetFileWriteEnable(); + } +} + +void qTabMeasurement::GetFileName() { + FILE_LOG(logDEBUG) << "Getting file name prefix"; + disconnect(dispFileName, SIGNAL(editingFinished()), this, SLOT(SetFileName())); + + try { + auto retval = myDet->getFileName(); + dispFileName->setText(QString(retval.c_str())); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not get file name prefix.", e.what(), "qTabMeasurement::GetFileName"); + } + + connect(dispFileName, SIGNAL(editingFinished()), this, SLOT(SetFileName())); +} + +void qTabMeasurement::SetFileName() { + auto val = dispFileName->text().toAscii().constData(); + FILE_LOG(logINFO) << "Setting File Name Prefix:" << val; + try { + myDet->setFileName(val); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not set file name prefix.", e.what(), "qTabMeasurement::SetFileName"); + GetFileName(); + } +} + +void qTabMeasurement::GetRunIndex() { + FILE_LOG(logDEBUG) << "Getting Acquisition File index"; + disconnect(spinIndex, SIGNAL(valueChanged(int)), this, SLOT(SetRunIndex(int))); + + try { + auto retval = myDet->getFileIndex(); + if (retval == -1) { + qDefs::Message(qDefs::WARNING, "Acquisition File Index is inconsistent for all detectors.", "qTabMeasurement::GetRunIndex"); + } + spinIndex->seValue(retval); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not get acquisition file index.", e.what(), "qTabMeasurement::GetRunIndex"); + } + + connect(spinIndex, SIGNAL(valueChanged(int)), this, SLOT(SetRunIndex(int))); +} + +void qTabMeasurement::SetRunIndex(int val) { + FILE_LOG(logINFO) << "Setting Acquisition File Index to " << val; + + try { + myDet->setFileIndex(val); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not set acquisition file index.", e.what(), "qTabMeasurement::SetRunIndex"); + GetRunIndex(); + } myDet->setFileIndex(index); - - disconnect(spinIndex, SIGNAL(valueChanged(int)), this, SLOT(setRunIndex(int))); - spinIndex->setValue(myDet->getFileIndex()); - connect(spinIndex, SIGNAL(valueChanged(int)), this, SLOT(setRunIndex(int))); - - qDefs::checkErrorMessage(myDet, "qTabMeasurement::setRunIndex"); } +void qTabMeasurement::SetCurrentMeasurement(int val) { + FILE_LOG(logDEBUG) << "Setting Current Measurement"; + if ((val) < spinNumMeasurements->value()) { + lblCurrentMeasurement->setText(QString::number(val)); + } +} + +void ResetProgress() { + FILE_LOG(logDEBUG) << "Resetting progress"; + lblCurrentFrame->setText(QString::number(0)); + lblCurrentMeasurement->setText(QString::number(0)); + progressBar->setValue(0); +} void qTabMeasurement::UpdateProgress() { - progressBar->setValue((int)myPlot->GetProgress()); - lblProgressIndex->setText(QString::number(myPlot->GetFrameIndex())); - qDefs::checkErrorMessage(myDet, "qTabMeasurement::UpdateProgress"); + FILE_LOG(logDEBUG) << "Updating progress"; + progressBar->setValue(myPlot->GetProgress()); + lblCurrentFrame->setText(QString::number(myPlot->GetFrameIndex())); } +void qTabMeasurement::UpdateFinished() { + UpdateProgress(); + disconnect(spinIndex, SIGNAL(valueChanged(int)), this, SLOT(SetRunIndex(int))); + spinIndex->setValue(myDet->getFileIndex()); + connect(spinIndex, SIGNAL(valueChanged(int)), this, SLOT(SetRunIndex(int))); + progressTimer->stop(); -void qTabMeasurement::startAcquisition() { + Enable(1); + btnStart->setEnabled(true); + qDefs::checkErrorMessage(myDet, "qTabMeasurement::UpdateFinished"); +} + +void qTabMeasurement::StartAcquisition() { btnStart->setEnabled(false); //if file write enabled and output dir doesnt exist if ((chkFile->isChecked()) && (VerifyOutputDirectoryError() == slsDetectorDefs::FAIL)) { if (qDefs::Message(qDefs::QUESTION, "Your data will not be saved.
Disable File write and Proceed with acquisition anyway?", - "qTabMeasurement::startAcquisition") == slsDetectorDefs::FAIL) { + "qTabMeasurement::StartAcquisition") == slsDetectorDefs::FAIL) { btnStart->setEnabled(true); return; } else { //done because for receiver it cant save a file with blank file path and returns without acquiring even to the gui - disconnect(chkFile, SIGNAL(toggled(bool)), this, SLOT(EnableFileWrite(bool))); - EnableFileWrite(false); - connect(chkFile, SIGNAL(toggled(bool)), this, SLOT(EnableFileWrite(bool))); + disconnect(chkFile, SIGNAL(toggled(bool)), this, SLOT(SetFileWriteEnable(bool))); + SetFileWriteEnable(false); + connect(chkFile, SIGNAL(toggled(bool)), this, SLOT(SetFileWriteEnable(bool))); } } @@ -380,14 +640,14 @@ void qTabMeasurement::startAcquisition() { progressTimer->start(100); emit StartSignal(); - qDefs::checkErrorMessage(myDet, "qTabMeasurement::startAcquisition"); + qDefs::checkErrorMessage(myDet, "qTabMeasurement::StartAcquisition"); } -void qTabMeasurement::stopAcquisition() { +void qTabMeasurement::StopAcquisition() { FILE_LOG(logINFORED) << "Stopping Acquisition"; myDet->stopAcquisition(); - qDefs::checkErrorMessage(myDet, "qTabMeasurement::stopAcquisition"); + qDefs::checkErrorMessage(myDet, "qTabMeasurement::StopAcquisition"); } @@ -400,274 +660,39 @@ void qTabMeasurement::Enable(bool enable) { } int qTabMeasurement::VerifyOutputDirectoryError() { - for (int i = 0; i < myDet->getNumberOfDetectors(); i++) {xx - if (getModuleErrorMask(i) == FILE_PATH_DOES_NOT_EXIST) { - return slsDetectorDefs:: FAIL; - } - return slsDetectorDefs:: OK; - } + try { + auto retval = myDet->getFilePath(); + // if path has no +, set multi path, else set all individually + // myDet->setFileIndex(val); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not set path.", e.what(), "qTabMeasurement::VerifyOutputDirectoryError"); + return slsDetectorDefs::FAIL; + } + return slsDetectorDefs::OK; } - -void qTabMeasurement::UpdateFinished() { - UpdateProgress(); - disconnect(spinIndex, SIGNAL(valueChanged(int)), this, SLOT(setRunIndex(int))); - spinIndex->setValue(myDet->getFileIndex()); - connect(spinIndex, SIGNAL(valueChanged(int)), this, SLOT(setRunIndex(int))); - progressTimer->stop(); - - Enable(1); - btnStart->setEnabled(true); - qDefs::checkErrorMessage(myDet, "qTabMeasurement::UpdateFinished"); -} - - -void qTabMeasurement::SetCurrentMeasurement(int val) { - if ((val) < spinNumMeasurements->value()) - lblCurrentMeasurement->setText(QString::number(val)); -} - - -void qTabMeasurement::CheckAcqPeriodGreaterThanExp() { - bool error = false; - if (lblPeriod->isEnabled()) { - double exptimeNS = qDefs::getNSTime((qDefs::timeUnit)comboExpUnit->currentIndex(), spinExpTime->value()); - double acqtimeNS = qDefs::getNSTime((qDefs::timeUnit)comboPeriodUnit->currentIndex(), spinPeriod->value()); - if (exptimeNS > acqtimeNS) { - error = true; - spinPeriod->setToolTip(errPeriodTip); - lblPeriod->setToolTip(errPeriodTip); - lblPeriod->setPalette(red); - lblPeriod->setText("Acquisition Period:*"); - } - } - - // no error or period disabled - if (!error) { - spinPeriod->setToolTip(acqPeriodTip); - lblPeriod->setToolTip(acqPeriodTip); - lblPeriod->setPalette(lblTimingMode->palette()); - lblPeriod->setText("Acquisition Period:"); - } -} - - -void qTabMeasurement::SetTimingMode(int mode) { - FILE_LOG(logINFO) << "Setting Timing mode to " << comboTimingMode->currentText().toAscii().data(); - - //Default settings - lblNumFrames->setEnabled(false); - spinNumFrames->setEnabled(false); - lblExpTime->setEnabled(false); - spinExpTime->setEnabled(false); - comboExpUnit->setEnabled(false); - lblPeriod->setEnabled(false); - spinPeriod->setEnabled(false); - comboPeriodUnit->setEnabled(false); - lblNumTriggers->setEnabled(false); - spinNumTriggers->setEnabled(false); - lblDelay->setEnabled(false); - spinDelay->setEnabled(false); - comboDelayUnit->setEnabled(false); - - bool success = false; - switch (mode) { - case AUTO: //#Frames, ExpTime, Period - spinNumTriggers->setValue(1); - lblNumFrames->setEnabled(true); - spinNumFrames->setEnabled(true); - lblExpTime->setEnabled(true); - spinExpTime->setEnabled(true); - comboExpUnit->setEnabled(true); - lblPeriod->setEnabled(true); - spinPeriod->setEnabled(true); - comboPeriodUnit->setEnabled(true); - if (myDet->setExternalCommunicationMode(slsDetectorDefs::AUTO_TIMING) == slsDetectorDefs::AUTO_TIMING) - success = true; - break; - case TRIGGER: // #Triggers, ExpTime, (#Frames, Period, Delay) - if (detType == slsDetectorDefs::EIGER) //only 1 frame for each trigger for eiger - spinNumFrames->setValue(1); - else { - lblNumFrames->setEnabled(true); - spinNumFrames->setEnabled(true); - lblDelay->setEnabled(true); - spinDelay->setEnabled(true); - comboDelayUnit->setEnabled(true); - lblPeriod->setEnabled(true); - spinPeriod->setEnabled(true); - comboPeriodUnit->setEnabled(true); - } - lblExpTime->setEnabled(true); - spinExpTime->setEnabled(true); - comboExpUnit->setEnabled(true); - lblNumTriggers->setEnabled(true); - spinNumTriggers->setEnabled(true); - if (myDet->setExternalCommunicationMode(slsDetectorDefs::TRIGGER_EXPOSURE) == slsDetectorDefs::TRIGGER_EXPOSURE) - success = true; - break; - - case GATED: //#Frames (Only Eiger) - - spinNumTriggers->setValue(1); - lblNumFrames->setEnabled(true); - spinNumFrames->setEnabled(true); - - if (myDet->setExternalCommunicationMode(slsDetectorDefs::GATED) == slsDetectorDefs::GATED) - success = true; - break; - - case BURST_TRIGGER: //#Frames, ExpTime, Period (Only Eiger) - spinNumTriggers->setValue(1); - - lblNumFrames->setEnabled(true); - spinNumFrames->setEnabled(true); - lblExpTime->setEnabled(true); - spinExpTime->setEnabled(true); - comboExpUnit->setEnabled(true); - lblPeriod->setEnabled(true); - spinPeriod->setEnabled(true); - comboPeriodUnit->setEnabled(true); - if (myDet->setExternalCommunicationMode(slsDetectorDefs::BURST_TRIGGER) == slsDetectorDefs::BURST_TRIGGER) - success = true; - break; - default: - FILE_LOG(logERROR) << "Timing mode unknown to GUI"; - //This should never happen - qDefs::Message(qDefs::CRITICAL, "Timing mode unknown to GUI", "qTabMeasurement::SetTimingMode"); - qDefs::checkErrorMessage(myDet, "qTabMeasurement::SetTimingMode"); - exit(-1); - } - qDefs::checkErrorMessage(myDet, "qTabMeasurement::SetTimingMode"); - if (!success) { - - if (mode != AUTO) { - qDefs::Message(qDefs::WARNING, "The detector timing mode could not be set.\n\nSetting timing mode to Auto", - "qTabMeasurement::SetTimingMode"); - comboTimingMode->setCurrentIndex((int)AUTO); - return; - } else { - // can't do anything. just ignore - qDefs::Message(qDefs::ERROR, "The detector timing mode could not be set.", "qTabMeasurement::SetTimingMode"); - } - } - - //Frame Period between exposures - CheckAcqPeriodGreaterThanExp(); - - // to let qdrawplot know that triggers or frames are used - myPlot->setFrameEnabled(lblNumFrames->isEnabled()); - myPlot->setTriggerEnabled(lblNumTriggers->isEnabled()); - - qDefs::checkErrorMessage(myDet, "qTabMeasurement::SetTimingMode"); - - emit CheckPlotIntervalSignal(); -} - - void qTabMeasurement::Refresh() { FILE_LOG(logDEBUG) << "**Updating Measurement Tab"; if (!myPlot->isRunning()) { //timing mode - will also check if exptime>acq period - GetTimingModeFromDetector(); - - //to prevent it from recalculating forever - disconnect(spinNumMeasurements, SIGNAL(valueChanged(int)), this, SLOT(setNumMeasurements(int))); - disconnect(spinNumFrames, SIGNAL(valueChanged(int)), this, SLOT(setNumFrames(int))); - disconnect(spinExpTime, SIGNAL(valueChanged(double)), this, SLOT(setExposureTime())); - disconnect(comboExpUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(setExposureTime())); - disconnect(spinPeriod, SIGNAL(valueChanged(double)), this, SLOT(setAcquisitionPeriod())); - disconnect(comboPeriodUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(setAcquisitionPeriod())); - disconnect(spinNumTriggers, SIGNAL(valueChanged(int)), this, SLOT(setNumTriggers(int))); - if (spinDelay->isEnabled()) { - disconnect(spinDelay, SIGNAL(valueChanged(double)), this, SLOT(setDelay())); - disconnect(comboDelayUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(setDelay())); + GetTimingMode(); + GetNumMeasurements(); + GetNumFrames(); + GetExposureTime(); + GetAcquisitionPeriod(); + GetNumTriggers(); + if (delayImplemented) { + GetDelay(); } - if (spinSamples->isEnabled()) - disconnect(spinNumSamples, SIGNAL(valueChanged(int)), this, SLOT(setNumSamples(int))); - disconnect(dispFileName, SIGNAL(editingFinished()), this, SLOT(setFileName())); - disconnect(chkFile, SIGNAL(toggled(bool)), this, SLOT(EnableFileWrite(bool))); - disconnect(spinIndex, SIGNAL(valueChanged(int)), this, SLOT(setRunIndex(int))); - disconnect(progressTimer, SIGNAL(timeout()), this, SLOT(UpdateProgress())); - - - FILE_LOG(logDEBUG) << "Getting number of measurements & frames"; - //measurements - spinNumMeasurements->setValue((int)myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER, -1)); - //frames - spinNumFrames->setValue((int)myDet->setTimer(slsDetectorDefs::FRAME_NUMBER, -1)); - - FILE_LOG(logDEBUG) << "Getting Exposure time"; - qDefs::timeUnit unit; - //Exp Time - double oldExptimeNs = qDefs::getNSTime((qDefs::timeUnit)comboExpUnit->currentIndex(), spinExpTime->value()); - double time = qDefs::getCorrectTime(unit, ((double)(myDet->setTimer(slsDetectorDefs::ACQUISITION_TIME, -1) * (1E-9)))); - spinExpTime->setValue(time); - comboExpUnit->setCurrentIndex((int)unit); - double newExptimeNs = qDefs::getNSTime((qDefs::timeUnit)comboExpUnit->currentIndex(), spinExpTime->value()); - - //period - FILE_LOG(logDEBUG) << "Getting Acquisition Period"; - double oldAcqtimeNS = qDefs::getNSTime((qDefs::timeUnit)comboPeriodUnit->currentIndex(), spinPeriod->value()); - time = qDefs::getCorrectTime(unit, ((double)(myDet->setTimer(slsDetectorDefs::FRAME_PERIOD, -1) * (1E-9)))); - spinPeriod->setValue(time); - comboPeriodUnit->setCurrentIndex((int)unit); - double newAcqtimeNS = qDefs::getNSTime((qDefs::timeUnit)comboPeriodUnit->currentIndex(), spinPeriod->value()); - - // change in period or exptime - if (newExptimeNs != oldExptimeNs || newAcqtimeNS != oldAcqtimeNS) { - //Frame Period between exposures - CheckAcqPeriodGreaterThanExp(); - - emit CheckPlotIntervalSignal(); + if (sampleImplemented) { + GetNumSamples(); } - - FILE_LOG(logDEBUG) << "Getting #triggers and delay"; - //triggers - spinNumTriggers->setValue((int)myDet->setTimer(slsDetectorDefs::CYCLES_NUMBER, -1)); - - //delay - if (spinDelay->isEnabled()) - time = qDefs::getCorrectTime(unit, ((double)(myDet->setTimer(slsDetectorDefs::DELAY_AFTER_TRIGGER, -1) * (1E-9)))); - - // samples - if (spinSamples->isEnabled()) { - spinNumSamples->setValue((int)myDet->setTimer(slsDetectorDefs::SAMPLES, -1)); - } - - FILE_LOG(logDEBUG) << "Getting file name prefix, file index, file write enable and progress index"; - //file name - dispFileName->setText(QString(myDet->getFileName().c_str())); - //file write enable - chkFile->setChecked(myDet->enableWriteToFile()); - //file index - spinIndex->setValue(myDet->getFileIndex()); - - //progress label index - lblProgressIndex->setText("0"); - - connect(spinNumMeasurements, SIGNAL(valueChanged(int)), this, SLOT(setNumMeasurements(int))); - connect(spinNumFrames, SIGNAL(valueChanged(int)), this, SLOT(setNumFrames(int))); - connect(spinExpTime, SIGNAL(valueChanged(double)), this, SLOT(setExposureTime())); - connect(comboExpUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(setExposureTime())); - connect(spinPeriod, SIGNAL(valueChanged(double)), this, SLOT(setAcquisitionPeriod())); - connect(comboPeriodUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(setAcquisitionPeriod())); - connect(spinNumTriggers, SIGNAL(valueChanged(int)), this, SLOT(setNumTriggers(int))); - if (spinDelay->isEnabled()) { - connect(spinDelay, SIGNAL(valueChanged(double)), this, SLOT(setDelay())); - connect(comboDelayUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(setDelay())); - } - if (spinSamples->isEnabled()) - connect(spinNumSamples, SIGNAL(valueChanged(int)), this, SLOT(setNumSamples(int))); - disconnect(dispFileName, SIGNAL(editingFinished()), this, SLOT(setFileName())); - connect(chkFile, SIGNAL(toggled(bool)), this, SLOT(EnableFileWrite(bool))); - connect(spinIndex, SIGNAL(valueChanged(int)), this, SLOT(setRunIndex(int))); - connect(progressTimer, SIGNAL(timeout()), this, SLOT(UpdateProgress())); - - qDefs::checkErrorMessage(myDet, "qTabMeasurement::Refresh"); - } + GetFileWriteEnable(); + GetFileName(); + GetRunIndex(); + ResetProgress(); FILE_LOG(logDEBUG) << "**Updated Measurement Tab"; } diff --git a/slsDetectorGui/src/qTabSettings.cpp b/slsDetectorGui/src/qTabSettings.cpp index a3363f2b4..41d5dcfad 100755 --- a/slsDetectorGui/src/qTabSettings.cpp +++ b/slsDetectorGui/src/qTabSettings.cpp @@ -1,6 +1,5 @@ #include "qTabSettings.h" - -#include "multiSlsDetector.h" +#include "qDefs.h" #include @@ -135,6 +134,24 @@ void qTabSettings::GetSettings() { connect(comboSettings, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSettings(int))); } +void qTabSettings::SetSettings(int index) { + // settings + auto val = static_cast(index); + FILE_LOG(logINFO) << "Setting Settings to " << myDet->slsDetectorDefs::getDetectorSettings(val); + + try { + myDet->setSettings(val); + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not set settings.", e.what(), "qTabSettings::SetSettings"); + GetSettings(); + } + + // threshold + if (spinThreshold->isEnabled()) { + SetThresholdEnergy(spinThreshold->value()); + } +} + void qTabSettings::GetDynamicRange() { FILE_LOG(logDEBUG) << "Getting dynamic range"; disconnect(comboDynamicRange, SIGNAL(activated(int)), this, SLOT(SetDynamicRange(int))); @@ -170,6 +187,32 @@ void 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() + try { + switch (index) { + case DYNAMICRANGE_32: + myDet->setDynamicRange(32); + break; + case DYNAMICRANGE_16: + myDet->setDynamicRange(16); + break; + case DYNAMICRANGE_8: + myDet->setDynamicRange(8); + break; + case DYNAMICRANGE_4: + myDet->setDynamicRange(4); + break; + default: + qDefs::Message(qDefs::WARNING, std::string("Unknown dynamic range: ") + std::to_string(index), "qTabSettings::SetDynamicRange"); + break; + } + } catch (const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not set dynamic range.", e.what(), "qTabSettings::SetDynamicRange"); + GetDynamicRange(); + } +} + void qTabSettings::GetThresholdEnergy() { FILE_LOG(logDEBUG) << "Getting theshold energy"; disconnect(spinThreshold, SIGNAL(valueChanged(int)), this, SLOT(SetThresholdEnergy())); @@ -189,53 +232,6 @@ void qTabSettings::GetThresholdEnergy() { connect(spinThreshold, SIGNAL(valueChanged(int)), this, SLOT(SetThresholdEnergy())); } -void qTabSettings::SetSettings(int index) { - // settings - auto val = static_cast(index); - FILE_LOG(logINFO) << "Setting Settings to " << myDet->slsDetectorDefs::getDetectorSettings(val); - - try { - myDet->setSettings(val); - } catch (const sls::NonCriticalError &e) { - qDefs::ExceptionMessage("Could not set settings.", e.what(), "qTabSettings::SetSettings"); - GetSettings(); - } - - // threshold - if (spinThreshold->isEnabled()) { - SetThresholdEnergy(spinThreshold->value()); - } -} - -void qTabSettings::SetDynamicRange(int index) { - try { - switch (index) { - case DYNAMICRANGE_32: - FILE_LOG(logINFO) << "Setting dynamic range to 32"; - myDet->setDynamicRange(32); - break; - case DYNAMICRANGE_16: - FILE_LOG(logINFO) << "Setting dynamic range to 16"; - myDet->setDynamicRange(16); - break; - case DYNAMICRANGE_8: - FILE_LOG(logINFO) << "Setting dynamic range to 8"; - myDet->setDynamicRange(8); - break; - case DYNAMICRANGE_4: - FILE_LOG(logINFO) << "Setting dynamic range to 4"; - myDet->setDynamicRange(4); - break; - default: - qDefs::Message(qDefs::WARNING, std::string("Unknown dynamic range: ") + std::to_string(index), "qTabSettings::SetDynamicRange"); - break; - } - } catch (const sls::NonCriticalError &e) { - qDefs::ExceptionMessage("Could not set dynamic range.", e.what(), "qTabSettings::SetDynamicRange"); - GetDynamicRange(); - } -} - void qTabSettings::SetThresholdEnergy(int index) { FILE_LOG(logINFO) << "Setting Threshold Energy to " << index << " eV"; try {