diff --git a/slsDetectorGui/forms/form_tab_dataoutput.ui b/slsDetectorGui/forms/form_tab_dataoutput.ui index 9461e31bf..628d20f66 100644 --- a/slsDetectorGui/forms/form_tab_dataoutput.ui +++ b/slsDetectorGui/forms/form_tab_dataoutput.ui @@ -6,7 +6,7 @@ 0 0 - 748 + 734 339 @@ -44,6 +44,29 @@ PushButton + + + + 10 + 10 + 108 + 16 + + + + Output Directory: + + + + + + 118 + 10 + 113 + 21 + + + diff --git a/slsDetectorGui/forms/form_tab_plot.ui b/slsDetectorGui/forms/form_tab_plot.ui index 9b3c1d0fa..5f485af19 100644 --- a/slsDetectorGui/forms/form_tab_plot.ui +++ b/slsDetectorGui/forms/form_tab_plot.ui @@ -483,7 +483,7 @@ 10 20 551 - 16 + 27 @@ -494,11 +494,31 @@ + + + + Qt::NoFocus + + + Clear + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + - gridLayoutWidget_3 - btnClear - gridLayoutWidget_4 @@ -628,9 +648,9 @@ 599 - 41 + 10 121 - 80 + 111 @@ -639,10 +659,10 @@ - 10 - 10 - 101 - 71 + 20 + 20 + 81 + 81 @@ -653,7 +673,7 @@ 9 - -1 + 13 @@ -690,28 +710,6 @@ - - - - 600 - 16 - 121 - 21 - - - - - - - Qt::NoFocus - - - Clear - - - - - diff --git a/slsDetectorGui/include/qCloneWidget.h b/slsDetectorGui/include/qCloneWidget.h index d7dc22472..4cf22c26f 100644 --- a/slsDetectorGui/include/qCloneWidget.h +++ b/slsDetectorGui/include/qCloneWidget.h @@ -9,63 +9,93 @@ #define QCLONEWIDGET_H_ /** Qt Project Class Headers */ +class SlsQtH1D; class SlsQt1DPlot; class SlsQt2DPlotLayout; /** Qt Include Headers */ #include +#include #include #include #include #include -#include #include #include #include +#include #include +/** C++ Include Headers */ +#include +using namespace std; /** *@short Sets up the clone plot widget */ -class qCloneWidget:public QMainWindow{ +class qCloneWidget:public QFrame{ Q_OBJECT public: /** \short The constructor */ - qCloneWidget(QWidget *parent,int id,QSize fSize,QString title,int numDim,SlsQt1DPlot*& plot1D,SlsQt2DPlotLayout*& plot2D); + qCloneWidget(QWidget *parent,int id,QString title,int numDim,SlsQt1DPlot*& plot1D,SlsQt2DPlotLayout*& plot2D,string FilePath); /** Destructor */ ~qCloneWidget(); + /** Sets up the widget window + * @param title title of the image with frame number + * @param numDim 1D or 2D + * @param plot1D plot1d object reference + * @param plot2D plot2d object reference + * */ + void SetupWidgetWindow(QString title,int numDim,SlsQt1DPlot*& plot1D,SlsQt2DPlotLayout*& plot2D); - /** Get the 1D plot reference - */ - SlsQt1DPlot* Get1Dplot(){ return cloneplot1D;}; -public slots: + /** Get the 1D hist values to plot + * @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 + * */ + void SetCloneHists(int nHists,int histNBins,double* histXAxis,double* histYAxis[],string histTitle[]); private: /** clone window id*/ int id; - /** clone 1D Plot */ - SlsQt1DPlot* cloneplot1D; + /** Default Save file path */ + string filePath; + /** clone 2D Plot */ SlsQt2DPlotLayout* cloneplot2D; + /** clone 1D Plot */ + SlsQt1DPlot* cloneplot1D; + /** vector of 1D hist values */ + QVector cloneplot1D_hists; + QGridLayout *mainLayout; - QGroupBox *boxSave; - QWidget *horizontalLayoutWidget; + QGroupBox *cloneBox; + QGridLayout *gridClone; + QGroupBox *boxSave; QHBoxLayout *layoutSave; - QLabel *lblFName; + QLabel *lblFName; QHBoxLayout *hLayoutSave; - QLineEdit *dispFName; - QComboBox *comboFormat; + QLineEdit *dispFName; + QComboBox *comboFormat; QPushButton *btnSave; - QCheckBox *chkAutoFName; - QCheckBox *chkSaveAll; + QCheckBox *chkAutoFName; + QCheckBox *chkSaveAll; + + + +private slots: +/** Save Plot */ +void SavePlot(); + protected: void closeEvent(QCloseEvent* event); diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index 520e7ce55..910e893b4 100644 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -23,6 +23,8 @@ class qCloneWidget; #include #include +#define MAX_1DPLOTS 10 + /** *@short Sets up the plot widget @@ -93,7 +95,7 @@ private: SlsQt2DPlotLayout* plot2D; /** vector of 1D hist values */ QVector plot1D_hists; - QVector cloneplot1D_hists; + /**variables for threads */ /** */ @@ -123,7 +125,7 @@ private: /** Number of graphs in 1D */ unsigned int nHists; /** Title for all the graphs in 1D */ - std::string histTitle[10]; + std::string histTitle[MAX_1DPLOTS]; /** X Axis Title in 1D */ QString histXAxisTitle; /** Y Axis Title in 1D */ @@ -133,7 +135,7 @@ private: /** X Axis value in 1D */ double* histXAxis; /** Y Axis value in 1D */ - double* histYAxis[10]; + double* histYAxis[MAX_1DPLOTS]; /** */ @@ -148,9 +150,9 @@ private: /** */ const char* GetImageTitle() {return imageTitle.c_str();} /** */ - const char* GetHistTitle(int i) {return (i>=0&&i<10) ? histTitle[i].c_str():0;} //int for hist number + const char* GetHistTitle(int i) {return (i>=0&&i=0&&i<10) ? histYAxis[i]:0;} //int for hist number + double* GetHistYAxis(int i) {return (i>=0&&i -#include -#include - +#include +#include /** C++ Include Headers */ #include -#include -#include using namespace std; -qCloneWidget::qCloneWidget(QWidget *parent,int id,QSize fSize,QString title,int numDim,SlsQt1DPlot*& plot1D,SlsQt2DPlotLayout*& plot2D):QMainWindow(parent),id(id){ +qCloneWidget::qCloneWidget(QWidget *parent,int id,QString title,int numDim,SlsQt1DPlot*& plot1D,SlsQt2DPlotLayout*& plot2D,string FilePath):QFrame(parent,Qt::Popup|Qt::SubWindow),id(id),filePath(FilePath){ + /** Window title*/ + char winTitle[100]; + sprintf(winTitle,"SLS Detector GUI Clone %d",id); + setWindowTitle(QString(winTitle)); - -/* mainLayout = new QGridLayout(this); - setLayout(mainLayout);*/ - - - - - QGroupBox *cloneBox = new QGroupBox(this); - QGridLayout *gridClone = new QGridLayout(cloneBox); - cloneBox->setLayout(gridClone); - cloneBox->resize(fSize); - cloneBox->setTitle(title); - cloneBox->setAlignment(Qt::AlignHCenter); - cloneBox->setFont(QFont("Sans Serif",11,QFont::Bold)); - if(numDim==1){ - cloneplot1D = plot1D; - gridClone->addWidget(cloneplot1D,0,0); - cloneBox->setFlat(false); - - }else{ - cloneplot2D = plot2D; - gridClone->addWidget(cloneplot2D,0,0); - cloneBox->setFlat(true); - } - - cloneBox->setCentralWidget(); - -/* - boxSave = new QGroupBox(this); - layoutSave = new QHBoxLayout; - boxSave->setLayout(layoutSave); - - lblFName = new QLabel(layoutSave); - lblFName->setText("File Name:"); - layoutSave->addWidget(lblFName); - - - - hLayoutSave = new QHBoxLayout(); - hLayoutSave->setSpacing(0); - - dispFName = new QLineEdit(layoutSave); - hLayoutSave->addWidget(dispFName); - - comboFormat = new QComboBox(layoutSave); - comboFormat->setFrame(true); - comboFormat->insertItem(".gif"); - comboFormat->insertItem(".pdf"); - comboFormat->insertItem(".png"); - comboFormat->insertItem(".gif+"); - comboFormat->insertItem(".jpg"); - comboFormat->insertItem(".ps"); - comboFormat->insertItem(".eps"); - comboFormat->insertItem(".xpm"); - comboFormat->insertItem(".C"); - hLayoutSave->addWidget(comboFormat); - - layoutSave->addLayout(hLayoutSave); - - - btnSave = new QPushButton(layoutSave); - bnSave->setText("Save"); - QSizePolicy sizePolicy2(QSizePolicy::Fixed, QSizePolicy::Fixed); - sizePolicy2.setHeightForWidth(btnSave->sizePolicy().hasHeightForWidth()); - btnSave->setSizePolicy(sizePolicy2); - btnSave->setFocusPolicy(Qt::NoFocus); - layoutSave->addWidget(btnSave); - - chkAutoFName = new QCheckBox(layoutSave); - chkAutoFName->setText("Automatic File Name"); - layoutSave->addWidget(chkAutoFName); - - chkSaveAll = new QCheckBox(layoutSave); - chkSaveAll->setText("Save All") - layoutSave->addWidget(chkSaveAll); - - - - gridClone->addWidget(boxSave,0,0); - mainLayout->addWidget(boxSave,1,1);*/ -/* - mainLayout->addWidget(cloneBox,0,0);*/ + /** Set up widget*/ + SetupWidgetWindow(title,numDim,plot1D,plot2D); } @@ -115,9 +35,129 @@ qCloneWidget::qCloneWidget(QWidget *parent,int id,QSize fSize,QString title,int qCloneWidget::~qCloneWidget(){ delete cloneplot1D; delete cloneplot2D; + delete cloneBox; + delete boxSave; } + +void qCloneWidget::SetupWidgetWindow(QString title,int numDim,SlsQt1DPlot*& plot1D,SlsQt2DPlotLayout*& plot2D){ + + /** Main Window Layout */ + mainLayout = new QGridLayout(this); + setLayout(mainLayout); + + /** plot group box*/ + cloneBox = new QGroupBox(this); + gridClone = new QGridLayout(cloneBox); + cloneBox->setLayout(gridClone); + cloneBox->setContentsMargins(0,0,0,0); + //cloneBox->resize(400,200); + cloneBox->setTitle(title); + cloneBox->setAlignment(Qt::AlignHCenter); + cloneBox->setFont(QFont("Sans Serif",11,QFont::Bold)); + /** According to dimensions, create appropriate 1D or 2Dplot */ + if(numDim==1){ + cloneplot1D = plot1D; + gridClone->addWidget(cloneplot1D,0,0); + cloneBox->setFlat(false); + cloneBox->setContentsMargins(0,30,0,0); + + }else{ + cloneplot2D = plot2D; + //cloneplot2D->setContentsMargins(0,0,0,0); + gridClone->addWidget(cloneplot2D,0,0); + cloneBox->setFlat(true); + cloneBox->setContentsMargins(0,5,0,0); + } + + /** Save group box */ + boxSave = new QGroupBox("Save",this); + boxSave->setFixedHeight(45); + boxSave->setContentsMargins(0,8,0,0); + layoutSave = new QHBoxLayout; + boxSave->setLayout(layoutSave); + /** Label file name*/ + lblFName = new QLabel("File Name:",this); + layoutSave->addWidget(lblFName); + /** To get 0 spacing between the next 2 widgets file name and file format */ + hLayoutSave = new QHBoxLayout(); + layoutSave->addLayout(hLayoutSave); + hLayoutSave->setSpacing(0); + /** file name */ + dispFName = new QLineEdit(this); + hLayoutSave->addWidget(dispFName); + /** file format */ + comboFormat = new QComboBox(this); + comboFormat->setFrame(true); + comboFormat->addItem(".gif"); + comboFormat->addItem(".pdf"); + comboFormat->addItem(".png"); + comboFormat->addItem(".gif+"); + comboFormat->addItem(".jpg"); + comboFormat->addItem(".ps"); + comboFormat->addItem(".eps"); + comboFormat->addItem(".xpm"); + comboFormat->addItem(".C"); + hLayoutSave->addWidget(comboFormat); + /** save button */ + btnSave = new QPushButton("Save",this); + btnSave->setFocusPolicy(Qt::NoFocus); + layoutSave->addWidget(btnSave); + /** automatic file name check box */ + chkAutoFName = new QCheckBox("Automatic File Name",this); + layoutSave->addWidget(chkAutoFName); + /** automatic save all check box */ + chkSaveAll = new QCheckBox("Save All",this); + layoutSave->addWidget(chkSaveAll); + + /** main window widgets */ + mainLayout->addWidget(boxSave,0,0); + mainLayout->addWidget(cloneBox,1,0); + + /** Save */ + connect(btnSave, SIGNAL(clicked()), this, SLOT(SavePlot())); + + +} + + + + +void qCloneWidget::SetCloneHists(int nHists,int histNBins,double* histXAxis,double* histYAxis[],string histTitle[]){ +/** for each plot*/ +for(int hist_num=0;hist_numcloneplot1D_hists.size()){ + cloneplot1D_hists.append(k=new SlsQtH1D("1d plot",histNBins,histXAxis,histYAxis[hist_num])); + k->SetLineColor(hist_num+1); + }else{ + k=cloneplot1D_hists.at(hist_num); + k->SetData(histNBins,histXAxis,histYAxis[hist_num]); + } + k->setTitle(histTitle[hist_num].c_str()); + k->Attach(cloneplot1D); +} +cloneplot1D->UnZoom(); + + +} + + + + +void qCloneWidget::SavePlot(){ + QString fName = QString(filePath.c_str())+'/'+dispFName->text()+comboFormat->currentText(); + QImage img(cloneBox->size().width(),cloneBox->size().height(),QImage::Format_RGB32); + QPainter painter(&img); + cloneBox->render(&painter); + img.save(fName); +} + + + + void qCloneWidget::closeEvent(QCloseEvent* event){ emit CloneClosedSignal(id); event->accept(); diff --git a/slsDetectorGui/src/qDetectorMain.cpp b/slsDetectorGui/src/qDetectorMain.cpp index b47612df3..5b5ec9fca 100644 --- a/slsDetectorGui/src/qDetectorMain.cpp +++ b/slsDetectorGui/src/qDetectorMain.cpp @@ -82,6 +82,7 @@ void qDetectorMain::SetUpWidgetWindow(){ layoutTabs= new QGridLayout; centralwidget->setLayout(layoutTabs); + /** plot setup*/ myPlot = new qDrawPlot(dockWidgetPlot,myDet); dockWidgetPlot->setWidget(myPlot); diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index 73e6dc70f..ba249a1c0 100644 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -14,6 +14,8 @@ #include "multiSlsDetector.h" /** Qt Include Headers */ #include +#include +#include /** C++ Include Headers */ #include #include @@ -60,7 +62,7 @@ void qDrawPlot::SetupWidgetWindow(){ nHists = 0; histNBins = 0; histXAxis = 0; - for(int i=0;i<10;i++) histYAxis[i]=0; + for(int i=0;isetLayout(layout); + boxPlot = new QGroupBox("Measurement"); + layout->addWidget(boxPlot,1,1); boxPlot->setAlignment(Qt::AlignHCenter); boxPlot->setFont(QFont("Sans Serif",11,QFont::Bold)); - layout->addWidget(boxPlot,1,1); - this->setLayout(layout); - plot_update_timer = new QTimer(this); connect(plot_update_timer, SIGNAL(timeout()), this, SLOT(UpdatePlot())); + + /** Defaults - only for the initial picture*/ + histXAxisTitle="Channel Number"; + histYAxisTitle="Counts"; + for(int i=0;isetFont(QFont("Sans Serif",9,QFont::Normal)); + plot1D->SetXTitle(histXAxisTitle.toAscii().constData()); + plot1D->SetYTitle(histYAxisTitle.toAscii().constData()); plot1D->hide(); plot2D = new SlsQt2DPlotLayout(boxPlot); plot2D->setFont(QFont("Sans Serif",9,QFont::Normal)); - plot2D->setTitle("Start Image"); + plot2D->setTitle(GetImageTitle()); + plot2D->SetXTitle(imageXAxisTitle); + plot2D->SetYTitle(imageYAxisTitle); + plot2D->SetZTitle(imageZAxisTitle); plot2D->setAlignment(Qt::AlignLeft); boxPlot->setFlat(true); + //QSizePolicy sizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); + //boxPlot->setSizePolicy(sizePolicy); plotLayout = new QGridLayout(boxPlot); plotLayout->addWidget(plot1D,1,1,1,1); plotLayout->addWidget(plot2D,1,1,1,1); + + boxPlot->setContentsMargins(0,15,0,0); } @@ -219,7 +243,7 @@ void* qDrawPlot::AcquireImages(){ - char cIndex[200]; +// char cIndex[200]; //string filePath = myDet->getFilePath()+'/'+myDet->getFileName()+'_'; //cout<<"filePath:"<SetXTitle(histXAxisTitle.toAscii().constData()); + plot1D->SetYTitle(histYAxisTitle.toAscii().constData()); plot1D->show(); plot2D->hide(); boxPlot->setFlat(false); plot_in_scope=1; }else{ + plot2D->SetXTitle(imageXAxisTitle); + plot2D->SetYTitle(imageYAxisTitle); + plot2D->SetZTitle(imageZAxisTitle); plot1D->hide(); plot2D->show(); boxPlot->setFlat(true); @@ -391,6 +420,8 @@ void qDrawPlot::StopUpdatePlot(){ +/**----------------------------CLONES-------------------------*/ + void qDrawPlot::ClonePlot(){ int i=0; @@ -405,30 +436,22 @@ void qDrawPlot::ClonePlot(){ exit(-1); } - winClone[i] = new qCloneWidget(this,i,boxPlot->size(),boxPlot->title(),(int)plot_in_scope,plot1D,plot2D); + winClone[i] = new qCloneWidget(this,i,boxPlot->title(),(int)plot_in_scope,plot1D,plot2D,myDet->getFilePath()); if(plot_in_scope==1){ plot1D = new SlsQt1DPlot(boxPlot); plot1D->setFont(QFont("Sans Serif",9,QFont::Normal)); + plot1D->SetXTitle(histXAxisTitle.toAscii().constData()); + plot1D->SetYTitle(histYAxisTitle.toAscii().constData()); plotLayout->addWidget(plot1D,1,1,1,1); - /** Somehow the 1d plot hists are lost*/ - SlsQtH1D* h; - for(int hist_num=0;hist_numcloneplot1D_hists.size()){ - cloneplot1D_hists.append(k=new SlsQtH1D("1d plot",histNBins,histXAxis,GetHistYAxis(hist_num))); - k->SetLineColor(hist_num+1); - }else{ - k=cloneplot1D_hists.at(hist_num); - k->SetData(histNBins,histXAxis,GetHistYAxis(hist_num)); - } - k->setTitle(GetHistTitle(hist_num)); - k->Attach(winClone[i]->Get1Dplot()); - } - winClone[i]->Get1Dplot()->UnZoom(); + winClone[i]->SetCloneHists((int)nHists,histNBins,histXAxis,histYAxis,histTitle); } else{ plot2D = new SlsQt2DPlotLayout(boxPlot); plot2D->setFont(QFont("Sans Serif",9,QFont::Normal)); + plot2D->setTitle(GetImageTitle()); + plot2D->SetXTitle(imageXAxisTitle); + plot2D->SetYTitle(imageYAxisTitle); + plot2D->SetZTitle(imageZAxisTitle); plotLayout->addWidget(plot2D,1,1,1,1); } UpdatePlot(); @@ -455,3 +478,15 @@ void qDrawPlot::CloneCloseEvent(int id){ #endif } + + + + + +/**----------------------------SAVE-------------------------*/ +void qDrawPlot::SavePlot(QString FName){ + QImage img(size().width(),size().height(),QImage::Format_RGB32); + QPainter painter(&img); + render(&painter); + img.save(FName); +} diff --git a/slsDetectorGui/src/qTabPlot.cpp b/slsDetectorGui/src/qTabPlot.cpp index be95ad67e..ed39e931a 100644 --- a/slsDetectorGui/src/qTabPlot.cpp +++ b/slsDetectorGui/src/qTabPlot.cpp @@ -36,6 +36,7 @@ qTabPlot::qTabPlot(QWidget *parent,slsDetectorUtils*& detector, qDrawPlot*& plot //This also selects the text if unchecked //includes setupwidgetwindow //SelectPlot(1); + Select1DPlot(false); Initialization(); } } @@ -65,13 +66,15 @@ void qTabPlot::SetupWidgetWindow(){ dispXMax->setEnabled(false); dispYMax->setEnabled(false); dispZMax->setEnabled(false); + + //dispFName->setText(QString(myDet->getFilePath().c_str())+'/'); + } void qTabPlot::Select1DPlot(bool b){ SetupWidgetWindow(); if(b){ - myPlot->Select1DPlot(); box1D->setEnabled(true); box2D->setEnabled(false); chkZAxis->setEnabled(false); @@ -81,8 +84,8 @@ void qTabPlot::Select1DPlot(bool b){ dispXAxis->setText(defaultHistXAxisTitle); myPlot->SetHistYAxisTitle(defaultHistYAxisTitle); dispYAxis->setText(defaultHistYAxisTitle); + myPlot->Select1DPlot(); }else{ - myPlot->Select2DPlot(); box1D->setEnabled(false); box2D->setEnabled(true); chkZAxis->setEnabled(true); @@ -94,6 +97,7 @@ void qTabPlot::Select1DPlot(bool b){ dispYAxis->setText(defaultImageYAxisTitle); myPlot->SetImageZAxisTitle(defaultImageZAxisTitle); dispZAxis->setText(defaultImageZAxisTitle); + myPlot->Select2DPlot(); } } @@ -115,12 +119,13 @@ void qTabPlot::Initialization(){ connect(dispXAxis, SIGNAL(returnPressed()), this, SLOT(SetTitles())); connect(dispYAxis, SIGNAL(returnPressed()), this, SLOT(SetTitles())); connect(dispZAxis, SIGNAL(returnPressed()), this, SLOT(SetTitles())); - /** Common Buttons*/ - connect(btnClear, SIGNAL(clicked()),myPlot, SLOT(Clear1DPlot())); + connect(btnClear, SIGNAL(clicked()), myPlot, SLOT(Clear1DPlot())); +/** Save */ + connect(btnSave, SIGNAL(clicked()), this, SLOT(SavePlot())); /** test for 1D*/ - connect(chktest1D, SIGNAL(toggled(bool)), this, SLOT(Select1DPlot(bool))); + connect(chktest1D, SIGNAL(toggled(bool)), this, SLOT(Select1DPlot(bool))); } @@ -194,4 +199,7 @@ void qTabPlot::EnableTitles(){ } - +void qTabPlot::SavePlot(){ + QString fullFileName = QString(myDet->getFilePath().c_str())+'/'+dispFName->text()+comboFormat->currentText(); + myPlot->SavePlot(fullFileName); +}