From f1dec40ab1787dfb09d6529f1dcb547a6eb459be Mon Sep 17 00:00:00 2001 From: asl Date: Fri, 30 Dec 2005 08:29:24 +0000 Subject: [PATCH] PAL11054 - crash if user enters "-8" as density function with exponent conversion PAL11055 - it is impossible to enter negative function value in case, when exponent conversion is applied some remarks from PAL8238 --- .../StdMeshersGUI_DistrPreview.cxx | 47 +++++++++++++------ .../StdMeshersGUI_DistrPreview.h | 2 +- .../StdMeshersGUI_DistrTable.cxx | 26 ++++++++-- src/StdMeshersGUI/StdMeshersGUI_DistrTable.h | 8 ++-- .../StdMeshersGUI_NbSegmentsCreator.cxx | 16 ++++++- .../StdMeshersGUI_NbSegmentsCreator.h | 2 + src/StdMeshersGUI/StdMeshers_msg_en.po | 9 ++++ 7 files changed, 87 insertions(+), 23 deletions(-) diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx index f763fbd9c..0d66dc53a 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx @@ -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(); } diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h index 5a3551dae..224658823 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h @@ -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; diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx b/src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx index db0b7f3ff..a68b6c9c7 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx @@ -26,9 +26,10 @@ // $Header$ #include "StdMeshersGUI_DistrTable.h" +#include + #include #include -#include #include //================================================================================= @@ -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; ifixup( 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() ); } + diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrTable.h b/src/StdMeshersGUI/StdMeshersGUI_DistrTable.h index 6f6ca829a..c3597dfe2 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_DistrTable.h +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrTable.h @@ -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 diff --git a/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx index fa2dc3a8f..728042c65 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -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 ); diff --git a/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h index aaa880b5e..6d902fe80 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h +++ b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h @@ -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 diff --git a/src/StdMeshersGUI/StdMeshers_msg_en.po b/src/StdMeshersGUI/StdMeshers_msg_en.po index 19cd9295e..dc86b0046 100644 --- a/src/StdMeshersGUI/StdMeshers_msg_en.po +++ b/src/StdMeshersGUI/StdMeshers_msg_en.po @@ -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" -- 2.39.2