Salome HOME
PAL11054 - crash if user enters "-8" as density function with exponent conversion
authorasl <asl@opencascade.com>
Fri, 30 Dec 2005 08:29:24 +0000 (08:29 +0000)
committerasl <asl@opencascade.com>
Fri, 30 Dec 2005 08:29:24 +0000 (08:29 +0000)
PAL11055 - it is impossible to enter negative function value in case, when exponent conversion is applied
some remarks from PAL8238

src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx
src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h
src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx
src/StdMeshersGUI/StdMeshersGUI_DistrTable.h
src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx
src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h
src/StdMeshersGUI/StdMeshers_msg_en.po

index f763fbd9c27b032f4e0099c6eb16da0a9bddd268..0d66dc53aa903a601113b0c772855057ee3a08f0 100644 (file)
@@ -19,8 +19,8 @@ StdMeshersGUI_DistrPreview::StdMeshersGUI_DistrPreview( QWidget* p, StdMeshers::
 {
   myHypo = StdMeshers::StdMeshers_NumberOfSegments::_duplicate( h );
   myVars.ChangeValue( 1 ) = new Expr_NamedUnknown( "t" );
-  myCurve1 = insertCurve( QString() );
-  myCurve2 = insertCurve( QString() );
+  myDensity = insertCurve( QString() );
+  myDistr = insertCurve( QString() );
   myMsg = insertMarker( new QwtPlotMarker( this ) );
   setMarkerPos( myMsg, 0.5, 0.5 );
   setMarkerLabelPen( myMsg, QPen( Qt::red, 1 ) );
@@ -28,11 +28,16 @@ StdMeshersGUI_DistrPreview::StdMeshersGUI_DistrPreview( QWidget* p, StdMeshers::
   f.setPointSize( 14 );
   f.setBold( true );
   setMarkerFont( myMsg, f );
-  setCurvePen( myCurve1, QPen( Qt::red, 1 ) );
+  setCurvePen( myDensity, QPen( Qt::red, 1 ) );
 
   QColor dc = Qt::blue;
-  setCurvePen( myCurve2, QPen( dc, 1 ) );
-  setCurveSymbol( myCurve2, QwtSymbol( QwtSymbol::XCross, QBrush( dc ), QPen( dc ), QSize( 5, 5 ) ) );
+  setCurvePen( myDistr, QPen( dc, 1 ) );
+  setCurveSymbol( myDistr, QwtSymbol( QwtSymbol::XCross, QBrush( dc ), QPen( dc ), QSize( 5, 5 ) ) );
+  setAutoLegend( true );
+  enableLegend( true );
+  setLegendPos( Qwt::Bottom );
+  setCurveTitle( myDensity, tr( "SMESH_DENSITY_FUNC" ) );
+  setCurveTitle( myDistr, tr( "SMESH_DISTR" ) );
 }
 
 StdMeshersGUI_DistrPreview::~StdMeshersGUI_DistrPreview()
@@ -196,9 +201,9 @@ void StdMeshersGUI_DistrPreview::update()
       max_x = x[i];
   }
 
-  setAxisScale( curveXAxis( myCurve1 ), min_x, max_x );
-  setAxisScale( curveYAxis( myCurve1 ), min( 0.0, min_y ), max( 0.0, max_y ) );
-  setCurveData( myCurve1, x, y, size );
+  setAxisScale( curveXAxis( myDensity ), min_x, max_x );
+  setAxisScale( curveYAxis( myDensity ), min( 0.0, min_y ), max( 0.0, max_y ) );
+  setCurveData( myDensity, x, y, size );
   if( x )
     delete[] x;
   if( y )
@@ -213,19 +218,33 @@ void StdMeshersGUI_DistrPreview::update()
     x[i] = distr[i];
     y[i] = 0;
   }
-  setCurveData( myCurve2, x, y, size );
+  setCurveData( myDistr, x, y, size );
   delete[] x;
   delete[] y;
   x = y = 0;
-  replot();
+
+  OSD::SetSignal( true );
+  CASCatch_CatchSignals aCatchSignals;
+  aCatchSignals.Activate();
+
+  CASCatch_TRY
+  {   
+    replot();
+  }
+  CASCatch_CATCH(CASCatch_Failure)
+  {
+    aCatchSignals.Deactivate();
+    Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught();
+  }
+  aCatchSignals.Deactivate();
 }
 
 void StdMeshersGUI_DistrPreview::showError()
 {
-  setAxisScale( curveXAxis( myCurve1 ), 0.0, 1.0 );
-  setAxisScale( curveYAxis( myCurve1 ), 0.0, 1.0 );
-  setCurveData( myCurve1, 0, 0, 0 );
-  setCurveData( myCurve2, 0, 0, 0 );
+  setAxisScale( curveXAxis( myDensity ), 0.0, 1.0 );
+  setAxisScale( curveYAxis( myDensity ), 0.0, 1.0 );
+  setCurveData( myDensity, 0, 0, 0 );
+  setCurveData( myDistr, 0, 0, 0 );
   setMarkerLabel( myMsg, tr( "SMESH_INVALID_FUNCTION" ) );
   replot();
 }
index 5a3551daecfe7d42544137f8f6e2c004c0845351..2246588236c3f461e890da3577efd6d32876435f 100644 (file)
@@ -48,7 +48,7 @@ private:
   bool                      myIsTable;
   Conversion                myConv;
   SMESH::double_array       myTableFunc;
-  long                      myCurve1, myCurve2, myMsg;
+  long                      myDensity, myDistr, myMsg;
   Handle(ExprIntrp_GenExp)  myExpr;
   Expr_Array1OfNamedUnknown myVars;
   TColStd_Array1OfReal      myValues;
index db0b7f3ff3e5ed1bb9438639df808ba15a156f95..a68b6c9c71ad5b4239604b66a3946b4708b9e50d 100644 (file)
 //  $Header$
 
 #include "StdMeshersGUI_DistrTable.h"
+#include <QtxDblValidator.h>
+
 #include <qlayout.h>
 #include <qpushbutton.h>
-#include <qvalidator.h>
 #include <qlineedit.h>
 
 //=================================================================================
@@ -40,8 +41,8 @@ StdMeshersGUI_DistrTable::StdMeshersGUI_DistrTable( const int rows, QWidget* par
 {
   horizontalHeader()->setLabel( 0, "t" );
   horizontalHeader()->setLabel( 1, "f(t)" );
-  myArgV = new QDoubleValidator( 0.0, 1.0, 3, this );
-  myFuncV = new QDoubleValidator( 0.0, 1E10, 3, this );
+  myArgV = new QtxDblValidator( 0.0, 1.0, 3, this );
+  myFuncV = new QtxDblValidator( 0.0, 1E20, 3, this );
 }
 
 StdMeshersGUI_DistrTable::~StdMeshersGUI_DistrTable()
@@ -265,8 +266,24 @@ void StdMeshersGUI_DistrTable::setData( const SMESH::double_array& d )
 {
   stopEditing( false );
   setNumRows( d.length()/2 );
+  QString val;
   for( int i=0; i<d.length(); i++ )
-    setText( i/2, i%2, QString( "%1" ).arg( d[i] ) );
+  {
+    QtxDblValidator* v = i%2==0 ? myArgV : myFuncV;
+    val = QString::number( d[i] );
+    v->fixup( val );
+    setText( i/2, i%2, val );
+  }
+}
+
+QtxDblValidator* StdMeshersGUI_DistrTable::argValidator() const
+{
+  return myArgV;
+}
+
+QtxDblValidator* StdMeshersGUI_DistrTable::funcValidator() const
+{
+  return myFuncV;
 }
 
 //=================================================================================
@@ -346,3 +363,4 @@ void StdMeshersGUI_DistrTableFrame::onButtonClicked()
   else if( sender()==button( REMOVE_ROW ) )
     emit toEdit( REMOVE_ROW, table()->currentRow() );
 }
+
index 6f6ca829aad3fa4d860692b1acb186b0636237ef..c3597dfe2df7a568bd636be59e3c1ad8f8bae1d9 100644 (file)
@@ -34,7 +34,7 @@
 #include CORBA_SERVER_HEADER(SMESH_Mesh)
 
 class QButton;
-class QDoubleValidator;
+class QtxDblValidator;
 
 /*!
  *  \brief Values corresponding to buttons for table resize
@@ -65,6 +65,9 @@ public:
   void data( SMESH::double_array& );
   void setData( const SMESH::double_array& );
 
+  QtxDblValidator* argValidator() const;
+  QtxDblValidator* funcValidator() const;
+
 protected:
   virtual QWidget* createEditor( int, int, bool ) const;
   virtual bool     eventFilter( QObject*, QEvent* );
@@ -75,7 +78,7 @@ private slots:
   void onEdit( TableButton, int );
 
 private:
-  QDoubleValidator   *myArgV, *myFuncV;
+  QtxDblValidator   *myArgV, *myFuncV;
 };
 
 
@@ -122,6 +125,5 @@ private:
   StdMeshersGUI_DistrTable  *myTable;
 };
 
-
 #endif
 
index fa2dc3a8fb16b24e2f27e333c5d09e96491b5dac..728042c6594b9172de77751894790c1d88d9e7f5 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <QtxIntSpinBox.h>
 #include <QtxComboBox.h>
+#include <QtxDblValidator.h>
 #include <SMESHGUI_SpinBox.h>
 
 #include <qlabel.h>
@@ -142,7 +143,7 @@ QFrame* StdMeshersGUI_NbSegmentsCreator::buildFrame()
   myConv->setColumnLayout( 0, Qt::Vertical );
   QGridLayout* convLay = new QGridLayout( myConv->layout() );
   convLay->addWidget( new QRadioButton( tr( "SMESH_EXP_MODE" ), myConv ), 0, 0 );
-  convLay->addWidget( new QRadioButton( tr( "SMESH_CUT_NEG_MODE" ), myConv ), 1, 0 );
+  convLay->addWidget( myCutNeg = new QRadioButton( tr( "SMESH_CUT_NEG_MODE" ), myConv ), 1, 0 );
   myGroupLayout->addWidget( myConv, row, 1 );
   row++;
 
@@ -312,6 +313,19 @@ void StdMeshersGUI_NbSegmentsCreator::onValueChanged()
 {
   int distr = myDistr->currentItem();
 
+/*  if( distr==2 ) //table func
+    myCutNeg->setText( tr( "SMESH_NO_CONV" ) );
+  else if( distr==3 )
+    myCutNeg->setText( tr( "SMESH_CUT_NEG_MODE" ) );*/
+
+  if( distr==2 ) //table func
+  {
+    myTable->table()->funcValidator()->setBottom( myConv->id( myConv->selected() )==0 ? -1E20 : 0 );
+    SMESH::double_array arr;
+    myTable->table()->data( arr );
+    myTable->table()->setData( arr ); //update data in table
+  }
+
   myScale->setShown( distr==1 );
   myLScale->setShown( distr==1 );
 
index aaa880b5e0abbdf50d70cfedb6e619b2f6467343..6d902fe801943b5e46ebd1b1a2f6ee71053c3726 100644 (file)
@@ -15,6 +15,7 @@ class StdMeshersGUI_DistrPreview;
 class QLineEdit;
 class QButtonGroup;
 class QGridLayout;
+class QRadioButton;
 
 typedef struct
 {
@@ -59,6 +60,7 @@ private:
   QLabel          *myLScale, *myLTable, *myLExpr, *myLConv, *myInfo;
   QGridLayout*     myGroupLayout;
   int              myTableRow, myPreviewRow;
+  QRadioButton*    myCutNeg;
 };
 
 #endif
index 19cd9295ef97c53aa378972fe825f05cce01df3e..dc86b0046d7236927dc760fbfa74c62ac71464e0 100644 (file)
@@ -47,6 +47,12 @@ msgstr "Distribution with analitic density"
 msgid "SMESH_NB_SEGMENTS_SCALE_PARAM"
 msgstr "Scale Factor"
 
+msgid "SMESH_DENSITY_FUNC"
+msgstr "Density function"
+
+msgid "SMESH_DISTR"
+msgstr "Distribution"
+
 msgid "SMESH_TAB_FUNC"
 msgstr "Table function"
 
@@ -65,6 +71,9 @@ msgstr "Exponent"
 msgid "SMESH_CUT_NEG_MODE"
 msgstr "Cut negative"
 
+msgid "SMESH_NO_CONV"
+msgstr "No conversion"
+
 msgid "SMESH_INSERT_ROW"
 msgstr "Insert row"