From 4d143a60e63acd96f6a92fb840d581a4a78e2bb2 Mon Sep 17 00:00:00 2001 From: ouv Date: Wed, 2 Dec 2009 16:02:07 +0000 Subject: [PATCH] Debug --- src/SalomeApp/SalomeApp_NoteBookDlg.cxx | 222 ++++++++++++-------- src/SalomeApp/SalomeApp_NoteBookDlg.h | 16 +- src/SalomeApp/SalomeApp_Notebook.cxx | 10 +- src/SalomeApp/SalomeApp_Notebook.h | 2 + src/SalomeApp/resources/SalomeApp_msg_en.ts | 14 +- 5 files changed, 154 insertions(+), 110 deletions(-) diff --git a/src/SalomeApp/SalomeApp_NoteBookDlg.cxx b/src/SalomeApp/SalomeApp_NoteBookDlg.cxx index 1614ce758..3be752564 100644 --- a/src/SalomeApp/SalomeApp_NoteBookDlg.cxx +++ b/src/SalomeApp/SalomeApp_NoteBookDlg.cxx @@ -335,19 +335,6 @@ void NoteBook_Table::markItem( NoteBook_TableRow* theRow, int theColumn, bool th } } -//============================================================================ -/*! Function : markRow - * Purpose : Mark the given row by red or black color - * (red color means incorrect value, black - correct) - */ -//============================================================================ -void NoteBook_Table::markRow( NoteBook_TableRow* theRow, bool theIsCorrect ) -{ - markItem( theRow, VARIABLE_COLUMN, theIsCorrect ); - markItem( theRow, EXPRESSION_COLUMN, theIsCorrect ); - markItem( theRow, VALUE_COLUMN, theIsCorrect ); -} - //============================================================================ /*! Function : checkItem * Purpose : Check validity of the item by its color @@ -362,6 +349,19 @@ bool NoteBook_Table::checkItem( NoteBook_TableRow* theRow, int theColumn ) const return false; } +//============================================================================ +/*! Function : markRow + * Purpose : Mark the given row by red or black color + * (red color means incorrect value, black - correct) + */ +//============================================================================ +void NoteBook_Table::markRow( NoteBook_TableRow* theRow, bool theIsCorrect ) +{ + markItem( theRow, VARIABLE_COLUMN, theIsCorrect ); + markItem( theRow, EXPRESSION_COLUMN, theIsCorrect ); + markItem( theRow, VALUE_COLUMN, theIsCorrect ); +} + //============================================================================ /*! Function : checkRow * Purpose : Check validity of the row by a color of its first item @@ -375,12 +375,14 @@ bool NoteBook_Table::checkRow( NoteBook_TableRow* theRow ) const } //============================================================================ -/*! Function : correctData - * Purpose : Try to correct data of the table +/*! Function : updateExpressions + * Purpose : Update variable expressions according to myNoteBook data + * (used after renaming or removing of some variable) */ //============================================================================ -void NoteBook_Table::correctData( int theBaseRowIndex ) +void NoteBook_Table::updateExpressions( int theBaseRowIndex ) { + bool isBlocked = blockSignals( true ); for( int i = 0, n = myRows.size(); i < n; i++ ) { if( NoteBook_TableRow* aRow = myRows[ i ] ) @@ -389,41 +391,39 @@ void NoteBook_Table::correctData( int theBaseRowIndex ) { QString aName = aRow->getVariable(); QString anExpression = myNoteBook->expression( aName ); + aRow->setExpression( anExpression ); } } } + blockSignals( isBlocked ); } //============================================================================ -/*! Function : updateExpressions - * Purpose : Update variable expressions according to myNoteBook data - * (used after renaming or removing of some variable) +/*! Function : updateValues + * Purpose : Update variable values according to myNoteBook data */ //============================================================================ -void NoteBook_Table::updateExpressions( int theBaseRowIndex ) +void NoteBook_Table::updateValues() { bool isBlocked = blockSignals( true ); for( int i = 0, n = myRows.size(); i < n; i++ ) { if( NoteBook_TableRow* aRow = myRows[ i ] ) { - if( aRow->getIndex() != theBaseRowIndex ) - { - QString aName = aRow->getVariable(); - QString anExpression = myNoteBook->expression( aName ); - aRow->setExpression( anExpression ); - } + QString aName = aRow->getVariable(); + QString aValue = myNoteBook->get( aName ).toString(); + aRow->setValue( aValue ); } } blockSignals( isBlocked ); } //============================================================================ -/*! Function : updateValues - * Purpose : Update variable values according to myNoteBook data +/*! Function : updateValidity + * Purpose : Update validity status of myNoteBook data */ //============================================================================ -void NoteBook_Table::updateValues() +void NoteBook_Table::updateValidity() { bool isBlocked = blockSignals( true ); for( int i = 0, n = myRows.size(); i < n; i++ ) @@ -431,8 +431,8 @@ void NoteBook_Table::updateValues() if( NoteBook_TableRow* aRow = myRows[ i ] ) { QString aName = aRow->getVariable(); - QVariant aValue = myNoteBook->get( aName ); - aRow->setValue( aValue.toString() ); + bool isValid = myNoteBook->isValid( aName ); + markRow( aRow, isValid ); } } blockSignals( isBlocked ); @@ -445,16 +445,12 @@ void NoteBook_Table::updateValues() //============================================================================ bool NoteBook_Table::setExpression( const QString& theName, const QString& theExpression, - bool theIsNew, - QString& theErrorType, - QString& theErrorMessage ) + bool theIsNew ) { - theErrorType.clear(); - theErrorMessage.clear(); - int iVal; double dVal; bool bVal; + QString anErrorType, anErrorMessage; try { if( NoteBook_TableRow::isIntegerValue( theExpression, &iVal ) ) @@ -467,54 +463,94 @@ bool NoteBook_Table::setExpression( const QString& theName, myNoteBook->set( theName, theExpression, theIsNew ); } catch( const SALOME::NotebookError& ex ) { - theErrorType = tr( "NOTEBOOK_ERROR" ); - theErrorMessage = ex.Reason.in(); + anErrorType = tr( "NOTEBOOK_ERROR" ); + anErrorMessage = ex.Reason.in(); } catch( const SALOME::ExpressionError& ex ) { - theErrorType = tr( "EXPRESSION_ERROR" ); - theErrorMessage = ex.Reason.in(); + anErrorType = tr( "EXPRESSION_ERROR" ); + anErrorMessage = ex.Reason.in(); } catch( const SALOME::CalculationError& ex ) { - theErrorType = tr( "CALCULATION_ERROR" ); - theErrorMessage = ex.Reason.in(); + anErrorType = tr( "CALCULATION_ERROR" ); + anErrorMessage = ex.Reason.in(); } catch( const SALOME::TypeError& ex ) { - theErrorType = tr( "TYPE_ERROR" ); - theErrorMessage = ex.Reason.in(); + anErrorType = tr( "TYPE_ERROR" ); + anErrorMessage = ex.Reason.in(); } - return theErrorType.isEmpty(); + if( !anErrorType.isEmpty() ) + { + SUIT_MessageBox::warning( this, anErrorType, anErrorMessage ); + return false; + } + return true; } //============================================================================ -/*! Function : setExpression +/*! Function : renameVariable * Purpose : Try to rename the variable */ //============================================================================ bool NoteBook_Table::renameVariable( const QString& theOldName, - const QString& theNewName, - QString& theErrorType, - QString& theErrorMessage ) + const QString& theNewName ) { - theErrorType.clear(); - theErrorMessage.clear(); - + QString anErrorType, anErrorMessage; try { myNoteBook->rename( theOldName, theNewName ); } catch( const SALOME::NotebookError& ex ) { - theErrorType = tr( "NOTEBOOK_ERROR" ); - theErrorMessage = ex.Reason.in(); + anErrorType = tr( "NOTEBOOK_ERROR" ); + anErrorMessage = ex.Reason.in(); } catch( const SALOME::ExpressionError& ex ) { - theErrorType = tr( "EXPRESSION_ERROR" ); - theErrorMessage = ex.Reason.in(); + anErrorType = tr( "EXPRESSION_ERROR" ); + anErrorMessage = ex.Reason.in(); } catch( const SALOME::CalculationError& ex ) { - theErrorType = tr( "CALCULATION_ERROR" ); - theErrorMessage = ex.Reason.in(); + anErrorType = tr( "CALCULATION_ERROR" ); + anErrorMessage = ex.Reason.in(); } catch( const SALOME::TypeError& ex ) { - theErrorType = tr( "TYPE_ERROR" ); - theErrorMessage = ex.Reason.in(); + anErrorType = tr( "TYPE_ERROR" ); + anErrorMessage = ex.Reason.in(); } - return theErrorType.isEmpty(); + if( !anErrorType.isEmpty() ) + { + SUIT_MessageBox::warning( this, anErrorType, anErrorMessage ); + return false; + } + return true; +} + +//============================================================================ +/*! Function : updateNoteBook + * Purpose : Try to update notebook + */ +//============================================================================ +bool NoteBook_Table::updateNoteBook( bool theOnlyParameters ) +{ + QString anErrorType, anErrorMessage; + try + { + myNoteBook->update( theOnlyParameters ); + } + catch( const SALOME::NotebookError& ex ) { + anErrorType = tr( "NOTEBOOK_ERROR" ); + anErrorMessage = ex.Reason.in(); + } catch( const SALOME::ExpressionError& ex ) { + anErrorType = tr( "EXPRESSION_ERROR" ); + anErrorMessage = ex.Reason.in(); + } catch( const SALOME::CalculationError& ex ) { + anErrorType = tr( "CALCULATION_ERROR" ); + anErrorMessage = ex.Reason.in(); + } catch( const SALOME::TypeError& ex ) { + anErrorType = tr( "TYPE_ERROR" ); + anErrorMessage = ex.Reason.in(); + } + + if( !anErrorType.isEmpty() ) + { + SUIT_MessageBox::warning( this, anErrorType, anErrorMessage ); + return false; + } + return true; } //============================================================================ @@ -651,11 +687,22 @@ bool NoteBook_Table::isLastRow( const NoteBook_TableRow* theRow ) const //============================================================================ void NoteBook_Table::onItemChanged( QTableWidgetItem* theItem ) { - NoteBook_TableRow* aRow = getRowByItem( theItem ); - if( !aRow ) - return; + if( NoteBook_TableRow* aRow = getRowByItem( theItem ) ) + { + int aColumn = column( theItem ); + processItemChanged( aRow, aColumn ); + updateValidity(); + } +} - int anIndex = aRow->getIndex(); +//============================================================================ +/*! Function : processItemChanged + * Purpose : Process item data changing + */ +//============================================================================ +void NoteBook_Table::processItemChanged( NoteBook_TableRow* theRow, int theColumn ) +{ + int anIndex = theRow->getIndex(); if( !myVariableMap.contains( anIndex ) ) return; @@ -664,44 +711,31 @@ void NoteBook_Table::onItemChanged( QTableWidgetItem* theItem ) QString anExpressionPrevious = aVariable.Expression; bool isCompletePrevious = !aVariable.Name.isEmpty() && !aVariable.Expression.isEmpty(); - bool isCorrectPrevious = checkRow( aRow ); - markRow( aRow, true ); + bool isCorrectPrevious = checkRow( theRow ); - QString aName = aRow->getVariable(); - QString anExpression = aRow->getExpression(); + QString aName = theRow->getVariable(); + QString anExpression = theRow->getExpression(); bool isComplete = !aName.isEmpty() && !anExpression.isEmpty(); aVariable.Name = aName; aVariable.Expression = anExpression; - QString anErrorType, anErrorMessage; - - int aCurrentColumn = column( theItem ); - if( aCurrentColumn == VARIABLE_COLUMN && isCompletePrevious && isCorrectPrevious && aName != aNamePrevious ) + if( theColumn == VARIABLE_COLUMN && isCompletePrevious && isCorrectPrevious && aName != aNamePrevious ) { - if( !renameVariable( aNamePrevious, aName, anErrorType, anErrorMessage ) ) - { - SUIT_MessageBox::warning( this, anErrorType, anErrorMessage ); - markRow( aRow, false ); + if( !renameVariable( aNamePrevious, aName ) ) return; - } updateExpressions( anIndex ); - return; // not necessary to update notebook data after renaming + return; // it is not necessary to update notebook data after renaming } - - if( isComplete ) + else if( isComplete ) { - if( !setExpression( aName, anExpression, !isCompletePrevious, anErrorType, anErrorMessage ) ) - { - SUIT_MessageBox::warning( this, anErrorType, anErrorMessage ); - markRow( aRow, false ); + if( !setExpression( aName, anExpression, !isCompletePrevious ) ) return; - } - myNoteBook->update( true ); + updateNoteBook( true ); updateValues(); } - if( isLastRow( aRow ) && isComplete ) + if( isLastRow( theRow ) && isComplete ) { bool isBlocked = blockSignals( true ); addRow(); @@ -898,7 +932,7 @@ void SalomeApp_NoteBookDlg::onUpdateStudy() } QApplication::setOverrideCursor( Qt::WaitCursor ); - myNoteBook->update( false ); + myTable->updateNoteBook( false ); QApplication::restoreOverrideCursor(); } @@ -909,14 +943,16 @@ void SalomeApp_NoteBookDlg::onUpdateStudy() //============================================================================ void SalomeApp_NoteBookDlg::onClose() { - if( !myTable->isValid() && + bool isTableValid = myTable->isValid(); + if( !isTableValid && SUIT_MessageBox::question( this, tr( "CLOSE_CAPTION" ), tr( "INCORRECT_DATA_ON_CLOSE" ), QMessageBox::Ok | QMessageBox::Cancel, - QMessageBox::Cancel ) != QMessageBox::Ok ) + QMessageBox::Cancel ) == QMessageBox::Cancel ) return; // update only variables - myNoteBook->update( true ); + if( isTableValid && !myTable->updateNoteBook( true ) ) + return; accept(); } diff --git a/src/SalomeApp/SalomeApp_NoteBookDlg.h b/src/SalomeApp/SalomeApp_NoteBookDlg.h index 90d0c2e52..25cbdcf9e 100644 --- a/src/SalomeApp/SalomeApp_NoteBookDlg.h +++ b/src/SalomeApp/SalomeApp_NoteBookDlg.h @@ -97,6 +97,8 @@ public: void removeSelected(); + bool updateNoteBook( bool theOnlyParameters ); + protected slots: void onItemChanged( QTableWidgetItem* theItem ); @@ -104,23 +106,19 @@ private: void clear(); int getUniqueIndex() const; void markItem( NoteBook_TableRow* theRow, int theColumn, bool theIsCorrect ); - void markRow( NoteBook_TableRow* theRow, bool theIsCorrect ); bool checkItem( NoteBook_TableRow* theRow, int theColumn ) const; + void markRow( NoteBook_TableRow* theRow, bool theIsCorrect ); bool checkRow( NoteBook_TableRow* theRow ) const; - void correctData( int theBaseRowIndex ); void updateExpressions( int theBaseRowIndex ); void updateValues(); + void updateValidity(); bool setExpression( const QString& theName, const QString& theExpression, - bool theIsNew, - QString& theErrorType, - QString& theErrorMessage ); + bool theIsNew ); bool renameVariable( const QString& theOldName, - const QString& theNewName, - QString& theErrorType, - QString& theErrorMessage ); + const QString& theNewName ); void addRow( const QString& theName = QString::null, const QString& theExpression = QString::null ); @@ -128,6 +126,8 @@ private: NoteBook_TableRow* getRowByItem( const QTableWidgetItem* theItem ) const; bool isLastRow( const NoteBook_TableRow* aRow ) const; + void processItemChanged( NoteBook_TableRow* theRow, int theColumn ); + private: QList myRows; diff --git a/src/SalomeApp/SalomeApp_Notebook.cxx b/src/SalomeApp/SalomeApp_Notebook.cxx index 1a1c5ca83..a07b18985 100644 --- a/src/SalomeApp/SalomeApp_Notebook.cxx +++ b/src/SalomeApp/SalomeApp_Notebook.cxx @@ -116,10 +116,16 @@ QVariant SalomeApp_Notebook::calculate( const QString& theExpr ) } } myTmp->SetExpression( theExpr.toLatin1().constData() ); - myTmp->Update( SALOME::Notebook::_duplicate( myNotebook ) ); + myTmp->Update( myNotebook.in() ); return convert( myTmp ); } +bool SalomeApp_Notebook::isValid( const QString& theName ) const +{ + SALOME::Parameter_var aParam = myNotebook->GetParameter( theName.toLatin1().constData() ); + return CORBA::is_nil( aParam ) ? false : aParam->IsValid(); +} + QVariant SalomeApp_Notebook::convert( SALOME::Parameter_ptr theParam ) const { QVariant aRes; @@ -223,7 +229,7 @@ void SalomeApp_Notebook::setParameters( SALOME::ParameterizedObject_ptr theObjec i++; } - theObject->SetParameters( SALOME::Notebook::_duplicate( myNotebook ), aParams ); + theObject->SetParameters( myNotebook.in(), aParams ); } QString SalomeApp_Notebook::getParameters( const QString& theComponent, const QString& theEntry ) diff --git a/src/SalomeApp/SalomeApp_Notebook.h b/src/SalomeApp/SalomeApp_Notebook.h index 2d4e12b78..33e5dfb3d 100644 --- a/src/SalomeApp/SalomeApp_Notebook.h +++ b/src/SalomeApp/SalomeApp_Notebook.h @@ -54,6 +54,8 @@ public: QString expression( const QString& theName ) const; QVariant calculate( const QString& theExpr ); + bool isValid( const QString& theName ) const; + void update( bool theOnlyParameters ); void remove( const QString& theParamName ); diff --git a/src/SalomeApp/resources/SalomeApp_msg_en.ts b/src/SalomeApp/resources/SalomeApp_msg_en.ts index a62694ab7..88c110be7 100644 --- a/src/SalomeApp/resources/SalomeApp_msg_en.ts +++ b/src/SalomeApp/resources/SalomeApp_msg_en.ts @@ -392,13 +392,6 @@ Do you want to reload it ? VALUE Value - - - SalomeApp_NoteBookDlg - - NOTEBOOK_TITLE - Salome NoteBook - NOTEBOOK_ERROR NoteBook error @@ -415,6 +408,13 @@ Do you want to reload it ? TYPE_ERROR Type error + + + SalomeApp_NoteBookDlg + + NOTEBOOK_TITLE + Salome NoteBook + BUT_UPDATE_STUDY &Update Study -- 2.39.2