From: dmv Date: Fri, 27 Feb 2009 08:26:56 +0000 (+0000) Subject: IPAL20900 Impossible "fit all" in logarithmic Plot2D X-Git-Tag: V4_1_5rc1~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3432a4ad90903ac5c4a01feae7177cee56b89aeb;p=modules%2Fgui.git IPAL20900 Impossible "fit all" in logarithmic Plot2D --- diff --git a/src/Plot2d/Plot2d_Curve.cxx b/src/Plot2d/Plot2d_Curve.cxx index 3f06bf423..2e4148ba3 100755 --- a/src/Plot2d/Plot2d_Curve.cxx +++ b/src/Plot2d/Plot2d_Curve.cxx @@ -371,7 +371,6 @@ double Plot2d_Curve::getMinX() const { QValueList::const_iterator aIt; double aMinX = 1e150; - //int aCurrent = 0; for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) { if ( (*aIt).x < aMinX ) aMinX = (*aIt).x; @@ -379,6 +378,20 @@ double Plot2d_Curve::getMinX() const return aMinX; } +/*! + Gets curve's maximal abscissa +*/ +double Plot2d_Curve::getMaxX() const +{ + QValueList::const_iterator aIt; + double aMaxX = -1e150; + for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) { + if ( (*aIt).x > aMaxX ) + aMaxX = (*aIt).x; + } + return aMaxX; +} + /*! Gets curve's minimal ordinate */ @@ -386,7 +399,6 @@ double Plot2d_Curve::getMinY() const { QValueList::const_iterator aIt; double aMinY = 1e150; - //int aCurrent = 0; for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) { if ( (*aIt).y < aMinY ) aMinY = (*aIt).y; @@ -394,6 +406,20 @@ double Plot2d_Curve::getMinY() const return aMinY; } +/*! + Gets curve's maximal ordinate +*/ +double Plot2d_Curve::getMaxY() const +{ + QValueList::const_iterator aIt; + double aMaxY = -1e150; + for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) { + if ( (*aIt).y > aMaxY ) + aMaxY = (*aIt).y; + } + return aMaxY; +} + /*! Changes text assigned to point of curve \param ind -- index of point diff --git a/src/Plot2d/Plot2d_Curve.h b/src/Plot2d/Plot2d_Curve.h index ec140dce3..08058dd2c 100755 --- a/src/Plot2d/Plot2d_Curve.h +++ b/src/Plot2d/Plot2d_Curve.h @@ -94,6 +94,8 @@ public: // non-positive X/Y coordinate double getMinX() const; double getMinY() const; + double getMaxX() const; + double getMaxY() const; protected: bool myAutoAssign; diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index 1f3c9f0ff..93e541c7a 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -800,7 +800,6 @@ void Plot2d_ViewFrame::fitAll() return; } - if ( myCurves.isEmpty() ) { // Nothing to fit all myPlot->replot(); return; @@ -810,24 +809,17 @@ void Plot2d_ViewFrame::fitAll() myPlot->setAxisAutoScale( QwtPlot::xBottom ); myPlot->replot(); - // for existing grid - QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom ); - QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft ); + double xmin, xmax, y1min, y1max, y2min, y2max; + getFitRangeByCurves(xmin, xmax, y1min, y1max, y2min, y2max); - myPlot->setAxisScale( QwtPlot::xBottom, - myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ), - myPlot->invTransform( QwtPlot::xBottom, xMap.i2() ) ); - myPlot->setAxisScale( QwtPlot::yLeft, - myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ), - myPlot->invTransform( QwtPlot::yLeft, yMap.i2() ) ); + myPlot->setAxisScale( QwtPlot::xBottom, xmin, xmax ); + myPlot->setAxisScale( QwtPlot::yLeft, y1min, y1max ); if (mySecondY) { myPlot->setAxisAutoScale( QwtPlot::yRight ); myPlot->replot(); QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight ); - myPlot->setAxisScale( QwtPlot::yRight, - myPlot->invTransform( QwtPlot::yRight, yMap2.i1() ), - myPlot->invTransform( QwtPlot::yRight, yMap2.i2() ) ); + myPlot->setAxisScale( QwtPlot::yRight, y2min, y2max); } myPlot->replot(); } @@ -902,6 +894,29 @@ void Plot2d_ViewFrame::getFitRanges(double& xMin,double& xMax, } } +/*! + Gets current fit ranges by Curves +*/ +void Plot2d_ViewFrame::getFitRangeByCurves(double& xMin,double& xMax, + double& yMin, double& yMax, + double& y2Min, double& y2Max) +{ + QList clist; + getCurves( clist ); + xMin = clist.at(0)->getMinX(); + xMax = clist.at(0)->getMaxX(); + yMin = clist.at(0)->getMinY(); + yMax = clist.at(0)->getMaxY(); + for ( int i = 1; i < (int)clist.count(); i++ ) { + if ( xMin > clist.at(i)->getMinX() ) xMin = clist.at(i)->getMinX(); + if ( xMax < clist.at(i)->getMaxX() ) xMax = clist.at(i)->getMaxX(); + if ( yMin > clist.at(i)->getMinY() ) yMin = clist.at(i)->getMinY(); + if ( yMax < clist.at(i)->getMaxY() ) yMax = clist.at(i)->getMaxY(); + } + y2Min = yMin; + y2Max = yMax; +} + /*! Tests if it is necessary to start operation on mouse action */ diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index ea3f7627f..ed8e6707a 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -83,6 +83,10 @@ public: double& yMin, double& yMax, double& y2Min, double& y2Max); + void getFitRangeByCurves(double& xMin, double& xMax, + double& yMin, double& yMax, + double& y2Min, double& y2Max); + /* view parameters */ void copyPreferences( Plot2d_ViewFrame* ); void setCurveType( int curveType, bool update = true );