Salome HOME
IPAL9301: SIGFPE appears after changing scale mode of the Plot2d presentation
authornds <nds@opencascade.com>
Thu, 22 Dec 2005 12:05:44 +0000 (12:05 +0000)
committernds <nds@opencascade.com>
Thu, 22 Dec 2005 12:05:44 +0000 (12:05 +0000)
src/Plot2d/Plot2d_Curve.cxx
src/Plot2d/Plot2d_Curve.h
src/Plot2d/Plot2d_ViewFrame.cxx
src/Plot2d/Plot2d_ViewFrame.h
src/Plot2d/resources/Plot2d_msg_en.po

index 325115aa27ad0bc418281d4609b4375128ebdfd3..c0a9abbb6f2a1694e188bf2898b8c613bfd5de57 100755 (executable)
@@ -353,3 +353,33 @@ QwtPlot::Axis Plot2d_Curve::getYAxis() const
 {
   return myYAxis;
 }
+
+/*!
+  Gets curve's minimal abscissa
+*/
+double Plot2d_Curve::getMinX() const
+{
+  QValueList<Plot2d_Point>::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<Plot2d_Point>::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;
+}
index e54009d5e18ed207e83c020902de8c404d2835e4..b17f7c327364b8ae26296d4c1f53b09199bfc78e 100755 (executable)
@@ -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;
index 295aff062f9d40c70cf9fac81550d3f961a6da86..999e62403db4611cb167f173308ae2212e80c1e0 100755 (executable)
@@ -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<Plot2d_Curve> 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<Plot2d_Curve> it( myCurves );
+  for ( ; allPositive && it.current(); ++it ) {
+    allPositive = ( it.current()->getMinY() > 0. );
+  }
+  return allPositive;
+}
+
 //=================================================================================
 // Plot2d_Plot2d implementation
 //=================================================================================
index a52d6d8f237ecc3a37baa639b2b315666d48b55c..51faa089840b9f1244884e880a5cda584c5980f7 100755 (executable)
@@ -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:
index 586daf450658cf7ebebb118478d2f7543c229f9f..8f70877326ec7f3eb3a9eeb057c4e9ae8d203bbd 100755 (executable)
@@ -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 )"