From 9f61104f0d6dc0d6a60294be90aa35e254740da0 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 27 Jun 2019 16:39:53 +0200 Subject: [PATCH] WIP --- slsDetectorGui/include/qCloneWidget.h | 8 +- slsDetectorGui/include/qDefs.h | 2 +- slsDetectorGui/include/qDrawPlot.h | 10 +- .../slsDetectorPlotting/include/SlsQt1DPlot.h | 2 + .../slsDetectorPlotting/include/SlsQt2DPlot.h | 4 +- slsDetectorGui/src/qCloneWidget.cpp | 134 +++----- slsDetectorGui/src/qDetectorMain.cpp | 4 - slsDetectorGui/src/qDrawPlot.cpp | 311 +++++++----------- slsDetectorGui/src/qTabPlot.cpp | 82 ++--- 9 files changed, 210 insertions(+), 347 deletions(-) diff --git a/slsDetectorGui/include/qCloneWidget.h b/slsDetectorGui/include/qCloneWidget.h index c499916e1..ce4183792 100755 --- a/slsDetectorGui/include/qCloneWidget.h +++ b/slsDetectorGui/include/qCloneWidget.h @@ -53,9 +53,10 @@ class qCloneWidget : public QMainWindow { /** * Set the range of the 1d plot * @param IsXYRange array of x,y,min,max if these values are set - * @param XYRangeValues array of set values of x,y, min, max + * @param XYRange array of set values of x,y, + * min, max */ - void SetRange(bool IsXYRange[], double XYRangeValues[]); + void SetRange(bool IsXYRange[], double XYRange[]); SlsQt1DPlot *Get1dPlot(); @@ -72,6 +73,7 @@ class qCloneWidget : public QMainWindow { char *GetCurrentTimeStamp(); void DisplayStats(bool enable, QString min, QString max, QString sum); + signals: void CloneClosedSignal(int); @@ -87,7 +89,7 @@ class qCloneWidget : public QMainWindow { QwtSymbol *marker; QwtSymbol *nomarker; QGridLayout *mainLayout; - QGroupBox *cloneBox; + QGroupBox *boxPlot; QLabel *lblHistTitle; }; diff --git a/slsDetectorGui/include/qDefs.h b/slsDetectorGui/include/qDefs.h index c1f50ee85..dbf937715 100755 --- a/slsDetectorGui/include/qDefs.h +++ b/slsDetectorGui/include/qDefs.h @@ -97,7 +97,7 @@ class qDefs : public QWidget { /** * range of x and y axes */ - enum range { XMINIMUM, XMAXIMUM, YMINIMUM, YMAXIMUM }; + enum range { XMIN, XMAX, YMIN, YMAX }; /** * function enums for the qServer and qClient diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index ead334b65..984404ee9 100755 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -106,15 +106,16 @@ class qDrawPlot : public QWidget { void Initialization(); void SetupStatistics(); void SetupPlots(); - int LockLastImageArray(); int UnlockLastImageArray(); void SetStyle(SlsQtH1D *h); void GetStatistics(double &min, double &max, double &sum, double *array, int size); void DetachHists(); - + void UpdateXYRange(); + + int StartDaqForGui(); int StopDaqForGui(); bool StartOrStopThread(bool start); @@ -130,6 +131,7 @@ class qDrawPlot : public QWidget { 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; @@ -162,8 +164,8 @@ class qDrawPlot : public QWidget { QString yTitle2d{"Pixel"}; QString zTitle2d{"Intensity"}; bool XYRangeChanged{false}; - double XYRangeValues[4]{0, 0, 0, 0}; - bool isXYRangeEnable[4]{false, false, false, false}; + double XYRange[4]{0, 0, 0, 0}; + bool isXYRange[4]{false, false, false, false}; // data unsigned int nHists{1}; diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h index c47d9b9df..fe0debe76 100755 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h @@ -120,6 +120,8 @@ class SlsQt1DPlot:public QwtPlot{ /** This group of functions have been added by Dhanya on 19.06.2012 to be able to use zooming functionality without mouse control*/ void DisableZoom(bool disableZoom); + void EnableXAutoScaling() {setAxisAutoScale(QwtPlot::xBottom, true);}; + void EnableYAutoScaling() {setAxisAutoScale(QwtPlot::yLeft, true);}; void SetXMinMax(double min,double max){setAxisScale(QwtPlot::xBottom,min,max);}; void SetYMinMax(double min,double max){setAxisScale(QwtPlot::yLeft,min,max);}; double GetXMinimum(){return hist_list->Hist()->GetXMin();}; diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlot.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlot.h index 30fb3bfe7..35d9261dd 100755 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlot.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlot.h @@ -69,7 +69,9 @@ public: /** This group of functions have been added by Dhanya on 19.06.2012 to be able to use zooming functionality without mouse control*/ - void DisableZoom(bool disableZoom); + void DisableZoom(bool disableZoom); + void EnableXAutoScaling() {setAxisAutoScale(QwtPlot::xBottom, true);}; + void EnableYAutoScaling() {setAxisAutoScale(QwtPlot::yLeft, true);}; void SetXMinMax(double min,double max){setAxisScale(QwtPlot::xBottom,min,max);}; void SetYMinMax(double min,double max){setAxisScale(QwtPlot::yLeft,min,max);}; double GetXMinimum(){return hist->GetXMin();}; diff --git a/slsDetectorGui/src/qCloneWidget.cpp b/slsDetectorGui/src/qCloneWidget.cpp index c7edd8d35..7576f20ed 100755 --- a/slsDetectorGui/src/qCloneWidget.cpp +++ b/slsDetectorGui/src/qCloneWidget.cpp @@ -25,7 +25,7 @@ qCloneWidget::qCloneWidget(QWidget *parent, int id, QString title, QString xTitle, QString yTitle, QString zTitle, int numDim, QString fPath, QString fName, int fIndex, bool displayStats, QString min, QString max, QString sum) : QMainWindow(parent), id(id), filePath(fPath), fileName(fName), fileIndex(fIndex), cloneplot1D(nullptr), cloneplot2D(nullptr), - marker(nullptr), nomarker(nullptr), mainLayout(nullptr), cloneBox(nullptr), lblHistTitle(nullptr) { + marker(nullptr), nomarker(nullptr), mainLayout(nullptr), boxPlot(nullptr), lblHistTitle(nullptr) { // Window title char winTitle[300], currTime[50]; strcpy(currTime, GetCurrentTimeStamp()); @@ -54,8 +54,8 @@ qCloneWidget::~qCloneWidget() { delete nomarker; if (mainLayout) delete mainLayout; - if (cloneBox) - delete cloneBox; + if (boxPlot) + delete boxPlot; if (lblHistTitle) delete lblHistTitle; } @@ -77,43 +77,44 @@ void qCloneWidget::SetupWidgetWindow(QString title, QString xTitle, QString yTit centralWidget->setLayout(mainLayout); //plot group box - cloneBox = new QGroupBox(this); - QGridLayout* gridClone = new QGridLayout(cloneBox); - cloneBox->setLayout(gridClone); - cloneBox->setContentsMargins(0, 0, 0, 0); - cloneBox->setAlignment(Qt::AlignHCenter); - cloneBox->setFont(QFont("Sans Serif", 11, QFont::Normal)); - cloneBox->setTitle(title); + boxPlot = new QGroupBox(this); + QGridLayout* plotLayout = new QGridLayout(boxPlot); + boxPlot->setLayout(plotLayout); + boxPlot->setAlignment(Qt::AlignHCenter); + boxPlot->setFont(QFont("Sans Serif", 11, QFont::Normal)); + boxPlot->setTitle(title); + boxPlot->setContentsMargins(0, 0, 0, 0); + // According to dimensions, create appropriate 1D or 2Dplot if (numDim == 1) { - cloneplot1D = new SlsQt1DPlot(cloneBox); + cloneplot1D = new SlsQt1DPlot(boxPlot); cloneplot1D->setFont(QFont("Sans Serif", 9, QFont::Normal)); cloneplot1D->SetXTitle(xTitle.toAscii().constData()); cloneplot1D->SetYTitle(yTitle.toAscii().constData()); - cloneBox->setFlat(false); - cloneBox->setContentsMargins(0, 30, 0, 0); - gridClone->addWidget(cloneplot1D, 0, 0); + boxPlot->setFlat(false); + boxPlot->setContentsMargins(0, 30, 0, 0); + plotLayout->addWidget(cloneplot1D, 0, 0); lblHistTitle = new QLabel(""); mainLayout->addWidget(lblHistTitle, 0, 0); } else { - cloneplot2D = new SlsQt2DPlotLayout(cloneBox); + cloneplot2D = new SlsQt2DPlotLayout(boxPlot); cloneplot2D->setFont(QFont("Sans Serif", 9, QFont::Normal)); cloneplot2D->SetXTitle(xTitle); cloneplot2D->SetYTitle(yTitle); cloneplot2D->SetZTitle(zTitle); cloneplot2D->setAlignment(Qt::AlignLeft); - cloneBox->setFlat(true); - cloneBox->setContentsMargins(0, 20, 0, 0); - gridClone->addWidget(cloneplot2D, 0, 0); + boxPlot->setFlat(true); + boxPlot->setContentsMargins(0, 20, 0, 0); + plotLayout->addWidget(cloneplot2D, 0, 0); } // main window widgets - mainLayout->addWidget(cloneBox, 1, 0); + mainLayout->addWidget(boxPlot, 1, 0); setCentralWidget(centralWidget); // Save @@ -126,36 +127,18 @@ void qCloneWidget::SetupWidgetWindow(QString title, QString xTitle, QString yTit void qCloneWidget::SetCloneHists(unsigned int nHists, int histNBins, double *histXAxis, std::vector histYAxis, std::vector histTitle, bool lines, bool markers) { //for each plot, create hists for (unsigned 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[hist_num])); - k->SetLineColor(0); - } else { - k = cloneplot1D_hists.at(hist_num); - k->SetData(histNBins, histXAxis, histYAxis[hist_num]); - } - - //style of plot - if (lines) - k->setStyle(QwtPlotCurve::Lines); - else - k->setStyle(QwtPlotCurve::Dots); + SlsQtH1D *h = new SlsQtH1D("1d plot", histNBins, histXAxis, histYAxis[hist_num]); + h->SetLineColor(0); + h->setStyle(lines ? QwtPlotCurve::Lines : QwtPlotCurve::Dots); #if QWT_VERSION < 0x060000 - if (markers) - k->setSymbol(*marker); - else - k->setSymbol(*nomarker); + h->setSymbol(markers ? *marker : *nomarker); #else - if (markers) - k->setSymbol(marker); - else - k->setSymbol(nomarker); + h->setSymbol(markers ? marker : nomarker); #endif + cloneplot1D_hists.append(h); + h->Attach(cloneplot1D); - //set title and attach plot lblHistTitle->setText(QString(histTitle[0].c_str())); - - k->Attach(cloneplot1D); } } @@ -164,49 +147,16 @@ void qCloneWidget::SetCloneHists2D(int nbinsx, double xmin, double xmax, int nbi cloneplot2D->KeepZRangeIfSet(); } -void qCloneWidget::SetRange(bool IsXYRange[], double XYRangeValues[]) { - double XYCloneRangeValues[4]; - - if (!IsXYRange[qDefs::XMINIMUM]) { - if (cloneplot1D) - XYCloneRangeValues[qDefs::XMINIMUM] = cloneplot1D->GetXMinimum(); - else - XYCloneRangeValues[qDefs::XMINIMUM] = cloneplot2D->GetPlot()->GetXMinimum(); - } else - XYCloneRangeValues[qDefs::XMINIMUM] = XYRangeValues[qDefs::XMINIMUM]; - - if (!IsXYRange[qDefs::XMAXIMUM]) { - if (cloneplot1D) - XYCloneRangeValues[qDefs::XMAXIMUM] = cloneplot1D->GetXMaximum(); - else - XYCloneRangeValues[qDefs::XMAXIMUM] = cloneplot2D->GetPlot()->GetXMaximum(); - } else - XYCloneRangeValues[qDefs::XMAXIMUM] = XYRangeValues[qDefs::XMAXIMUM]; - - if (!IsXYRange[qDefs::YMINIMUM]) { - if (cloneplot1D) - XYCloneRangeValues[qDefs::YMINIMUM] = cloneplot1D->GetYMinimum(); - else - XYCloneRangeValues[qDefs::YMINIMUM] = cloneplot2D->GetPlot()->GetYMinimum(); - } else - XYCloneRangeValues[qDefs::YMINIMUM] = XYRangeValues[qDefs::YMINIMUM]; - - if (!IsXYRange[qDefs::YMAXIMUM]) { - if (cloneplot1D) - XYCloneRangeValues[qDefs::YMAXIMUM] = cloneplot1D->GetYMaximum(); - else - XYCloneRangeValues[qDefs::YMAXIMUM] = cloneplot2D->GetPlot()->GetYMaximum(); - } else - XYCloneRangeValues[qDefs::YMAXIMUM] = XYRangeValues[qDefs::YMAXIMUM]; - - if (cloneplot1D) { - cloneplot1D->SetXMinMax(XYCloneRangeValues[qDefs::XMINIMUM], XYCloneRangeValues[qDefs::XMAXIMUM]); - cloneplot1D->SetYMinMax(XYCloneRangeValues[qDefs::YMINIMUM], XYCloneRangeValues[qDefs::YMAXIMUM]); - } else { - cloneplot2D->GetPlot()->SetXMinMax(XYRangeValues[qDefs::XMINIMUM], XYRangeValues[qDefs::XMAXIMUM]); - cloneplot2D->GetPlot()->SetYMinMax(XYRangeValues[qDefs::YMINIMUM], XYRangeValues[qDefs::YMAXIMUM]); - cloneplot2D->GetPlot()->Update(); +void qCloneWidget::SetRange(bool IsXYRange[], double XYRange[]) { + double XYRange[4] {0, 0, 0, 0}; + void* plot = cloneplot1D; + if (cloneplot2D) { + plot = cloneplot2D->GetPlot(); } + + plot->SetXMinMax(XYRange[qDefs::XMIN], XYRange[qDefs::XMAX]); + plot->SetYMinMax(XYRange[qDefs::YMIN], XYRange[qDefs::YMAX]); + plot->Update(); } void qCloneWidget::SavePlot() { @@ -216,9 +166,9 @@ void qCloneWidget::SavePlot() { QString fName = filePath + Qstring('/') + fileName + Qstring('_') + imageIndex + Qstring('_') + QString(NowTime().c_str()) + QString(".png"); FILE_LOG(logDEBUG) << "fname:" << fName.toAscii().constData(); //save - QImage img(cloneBox->size().width(), cloneBox->size().height(), QImage::Format_RGB32); + QImage img(boxPlot->size().width(), boxPlot->size().height(), QImage::Format_RGB32); QPainter painter(&img); - cloneBox->render(&painter); + boxPlot->render(&painter); fName = QFileDialog::getSaveFileName(this, tr("Save Snapshot "), fName, tr("PNG Files (*.png);;XPM Files(*.xpm);;JPEG Files(*.jpg)"), 0, QFileDialog::ShowDirsOnly); if (!fName.isEmpty()) { @@ -226,9 +176,7 @@ void qCloneWidget::SavePlot() { qDefs::Message(qDefs::INFORMATION, "The SnapShot has been successfully saved", "qCloneWidget::SavePlot"); FILE_LOG(logINFO) << "The SnapShot has been successfully saved"; } else { - qDefs::Message(qDefs::WARNING, "Attempt to save snapshot failed.\n" - "Formats: .png, .jpg, .xpm.", - "qCloneWidget::SavePlot"); + qDefs::Message(qDefs::WARNING, "Attempt to save snapshot failed.\n Formats: .png, .jpg, .xpm.", "qCloneWidget::SavePlot"); FILE_LOG(logWARNING) << "Attempt to save snapshot failed"; } } @@ -241,9 +189,9 @@ int qCloneWidget::SavePlotAutomatic() { QString fName = filePath + Qstring('/') + fileName + Qstring('_') + imageIndex + Qstring('_') + QString(NowTime().c_str()) + QString(".png"); FILE_LOG(logDEBUG) << "fname:" << fName.toAscii().constData(); //save - QImage img(cloneBox->size().width(), cloneBox->size().height(), QImage::Format_RGB32); + QImage img(boxPlot->size().width(), boxPlot->size().height(), QImage::Format_RGB32); QPainter painter(&img); - cloneBox->render(&painter); + boxPlot->render(&painter); if (img.save(fName)) return 0; else diff --git a/slsDetectorGui/src/qDetectorMain.cpp b/slsDetectorGui/src/qDetectorMain.cpp index 572437b52..41ee7a75f 100755 --- a/slsDetectorGui/src/qDetectorMain.cpp +++ b/slsDetectorGui/src/qDetectorMain.cpp @@ -721,10 +721,6 @@ void qDetectorMain::EnableTabs() { tabDeveloper->Refresh(); tabPlot->Refresh(); - - // set the plot type first(acccss shared memory) - tabPlot->SetScanArgument(); - // sets running to true myPlot->StartStopDaqToggle(); } else { // to enable scan box tabPlot->Refresh(); diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index ded91a3e2..9550169cd 100755 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -220,10 +220,10 @@ void qDrawPlot::SetupPlots() { } // add a hist DetachHists(); - SlsQtH1D *h; - hists1d.append(h = new SlsQtH1D("", nPixelsX, datax1d, datay1d[0])); + SlsQtH1D *h = new SlsQtH1D("", nPixelsX, datax1d, datay1d[0]); h->SetLineColor(0); SetStyle(h); + hists1d.append(h); // setup 2d plot plot2d = new SlsQt2DPlotLayout(boxPlot); @@ -377,14 +377,14 @@ void qDrawPlot::SetXYRangeChanged() { void qDrawPlot::SetXYRangeValues(double val, qDefs::range xy) { LockLastImageArray(); FILE_LOG(logDEBUG) << "Setting XY Range [" << static_cast(xy) << "] to " << val; - XYRangeValues[xy] = val; + XYRange[xy] = val; UnlockLastImageArray(); } void qDrawPlot::IsXYRangeValues(bool changed, qDefs::range xy) { LockLastImageArray(); FILE_LOG(logDEBUG) << "Setting XY Range Change [" << static_cast(xy) << "] to " << std::boolalpha << changed << std::noboolalpha;; - isXYRangeEnable[xy] = changed; + isXYRange[xy] = changed; UnlockLastImageArray(); } @@ -592,8 +592,8 @@ void qDrawPlot::ClonePlot() { data2d); } - if (isXYRangeEnable[qDefs::XMINIMUM] || isXYRangeEnable[qDefs::XMAXIMUM] ||isXYRangeEnable[qDefs::YMINIMUM] ||isXYRangeEnable[qDefs::YMAXIMUM]) { - cloneWidgets[i]->SetRange(isXYRangeEnable, XYRangeValues); + if (isXYRange[qDefs::XMIN] || isXYRange[qDefs::XMAX] ||isXYRange[qDefs::YMIN] ||isXYRange[qDefs::YMAX]) { + cloneWidgets[i]->SetRange(isXYRange, XYRange); } UnlockLastImageArray(); cloneWidgets[i]->show(); @@ -603,18 +603,19 @@ void qDrawPlot::ClonePlot() { } void qDrawPlot::CloseClones() { + FILE_LOG(logDEBUG) << "Closing all Clones"; for (auto &it : cloneWidgets) { it->close(); } +} - void qDrawPlot::CloneCloseEvent(int id) { +void qDrawPlot::CloneCloseEvent(int id) { + FILE_LOG(logDEBUG) << "Closing Clone " << id; cloneWidgets.erase(cloneWidgets.begin() + id; -#ifdef VERBOSE - std::cout << "Closing Clone Window id:" << id << '\n'; -#endif - } +} void qDrawPlot::SaveClones() { + FILE_LOG(logINFO) << "Saving all Clones"; char errID[200]; std::string errMessage = "The Snapshots with ID's: "; bool success = true; @@ -625,44 +626,41 @@ void qDrawPlot::SaveClones() { errMessage.append(std::string(errID) + std::string(", ")); } } - if (success) + if (success) { qDefs::Message( qDefs::INFORMATION, "The Snapshots have all been saved successfully in .png.", "Dock"); - else + } else { qDefs::Message(qDefs::WARNING, errMessage + std::string("were not saved."), "qDrawPlot::SaveClones"); + FILE_LOG(logWARNING) << errMessage << "were not saved"; + } +} + +void qDrawPlot::SavePlot() { + // render image + QImage savedImage(size().width(), size().height(), QImage::Format_RGB32); + QPainter painter(&savedImage); + render(&painter); + + QString fName = fileSavePath + Qstring('/') + fileSaveName + Qstring('_') + lastImageNumber + Qstring('_') + QString(NowTime().c_str()) + QString(".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"); + fileSavePath = fName.section('/', 0, -2); + } else { + qDefs::Message(qDefs::WARNING, "Attempt to save image failed.\n Formats: .png, .jpg, .xpm.", "qDrawPlot::SavePlot"); + } + } } - void qDrawPlot::SavePlot() { - // render image - QImage savedImage(size().width(), size().height(), - QImage::Format_RGB32); - QPainter painter(&savedImage); - render(&painter); - - QString fName = fileSavePath + Qstring('/') + fileSaveName + Qstring('_') + lastImageNumber + Qstring('_') + QString(NowTime().c_str()) + QString(".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"); - fileSavePath = fName.section('/', 0, -2); - - } else - qDefs::Message(qDefs::WARNING, - "Attempt to save image failed.\n" - "Formats: .png, .jpg, .xpm.", - "qDrawPlot::SavePlot"); - } - } @@ -691,25 +689,23 @@ int qDrawPlot::UnlockLastImageArray() { } void qDrawPlot::SetStyle(SlsQtH1D *h) { - if (isLines) - h->setStyle(QwtPlotCurve::isLines); - else - h->setStyle(QwtPlotCurve::Dots); + h->setStyle(isLines ? QwtPlotCurve::Lines : QwtPlotCurve::Dots); #if QWT_VERSION < 0x060000 - if (isMarkers) - h->setSymbol(*marker); - else - h->setSymbol(*noMarker); + h->setSymbol(isMarkers ? *marker : *nomarker); #else - if (isMarkers) - h->setSymbol(marker); - else - h->setSymbol(noMarker); + h->setSymbol(isMarkers ? marker : nomarker); #endif } -void qDrawPlot::GetStatistics(double &min, double &max, double &sum, double *array, int size) { +void qDrawPlot::GetStatistics(double &min, double &max, double &sum) { FILE_LOG(logDEBUG) << "Calculating Statistics"; + double *array = data2d; + int size = nPixelsX * nPixelsY; + if(is1d) { + array = datay1d[0]; + size = nPixelsX; + } + , int size for (int i = 0; i < size; ++i) { if (array[i] < min) min = array[i]; @@ -719,6 +715,42 @@ void qDrawPlot::GetStatistics(double &min, double &max, double &sum, double *arr } } +void qDrawPlot::DetachHists() { + for (QVector::iterator h = hists1d.begin(); h != hists1d.end(); ++h) { + (*h)->Detach(plot1d); + } +} + +void qDrawPlot::UpdateXYRange() { + if (XYRangeChanged) { + void* plot = plot1d; + if (!is1d) { + plot = plot2d->GetPlot(); + } + + if (!isXYRange[qDefs::XMIN] || !isXYRange[qDefs::XMAX]) { + plot->EnableXAutoScaling(); + } else { + if (!isXYRange[qDefs::XMIN]) + XYRange[qDefs::XMIN] = plot->GetXMinimum(); + if (!isXYRange[qDefs::XMAX]) + XYRange[qDefs::XMAX] = plot->GetXMaximum(); + plot->SetXMinMax(XYRange[qDefs::XMIN], XYRange[qDefs::XMAX]); + } + + if (!isXYRange[qDefs::YMIN] || !isXYRange[qDefs::YMAX]) { + plot->EnableYAutoScaling(); + } else { + if (!isXYRange[qDefs::YMIN]) + XYRange[qDefs::YMIN] = plot->GetYMinimum(); + if (!isXYRange[qDefs::YMAX]) + XYRange[qDefs::YMAX] = plot->GetYMaximum(); + plot->SetYMinMax(XYRange[qDefs::YMIN], XYRange[qDefs::YMAX]); + } + XYRangeChanged = false; + plot->Update(); + } +} @@ -1657,11 +1689,6 @@ int qDrawPlot::MeasurementFinished(int currentMeasurementIndex, int fileIndex) { boxPlot->setTitle("OLD_plot.raw");*/ return 0; } -void qDrawPlot::DetachHists() { - for (QVector::iterator h = hists1d.begin(); h != hists1d.end(); ++h) { - (*h)->Detach(plot1d); - } -} void qDrawPlot::UpdatePlot() { #ifdef VERYVERBOSE @@ -1686,166 +1713,50 @@ void qDrawPlot::UpdatePlot() { plot1d->SetXTitle(xTitle1d.toAscii().constData()); plot1d->SetYTitle(yTitle1d.toAscii().constData()); - // histogram - if (histogram) { - plotHistogram->setData( - new QwtIntervalSeriesData(histogramSamples)); - plotHistogram->setPen(QPen(Qt::red)); - plotHistogram->setBrush( - QBrush(Qt::red, Qt::Dense4Pattern)); // Qt::SolidPattern + for (int hist_num = 0; hist_num < (int)nHists; ++hist_num) { + SlsQtH1D *h; + if (hist_num + 1 > hists1d.size()) { + hists1d.append(h = new SlsQtH1D("", nPixelsX, datax1d, datay1d[0])); + h->SetLineColor(hist_num); + } else { + h = hists1d.at(hist_num); + h->SetData(nPixelsX, datax1d, datay1d[hist_num]); + } + SetStyle(h); lblFrameIndexTitle1d->setText(title1d[0].c_str()); - 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()); - - } - // not histogram - else { - for (int hist_num = 0; hist_num < (int)nHists; ++hist_num) { - SlsQtH1D *h; - if (hist_num + 1 > hists1d.size()) { - if (anglePlot) - hists1d.append( - h = new SlsQtH1D("", nPixelsX, - histXAngleAxis, - histYAngleAxis)); - else - hists1d.append( - h = new SlsQtH1D("", nPixelsX, datax1d, - datay1d[0])); - h->SetLineColor(hist_num); - } else { - h = hists1d.at(hist_num); - if (anglePlot) - h->SetData(nPixelsX, histXAngleAxis, - histYAngleAxis); - else - h->SetData(nPixelsX, datax1d, - datay1d[hist_num]); - } - SetStyle(h); - lblFrameIndexTitle1d->setText(title1d[0].c_str()); - h->Attach(plot1d); - } - - /**moved from below (had applied to histograms as well) to - * here, */ - // update range if required - if (XYRangeChanged) { - 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 - if (displayStatistics) { - double min = 0, max = 0, sum = 0; - if (anglePlot) - GetStatistics(min, max, sum, histYAngleAxis, - nPixelsX); - else - GetStatistics(min, max, sum, datay1d[0], nPixelsX); - lblMinDisp->setText(QString("%1").arg(min)); - lblMaxDisp->setText(QString("%1").arg(max)); - lblSumDisp->setText(QString("%1").arg(sum)); - widgetStatistics->show(); - } + h->Attach(plot1d); } } } // 2-d plot stuff else { - if (data2d) { - if (nPixelsX > 0 && nPixelsY > 0) { plot2d->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, - nPixelsY, startPixel, endPixel, - data2d); + nPixelsY, startPixel, endPixel,data2d); 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 + // 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(); - } - } - // update range if required - if (XYRangeChanged) { - 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 (gainDataExtracted) { - gainplot2d->GetPlot()->Update(); + gainplot2d->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, + startPixel, endPixel, gainImage); + gainplot2d->setTitle(title2d.c_str()); gainplot2d->setFixedWidth(plot2d->width() / 4); gainplot2d->setFixedHeight(plot2d->height() / 4); gainplot2d->show(); } else gainplot2d->hide(); - // Display Statistics - if (displayStatistics) { - double min = 0, max = 0, sum = 0; - GetStatistics(min, max, sum, data2d, nPixelsX * nPixelsY); - lblMinDisp->setText(QString("%1").arg(min)); - lblMaxDisp->setText(QString("%1").arg(max)); - lblSumDisp->setText(QString("%1").arg(sum)); - } - } } + UpdateXYRange(); + // Display Statistics + if (displayStatistics) { + double min = 0, max = 0, sum = 0; + GetStatistics(min, max, sum); + lblMinDisp->setText(QString("%1").arg(min)); + lblMaxDisp->setText(QString("%1").arg(max)); + lblSumDisp->setText(QString("%1").arg(sum)); + } + // set plot title boxPlot->setTitle(plotTitle); // to notify the measurement finished when its done diff --git a/slsDetectorGui/src/qTabPlot.cpp b/slsDetectorGui/src/qTabPlot.cpp index ecdeda476..41cd157b5 100755 --- a/slsDetectorGui/src/qTabPlot.cpp +++ b/slsDetectorGui/src/qTabPlot.cpp @@ -429,53 +429,53 @@ void qTabPlot::SetXYRange() { // xmin // if unchecked, empty or invalid (set to false so it takes the min/max of plot) if (!chkXMin->isChecked() || dispXMin->text().isEmpty()) { - myPlot->IsXYRangeValues(false, qDefs::XMINIMUM); + myPlot->IsXYRangeValues(false, qDefs::XMIN); } else if (dispXMin->text().toDouble() < myPlot->GetXMinimum()) { qDefs::Message(qDefs::WARNING, "XMin Outside Plot Range", "qTabPlot::SetXRange"); dispXMin->setText(""); - myPlot->IsXYRangeValues(false, qDefs::XMINIMUM); + myPlot->IsXYRangeValues(false, qDefs::XMIN); } else { - myPlot->SetXYRangeValues(dispXMin->text().toDouble(), qDefs::XMINIMUM); - myPlot->IsXYRangeValues(true, qDefs::XMINIMUM); + myPlot->SetXYRangeValues(dispXMin->text().toDouble(), qDefs::XMIN); + myPlot->IsXYRangeValues(true, qDefs::XMIN); disablezoom = true; } //xmax if (!chkXMax->isChecked() || dispXMax->text().isEmpty()) { - myPlot->IsXYRangeValues(false, qDefs::XMAXIMUM); + myPlot->IsXYRangeValues(false, qDefs::XMAX); } else if (dispXMax->text().toDouble() < myPlot->GetXMaximum()) { qDefs::Message(qDefs::WARNING, "XMax Outside Plot Range", "qTabPlot::SetXYRange"); dispXMax->setText(""); - myPlot->IsXYRangeValues(false, qDefs::XMAXIMUM); + myPlot->IsXYRangeValues(false, qDefs::XMAX); } else { - myPlot->SetXYRangeValues(dispXMax->text().toDouble(), qDefs::XMAXIMUM); - myPlot->IsXYRangeValues(true, qDefs::XMAXIMUM); + myPlot->SetXYRangeValues(dispXMax->text().toDouble(), qDefs::XMAX); + myPlot->IsXYRangeValues(true, qDefs::XMAX); disablezoom = true; } // ymin if (!chkYMin->isChecked() || dispYMin->text().isEmpty()) { - myPlot->IsXYRangeValues(false, qDefs::YMINIMUM); + myPlot->IsXYRangeValues(false, qDefs::YMIN); } else if (dispYMin->text().toDouble() < myPlot->GetYMinimum()) { qDefs::Message(qDefs::WARNING, "YMin Outside Plot Range", "qTabPlot::SetXYRange"); dispYMin->setText(""); - myPlot->IsXYRangeValues(false, qDefs::YMINIMUM); + myPlot->IsXYRangeValues(false, qDefs::YMIN); } else { - myPlot->SetXYRangeValues(dispYMin->text().toDouble(), qDefs::YMINIMUM); - myPlot->IsXYRangeValues(true, qDefs::YMINIMUM); + myPlot->SetXYRangeValues(dispYMin->text().toDouble(), qDefs::YMIN); + myPlot->IsXYRangeValues(true, qDefs::YMIN); disablezoom = true; } //ymax if (!chkYMax->isChecked() || dispYMax->text().isEmpty()) { - myPlot->IsXYRangeValues(false, qDefs::YMAXIMUM); + myPlot->IsXYRangeValues(false, qDefs::YMAX); } else if (dispYMax->text().toDouble() < myPlot->GetYMaximum()) { qDefs::Message(qDefs::WARNING, "YMax Outside Plot Range", "qTabPlot::SetXYRange"); dispYMax->setText(""); - myPlot->IsXYRangeValues(false, qDefs::YMAXIMUM); + myPlot->IsXYRangeValues(false, qDefs::YMAX); } else { - myPlot->SetXYRangeValues(dispYMax->text().toDouble(), qDefs::YMAXIMUM); - myPlot->IsXYRangeValues(true, qDefs::YMAXIMUM); + myPlot->SetXYRangeValues(dispYMax->text().toDouble(), qDefs::YMAX); + myPlot->IsXYRangeValues(true, qDefs::YMAX); disablezoom = true; } @@ -518,25 +518,25 @@ void qTabPlot::MaintainAspectRatio(int dimension) { // calculate ideal aspect ratio with previous limits double ranges[4]; - ranges[qDefs::XMINIMUM] = myPlot->GetXMinimum(); - ranges[qDefs::XMAXIMUM] = myPlot->GetXMaximum(); - ranges[qDefs::YMINIMUM] = myPlot->GetYMinimum(); - ranges[qDefs::YMAXIMUM] = myPlot->GetYMaximum(); - double idealAspectratio = (ranges[qDefs::XMAXIMUM] - ranges[qDefs::XMINIMUM]) / (ranges[qDefs::YMAXIMUM] - ranges[qDefs::YMINIMUM]); - FILE_LOG(logDEBUG) << "Ideal Aspect ratio: " << idealAspectratio << " for x(" << ranges[qDefs::XMINIMUM] << " - " << ranges[qDefs::XMAXIMUM] << "), y(" << ranges[qDefs::YMINIMUM] << " - " << ranges[qDefs::YMAXIMUM] << ")"; + ranges[qDefs::XMIN] = myPlot->GetXMinimum(); + ranges[qDefs::XMAX] = myPlot->GetXMaximum(); + ranges[qDefs::YMIN] = myPlot->GetYMinimum(); + ranges[qDefs::YMAX] = myPlot->GetYMaximum(); + double idealAspectratio = (ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) / (ranges[qDefs::YMAX] - ranges[qDefs::YMIN]); + FILE_LOG(logDEBUG) << "Ideal Aspect ratio: " << idealAspectratio << " for x(" << ranges[qDefs::XMIN] << " - " << ranges[qDefs::XMAX] << "), y(" << ranges[qDefs::YMIN] << " - " << ranges[qDefs::YMAX] << ")"; // calculate current aspect ratio - ranges[qDefs::XMINIMUM] = dispXMin->text().toDouble(); - ranges[qDefs::XMAXIMUM] = dispXMax->text().toDouble(); - ranges[qDefs::YMINIMUM] = dispYMin->text().toDouble(); - ranges[qDefs::YMAXIMUM] = dispYMax->text().toDouble(); - double currentAspectRatio = (ranges[qDefs::XMAXIMUM] - ranges[qDefs::XMINIMUM]) / (ranges[qDefs::YMAXIMUM] - ranges[qDefs::YMINIMUM]); - FILE_LOG(logDEBUG) << "Current Aspect ratio: " << currentAspectRatio << " for x(" << ranges[qDefs::XMINIMUM] << " - " << ranges[qDefs::XMAXIMUM] << "), y(" << ranges[qDefs::YMINIMUM] << " - " << ranges[qDefs::YMAXIMUM] << ")"; + ranges[qDefs::XMIN] = dispXMin->text().toDouble(); + ranges[qDefs::XMAX] = dispXMax->text().toDouble(); + ranges[qDefs::YMIN] = dispYMin->text().toDouble(); + ranges[qDefs::YMAX] = dispYMax->text().toDouble(); + double currentAspectRatio = (ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) / (ranges[qDefs::YMAX] - ranges[qDefs::YMIN]); + FILE_LOG(logDEBUG) << "Current Aspect ratio: " << currentAspectRatio << " for x(" << ranges[qDefs::XMIN] << " - " << ranges[qDefs::XMAX] << "), y(" << ranges[qDefs::YMIN] << " - " << ranges[qDefs::YMAX] << ")"; if (currentAspectRatio != idealAspectratio) { // dimension: 1(x changed: y adjusted), 0(y changed: x adjusted), -1(aspect ratio clicked: larger one adjusted) if (dimension == -1) { - dimension = ((ranges[qDefs::XMAXIMUM] - ranges[qDefs::XMINIMUM]) > (ranges[qDefs::YMAXIMUM] - ranges[qDefs::YMINIMUM])) + dimension = ((ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) > (ranges[qDefs::YMAX] - ranges[qDefs::YMIN])) ? static_cast(slsDetectorDefs::X) : static_cast(slsDetectorDefs::Y); } @@ -544,24 +544,24 @@ void qTabPlot::MaintainAspectRatio(int dimension) { // adjust x double newval = 0; if (dimension == static_cast(slsDetectorDefs::X)) { - newval = idealAspectratio * (ranges[qDefs::YMAXIMUM] - ranges[qDefs::YMINIMUM]) + ranges[qDefs::XMINIMUM]; + newval = idealAspectratio * (ranges[qDefs::YMAX] - ranges[qDefs::YMIN]) + ranges[qDefs::XMIN]; if (newval <= myPlot->GetXMaximum()) { dispXMax->setText(QString::number(newval)); FILE_LOG(logDEBUG) << "New XMax: " << newval; } else { - newval = ranges[qDefs::XMAXIMUM] - (idealAspectratio * (ranges[qDefs::YMAXIMUM] - ranges[qDefs::YMINIMUM])); + newval = ranges[qDefs::XMAX] - (idealAspectratio * (ranges[qDefs::YMAX] - ranges[qDefs::YMIN])); dispXMin->setText(QString::number(newval)); FILE_LOG(logDEBUG) << "New XMin: " << newval; } } // adjust y else { - newval = ((ranges[qDefs::XMAXIMUM] - ranges[qDefs::XMINIMUM]) / idealAspectratio) + ranges[qDefs::YMINIMUM]; + newval = ((ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) / idealAspectratio) + ranges[qDefs::YMIN]; if (newval <= myPlot->GetYMaximum()) { dispYMax->setText(QString::number(newval)); FILE_LOG(logDEBUG) << "New YMax: " << newval; } else { - newval = ranges[qDefs::YMAXIMUM] - ((ranges[qDefs::XMAXIMUM] - ranges[qDefs::XMINIMUM]) / idealAspectratio); + newval = ranges[qDefs::YMAX] - ((ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) / idealAspectratio); dispYMin->setText(QString::number(newval)); FILE_LOG(logDEBUG) << "New YMax: " << newval; } @@ -578,15 +578,15 @@ void qTabPlot::MaintainAspectRatio(int dimension) { connect(dispYMax, SIGNAL(editingFinished()), this, SLOT(SetYRange())); // set XY values in plot - myPlot->SetXYRangeValues(dispXMin->text().toDouble(), qDefs::XMINIMUM); - myPlot->SetXYRangeValues(dispXMax->text().toDouble(), qDefs::XMAXIMUM); - myPlot->SetXYRangeValues(dispYMin->text().toDouble(), qDefs::YMINIMUM); - myPlot->SetXYRangeValues(dispYMax->text().toDouble(), qDefs::YMAXIMUM); + myPlot->SetXYRangeValues(dispXMin->text().toDouble(), qDefs::XMIN); + myPlot->SetXYRangeValues(dispXMax->text().toDouble(), qDefs::XMAX); + myPlot->SetXYRangeValues(dispYMin->text().toDouble(), qDefs::YMIN); + myPlot->SetXYRangeValues(dispYMax->text().toDouble(), qDefs::YMAX); - myPlot->IsXYRangeValues(true, qDefs::XMINIMUM); - myPlot->IsXYRangeValues(true, qDefs::XMAXIMUM); - myPlot->IsXYRangeValues(true, qDefs::YMINIMUM); - myPlot->IsXYRangeValues(true, qDefs::YMAXIMUM); + myPlot->IsXYRangeValues(true, qDefs::XMIN); + myPlot->IsXYRangeValues(true, qDefs::XMAX); + myPlot->IsXYRangeValues(true, qDefs::YMIN); + myPlot->IsXYRangeValues(true, qDefs::YMAX); // to update plot with range myplot->SetXYRangeChanged();