/* * qDrawPlot.cpp * * Created on: May 7, 2012 * Author: Ian Johnson */ /** Qt Project Class Headers */ #include "qDrawPlot.h" #include "qCloneWidget.h" #include "SlsQt1DPlot.h" #include "SlsQt2DPlotLayout.h" /** Project Class Headers */ #include "slsDetector.h" #include "multiSlsDetector.h" /** Qt Include Headers */ #include #include #include /** C++ Include Headers */ #include #include using namespace std; #define Detector_Index 0 qDrawPlot::qDrawPlot(QWidget *parent,slsDetectorUtils*& detector):QWidget(parent),myDet(detector),numberOfMeasurements(1){ if(myDet) { SetupWidgetWindow(); Initialization(); StartStopDaqToggle(); //as default } } qDrawPlot::~qDrawPlot(){ /** Clear plot*/ Clear1DPlot(); for(QVector::iterator h = plot1D_hists.begin();h!=plot1D_hists.end();h++) delete *h; plot1D_hists.clear(); delete[] lastImageArray; lastImageArray=0; StartOrStopThread(0); delete myDet; 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)); 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(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); } void qDrawPlot::Initialization(){ connect(this, SIGNAL(InterpolateSignal(bool)), plot2D, SIGNAL(InterpolateSignal(bool))); connect(this, SIGNAL(ContourSignal(bool)), plot2D, SIGNAL(ContourSignal(bool))); connect(this, SIGNAL(LogzSignal(bool)), plot2D, SLOT(SetZScaleToLog(bool))); } void qDrawPlot::StartStopDaqToggle(bool stop_if_running){ static bool running = 1; if(running){ //stopping StartDaq(0); running=!running; }else if(!stop_if_running){ //then start StartDaq(1); running=!running; } } void qDrawPlot::StartDaq(bool start){ if(start){ #ifdef VERBOSE cout<<"Start Daq(1) function"<setTimer(slsDetectorDefs::FRAME_NUMBER,-1); cout<<"\tNumber of Exposures:"<setTimer(slsDetectorDefs::ACQUISITION_TIME,-1))*1E-9); cout<<"\tAcquisition Time:"<setTimer(slsDetectorDefs::FRAME_PERIOD,-1))*1E-9); cout<<"\tFrame Period:"<acquire(1);//acquiring } pthread_mutex_unlock(&gui_acquisition_start_stop_mutex); return gui_acquisition_thread_running; } void* qDrawPlot::DataAcquisionThread(void *this_pointer){ ((qDrawPlot*)this_pointer)->AcquireImages(); return this_pointer; } void* qDrawPlot::AcquireImages(){ //send data to detector static unsigned int nx=1280,ny=100; static double* image_data = new double[nx*ny]; if(!lastImageArray) lastImageArray = new double[nx*ny]; static double* xvalues = new double [nx]; static double* yvalues0 = new double [nx]; static double* yvalues1 = new double [nx]; if(!histXAxis) histXAxis = new double [nx]; if(!histYAxis[0]) histYAxis[0] = new double [nx]; if(!histYAxis[1]) histYAxis[1] = new double [nx]; // char cIndex[200]; //string filePath = myDet->getFilePath()+'/'+myDet->getFileName()+'_'; //cout<<"filePath:"<readDataFile(fileName,arg)==-1); ///////// //readout detector //fill and write data here for(unsigned int px=0;pxSetXTitle(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); plot_in_scope=2; } } void qDrawPlot::Clear1DPlot(){ for(QVector::iterator h = plot1D_hists.begin(); h!=plot1D_hists.end();h++) (*h)->Detach(plot1D); //clear plot } void qDrawPlot::UpdatePlot(){ //emit UpdatingPlot(); plot_update_timer->stop(); LockLastImageArray(); //1-d plot stuff if(histNBins){ plot1D->SetXTitle(histXAxisTitle.toAscii().constData()); plot1D->SetYTitle(histYAxisTitle.toAscii().constData()); for(int hist_num=0;hist_numplot1D_hists.size()){ plot1D_hists.append(h=new SlsQtH1D("1d plot",histNBins,histXAxis,GetHistYAxis(hist_num))); h->SetLineColor(hist_num+1); }else{ h=plot1D_hists.at(hist_num); h->SetData(histNBins,histXAxis,GetHistYAxis(hist_num)); } h->setTitle(GetHistTitle(hist_num)); h->Attach(plot1D); } plot1D->UnZoom(); } //2-d plot stuff static int last_plot_number = 0; if(lastImageArray){ if(lastImageNumber&&last_plot_number!=lastImageNumber && //there is a new plot nPixelsX>0&&nPixelsY>0){ plot2D->GetPlot()->SetData(nPixelsX,-0.5,nPixelsX-0.5,nPixelsY,-0.5,nPixelsY-0.5,lastImageArray); //as it inherits a widget plot2D->setTitle(GetImageTitle()); plot2D->SetXTitle(imageXAxisTitle); plot2D->SetYTitle(imageYAxisTitle); plot2D->SetZTitle(imageZAxisTitle); plot2D->UpdateNKeepSetRangeIfSet(); //this will keep a "set" z range, and call Plot()->Update(); } } last_plot_number=lastImageNumber; UnlockLastImageArray(); /* if(plot_in_scope==1) SelectPlot(1); else if(plot_in_scope==2) SelectPlot(2);*/ if(number_of_exposures==last_plot_number){ StartStopDaqToggle(1); emit UpdatingPlotFinished(); }else{ plot_update_timer->start(500); } } void qDrawPlot::StopUpdatePlot(){ plot_update_timer->stop(); } /**----------------------------CLONES-------------------------*/ void qDrawPlot::ClonePlot(){ int i=0; bool found = false; for(i=0;ititle(),(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); 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(); connect(this, SIGNAL(InterpolateSignal(bool)), plot2D, SIGNAL(InterpolateSignal(bool))); connect(this, SIGNAL(ContourSignal(bool)), plot2D, SIGNAL(ContourSignal(bool))); connect(this, SIGNAL(LogzSignal(bool)), plot2D, SLOT(SetZScaleToLog(bool))); winClone[i]->show(); connect(winClone[i], SIGNAL(CloneClosedSignal(int)),this, SLOT(CloneCloseEvent(int))); } void qDrawPlot::CloseClones(){ for(int i=0;iclose(); } void qDrawPlot::CloneCloseEvent(int id){ winClone[id]=0; #ifdef VERBOSE cout<<"Closing Clone Window id:"<