diff --git a/slsDetectorGui/forms/form_tab_plot.ui b/slsDetectorGui/forms/form_tab_plot.ui index f50abeb2b..241c8e944 100644 --- a/slsDetectorGui/forms/form_tab_plot.ui +++ b/slsDetectorGui/forms/form_tab_plot.ui @@ -99,7 +99,7 @@ - 3 + 0 @@ -107,7 +107,7 @@ 20 5 - 327 + 336 26 @@ -192,7 +192,7 @@ 25 5 - 95 + 100 26 @@ -300,7 +300,7 @@ 20 5 - 77 + 81 26 @@ -548,7 +548,7 @@ 25 5 - 128 + 314 26 @@ -577,6 +577,43 @@ Displays minimum, maximum and sum of values for each plot. + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 100 + 10 + + + + + + + + true + + + + 0 + 0 + + + + <nobr> +Displays minimum, maximum and sum of values for each plot. +<nobr> + + + Gain Plot + + + @@ -771,7 +808,7 @@ Displays minimum, maximum and sum of values for each plot. - 4 + 5 @@ -779,7 +816,7 @@ Displays minimum, maximum and sum of values for each plot. 25 5 - 107 + 108 26 @@ -1024,7 +1061,7 @@ Displays minimum, maximum and sum of values for each plot. 25 5 - 95 + 100 26 @@ -1057,7 +1094,7 @@ Displays minimum, maximum and sum of values for each plot. 25 5 - 77 + 81 26 @@ -1315,7 +1352,7 @@ All values between <b>from</b> and <b>to</b> will be res 25 5 - 128 + 132 26 @@ -1533,7 +1570,7 @@ Displays minimum, maximum and sum of values for each plot. 10 20 - 227 + 233 26 @@ -1658,7 +1695,7 @@ Displays minimum, maximum and sum of values for each plot. 10 20 - 342 + 331 26 @@ -1828,28 +1865,6 @@ Displays minimum, maximum and sum of values for each plot. - - - - - 0 - 0 - - - - - 250 - 0 - - - - QLineEdit::Normal - - - false - - - @@ -2158,6 +2173,41 @@ Displays minimum, maximum and sum of values for each plot. + + + + + 0 + 0 + + + + + 250 + 0 + + + + QLineEdit::Normal + + + false + + + + + + + + 0 + 0 + + + + Keep Aspect Ratio + + + @@ -2187,7 +2237,7 @@ Displays minimum, maximum and sum of values for each plot. 10 20 - 358 + 355 26 @@ -2243,11 +2293,11 @@ Displays minimum, maximum and sum of values for each plot. Qt::Horizontal - QSizePolicy::Fixed + QSizePolicy::Preferred - 45 + 40 10 @@ -2259,11 +2309,11 @@ Displays minimum, maximum and sum of values for each plot. Qt::Horizontal - QSizePolicy::Fixed + QSizePolicy::Preferred - 45 + 40 10 @@ -2471,9 +2521,9 @@ Interval between plots has 2 modes. A condition to be satisfied, in order to avo 10 - 15 + 12 331 - 31 + 36 @@ -2788,7 +2838,7 @@ Interval between plots has 2 modes. A condition to be satisfied, in order to avo 10 20 - 351 + 331 26 diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index 10393b386..5dc9bdcb7 100644 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -145,6 +145,15 @@ public: /** 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() { if(plot_in_scope==1) return plot1D->GetXMinimum(); else plot2D->GetPlot()->GetXMinimum();}; + /** Get X Maximum value from plot */ + double GetXMaximum() { if(plot_in_scope==1) return plot1D->GetXMaximum(); else plot2D->GetPlot()->GetXMaximum();}; + /** Get Y Minimum value from plot */ + double GetYMinimum() { if(plot_in_scope==1) return plot1D->GetYMinimum(); else plot2D->GetPlot()->GetYMinimum();}; + /** Get Y Maximum value from plot */ + double GetYMaximum() { if(plot_in_scope==1) return plot1D->GetYMaximum(); else plot2D->GetPlot()->GetYMaximum();}; + public slots: /** To select 1D or 2D plot @param i is 1 for 1D, else 2D plot */ @@ -313,6 +322,11 @@ void ShowSaveErrorMessage(QString fileName); * @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); private: @@ -348,7 +362,6 @@ SlsQt2DPlotLayout* plot2D; /** vector of 1D hist values */ QVector plot1D_hists; - /**label with frame index for those with many frames per file*/ QLabel *histFrameIndexTitle; @@ -571,7 +584,12 @@ QVector histogramSamples; bool plotRequired; - +/** 2D object second plot */ +SlsQt2DPlotLayout* gainplot2D; +/** Current Image Values in 2D gain plot */ +double* gainImageArray; +/** gain plot enable */ +bool gainPlotEnable; signals: void UpdatingPlotFinished(); @@ -579,12 +597,12 @@ void InterpolateSignal(bool); void ContourSignal(bool); void LogzSignal(bool); void LogySignal(bool); -void SetZRangeSignal(double,double); void ResetZMinZMaxSignal(bool,bool,double,double); void SetCurrentMeasurementSignal(int); void saveErrorSignal(QString); void AcquisitionErrorSignal(QString); void UpdatePlotSignal(); +void GainPlotSignal(bool); }; diff --git a/slsDetectorGui/include/qTabPlot.h b/slsDetectorGui/include/qTabPlot.h index 9ed83be7e..92fcae92a 100644 --- a/slsDetectorGui/include/qTabPlot.h +++ b/slsDetectorGui/include/qTabPlot.h @@ -124,10 +124,30 @@ private slots: /** Enables/Sets default Titles to default */ void EnableTitles(); - /** Enables range of the axes */ + /** check aspect ratio */ + void checkAspectRatio(); + + /** maintain aspect ratio + * @param axis axis to be changed: 0 for x(y axis values changed), 1 for y (xaxis values changes), -1 for the larger one (aspect ratio checked) + */ + void maintainAspectRatio(int axis); + + /** Enables range of the X axis */ + void EnableXRange(); + + /** Enables range of the Y axis */ + void EnableYRange(); + + /** Enables range of all axes, called by EnableXRange and EnableYRange */ void EnableRange(); - /** Sets the range of the x and y axes */ + /** Sets the range of the x axis */ + void SetXAxisRange(); + + /** Sets the range of the y axis */ + void SetYAxisRange(); + + /** Sets the range of both axes, called by SetXAxisRange and SetYAxisRange */ void SetAxesRange(); /** Sets the range of the z axis */ @@ -156,7 +176,6 @@ private slots: signals: void DisableZoomSignal(bool); - void SetZRangeSignal(double,double); void ResetZMinZMaxSignal(bool,bool,double,double); }; diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index b6fa8795e..315823258 100644 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -49,6 +49,7 @@ qDrawPlot::~qDrawPlot(){ for(QVector::iterator h = plot1D_hists.begin();h!=plot1D_hists.end();h++) delete *h; plot1D_hists.clear(); if(lastImageArray) delete[] lastImageArray; lastImageArray=0; + if(gainImageArray) delete[] gainImageArray; gainImageArray=0; StartOrStopThread(0); delete myDet; myDet = 0; for(int i=0;isetContentsMargins(0,0,0,0); - plotLayout->addWidget(plot1D,0,0,1,1); - plotLayout->addWidget(plot2D,0,0,1,1); + plotLayout->addWidget(plot1D,0,0,3,3); + plotLayout->addWidget(plot2D,0,0,3,3); + + + //gainplot + gainplot2D = new SlsQt2DPlotLayout(boxPlot); + gainImageArray = new double[nPixelsY*nPixelsX]; + for(unsigned int px=0;pxsetFont(QFont("Sans Serif",9,QFont::Normal)); + gainplot2D->GetPlot()->SetData(nPixelsX,-0.5,nPixelsX-0.5,nPixelsY,startPixel,endPixel,gainImageArray); + gainplot2D->setTitle(GetImageTitle()); + gainplot2D->SetXTitle(imageXAxisTitle); + gainplot2D->SetYTitle(imageYAxisTitle); + gainplot2D->SetZTitle(QString("Gain ") + imageZAxisTitle); + gainplot2D->setAlignment(Qt::AlignLeft); + plotLayout->addWidget(gainplot2D,1,3,1,1); + gainplot2D->hide(); + gainPlotEnable = false; + //callbacks @@ -348,11 +369,10 @@ void qDrawPlot::Initialization(){ connect(this, SIGNAL(LogySignal(bool)), plot1D, SLOT(SetLogY(bool))); connect(this, SIGNAL(ResetZMinZMaxSignal(bool,bool,double,double)),plot2D, SLOT(ResetZMinZMax(bool,bool,double,double))); - connect(this, SIGNAL(SetZRangeSignal(double,double)), plot2D, SLOT(SetZRange(double,double))); - connect(this, SIGNAL(AcquisitionErrorSignal(QString)), this, SLOT(ShowAcquisitionErrorMessage(QString))); + connect(this, SIGNAL(GainPlotSignal(bool)), this, SLOT(EnableGainPlot(bool))); } @@ -583,15 +603,20 @@ void qDrawPlot::SetScanArgument(int scanArg){ //2d if(lastImageArray) delete [] lastImageArray; lastImageArray = new double[nPixelsY*nPixelsX]; + if(gainImageArray) delete [] gainImageArray; gainImageArray = new double[nPixelsY*nPixelsX]; //initializing 1d x axis for(unsigned int px=0;px<(int)nPixelsX;px++) histXAxis[px] = px;/*+10;*/ //initializing 2d array - for(int py=0;py<(int)nPixelsY;py++) - for(int px=0;px<(int)nPixelsX;px++) + memset(lastImageArray,0,nPixelsY *nPixelsX * sizeof(double)); + memset(gainImageArray,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; - + gainImageArray[py*nPixelsX+px] = 0; + } + */ //histogram if(histogram){ @@ -644,10 +669,15 @@ void qDrawPlot::SetupMeasurement(){ if(!running) lastImageNumber = 0;/**Just now */ //initializing 2d array + memset(lastImageArray,0,nPixelsY *nPixelsX * sizeof(double)); + memset(gainImageArray,0,nPixelsY *nPixelsX * sizeof(double)); + /* for(int py=0;py<(int)nPixelsY;py++) - for(int px=0;px<(int)nPixelsX;px++) + for(int px=0;px<(int)nPixelsX;px++) { lastImageArray[py*nPixelsX+px] = 0; - + gainImageArray[py*nPixelsX+px] = 0; + } + */ //1d with no scan if ((!originally2D) && (scanArgument==qDefs::None)){ #ifdef VERYVERBOSE @@ -666,7 +696,7 @@ void qDrawPlot::SetupMeasurement(){ #endif //2d with no scan if ((originally2D) && (scanArgument==qDefs::None)){ - maxPixelsY = nPixelsY; + maxPixelsY = nPixelsY-1; minPixelsY = 0; } @@ -1122,6 +1152,15 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){ else{ // Titles imageTitle = temp_title; + + //jungfrau mask gain + if(data->gvalues != NULL) { + memcpy(gainImageArray, data->gvalues, nPixelsX*nPixelsY*sizeof(double)); + gainPlotEnable = true; + }else + gainPlotEnable = false; + + //recalculating pedestal if(startPedestalCal){ //start adding frames to get to the pedestal value @@ -1458,6 +1497,17 @@ void qDrawPlot::UpdatePlot(){ plot2D->SetYTitle(imageYAxisTitle); plot2D->SetZTitle(imageZAxisTitle); plot2D->UpdateNKeepSetRangeIfSet(); //keep a "set" z range, and call Update(); + if (gainPlotEnable) { + gainplot2D->GetPlot()->SetData(nPixelsX,-0.5,nPixelsX-0.5,nPixelsY,startPixel,endPixel,gainImageArray); + gainplot2D->setTitle(GetImageTitle()); + gainplot2D->SetXTitle(imageXAxisTitle); + gainplot2D->SetYTitle(imageYAxisTitle); + gainplot2D->SetZTitle(QString("Gain ") + imageZAxisTitle); + + gainplot2D->show(); + }else { + gainplot2D->hide(); + } } // update range if required if(XYRangeChanged){ @@ -1467,9 +1517,16 @@ void qDrawPlot::UpdatePlot(){ 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]); + if (gainPlotEnable) { + 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(); + } //Display Statistics if(displayStatistics){ double min=0,max=0,sum=0; @@ -1853,9 +1910,12 @@ int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){ 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){ @@ -2066,3 +2126,11 @@ void qDrawPlot::GetStatistics(double &min, double &max, double &sum, double* arr //------------------------------------------------------------------------------------------------------------------------------------------------- + + +void qDrawPlot::EnableGainPlot(bool e) { +#ifdef VERBOSE + cout << "Setting Gain Plot enable to " << e << endl; +#endif + myDet->setGainDataEnableinDataCallback(e); +} diff --git a/slsDetectorGui/src/qTabPlot.cpp b/slsDetectorGui/src/qTabPlot.cpp index 9cd16607b..1cab16655 100644 --- a/slsDetectorGui/src/qTabPlot.cpp +++ b/slsDetectorGui/src/qTabPlot.cpp @@ -156,6 +156,9 @@ void qTabPlot::SetupWidgetWindow(){ stackedWidget->setCurrentIndex(0); stackedWidget_2->setCurrentIndex(0); + //gain plot + chkGainPlot->setEnabled(false); + // Depending on whether the detector is 1d or 2d switch(myDet->getDetectorsType()){ case slsDetectorDefs::MYTHEN: @@ -176,9 +179,14 @@ void qTabPlot::SetupWidgetWindow(){ isOriginallyOneD = true; break; case slsDetectorDefs::PROPIX: + isOriginallyOneD = false; + break; case slsDetectorDefs::MOENCH: + isOriginallyOneD = false; + break; case slsDetectorDefs::JUNGFRAU: isOriginallyOneD = false; + chkGainPlot->setEnabled(true); break; default: cout << "ERROR: Detector Type is Generic" << endl; @@ -325,26 +333,25 @@ void qTabPlot::Initialization(){ connect(dispYAxis, SIGNAL(textChanged(const QString&)), this, SLOT(SetTitles())); connect(dispZAxis, SIGNAL(textChanged(const QString&)), this, SLOT(SetTitles())); - connect(chkXMin, SIGNAL(toggled(bool)), this, SLOT(EnableRange())); - connect(chkXMax, SIGNAL(toggled(bool)), this, SLOT(EnableRange())); - connect(chkYMin, SIGNAL(toggled(bool)), this, SLOT(EnableRange())); - connect(chkYMax, SIGNAL(toggled(bool)), this, SLOT(EnableRange())); + connect(chkXMin, SIGNAL(toggled(bool)), this, SLOT(EnableXRange())); + connect(chkXMax, SIGNAL(toggled(bool)), this, SLOT(EnableXRange())); + connect(chkYMin, SIGNAL(toggled(bool)), this, SLOT(EnableYRange())); + connect(chkYMax, SIGNAL(toggled(bool)), this, SLOT(EnableYRange())); connect(chkZMin, SIGNAL(toggled(bool)), this, SLOT(EnableZRange())); connect(chkZMax, SIGNAL(toggled(bool)), this, SLOT(EnableZRange())); + connect(chkAspectRatio, SIGNAL(toggled(bool)), this, SLOT(checkAspectRatio())); connect(this, SIGNAL(ResetZMinZMaxSignal(bool,bool,double,double)), myPlot, SIGNAL(ResetZMinZMaxSignal(bool,bool,double,double))); - connect(dispXMin, SIGNAL(editingFinished()), this, SLOT(SetAxesRange())); - connect(dispXMax, SIGNAL(editingFinished()), this, SLOT(SetAxesRange())); - connect(dispYMin, SIGNAL(editingFinished()), this, SLOT(SetAxesRange())); - connect(dispYMax, SIGNAL(editingFinished()), this, SLOT(SetAxesRange())); + connect(dispXMin, SIGNAL(editingFinished()), this, SLOT(SetXAxisRange())); + connect(dispXMax, SIGNAL(editingFinished()), this, SLOT(SetXAxisRange())); + connect(dispYMin, SIGNAL(editingFinished()), this, SLOT(SetYAxisRange())); + connect(dispYMax, SIGNAL(editingFinished()), this, SLOT(SetYAxisRange())); connect(dispZMin, SIGNAL(editingFinished()), this, SLOT(SetZRange())); connect(dispZMax, SIGNAL(editingFinished()), this, SLOT(SetZRange())); // Save connect(btnSave, SIGNAL(clicked()), myPlot, SLOT(SavePlot())); connect(chkSaveAll, SIGNAL(toggled(bool)), myPlot, SLOT(SaveAll(bool))); - connect(this,SIGNAL(SetZRangeSignal(double,double)),myPlot, SIGNAL(SetZRangeSignal(double,double))); - //pedstal connect(chkPedestal, SIGNAL(toggled(bool)), myPlot, SLOT(SetPedestal(bool))); connect(btnRecalPedestal, SIGNAL(clicked()), myPlot, SLOT(RecalculatePedestal())); @@ -364,6 +371,10 @@ void qTabPlot::Initialization(){ connect(spinFrom_2, SIGNAL(valueChanged(int)), this, SLOT(SetBinary())); connect(spinTo, SIGNAL(valueChanged(int)), this, SLOT(SetBinary())); connect(spinTo_2, SIGNAL(valueChanged(int)), this, SLOT(SetBinary())); + + //gainplot + if (chkGainPlot->isEnabled()) + connect(chkGainPlot, SIGNAL(toggled(bool)),myPlot, SIGNAL(GainPlotSignal(bool))); } @@ -456,18 +467,220 @@ void qTabPlot::EnableTitles(){ //------------------------------------------------------------------------------------------------------------------------------------------------- -void qTabPlot::EnableRange(){ - bool disableZoom = false; - if(!chkXMin->isChecked()) dispXMin->setEnabled(false); - else{disableZoom = true; dispXMin->setEnabled(true); } - if(!chkXMax->isChecked()) dispXMax->setEnabled(false); - else{disableZoom = true; dispXMax->setEnabled(true); } - if(!chkYMin->isChecked()) dispYMin->setEnabled(false); - else{disableZoom = true; dispYMin->setEnabled(true); } - if(!chkYMax->isChecked()) dispYMax->setEnabled(false); - else{disableZoom = true; dispYMax->setEnabled(true); } +void qTabPlot::checkAspectRatio() { + if (chkAspectRatio->isChecked()) { + maintainAspectRatio(-1); + } +} - myPlot->DisableZoom(disableZoom); + +//------------------------------------------------------------------------------------------------------------------------------------------------- + + +void qTabPlot::maintainAspectRatio(int axis) { +#ifdef VERBOSE + cout << "Maintaining Aspect Ratio" << endl; +#endif + disconnect(chkXMin, SIGNAL(toggled(bool)), this, SLOT(EnableXRange())); + disconnect(chkXMax, SIGNAL(toggled(bool)), this, SLOT(EnableXRange())); + disconnect(chkYMin, SIGNAL(toggled(bool)), this, SLOT(EnableYRange())); + disconnect(chkYMax, SIGNAL(toggled(bool)), this, SLOT(EnableYRange())); + disconnect(dispXMin, SIGNAL(editingFinished()), this, SLOT(SetXAxisRange())); + disconnect(dispXMax, SIGNAL(editingFinished()), this, SLOT(SetXAxisRange())); + disconnect(dispYMin, SIGNAL(editingFinished()), this, SLOT(SetYAxisRange())); + disconnect(dispYMax, SIGNAL(editingFinished()), this, SLOT(SetYAxisRange())); + + double ranges[4]; + //get previous plot limits + ranges[qDefs::XMINIMUM] = myPlot->GetXMinimum(); + ranges[qDefs::XMAXIMUM] = myPlot->GetXMaximum(); + ranges[qDefs::YMINIMUM] = myPlot->GetYMinimum(); + ranges[qDefs::YMAXIMUM] = myPlot->GetYMaximum(); +#ifdef VERYVERBOSE + cprintf(BLUE,"ideal values: xmin:%f, xmax:%f ymin:%f ymax:%f\n",ranges[qDefs::XMINIMUM],ranges[qDefs::XMAXIMUM],ranges[qDefs::YMINIMUM],ranges[qDefs::YMAXIMUM]); +#endif + double idealAspectratio = (ranges[qDefs::XMAXIMUM] - ranges[qDefs::XMINIMUM]) / (ranges[qDefs::YMAXIMUM] - ranges[qDefs::YMINIMUM]); + + // enable all + chkXMin->setChecked(true); dispXMin->setEnabled(true); + chkXMax->setChecked(true); dispXMax->setEnabled(true); + chkYMin->setChecked(true); dispYMin->setEnabled(true); + chkYMax->setChecked(true); dispYMax->setEnabled(true); + + // if any empty, set it to previous plots boundaries + if (dispXMin->text().isEmpty()) dispXMin->setText(QString::number(myPlot->GetXMinimum())); + if (dispXMax->text().isEmpty()) dispXMax->setText(QString::number(myPlot->GetXMaximum())); + if (dispYMin->text().isEmpty()) dispYMin->setText(QString::number(myPlot->GetYMinimum())); + if (dispYMax->text().isEmpty()) dispYMax->setText(QString::number(myPlot->GetYMaximum())); + + //get actual limits + ranges[qDefs::XMINIMUM] = dispXMin->text().toDouble(); + ranges[qDefs::XMAXIMUM] = dispXMax->text().toDouble(); + ranges[qDefs::YMINIMUM] = dispYMin->text().toDouble(); + ranges[qDefs::YMAXIMUM] = dispYMax->text().toDouble(); +#ifdef VERYVERBOSE + cprintf(BLUE,"new limits: xmin:%f, xmax:%f ymin:%f ymax:%f\n",ranges[qDefs::XMINIMUM],ranges[qDefs::XMAXIMUM],ranges[qDefs::YMINIMUM],ranges[qDefs::YMAXIMUM]); +#endif + // calcualte new aspect ratio + double newAspectRatio = (ranges[qDefs::XMAXIMUM] - ranges[qDefs::XMINIMUM]) / (ranges[qDefs::YMAXIMUM] - ranges[qDefs::YMINIMUM]); + + // if not ideal aspect ratio + if (newAspectRatio != idealAspectratio) { + + // find the larger difference + if (axis == -1) { + if ((ranges[qDefs::XMAXIMUM] - ranges[qDefs::XMINIMUM]) > (ranges[qDefs::YMAXIMUM] - ranges[qDefs::YMINIMUM])) { + //change x + axis = 0; + } else { + //change y + axis = 1; + } + } + + // if x changed: y adjusted, y changed: x adjusted, aspect ratio clicked: larger one adjusted + switch(axis) { + case 0: + //change x + dispXMax->setText(QString::number(idealAspectratio * (ranges[qDefs::YMAXIMUM] - ranges[qDefs::YMINIMUM]) + ranges[qDefs::XMINIMUM])); +#ifdef VERYVERBOSE + cprintf(BLUE,"new xmax: %f\n",dispXMax->text().toDouble()); +#endif + break; + case 1: + // change y + dispYMax->setText(QString::number(((ranges[qDefs::XMAXIMUM] - ranges[qDefs::XMINIMUM]) / idealAspectratio) + ranges[qDefs::YMINIMUM])); +#ifdef VERYVERBOSE + cprintf(BLUE,"new ymax: %f\n",dispYMax->text().toDouble()); +#endif + break; + default: + break; + } + } + + connect(chkXMin, SIGNAL(toggled(bool)), this, SLOT(EnableXRange())); + connect(chkXMax, SIGNAL(toggled(bool)), this, SLOT(EnableXRange())); + connect(chkYMin, SIGNAL(toggled(bool)), this, SLOT(EnableYRange())); + connect(chkYMax, SIGNAL(toggled(bool)), this, SLOT(EnableYRange())); + connect(dispXMin, SIGNAL(editingFinished()), this, SLOT(SetXAxisRange())); + connect(dispXMax, SIGNAL(editingFinished()), this, SLOT(SetXAxisRange())); + connect(dispYMin, SIGNAL(editingFinished()), this, SLOT(SetYAxisRange())); + connect(dispYMax, SIGNAL(editingFinished()), this, SLOT(SetYAxisRange())); + + // disable mouse zooming if any checked + myPlot->DisableZoom(true); + emit DisableZoomSignal(true); + + // 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->IsXYRangeValues(true,qDefs::XMINIMUM); + myPlot->IsXYRangeValues(true,qDefs::XMAXIMUM); + myPlot->IsXYRangeValues(true,qDefs::YMINIMUM); + myPlot->IsXYRangeValues(true,qDefs::YMAXIMUM); + + // To remind the updateplot in qdrawplot to set range after updating plot + myPlot->SetXYRange(true); +} + + +//------------------------------------------------------------------------------------------------------------------------------------------------- + +void qTabPlot::EnableXRange(){ +#ifdef VERBOSE + cout << "Enable X Axis Range" << endl; +#endif + // keeping aspect ratio + if (chkAspectRatio->isChecked()) { + maintainAspectRatio(1); + return; + } + disconnect(dispXMin, SIGNAL(editingFinished()), this, SLOT(SetXAxisRange())); + disconnect(dispXMax, SIGNAL(editingFinished()), this, SLOT(SetXAxisRange())); + + // enable/disable lineedit + if(chkXMin->isChecked()) { + dispXMin->setEnabled(true); + // if any empty, set it to previous plots boundaries + if (dispXMin->text().isEmpty()) + dispXMin->setText(QString::number(myPlot->GetXMinimum())); + } else { + dispXMin->setEnabled(false); + } + // enable/disable lineedit + if(chkXMax->isChecked()) { + dispXMax->setEnabled(true); + // if any empty, set it to previous plots boundaries + if (dispXMax->text().isEmpty()) + dispXMax->setText(QString::number(myPlot->GetXMaximum())); + } else { + dispXMax->setEnabled(false); + } + + connect(dispXMin, SIGNAL(editingFinished()), this, SLOT(SetXAxisRange())); + connect(dispXMax, SIGNAL(editingFinished()), this, SLOT(SetXAxisRange())); + + EnableRange(); +} + + +//------------------------------------------------------------------------------------------------------------------------------------------------- + + +void qTabPlot::EnableYRange(){ +#ifdef VERBOSE + cout << "Enable Y Axis Range" << endl; +#endif + // keeping aspect ratio + if (chkAspectRatio->isChecked()) { + maintainAspectRatio(0); + return; + } + disconnect(dispYMin, SIGNAL(editingFinished()), this, SLOT(SetYAxisRange())); + disconnect(dispYMax, SIGNAL(editingFinished()), this, SLOT(SetYAxisRange())); + + // enable/disable lineedit + if(chkYMin->isChecked()) { + dispYMin->setEnabled(true); + // if any empty, set it to previous plots boundaries + if (dispYMin->text().isEmpty()) + dispYMin->setText(QString::number(myPlot->GetYMinimum())); + } else { + dispYMin->setEnabled(false); + } + // enable/disable lineedit + if(chkYMax->isChecked()) { + dispYMax->setEnabled(true); + // if any empty, set it to previous plots boundaries + if (dispYMax->text().isEmpty()) + dispYMax->setText(QString::number(myPlot->GetYMaximum())); + } else { + dispYMax->setEnabled(false); + } + + connect(dispYMin, SIGNAL(editingFinished()), this, SLOT(SetYAxisRange())); + connect(dispYMax, SIGNAL(editingFinished()), this, SLOT(SetYAxisRange())); + + EnableRange(); +} + + +//------------------------------------------------------------------------------------------------------------------------------------------------- + + +void qTabPlot::EnableRange(){ +#ifdef VERBOSE + cout << "Enable Axes Range" << endl; +#endif + // disable mouse zooming if any checked + bool disableZoom= false; + if(chkYMin->isChecked() || chkYMax->isChecked() || chkYMin->isChecked() || chkYMax->isChecked()) + disableZoom = true; emit DisableZoomSignal(disableZoom); SetAxesRange(); } @@ -476,31 +689,75 @@ void qTabPlot::EnableRange(){ //------------------------------------------------------------------------------------------------------------------------------------------------- +void qTabPlot::SetXAxisRange(){ +#ifdef VERBOSE + cout << "Setting X Axis Range" << endl; +#endif + + // keeping aspect ratio + if (chkAspectRatio->isChecked()) { + maintainAspectRatio(1); + return; + } + + SetAxesRange(); +} + + +//------------------------------------------------------------------------------------------------------------------------------------------------- + + +void qTabPlot::SetYAxisRange(){ +#ifdef VERBOSE + cout << "Setting X Axis Range" << endl; +#endif + + // keeping aspect ratio + if (chkAspectRatio->isChecked()) { + maintainAspectRatio(0); + return; + } + + SetAxesRange(); +} + + +//------------------------------------------------------------------------------------------------------------------------------------------------- + + void qTabPlot::SetAxesRange(){ #ifdef VERBOSE - cout << "Setting Range" << endl; + cout << "Setting Axes Range" << endl; #endif - bool changed = false; // x min - changed = (dispXMin->isEnabled())&&(!dispXMin->text().isEmpty()); - if(changed) myPlot->SetXYRangeValues(dispXMin->text().toDouble(),qDefs::XMINIMUM); - myPlot->IsXYRangeValues(changed,qDefs::XMINIMUM); - + if (dispXMin->isEnabled()) { + myPlot->SetXYRangeValues(dispXMin->text().toDouble(),qDefs::XMINIMUM); + myPlot->IsXYRangeValues(true,qDefs::XMINIMUM); + } + else + myPlot->IsXYRangeValues(false,qDefs::XMINIMUM); // x max - changed = (dispXMax->isEnabled())&&(!dispXMax->text().isEmpty()); - if(changed) myPlot->SetXYRangeValues(dispXMax->text().toDouble(),qDefs::XMAXIMUM); - myPlot->IsXYRangeValues(changed,qDefs::XMAXIMUM); - + if (dispXMax->isEnabled()) { + myPlot->SetXYRangeValues(dispXMax->text().toDouble(),qDefs::XMAXIMUM); + myPlot->IsXYRangeValues(true,qDefs::XMAXIMUM); + } + else + myPlot->IsXYRangeValues(false,qDefs::XMAXIMUM); // y min - changed = (dispYMin->isEnabled())&&(!dispYMin->text().isEmpty()); - if(changed) myPlot->SetXYRangeValues(dispYMin->text().toDouble(),qDefs::YMINIMUM); - myPlot->IsXYRangeValues(changed,qDefs::YMINIMUM); - + if (dispYMin->isEnabled()) { + myPlot->SetXYRangeValues(dispYMin->text().toDouble(),qDefs::YMINIMUM); + myPlot->IsXYRangeValues(true,qDefs::YMINIMUM); + } + else + myPlot->IsXYRangeValues(false,qDefs::YMINIMUM); // y max - changed = (dispYMax->isEnabled())&&(!dispYMax->text().isEmpty()); - if(changed) myPlot->SetXYRangeValues(dispYMax->text().toDouble(),qDefs::YMAXIMUM); - myPlot->IsXYRangeValues(changed,qDefs::YMAXIMUM); + if (dispYMax->isEnabled()) { + myPlot->SetXYRangeValues(dispYMax->text().toDouble(),qDefs::YMAXIMUM); + myPlot->IsXYRangeValues(true,qDefs::YMAXIMUM); + } + else + myPlot->IsXYRangeValues(false,qDefs::YMAXIMUM); // To remind the updateplot in qdrawplot to set range after updating plot myPlot->SetXYRange(true); @@ -524,6 +781,9 @@ void qTabPlot::SetZRange(){ void qTabPlot::EnableZRange(){ + disconnect(dispZMin, SIGNAL(editingFinished()), this, SLOT(SetZRange())); + disconnect(dispZMax, SIGNAL(editingFinished()), this, SLOT(SetZRange())); + dispZMin->setEnabled(chkZMin->isChecked()); dispZMax->setEnabled(chkZMax->isChecked()); emit ResetZMinZMaxSignal( @@ -531,6 +791,9 @@ void qTabPlot::EnableZRange(){ (chkZMax->isChecked() && CheckZRange(dispZMax->text())), dispZMin->text().toDouble(), dispZMax->text().toDouble()); + + connect(dispZMin, SIGNAL(editingFinished()), this, SLOT(SetZRange())); + connect(dispZMax, SIGNAL(editingFinished()), this, SLOT(SetZRange())); } @@ -543,8 +806,11 @@ bool qTabPlot::CheckZRange(QString value){ bool ok; value.toDouble(&ok); - if(!ok) + if(!ok) { + qDefs::Message(qDefs::WARNING,"Check Z Range
" + "Zmin and Zmax should be in double","qTabPlot::CheckZRange"); return false; + } return true; }