diff --git a/slsDetectorGui/forms/form_tab_plot.ui b/slsDetectorGui/forms/form_tab_plot.ui index ebec9595c..a882c7c57 100755 --- a/slsDetectorGui/forms/form_tab_plot.ui +++ b/slsDetectorGui/forms/form_tab_plot.ui @@ -1382,8 +1382,8 @@ Displays minimum, maximum and sum of values for each plot. - 20 - 130 + 11 + 124 356 57 @@ -1400,9 +1400,9 @@ Displays minimum, maximum and sum of values for each plot. - 10 + 18 22 - 342 + 72 35 @@ -1410,22 +1410,6 @@ Displays minimum, maximum and sum of values for each plot. 0 - - - - true - - - - 0 - 0 - - - - Save All with Automatic File Name - - - @@ -1501,8 +1485,8 @@ Displays minimum, maximum and sum of values for each plot. - 15 - 190 + 11 + 187 746 150 @@ -1522,7 +1506,7 @@ Displays minimum, maximum and sum of values for each plot. 10 20 726 - 126 + 129 @@ -2160,8 +2144,8 @@ Streaming Interval between 2 plots. Default is time interval with 200 ms. - 400 - 130 + 399 + 122 355 60 @@ -2180,7 +2164,7 @@ Streaming Interval between 2 plots. Default is time interval with 200 ms. 10 23 - 342 + 336 37 @@ -2315,7 +2299,7 @@ Streaming Interval between 2 plots. Default is time interval with 200 ms. - 10 + 5 20 @@ -2331,7 +2315,7 @@ Streaming Interval between 2 plots. Default is time interval with 200 ms. - 10 + 5 20 @@ -2417,7 +2401,6 @@ Streaming Interval between 2 plots. Default is time interval with 200 ms. chkInterpolate chkContour chkLogz - chkSaveAll comboFrequency chkTitle dispTitle diff --git a/slsDetectorGui/include/qCloneWidget.h b/slsDetectorGui/include/qCloneWidget.h index 17bb83883..2d5c1f1e5 100755 --- a/slsDetectorGui/include/qCloneWidget.h +++ b/slsDetectorGui/include/qCloneWidget.h @@ -35,21 +35,9 @@ class qCloneWidget : public QMainWindow { * @param lines style of plot if lines or dots * @param markers style of plot markers or not */ - void SetCloneHists(int nHists, int histNBins, double *histXAxis, double *histYAxis[], std::string histTitle[], bool lines, bool markers); + void SetCloneHists(int nHists, int histNBins, double *histXAxis, std::vector histYAxis, std::vector histTitle, bool lines, bool markers); - /** - * Get the 1D hist values to plot for angle plotting - * @param nHists Number of graphs in 1D - * @param histNBins Total Number of X axis values/channels in 1D - * @param histXAxis X Axis value in 1D - * @param histYAxis Y Axis value in 1D - * @param histTitle Title for all the graphs in 1D - * @param lines style of plot if lines or dots - * @param markers style of plot markers or not - */ - void SetCloneHists(int nHists, int histNBins, double *histXAxis, double *histYAxis, std::string histTitle[], bool lines, bool markers); - - /** + /** * Get the 1D hist values to plot for angle plotting * @param nbinsx number of bins in x axis * @param xmin minimum in x axis diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index 2acbec855..224672f6b 100755 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -3,550 +3,224 @@ #include "qDefs.h" class detectorData; class SlsQt1DPlot; +class SlsQtH1D; class SlsQt2DPlotLayout; class qCloneWidget; - -#include +/* +#include "qwt_symbol.h" #include #include -#include #include -#include "qwt_symbol.h" - +#include +#include #include -#include -#include -#include -#include #include - - - - -#define MAX_1DPLOTS 10 - - -/** - *@short Sets up the plot widget - */ -class qDrawPlot:public QWidget{ - Q_OBJECT - - - - -public: - /** \short The constructor */ - qDrawPlot(QWidget *parent, multiSlsDetector* detector); - /** Destructor */ - ~qDrawPlot(); - - - bool isRunning(); - int GetProgress(); - int GetFileIndex(); - int GetFrameIndex(); - void SetFileWrite(bool enable); - void SetPlotTitlePrefix(QString title); - void SetXAxisTitle(QString title); - void SetYAxisTitle(QString title); - void SetZAxisTitle(QString title); - void DisableZoom(bool disable); - void EnablePlot(bool enable); - void EnableAnglePlot(bool enable); - - - void SetXYRange(bool changed); - /**Sets the min/max for x/y - * @param val is the value to be set - * @param xy is xmin,xmax,ymin or ymax */ - void SetXYRangeValues(double val,qDefs::range xy); - /**Sets if min/max for x/y is enabled - * @param changed is if this has been changed - * @param xy is xmin,xmax,ymin or ymax */ - void IsXYRangeValues(bool changed,qDefs::range xy); - - /** Set Plot timer - between plots in ms*/ - void SetPlotTimer(double time); - /** Set Plot frame factor - between plots, also for receiver if exists */ - void SetFrameFactor(int frame); - - void SetCallBacks(bool enable); - - /** Starts or stop acquisition - * Calls startDaq() function - * @param stop_if_running is 0 to stop acquisition and 1 to start acquisition - */ - void StartStopDaqToggle(bool stop_if_running=0); - /** Set frame enabled - * @param enable enable*/ - void setFrameEnabled(bool enable); - /** Set trigger enabled - * @param enable enable */ - void setTriggerEnabled(bool enable); - - /** Updates the trimbit plot - * @param fromDetector is true if the trimbits should be loaded from detector - * @param Histogram true if histogram, else data graph - * returns ok/fail - * */ - int UpdateTrimbitPlot(bool fromDetector,bool Histogram); - - /** This is set once client initiates start/stop acquisition - * and this is reset when the gui really starts/stops- to know when to return - */ - void SetClientInitiated(); - - /** Get client intiated variable. This is set once client initiates start/stop acquisition - * and this is reset when the gui really starts/stops- to know when to return - */ - bool GetClientInitiated(); - - /** Update all ranges, interpolate etc after cloning - * parameters are if they are checked or not - */ - void UpdateAfterCloning(bool points, bool logy, bool interpolate, bool contour, bool logz); - - /** set binary range */ - void SetBinary(bool enable, int from=0, int to=0); - - /** Enable/Disable Histogram */ - void SetHistogram(bool enable,int histArg, int min=0, int max=0, double size=0){histogram = enable;histogramArgument = histArg; histFrom=min;histTo=max;histSize=size;}; - - /** Get X Minimum value from plot */ - double GetXMinimum(); - /** Get X Maximum value from plot */ - double GetXMaximum(); - /** Get Y Minimum value from plot */ - double GetYMinimum(); - /** Get Y Maximum value from plot */ - double GetYMaximum(); - -public slots: -/** To select 1D or 2D plot - @param i is 1 for 1D, else 2D plot */ -void SelectPlot(int i=2); -/** To select 1D plot */ -void Select1DPlot(); -/** To select 2D plot */ -void Select2DPlot(); -/** To clear plot */ -void Clear1DPlot(); -/** Creates a clone of the plot */ -void ClonePlot(); -/** Closes all the clone plots */ -void CloseClones(); -/** Saves all the clone plots */ -void SaveClones(); -/** To Save plot */ -void SavePlot(); -/** Save all plots **/ -void SaveAll(bool enable); -/** Sets persistency from plot tab */ -void SetPersistency(int val); -/** sets style of plot to lines*/ -void SetLines(bool enable); -/** sets markers */ -void SetMarkers(bool enable); -/** sets the scan argument to prepare the plot*/ -// void SetScanArgument(int scanArg); -/** sets stop_signal to true */ -void StopAcquisition(); -/** Set/unset pedestal */ -void SetPedestal(bool enable); -/** Recalculate Pedestal */ -void RecalculatePedestal(); -/** Set/unset accumulate */ -void SetAccumulate(bool enable); -/** Reset accumulation */ -void ResetAccumulate(); -/** Display Statistics */ -void DisplayStatistics(bool enable); - - - - - -private: -/** Initializes all its members and the thread */ -void Initialization(); -/** Sets up the widget */ -void SetupWidgetWindow(); - - -/** Gets the image title */ -const char* GetImageTitle(); -/** Gets the hist title for a 1D plot */ -const char* GetHistTitle(int i); -/** Gets the y axis value for the hist in 1D plot */ -double* GetHistYAxis(int i); - - -/** Locks the image to update plot */ -int LockLastImageArray(); -/** Unocks the image to update plot */ -int UnlockLastImageArray(); -/** Starts the acquisition */ -int StartDaqForGui(); -/** Stops the acquisition */ -int StopDaqForGui(); - -/** Starts/stops Acquisition Thread */ -bool StartOrStopThread(bool start); - -/** Sets up measurement each time - * */ -void SetupMeasurement(); - -/** Resets the acquisition parameter like lastimagenumber */ -int ResetDaqForGui(); - -/** The function which is called when start acquisition thread is created */ -static void* DataStartAcquireThread(void *this_pointer); - -/** This is called by the detector class to copy the data it jus acquired */ -static int GetDataCallBack(detectorData *data, int fIndex, int subIndex, void *this_pointer); - -/** This is called by the GetDataCallBack function to copy the data */ -int GetData(detectorData *data, int fIndex, int subIndex); - -/** This is called by detector class when acquisition is finished - * @param currentProgress current progress of measurement - * @param detectorStatus current status of the detector - * @param this_pointer is the pointer pointing to this object - * */ -static int GetAcquisitionFinishedCallBack(double currentProgress,int detectorStatus, void *this_pointer); - -/** This is called by static function when acquisition is finished - * @param currentProgress current progress of measurement - * @param detectorStatus current status of the detector - * */ -int AcquisitionFinished(double currentProgress,int detectorStatus); - -/** This is called by detector class when a measurement is finished - * @param currentMeasurementIndex current measurement index - * @param fileIndex current file index - * @param this_pointer is the pointer pointing to this object - * */ -static int GetMeasurementFinishedCallBack(int currentMeasurementIndex, int fileIndex, void *this_pointer); - -/** This is called by the static function when meausrement is finished - * @param currentMeasurementIndex current measurement index - * @param fileIndex current file index - * */ -int MeasurementFinished(int currentMeasurementIndex, int fileIndex); - -/** This is called by the detector class to send progress if receiver is online */ -static int GetProgressCallBack(double currentProgress, void *this_pointer); - - -/** Saves all the plots. All sets saveError to true if not saved.*/ -void SavePlotAutomatic(); -/** Sets the style of the 1d plot */ -void SetStyle(SlsQtH1D* h); - - -/** Find Statistics - * @param min is the minimum value - * @param max is the maximum value - * @param sum is the sum of all values - * @param array is the array to get statistics from - * @param size is the size of the array */ -void GetStatistics(double &min, double &max, double &sum, double* array, int size); - - -/** - * Convert data from char* to double based on bit mode (get gain data from plot if enabled for jungfrau - * @param dest destination double array - * @param source source char array - * @param size number of pixels - * @param databytes number of data bytes - * @param dr dynamic range - * @param gaindest NULL if not required, points to a double array to be filled up if gain data enabled - * - */ -void toDoublePixelData(double* dest, char* source,int size, int databytes, int dr, double* gaindest = NULL); - -private slots: -/** To update plot - * */ -void UpdatePlot(); -/** To start or stop acquisition - * @param start is 1 to start and 0 to stop acquisition - * */ -void StartDaq(bool start); -/** To set the reference to zero after closing a clone - * @param id is the id of the clone - * */ -void CloneCloseEvent(int id); -/**After a pause, the gui is allowed to collect the data - * this is called when it is over - * */ -void UpdatePause(); -/** Shows the first save error message while automatic saving - * @param fileName file name of the first file that it tried to save. - * */ -void ShowSaveErrorMessage(QString fileName); -/**Shows an error message when acquisition stopped unexpectedly - * @param status is the status of the detector - * */ -void ShowAcquisitionErrorMessage(QString status); -/** - * Enable Gain Plot - * @param e true for enable, false for disable - */ -void EnableGainPlot(bool e); - -signals: -void UpdatingPlotFinished(); -void InterpolateSignal(bool); -void ContourSignal(bool); -void LogzSignal(bool); -void LogySignal(bool); -void ResetZMinZMaxSignal(bool,bool,double,double); -void SetCurrentMeasurementSignal(int); -void saveErrorSignal(QString); -void AcquisitionErrorSignal(QString); -void UpdatePlotSignal(); -void GainPlotSignal(bool); - - -private: -multiSlsDetector *myDet; -slsDetectorDefs::detectorType detType; - -SlsQt1DPlot* plot1D; -QVector plot1DHists; - - -SlsQt2DPlotLayout* plot2D; - - -static const int MAXCloneWindows = 50; -qCloneWidget *cloneWidgets[MAXCloneWindows]; - -/** Widgets needed to set up plot*/ -QGroupBox *boxPlot; -QGridLayout *layout; -QGridLayout *plotLayout; - -QLabel *histFrameIndexTitle; - - - -int currentMeasurement; -int currentFrame; -int currentFileIndex; -int currentFrameIndex; - -int numberofFrames; -double acquisitionPeriod; -double exposureTime; - -volatile bool stop_signal; - - -pthread_mutex_t last_image_complete_mutex; - -/**variables for histograms */ -/** X Axis Title in 2D */ -QString imageXAxisTitle; -/** Y Axis Title in 2D */ -QString imageYAxisTitle; -/** Z Axis Title in 2D */ -QString imageZAxisTitle; -/** X Axis Title in 1D */ -QString histXAxisTitle; -/** Y Axis Title in 1D */ -QString histYAxisTitle; -/** Title for all the graphs in 1D */ -std::string histTitle[MAX_1DPLOTS]; -/** Title in 2D */ -std::string imageTitle; -/** plot Title */ -QString plotTitle; -/** plot Title prefix */ -QString plotTitle_prefix; -/** 1D or 2D */ -unsigned int plot_in_scope; -/** Number of Pixels in X Axis */ -unsigned int nPixelsX; -/** Number of angle Pixels in X Axis */ -int nAnglePixelsX; -/** Number of pixel bins in Y Axis */ -unsigned int nPixelsY; -/** Min Pixel number for Y Axis*/ -double minPixelsY; -/** Max Pixel number for Y Axis*/ -double maxPixelsY; -/** starting pixel */ -double startPixel; -/** end Pixel*/ -double endPixel; -/** pixel width */ -double pixelWidth; - -/** Current Image Number */ -unsigned int lastImageNumber; - -/** Number of graphs in 1D */ -unsigned int nHists; -/** Total Number of X axis values/channels in 1D */ -int histNBins; -/** X Axis value in 1D */ -double* histXAxis; -/** Y Axis value in 1D */ -double* histYAxis[MAX_1DPLOTS]; -/** X Axis for angles in 1D */ -double* histXAngleAxis; -/** Y Axis for angles in 1D (no persistency) */ -double* histYAngleAxis; -/** X Axis for trimbits in 1D */ -double* histTrimbits; - - -/** Current Image Values in 2D */ -double* lastImageArray; - -/**persistency to be reached*/ -int persistency; -/** persistency takes time to reach as it increases per frame - * this is the current one */ -int currentPersistency; -/** to update the progress for each getData() so that - * measurement tab can request on a timer basis*/ -int progress; -/**If plot is enabled from plot tab*/ -bool plotEnable; -/**If plot is dotted */ -bool lines; -bool markers; -/** Plot marker */ -QwtSymbol *marker; -QwtSymbol *noMarker; -/** Save all plots */ -bool saveAll; -/** If error, while automatically saving plots, checks this at the end of an acquistion */ -bool saveError; -/** index of last saved image for automatic saving*/ -int lastSavedFrame; -/** index of measurement number of last saved image for automatic saving*/ -int lastSavedMeasurement; -/**if an acquisition is running, so as not to refresh tab - * and also to update plot only if running (while creating clones)*/ -bool running; - -/** if the min/max of x and y has been changed, - * to notify while plotting */ -bool XYRangeChanged; -/**the specific min/max of x/y*/ -double XYRangeValues[4]; -/**if the specific min/max of x/y is enabled */ -bool IsXYRange[4]; - -/** Specific timer value between plots */ -double timerValue; -/** every nth frame when to plot */ -int frameFactor; -/**if frame is enabled in measurement tab */ -bool isFrameEnabled; -/**if trigger is enabled in measurement tab */ -bool isTriggerEnabled; - -/** scan arguments*/ -int scanArgument; - -/** histogram arguments*/ -int histogramArgument; - -/** enable angle plot */ -bool anglePlot; -/** prevents err msg displaying twice when detector stopped, "transmitting" */ -bool alreadyDisplayed; - -/**saves the file path and file name, not to access shared memory while running*/ -QString filePath; -QString fileName; - -/** Max Number of Clone Windows */ -static const int TRIM_HISTOGRAM_XMAX = 63; - -/**if the values increment backwards*/ -bool backwardScanPlot; - -/**if files will be saved and index increased*/ -bool fileSaveEnable; - - -/** true of originally 2d */ -bool originally2D; - - -//pedstal -/** Number of pedestal frames*/ -static const int NUM_PEDESTAL_FRAMES = 20; -/** set/unset pedestal*/ -bool pedestal; -/** pedestal values */ -double* pedestalVals; -/** temporary pedestal values to hide while recalculating*/ -double* tempPedestalVals; -/** count for 20 frames to calculate the pedestal */ -int pedestalCount; -/** start pedestal calculation */ -bool startPedestalCal; - -//accumulation -/** set/unset accumulation */ -bool accumulate; -/** to reset accumulation */ -bool resetAccumulate; - -/** range for binary plot output */ -bool binary; -int binaryFrom; -int binaryTo; - -/** this is set when client starts/stops acquisition - * and is reset once the gui really starts/stops */ -bool clientInitiated; - - -/** display statistics widgets */ -QWidget *widgetStatistics; -QLabel *lblMinDisp; -QLabel *lblMaxDisp; -QLabel *lblSumDisp; - -bool displayStatistics; - - -/* histogram */ -bool histogram; -int histFrom; -int histTo; -double histSize; -QwtPlotGrid *grid; -QwtPlotHistogram *plotHistogram; -QVector histogramSamples; - - -bool plotRequired; - - -/** 2D object second plot */ -SlsQt2DPlotLayout* gainplot2D; -/** Current Image Values in 2D gain plot */ -double* gainImageArray; -/** gain plot enable, enabled if gain data has been extracted and is available */ -bool gainPlotEnable; -/** gain data enable, enabled if gain data to be extracted from normal data */ -bool gainDataEnable; - -const static int npixelsx_jctb = 400; -int npixelsy_jctb; - - +#include +#include +#include +#include +*/ + +class qDrawPlot : public QWidget { + Q_OBJECT + + public: + /** \short The constructor */ + qDrawPlot(QWidget *parent, multiSlsDetector *detector); + /** Destructor */ + ~qDrawPlot(); + + /** If the gui client has started or stopped */ + void SetClientInitiated(); + bool GetClientInitiated(); + bool isRunning(); + int GetProgress(); + int GetCurrentFrameIndex(); + void SetPlotTitlePrefix(QString title); + void SetXAxisTitle(QString title); + void SetYAxisTitle(QString title); + void SetZAxisTitle(QString title); + void DisableZoom(bool disable); + void SetXYRange(bool changed); + void SetXYRangeValues(double val, qDefs::range xy); + void IsXYRangeValues(bool changed, qDefs::range xy); + double GetXMinimum(); + double GetXMaximum(); + double GetYMinimum(); + double GetYMaximum(); + void SetDataCallBack(bool enable); + void SetBinary(bool enable, int from = 0, int to = 0); + + /** Starts or stop acquisition + * Calls startDaq() function + * @param stop_if_running is 0 to stop acquisition and 1 to start + * acquisition + */ + void StartStopDaqToggle(bool stop_if_running = 0); + + public slots: + void StopAcquisition(); + void SetPersistency(int val); + void SetLines(bool enable); + void SetMarkers(bool enable); + void SetPedestal(bool enable); + void RecalculatePedestal(); + void SetAccumulate(bool enable); + void ResetAccumulate(); + void DisplayStatistics(bool enable); + void ClonePlot(); + void CloseClones(); + void SaveClones(); + void SavePlot(); + void Select1DPlot(); + void Select2DPlot(); + + private slots: + void CloneCloseEvent(int id); + void EnableGainPlot(bool e); + + void UpdatePlot(); + void StartDaq(bool start); + void ShowAcquisitionErrorMessage(QString status); + + signals: + void UpdatingPlotFinished(); + void InterpolateSignal(bool); + void ContourSignal(bool); + void LogzSignal(bool); + void LogySignal(bool); + void ResetZMinZMaxSignal(bool, bool, double, double); + void SetCurrentMeasurementSignal(int); + void AcquisitionErrorSignal(QString); + void UpdatePlotSignal(); + void GainPlotSignal(bool); + + private: + void SetupWidgetWindow(); + void Initialization(); + void SetupStatistics(); + void SetupPlots(); + const char *GetTitle1d(int histIndex); + double *GetHistYAxis(int histIndex); + void SetStyle(SlsQtH1D *h); + void GetStatistics(double &min, double &max, double &sum, double *array, int size); + void SelectPlot(int i = 2); + void Clear1DPlot(); + + + int LockLastImageArray(); + int UnlockLastImageArray(); + int StartDaqForGui(); + int StopDaqForGui(); + bool StartOrStopThread(bool start); + void SetupMeasurement(); + int ResetDaqForGui(); + static void *DataStartAcquireThread(void *this_pointer); + static int GetDataCallBack(detectorData *data, int fIndex, int subIndex, void *this_pointer); + int GetData(detectorData *data, int fIndex, int subIndex); + static int GetAcquisitionFinishedCallBack(double currentProgress, int detectorStatus, void *this_pointer); + int AcquisitionFinished(double currentProgress, int detectorStatus); + static int GetMeasurementFinishedCallBack(int currentMeasurementIndex, int fileIndex, void *this_pointer); + int MeasurementFinished(int currentMeasurementIndex, int fileIndex); + static int GetProgressCallBack(double currentProgress, void *this_pointer); + void toDoublePixelData(double *dest, char *source, int size, int databytes, int dr, double *gaindest = NULL); + + static const int NUM_PEDESTAL_FRAMES = 20; + multiSlsDetector *myDet; + slsDetectorDefs::detectorType detType; + + SlsQt1DPlot *plot1d{nullptr}; + QVector hists1d; + SlsQt2DPlotLayout *plot2d{nullptr}; + SlsQt2DPlotLayout *gainplot2d{nullptr}; + + QGridLayout *layout{nullptr}; + QGroupBox *boxPlot{nullptr}; + QGridLayout *plotLayout{nullptr}; + + bool is1d{true}; + bool plotEnable{true}; + bool plotRequired{false};/**?? */ + bool running{false}; + int progress{0}; + volatile bool stopSignal{false}; + bool clientInitiated{false}; + + // titles + QString plotTitle{""}; + QString plotTitle_prefix{""}; + QLabel *lblFrameIndexTitle1d{nullptr}; + std::vector title1d; + std::string title2d{""}; + QString xTitle1d{"Channel Number"}; + QString yTitle1d{"Counts"}; + QString xTitle2d{"Pixel"}; + QString yTitle2d{"Pixel"}; + QString zTitle2d{"Intensity"}; + bool XYRangeChanged{false}; + double XYRangeValues[4]{0, 0, 0, 0}; + bool isXYRangeEnable[4]{false, false, false, false}; + + // data + unsigned int nHists{0}; + int histNBins{0}; + double *x1d{nullptr}; + std::vector y1d; + double *image2d{nullptr}; + + //options + bool binary{false}; + int binaryFrom{0}; + int binaryTo{0}; + int persistency0}; + int currentPersistency0}; + bool isLines{true}; + bool isMarkers{false}; + QwtSymbol *marker{nullptr}; + QwtSymbol *noMarker{nullptr}; + bool pedestal{false}; + double *pedestalVals{nullptr}; + double *tempPedestalVals{nullptr}; + int pedestalCount{0}; + bool startPedestalCal{false}; + bool accumulate{false}; + bool resetAccumulate{false}; + QWidget *widgetStatistics{nullptr}; + QLabel *lblMinDisp{nullptr}; + QLabel *lblMaxDisp{nullptr}; + QLabel *lblSumDisp{nullptr}; + bool displayStatistics{false}; + std::vector cloneWidgets; + QString fileSavePath{"/tmp"}; + QString fileSaveName{"Image"}; + double *gainImage{nullptr}; + bool gainDataExtracted{false}; + bool gainDataEnable{false}; + + unsigned int nPixelsX{0}; + unsigned int nPixelsY{0}; + double minPixelsY{0}; + double maxPixelsY{0}; + double startPixel{0}; + double endPixel{0}; + double pixelWidth{0}; + + int currentMeasurement{0}; + int currentFrame{0}; + int currentFileIndex{0}; + int currentFrameIndex{0}; + pthread_mutex_t lastImageCompleteMutex; + unsigned int lastImageNumber{0}; + int numberofFrames{0}; + double acquisitionPeriod{0}; + double exposureTime{0}; + + /** prevents err msg displaying twice when detector stopped, "transmitting" + */ + bool alreadyDisplayed{false}; + + const static int npixelsx_jctb = 400; + int npixelsy_jctb{0}; }; diff --git a/slsDetectorGui/include/qTabPlot.h b/slsDetectorGui/include/qTabPlot.h index d21726351..24b19010f 100755 --- a/slsDetectorGui/include/qTabPlot.h +++ b/slsDetectorGui/include/qTabPlot.h @@ -56,7 +56,6 @@ private: bool isOneD; QButtonGroup *btnGroupPlotType; - /** interval between plots */ QStackedLayout *stackedLayout; QSpinBox *spinNthFrame; QDoubleSpinBox *spinTimeGap; diff --git a/slsDetectorGui/src/qCloneWidget.cpp b/slsDetectorGui/src/qCloneWidget.cpp index a948ff89b..fd3ea55b0 100755 --- a/slsDetectorGui/src/qCloneWidget.cpp +++ b/slsDetectorGui/src/qCloneWidget.cpp @@ -23,7 +23,9 @@ #include qCloneWidget::qCloneWidget(QWidget *parent, int id, QString title, QString xTitle, QString yTitle, QString zTitle, - int numDim, std::string FilePath, bool displayStats, QString min, QString max, QString sum) : QMainWindow(parent), id(id), filePath(FilePath), cloneplot1D(0), cloneplot2D(0) { + int numDim, std::string FilePath, bool displayStats, QString min, QString max, QString sum) : + QMainWindow(parent), id(id), filePath(FilePath), cloneplot1D(nullptr), cloneplot2D(nullptr), + marker(nullptr), nomarker(nullptr), mainLayout(nullptr), cloneBox(nullptr), lblHistTitle(nullptr) { // Window title char winTitle[300], currTime[50]; strcpy(currTime, GetCurrentTimeStamp()); @@ -41,10 +43,21 @@ qCloneWidget::qCloneWidget(QWidget *parent, int id, QString title, QString xTitl } qCloneWidget::~qCloneWidget() { - delete cloneplot1D; - delete cloneplot2D; - delete cloneBox; - cloneplot1D_hists.clear(); + if (cloneplot1D) + delete cloneplot1D; + if (cloneplot2D) + delete cloneplot2D; + cloneplot1D_hists.clear(); + if (marker) + delete marker; + if (nomarker) + delete nomarker; + if (mainLayout) + delete mainLayout; + if (cloneBox) + delete cloneBox; + if (lblHistTitle) + delete lblHistTitle; } SlsQt1DPlot* qCloneWidget::Get1dPlot() { @@ -110,7 +123,7 @@ void qCloneWidget::SetupWidgetWindow(QString title, QString xTitle, QString yTit resize(500, 350); } -void qCloneWidget::SetCloneHists(int nHists, int histNBins, double *histXAxis, double *histYAxis[], std::string histTitle[], bool lines, bool markers) { +void qCloneWidget::SetCloneHists(int nHists, int histNBins, double *histXAxis, std::vector histYAxis, std::vector histTitle, bool lines, bool markers) { //for each plot, create hists for (int hist_num = 0; hist_num < nHists; ++hist_num) { SlsQtH1D *k; @@ -146,45 +159,6 @@ void qCloneWidget::SetCloneHists(int nHists, int histNBins, double *histXAxis, d } } -void qCloneWidget::SetCloneHists(int nHists, int histNBins, double *histXAxis, double *histYAxis, std::string histTitle[], bool lines, bool markers) { - // for each plot create hists - for (int hist_num = 0; hist_num < nHists; ++hist_num) { - SlsQtH1D *k; - if (hist_num + 1 > cloneplot1D_hists.size()) { - cloneplot1D_hists.append(k = new SlsQtH1D("1d plot", histNBins, histXAxis, histYAxis)); - k->SetLineColor(hist_num + 1); - } else { - k = cloneplot1D_hists.at(hist_num); - k->SetData(histNBins, histXAxis, histYAxis); - } - //style of plot - if (lines) - k->setStyle(QwtPlotCurve::Lines); - else - k->setStyle(QwtPlotCurve::Dots); - if (markers) { - QwtSymbol *marker = new QwtSymbol(); - marker->setStyle(QwtSymbol::Cross); - marker->setSize(5, 5); -#if QWT_VERSION < 0x060000 - k->setSymbol(*marker); -#else - k->setSymbol(marker); -#endif - } else { - QwtSymbol *noMarker = new QwtSymbol(); -#if QWT_VERSION < 0x060000 - k->setSymbol(*noMarker); -#else - k->setSymbol(noMarker); -#endif - } - //set title and attach plot - lblHistTitle->setText(QString(histTitle[0].c_str())); - k->Attach(cloneplot1D); - } -} - void qCloneWidget::SetCloneHists2D(int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, double *d) { cloneplot2D->GetPlot()->SetData(nbinsx, xmin, xmax, nbinsy, ymin, ymax, d); cloneplot2D->KeepZRangeIfSet(); diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index 595ae5d3f..f2724ee7b 100755 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -1,16 +1,11 @@ - #include "qDrawPlot.h" - -#include "detectorData.h" #include "SlsQt1DPlot.h" #include "SlsQt2DPlotLayout.h" +#include "detectorData.h" #include "qCloneWidget.h" - - - - +/* #include #include #include @@ -22,234 +17,148 @@ #include #include #include +*/ - - - - -qDrawPlot::qDrawPlot(QWidget *parent, multiSlsDetector *detector) : QWidget(parent), myDet(detector), plot1DHists(0) { +qDrawPlot::qDrawPlot(QWidget *parent, multiSlsDetector *detector) + : QWidget(parent), myDet(detector) { SetupWidgetWindow(); - Initialization(); - StartStopDaqToggle(); //as default } - - qDrawPlot::~qDrawPlot() { - // Clear plot + Clear1DPlot(); - for (QVector::iterator h = plot1DHists.begin(); h != plot1DHists.end(); ++h) + for (QVector::iterator h = hists1d.begin(); + h != hists1d.end(); ++h) delete *h; - plot1DHists.clear(); - if (lastImageArray) - delete[] lastImageArray; - lastImageArray = 0; - if (gainImageArray) - delete[] gainImageArray; - gainImageArray = 0; + hists1d.clear(); + if (x1d) + delete [] x1d; + for (auto &it : y1d) + delete [] it; + if (plot1d) + delete plot1d; + + if (image2d) + delete [] image2d; + if (plot2d) + delete plot2d; + + if (gainImage) + delete [] gainImage; + if (gainplot2d) + delete gainplot2d; + + if (pedestalVals) + delete [] pedestalVals; + if (tempPedestalVals) + delete [] tempPedestalVals; + StartOrStopThread(0); - delete myDet; - myDet = 0; - for (int i = 0; i < MAXCloneWindows; ++i) - if (cloneWidgets[i]) { - delete cloneWidgets[i]; - cloneWidgets[i] = NULL; - } + + for (auto &it : cloneWidgets) { + delete it; + } + + if (lblFrameIndexTitle1d) + delete lblFrameIndexTitle1d; + if (boxPlot) + delete boxPlot; + if (layout) + delete layout; + if (plotLayout) + delete plotLayout; + if (marker) + delete marker; + if (noMarker) + delete noMarker; + if (widgetStatistics) + delete widgetStatistics; + if (lblMinDisp) + delete lblMinDisp; + if (lblMaxDisp) + delete lblMaxDisp; + if (lblSumDisp) + delete lblSumDisp; } - - void qDrawPlot::SetupWidgetWindow() { -#ifdef VERBOSE - std::cout << "Setting up plot variables\n"; -#endif - // Depending on whether the detector is 1d or 2d detType = myDet->getDetectorTypeAsEnum(); - switch (detType) { - case slsDetectorDefs::GOTTHARD: - originally2D = false; - break; - case slsDetectorDefs::EIGER: - case slsDetectorDefs::MOENCH: - case slsDetectorDefs::JUNGFRAU: - originally2D = true; - break; - default: - std::cout << "ERROR: Detector Type is Generic\n"; - exit(-1); - } + pthread_mutex_init(&lastImageCompleteMutex, NULL); - //initialization - data_pause_over = true; - - currentMeasurement = 0; - currentFrame = 0; - - currentScanDivLevel = 0; - currentScanValue = 0; - number_of_exposures = 0; - numberofFrames = 0; - acquisitionPeriod = 0; - exposureTime = 0; - currentFileIndex = 0; - currentFrameIndex = 0; - - stopSignal = 0; - pthread_mutex_init(&last_image_complete_mutex, NULL); - - // Default titles- only for the initial picture - imageXAxisTitle = "Pixel"; - imageYAxisTitle = "Pixel"; - imageZAxisTitle = "Intensity"; - histXAxisTitle = "Channel Number"; - histYAxisTitle = "Counts"; - for (int i = 0; i < MAX_1DPLOTS; ++i) { - histTitle[i] = ""; - //char temp_title[2000]; - //sprintf(temp_title,"Frame -%d",i); - //histTitle[i] = temp_title; - } - imageTitle = ""; - plotTitle = ""; - plotTitle_prefix = ""; - plot_in_scope = 0; - - nPixelsX = myDet->getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::X); - nPixelsY = myDet->getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::Y); - if (detType == slsDetectorDefs::MOENCH) { - npixelsy_jctb = (myDet->setTimer(slsDetectorDefs::SAMPLES, -1) * 2) / 25; // for moench 03 - nPixelsX = npixelsx_jctb; - nPixelsY = npixelsy_jctb; - } - - std::cout << "nPixelsX:" << nPixelsX << '\n'; - std::cout << "nPixelsY:" << nPixelsY << '\n'; - - nAnglePixelsX = 1; - minPixelsY = 0; - maxPixelsY = 0; - startPixel = -0.5; - endPixel = nPixelsY - 0.5; - pixelWidth = 0; - - lastImageNumber = 0; - - nHists = 0; - histNBins = 0; - histXAxis = 0; - for (int i = 0; i < MAX_1DPLOTS; ++i) - histYAxis[i] = 0; - histXAngleAxis = 0; - histYAngleAxis = 0; - histTrimbits = 0; - lastImageArray = 0; - gainImageArray = 0; - - persistency = 0; - currentPersistency = 0; - progress = 0; - plotEnable = true; - - //marker - lines = true; - markers = false; - marker = new QwtSymbol(); - marker->setStyle(QwtSymbol::Cross); - marker->setSize(5, 5); - noMarker = new QwtSymbol(); - - //for save automatically, - saveAll = false; - saveError = false; - lastSavedFrame = -1; - lastSavedMeasurement = -1; - - // This is so that it initially stop and plots - running = 1; - - XYRangeChanged = false; - XYRangeValues[0] = 0; - XYRangeValues[1] = 0; - XYRangeValues[2] = 0; - XYRangeValues[3] = 0; - IsXYRange[0] = false; - IsXYRange[1] = false; - IsXYRange[2] = false; - IsXYRange[3] = false; - - - isFrameEnabled = false; - isTriggerEnabled = false; - - scanArgument = qDefs::None; - histogramArgument = qDefs::Intensity; - anglePlot = false; - alreadyDisplayed = false; - - //filepath and file name - filePath = QString(myDet->getFilePath().c_str()); - fileName = QString(myDet->getFileName().c_str()); - - backwardScanPlot = false; - fileSaveEnable = myDet->enableWriteToFile(); - - //pedestal - pedestal = false; - pedestalVals = 0; - tempPedestalVals = 0; - pedestalCount = 0; - startPedestalCal = false; - - //accumulate - accumulate = false; - resetAccumulate = false; - - clientInitiated = false; - - //binary plot output - binary = false; - binaryFrom = 0; - binaryTo = 0; - - //histogram - histogram = false; - histFrom = 0; - histTo = 0; - histSize = 0; - /* - grid = new QwtPlotGrid; - grid->enableXMin(true); - grid->enableYMin(true); - grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine)); - grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); - */ - plotHistogram = new QwtPlotHistogram(); - plotHistogram->setStyle(QwtPlotHistogram::Columns); //Options:Outline,Columns, Lines - - plotRequired = false; - - //widget related initialization - - // clone - for (int i = 0; i < MAXCloneWindows; ++i) - cloneWidgets[i] = 0; - - // Setting up window + // layout setFont(QFont("Sans Serif", 9)); layout = new QGridLayout; this->setLayout(layout); - - histFrameIndexTitle = new QLabel(""); - histFrameIndexTitle->setFixedHeight(10); boxPlot = new QGroupBox(""); layout->addWidget(boxPlot, 1, 0); boxPlot->setAlignment(Qt::AlignHCenter); boxPlot->setFont(QFont("Sans Serif", 11, QFont::Normal)); boxPlot->setTitle("Sample Plot"); - //display statistics - displayStatistics = false; + // frame index 1d + lblFrameIndexTitle1d = new QLabel(""); + lblFrameIndexTitle1d->setFixedHeight(10); + + // marker + marker = new QwtSymbol(); + marker->setStyle(QwtSymbol::Cross); + marker->setSize(5, 5); + noMarker = new QwtSymbol(); + + // save + try { + std::string temp = myDet->getFilePath(); + fileSavePath = QString(temp.c_str()); + temp = myDet->getFileName(); + fileSaveName = QString(temp.c_str()); + } const sls::NonCriticalError &e) { + qDefs::ExceptionMessage("Could not get file path or file name.", e.what(), "qDrawPlot::SetupWidgetWindow"); + fileSavePath = "/tmp"; + fileSaveName = "Image"; + } + + SetupStatistics(); + + nPixelsX = myDet->getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::X); + nPixelsY = myDet->getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::Y); + if (detType == slsDetectorDefs::MOENCH) { + npixelsy_jctb = (myDet->setTimer(slsDetectorDefs::SAMPLES, -1) * 2) / + 25; // for moench 03 + nPixelsX = npixelsx_jctb; + nPixelsY = npixelsy_jctb; + } + std::cout << "nPixelsX:" << nPixelsX << '\n'; + std::cout << "nPixelsY:" << nPixelsY << '\n'; + startPixel = -0.5; + endPixel = nPixelsY - 0.5; + + SetupPlots(); + SetDataCallBack(true); + + // other call backs + myDet->registerAcquisitionFinishedCallback( + &(GetAcquisitionFinishedCallBack), this); + myDet->registerMeasurementFinishedCallback( + &(GetMeasurementFinishedCallBack), this); + myDet->registerProgressCallback(&(GetProgressCallBack), this); + + Initialization(); + StartStopDaqToggle(); +} + +void qDrawPlot::Initialization() { + connect(this, SIGNAL(UpdatePlotSignal()), this, SLOT(UpdatePlot())); + connect(this, SIGNAL(InterpolateSignal(bool)), plot2d, SIGNAL(InterpolateSignal(bool))); + connect(this, SIGNAL(ContourSignal(bool)), plot2d, SIGNAL(ContourSignal(bool))); + connect(this, SIGNAL(LogzSignal(bool)), plot2d, SIGNAL(LogzSignal(bool)))); + connect(this, SIGNAL(LogySignal(bool)), plot1d, SLOT(SetLogY(bool))); + connect(this, SIGNAL(ResetZMinZMaxSignal(bool, bool, double, double)), plot2d, SLOT(SetZRange(bool, bool, double, double))); + connect(this, SIGNAL(AcquisitionErrorSignal(QString)), this, SLOT(ShowAcquisitionErrorMessage(QString))); + connect(this, SIGNAL(GainPlotSignal(bool)), this, SLOT(EnableGainPlot(bool))); +} + +void qDrawPlot::SetupStatistics() { widgetStatistics = new QWidget(this); widgetStatistics->setFixedHeight(15); QHBoxLayout *hl1 = new QHBoxLayout; @@ -284,254 +193,636 @@ void qDrawPlot::SetupWidgetWindow() { widgetStatistics->setLayout(hl1); layout->addWidget(widgetStatistics, 2, 0); widgetStatistics->hide(); +} - // setting default plot titles and settings - plot1D = new SlsQt1DPlot(boxPlot); +void qDrawPlot::SetupPlots() { + plot1d = new SlsQt1DPlot(boxPlot); + plot1d->setFont(QFont("Sans Serif", 9, QFont::Normal)); + plot1d->SetXTitle(xTitle1d.toAscii().constData()); + plot1d->SetYTitle(yTitle1d.toAscii().constData()); + plot1d->hide(); - plot1D->setFont(QFont("Sans Serif", 9, QFont::Normal)); - plot1D->SetXTitle(histXAxisTitle.toAscii().constData()); - plot1D->SetYTitle(histYAxisTitle.toAscii().constData()); - plot1D->hide(); - - SlsQtH1D *h; histNBins = nPixelsX; nHists = 1; - if (histXAxis) - delete[] histXAxis; - histXAxis = new double[nPixelsX]; - if (histYAxis[0]) - delete[] histYAxis[0]; - histYAxis[0] = new double[nPixelsX]; + if (x1d) + delete[] x1d; + x1d = new double[nPixelsX]; + for (auto &it : y1d) { + delete[] it; + } + if (y1d.size()) { + y1d.clear(); + title1d.clear(); + } + y1d.push_back(new double[nPixelsX]); + title1d.push_back(""); + for (unsigned int px = 0; px < nPixelsX; ++px) { - histXAxis[px] = px; - histYAxis[0][px] = 0; + x1d[px] = px; + y1d[0][px] = 0; } Clear1DPlot(); - plot1D->SetXTitle("X Axis"); - plot1D->SetYTitle("Y Axis"); - plot1DHists.append(h = new SlsQtH1D("", histNBins, histXAxis, histYAxis[0])); + plot1d->SetXTitle("X Axis"); + plot1d->SetYTitle("Y Axis"); + + SlsQtH1D *h; + hists1d.append(h = new SlsQtH1D("", histNBins, x1d, y1d[0])); h->SetLineColor(0); SetStyle(h); - h->Attach(plot1D); + h->Attach(plot1d); Clear1DPlot(); - plot2D = new SlsQt2DPlotLayout(boxPlot); - //default plot - lastImageArray = new double[nPixelsY * nPixelsX]; + plot2d = new SlsQt2DPlotLayout(boxPlot); + // default plot + image2d = new double[nPixelsY * nPixelsX]; for (unsigned int px = 0; px < nPixelsX; ++px) for (unsigned int py = 0; py < nPixelsY; ++py) - lastImageArray[py * nPixelsX + px] = sqrt(pow(0 + 1, 2) * pow(double(px) - nPixelsX / 2, 2) / pow(nPixelsX / 2, 2) / pow(1 + 1, 2) + pow(double(py) - nPixelsY / 2, 2) / pow(nPixelsY / 2, 2)) / sqrt(2); - plot2D->setFont(QFont("Sans Serif", 9, QFont::Normal)); - plot2D->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, startPixel, endPixel, lastImageArray); - plot2D->setTitle(GetImageTitle()); - plot2D->SetXTitle(imageXAxisTitle); - plot2D->SetYTitle(imageYAxisTitle); - plot2D->SetZTitle(imageZAxisTitle); - plot2D->setAlignment(Qt::AlignLeft); + image2d[py * nPixelsX + px] = + sqrt(pow(0 + 1, 2) * pow(double(px) - nPixelsX / 2, 2) / + pow(nPixelsX / 2, 2) / pow(1 + 1, 2) + + pow(double(py) - nPixelsY / 2, 2) / pow(nPixelsY / 2, 2)) / + sqrt(2); + plot2d->setFont(QFont("Sans Serif", 9, QFont::Normal)); + plot2d->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, + startPixel, endPixel, image2d); + plot2d->setTitle(title2d.c_str()); + plot2d->SetXTitle(xTitle2d); + plot2d->SetYTitle(yTitle2d); + plot2d->SetZTitle(zTitle2d); + plot2d->setAlignment(Qt::AlignLeft); boxPlot->setFlat(true); boxPlot->setContentsMargins(0, 15, 0, 0); plotLayout = new QGridLayout(boxPlot); plotLayout->setContentsMargins(0, 0, 0, 0); - plotLayout->addWidget(plot1D, 0, 0, 4, 4); - plotLayout->addWidget(plot2D, 0, 0, 4, 4); + plotLayout->addWidget(plot1d, 0, 0, 4, 4); + plotLayout->addWidget(plot2d, 0, 0, 4, 4); - //gainplot - gainplot2D = new SlsQt2DPlotLayout(boxPlot); - gainImageArray = new double[nPixelsY * nPixelsX]; + // gainplot + gainplot2d = new SlsQt2DPlotLayout(boxPlot); + gainImage = new double[nPixelsY * nPixelsX]; for (unsigned int px = 0; px < nPixelsX; ++px) for (unsigned int py = 0; py < nPixelsY; ++py) - gainImageArray[py * nPixelsX + px] = sqrt(pow(0 + 1, 2) * pow(double(px) - nPixelsX / 2, 2) / pow(nPixelsX / 2, 2) / pow(1 + 1, 2) + pow(double(py) - nPixelsY / 2, 2) / pow(nPixelsY / 2, 2)) / sqrt(2); - gainplot2D->setFont(QFont("Sans Serif", 9, QFont::Normal)); - gainplot2D->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, startPixel, endPixel, gainImageArray); - gainplot2D->setTitle(GetImageTitle()); - gainplot2D->setAlignment(Qt::AlignLeft); - gainplot2D->GetPlot()->enableAxis(0, false); - gainplot2D->GetPlot()->enableAxis(1, false); - gainplot2D->GetPlot()->enableAxis(2, false); - plotLayout->addWidget(gainplot2D, 0, 4, 1, 1); - gainplot2D->hide(); - gainPlotEnable = false; - gainDataEnable = false; - - // callbacks - SetCallBacks(true); - //Setting the callback function to alert when acquisition finished from detector class - myDet->registerAcquisitionFinishedCallback(&(GetAcquisitionFinishedCallBack), this); - //Setting the callback function to alert when each measurement finished from detector class - myDet->registerMeasurementFinishedCallback(&(GetMeasurementFinishedCallBack), this); - //Setting the callback function to get progress from detector class(using receivers) - myDet->registerProgressCallback(&(GetProgressCallBack), this); - - qDefs::checkErrorMessage(myDet, "qDrawPlot::SetupWidgetWindow"); + gainImage[py * nPixelsX + px] = + sqrt(pow(0 + 1, 2) * pow(double(px) - nPixelsX / 2, 2) / + pow(nPixelsX / 2, 2) / pow(1 + 1, 2) + + pow(double(py) - nPixelsY / 2, 2) / pow(nPixelsY / 2, 2)) / + sqrt(2); + gainplot2d->setFont(QFont("Sans Serif", 9, QFont::Normal)); + gainplot2d->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, + startPixel, endPixel, gainImage); + gainplot2d->setTitle(title2d.c_str()); + gainplot2d->setAlignment(Qt::AlignLeft); + gainplot2d->GetPlot()->enableAxis(0, false); + gainplot2d->GetPlot()->enableAxis(1, false); + gainplot2d->GetPlot()->enableAxis(2, false); + plotLayout->addWidget(gainplot2d, 0, 4, 1, 1); + gainplot2d->hide(); } - -void qDrawPlot::Initialization() { - connect(this, SIGNAL(UpdatePlotSignal()), this, SLOT(UpdatePlot())); - connect(this, SIGNAL(InterpolateSignal(bool)), plot2D, SIGNAL(InterpolateSignal(bool))); - connect(this, SIGNAL(ContourSignal(bool)), plot2D, SIGNAL(ContourSignal(bool))); - connect(this, SIGNAL(LogzSignal(bool)), plot2D, SIGNAL(LogzSignal(bool)))); - connect(this, SIGNAL(LogySignal(bool)), plot1D, SLOT(SetLogY(bool))); - connect(this, SIGNAL(ResetZMinZMaxSignal(bool, bool, double, double)), plot2D, SLOT(SetZRange(bool, bool, double, double))); - - connect(this, SIGNAL(AcquisitionErrorSignal(QString)), this, SLOT(ShowAcquisitionErrorMessage(QString))); - - connect(this, SIGNAL(GainPlotSignal(bool)), this, SLOT(EnableGainPlot(bool))); +void qDrawPlot::SetClientInitiated() { + clientInitiated = true; } +bool qDrawPlot::GetClientInitiated() { + return clientInitiated; +} - bool qDrawPlot::isRunning(){return running;}; +void qDrawPlot::StopAcquisition() { stopSignal = true; }; - int qDrawPlot::GetProgress(){return progress;}; +bool qDrawPlot::isRunning() { + return running; +} - int qDrawPlot::GetFileIndex(){return currentFileIndex;}; +int qDrawPlot::GetProgress() { + return progress; +} - int qDrawPlot::GetFrameIndex(){return currentFrameIndex;}; - void qDrawPlot::SetFileWrite(bool enable){fileSaveEnable = enable;}; +int qDrawPlot::GetCurrentFrameIndex() { + return currentFrameIndex; +} - void qDrawPlot::SetPlotTitlePrefix(QString title) {plotTitle_prefix = title;} - - void qDrawPlot::SetXAxisTitle(QString title) { - if(plot_in_scope==1) { - histXAxisTitle = title; - } else { - imageXAxisTitle = title; - } - } +void qDrawPlot::SetPlotTitlePrefix(QString title) { + plotTitle_prefix = title; +} - void qDrawPlot::SetYAxisTitle(QString title) { - if(plot_in_scope==1) { - histYAxisTitle = title; - } else { - imageYAxisTitle = title; - } - } +void qDrawPlot::SetXAxisTitle(QString title) { + if (is1d) { + xTitle1d = title; + } else { + xTitle2d = title; + } +} - void qDrawPlot::SetZAxisTitle(QString title) {imageZAxisTitle = title;} +void qDrawPlot::SetYAxisTitle(QString title) { + if (is1d) { + yTitle1d = title; + } else { + yTitle2d = title; + } +} +void qDrawPlot::SetZAxisTitle(QString title) { + zTitle2d = title; +} - void qDrawPlot::EnableAnglePlot(bool enable){anglePlot = enable;}; +void qDrawPlot::DisableZoom(bool disable) { + if (is1d) + plot1d->DisableZoom(disable); + else + plot2d->GetPlot()->DisableZoom(disable); +} - void qDrawPlot::SetXYRange(bool changed){XYRangeChanged = changed;}; +void qDrawPlot::SetXYRange(bool changed) { + XYRangeChanged = changed; +} - void qDrawPlot::SetXYRangeValues(double val,qDefs::range xy){XYRangeValues[xy]=val;}; +void qDrawPlot::SetXYRangeValues(double val, qDefs::range xy) { + XYRangeValues[xy] = val; +} - void qDrawPlot::IsXYRangeValues(bool changed,qDefs::range xy){IsXYRange[xy]=changed;}; - - void qDrawPlot::setFrameEnabled(bool enable){isFrameEnabled = enable;}; +void qDrawPlot::IsXYRangeValues(bool changed, qDefs::range xy) { + isXYRangeEnable[xy] = changed; +} - void qDrawPlot::setTriggerEnabled(bool enable){isTriggerEnabled = enable;}; +double qDrawPlot::GetXMinimum() { + if (is1d) + return plot1d->GetXMinimum(); + else + return plot2d->GetPlot()->GetXMinimum(); +} - void qDrawPlot::SetClientInitiated(){clientInitiated = true;}; - bool qDrawPlot::GetClientInitiated(){return clientInitiated;}; - double qDrawPlot::GetXMinimum() { if(plot_in_scope==1) return plot1D->GetXMinimum(); else return plot2D->GetPlot()->GetXMinimum();}; +double qDrawPlot::GetXMaximum() { + if (is1d) + return plot1d->GetXMaximum(); + else + return plot2d->GetPlot()->GetXMaximum(); +} - double qDrawPlot::GetXMaximum() { if(plot_in_scope==1) return plot1D->GetXMaximum(); else return plot2D->GetPlot()->GetXMaximum();}; - - double qDrawPlot::GetYMinimum() { if(plot_in_scope==1) return plot1D->GetYMinimum(); else return plot2D->GetPlot()->GetYMinimum();}; - - double qDrawPlot::GetYMaximum() { if(plot_in_scope==1) return plot1D->GetYMaximum(); else return plot2D->GetPlot()->GetYMaximum();}; +double qDrawPlot::GetYMinimum() { + if (is1d) + return plot1d->GetYMinimum(); + else + return plot2d->GetPlot()->GetYMinimum(); +} - void qDrawPlot::Select1DPlot() {SelectPlot(1);} - void qDrawPlot::Select2DPlot() {SelectPlot(2);} +double qDrawPlot::GetYMaximum() { + if (is1d) + return plot1d->GetYMaximum(); + else + return plot2d->GetPlot()->GetYMaximum(); +} -void qDrawPlot::SaveAll(bool enable){saveAll = enable;}; +const char *qDrawPlot::GetTitle1d(int histIndex) { + return (histIndex >= 0 && histIndex < title1d.size()) ? title1d[histIndex].c_str() : 0; +} -void qDrawPlot::SetLines(bool enable){lines = enable;}; +double *qDrawPlot::GetHistYAxis(int histIndex) { + return (histIndex >= 0 && histIndex < y1d.size()) ? y1d[histIndex] : 0; +} -void qDrawPlot::SetMarkers(bool enable){markers = enable;}; -void qDrawPlot::StopAcquisition(){ stopSignal = true; }; - - -const char* qDrawPlot::GetImageTitle() {return imageTitle.c_str();} - -const char* qDrawPlot::GetHistTitle(int i) {return (i>=0&&i=0&&isetStyle(QwtPlotCurve::Lines); else h->setStyle(QwtPlotCurve::Dots); -#if QWT_VERSION<0x060000 - if(markers) h->setSymbol(*marker); else h->setSymbol(*noMarker); -#else - if(markers) h->setSymbol(marker); else h->setSymbol(noMarker); -#endif -}; - -void qDrawPlot::UpdatePause(){data_pause_over=true;}; - -void qDrawPlot::SetCallBacks(bool enable) { +void qDrawPlot::SetDataCallBack(bool enable) { if (enable) { - // Setting the callback function to get data from detector class - myDet->registerDataCallback(&(GetDataCallBack), this); // also enables data streaming in client and receiver (if receiver exists) + myDet->registerDataCallback(&(GetDataCallBack), this); } else { myDet->registerDataCallback(nullptr, this); } } +void qDrawPlot::SetBinary(bool enable, int from, int to) { + FILE_LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Binary output from " << from << " to " << to; + binary = enable; + binaryFrom = from; + binaryTo = to; +} + +void qDrawPlot::SetPersistency(int val) { + for (int i = y1d.size(); i <= val; ++i) + y1d.push_back(new double[nPixelsX]); + persistency = val; +} + +void qDrawPlot::SetLines(bool enable) { + isLines = enable; +} + +void qDrawPlot::SetMarkers(bool enable) { + isMarkers = enable; +} + +void qDrawPlot::SetStyle(SlsQtH1D *h) { + if (isLines) + h->setStyle(QwtPlotCurve::isLines); + else + h->setStyle(QwtPlotCurve::Dots); +#if QWT_VERSION < 0x060000 + if (isMarkers) + h->setSymbol(*marker); + else + h->setSymbol(*noMarker); +#else + if (isMarkers) + h->setSymbol(marker); + else + h->setSymbol(noMarker); +#endif +} + +void qDrawPlot::SetPedestal(bool enable) { + FILE_LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Pedestal"; + LockLastImageArray(); + if (enable) { + isPedestal = true; + if (pedestalVals == nullptr) + RecalculatePedestal(); + } else { + isPedestal = false; + } + UnlockLastImageArray(); +} + +void qDrawPlot::RecalculatePedestal() { + FILE_LOG(logDEBUG) << "Recalculating Pedestal"; + LockLastImageArray(); + startPedestalCal = true; + pedestalCount = 0; + + if (pedestalVals != nullptr) + delete [] pedestalVals; + int nPixels = nPixelsX * nPixelsY; + pedestalVals = new double[nPixels]; + std::fill(pedestalVals, pedestalVals + nPixels, 0); + + if (tempPedestalVals != nullptr) + delete [] tempPedestalVals; + tempPedestalVals = new double[nPixels]; + std::fill(tempPedestalVals, tempPedestalVals + nPixels, 0); + UnlockLastImageArray(); +} + +void qDrawPlot::SetAccumulate(bool enable) { + FILE_LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Accumulation"; + LockLastImageArray(); + accumulate = enable; + UnlockLastImageArray(); +} + +void qDrawPlot::ResetAccumulate() { + FILE_LOG(logDEBUG) << "Resetting Accumulation"; + LockLastImageArray(); + resetAccumulate = true; + UnlockLastImageArray(); +} + +void qDrawPlot::DisplayStatistics(bool enable) { + FILE_LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Statistics Display"; + LockLastImageArray(); + if (!enable) + widgetStatistics->hide(); + // shown when calculated + displayStatistics = enable; + lblMinDisp->setText("-"); + lblMaxDisp->setText("-"); + lblSumDisp->setText("-"); + UnlockLastImageArray(); +} + +void qDrawPlot::GetStatistics(double &min, double &max, double &sum, double *array, int size) { + FILE_LOG(logDEBUG) << "Calculating Statistics"; + for (int i = 0; i < size; ++i) { + if (array[i] < min) + min = array[i]; + if (array[i] > max) + max = array[i]; + sum += array[i]; + } +} + + + + + + + + + + + + + +void qDrawPlot::ClonePlot() { + int i = cloneWidgets.size(); + + // get file path while acquisition runnign without accessing shared memory + std::string sFilePath; + if (running) + sFilePath = fileSavePath.toAscii().constData(); + else { + sFilePath = myDet->getFilePath(); + qDefs::checkErrorMessage(myDet, "qDrawPlot::ClonePlot"); + } + + LockLastImageArray(); + + // create clone & copy data + if (is1d) { + qCloneWidget *q = new qCloneWidget( + this, i, boxPlot->title(), xTitle1d, yTitle1d, "", (is1d ? 1 : 2), + sFilePath, displayStatistics, lblMinDisp->text(), + lblMaxDisp->text(), lblSumDisp->text()); + cloneWidgets.push_back(q); + cloneWidgets[i]->SetCloneHists((int)nHists, histNBins, x1d, y1d, + title1d, isLines, isMarkers); + + } else { + qCloneWidget *q = new qCloneWidget( + this, i, boxPlot->title(), xTitle2d, yTitle2d, zTitle2d, + (is1d ? 1 : 2), sFilePath, displayStatistics, lblMinDisp->text(), + lblMaxDisp->text(), lblSumDisp->text()); + cloneWidgets.push_back(q); + cloneWidgets[i]->SetCloneHists2D(nPixelsX, -0.5, nPixelsX - 0.5, + nPixelsY, startPixel, endPixel, + image2d); + } + + // update range + found = false; + for (int index = 0; index < 4; ++index) + if (isXYRangeEnable[index]) { + found = true; + break; + } + if (found) + cloneWidgets[i]->SetRange(isXYRangeEnable, XYRangeValues); + + UnlockLastImageArray(); + + cloneWidgets[i]->show(); + + // to remember which all clone widgets were closed + connect(cloneWidgets[i], SIGNAL(CloneClosedSignal(int)), this, + SLOT(CloneCloseEvent(int))); +} + +void qDrawPlot::CloseClones() { + for (auto &it : cloneWidgets) { + it->close(); + } + + void qDrawPlot::CloneCloseEvent(int id) { + cloneWidgets.erase(cloneWidgets.begin() + id; +#ifdef VERBOSE + std::cout << "Closing Clone Window id:" << id << '\n'; +#endif + } + +void qDrawPlot::SaveClones() { + char errID[200]; + std::string errMessage = "The Snapshots with ID's: "; + bool success = true; + for (int i = 0; i < cloneWidgets.size(); ++i) { + if (cloneWidgets[i]->SavePlotAutomatic()) { + success = false; + sprintf(errID, "%d", i); + errMessage.append(std::string(errID) + std::string(", ")); + } + } + if (success) + qDefs::Message( + qDefs::INFORMATION, + "The Snapshots have all been saved successfully in .png.", "Dock"); + else + qDefs::Message(qDefs::WARNING, + errMessage + std::string("were not saved."), + "qDrawPlot::SaveClones"); +} + + + void qDrawPlot::SavePlot() { + // render image + QImage savedImage(size().width(), size().height(), + QImage::Format_RGB32); + QPainter painter(&savedImage); + render(&painter); + + QString fName; + if (running) + fName = fileSavePath; + else { + fName = QString(myDet->getFilePath().c_str()); + qDefs::checkErrorMessage(myDet, "qDrawPlot::SavePlot"); + } + + if (boxPlot->title().contains('.')) { + fName.append(QString('/') + boxPlot->title()); + fName.replace(".dat", ".png"); + fName.replace(".raw", ".png"); + } else + fName.append(QString("/Image.png")); + + fName = QFileDialog::getSaveFileName( + 0, tr("Save Image"), fName, + tr("PNG Files (*.png);;XPM Files(*.xpm);;JPEG Files(*.jpg)"), 0, + QFileDialog::ShowDirsOnly); + + if (!fName.isEmpty()) { + if (savedImage.save(fName)) + qDefs::Message(qDefs::INFORMATION, + "The Image has been successfully saved", + "qDrawPlot::SavePlot"); + else + qDefs::Message(qDefs::WARNING, + "Attempt to save image failed.\n" + "Formats: .png, .jpg, .xpm.", + "qDrawPlot::SavePlot"); + } + } + +void qDrawPlot::Select1DPlot() { SelectPlot(1); } +void qDrawPlot::Select2DPlot() { SelectPlot(2); } + +void qDrawPlot::SelectPlot(int i) { // 1 for 1D otherwise 2D + if (i == 1) { + // Clear1DPlot(); it clears the last measurement + plot1d->SetXTitle(xTitle1d.toAscii().constData()); + plot1d->SetYTitle(yTitle1d.toAscii().constData()); + plot1d->show(); + plot2d->hide(); + boxPlot->setFlat(false); + is1d = true; + layout->addWidget(lblFrameIndexTitle1d, 0, 0); + plotLayout->setContentsMargins(10, 10, 10, 10); + } else { + plot2d->SetXTitle(xTitle2d); + plot2d->SetYTitle(yTitle2d); + plot2d->SetZTitle(zTitle2d); + plot1d->hide(); + plot2d->show(); + boxPlot->setFlat(true); + is1d = false; + lblFrameIndexTitle1d->setText(""); + layout->removeWidget(lblFrameIndexTitle1d); + plotLayout->setContentsMargins(0, 0, 0, 0); + } +} + + + void qDrawPlot::EnableGainPlot(bool e) { +#ifdef VERBOSE + std::cout << "Setting Gain Data enable to " << e << '\n'; +#endif + gainDataEnable = e; + } + + void qDrawPlot::toDoublePixelData(double *dest, char *source, int size, + int databytes, int dr, double *gaindest) { + int ichan = 0; + int ibyte = 0; + int halfbyte = 0; + char cbyte = '\0'; + + switch (dr) { + + case 4: + for (ibyte = 0; ibyte < databytes; ++ibyte) { + cbyte = source[ibyte]; + for (halfbyte = 1; halfbyte >= 0; --halfbyte) { + dest[ichan] = (cbyte >> (halfbyte * 4)) & 0xf; + ++ichan; + } + } + break; + + case 8: + for (ichan = 0; ichan < databytes; ++ichan) { + dest[ichan] = *((u_int8_t *)source); + ++source; + } + break; + + case 16: + if (detType == slsDetectorDefs::JUNGFRAU || + detType == slsDetectorDefs::MOENCH) { + + // show gain plot + if (gaindest != NULL) { + for (ichan = 0; ichan < size; ++ichan) { + if ((*((u_int16_t *)source)) == 0xFFFF) { + gaindest[ichan] = 0xFFFF; + dest[ichan] = 0xFFFF; + } else { + gaindest[ichan] = + (((*((u_int16_t *)source)) & 0xC000) >> 14); + dest[ichan] = ((*((u_int16_t *)source)) & 0x3FFF); + } + source += 2; + } + } + + // only data plot + else { + for (ichan = 0; ichan < size; ++ichan) { + /*if ( (*((u_int16_t*)source)) == 0xFFFF ) + dest[ichan] = 0xFFFF; + else*/ + dest[ichan] = ((*((u_int16_t *)source)) & 0x3FFF); + source += 2; + } + } + break; + } + + // other detectors + for (ichan = 0; ichan < size; ++ichan) { + dest[ichan] = *((u_int16_t *)source); + source += 2; + } + break; + + default: + for (ichan = 0; ichan < size; ++ichan) { + dest[ichan] = *((u_int32_t *)source); + source += 4; + } + break; + } + } + + + + + + +int qDrawPlot::LockLastImageArray() { + return pthread_mutex_lock(&lastImageCompleteMutex); +} + +int qDrawPlot::UnlockLastImageArray() { + return pthread_mutex_unlock(&lastImageCompleteMutex); +} + +int qDrawPlot::StartDaqForGui() { return StartOrStopThread(1) ? 1 : 0; } + +int qDrawPlot::StopDaqForGui() { return StartOrStopThread(0) ? 0 : 1; } + void qDrawPlot::StartStopDaqToggle(bool stop_if_running) { #ifdef VERYVERBOSE std::cout << "Entering StartStopDaqToggle(" << stop_if_running << ")\n"; #endif - //static bool running = 1; - if (running) { //stopping + // static bool running = 1; + if (running) { // stopping StartDaq(false); running = !running; - } else if (!stop_if_running) { //then start + } else if (!stop_if_running) { // then start // Reset Current Measurement currentMeasurement = 0; emit SetCurrentMeasurementSignal(currentMeasurement); - data_pause_over = true; - //in case of error message + // in case of error message alreadyDisplayed = false; /* - // Number of Exposures - int numFrames = (isFrameEnabled)*((int)myDet->setTimer(slsDetectorDefs::FRAME_NUMBER,-1)); - int numTriggers = (isTriggerEnabled)*((int)myDet->setTimer(slsDetectorDefs::CYCLES_NUMBER,-1)); - numFrames = ((numFrames==0)?1:numFrames); - numTriggers = ((numTriggers==0)?1:numTriggers); - numberofFrames = numFrames * numTriggers; - std::cout << "\tNumber of Frames per Scan/Measurement:" << numberofFrames <<'\n'; - //get #scansets for level 0 and level 1 - int numScan0 = myDet->getScanSteps(0); numScan0 = ((numScan0==0)?1:numScan0); - int numScan1 = myDet->getScanSteps(1); numScan1 = ((numScan1==0)?1:numScan1); - int numPos=myDet->getPositions(); + // Number of Exposures + int numFrames = + (isFrameEnabled)*((int)myDet->setTimer(slsDetectorDefs::FRAME_NUMBER,-1)); + int numTriggers = + (isTriggerEnabled)*((int)myDet->setTimer(slsDetectorDefs::CYCLES_NUMBER,-1)); + numFrames = ((numFrames==0)?1:numFrames); + numTriggers = ((numTriggers==0)?1:numTriggers); + numberofFrames = numFrames * numTriggers; + std::cout << "\tNumber of Frames per Scan/Measurement:" << + numberofFrames <<'\n'; + //get #scansets for level 0 and level 1 + int numScan0 = myDet->getScanSteps(0); numScan0 = + ((numScan0==0)?1:numScan0); int numScan1 = myDet->getScanSteps(1); + numScan1 = ((numScan1==0)?1:numScan1); int + numPos=myDet->getPositions(); - number_of_exposures = numberofFrames * numScan0 * numScan1; - if(anglePlot) number_of_exposures = numScan0 * numScan1;// * numPos; - std::cout << "\tNumber of Exposures Per Measurement:" << number_of_exposures <<'\n'; - */ + number_of_exposures = numberofFrames * numScan0 * numScan1; + if(anglePlot) number_of_exposures = numScan0 * numScan1;// * + numPos; std::cout << "\tNumber of Exposures Per Measurement:" << + number_of_exposures <<'\n'; + */ // ExposureTime - exposureTime = ((double)(myDet->setTimer(slsDetectorDefs::ACQUISITION_TIME, -1)) * 1E-9); - std::cout << "\tExposure Time:" << std::setprecision(10) << exposureTime << '\n'; + exposureTime = + ((double)(myDet->setTimer(slsDetectorDefs::ACQUISITION_TIME, -1)) * + 1E-9); + std::cout << "\tExposure Time:" << std::setprecision(10) << exposureTime + << '\n'; // Acquisition Period - acquisitionPeriod = ((double)(myDet->setTimer(slsDetectorDefs::FRAME_PERIOD, -1)) * 1E-9); - std::cout << "\tAcquisition Period:" << std::setprecision(10) << acquisitionPeriod << '\n'; + acquisitionPeriod = + ((double)(myDet->setTimer(slsDetectorDefs::FRAME_PERIOD, -1)) * + 1E-9); + std::cout << "\tAcquisition Period:" << std::setprecision(10) + << acquisitionPeriod << '\n'; std::cout << "\tFile Index:" << myDet->getFileIndex() << '\n'; - - //for save automatically, - saveError = false; - lastSavedFrame = -1; - lastSavedMeasurement = -1; - - //update file path and file name - filePath = QString(myDet->getFilePath().c_str()); - fileName = QString(myDet->getFileName().c_str()); - //update index + // update file path and file name + fileSavePath = QString(myDet->getFilePath().c_str()); + fileSaveName = QString(myDet->getFileName().c_str()); + // update index currentFileIndex = myDet->getFileIndex(); currentFrameIndex = 0; @@ -545,8 +836,6 @@ void qDrawPlot::StartStopDaqToggle(bool stop_if_running) { clientInitiated = false; } - - void qDrawPlot::StartDaq(bool start) { if (start) { #ifdef VERBOSE @@ -562,8 +851,6 @@ void qDrawPlot::StartDaq(bool start) { } } - - int qDrawPlot::ResetDaqForGui() { if (!StopDaqForGui()) return 0; @@ -572,8 +859,6 @@ int qDrawPlot::ResetDaqForGui() { return 1; } - - bool qDrawPlot::StartOrStopThread(bool start) { #ifdef VERYVERBOSE std::cout << "StartOrStopThread:" << start << '\n'; @@ -581,40 +866,44 @@ bool qDrawPlot::StartOrStopThread(bool start) { static bool firstTime = true; static bool gui_acquisition_thread_running = 0; static pthread_t gui_acquisition_thread; - static pthread_mutex_t gui_acquisition_start_stop_mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_mutex_t gui_acquisition_start_stop_mutex = + PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&gui_acquisition_start_stop_mutex); - //stop part, before start or restart + // stop part, before start or restart if (gui_acquisition_thread_running) { std::cout << "Stopping current acquisition thread ...." << '\n'; - stopSignal = 1; //sorta useless right now + stopSignal = 1; // sorta useless right now gui_acquisition_thread_running = 0; } - //start part + // start part if (start) { progress = 0; - //sets up the measurement parameters + // sets up the measurement parameters SetupMeasurement(); - //refixing all the zooming - plot2D->GetPlot()->SetXMinMax(-0.5, nPixelsX + 0.5); - plot2D->GetPlot()->SetYMinMax(startPixel, endPixel); - plot2D->GetPlot()->SetZoom(-0.5, startPixel, nPixelsX, endPixel - startPixel); + // refixing all the zooming + plot2d->GetPlot()->SetXMinMax(-0.5, nPixelsX + 0.5); + plot2d->GetPlot()->SetYMinMax(startPixel, endPixel); + plot2d->GetPlot()->SetZoom(-0.5, startPixel, nPixelsX, + endPixel - startPixel); if (boxPlot->title() == "Sample Plot") - plot2D->GetPlot()->UnZoom(); + plot2d->GetPlot()->UnZoom(); else - plot2D->GetPlot()->UnZoom(false); + plot2d->GetPlot()->UnZoom(false); /*XYRangeChanged = true;*/ boxPlot->setTitle("Old_Plot.raw"); cprintf(BLUE, "Starting new acquisition thread ....\n"); // Start acquiring data from server if (!firstTime) - pthread_join(gui_acquisition_thread, NULL); //wait until he's finished, ie. exits - pthread_create(&gui_acquisition_thread, NULL, DataStartAcquireThread, (void *)this); - // This is set here and later reset to zero when all the plotting is done - // This is manually done instead of keeping track of thread because + pthread_join(gui_acquisition_thread, + NULL); // wait until he's finished, ie. exits + pthread_create(&gui_acquisition_thread, NULL, DataStartAcquireThread, + (void *)this); + // This is set here and later reset to zero when all the plotting is + // done This is manually done instead of keeping track of thread because // this thread returns immediately after executing the acquire command gui_acquisition_thread_running = 1; #ifdef VERYVERBOSE @@ -625,132 +914,167 @@ bool qDrawPlot::StartOrStopThread(bool start) { return gui_acquisition_thread_running; } - - -void qDrawPlot::SetScanArgument(int scanArg){ +void qDrawPlot::SetScanArgument(int scanArg) { #ifdef VERYVERBOSE - std::cout << "SetScanArgument function:" << scanArg << " running:" << running <<'\n'; + std::cout << "SetScanArgument function:" << scanArg + << " running:" << running << '\n'; #endif - scanArgument = scanArg; + scanArgument = scanArg; - LockLastImageArray(); + LockLastImageArray(); - if(plot_in_scope==1) Clear1DPlot(); + if (is1d) + Clear1DPlot(); - // Number of Exposures - must be calculated here to get npixelsy for allframes/frameindex scans - int numFrames = (isFrameEnabled)*((int)myDet->setTimer(slsDetectorDefs::FRAME_NUMBER,-1)); - int numTriggers = (isTriggerEnabled)*((int)myDet->setTimer(slsDetectorDefs::CYCLES_NUMBER,-1)); - int numStoragecells = 0; - if (detType == slsDetectorDefs::JUNGFRAU) - numStoragecells = (int)myDet->setTimer(slsDetectorDefs::STORAGE_CELL_NUMBER, -1); - numFrames = ((numFrames==0)?1:numFrames); - numTriggers = ((numTriggers==0)?1:numTriggers); - numStoragecells = ((numStoragecells<=0)?1:numStoragecells+1); - numberofFrames = numFrames * numTriggers * numStoragecells; - std::cout << "\tNumber of Frames per Scan/Measurement:" << numberofFrames <<'\n'; - //get #scansets for level 0 and level 1 - int numScan0 = myDet->getScanSteps(0); numScan0 = ((numScan0==0)?1:numScan0); - int numScan1 = myDet->getScanSteps(1); numScan1 = ((numScan1==0)?1:numScan1); - //int numPos=myDet->getPositions(); + // Number of Exposures - must be calculated here to get npixelsy for + // allframes/frameindex scans + int numFrames = (isFrameEnabled) * + ((int)myDet->setTimer(slsDetectorDefs::FRAME_NUMBER, -1)); + int numTriggers = + (isTriggerEnabled) * + ((int)myDet->setTimer(slsDetectorDefs::CYCLES_NUMBER, -1)); + int numStoragecells = 0; + if (detType == slsDetectorDefs::JUNGFRAU) + numStoragecells = + (int)myDet->setTimer(slsDetectorDefs::STORAGE_CELL_NUMBER, -1); + numFrames = ((numFrames == 0) ? 1 : numFrames); + numTriggers = ((numTriggers == 0) ? 1 : numTriggers); + numStoragecells = ((numStoragecells <= 0) ? 1 : numStoragecells + 1); + numberofFrames = numFrames * numTriggers * numStoragecells; + std::cout << "\tNumber of Frames per Scan/Measurement:" << numberofFrames + << '\n'; + // get #scansets for level 0 and level 1 + int numScan0 = myDet->getScanSteps(0); + numScan0 = ((numScan0 == 0) ? 1 : numScan0); + int numScan1 = myDet->getScanSteps(1); + numScan1 = ((numScan1 == 0) ? 1 : numScan1); + // int numPos=myDet->getPositions(); - number_of_exposures = numberofFrames * numScan0 * numScan1; - if(anglePlot) number_of_exposures = numScan0 * numScan1;// * numPos; - std::cout << "\tNumber of Exposures Per Measurement:" << number_of_exposures <<'\n'; + number_of_exposures = numberofFrames * numScan0 * numScan1; + if (anglePlot) + number_of_exposures = numScan0 * numScan1; // * numPos; + std::cout << "\tNumber of Exposures Per Measurement:" << number_of_exposures + << '\n'; - maxPixelsY = 0; - minPixelsY = 0; - nPixelsX = myDet->getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::X); - nPixelsY = myDet->getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::Y); - if (detType == slsDetectorDefs::MOENCH) { - npixelsy_jctb = (myDet->setTimer(slsDetectorDefs::SAMPLES, -1) * 2)/25; // for moench 03 - nPixelsX = npixelsx_jctb; - nPixelsY = npixelsy_jctb; - } + maxPixelsY = 0; + minPixelsY = 0; + nPixelsX = myDet->getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::X); + nPixelsY = myDet->getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::Y); + if (detType == slsDetectorDefs::MOENCH) { + npixelsy_jctb = (myDet->setTimer(slsDetectorDefs::SAMPLES, -1) * 2) / + 25; // for moench 03 + nPixelsX = npixelsx_jctb; + nPixelsY = npixelsy_jctb; + } - //cannot do this in between measurements , so update instantly - if(scanArgument==qDefs::Level0){ - //no need to check if numsteps=0,cuz otherwise this mode wont be set in plot tab - int numSteps = myDet->getScanSteps(0); - double *values = new double[numSteps]; - myDet->getScanSteps(0,values); + // cannot do this in between measurements , so update instantly + if (scanArgument == qDefs::Level0) { + // no need to check if numsteps=0,cuz otherwise this mode wont be set in + // plot tab + int numSteps = myDet->getScanSteps(0); + double *values = new double[numSteps]; + myDet->getScanSteps(0, values); - maxPixelsY = values[numSteps-1]; - minPixelsY = values[0]; - nPixelsY = numSteps; - }else if(scanArgument==qDefs::Level1) { - //no need to check if numsteps=0,cuz otherwise this mode wont be set in plot tab - int numSteps = myDet->getScanSteps(1); - double *values = new double[numSteps]; - myDet->getScanSteps(1,values); + maxPixelsY = values[numSteps - 1]; + minPixelsY = values[0]; + nPixelsY = numSteps; + } else if (scanArgument == qDefs::Level1) { + // no need to check if numsteps=0,cuz otherwise this mode wont be set in + // plot tab + int numSteps = myDet->getScanSteps(1); + double *values = new double[numSteps]; + myDet->getScanSteps(1, values); - maxPixelsY = values[numSteps-1]; - minPixelsY = values[0]; - nPixelsY = numSteps; - }else if(scanArgument==qDefs::AllFrames) - nPixelsY = number_of_exposures; - else if(scanArgument==qDefs::FileIndex) - nPixelsY = numberofFrames; + maxPixelsY = values[numSteps - 1]; + minPixelsY = values[0]; + nPixelsY = numSteps; + } else if (scanArgument == qDefs::AllFrames) + nPixelsY = number_of_exposures; + else if (scanArgument == qDefs::FileIndex) + nPixelsY = numberofFrames; - if(minPixelsY>maxPixelsY){ - double temp = minPixelsY; - minPixelsY = maxPixelsY; - maxPixelsY = temp; - backwardScanPlot = true; - }else backwardScanPlot = false; + if (minPixelsY > maxPixelsY) { + double temp = minPixelsY; + minPixelsY = maxPixelsY; + maxPixelsY = temp; + backwardScanPlot = true; + } else + backwardScanPlot = false; - //1d - if(histXAxis) delete [] histXAxis; histXAxis = new double [nPixelsX]; + // 1d + if (x1d) + delete[] x1d; + x1d = new double[nPixelsX]; - if(histYAxis[0]) delete [] histYAxis[0]; histYAxis[0] = new double [nPixelsX]; + for (auto &it : y1d) { + delete[] it; + } + if (y1d.size()) { + y1d.clear(); + title1d.clear(); + } + y1d.push_back(new double[nPixelsX]); + title1d.push_back(""); - //2d - if(lastImageArray) delete [] lastImageArray; lastImageArray = new double[nPixelsY*nPixelsX]; - if(gainImageArray) delete [] gainImageArray; gainImageArray = new double[nPixelsY*nPixelsX]; + // 2d + if (image2d) + delete[] image2d; + image2d = new double[nPixelsY * nPixelsX]; + if (gainImage) + delete[] gainImage; + gainImage = new double[nPixelsY * nPixelsX]; - //initializing 1d x axis - for(unsigned int px=0;pxmyDet->setReceiverOnline() == slsDetectorDefs::ONLINE_FLAG) { + if (((qDrawPlot *)this_pointer)->myDet->setReceiverOnline() == + slsDetectorDefs::ONLINE_FLAG) { // if receiver data up streaming not on, switch it on - if (((qDrawPlot *)this_pointer)->myDet->enableDataStreamingFromReceiver() != 1) { + if (((qDrawPlot *)this_pointer) + ->myDet->enableDataStreamingFromReceiver() != 1) { // switch on receiver - if (((qDrawPlot *)this_pointer)->myDet->enableDataStreamingFromReceiver(1) != 1) { - qDefs::checkErrorMessage(((qDrawPlot *)this_pointer)->myDet, "qDrawPlot::DataStartAcquireThread"); + if (((qDrawPlot *)this_pointer) + ->myDet->enableDataStreamingFromReceiver(1) != 1) { + qDefs::checkErrorMessage(((qDrawPlot *)this_pointer)->myDet, + "qDrawPlot::DataStartAcquireThread"); return this_pointer; } } @@ -876,21 +1202,18 @@ void *qDrawPlot::DataStartAcquireThread(void *this_pointer) { return this_pointer; } - - -int qDrawPlot::GetDataCallBack(detectorData *data, int fIndex, int subIndex, void *this_pointer) { +int qDrawPlot::GetDataCallBack(detectorData *data, int fIndex, int subIndex, + void *this_pointer) { ((qDrawPlot *)this_pointer)->GetData(data, fIndex, subIndex); return 0; } - - int qDrawPlot::GetData(detectorData *data, int fIndex, int subIndex) { #ifdef VERYVERBOSE std::cout << "******Entering GetDatafunction********\n"; std::cout << "fIndex " << fIndex << '\n'; std::cout << "subIndex " << subIndex << '\n'; - std::cout << "fname " << data->fileName << '\n'; + std::cout << "fname " << data->fileSaveName << '\n'; std::cout << "npoints " << data->npoints << '\n'; std::cout << "npy " << data->npy << '\n'; std::cout << "progress " << data->progressIndex << '\n'; @@ -902,173 +1225,71 @@ int qDrawPlot::GetData(detectorData *data, int fIndex, int subIndex) { #endif if (!stopSignal) { - //set progress + // set progress progress = (int)data->progressIndex; - //TODO! - // currentFrameIndex = fileIOStatic::getIndicesFromFileName(std::string(data->fileName),currentFileIndex); + // TODO! + // currentFrameIndex = + // fileIOStatic::getIndicesFromFileName(std::string(data->fileSaveName),currentFileIndex); currentFileIndex = data->fileIndex; - //happens if receiver sends a null and empty file name - /*if(std::string(data->fileName).empty()){ - std::cout << "Received empty file name. Exiting function without updating data for plot." <<'\n'; - return -1; - }*/ + // happens if receiver sends a null and empty file name + /*if(std::string(data->fileSaveName).empty()){ + std::cout << "Received empty file name. Exiting function + without updating data for plot." <<'\n'; return -1; + }*/ #ifdef VERYVERBOSE std::cout << "progress:" << progress << '\n'; #endif - // secondary title necessary to differentiate between frames when not saving data + // secondary title necessary to differentiate between frames when not + // saving data char temp_title[2000]; - //findex is the frame index given by receiver, cannot be derived from file name + // findex is the frame index given by receiver, cannot be derived from + // file name if (fIndex != -1) { currentFrameIndex = fIndex; sprintf(temp_title, "#%d", fIndex); if ((detType == slsDetectorDefs::EIGER) && (subIndex != -1)) sprintf(temp_title, "#%d %d", fIndex, subIndex); } else { - if (fileSaveEnable) - strcpy(temp_title, "#%d"); - else + sprintf(temp_title, "#%d", currentFrame); } if (subIndex != -1) sprintf(temp_title, "#%d %d", fIndex, subIndex); - //Plot Disabled + // Plot Disabled if (!plotEnable) return 0; - if (scanArgument == qDefs::None) { - //if the time is not over, RETURN - if (!data_pause_over) { - return 0; - } - data_pause_over = false; - data_pause_timer->start((int)(timerValue)); - } - // convert char* to double if (data->values == NULL) { data->values = new double[nPixelsX * nPixelsY]; if (gainDataEnable) { data->dgainvalues = new double[nPixelsX * nPixelsY]; - toDoublePixelData(data->values, data->cvalues, nPixelsX * nPixelsY, data->databytes, data->dynamicRange, data->dgainvalues); + toDoublePixelData(data->values, data->cvalues, + nPixelsX * nPixelsY, data->databytes, + data->dynamicRange, data->dgainvalues); } else - toDoublePixelData(data->values, data->cvalues, nPixelsX * nPixelsY, data->databytes, data->dynamicRange); + toDoublePixelData(data->values, data->cvalues, + nPixelsX * nPixelsY, data->databytes, + data->dynamicRange); } - //if scan - //alframes - if (scanArgument == qDefs::AllFrames) { - LockLastImageArray(); - //set title - plotTitle = QString(plotTitle_prefix) + QString(data->fileName).section('/', -1); - //variables - lastImageNumber = currentFrame + 1; - //title - imageTitle = temp_title; - //copy data - memcpy(lastImageArray + (currentScanDivLevel * nPixelsX), data->values, nPixelsX * sizeof(double)); - plotRequired = true; - UnlockLastImageArray(); - currentFrame++; - currentScanDivLevel++; - emit UpdatePlotSignal(); - return 0; - } - //file index - if (scanArgument == qDefs::FileIndex) { - LockLastImageArray(); - //set title - plotTitle = QString(plotTitle_prefix) + QString(data->fileName).section('/', -1); - //variables - if (currentFrameIndex == 0) - currentScanDivLevel = 0; - lastImageNumber = currentFrame + 1; - //title - imageTitle = temp_title; - //copy data - for (unsigned int px = 0; px < nPixelsX; ++px) - lastImageArray[currentScanDivLevel * nPixelsX + px] += data->values[px]; - plotRequired = true; - UnlockLastImageArray(); - currentFrame++; - currentScanDivLevel++; - emit UpdatePlotSignal(); - return 0; - } - //level0 - if (scanArgument == qDefs::Level0) { - std::cout << "Should not end up here! 0\n"; - // LockLastImageArray(); - // //set title - // plotTitle = QString(plotTitle_prefix) + QString(data->fileName).section('/', -1); - // //get scanvariable0 - // int ci = 0, fi = 0, p = 0, di = 0; - // double cs0 = 0, cs1 = 0; - // fileIOStatic::getVariablesFromFileName(std::string(data->fileName), ci, fi, p, cs0, cs1, di); - // //variables - // if (cs0 != currentScanValue) { - // if (backwardScanPlot) - // currentScanDivLevel--; - // else - // currentScanDivLevel++; - // } - // currentScanValue = cs0; - // lastImageNumber = currentFrame + 1; - // //title - // imageTitle = temp_title; - // //copy data - // for (unsigned int px = 0; px < nPixelsX; ++px) - // lastImageArray[currentScanDivLevel * nPixelsX + px] += data->values[px]; - // plotRequired = true; - // UnlockLastImageArray(); - // currentFrame++; - // emit UpdatePlotSignal(); - return 0; - } - if (scanArgument == qDefs::Level1) { - std::cout << "Should not end up here! 1\n"; - // LockLastImageArray(); - // //set title - // plotTitle = QString(plotTitle_prefix) + QString(data->fileName).section('/', -1); - // //get scanvariable1 - // int ci = 0, fi = 0, p = 0, di = 0; - // double cs0 = 0, cs1 = 0; - // fileIOStatic::getVariablesFromFileName(std::string(data->fileName), ci, fi, p, cs0, cs1, di); - // //variables - // if (cs1 != currentScanValue) { - // if (backwardScanPlot) - // currentScanDivLevel--; - // else - // currentScanDivLevel++; - // } - // currentScanValue = cs1; - // lastImageNumber = currentFrame + 1; - // //title - // imageTitle = temp_title; - // //copy data - // for (unsigned int px = 0; px < nPixelsX; ++px) - // lastImageArray[currentScanDivLevel * nPixelsX + px] += data->values[px]; - // plotRequired = true; - // UnlockLastImageArray(); - // currentFrame++; - // emit UpdatePlotSignal(); - return 0; - } - - //normal measurement or 1d scans + // normal measurement or 1d scans LockLastImageArray(); - /*if(!pthread_mutex_trylock(&(last_image_complete_mutex))){*/ - //set title - plotTitle = QString(plotTitle_prefix) + QString(data->fileName).section('/', -1); - // only if you got the lock, do u need to remember lastimagenumber to plot + /*if(!pthread_mutex_trylock(&(lastImageCompleteMutex))){*/ + // set title + plotTitle = QString(plotTitle_prefix) + + QString(data->fileSaveName).section('/', -1); + // only if you got the lock, do u need to remember lastimagenumber to + // plot lastImageNumber = currentFrame + 1; - //cout<<"got last imagenumber:"<values[i] < histFrom) || (data->values[i] > histTo)) + // ignore outside limits + if ((data->values[i] < histFrom) || + (data->values[i] > histTo)) continue; - //check for intervals, increment if validates + // check for intervals, increment if validates for (int j = 0; j < histogramSamples.size(); ++j) { - if (histogramSamples[j].interval.contains(data->values[i])) + if (histogramSamples[j].interval.contains( + data->values[i])) histogramSamples[j].value += 1; } } - //get sum of data pixels + // get sum of data pixels else val += data->values[i]; } @@ -1109,7 +1332,8 @@ int qDrawPlot::GetData(detectorData *data, int fIndex, int subIndex) { // //find scan value // int ci = 0, fi = 0; // double cs0 = 0, cs1 = 0; - // fileIOStatic::getVariablesFromFileName(std::string(data->fileName), ci, fi, cs0, cs1); + // fileIOStatic::getVariablesFromFileName(std::string(data->fileSaveName), + // ci, fi, cs0, cs1); // int scanval = -1; // if (cs0 != -1) @@ -1118,19 +1342,21 @@ int qDrawPlot::GetData(detectorData *data, int fIndex, int subIndex) { // scanval = cs1; // //ignore outside limits - // if ((scanval < histFrom) || (scanval > histTo) || (scanval == -1)) + // if ((scanval < histFrom) || (scanval > histTo) || + // (scanval == -1)) // scanval = -1; // //check for intervals, increment if validates // for (int j = 0; j < histogramSamples.size(); ++j) { // if (histogramSamples[j].interval.contains(scanval)) { // histogramSamples[j].value = val; - // cout << "j:" << j << " scanval:" << scanval << " val:" << val << endl; + // cout << "j:" << j << " scanval:" << scanval << " + // val:" << val << endl; // } // } } } - //not histogram + // not histogram else { // Persistency if (currentPersistency < persistency) @@ -1142,38 +1368,42 @@ int qDrawPlot::GetData(detectorData *data, int fIndex, int subIndex) { // copy data for (int i = currentPersistency; i > 0; i--) - memcpy(histYAxis[i], histYAxis[i - 1], nPixelsX * sizeof(double)); + memcpy(y1d[i], y1d[i - 1], nPixelsX * sizeof(double)); - //recalculating pedestal + // recalculating pedestal if (startPedestalCal) { - //start adding frames to get to the pedestal value + // start adding frames to get to the pedestal value if (pedestalCount < NUM_PEDESTAL_FRAMES) { for (unsigned int px = 0; px < nPixelsX; ++px) tempPedestalVals[px] += data->values[px]; - memcpy(histYAxis[0], data->values, nPixelsX * sizeof(double)); + memcpy(y1d[0], data->values, nPixelsX * sizeof(double)); pedestalCount++; } - //calculate the pedestal value + // calculate the pedestal value if (pedestalCount == NUM_PEDESTAL_FRAMES) { cout << "Pedestal Calculated" << '\n'; for (unsigned int px = 0; px < nPixelsX; ++px) - tempPedestalVals[px] = tempPedestalVals[px] / (double)NUM_PEDESTAL_FRAMES; - memcpy(pedestalVals, tempPedestalVals, nPixelsX * sizeof(double)); + tempPedestalVals[px] = tempPedestalVals[px] / + (double)NUM_PEDESTAL_FRAMES; + memcpy(pedestalVals, tempPedestalVals, + nPixelsX * sizeof(double)); startPedestalCal = 0; } } - //normal data - if (((!pedestal) & (!accumulate) & (!binary)) || (resetAccumulate)) { - memcpy(histYAxis[0], data->values, nPixelsX * sizeof(double)); + // normal data + if (((!isPedestal) & (!accumulate) & (!binary)) || + (resetAccumulate)) { + memcpy(y1d[0], data->values, nPixelsX * sizeof(double)); resetAccumulate = false; } - //pedestal or accumulate + // pedestal or accumulate else { - double temp; //cannot overwrite cuz of accumulate - for (unsigned int px = 0; px < (nPixelsX * nPixelsY); ++px) { + double temp; // cannot overwrite cuz of accumulate + for (unsigned int px = 0; px < (nPixelsX * nPixelsY); + ++px) { temp = data->values[px]; - if (pedestal) + if (isPedestal) temp = data->values[px] - (pedestalVals[px]); if (binary) { if ((temp >= binaryFrom) && (temp <= binaryTo)) @@ -1182,55 +1412,61 @@ int qDrawPlot::GetData(detectorData *data, int fIndex, int subIndex) { temp = 0; } if (accumulate) - temp += histYAxis[0][px]; - //after all processing - histYAxis[0][px] = temp; + temp += y1d[0][px]; + // after all processing + y1d[0][px] = temp; } } } } - //2d + // 2d else { // Titles - imageTitle = temp_title; + title2d = temp_title; - //jungfrau mask gain + // jungfrau mask gain if (data->dgainvalues != NULL) { - memcpy(gainImageArray, data->dgainvalues, nPixelsX * nPixelsY * sizeof(double)); - gainPlotEnable = true; + memcpy(gainImage, data->dgainvalues, + nPixelsX * nPixelsY * sizeof(double)); + gainDataExtracted = true; } else - gainPlotEnable = false; + gainDataExtracted = false; - //recalculating pedestal + // recalculating pedestal if (startPedestalCal) { - //start adding frames to get to the pedestal value + // start adding frames to get to the pedestal value if (pedestalCount < NUM_PEDESTAL_FRAMES) { for (unsigned int px = 0; px < (nPixelsX * nPixelsY); ++px) tempPedestalVals[px] += data->values[px]; - memcpy(lastImageArray, data->values, nPixelsX * nPixelsY * sizeof(double)); + memcpy(image2d, data->values, + nPixelsX * nPixelsY * sizeof(double)); pedestalCount++; } - //calculate the pedestal value + // calculate the pedestal value if (pedestalCount == NUM_PEDESTAL_FRAMES) { std::cout << "Pedestal Calculated" << '\n'; for (unsigned int px = 0; px < (nPixelsX * nPixelsY); ++px) - tempPedestalVals[px] = tempPedestalVals[px] / (double)NUM_PEDESTAL_FRAMES; - memcpy(pedestalVals, tempPedestalVals, nPixelsX * nPixelsY * sizeof(double)); + tempPedestalVals[px] = + tempPedestalVals[px] / (double)NUM_PEDESTAL_FRAMES; + memcpy(pedestalVals, tempPedestalVals, + nPixelsX * nPixelsY * sizeof(double)); startPedestalCal = 0; } } - //normal data - if (((!pedestal) & (!accumulate) & (!binary)) || (resetAccumulate)) { - memcpy(lastImageArray, data->values, nPixelsX * nPixelsY * sizeof(double)); + // normal data + if (((!isPedestal) & (!accumulate) & (!binary)) || + (resetAccumulate)) { + memcpy(image2d, data->values, + nPixelsX * nPixelsY * sizeof(double)); resetAccumulate = false; } - //pedestal or accumulate or binary + // pedestal or accumulate or binary else { double temp; for (unsigned int px = 0; px < (nPixelsX * nPixelsY); ++px) { temp = data->values[px]; - if (pedestal) + if (isPedestal) temp = data->values[px] - (pedestalVals[px]); if (binary) { if ((temp >= binaryFrom) && (temp <= binaryTo)) @@ -1239,19 +1475,20 @@ int qDrawPlot::GetData(detectorData *data, int fIndex, int subIndex) { temp = 0; } if (accumulate) - temp += lastImageArray[px]; - //after all processing - lastImageArray[px] = temp; + temp += image2d[px]; + // after all processing + image2d[px] = temp; } } } - /* pthread_mutex_unlock(&(last_image_complete_mutex)); - }*/ + /* pthread_mutex_unlock(&(lastImageCompleteMutex)); + }*/ plotRequired = true; UnlockLastImageArray(); #ifdef VERYVERBOSE - cprintf(BLUE, "currentframe:%d \tcurrentframeindex:%d\n", currentFrame, currentFrameIndex); + cprintf(BLUE, "currentframe:%d \tcurrentframeindex:%d\n", currentFrame, + currentFrameIndex); #endif currentFrame++; emit UpdatePlotSignal(); @@ -1263,53 +1500,57 @@ int qDrawPlot::GetData(detectorData *data, int fIndex, int subIndex) { return 0; } - - -int qDrawPlot::GetAcquisitionFinishedCallBack(double currentProgress, int detectorStatus, void *this_pointer) { - ((qDrawPlot *)this_pointer)->AcquisitionFinished(currentProgress, detectorStatus); +int qDrawPlot::GetAcquisitionFinishedCallBack(double currentProgress, + int detectorStatus, + void *this_pointer) { + ((qDrawPlot *)this_pointer) + ->AcquisitionFinished(currentProgress, detectorStatus); #ifdef VERYVERBOSE std::cout << "acquisition finished callback worked ok\n"; #endif return 0; } - - int qDrawPlot::AcquisitionFinished(double currentProgress, int detectorStatus) { #ifdef VERBOSE std::cout << "\nEntering Acquisition Finished with status "; #endif - QString status = QString(slsDetectorDefs::runStatusType(slsDetectorDefs::runStatus(detectorStatus)).c_str()); + QString status = QString(slsDetectorDefs::runStatusType( + slsDetectorDefs::runStatus(detectorStatus)) + .c_str()); #ifdef VERBOSE - std::cout << status.toAscii().constData() << " and progress " << currentProgress << '\n'; + std::cout << status.toAscii().constData() << " and progress " + << currentProgress << '\n'; #endif - //error or stopped + // error or stopped if ((stopSignal) || (detectorStatus == slsDetectorDefs::ERROR)) { #ifdef VERBOSE std::cout << "Error in Acquisition\n\n"; #endif - //stopSignal = 1;//just to be sure + // stopSignal = 1;//just to be sure emit AcquisitionErrorSignal(status); } #ifdef VERBOSE - //all measurements are over + // all measurements are over else if (currentProgress == 100) { std::cout << "Acquisition Finished\n"; } #endif StartStopDaqToggle(true); - //this lets the measurement tab know its over, and to enable tabs + // this lets the measurement tab know its over, and to enable tabs emit UpdatingPlotFinished(); - //calculate s curve inflection point + // calculate s curve inflection point int l1 = 0, l2 = 0, j; if ((histogram) && (histogramArgument != qDefs::Intensity)) { for (j = 0; j < histogramSamples.size() - 2; ++j) { l1 = histogramSamples[j + 1].value - histogramSamples[j].value; l2 = histogramSamples[j + 2].value - histogramSamples[j + 1].value; if (l1 > l2) { - std::cout << "***** s curve inflectionfound at " << histogramSamples[j].interval.maxValue() << "" - "or j at " + std::cout << "***** s curve inflectionfound at " + << histogramSamples[j].interval.maxValue() + << "" + "or j at " << j << " with l1 " << l1 << " and l2 " << l2 << '\n'; } } @@ -1318,40 +1559,39 @@ int qDrawPlot::AcquisitionFinished(double currentProgress, int detectorStatus) { return 0; } - - int qDrawPlot::GetProgressCallBack(double currentProgress, void *this_pointer) { ((qDrawPlot *)this_pointer)->progress = currentProgress; return 0; } - - void qDrawPlot::ShowAcquisitionErrorMessage(QString status) { if (!alreadyDisplayed) { alreadyDisplayed = true; - qDefs::Message(qDefs::WARNING, std::string("The acquisiton has ended abruptly. " - "Current Detector Status: ") + - status.toAscii().constData() + std::string("."), + qDefs::Message(qDefs::WARNING, + std::string("The acquisiton has ended abruptly. " + "Current Detector Status: ") + + status.toAscii().constData() + + std::string("."), "qDrawPlot::ShowAcquisitionErrorMessage"); } } - - -int qDrawPlot::GetMeasurementFinishedCallBack(int currentMeasurementIndex, int fileIndex, void *this_pointer) { - ((qDrawPlot *)this_pointer)->MeasurementFinished(currentMeasurementIndex, fileIndex); +int qDrawPlot::GetMeasurementFinishedCallBack(int currentMeasurementIndex, + int fileIndex, + void *this_pointer) { + ((qDrawPlot *)this_pointer) + ->MeasurementFinished(currentMeasurementIndex, fileIndex); return 0; } - - int qDrawPlot::MeasurementFinished(int currentMeasurementIndex, int fileIndex) { #ifdef VERBOSE - std::cout << "Entering Measurement Finished with currentMeasurement " << currentMeasurementIndex << " and fileIndex " << fileIndex << '\n'; + std::cout << "Entering Measurement Finished with currentMeasurement " + << currentMeasurementIndex << " and fileIndex " << fileIndex + << '\n'; #endif - //to make sure it plots the last frame + // to make sure it plots the last frame while (plotRequired) { usleep(2000); } @@ -1363,51 +1603,19 @@ int qDrawPlot::MeasurementFinished(int currentMeasurementIndex, int fileIndex) { #endif emit SetCurrentMeasurementSignal(currentMeasurement); SetupMeasurement(); - /*if((myDet->setReceiverOnline()==slsDetectorDefs::ONLINE_FLAG) && (myDet->getFramesCaughtByReceiver() == 0)) - boxPlot->setTitle("OLD_plot.raw");*/ + /*if((myDet->setReceiverOnline()==slsDetectorDefs::ONLINE_FLAG) && + (myDet->getFramesCaughtByReceiver() == 0)) + boxPlot->setTitle("OLD_plot.raw");*/ return 0; } - - - -void qDrawPlot::SelectPlot(int i) { //1 for 1D otherwise 2D - if (i == 1) { - //Clear1DPlot(); it clears the last measurement - plot1D->SetXTitle(histXAxisTitle.toAscii().constData()); - plot1D->SetYTitle(histYAxisTitle.toAscii().constData()); - plot1D->show(); - plot2D->hide(); - boxPlot->setFlat(false); - plot_in_scope = 1; - layout->addWidget(histFrameIndexTitle, 0, 0); - plotLayout->setContentsMargins(10, 10, 10, 10); - } else { - plot2D->SetXTitle(imageXAxisTitle); - plot2D->SetYTitle(imageYAxisTitle); - plot2D->SetZTitle(imageZAxisTitle); - plot1D->hide(); - plot2D->show(); - boxPlot->setFlat(true); - plot_in_scope = 2; - histFrameIndexTitle->setText(""); - layout->removeWidget(histFrameIndexTitle); - plotLayout->setContentsMargins(0, 0, 0, 0); - } -} - - - void qDrawPlot::Clear1DPlot() { - for (QVector::iterator h = plot1DHists.begin(); h != plot1DHists.end(); ++h) { - (*h)->Detach(plot1D); - //do not delete *h or h. + for (QVector::iterator h = hists1d.begin(); + h != hists1d.end(); ++h) { + (*h)->Detach(plot1d); + // do not delete *h or h. } - - plotHistogram->detach(); } - - void qDrawPlot::UpdatePlot() { #ifdef VERYVERBOSE std::cout << "Entering UpdatePlot function\n"; @@ -1415,159 +1623,193 @@ void qDrawPlot::UpdatePlot() { // only if no plot isnt enabled if (plotEnable && plotRequired) { LockLastImageArray(); - //so that it doesnt plot every single thing + // so that it doesnt plot every single thing #ifdef VERYVERBOSE cprintf(GREEN, "Updating Plot\n"); #endif - //so as to not plot it again and to let measurment finished know its done plotting it - //1-d plot stuff - if (plot_in_scope == 1) { + // so as to not plot it again and to let measurment finished know its + // done plotting it 1-d plot stuff + if (is1d) { #ifdef VERYVERBOSE std::cout << "Last Image Number:" << lastImageNumber << '\n'; #endif if (histNBins) { Clear1DPlot(); - plot1D->SetXTitle(histXAxisTitle.toAscii().constData()); - plot1D->SetYTitle(histYAxisTitle.toAscii().constData()); + plot1d->SetXTitle(xTitle1d.toAscii().constData()); + plot1d->SetYTitle(yTitle1d.toAscii().constData()); - //histogram + // histogram if (histogram) { - plotHistogram->setData(new QwtIntervalSeriesData(histogramSamples)); + plotHistogram->setData( + new QwtIntervalSeriesData(histogramSamples)); plotHistogram->setPen(QPen(Qt::red)); - plotHistogram->setBrush(QBrush(Qt::red, Qt::Dense4Pattern)); //Qt::SolidPattern - histFrameIndexTitle->setText(GetHistTitle(0)); - plotHistogram->attach(plot1D); - //refixing all the zooming + plotHistogram->setBrush( + QBrush(Qt::red, Qt::Dense4Pattern)); // Qt::SolidPattern + lblFrameIndexTitle1d->setText(GetTitle1d(0)); + plotHistogram->attach(plot1d); + // refixing all the zooming - plot1D->SetXMinMax(startPixel, endPixel); - plot1D->SetYMinMax(0, plotHistogram->boundingRect().height()); - plot1D->SetZoomBase(startPixel, 0, endPixel - startPixel, plotHistogram->boundingRect().height()); + plot1d->SetXMinMax(startPixel, endPixel); + plot1d->SetYMinMax(0, + plotHistogram->boundingRect().height()); + plot1d->SetZoomBase(startPixel, 0, endPixel - startPixel, + plotHistogram->boundingRect().height()); } - //not histogram + // not histogram else { for (int hist_num = 0; hist_num < (int)nHists; ++hist_num) { SlsQtH1D *h; - if (hist_num + 1 > plot1DHists.size()) { + if (hist_num + 1 > hists1d.size()) { if (anglePlot) - plot1DHists.append(h = new SlsQtH1D("", histNBins, histXAngleAxis, histYAngleAxis)); + hists1d.append( + h = new SlsQtH1D("", histNBins, + histXAngleAxis, + histYAngleAxis)); else - plot1DHists.append(h = new SlsQtH1D("", histNBins, histXAxis, GetHistYAxis(hist_num))); + hists1d.append( + h = new SlsQtH1D("", histNBins, x1d, + GetHistYAxis(hist_num))); h->SetLineColor(hist_num); } else { - h = plot1DHists.at(hist_num); + h = hists1d.at(hist_num); if (anglePlot) - h->SetData(histNBins, histXAngleAxis, histYAngleAxis); + h->SetData(histNBins, histXAngleAxis, + histYAngleAxis); else - h->SetData(histNBins, histXAxis, GetHistYAxis(hist_num)); + h->SetData(histNBins, x1d, + GetHistYAxis(hist_num)); } SetStyle(h); - histFrameIndexTitle->setText(GetHistTitle(0)); - //h->setTitle(GetHistTitle(hist_num)); - h->Attach(plot1D); - //refixing all the zooming - //if((firstPlot) || (anglePlot)){ - /*plot1D->SetXMinMax(h->minXValue(),h->maxXValue()); - plot1D->SetYMinMax(h->minYValue(),h->maxYValue()); - plot1D->SetZoomBase(h->minXValue(),h->minYValue(), - h->maxXValue()-h->minXValue(),h->maxYValue()-h->minYValue());*/ + lblFrameIndexTitle1d->setText(GetTitle1d(0)); + // h->setTitle(GetTitle1d(hist_num)); + h->Attach(plot1d); + // refixing all the zooming + // if((firstPlot) || (anglePlot)){ + /*plot1d->SetXMinMax(h->minXValue(),h->maxXValue()); + plot1d->SetYMinMax(h->minYValue(),h->maxYValue()); + plot1d->SetZoomBase(h->minXValue(),h->minYValue(), + h->maxXValue()-h->minXValue(),h->maxYValue()-h->minYValue());*/ // firstPlot = false; //} } - /**moved from below (had applied to histograms as well) to here, */ + /**moved from below (had applied to histograms as well) to + * here, */ // update range if required if (XYRangeChanged) { - if (!IsXYRange[qDefs::XMINIMUM]) - XYRangeValues[qDefs::XMINIMUM] = plot1D->GetXMinimum(); - if (!IsXYRange[qDefs::XMAXIMUM]) - XYRangeValues[qDefs::XMAXIMUM] = plot1D->GetXMaximum(); - if (!IsXYRange[qDefs::YMINIMUM]) - XYRangeValues[qDefs::YMINIMUM] = plot1D->GetYMinimum(); - if (!IsXYRange[qDefs::YMAXIMUM]) - XYRangeValues[qDefs::YMAXIMUM] = plot1D->GetYMaximum(); - plot1D->SetXMinMax(XYRangeValues[qDefs::XMINIMUM], XYRangeValues[qDefs::XMAXIMUM]); - plot1D->SetYMinMax(XYRangeValues[qDefs::YMINIMUM], XYRangeValues[qDefs::YMAXIMUM]); - //Should not be reset for histogram, - //that is the only way to zoom in (new plots are zoomed out as its different each time) + if (!isXYRangeEnable[qDefs::XMINIMUM]) + XYRangeValues[qDefs::XMINIMUM] = + plot1d->GetXMinimum(); + if (!isXYRangeEnable[qDefs::XMAXIMUM]) + XYRangeValues[qDefs::XMAXIMUM] = + plot1d->GetXMaximum(); + if (!isXYRangeEnable[qDefs::YMINIMUM]) + XYRangeValues[qDefs::YMINIMUM] = + plot1d->GetYMinimum(); + if (!isXYRangeEnable[qDefs::YMAXIMUM]) + XYRangeValues[qDefs::YMAXIMUM] = + plot1d->GetYMaximum(); + plot1d->SetXMinMax(XYRangeValues[qDefs::XMINIMUM], + XYRangeValues[qDefs::XMAXIMUM]); + plot1d->SetYMinMax(XYRangeValues[qDefs::YMINIMUM], + XYRangeValues[qDefs::YMAXIMUM]); + // Should not be reset for histogram, + // that is the only way to zoom in (new plots are zoomed + // out as its different each time) if (!histogram) XYRangeChanged = false; } - /**moved from below (had applied to histograms as well) to here, */ - //Display Statistics + /**moved from below (had applied to histograms as well) to + * here, */ + // Display Statistics if (displayStatistics) { double min = 0, max = 0, sum = 0; if (anglePlot) - GetStatistics(min, max, sum, histYAngleAxis, histNBins); + GetStatistics(min, max, sum, histYAngleAxis, + histNBins); else - GetStatistics(min, max, sum, histYAxis[0], histNBins); + GetStatistics(min, max, sum, y1d[0], histNBins); lblMinDisp->setText(QString("%1").arg(min)); lblMaxDisp->setText(QString("%1").arg(max)); lblSumDisp->setText(QString("%1").arg(sum)); + widgetStatistics->show(); } } - - if (saveAll) - SavePlotAutomatic(); } - } //2-d plot stuff + } // 2-d plot stuff else { - if (lastImageArray) { + if (image2d) { if (nPixelsX > 0 && nPixelsY > 0) { - plot2D->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, startPixel, endPixel, lastImageArray); - plot2D->setTitle(GetImageTitle()); - plot2D->SetXTitle(imageXAxisTitle); - plot2D->SetYTitle(imageYAxisTitle); - plot2D->SetZTitle(imageZAxisTitle); - //zmin and zmax of plot already calculated using SetData, now recalculate if z is set - plot2D->KeepZRangeIfSet(); - if (gainPlotEnable) { - gainplot2D->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, startPixel, endPixel, gainImageArray); - gainplot2D->setTitle(GetImageTitle()); - gainplot2D->show(); + plot2d->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, + nPixelsY, startPixel, endPixel, + image2d); + plot2d->setTitle(title2d.c_str()); + plot2d->SetXTitle(xTitle2d); + plot2d->SetYTitle(yTitle2d); + plot2d->SetZTitle(zTitle2d); + // zmin and zmax of plot already calculated using SetData, + // now recalculate if z is set + plot2d->KeepZRangeIfSet(); + if (gainDataExtracted) { + gainplot2d->GetPlot()->SetData( + nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, + startPixel, endPixel, gainImage); + gainplot2d->setTitle(title2d.c_str()); + gainplot2d->show(); } else { - gainplot2D->hide(); + gainplot2d->hide(); } } // update range if required if (XYRangeChanged) { - if (!IsXYRange[qDefs::XMINIMUM]) - XYRangeValues[qDefs::XMINIMUM] = plot2D->GetPlot()->GetXMinimum(); - if (!IsXYRange[qDefs::XMAXIMUM]) - XYRangeValues[qDefs::XMAXIMUM] = plot2D->GetPlot()->GetXMaximum(); - if (!IsXYRange[qDefs::YMINIMUM]) - XYRangeValues[qDefs::YMINIMUM] = plot2D->GetPlot()->GetYMinimum(); - if (!IsXYRange[qDefs::YMAXIMUM]) - XYRangeValues[qDefs::YMAXIMUM] = plot2D->GetPlot()->GetYMaximum(); - plot2D->GetPlot()->SetXMinMax(XYRangeValues[qDefs::XMINIMUM], XYRangeValues[qDefs::XMAXIMUM]); - plot2D->GetPlot()->SetYMinMax(XYRangeValues[qDefs::YMINIMUM], XYRangeValues[qDefs::YMAXIMUM]); - gainplot2D->GetPlot()->SetXMinMax(XYRangeValues[qDefs::XMINIMUM], XYRangeValues[qDefs::XMAXIMUM]); - gainplot2D->GetPlot()->SetYMinMax(XYRangeValues[qDefs::YMINIMUM], XYRangeValues[qDefs::YMAXIMUM]); + if (!isXYRangeEnable[qDefs::XMINIMUM]) + XYRangeValues[qDefs::XMINIMUM] = + plot2d->GetPlot()->GetXMinimum(); + if (!isXYRangeEnable[qDefs::XMAXIMUM]) + XYRangeValues[qDefs::XMAXIMUM] = + plot2d->GetPlot()->GetXMaximum(); + if (!isXYRangeEnable[qDefs::YMINIMUM]) + XYRangeValues[qDefs::YMINIMUM] = + plot2d->GetPlot()->GetYMinimum(); + if (!isXYRangeEnable[qDefs::YMAXIMUM]) + XYRangeValues[qDefs::YMAXIMUM] = + plot2d->GetPlot()->GetYMaximum(); + plot2d->GetPlot()->SetXMinMax( + XYRangeValues[qDefs::XMINIMUM], + XYRangeValues[qDefs::XMAXIMUM]); + plot2d->GetPlot()->SetYMinMax( + XYRangeValues[qDefs::YMINIMUM], + XYRangeValues[qDefs::YMAXIMUM]); + gainplot2d->GetPlot()->SetXMinMax( + XYRangeValues[qDefs::XMINIMUM], + XYRangeValues[qDefs::XMAXIMUM]); + gainplot2d->GetPlot()->SetYMinMax( + XYRangeValues[qDefs::YMINIMUM], + XYRangeValues[qDefs::YMAXIMUM]); XYRangeChanged = false; } - plot2D->GetPlot()->Update(); - if (gainPlotEnable) { - gainplot2D->GetPlot()->Update(); - gainplot2D->setFixedWidth(plot2D->width() / 4); - gainplot2D->setFixedHeight(plot2D->height() / 4); - gainplot2D->show(); + plot2d->GetPlot()->Update(); + if (gainDataExtracted) { + gainplot2d->GetPlot()->Update(); + gainplot2d->setFixedWidth(plot2d->width() / 4); + gainplot2d->setFixedHeight(plot2d->height() / 4); + gainplot2d->show(); } else - gainplot2D->hide(); - //Display Statistics + gainplot2d->hide(); + // Display Statistics if (displayStatistics) { double min = 0, max = 0, sum = 0; - GetStatistics(min, max, sum, lastImageArray, nPixelsX * nPixelsY); + GetStatistics(min, max, sum, image2d, nPixelsX * nPixelsY); lblMinDisp->setText(QString("%1").arg(min)); lblMaxDisp->setText(QString("%1").arg(max)); lblSumDisp->setText(QString("%1").arg(sum)); } - if (saveAll) - SavePlotAutomatic(); } } - //set plot title + // set plot title boxPlot->setTitle(plotTitle); - //to notify the measurement finished when its done + // to notify the measurement finished when its done plotRequired = false; UnlockLastImageArray(); } @@ -1575,519 +1817,4 @@ void qDrawPlot::UpdatePlot() { #ifdef VERYVERBOSE std::cout << "Exiting UpdatePlot function\n"; #endif -} - - - -void qDrawPlot::ClonePlot() { - int i; - - //check for space for more clone widget references - bool found = false; - for (i = 0; i < MAXCloneWindows; ++i) - if (!cloneWidgets[i]) { - found = true; - break; - } - // no space - if (!found) { - std::cout << "Too many clones\n"; - exit(-1); - } - - //get file path while acquisition runnign without accessing shared memory - std::string sFilePath; - if (running) - sFilePath = filePath.toAscii().constData(); - else { - sFilePath = myDet->getFilePath(); - qDefs::checkErrorMessage(myDet, "qDrawPlot::ClonePlot"); - } - - LockLastImageArray(); - - // create clone & copy data - if (plot_in_scope == 1) { - cloneWidgets[i] = new qCloneWidget(this, i, boxPlot->title(), histXAxisTitle, histYAxisTitle, "", - (int)plot_in_scope, sFilePath, displayStatistics, lblMinDisp->text(), lblMaxDisp->text(), lblSumDisp->text()); - if (!anglePlot) - cloneWidgets[i]->SetCloneHists((int)nHists, histNBins, histXAxis, histYAxis, histTitle, lines, markers); - else - cloneWidgets[i]->SetCloneHists((int)nHists, histNBins, histXAngleAxis, histYAngleAxis, histTitle, lines, markers); - - } else { - cloneWidgets[i] = new qCloneWidget(this, i, boxPlot->title(), imageXAxisTitle, imageYAxisTitle, imageZAxisTitle, - (int)plot_in_scope, sFilePath, displayStatistics, lblMinDisp->text(), lblMaxDisp->text(), lblSumDisp->text()); - cloneWidgets[i]->SetCloneHists2D(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, startPixel, endPixel, lastImageArray); - } - - // update range - found = false; - for (int index = 0; index < 4; ++index) - if (IsXYRange[index]) { - found = true; - break; - } - if (found) - cloneWidgets[i]->SetRange(IsXYRange, XYRangeValues); - - UnlockLastImageArray(); - - cloneWidgets[i]->show(); - - // to remember which all clone widgets were closed - connect(cloneWidgets[i], SIGNAL(CloneClosedSignal(int)), this, SLOT(CloneCloseEvent(int))); -} - - - -void qDrawPlot::SaveClones() { - char errID[200]; - std::string errMessage = "The Snapshots with ID's: "; - bool success = true; - for (int i = 0; i < MAXCloneWindows; ++i) - if (cloneWidgets[i]) { - if (cloneWidgets[i]->SavePlotAutomatic()) { - success = false; - sprintf(errID, "%d", i); - errMessage.append(std::string(errID) + std::string(", ")); - } - } - if (success) - qDefs::Message(qDefs::INFORMATION, "The Snapshots have all been saved successfully in .png.", "Dock"); - else - qDefs::Message(qDefs::WARNING, errMessage + std::string("were not saved."), "qDrawPlot::SaveClones"); -} - - - -void qDrawPlot::CloseClones() { - for (int i = 0; i < MAXCloneWindows; ++i) - if (cloneWidgets[i]) - cloneWidgets[i]->close(); -} - - - -void qDrawPlot::CloneCloseEvent(int id) { - cloneWidgets[id] = 0; -#ifdef VERBOSE - std::cout << "Closing Clone Window id:" << id << '\n'; -#endif -} - - - -void qDrawPlot::SavePlot() { - // render image - QImage savedImage(size().width(), size().height(), QImage::Format_RGB32); - QPainter painter(&savedImage); - render(&painter); - - QString fName; - if (running) - fName = filePath; - else { - fName = QString(myDet->getFilePath().c_str()); - qDefs::checkErrorMessage(myDet, "qDrawPlot::SavePlot"); - } - - if (boxPlot->title().contains('.')) { - fName.append(QString('/') + boxPlot->title()); - fName.replace(".dat", ".png"); - fName.replace(".raw", ".png"); - } else - fName.append(QString("/Image.png")); - - fName = QFileDialog::getSaveFileName(0, tr("Save Image"), fName, tr("PNG Files (*.png);;XPM Files(*.xpm);;JPEG Files(*.jpg)"), 0, QFileDialog::ShowDirsOnly); - - if (!fName.isEmpty()) { - if (savedImage.save(fName)) - qDefs::Message(qDefs::INFORMATION, "The Image has been successfully saved", "qDrawPlot::SavePlot"); - else - qDefs::Message(qDefs::WARNING, "Attempt to save image failed.\n" - "Formats: .png, .jpg, .xpm.", - "qDrawPlot::SavePlot"); - } -} - - - -void qDrawPlot::SavePlotAutomatic() { - //no need to save the same plot many times - if ((currentFrame > lastSavedFrame) && (currentMeasurement >= lastSavedMeasurement)) { - - QString qFilePath; - if (running) - qFilePath = filePath; - else { - qFilePath = QString(myDet->getFilePath().c_str()); - qDefs::checkErrorMessage(myDet, "qDrawPlot::SavePlotAutomatic"); - } - - lastSavedFrame = currentFrame; - lastSavedMeasurement = currentMeasurement; - char cID[10]; - sprintf(cID, "%d", lastSavedFrame); - //title - QString fName = qFilePath; - if (boxPlot->title().contains('.')) { - fName.append(QString('/') + boxPlot->title()); - fName.replace(".dat", ".png"); - fName.replace(".raw", ".png"); - } else - fName.append(QString("/Image_unknown_title.png")); - //save - QImage img(size().width(), size().height(), QImage::Format_RGB32); - QPainter painter(&img); - render(&painter); - //if error while saving - if (!img.save(fName)) { - //mention the error only the first time - if (!saveError) { - //so it doesnt repeat again - saveError = true; - connect(this, SIGNAL(saveErrorSignal(QString)), this, SLOT(ShowSaveErrorMessage(QString))); - emit saveErrorSignal(fName); - } - } - } -} - - - -void qDrawPlot::ShowSaveErrorMessage(QString fileName) { - qDefs::Message(qDefs::WARNING, std::string("Automatic Saving: Could not save the first file:\n") + std::string(fileName.toAscii().constData()) + std::string("\n\nNote: Will not show future file save errors for this acquisition."), "qDrawPlot::ShowSaveErrorMessage"); -} - - - -void qDrawPlot::SetPersistency(int val) { - for (int i = 0; i <= val; ++i) - if (!histYAxis[i]) - histYAxis[i] = new double[nPixelsX]; - persistency = val; -} - - - -void qDrawPlot::EnablePlot(bool enable) { -#ifdef VERBOSE - std::cout << "Plotting set to:" << enable << '\n'; -#endif - plotEnable = enable; - //if no plot, cant do setting range. - // not true vice versa where plot was false and now set it to true - Clear1DPlot(); -} - - - -void qDrawPlot::DisableZoom(bool disable) { - if (plot_in_scope == 1) - plot1D->DisableZoom(disable); - else - plot2D->GetPlot()->DisableZoom(disable); -} - - - - int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){ - int ret; - double min=0,max=0,sum=0; - #ifdef VERBOSE - if(fromDetector) std::cout << "Geting Trimbits from Detector" <<'\n'; - else std::cout << "Getting Trimbits from Shared Memory" <<'\n'; - #endif - - LockLastImageArray(); - - if(detType == slsDetectorDefs::EIGER){ - - //defining axes - nPixelsX = 100;/**??*/ - nPixelsY = 100; - if(lastImageArray) delete [] lastImageArray; lastImageArray = new double[nPixelsY*nPixelsX]; - //initializing 2d array - memset(lastImageArray, 0 ,nPixelsY * nPixelsX * sizeof(double)); - /* - for(int py=0;py<(int)nPixelsY;++py) - for(int px=0;px<(int)nPixelsX;++px) - lastImageArray[py*nPixelsX+px] = 0; - */ - //get trimbits - ret = 1;/*myDet->getChanRegs(lastImageArray,fromDetector);*/ - if(!ret){ - qDefs::Message(qDefs::WARNING,"No Trimbit data found in shared memory.","qDrawPlot::UpdateTrimbitPlot"); - UnlockLastImageArray(); - return qDefs::FAIL; - } - //clear/select plot and set titles - Select2DPlot(); - plot2D->GetPlot()->SetData(nPixelsX,-0.5,nPixelsX-0.5,nPixelsY,-0.5,nPixelsY-0.5,lastImageArray); - plot2D->setTitle("Image"); - plot2D->SetXTitle("Pixel"); - plot2D->SetYTitle("Pixel"); - plot2D->SetZTitle("Trimbits"); - //zmin and zmax of plot already calculated using SetData, now recalculate if z is set - plot2D->KeepZRangeIfSet(); - #ifdef VERBOSE - std::cout << "Trimbits Plot updated" <<'\n'; - #endif - - //Display Statistics - if(displayStatistics){ - GetStatistics(min,max,sum,lastImageArray,nPixelsX*nPixelsY); - lblMinDisp->setText(QString("%1").arg(min)); - lblMaxDisp->setText(QString("%1").arg(max)); - lblSumDisp->setText(QString("%1").arg(sum)); - } - - } - - UnlockLastImageArray(); - #ifdef VERBOSE - std::cout << "Trimbits Plot updated" <<'\n'; - #endif - return qDefs::OK; - } - - - -void qDrawPlot::SetPedestal(bool enable) { -#ifdef VERBOSE - std::cout << "Setting Pedestal to " << enable << '\n'; -#endif - if (enable) { - pedestal = true; - if (pedestalVals == 0) - RecalculatePedestal(); - } else { - pedestal = false; - } -} - - - -void qDrawPlot::RecalculatePedestal() { -#ifdef VERBOSE - std::cout << "Recalculating Pedestal\n"; -#endif - LockLastImageArray(); - startPedestalCal = 1; - pedestalCount = 0; - - //create array - if (pedestalVals) - delete[] pedestalVals; - pedestalVals = new double[nPixelsX * nPixelsY]; - if (tempPedestalVals) - delete[] tempPedestalVals; - tempPedestalVals = new double[nPixelsX * nPixelsY]; - //reset all values - for (unsigned int px = 0; px < (nPixelsX * nPixelsY); ++px) - pedestalVals[px] = 0; - for (unsigned int px = 0; px < (nPixelsX * nPixelsY); ++px) - tempPedestalVals[px] = 0; - UnlockLastImageArray(); -} - - - -void qDrawPlot::SetAccumulate(bool enable) { -#ifdef VERBOSE - std::cout << "Setting Accumulate to " << enable << '\n'; -#endif - accumulate = enable; -} - - - -void qDrawPlot::ResetAccumulate() { -#ifdef VERBOSE - std::cout << "Resetting Accumulation" << '\n'; -#endif - LockLastImageArray(); - resetAccumulate = true; - UnlockLastImageArray(); -} - - - -void qDrawPlot::SetPlotTimer(double time) { - // timerValue = time; - // if(myDet->setReceiverOnline()==slsDetectorDefs::ONLINE_FLAG){ - // time = myDet->setReceiverReadTimer(timerValue); - // #ifdef VERBOSE - // std::cout << "Receiver read timer set to : " << time <<'\n'; - // #endif - // qDefs::checkErrorMessage(myDet,"qDrawPlot::SetPlotTimer"); - // } -} - - - -void qDrawPlot::SetFrameFactor(int frame) { - // frameFactor = frame; - // if(myDet->setReceiverOnline()==slsDetectorDefs::ONLINE_FLAG){ - // frame = myDet->setReadReceiverFrequency(frame); - // #ifdef VERBOSE - // std::cout << "Receiver read frequency set to : " << frame <<'\n'; - // #endif - // } -} - - - -void qDrawPlot::UpdateAfterCloning(bool points, bool logy, bool interpolate, bool contour, bool logz) { -#ifdef VERBOSE - std::cout << "**Updating Plot After Cloning\n"; -#endif - - //1d - if (plot_in_scope == 1) { - SetMarkers(points); - emit LogySignal(logy); - } - //2d - else { - emit InterpolateSignal(interpolate); - emit ContourSignal(contour); - emit LogzSignal(logz); - } -} - - - -void qDrawPlot::SetBinary(bool enable, int from, int to) { -#ifdef VERBOSE - if (!enable) - std::cout << "Disabling Binary output \n"; - else - std::cout << "Enabling Binary output from " << from << " to " << to << '\n'; -#endif - binary = enable; - binaryFrom = from; - binaryTo = to; -} - - - -void qDrawPlot::DisplayStatistics(bool enable) { -#ifdef VERBOSE - if (!enable) - std::cout << "Disabling Statistics Display\n"; - else - std::cout << "Enabling Statistics Display\n"; -#endif - if (enable) - widgetStatistics->show(); - else - widgetStatistics->hide(); - - displayStatistics = enable; - lblMinDisp->setText("-"); - lblMaxDisp->setText("-"); - lblSumDisp->setText("-"); -} - - - -void qDrawPlot::GetStatistics(double &min, double &max, double &sum, double *array, int size) { -#ifdef VERYVERBOSE - std::cout << "Calculating Statistics\n"; -#endif - - for (int i = 0; i < size; ++i) { - //calculate min - if (array[i] < min) - min = array[i]; - //calculate max - if (array[i] > max) - max = array[i]; - //calculate sum - sum += array[i]; - } -} - - - -void qDrawPlot::EnableGainPlot(bool e) { -#ifdef VERBOSE - std::cout << "Setting Gain Data enable to " << e << '\n'; -#endif - gainDataEnable = e; -} - - - -void qDrawPlot::toDoublePixelData(double *dest, char *source, int size, int databytes, int dr, double *gaindest) { - int ichan = 0; - int ibyte = 0; - int halfbyte = 0; - char cbyte = '\0'; - - switch (dr) { - - case 4: - for (ibyte = 0; ibyte < databytes; ++ibyte) { - cbyte = source[ibyte]; - for (halfbyte = 1; halfbyte >= 0; --halfbyte) { - dest[ichan] = (cbyte >> (halfbyte * 4)) & 0xf; - ++ichan; - } - } - break; - - case 8: - for (ichan = 0; ichan < databytes; ++ichan) { - dest[ichan] = *((u_int8_t *)source); - ++source; - } - break; - - case 16: - if (detType == slsDetectorDefs::JUNGFRAU || detType == slsDetectorDefs::MOENCH) { - - // show gain plot - if (gaindest != NULL) { - for (ichan = 0; ichan < size; ++ichan) { - if ((*((u_int16_t *)source)) == 0xFFFF) { - gaindest[ichan] = 0xFFFF; - dest[ichan] = 0xFFFF; - } else { - gaindest[ichan] = (((*((u_int16_t *)source)) & 0xC000) >> 14); - dest[ichan] = ((*((u_int16_t *)source)) & 0x3FFF); - } - source += 2; - } - } - - // only data plot - else { - for (ichan = 0; ichan < size; ++ichan) { - /*if ( (*((u_int16_t*)source)) == 0xFFFF ) - dest[ichan] = 0xFFFF; - else*/ - dest[ichan] = ((*((u_int16_t *)source)) & 0x3FFF); - source += 2; - } - } - break; - } - - // other detectors - for (ichan = 0; ichan < size; ++ichan) { - dest[ichan] = *((u_int16_t *)source); - source += 2; - } - break; - - default: - for (ichan = 0; ichan < size; ++ichan) { - dest[ichan] = *((u_int32_t *)source); - source += 4; - } - break; - } -} +} \ No newline at end of file diff --git a/slsDetectorGui/src/qTabAdvanced.cpp b/slsDetectorGui/src/qTabAdvanced.cpp index a0d5a4b72..12c5c4bb3 100755 --- a/slsDetectorGui/src/qTabAdvanced.cpp +++ b/slsDetectorGui/src/qTabAdvanced.cpp @@ -11,7 +11,18 @@ QWidget(parent), myDet(detector) { FILE_LOG(logDEBUG) << "Advanced ready"; } -qTabAdvanced::~qTabAdvanced(){} +qTabAdvanced::~qTabAdvanced(){ + for (int i = 0; i < lblFromX.size(); ++i) { + delete lblFromX[i]; + delete lblFromY[i]; + delete lblToX[i]; + delete lblToY[i]; + delete spinFromX[i]; + delete spinFromY[i]; + delete spinToX[i]; + delete spinToY[i]; + } +} void qTabAdvanced::SetupWidgetWindow(){ // palette diff --git a/slsDetectorGui/src/qTabDataOutput.cpp b/slsDetectorGui/src/qTabDataOutput.cpp index 2298e6da1..995a90f00 100755 --- a/slsDetectorGui/src/qTabDataOutput.cpp +++ b/slsDetectorGui/src/qTabDataOutput.cpp @@ -10,13 +10,16 @@ #include -qTabDataOutput::qTabDataOutput(QWidget *parent, multiSlsDetector *detector) : QWidget(parent), myDet(detector) { +qTabDataOutput::qTabDataOutput(QWidget *parent, multiSlsDetector *detector) : QWidget(parent), myDet(detector), btnGroupRate(nullptr) { setupUi(this); SetupWidgetWindow(); FILE_LOG(logDEBUG) << "DataOutput ready"; } -qTabDataOutput::~qTabDataOutput() {} +qTabDataOutput::~qTabDataOutput() { + if (btnGroupRate) + delete btnGroupRate; +} void qTabDataOutput::SetupWidgetWindow() { // button group for rate diff --git a/slsDetectorGui/src/qTabDebugging.cpp b/slsDetectorGui/src/qTabDebugging.cpp index 474fd83eb..ba6d5ba8e 100755 --- a/slsDetectorGui/src/qTabDebugging.cpp +++ b/slsDetectorGui/src/qTabDebugging.cpp @@ -8,13 +8,22 @@ #include qTabDebugging::qTabDebugging(QWidget *parent, multiSlsDetector *detector) : - QWidget(parent), myDet(detector), treeDet(0), lblDetectorHostname(0), lblDetectorFirmware(0), lblDetectorSoftware(0) { + QWidget(parent), myDet(detector), treeDet(nullptr), lblDetectorHostname(nullptr), lblDetectorFirmware(nullptr), lblDetectorSoftware(nullptr) { setupUi(this); SetupWidgetWindow(); FILE_LOG(logDEBUG) << "Debugging ready"; } -qTabDebugging::~qTabDebugging() {} +qTabDebugging::~qTabDebugging() { + if (treeDet) + delete treeDet; + if (lblDetectorHostname) + delete lblDetectorHostname; + if (lblDetectorFirmware) + delete lblDetectorFirmware; + if (lblDetectorSoftware) + delete lblDetectorSoftware; +} void qTabDebugging::SetupWidgetWindow() { diff --git a/slsDetectorGui/src/qTabDeveloper.cpp b/slsDetectorGui/src/qTabDeveloper.cpp index 2cc923316..e5497f5ea 100755 --- a/slsDetectorGui/src/qTabDeveloper.cpp +++ b/slsDetectorGui/src/qTabDeveloper.cpp @@ -21,13 +21,39 @@ qTabDeveloper::qTabDeveloper(QWidget *parent, multiSlsDetector *detector) : QWidget(parent), myDet(detector), detType(slsDetectorDefs::GENERIC), numDACWidgets(0), numADCWidgets(0), - boxDacs(nullptr), boxAdcs(nullptr), lblHV(nullptr), comboHV(nullptr), dacLayout(nullptr), comboDetector(nullptr) { + boxDacs(nullptr), boxAdcs(nullptr), lblHV(nullptr), comboHV(nullptr), spinHV(nullptr), dacLayout(nullptr), comboDetector(nullptr), layout(nullptr) { SetupWidgetWindow(); Initialization(); FILE_LOG(logDEBUG) << "Developer ready"; } -qTabDeveloper::~qTabDeveloper() {} +qTabDeveloper::~qTabDeveloper() { + for (int i = 0; i < lblDacs.size(); ++i) { + delete lblDacs[i]; + delete lblDacsmV[i]; + delete spinDacs[i]; + } + for (int i = 0; i < lblAdcs.size(); ++i) { + delete lblAdcs[i]; + delete spinAdcs[i]; + } + if (boxDacs) + delete boxDacs; + if (boxAdcs) + delete boxAdcs; + if (lblHV) + delete lblHV; + if (comboHV) + delete comboHV; + if (spinHV) + delete spinHV; + if (dacLayout) + delete dacLayout; + if (comboDetector) + delete comboDetector; + if (layout) + delete layout; +} void qTabDeveloper::SetupWidgetWindow() { detType = myDet->getDetectorTypeAsEnum(); diff --git a/slsDetectorGui/src/qTabMeasurement.cpp b/slsDetectorGui/src/qTabMeasurement.cpp index be7b41c73..a43ed6ae5 100755 --- a/slsDetectorGui/src/qTabMeasurement.cpp +++ b/slsDetectorGui/src/qTabMeasurement.cpp @@ -8,13 +8,17 @@ #include -qTabMeasurement::qTabMeasurement(QWidget *parent, multiSlsDetector *detector, qDrawPlot *plot) : QWidget(parent), myDet(detector), myPlot(plot) { +qTabMeasurement::qTabMeasurement(QWidget *parent, multiSlsDetector *detector, qDrawPlot *plot) : QWidget(parent), myDet(detector), myPlot(plot), + progressTimer(nullptr) { setupUi(this); SetupWidgetWindow(); FILE_LOG(logDEBUG) << "Measurement ready"; } -qTabMeasurement::~qTabMeasurement() {} +qTabMeasurement::~qTabMeasurement() { + if (progressTimer) + delete progressTimer; +} bool qTabMeasurement::GetStartStatus(){ return (!btnStart->isEnabled()); @@ -523,8 +527,6 @@ void qTabMeasurement::SetFileWrite(bool val) { try { myDet->setFileWrite(val); - // for file save enable - myPlot->SetFileWrite(val); dispFileName->setEnabled(chkFile->isChecked()); } catch (const sls::NonCriticalError &e) { qDefs::ExceptionMessage("Could not set file write enable.", e.what(), "qTabMeasurement::SetFileWrite"); @@ -602,7 +604,7 @@ void qTabMeasurement::ResetProgress() { void qTabMeasurement::UpdateProgress() { FILE_LOG(logDEBUG) << "Updating progress"; progressBar->setValue(myPlot->GetProgress()); - lblCurrentFrame->setText(QString::number(myPlot->GetFrameIndex())); + lblCurrentFrame->setText(QString::number(myPlot->GetCurrentFrameIndex())); } int qTabMeasurement::VerifyOutputDirectoryError() { diff --git a/slsDetectorGui/src/qTabMessages.cpp b/slsDetectorGui/src/qTabMessages.cpp index 45b957259..b5a5bbe6b 100755 --- a/slsDetectorGui/src/qTabMessages.cpp +++ b/slsDetectorGui/src/qTabMessages.cpp @@ -13,14 +13,19 @@ #include #include -qTabMessages::qTabMessages(QWidget *parent) : QWidget(parent) { +qTabMessages::qTabMessages(QWidget *parent) : QWidget(parent), + dispLog(nullptr), btnSave(nullptr), btnClear(nullptr) { SetupWidgetWindow(); - Initialization(); FILE_LOG(logDEBUG) << "Messages ready"; } qTabMessages::~qTabMessages() { - delete dispLog; + if (dispLog) + delete dispLog; + if (btnSave) + delete btnSave; + if (btnClear) + delete btnClear; } void qTabMessages::SetupWidgetWindow() { @@ -49,6 +54,8 @@ void qTabMessages::SetupWidgetWindow() { qDebugStream(std::cout, this); qDebugStream(std::cerr, this); + + Initialization(); } void qTabMessages::Initialization() { diff --git a/slsDetectorGui/src/qTabPlot.cpp b/slsDetectorGui/src/qTabPlot.cpp index 76a4df8dd..eca334f25 100755 --- a/slsDetectorGui/src/qTabPlot.cpp +++ b/slsDetectorGui/src/qTabPlot.cpp @@ -27,7 +27,18 @@ qTabPlot::qTabPlot(QWidget *parent, multiSlsDetector *detector, qDrawPlot *plot) FILE_LOG(logDEBUG) << "Plot ready"; } -qTabPlot::~qTabPlot() {} +qTabPlot::~qTabPlot() { + if (btnGroupPlotType) + delete btnGroupPlotType; + if (stackedLayout) + delete stackedLayout; + if (spinNthFrame) + delete spinNthFrame; + if (spinTimeGap) + delete spinTimeGap; + if (comboTimeGapUnit) + delete comboTimeGapUnit; +} void qTabPlot::SetupWidgetWindow() { // button group for plot type @@ -157,7 +168,6 @@ void qTabPlot::Initialization() { // Save connect(btnSave, SIGNAL(clicked()), myPlot, SLOT(SavePlot())); - connect(chkSaveAll, SIGNAL(toggled(bool)), myPlot, SLOT(SaveAll(bool))); // Snapshot box connect(btnClone, SIGNAL(clicked()), myPlot, SLOT(ClonePlot())); @@ -236,6 +246,8 @@ void qTabPlot::SetPlot() { SetZRange(); } } + + myPlot->SetDataCallBack(plotEnable); } void qTabPlot::Set1DPlotOptionsRight() { diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index 487f5070d..38ba43453 100755 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -4091,8 +4091,13 @@ void multiSlsDetector::registerDataCallback(int (*userCallback)(detectorData *, dataReady = userCallback; pCallbackArg = pArg; if (setReceiverOnline() == slsDetectorDefs::ONLINE_FLAG) { - enableDataStreamingToClient(1); - enableDataStreamingFromReceiver(1); + if (dataReady == nullptr) { + enableDataStreamingToClient(0); + enableDataStreamingFromReceiver(0); + } else { + enableDataStreamingToClient(1); + enableDataStreamingFromReceiver(1); + } } }