From 45889f7df95bb632d94f0fb79f039778fedb6df7 Mon Sep 17 00:00:00 2001 From: enk Date: Thu, 20 Oct 2005 14:05:05 +0000 Subject: [PATCH] Fix for Bug PAL8856 set axis scale not available from TUI --- src/Plot2d/Plot2d_ViewFrame.cxx | 70 ++++++++++++++++++++++----------- src/Plot2d/Plot2d_ViewFrame.h | 8 ++++ 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index 880ce2136..4875b6a62 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -824,6 +824,49 @@ void Plot2d_ViewFrame::fitArea( const QRect& area ) myPlot->replot(); } +/*! + "Fit Data" command for TUI interface +*/ +void Plot2d_ViewFrame::fitData(const int mode, + const double xMin, const double xMax, + const double yMin, const double yMax, + double y2Min, double y2Max) +{ + if ( mode == 0 || mode == 2 ) { + myPlot->setAxisScale( QwtPlot::yLeft, yMax, yMin ); + if (mySecondY) + myPlot->setAxisScale( QwtPlot::yRight, y2Max, y2Min ); + } + if ( mode == 0 || mode == 1 ) + myPlot->setAxisScale( QwtPlot::xBottom, xMin, xMax ); + myPlot->replot(); +} + +/*! + Gets current fit ranges for view frame +*/ +void Plot2d_ViewFrame::getFitRanges(double& xMin,double& xMax, + double& yMin, double& yMax, + double& y2Min, double& y2Max) +{ + int ixMin = myPlot->canvasMap( QwtPlot::xBottom ).i1(); + int ixMax = myPlot->canvasMap( QwtPlot::xBottom ).i2(); + int iyMin = myPlot->canvasMap( QwtPlot::yLeft ).i1(); + int iyMax = myPlot->canvasMap( QwtPlot::yLeft ).i2(); + xMin = myPlot->invTransform(QwtPlot::xBottom, ixMin); + xMax = myPlot->invTransform(QwtPlot::xBottom, ixMax); + yMin = myPlot->invTransform(QwtPlot::yLeft, iyMin); + yMax = myPlot->invTransform(QwtPlot::yLeft, iyMax); + y2Min = 0; + y2Max = 0; + if (mySecondY) { + int iyMin = myPlot->canvasMap( QwtPlot::yRight ).i1(); + int iyMax = myPlot->canvasMap( QwtPlot::yRight ).i2(); + y2Min = myPlot->invTransform(QwtPlot::yRight, iyMin); + y2Max = myPlot->invTransform(QwtPlot::yRight, iyMax); + } +} + /*! Tests if it is necessary to start operation on mouse action */ @@ -980,34 +1023,13 @@ void Plot2d_ViewFrame::onSettings() void Plot2d_ViewFrame::onFitData() { Plot2d_FitDataDlg* dlg = new Plot2d_FitDataDlg( this, mySecondY ); - int ixMin = myPlot->canvasMap( QwtPlot::xBottom ).i1(); - int ixMax = myPlot->canvasMap( QwtPlot::xBottom ).i2(); - int iyMin = myPlot->canvasMap( QwtPlot::yLeft ).i1(); - int iyMax = myPlot->canvasMap( QwtPlot::yLeft ).i2(); - double xMin = myPlot->invTransform(QwtPlot::xBottom, ixMin); - double xMax = myPlot->invTransform(QwtPlot::xBottom, ixMax); - double yMin = myPlot->invTransform(QwtPlot::yLeft, iyMin); - double yMax = myPlot->invTransform(QwtPlot::yLeft, iyMax); - double y2Min = 0; - double y2Max = 0; - if (mySecondY) { - int iyMin = myPlot->canvasMap( QwtPlot::yRight ).i1(); - int iyMax = myPlot->canvasMap( QwtPlot::yRight ).i2(); - y2Min = myPlot->invTransform(QwtPlot::yRight, iyMin); - y2Max = myPlot->invTransform(QwtPlot::yRight, iyMax); - } + double xMin,xMax,yMin,yMax,y2Min,y2Max; + getFitRanges(xMin,xMax,yMin,yMax,y2Min,y2Max); dlg->setRange( xMin, xMax, yMin, yMax, y2Min, y2Max ); if ( dlg->exec() == QDialog::Accepted ) { int mode = dlg->getRange( xMin, xMax, yMin, yMax, y2Min, y2Max ); - if ( mode == 0 || mode == 2 ) { - myPlot->setAxisScale( QwtPlot::yLeft, yMax, yMin ); - if (mySecondY) - myPlot->setAxisScale( QwtPlot::yRight, y2Max, y2Min ); - } - if ( mode == 0 || mode == 1 ) - myPlot->setAxisScale( QwtPlot::xBottom, xMin, xMax ); - myPlot->replot(); + fitData(mode,xMin,xMax,yMin,yMax,y2Min,y2Max); } delete dlg; } diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index bd5d988f8..6cc8ff364 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -51,6 +51,14 @@ public: void updateLegend( const Plot2d_Prs* prs ); void fitAll(); void fitArea( const QRect& area ); + void fitData(const int mode, + const double xMin, const double xMax, + const double yMin, const double yMax, + const double y2Min = 0, const double y2Max = 0); + + void getFitRanges(double& xMin, double& xMax, + double& yMin, double& yMax, + double& y2Min, double& y2Max); /* view parameters */ void copyPreferences( Plot2d_ViewFrame* ); -- 2.39.2