From: nds Date: Thu, 22 Dec 2005 12:05:44 +0000 (+0000) Subject: IPAL9301: SIGFPE appears after changing scale mode of the Plot2d presentation X-Git-Tag: T_Before_Join_BR_3_1_0deb~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=adcff522110df0e27dd828d2d80a3c7c914fcc2b;p=modules%2Fgui.git IPAL9301: SIGFPE appears after changing scale mode of the Plot2d presentation --- diff --git a/src/Plot2d/Plot2d_Curve.cxx b/src/Plot2d/Plot2d_Curve.cxx index 325115aa2..c0a9abbb6 100755 --- a/src/Plot2d/Plot2d_Curve.cxx +++ b/src/Plot2d/Plot2d_Curve.cxx @@ -353,3 +353,33 @@ QwtPlot::Axis Plot2d_Curve::getYAxis() const { return myYAxis; } + +/*! + Gets curve's minimal abscissa +*/ +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; + } + return aMinX; +} + +/*! + Gets curve's minimal ordinate +*/ +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; + } + return aMinY; +} diff --git a/src/Plot2d/Plot2d_Curve.h b/src/Plot2d/Plot2d_Curve.h index e54009d5e..b17f7c327 100755 --- a/src/Plot2d/Plot2d_Curve.h +++ b/src/Plot2d/Plot2d_Curve.h @@ -82,6 +82,12 @@ public: void setYAxis(QwtPlot::Axis theYAxis); QwtPlot::Axis getYAxis() const; + // Protection against QwtCurve::drawLines() bug in Qwt 0.4.x: + // it crashes if switched to X/Y logarithmic mode, when one or more points have + // non-positive X/Y coordinate + double getMinX() const; + double getMinY() const; + protected: bool myAutoAssign; QString myHorTitle; diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index 295aff062..999e62403 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -600,6 +600,15 @@ void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update ) { if ( !curve ) return; + // san -- Protection against QwtCurve bug in Qwt 0.4.x: + // it crashes if switched to X/Y logarithmic mode, when one or more points have + // non-positive X/Y coordinate + if ( myXMode && curve->getMinX() <= 0. ) + setHorScaleMode( 0, false ); + if ( myYMode && curve->getMinY() <= 0. ) + setVerScaleMode( 0, false ); + + if ( hasCurve( curve ) ) { updateCurve( curve, update ); } @@ -1170,9 +1179,6 @@ void Plot2d_ViewFrame::setXGrid( bool xMajorEnabled, const int xMajorMax, bool xMinorEnabled, const int xMinorMax, bool update ) { - if( xMinorMax>=xMajorMax ) - return; - myXGridMajorEnabled = xMajorEnabled; myXGridMinorEnabled = xMinorEnabled; myXGridMaxMajor = xMajorMax; @@ -1317,6 +1323,14 @@ void Plot2d_ViewFrame::setFont( const QFont& font, ObjectType type, bool update) */ void Plot2d_ViewFrame::setHorScaleMode( const int mode, bool update ) { + // san -- Protection against QwtCurve bug in Qwt 0.4.x: + // it crashes if switched to X/Y logarithmic mode, when one or more points have + // non-positive X/Y coordinate + if ( mode && !isXLogEnabled() ){ + SUIT_MessageBox::warn1(this, tr("WARNING"), tr("WRN_XLOG_NOT_ALLOWED"), tr("BUT_OK")); + return; + } + myXMode = mode; if ( myXMode == 0 ) // linear myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, false ); @@ -1332,6 +1346,14 @@ void Plot2d_ViewFrame::setHorScaleMode( const int mode, bool update ) */ void Plot2d_ViewFrame::setVerScaleMode( const int mode, bool update ) { + // san -- Protection against QwtCurve bug in Qwt 0.4.x: + // it crashes if switched to X/Y logarithmic mode, when one or more points have + // non-positive X/Y coordinate + if ( mode && !isYLogEnabled() ){ + SUIT_MessageBox::warn1(this, tr("WARNING"), tr("WRN_YLOG_NOT_ALLOWED"), tr("BUT_OK")); + return; + } + myYMode = mode; if ( myYMode == 0 ) { // linear myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, false ); @@ -1560,6 +1582,32 @@ void Plot2d_ViewFrame::onViewGlobalPan() qApp->installEventFilter( this ); } +/*! + Precaution for logarithmic X scale +*/ +bool Plot2d_ViewFrame::isXLogEnabled() const +{ + bool allPositive = true; + QIntDictIterator it( myCurves ); + for ( ; allPositive && it.current(); ++it ) { + allPositive = ( it.current()->getMinX() > 0. ); + } + return allPositive; +} + +/*! + Precaution for logarithmic Y scale +*/ +bool Plot2d_ViewFrame::isYLogEnabled() const +{ + bool allPositive = true; + QIntDictIterator it( myCurves ); + for ( ; allPositive && it.current(); ++it ) { + allPositive = ( it.current()->getMinY() > 0. ); + } + return allPositive; +} + //================================================================================= // Plot2d_Plot2d implementation //================================================================================= diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index a52d6d8f2..51faa0898 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -110,6 +110,12 @@ public: bool isModeVerLinear(); bool isLegendShow() { return myShowLegend; }; + // Protection against QwtCurve::drawLines() bug in Qwt 0.4.x: + // it crashes if switched to X/Y logarithmic mode, when one or more points have + // non-positive X/Y coordinate + bool isXLogEnabled() const; + bool isYLogEnabled() const; + virtual bool print( const QString& file, const QString& format ) const; protected: diff --git a/src/Plot2d/resources/Plot2d_msg_en.po b/src/Plot2d/resources/Plot2d_msg_en.po index 586daf450..8f7087732 100755 --- a/src/Plot2d/resources/Plot2d_msg_en.po +++ b/src/Plot2d/resources/Plot2d_msg_en.po @@ -120,6 +120,15 @@ msgstr "Curve type" msgid "INF_COORDINATES" msgstr "Coordinates: X : %1, Y : %2" +msgid "WARNING" +msgstr "Warning" + +msgid "WRN_XLOG_NOT_ALLOWED" +msgstr "Some points with non-positive abscissa values have been detected.\nLogarithmic scale for abscissa axis is not allowed." + +msgid "WRN_YLOG_NOT_ALLOWED" +msgstr "Some points with non-positive ordinate values have been detected.\nLogarithmic scale for ordinate axis is not allowed." + msgid "INF_COORDINATES_SOME_Y" msgstr "Coordinates: X : %1, Y : %2 ( %3 )"