From: dmv Date: Fri, 27 Feb 2009 08:18:55 +0000 (+0000) Subject: IPAL20900 TC5.1.1 Impossible "fit all" in logarithmic Plot2D X-Git-Tag: V5_1_1a2~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3f06a63c61b7364a4e141ee7cc68f1f6bd97bb8d;p=modules%2Fgui.git IPAL20900 TC5.1.1 Impossible "fit all" in logarithmic Plot2D --- diff --git a/src/Plot2d/Plot2d_Curve.cxx b/src/Plot2d/Plot2d_Curve.cxx index 4232eff2b..434d62703 100755 --- a/src/Plot2d/Plot2d_Curve.cxx +++ b/src/Plot2d/Plot2d_Curve.cxx @@ -379,6 +379,20 @@ double Plot2d_Curve::getMinX() const return aMinX; } +/*! + Gets curve's maximal abscissa +*/ +double Plot2d_Curve::getMaxX() const +{ + pointList::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 */ @@ -394,6 +408,20 @@ double Plot2d_Curve::getMinY() const return aMinY; } +/*! + Gets curve's maximal ordinate +*/ +double Plot2d_Curve::getMaxY() const +{ + pointList::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 8cf390d80..a8e4f98bf 100755 --- a/src/Plot2d/Plot2d_Curve.h +++ b/src/Plot2d/Plot2d_Curve.h @@ -99,6 +99,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 d57f3e94d..bb629289d 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -741,18 +741,17 @@ void Plot2d_ViewFrame::fitAll() myPlot->setAxisAutoScale( QwtPlot::xBottom ); myPlot->replot(); - // for existing grid - QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom ); - QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft ); + double xmin, xmax, y1min, y1max, y2min, y2max; + getFitRangeByCurves(xmin, xmax, y1min, y1max, y2min, y2max); - myPlot->setAxisScale( QwtPlot::xBottom, xMap.s1(), xMap.s2() ); - myPlot->setAxisScale( QwtPlot::yLeft, yMap.s1(), yMap.s2() ); + myPlot->setAxisScale( QwtPlot::xBottom, xmin, xmax ); + myPlot->setAxisScale( QwtPlot::yLeft, y1min, y1max ); if (mySecondY) { myPlot->setAxisAutoScale( QwtPlot::yRight ); myPlot->replot(); QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight ); - myPlot->setAxisScale( QwtPlot::yRight, yMap2.s1(), yMap2.s2() ); + myPlot->setAxisScale( QwtPlot::yRight, y2min, y2max ); } myPlot->replot(); } @@ -827,6 +826,26 @@ 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) +{ + CurveDict::const_iterator it = myPlot->getCurves().begin(); + xMin = yMin = y2Min = 1e150; + xMax = yMax = y2Max = -1e150; + for ( ; it != myPlot->getCurves().end(); it++ ) { + if ( xMin > it.value()->getMinX() ) xMin = it.value()->getMinX(); + if ( xMax < it.value()->getMaxX() ) xMax = it.value()->getMaxX(); + if ( yMin > it.value()->getMinY() ) yMin = it.value()->getMinY(); + if ( yMax < it.value()->getMaxY() ) yMax = it.value()->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 e2e99e9e2..3308b6682 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -90,6 +90,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 );