From d5d609e43788b3274fafb374818762e122cc9f00 Mon Sep 17 00:00:00 2001 From: ouv Date: Mon, 15 Dec 2008 12:42:46 +0000 Subject: [PATCH] Dump Python Extension --- src/SalomeApp/SalomeApp_DoubleSpinBox.cxx | 26 +++++++++++++------ src/SalomeApp/SalomeApp_DoubleSpinBox.h | 5 ++-- src/SalomeApp/SalomeApp_IntSpinBox.cxx | 31 +++++++++++++++++------ src/SalomeApp/SalomeApp_IntSpinBox.h | 5 ++-- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx index b40231f23..42cf9e48d 100644 --- a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx +++ b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx @@ -198,7 +198,9 @@ bool SalomeApp_DoubleSpinBox::isValid( QString& msg, bool toCorrect ) { if( toCorrect ) { - if( aState == NoVariable ) + if( aState == Incompatible ) + msg += tr( "ERR_INCOMPATIBLE_TYPE" ).arg( text() ) + "\n"; + else if( aState == NoVariable ) msg += tr( "ERR_NO_VARIABLE" ).arg( text() ) + "\n"; else if( aState == Invalid ) msg += tr( "ERR_INVALID_VALUE" ) + "\n"; @@ -261,13 +263,16 @@ void SalomeApp_DoubleSpinBox::setText( const QString& value ) */ SalomeApp_DoubleSpinBox::State SalomeApp_DoubleSpinBox::isValid( const QString& text, double& value ) const { - if( !findVariable( text, value ) ) + SearchState aSearchState = findVariable( text, value ); + if( aSearchState == NotFound ) { bool ok = false; value = text.toDouble( &ok ); if( !ok ) return NoVariable; } + else if( aSearchState == IncorrectType ) + return Incompatible; if( !checkRange( value ) ) return Invalid; @@ -301,10 +306,11 @@ bool SalomeApp_DoubleSpinBox::checkRange( const double value ) const /*! \brief This function is used to determine whether input is a variable name and to get its value. - \return true if the input is a variable name + \return status of search operation */ -bool SalomeApp_DoubleSpinBox::findVariable( const QString& name, double& value ) const +SalomeApp_DoubleSpinBox::SearchState SalomeApp_DoubleSpinBox::findVariable( const QString& name, double& value ) const { + value = 0; if( SalomeApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ) ) { if( SalomeApp_Study* study = dynamic_cast( app->activeStudy() ) ) @@ -312,14 +318,18 @@ bool SalomeApp_DoubleSpinBox::findVariable( const QString& name, double& value ) _PTR(Study) studyDS = study->studyDS(); std::string aName = name.toStdString(); - if( studyDS->IsVariable( aName ) && ( studyDS->IsReal( aName ) || studyDS->IsInteger( aName ) ) ) + if( studyDS->IsVariable( aName ) ) { - value = studyDS->GetReal( aName ); - return true; + if( studyDS->IsReal( aName ) || studyDS->IsInteger( aName ) ) + { + value = studyDS->GetReal( aName ); + return Found; + } + return IncorrectType; } } } - return false; + return NotFound; } /*! diff --git a/src/SalomeApp/SalomeApp_DoubleSpinBox.h b/src/SalomeApp/SalomeApp_DoubleSpinBox.h index 1bb25964d..c5b6539ca 100644 --- a/src/SalomeApp/SalomeApp_DoubleSpinBox.h +++ b/src/SalomeApp/SalomeApp_DoubleSpinBox.h @@ -32,7 +32,8 @@ class SALOMEAPP_EXPORT SalomeApp_DoubleSpinBox : public QtxDoubleSpinBox { Q_OBJECT - enum State { Invalid = 0, NoVariable, Acceptable }; + enum State { Invalid = 0, NoVariable, Incompatible, Acceptable }; + enum SearchState { NotFound = 0, IncorrectType, Found }; public: SalomeApp_DoubleSpinBox( QWidget* = 0 ); @@ -63,7 +64,7 @@ protected: double defaultValue() const; bool checkRange( const double ) const; - bool findVariable( const QString&, double& ) const; + SearchState findVariable( const QString&, double& ) const; protected: virtual void keyPressEvent( QKeyEvent* ); diff --git a/src/SalomeApp/SalomeApp_IntSpinBox.cxx b/src/SalomeApp/SalomeApp_IntSpinBox.cxx index c950062f6..4d3460a3b 100644 --- a/src/SalomeApp/SalomeApp_IntSpinBox.cxx +++ b/src/SalomeApp/SalomeApp_IntSpinBox.cxx @@ -168,7 +168,9 @@ bool SalomeApp_IntSpinBox::isValid( QString& msg, bool toCorrect ) { if( toCorrect ) { - if( aState == NoVariable ) + if( aState == Incompatible ) + msg += tr( "ERR_INCOMPATIBLE_TYPE" ).arg( text() ) + "\n"; + else if( aState == NoVariable ) msg += tr( "ERR_NO_VARIABLE" ).arg( text() ) + "\n"; else if( aState == Invalid ) msg += tr( "ERR_INVALID_VALUE" ) + "\n"; @@ -217,13 +219,21 @@ void SalomeApp_IntSpinBox::setText( const QString& value ) */ SalomeApp_IntSpinBox::State SalomeApp_IntSpinBox::isValid( const QString& text, int& value ) const { - if( !findVariable( text, value ) ) + SearchState aSearchState = findVariable( text, value ); + if( aSearchState == NotFound ) { bool ok = false; value = text.toInt( &ok ); if( !ok ) + { + text.toDouble( &ok ); + if( ok ) + return Invalid; return NoVariable; + } } + else if( aSearchState == IncorrectType ) + return Incompatible; if( !checkRange( value ) ) return Invalid; @@ -254,10 +264,11 @@ bool SalomeApp_IntSpinBox::checkRange( const int value ) const /*! \brief This function is used to determine whether input is a variable name and to get its value. - \return true if the input is a variable name + \return status of search operation */ -bool SalomeApp_IntSpinBox::findVariable( const QString& name, int& value ) const +SalomeApp_IntSpinBox::SearchState SalomeApp_IntSpinBox::findVariable( const QString& name, int& value ) const { + value = 0; if( SalomeApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ) ) { if( SalomeApp_Study* study = dynamic_cast( app->activeStudy() ) ) @@ -265,14 +276,18 @@ bool SalomeApp_IntSpinBox::findVariable( const QString& name, int& value ) const _PTR(Study) studyDS = study->studyDS(); std::string aName = name.toStdString(); - if( studyDS->IsVariable( aName ) && studyDS->IsInteger( aName ) ) + if( studyDS->IsVariable( aName ) ) { - value = studyDS->GetInteger( aName ); - return true; + if( studyDS->IsInteger( aName ) ) + { + value = studyDS->GetInteger( aName ); + return Found; + } + return IncorrectType; } } } - return false; + return NotFound; } /*! diff --git a/src/SalomeApp/SalomeApp_IntSpinBox.h b/src/SalomeApp/SalomeApp_IntSpinBox.h index 82508d83b..d15fe99c1 100644 --- a/src/SalomeApp/SalomeApp_IntSpinBox.h +++ b/src/SalomeApp/SalomeApp_IntSpinBox.h @@ -32,7 +32,8 @@ class SALOMEAPP_EXPORT SalomeApp_IntSpinBox : public QtxIntSpinBox { Q_OBJECT - enum State { Invalid = 0, NoVariable, Acceptable }; + enum State { Invalid = 0, NoVariable, Incompatible, Acceptable }; + enum SearchState { NotFound = 0, IncorrectType, Found }; public: SalomeApp_IntSpinBox( QWidget* = 0 ); @@ -61,7 +62,7 @@ protected: int defaultValue() const; bool checkRange( const int ) const; - bool findVariable( const QString&, int& ) const; + SearchState findVariable( const QString&, int& ) const; protected: virtual void keyPressEvent( QKeyEvent* ); -- 2.39.2