From: ouv Date: Mon, 30 Nov 2009 13:21:56 +0000 (+0000) Subject: Preparation of intermediate revision X-Git-Tag: PHASE_17_Part1_V1~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=67389417fb6963c55943059058affbab212eba4a;p=modules%2Fgui.git Preparation of intermediate revision --- diff --git a/src/SalomeApp/SalomeApp_DataObject.cxx b/src/SalomeApp/SalomeApp_DataObject.cxx index e3511dce4..a9caeaadf 100644 --- a/src/SalomeApp/SalomeApp_DataObject.cxx +++ b/src/SalomeApp/SalomeApp_DataObject.cxx @@ -504,7 +504,7 @@ QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const for ( int i = 0, n = aStringList.size(); i < n; i++ ) { QString aStr = aStringList[i]; - if ( aNb.get( aStr ).isValid() ) + if ( aNb.isParameter( aStr ) ) val.append( aStr + ", " ); } diff --git a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx index f63495e23..9ead23dc4 100644 --- a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx +++ b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx @@ -19,9 +19,6 @@ // File: SalomeApp_DoubleSpinBox.cxx // Author: Oleg UVAROV -#include // this include must be first (see PyInterp_base.h)! -#include - #include "SalomeApp_DoubleSpinBox.h" #include "SalomeApp_Application.h" #include "SalomeApp_Study.h" @@ -29,15 +26,9 @@ #include -#include "SALOMEDSClient_ClientFactory.hxx" -#include CORBA_SERVER_HEADER(SALOMEDS) - #include #include -#include - - /*! \class SalomeApp_DoubleSpinBox */ @@ -199,18 +190,19 @@ QValidator::State SalomeApp_DoubleSpinBox::validate( QString& str, int& pos ) co bool SalomeApp_DoubleSpinBox::isValid( QString& msg, bool toCorrect ) { double value; - State aState = isValid( text(), value ); + QString absent; + State aState = isValid( text(), value, &absent ); if( aState != Acceptable ) { if( toCorrect ) { if( aState == Incompatible ) - msg += tr( "ERR_INCOMPATIBLE_TYPE" ).arg( text() ) + "\n"; - else if( aState == NoVariable ) - msg += tr( "ERR_NO_VARIABLE" ).arg( text() ) + "\n"; + msg += tr( "ERR_INCOMPATIBLE_TYPE" ).arg( text() ) + "\n"; + else if( aState == NoVariable && !absent.isEmpty() ) + msg += tr( "ERR_NO_VARIABLE" ).arg( absent ) + "\n"; else if( aState == Invalid ) - msg += tr( "ERR_INVALID_VALUE" ) + "\n"; + msg += tr( "ERR_INVALID_VALUE" ) + "\n"; setText( myCorrectValue ); } @@ -268,9 +260,9 @@ void SalomeApp_DoubleSpinBox::setText( const QString& value ) \brief This function is used to determine whether input is valid. \return validating operation result */ -SalomeApp_DoubleSpinBox::State SalomeApp_DoubleSpinBox::isValid( const QString& text, double& value ) const +SalomeApp_DoubleSpinBox::State SalomeApp_DoubleSpinBox::isValid( const QString& text, double& value, QString* absent ) const { - SearchState aSearchState = findVariable( text, value ); + SearchState aSearchState = findVariable( text, value, absent ); if( aSearchState == NotFound ) { bool ok = false; @@ -280,6 +272,8 @@ SalomeApp_DoubleSpinBox::State SalomeApp_DoubleSpinBox::isValid( const QString& } else if( aSearchState == IncorrectType ) return Incompatible; + else if( aSearchState == IncorrectExpression ) + return Invalid; if( !checkRange( value ) ) return Invalid; @@ -315,50 +309,49 @@ 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 status of search operation */ -SalomeApp_DoubleSpinBox::SearchState SalomeApp_DoubleSpinBox::findVariable( const QString& name, double& value ) const +SalomeApp_DoubleSpinBox::SearchState SalomeApp_DoubleSpinBox::findVariable( const QString& name, double& value, QString* absent ) const { value = 0; if( SalomeApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ) ) { if( SalomeApp_Study* study = dynamic_cast( app->activeStudy() ) ) { - std::string aName = name.toStdString(); - // SalomeApp_Notebook aNotebook( study ); - bool bisParameter=aNotebook.isParameter(name); - // - if (bisParameter) + QStringList anAbsentParameters = aNotebook.absentParameters( name ); + if( !anAbsentParameters.isEmpty() ) + { + if( absent ) + *absent = anAbsentParameters.join( "\", \"" ); + return NotFound; + } + + QVariant aVariant; + if( aNotebook.isParameter( name ) ) + aVariant = aNotebook.get( name ); + else + { + try { + aVariant = aNotebook.calculate( name ); + } catch ( const SALOME::TypeError& ex ) { + return IncorrectType; + } catch ( const SALOME::ExpressionError& ex ) { + return IncorrectExpression; + } + } + + QVariant::Type aType = aVariant.type(); + if( aType == QVariant::Double || aType == QVariant::Int || aType == QVariant::String ) { - QVariant aVariant=aNotebook.get(name); - QVariant::Type aType=aVariant.type(); - - if(aType==QVariant::Double || aType==QVariant::Int || aType==QVariant::String) - { - if(aType==QVariant::String) - { - PyConsole_Console* pyConsole = app->pythonConsole(); - PyConsole_Interp* pyInterp = pyConsole->getInterp(); - PyLockWrapper aLock = pyInterp->GetLockWrapper(); - std::string command; - command = "import salome_notebook ; "; - command += "salome_notebook.notebook.setAsReal(\""; - command += aName; - command += "\")"; - bool aResult; - aResult = pyInterp->run(command.c_str()); - if(aResult) - { - return IncorrectType; - } - } - bool bOk; - value = aVariant.toDouble(&bOk); - return Found; - } - return IncorrectType; + bool ok = false; + value = aVariant.toDouble( &ok ); + if( ok ) + return Found; } + return IncorrectType; } } + if( absent ) + *absent = name; return NotFound; } diff --git a/src/SalomeApp/SalomeApp_DoubleSpinBox.h b/src/SalomeApp/SalomeApp_DoubleSpinBox.h index c5b6539ca..66da0ab6d 100644 --- a/src/SalomeApp/SalomeApp_DoubleSpinBox.h +++ b/src/SalomeApp/SalomeApp_DoubleSpinBox.h @@ -33,7 +33,7 @@ class SALOMEAPP_EXPORT SalomeApp_DoubleSpinBox : public QtxDoubleSpinBox Q_OBJECT enum State { Invalid = 0, NoVariable, Incompatible, Acceptable }; - enum SearchState { NotFound = 0, IncorrectType, Found }; + enum SearchState { NotFound = 0, IncorrectType, IncorrectExpression, Found }; public: SalomeApp_DoubleSpinBox( QWidget* = 0 ); @@ -53,18 +53,18 @@ public: virtual void setRange( double, double ); virtual void setValue( double ); - virtual void setText(const QString& ); + virtual void setText( const QString& ); signals: void textChanged( const QString& ); protected: - State isValid( const QString&, double& ) const; + State isValid( const QString&, double&, QString* = 0 ) const; double defaultValue() const; bool checkRange( const double ) const; - SearchState findVariable( const QString&, double& ) const; + SearchState findVariable( const QString&, double&, QString* = 0 ) const; protected: virtual void keyPressEvent( QKeyEvent* ); diff --git a/src/SalomeApp/SalomeApp_IntSpinBox.cxx b/src/SalomeApp/SalomeApp_IntSpinBox.cxx index fbae1e297..99746baeb 100644 --- a/src/SalomeApp/SalomeApp_IntSpinBox.cxx +++ b/src/SalomeApp/SalomeApp_IntSpinBox.cxx @@ -19,9 +19,6 @@ // File: SalomeApp_IntSpinBox.cxx // Author: Oleg UVAROV -#include //this include must be first (see PyInterp_base.h)! -#include - #include "SalomeApp_IntSpinBox.h" #include "SalomeApp_Application.h" #include "SalomeApp_Study.h" @@ -29,14 +26,9 @@ #include -#include "SALOMEDSClient_ClientFactory.hxx" -#include CORBA_SERVER_HEADER(SALOMEDS) - #include #include -#include - /*! \class SalomeApp_IntSpinBox */ @@ -168,18 +160,19 @@ QValidator::State SalomeApp_IntSpinBox::validate( QString& str, int& pos ) const bool SalomeApp_IntSpinBox::isValid( QString& msg, bool toCorrect ) { int value; - State aState = isValid( text(), value ); + QString absent; + State aState = isValid( text(), value, &absent ); if( aState != Acceptable ) { if( toCorrect ) { if( aState == Incompatible ) - msg += tr( "ERR_INCOMPATIBLE_TYPE" ).arg( text() ) + "\n"; - else if( aState == NoVariable ) - msg += tr( "ERR_NO_VARIABLE" ).arg( text() ) + "\n"; + msg += tr( "ERR_INCOMPATIBLE_TYPE" ).arg( text() ) + "\n"; + else if( aState == NoVariable && !absent.isEmpty() ) + msg += tr( "ERR_NO_VARIABLE" ).arg( absent ) + "\n"; else if( aState == Invalid ) - msg += tr( "ERR_INVALID_VALUE" ) + "\n"; + msg += tr( "ERR_INVALID_VALUE" ) + "\n"; setText( myCorrectValue ); } @@ -223,9 +216,9 @@ void SalomeApp_IntSpinBox::setText( const QString& value ) \brief This function is used to determine whether input is valid. \return validating operation result */ -SalomeApp_IntSpinBox::State SalomeApp_IntSpinBox::isValid( const QString& text, int& value ) const +SalomeApp_IntSpinBox::State SalomeApp_IntSpinBox::isValid( const QString& text, int& value, QString* absent ) const { - SearchState aSearchState = findVariable( text, value ); + SearchState aSearchState = findVariable( text, value, absent ); if( aSearchState == NotFound ) { bool ok = false; @@ -240,6 +233,8 @@ SalomeApp_IntSpinBox::State SalomeApp_IntSpinBox::isValid( const QString& text, } else if( aSearchState == IncorrectType ) return Incompatible; + else if( aSearchState == IncorrectExpression ) + return Invalid; if( !checkRange( value ) ) return Invalid; @@ -272,50 +267,49 @@ 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 status of search operation */ -SalomeApp_IntSpinBox::SearchState SalomeApp_IntSpinBox::findVariable( const QString& name, int& value ) const +SalomeApp_IntSpinBox::SearchState SalomeApp_IntSpinBox::findVariable( const QString& name, int& value, QString* absent ) const { value = 0; if( SalomeApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ) ) { if( SalomeApp_Study* study = dynamic_cast( app->activeStudy() ) ) { - std::string aName = name.toStdString(); - // SalomeApp_Notebook aNotebook( study ); - bool bisParameter=aNotebook.isParameter(name); - // - if(bisParameter) + QStringList anAbsentParameters = aNotebook.absentParameters( name ); + if( !anAbsentParameters.isEmpty() ) + { + if( absent ) + *absent = anAbsentParameters.join( "\", \"" ); + return NotFound; + } + + QVariant aVariant; + if( aNotebook.isParameter( name ) ) + aVariant = aNotebook.get( name ); + else + { + try { + aVariant = aNotebook.calculate( name ); + } catch ( const SALOME::TypeError& ex ) { + return IncorrectType; + } catch ( const SALOME::ExpressionError& ex ) { + return IncorrectExpression; + } + } + + QVariant::Type aType = aVariant.type(); + if( aType == QVariant::Int || aType == QVariant::String ) { - QVariant aVariant=aNotebook.get(name); - QVariant::Type aType=aVariant.type(); - - if(aType==QVariant::Int || aType==QVariant::String) - { - if(aType==QVariant::String) - { - PyConsole_Console* pyConsole = app->pythonConsole(); - PyConsole_Interp* pyInterp = pyConsole->getInterp(); - PyLockWrapper aLock = pyInterp->GetLockWrapper(); - std::string command; - command = "import salome_notebook ; "; - command += "salome_notebook.notebook.setAsInteger(\""; - command += aName; - command += "\")"; - bool aResult; - aResult = pyInterp->run(command.c_str()); - if(aResult) - { - return IncorrectType; - } - } - bool bOk; - value = aVariant.toInt(&bOk); - return Found; - } - return IncorrectType; + bool ok = false; + value = aVariant.toInt( &ok ); + if( ok ) + return Found; } + return IncorrectType; } } + if( absent ) + *absent = name; return NotFound; } diff --git a/src/SalomeApp/SalomeApp_IntSpinBox.h b/src/SalomeApp/SalomeApp_IntSpinBox.h index d15fe99c1..5df15d3ae 100644 --- a/src/SalomeApp/SalomeApp_IntSpinBox.h +++ b/src/SalomeApp/SalomeApp_IntSpinBox.h @@ -33,7 +33,7 @@ class SALOMEAPP_EXPORT SalomeApp_IntSpinBox : public QtxIntSpinBox Q_OBJECT enum State { Invalid = 0, NoVariable, Incompatible, Acceptable }; - enum SearchState { NotFound = 0, IncorrectType, Found }; + enum SearchState { NotFound = 0, IncorrectType, IncorrectExpression, Found }; public: SalomeApp_IntSpinBox( QWidget* = 0 ); @@ -51,18 +51,18 @@ public: virtual void setValue( int ); - virtual void setText(const QString& ); + virtual void setText( const QString& ); signals: void textChanged( const QString& ); protected: - State isValid( const QString&, int& ) const; + State isValid( const QString&, int&, QString* = 0 ) const; int defaultValue() const; bool checkRange( const int ) const; - SearchState findVariable( const QString&, int& ) const; + SearchState findVariable( const QString&, int&, QString* = 0 ) const; protected: virtual void keyPressEvent( QKeyEvent* ); diff --git a/src/SalomeApp/SalomeApp_NoteBookDlg.cxx b/src/SalomeApp/SalomeApp_NoteBookDlg.cxx index 79db2f479..b9a172008 100644 --- a/src/SalomeApp/SalomeApp_NoteBookDlg.cxx +++ b/src/SalomeApp/SalomeApp_NoteBookDlg.cxx @@ -35,13 +35,14 @@ #include #include -#define DEFAULT_MARGIN 11 -#define DEFAULT_SPACING 6 -#define COLUMN_SIZE 180 - -#define NAME_COLUMN 0 -#define VALUE_COLUMN 1 +#define VARIABLE_COLUMN 0 +#define EXPRESSION_COLUMN 1 +#define VALUE_COLUMN 2 +#define VARIABLE_COLUMN_SIZE 120 +#define EXPRESSION_COLUMN_SIZE 180 +#define VALUE_COLUMN_SIZE 100 +#define GAP_SIZE 80 /////////////////////////////////////////////////////////////////////////// // NoteBook_TableRow class // @@ -51,13 +52,16 @@ * Purpose : Constructor */ //============================================================================ -NoteBook_TableRow::NoteBook_TableRow(int index, QWidget* parent): - QWidget(parent), - myIndex(index), - myRowHeader(new QTableWidgetItem()), - myVariableName(new QTableWidgetItem()), - myVariableValue(new QTableWidgetItem()) +NoteBook_TableRow::NoteBook_TableRow( int index, QWidget* parent ): + QWidget( parent ), + myIndex( index ), + myRowHeaderItem( new QTableWidgetItem() ), + myVariableItem( new QTableWidgetItem() ), + myExpressionItem( new QTableWidgetItem() ), + myValueItem( new QTableWidgetItem() ) { + Qt::ItemFlags aFlags = myValueItem->flags(); + myValueItem->setFlags( aFlags ^ Qt::ItemIsEditable ); } //============================================================================ @@ -74,86 +78,77 @@ NoteBook_TableRow::~NoteBook_TableRow() * Purpose : Add this row to the table theTable */ //============================================================================ -void NoteBook_TableRow::AddToTable(QTableWidget *theTable) +void NoteBook_TableRow::AddToTable( QTableWidget *theTable ) { int aPosition = theTable->rowCount(); int aRowCount = aPosition+1; - theTable->setRowCount(aRowCount); - myRowHeader->setText(QString::number(aRowCount)); + theTable->setRowCount( aRowCount ); + myRowHeaderItem->setText( QString::number( aRowCount ) ); - theTable->setVerticalHeaderItem(aPosition,myRowHeader); - theTable->setItem(aPosition, NAME_COLUMN, myVariableName); - theTable->setItem(aPosition, VALUE_COLUMN, myVariableValue); + theTable->setVerticalHeaderItem( aPosition, myRowHeaderItem ); + theTable->setItem( aPosition, VARIABLE_COLUMN, myVariableItem ); + theTable->setItem( aPosition, EXPRESSION_COLUMN, myExpressionItem ); + theTable->setItem( aPosition, VALUE_COLUMN, myValueItem ); } //============================================================================ -/*! Function : SetName +/*! Function : SetVariable * Purpose : */ //============================================================================ -void NoteBook_TableRow::SetName(const QString theName) +void NoteBook_TableRow::SetVariable( const QString& theVariable ) { - myVariableName->setText(theName); + myVariableItem->setText( theVariable ); } //============================================================================ -/*! Function : SetValue +/*! Function : SetExpression * Purpose : */ //============================================================================ -void NoteBook_TableRow::SetValue(const QString theValue) +void NoteBook_TableRow::SetExpression( const QString& theExpression ) { - myVariableValue->setText(theValue); + myExpressionItem->setText( theExpression ); } //============================================================================ -/*! Function : GetName - * Purpose : Return variable name - */ -//============================================================================ -QString NoteBook_TableRow::GetName() const -{ - return myVariableName->text(); -} - -//============================================================================ -/*! Function : GetValue - * Purpose : Return variable value +/*! Function : SetValue + * Purpose : */ //============================================================================ -QString NoteBook_TableRow::GetValue() const +void NoteBook_TableRow::SetValue( const QString& theValue ) { - return myVariableValue->text(); + myValueItem->setText( theValue ); } //============================================================================ -/*! Function : GetVariableItem - * Purpose : +/*! Function : GetVariable + * Purpose : Return variable name */ //============================================================================ -QTableWidgetItem* NoteBook_TableRow::GetVariableItem() +QString NoteBook_TableRow::GetVariable() const { - return myVariableValue; + return myVariableItem->text(); } //============================================================================ -/*! Function : GetNameItem - * Purpose : +/*! Function : GetExpression + * Purpose : Return variable expression */ //============================================================================ -QTableWidgetItem* NoteBook_TableRow::GetNameItem() +QString NoteBook_TableRow::GetExpression() const { - return myVariableName; + return myExpressionItem->text(); } //============================================================================ -/*! Function : GetHeaderItem - * Purpose : +/*! Function : GetValue + * Purpose : Return variable value */ //============================================================================ -QTableWidgetItem* NoteBook_TableRow::GetHeaderItem() +QString NoteBook_TableRow::GetValue() const { - return myRowHeader; + return myValueItem->text(); } //============================================================================ @@ -162,11 +157,11 @@ QTableWidgetItem* NoteBook_TableRow::GetHeaderItem() * false */ //============================================================================ -bool NoteBook_TableRow::IsRealValue(const QString theValue, double* theResult) +bool NoteBook_TableRow::IsRealValue( const QString theValue, double* theResult ) { bool aResult = false; - double aDResult = theValue.toDouble(&aResult); - if(aResult && theResult) + double aDResult = theValue.toDouble( &aResult ); + if( aResult && theResult ) *theResult = aDResult; return aResult; @@ -178,18 +173,21 @@ bool NoteBook_TableRow::IsRealValue(const QString theValue, double* theResult) * false */ //============================================================================ -bool NoteBook_TableRow::IsBooleanValue(const QString theValue, bool* theResult){ +bool NoteBook_TableRow::IsBooleanValue( const QString theValue, bool* theResult ) +{ bool aResult = false; bool aBResult; - if(theValue.compare("True") == 0) { + if( theValue.compare( "True" ) == 0 ) + { aBResult = true; aResult = true; } - else if(theValue.compare("False") == 0) { + else if( theValue.compare( "False" ) == 0 ) + { aBResult = false; aResult = true; } - if(aResult && theResult) + if( aResult && theResult ) *theResult = aBResult; return aResult; @@ -201,13 +199,13 @@ bool NoteBook_TableRow::IsBooleanValue(const QString theValue, bool* theResult){ * false */ //============================================================================ -bool NoteBook_TableRow::IsIntegerValue(const QString theValue, int* theResult) +bool NoteBook_TableRow::IsIntegerValue( const QString theValue, int* theResult ) { bool aResult = false; int anIResult; - anIResult = theValue.toInt(&aResult); + anIResult = theValue.toInt( &aResult ); - if(aResult && theResult) + if( aResult && theResult ) *theResult = anIResult; return aResult; @@ -221,7 +219,7 @@ bool NoteBook_TableRow::IsIntegerValue(const QString theValue, int* theResult) * The whole notebook is verified on apply */ //============================================================================ -bool NoteBook_TableRow::IsValidStringValue(const QString theValue) +bool NoteBook_TableRow::IsValidStringValue( const QString theValue ) { return true; } @@ -234,33 +232,42 @@ bool NoteBook_TableRow::IsValidStringValue(const QString theValue) * Purpose : Constructor */ //============================================================================ -NoteBook_Table::NoteBook_Table(QWidget * parent) - :QTableWidget(parent) +NoteBook_Table::NoteBook_Table( QWidget* parent ) + : QTableWidget( parent ) { - setColumnCount(2); - setSelectionMode(QAbstractItemView::SingleSelection); + setColumnCount( 3 ); + setSelectionMode( QAbstractItemView::SingleSelection ); - //Add Headers Columns + // Add headers columns QFont aFont = QFont(); - aFont.setBold(true); - aFont.setPointSize(10); + aFont.setBold( true ); + aFont.setPointSize( 10 ); - //"Name" column - QTableWidgetItem * aNameHeader = new QTableWidgetItem(); - aNameHeader->setText(tr("VARNAME_COLUMN")); - aNameHeader->setFont(aFont); - setHorizontalHeaderItem(0,aNameHeader); - setColumnWidth ( 0, COLUMN_SIZE); - - //"Value" Column - QTableWidgetItem * aValueHeader = new QTableWidgetItem(); - aValueHeader->setText(tr("VARVALUE_COLUMN")); - aValueHeader->setFont(aFont); - setHorizontalHeaderItem(1,aValueHeader); - setColumnWidth ( 1, COLUMN_SIZE); - setSortingEnabled(false); + // "Variable" column + QTableWidgetItem* aVariableHeader = new QTableWidgetItem(); + aVariableHeader->setText( tr( "VARIABLE" ) ); + aVariableHeader->setFont( aFont ); + setHorizontalHeaderItem( VARIABLE_COLUMN, aVariableHeader ); + setColumnWidth( VARIABLE_COLUMN, VARIABLE_COLUMN_SIZE ); + + // "Expression" column + QTableWidgetItem* anExpressionHeader = new QTableWidgetItem(); + anExpressionHeader->setText( tr( "EXPRESSION" ) ); + anExpressionHeader->setFont( aFont ); + setHorizontalHeaderItem( EXPRESSION_COLUMN, anExpressionHeader ); + setColumnWidth( EXPRESSION_COLUMN, EXPRESSION_COLUMN_SIZE ); + setSortingEnabled( false ); + + // "Value" column + QTableWidgetItem* aValueHeader = new QTableWidgetItem(); + aValueHeader->setText( tr( "VALUE" ) ); + aValueHeader->setFont( aFont ); + setHorizontalHeaderItem( VALUE_COLUMN, aValueHeader ); + setColumnWidth( VALUE_COLUMN, VALUE_COLUMN_SIZE ); + setSortingEnabled( false ); - connect(this,SIGNAL(itemChanged(QTableWidgetItem*)),this,SLOT(onItemChanged(QTableWidgetItem*))); + connect( this, SIGNAL( itemChanged( QTableWidgetItem* ) ), + this, SLOT( onItemChanged( QTableWidgetItem* ) ) ); } //============================================================================ @@ -268,20 +275,30 @@ NoteBook_Table::NoteBook_Table(QWidget * parent) * Purpose : Destructor */ //============================================================================ -NoteBook_Table::~NoteBook_Table(){} +NoteBook_Table::~NoteBook_Table() +{ + clear(); +} -void NoteBook_Table::printVariableMap() +//============================================================================ +/*! Function : clear + * Purpose : Clear contents of the table + */ +//============================================================================ +void NoteBook_Table::clear() { - printf( "VariableMap:\n" ); - VariableMap::const_iterator it = myVariableMap.constBegin(), itEnd = myVariableMap.constEnd(); - for( ; it != itEnd; ++it ) + bool isBlocked = blockSignals( true ); + for( int i = 0, n = myRows.size(); i < n; i++ ) { - int anIndex = it.key(); - const NoteBoox_Variable& aVariable = it.value(); - QString aName = aVariable.Name; - QString aValue = aVariable.Value; - printf( "%d - %s - %s\n", anIndex, aName.toLatin1().constData(), aValue.toLatin1().constData() ); + if( NoteBook_TableRow* aRow = myRows[ i ] ) + { + delete aRow; + aRow = 0; + } } + myRows.clear(); + setRowCount( 0 ); + blockSignals( isBlocked ); } //============================================================================ @@ -309,7 +326,8 @@ int NoteBook_Table::getUniqueIndex() const void NoteBook_Table::markItem( NoteBook_TableRow* theRow, int theColumn, bool theIsCorrect ) { if( QTableWidgetItem* anItem = - theColumn == NAME_COLUMN ? theRow->GetNameItem() : theRow->GetVariableItem() ) + theColumn == VARIABLE_COLUMN ? theRow->GetVariableItem() : + theColumn == EXPRESSION_COLUMN ? theRow->GetExpressionItem() : theRow->GetValueItem() ) { bool isBlocked = blockSignals( true ); anItem->setForeground( QBrush( theIsCorrect ? Qt::black : Qt::red ) ); @@ -317,57 +335,218 @@ 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 item by its color + * Purpose : Check validity of the item by its color */ //============================================================================ -bool NoteBook_Table::checkItem( QTableWidgetItem* theItem ) const +bool NoteBook_Table::checkItem( NoteBook_TableRow* theRow, int theColumn ) const { - return theItem->foreground().color() == Qt::black; + if( QTableWidgetItem* anItem = + theColumn == VARIABLE_COLUMN ? theRow->GetVariableItem() : + theColumn == EXPRESSION_COLUMN ? theRow->GetExpressionItem() : theRow->GetValueItem() ) + return anItem->foreground().color() == Qt::black; + return false; } //============================================================================ -/*! Function : Init - * Purpose : Add variables in the table from theNoteBook +/*! Function : checkRow + * Purpose : Check validity of the row by a color of its first item */ //============================================================================ -void NoteBook_Table::Init(SalomeApp_Notebook* theNoteBook) +bool NoteBook_Table::checkRow( NoteBook_TableRow* theRow ) const { - bool isBlocked = blockSignals( true ); + return checkItem( theRow, VARIABLE_COLUMN ) && + checkItem( theRow, EXPRESSION_COLUMN ) && + checkItem( theRow, VALUE_COLUMN ); +} - int aNumRows = myRows.count(); - if( aNumRows > 0 ) +//============================================================================ +/*! Function : correctData + * Purpose : Try to correct data of the table + */ +//============================================================================ +void NoteBook_Table::correctData( int theBaseRowIndex ) +{ + for( int i = 0, n = myRows.size(); i < n; i++ ) { - for( int i = 0; i < myRows.size(); i++ ) + if( NoteBook_TableRow* aRow = myRows[ i ] ) { - NoteBook_TableRow* aRow = myRows[ i ]; - if( aRow ) + if( aRow->GetIndex() != theBaseRowIndex ) { - delete aRow; - aRow = 0; + QString aName = aRow->GetVariable(); + QString anExpression = myNoteBook->expression( aName ); } } - myRows.clear(); } - setRowCount( 0 ); +} + +//============================================================================ +/*! Function : updateExpressions + * Purpose : Update variable expressions according to myNoteBook data + * (used after renaming or removing of some variable) + */ +//============================================================================ +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 ] ) + { + if( aRow->GetIndex() != theBaseRowIndex ) + { + QString aName = aRow->GetVariable(); + QString anExpression = myNoteBook->expression( aName ); + aRow->SetExpression( anExpression ); + } + } + } + blockSignals( isBlocked ); +} + +//============================================================================ +/*! Function : updateValues + * Purpose : Update variable values according to myNoteBook data + */ +//============================================================================ +void NoteBook_Table::updateValues() +{ + bool isBlocked = blockSignals( true ); + for( int i = 0, n = myRows.size(); i < n; i++ ) + { + if( NoteBook_TableRow* aRow = myRows[ i ] ) + { + QString aName = aRow->GetVariable(); + QVariant aValue = myNoteBook->get( aName ); + aRow->SetValue( aValue.toString() ); + } + } + blockSignals( isBlocked ); +} + +//============================================================================ +/*! Function : setExpression + * Purpose : Try to set expression of the variable + */ +//============================================================================ +bool NoteBook_Table::setExpression( const QString& theName, + const QString& theExpression, + bool theIsNew, + QString& theErrorType, + QString& theErrorMessage ) +{ + theErrorType.clear(); + theErrorMessage.clear(); + int iVal; + double dVal; + bool bVal; + try + { + if( NoteBook_TableRow::IsIntegerValue( theExpression, &iVal ) ) + myNoteBook->set( theName, iVal, theIsNew ); + else if( NoteBook_TableRow::IsRealValue( theExpression, &dVal ) ) + myNoteBook->set( theName, dVal, theIsNew ); + else if( NoteBook_TableRow::IsBooleanValue( theExpression, &bVal ) ) + myNoteBook->set( theName, bVal, theIsNew ); + else if( NoteBook_TableRow::IsValidStringValue( theExpression ) ) + myNoteBook->set( theName, theExpression, theIsNew ); + } + catch( const SALOME::NotebookError& ex ) { + theErrorType = tr( "NOTEBOOK_ERROR" ); + theErrorMessage = ex.Reason.in(); + } catch( const SALOME::ExpressionError& ex ) { + theErrorType = tr( "EXPRESSION_ERROR" ); + theErrorMessage = ex.Reason.in(); + } catch( const SALOME::CalculationError& ex ) { + theErrorType = tr( "CALCULATION_ERROR" ); + theErrorMessage = ex.Reason.in(); + } catch( const SALOME::TypeError& ex ) { + theErrorType = tr( "TYPE_ERROR" ); + theErrorMessage = ex.Reason.in(); + } + + return theErrorType.isEmpty(); +} + +//============================================================================ +/*! Function : setExpression + * Purpose : Try to rename the variable + */ +//============================================================================ +bool NoteBook_Table::renameVariable( const QString& theOldName, + const QString& theNewName, + QString& theErrorType, + QString& theErrorMessage ) +{ + theErrorType.clear(); + theErrorMessage.clear(); + + try + { + myNoteBook->rename( theOldName, theNewName ); + } + catch( const SALOME::NotebookError& ex ) { + theErrorType = tr( "NOTEBOOK_ERROR" ); + theErrorMessage = ex.Reason.in(); + } catch( const SALOME::ExpressionError& ex ) { + theErrorType = tr( "EXPRESSION_ERROR" ); + theErrorMessage = ex.Reason.in(); + } catch( const SALOME::CalculationError& ex ) { + theErrorType = tr( "CALCULATION_ERROR" ); + theErrorMessage = ex.Reason.in(); + } catch( const SALOME::TypeError& ex ) { + theErrorType = tr( "TYPE_ERROR" ); + theErrorMessage = ex.Reason.in(); + } + + return theErrorType.isEmpty(); +} + +//============================================================================ +/*! Function : Init + * Purpose : Add variables in the table from theNoteBook + */ +//============================================================================ +void NoteBook_Table::Init( SalomeApp_Notebook* theNoteBook ) +{ + myNoteBook = theNoteBook; + + bool isBlocked = blockSignals( true ); + + clear(); myVariableMap.clear(); - //Add all variables into the table - QStringList aVariables = theNoteBook->parameters(); + // Add all variables into the table + QStringList aVariables = myNoteBook->parameters(); QStringListIterator anIter( aVariables ); while( anIter.hasNext() ) { QString aVariable = anIter.next(); - QString aVariableValue = theNoteBook->get(aVariable).toString(); + if( aVariable.left( 2 ).compare( "__" ) == 0 ) // tmp variable + continue; + QString aVariableValue = myNoteBook->expression(aVariable); AddRow( aVariable, aVariableValue ); } - //Add empty row + // Add empty row AddRow(); - myNoteBook = theNoteBook; + updateValues(); blockSignals( isBlocked ); } @@ -383,15 +562,15 @@ bool NoteBook_Table::IsValid() const if( aNumRows == 0 ) return true; - if( !myRows[ aNumRows - 1 ]->GetName().isEmpty() || + if( !myRows[ aNumRows - 1 ]->GetVariable().isEmpty() || + !myRows[ aNumRows - 1 ]->GetExpression().isEmpty() || !myRows[ aNumRows - 1 ]->GetValue().isEmpty() ) return false; - for( int aRow = 0, aRowCount = rowCount(); aRow < aRowCount; aRow++ ) - for( int aCol = 0, aColCount = columnCount(); aCol < aColCount; aCol++ ) - if( QTableWidgetItem* anItem = item( aRow, aCol ) ) - if( !checkItem( anItem ) ) - return false; + for( int i = 0, n = myRows.size(); i < n; i++ ) + if( NoteBook_TableRow* aRow = myRows[ i ] ) + if( !checkRow( aRow ) ) + return false; return true; } @@ -401,16 +580,16 @@ bool NoteBook_Table::IsValid() const * Purpose : Add a row into the table */ //============================================================================ -void NoteBook_Table::AddRow(const QString& theName, const QString& theValue) +void NoteBook_Table::AddRow( const QString& theName, const QString& theExpression ) { int anIndex = getUniqueIndex(); - NoteBook_TableRow* aRow = new NoteBook_TableRow(anIndex, this); - aRow->SetName(theName); - aRow->SetValue(theValue); - aRow->AddToTable(this); - myRows.append(aRow); + NoteBook_TableRow* aRow = new NoteBook_TableRow( anIndex, this ); + aRow->SetVariable( theName ); + aRow->SetExpression( theExpression ); + aRow->AddToTable( this ); + myRows.append( aRow ); - myVariableMap.insert( anIndex, NoteBoox_Variable( theName, theValue ) ); + myVariableMap.insert( anIndex, NoteBoox_Variable( theName, theExpression ) ); } //============================================================================ @@ -418,14 +597,12 @@ void NoteBook_Table::AddRow(const QString& theName, const QString& theValue) * Purpose : */ //============================================================================ -NoteBook_TableRow* NoteBook_Table::GetRowByItem(const QTableWidgetItem* theItem) const +NoteBook_TableRow* NoteBook_Table::GetRowByItem( const QTableWidgetItem* theItem ) const { - int aCurrentRow = row(theItem); - - if( (myRows.size() <= aCurrentRow ) && (aCurrentRow < 0)) - return NULL; - else - return myRows.at(aCurrentRow); + int aCurrentRow = row( theItem ); + if( aCurrentRow >= 0 && aCurrentRow < myRows.size() ) + return myRows.at( aCurrentRow ); + return NULL; } //============================================================================ @@ -433,9 +610,9 @@ NoteBook_TableRow* NoteBook_Table::GetRowByItem(const QTableWidgetItem* theItem) * Purpose : Return true if theRow is last row in the table */ //============================================================================ -bool NoteBook_Table::IsLastRow(const NoteBook_TableRow* theRow) const +bool NoteBook_Table::IsLastRow( const NoteBook_TableRow* theRow ) const { - return (myRows.last() == theRow); + return theRow == myRows.last(); } //============================================================================ @@ -443,13 +620,8 @@ bool NoteBook_Table::IsLastRow(const NoteBook_TableRow* theRow) const * Purpose : [slot] called then table item changed */ //============================================================================ -void NoteBook_Table::onItemChanged(QTableWidgetItem* theItem) +void NoteBook_Table::onItemChanged( QTableWidgetItem* theItem ) { - //printf( "onItemChanged( %d, %d )\n", theItem->row(), theItem->column() ); - - //printf( "Before:\n" ); - //printVariableMap(); - NoteBook_TableRow* aRow = GetRowByItem( theItem ); if( !aRow ) return; @@ -459,106 +631,53 @@ void NoteBook_Table::onItemChanged(QTableWidgetItem* theItem) return; NoteBoox_Variable& aVariable = myVariableMap[ anIndex ]; + QString aNamePrevious = aVariable.Name; + QString anExpressionPrevious = aVariable.Expression; + bool isCompletePrevious = !aVariable.Name.isEmpty() && !aVariable.Expression.isEmpty(); + + bool isCorrectPrevious = checkRow( aRow ); + markRow( aRow, true ); + + QString aName = aRow->GetVariable(); + QString anExpression = aRow->GetExpression(); + bool isComplete = !aName.isEmpty() && !anExpression.isEmpty(); - QString aName = aRow->GetName(); - QString aValue = aRow->GetValue(); - bool isComplete = !aName.isEmpty() && !aValue.isEmpty(); + aVariable.Name = aName; + aVariable.Expression = anExpression; QString anErrorType, anErrorMessage; int aCurrentColumn = column( theItem ); - if( aCurrentColumn == NAME_COLUMN ) + if( aCurrentColumn == VARIABLE_COLUMN && isCompletePrevious && isCorrectPrevious && aName != aNamePrevious ) { - if( !aVariable.Name.isEmpty() && !aVariable.Value.isEmpty() && aName != aVariable.Name) - { // just rename and return - try - { - myNoteBook->rename( aVariable.Name, aName ); - } - 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 ); - - //aRow->SetValue( aVariable.Value ); - markItem( aRow, aCurrentColumn, false ); - - return; - } + if( !renameVariable( aNamePrevious, aName, anErrorType, anErrorMessage ) ) + { + SUIT_MessageBox::warning( this, anErrorType, anErrorMessage ); + markRow( aRow, false ); + return; } - aVariable.Name = aName; - return; + updateExpressions( anIndex ); + return; // not necessary to update notebook data after renaming } if( isComplete ) { - int iVal; - double dVal; - bool bVal; - QString anErrorType, anErrorMessage; - try - { - //printf( "myNoteBook->set( %s, %s )\n", aName.toLatin1().constData(), aValue.toLatin1().constData() ); - if( NoteBook_TableRow::IsIntegerValue( aValue, &iVal ) ) - myNoteBook->set( aName, iVal ); - else if( NoteBook_TableRow::IsRealValue( aValue, &dVal ) ) - myNoteBook->set( aName, dVal ); - else if( NoteBook_TableRow::IsBooleanValue( aValue, &bVal ) ) - myNoteBook->set( aName, bVal ); - else if( NoteBook_TableRow::IsValidStringValue( aValue ) ) - myNoteBook->set( aName, aValue ); - aVariable.Value = aValue; - } - 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() ) + if( !setExpression( aName, anExpression, !isCompletePrevious, anErrorType, anErrorMessage ) ) { SUIT_MessageBox::warning( this, anErrorType, anErrorMessage ); - - //aRow->SetValue( aVariable.Value ); - markItem( aRow, aCurrentColumn, false ); - + markRow( aRow, false ); return; } + myNoteBook->update( true ); + updateValues(); } - markItem( aRow, NAME_COLUMN, true ); - markItem( aRow, VALUE_COLUMN, true ); - - if( IsLastRow( aRow ) ) // && isComplete + if( IsLastRow( aRow ) && isComplete ) { bool isBlocked = blockSignals( true ); AddRow(); blockSignals( isBlocked ); } - - //printf( "After:\n" ); - //printVariableMap(); } //============================================================================ @@ -578,28 +697,28 @@ void NoteBook_Table::RemoveSelected() { if( IsLastRow( aRow ) ) { - aRow->SetName( QString() ); - aRow->SetValue( QString() ); + aRow->SetVariable( QString() ); + aRow->SetExpression( QString() ); } else { - int nRow = row( anItem ); - int index = aRow->GetIndex(); - - QString aName = aRow->GetName(); - if( myVariableMap.contains( index ) ) - myVariableMap.remove( index ); + int anIndex = aRow->GetIndex(); + QString aName = aRow->GetVariable(); + if( myVariableMap.contains( anIndex ) ) + myVariableMap.remove( anIndex ); + int nRow = row( anItem ); removeRow( nRow ); myRows.removeAt( nRow ); myNoteBook->remove( aName ); + updateExpressions( anIndex ); } } // renumber header items - for( int i = 0; i < myRows.size(); i++ ) - myRows[i]->GetHeaderItem()->setText( QString::number( i+1 ) ); + for( int i = 0, n = myRows.size(); i < n; i++ ) + myRows[i]->GetRowHeaderItem()->setText( QString::number( i+1 ) ); } blockSignals( isBlocked ); @@ -613,67 +732,67 @@ void NoteBook_Table::RemoveSelected() * Purpose : Constructor */ //============================================================================ -SalomeApp_NoteBookDlg::SalomeApp_NoteBookDlg(QWidget* parent, SalomeApp_Study* theStudy): - QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), - myNoteBook(0) +SalomeApp_NoteBookDlg::SalomeApp_NoteBookDlg( QWidget* parent, SalomeApp_Study* theStudy ) + : QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ), + myNoteBook( 0 ) { - setModal(false); - setObjectName("SalomeApp_NoteBookDlg"); - setWindowTitle(tr("NOTEBOOK_TITLE")); + setModal( false ); + setWindowTitle( tr( "NOTEBOOK_TITLE" ) ); - QGridLayout* aLayout = new QGridLayout(this); - aLayout->setMargin(DEFAULT_MARGIN); - aLayout->setSpacing(DEFAULT_SPACING); - - //Table - myTable = new NoteBook_Table(this); - aLayout->addWidget(myTable, 0, 0, 1, 3); + // Table + myTable = new NoteBook_Table( this ); - //Buttons - myRemoveButton = new QPushButton(tr("BUT_REMOVE")); - aLayout->addWidget(myRemoveButton, 1, 0, 1, 1); - - QSpacerItem* spacer = - new QSpacerItem(DEFAULT_SPACING, 5 , QSizePolicy::Expanding, QSizePolicy::Minimum); - aLayout->addItem(spacer, 1, 1, 2, 1); - - myUpdateStudyBtn = new QPushButton(tr("BUT_UPDATE_STUDY")); - aLayout->addWidget(myUpdateStudyBtn, 1, 2, 1, 1); + // Buttons + QPushButton* aRemoveBtn = new QPushButton( tr( "BUT_REMOVE" ) ); + QSpacerItem* aSpacer1 = new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ); + QPushButton* aDumpBtn = new QPushButton( tr( "BUT_DUMP" ) ); + QPushButton* anUpdateStudyBtn = new QPushButton( tr( "BUT_UPDATE_STUDY" ) ); - QGroupBox* groupBox = new QGroupBox(this); - - QBoxLayout* aLayout1 = new QHBoxLayout(groupBox); - - aLayout1->setMargin(DEFAULT_MARGIN); - aLayout1->setSpacing(DEFAULT_SPACING); - - myCloseBtn = new QPushButton(tr("BUT_CLOSE")); - aLayout1->addWidget(myCloseBtn); - - QSpacerItem* spacer1 = - new QSpacerItem(DEFAULT_SPACING, 5, QSizePolicy::Expanding, QSizePolicy::Minimum); - aLayout1->addItem(spacer1); - - myHelpBtn = new QPushButton(tr("BUT_HELP")); - aLayout1->addWidget(myHelpBtn); + QGroupBox* aGroupBox = new QGroupBox( this ); + + QPushButton* aCloseBtn = new QPushButton( tr( "BUT_CLOSE" ) ); + QSpacerItem* aSpacer2 = new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ); + QPushButton* aHelpBtn = new QPushButton( tr( "BUT_HELP" ) ); + + QBoxLayout* aLayout = new QHBoxLayout( aGroupBox ); + aLayout->setMargin( 11 ); + aLayout->setSpacing( 6 ); + aLayout->addWidget( aCloseBtn ); + aLayout->addItem( aSpacer2 ); + aLayout->addWidget( aHelpBtn ); - aLayout->addWidget(groupBox, 2, 0, 1, 3); - - setMinimumWidth( 2 * COLUMN_SIZE + 50 ); + QGridLayout* aTopLayout = new QGridLayout( this ); + aTopLayout->setMargin( 11 ); + aTopLayout->setSpacing( 6 ); + aTopLayout->addWidget( myTable, 0, 0, 1, 4 ); + aTopLayout->addWidget( aRemoveBtn, 1, 0, 1, 1 ); + aTopLayout->addItem( aSpacer1, 1, 1, 2, 1 ); + aTopLayout->addWidget( aDumpBtn, 1, 2, 1, 1 ); + aTopLayout->addWidget( anUpdateStudyBtn, 1, 3, 1, 1 ); + aTopLayout->addWidget( aGroupBox, 2, 0, 1, 4 ); + + setMinimumWidth( VARIABLE_COLUMN_SIZE + + EXPRESSION_COLUMN_SIZE + + VALUE_COLUMN_SIZE + + GAP_SIZE ); QWidgetList aWidgetList; aWidgetList.append( myTable ); - aWidgetList.append( myRemoveButton ); - aWidgetList.append( myUpdateStudyBtn ); - aWidgetList.append( myCloseBtn ); - aWidgetList.append( myHelpBtn ); + aWidgetList.append( aRemoveBtn ); + aWidgetList.append( aDumpBtn ); + aWidgetList.append( anUpdateStudyBtn ); + aWidgetList.append( aCloseBtn ); + aWidgetList.append( aHelpBtn ); Qtx::setTabOrder( aWidgetList ); - connect( myRemoveButton, SIGNAL(clicked()), this, SLOT(onRemove())); - connect( myUpdateStudyBtn, SIGNAL(clicked()), this, SLOT(onUpdateStudy()) ); - connect( myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()) ); - connect( myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp())); + connect( aRemoveBtn, SIGNAL( clicked() ), this, SLOT( onRemove() ) ); + connect( aDumpBtn, SIGNAL( clicked() ), this, SLOT( onDump() ) ); + connect( anUpdateStudyBtn, SIGNAL( clicked() ), this, SLOT( onUpdateStudy() ) ); + connect( aCloseBtn, SIGNAL( clicked() ), this, SLOT( onClose() ) ); + connect( aHelpBtn, SIGNAL( clicked() ), this, SLOT( onHelp() ) ); + //aDumpBtn->hide(); + Init( theStudy ); } @@ -696,7 +815,7 @@ SalomeApp_NoteBookDlg::~SalomeApp_NoteBookDlg() * Purpose : init variable table */ //============================================================================ -void SalomeApp_NoteBookDlg::Init(SalomeApp_Study* theStudy) +void SalomeApp_NoteBookDlg::Init( SalomeApp_Study* theStudy ) { // delete the current notebook (if can based on another study) if( myNoteBook ) @@ -717,6 +836,16 @@ void SalomeApp_NoteBookDlg::onRemove() myTable->RemoveSelected(); } +//============================================================================ +/*! Function : onDump + * Purpose : [slot] + */ +//============================================================================ +void SalomeApp_NoteBookDlg::onDump() +{ + SUIT_MessageBox::information( this, tr( "NOTEBOOK_TITLE" ), QString( myNoteBook->dump() ) ); +} + //============================================================================ /*! Function : onUpdateStudy * Purpose : [slot] @@ -724,19 +853,14 @@ void SalomeApp_NoteBookDlg::onRemove() //============================================================================ void SalomeApp_NoteBookDlg::onUpdateStudy() { - //printf( "Notebook:\n%s", myNoteBook->dump() ); - //printf( "-----------------------------------------\n" ); - //return; - - //onApply(); if( !myTable->IsValid() ) + { + SUIT_MessageBox::warning( this, tr( "ERROR" ), tr( "INCORRECT_DATA_ON_UPDATE" ) ); return; + } QApplication::setOverrideCursor( Qt::WaitCursor ); - myNoteBook->update( false ); - //SUIT_MessageBox::warning( this, tr( "ERROR" ), tr( "ERR_UPDATE_STUDY_FAILED" ) ); - QApplication::restoreOverrideCursor(); } @@ -748,9 +872,14 @@ void SalomeApp_NoteBookDlg::onUpdateStudy() void SalomeApp_NoteBookDlg::onClose() { if( !myTable->IsValid() && - SUIT_MessageBox::question( this, tr( "CLOSE_CAPTION" ), tr( "INCORRECT_DATA" ), - QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel ) != QMessageBox::Ok ) + SUIT_MessageBox::question( this, tr( "CLOSE_CAPTION" ), tr( "INCORRECT_DATA_ON_CLOSE" ), + QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Cancel ) != QMessageBox::Ok ) return; + + // update only variables + myNoteBook->update( true ); + accept(); } @@ -761,21 +890,21 @@ void SalomeApp_NoteBookDlg::onClose() //============================================================================ void SalomeApp_NoteBookDlg::onHelp() { - QString aHelpFileName("using_notebook.html"); - LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication()); - if (app) - app->onHelpContextModule("GUI",aHelpFileName); - else { + QString aHelpFileName( "using_notebook.html" ); + LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() ); + if( app ) + app->onHelpContextModule( "GUI", aHelpFileName ); + else + { QString platform; #ifdef WIN32 platform = "winapplication"; #else platform = "application"; #endif - SUIT_MessageBox::warning(this, tr("WRN_WARNING"), - tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE"). - arg(app->resourceMgr()->stringValue("ExternalBrowser", - platform)). - arg(aHelpFileName)); + SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), + tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ). + arg( app->resourceMgr()->stringValue("ExternalBrowser", platform ) ). + arg( aHelpFileName ) ); } } diff --git a/src/SalomeApp/SalomeApp_NoteBookDlg.h b/src/SalomeApp/SalomeApp_NoteBookDlg.h index 10d4ee883..f2e4e3c30 100644 --- a/src/SalomeApp/SalomeApp_NoteBookDlg.h +++ b/src/SalomeApp/SalomeApp_NoteBookDlg.h @@ -29,22 +29,19 @@ #include #include -class QPushButton; -class QTableWidgetItem; - class SalomeApp_Notebook; class SalomeApp_Study; struct NoteBoox_Variable { NoteBoox_Variable() {} - NoteBoox_Variable( const QString& theName, const QString& theValue ) + NoteBoox_Variable( const QString& theName, const QString& theExpression ) { Name = theName; - Value = theValue; + Expression = theExpression; } QString Name; - QString Value; + QString Expression; }; typedef QMap< int, NoteBoox_Variable > VariableMap; @@ -57,28 +54,32 @@ class SALOMEAPP_EXPORT NoteBook_TableRow : public QWidget int GetIndex() const { return myIndex; } - void AddToTable(QTableWidget *theTable); + void AddToTable( QTableWidget *theTable ); - void SetName(const QString theName); - void SetValue(const QString theValue); + void SetVariable( const QString& theVariable ); + void SetExpression( const QString& theExpression ); + void SetValue( const QString& theValue ); + QString GetVariable() const; + QString GetExpression() const; QString GetValue() const; - QString GetName() const; - QTableWidgetItem* GetVariableItem(); - QTableWidgetItem* GetNameItem(); - QTableWidgetItem* GetHeaderItem(); + QTableWidgetItem* GetRowHeaderItem() { return myRowHeaderItem; } + QTableWidgetItem* GetVariableItem() { return myVariableItem; } + QTableWidgetItem* GetExpressionItem() { return myExpressionItem; } + QTableWidgetItem* GetValueItem() { return myValueItem; } - static bool IsRealValue(const QString theValue, double* theResult = 0); - static bool IsIntegerValue(const QString theValue, int* theResult = 0); - static bool IsBooleanValue(const QString theValue, bool* theResult = 0); - static bool IsValidStringValue(const QString theName); + static bool IsRealValue( const QString theValue, double* theResult = 0 ); + static bool IsIntegerValue( const QString theValue, int* theResult = 0 ); + static bool IsBooleanValue( const QString theValue, bool* theResult = 0 ); + static bool IsValidStringValue( const QString theName ); private: int myIndex; - QTableWidgetItem* myRowHeader; - QTableWidgetItem* myVariableName; - QTableWidgetItem* myVariableValue; + QTableWidgetItem* myRowHeaderItem; + QTableWidgetItem* myVariableItem; + QTableWidgetItem* myExpressionItem; + QTableWidgetItem* myValueItem; }; class SALOMEAPP_EXPORT NoteBook_Table : public QTableWidget @@ -94,21 +95,37 @@ public: bool IsValid() const; void AddRow( const QString& theName = QString::null, - const QString& theValue = QString::null ); + const QString& theExpression = QString::null ); - NoteBook_TableRow* GetRowByItem(const QTableWidgetItem* theItem) const; - bool IsLastRow(const NoteBook_TableRow* aRow) const; + NoteBook_TableRow* GetRowByItem( const QTableWidgetItem* theItem ) const; + bool IsLastRow( const NoteBook_TableRow* aRow ) const; void RemoveSelected(); protected slots: - void onItemChanged(QTableWidgetItem* theItem); + void onItemChanged( QTableWidgetItem* theItem ); private: - void printVariableMap(); // tmp + void clear(); int getUniqueIndex() const; void markItem( NoteBook_TableRow* theRow, int theColumn, bool theIsCorrect ); - bool checkItem( QTableWidgetItem* theItem ) const; + void markRow( NoteBook_TableRow* theRow, bool theIsCorrect ); + bool checkItem( NoteBook_TableRow* theRow, int theColumn ) const; + bool checkRow( NoteBook_TableRow* theRow ) const; + void correctData( int theBaseRowIndex ); + void updateExpressions( int theBaseRowIndex ); + void updateValues(); + + bool setExpression( const QString& theName, + const QString& theExpression, + bool theIsNew, + QString& theErrorType, + QString& theErrorMessage ); + + bool renameVariable( const QString& theOldName, + const QString& theNewName, + QString& theErrorType, + QString& theErrorMessage ); private: QList myRows; @@ -123,13 +140,14 @@ class SALOMEAPP_EXPORT SalomeApp_NoteBookDlg : public QDialog Q_OBJECT public: - SalomeApp_NoteBookDlg(QWidget* parent, SalomeApp_Study* theStudy); + SalomeApp_NoteBookDlg( QWidget* parent, SalomeApp_Study* theStudy ); virtual ~SalomeApp_NoteBookDlg(); - void Init(SalomeApp_Study* theStudy); + void Init( SalomeApp_Study* theStudy ); public slots: void onRemove(); + void onDump(); void onUpdateStudy(); void onClose(); void onHelp(); @@ -140,11 +158,6 @@ protected: private: NoteBook_Table* myTable; - QPushButton* myRemoveButton; - QPushButton* myUpdateStudyBtn; - QPushButton* myCloseBtn; - QPushButton* myHelpBtn; - SalomeApp_Notebook* myNoteBook; }; diff --git a/src/SalomeApp/SalomeApp_Notebook.cxx b/src/SalomeApp/SalomeApp_Notebook.cxx index e63b21792..bd391a5f0 100644 --- a/src/SalomeApp/SalomeApp_Notebook.cxx +++ b/src/SalomeApp/SalomeApp_Notebook.cxx @@ -25,12 +25,14 @@ // #include "SalomeApp_Notebook.h" +#include "SalomeApp_Application.h" #include "SalomeApp_Study.h" -#include "SalomeApp_DoubleSpinBox.h" -#include "SalomeApp_IntSpinBox.h" + #include -#include + +#include #include +#include SalomeApp_Notebook::SalomeApp_Notebook( SalomeApp_Study* theStudy ) { @@ -49,10 +51,10 @@ bool SalomeApp_Notebook::isParameter( const QString& theName ) const return !CORBA::is_nil( aParam ); } -void SalomeApp_Notebook::set( const QString& theName, const QVariant& theValue ) +void SalomeApp_Notebook::set( const QString& theName, const QVariant& theValue, bool theIsNew ) { SALOME::Parameter_ptr aParam = myNotebook->GetParameter( theName.toLatin1().constData() ); - bool isNew = CORBA::is_nil( aParam ); + bool isNew = CORBA::is_nil( aParam ) || theIsNew; switch( theValue.type() ) { @@ -95,11 +97,17 @@ QVariant SalomeApp_Notebook::get( const QString& theName ) const return convert( myNotebook->GetParameter( theName.toLatin1().constData() ) ); } +QString SalomeApp_Notebook::expression( const QString& theName ) const +{ + SALOME::Parameter_var aParam = myNotebook->GetParameter( theName.toLatin1().constData() ); + return CORBA::is_nil( aParam ) ? QString::null : QString( aParam->GetExpression( true ) ); +} + QVariant SalomeApp_Notebook::calculate( const QString& theExpr ) { if( CORBA::is_nil( myTmp ) ) { - static const char TMP_NAME[] = "__notebook__tmp__"; + static const char TMP_NAME[] = "__tmp__"; myTmp = myNotebook->GetParameter( TMP_NAME ); if( CORBA::is_nil( myTmp ) ) { @@ -172,25 +180,47 @@ QStringList SalomeApp_Notebook::absentParameters( const QString& theExpr ) const void SalomeApp_Notebook::setParameters( SALOME::ParameterizedObject_ptr theObject, int theCount, QAbstractSpinBox* theFirstSpin, ... ) { - SALOME::StringArray_var aParams = new SALOME::StringArray(); - aParams->length( theCount ); - + QList aSpinList; QAbstractSpinBox** aSpinArray = &theFirstSpin; - for( int i=0; i theSpinList ) +{ + QStringList aParameters; + QListIterator anIter( theSpinList ); + while( anIter.hasNext() ) { - QAbstractSpinBox* aSpin = *aSpinArray; + QAbstractSpinBox* aSpin = anIter.next(); QString aText = aSpin->text(); + aParameters << aText; + } + setParameters( theObject, aParameters ); +} + +void SalomeApp_Notebook::setParameters( SALOME::ParameterizedObject_ptr theObject, const QStringList& theParameters ) +{ + SALOME::StringArray_var aParams = new SALOME::StringArray(); + aParams->length( theParameters.count() ); + + int i = 0; + QStringListIterator anIter( theParameters ); + while( anIter.hasNext() ) + { + QString aParameter = anIter.next(); bool anIsValue = false; - if( dynamic_cast( aSpin ) ) - aText.toDouble( &anIsValue ); - else if( dynamic_cast( aSpin ) ) - aText.toInt( &anIsValue ); + aParameter.toInt( &anIsValue ); + if( !anIsValue ) + aParameter.toDouble( &anIsValue ); if( anIsValue ) - aText = ""; + aParameter = ""; - aParams[i] = CORBA::string_dup( aText.toLatin1().constData() ); + aParams[i] = CORBA::string_dup( aParameter.toLatin1().constData() ); + i++; } theObject->SetParameters( myNotebook._retn(), aParams ); diff --git a/src/SalomeApp/SalomeApp_Notebook.h b/src/SalomeApp/SalomeApp_Notebook.h index 05c757a00..01aa156b6 100644 --- a/src/SalomeApp/SalomeApp_Notebook.h +++ b/src/SalomeApp/SalomeApp_Notebook.h @@ -29,6 +29,8 @@ #include "SalomeApp.h" #include CORBA_CLIENT_HEADER( SALOME_Notebook ) +#include + class SalomeApp_Study; class QString; class QVariant; @@ -47,8 +49,9 @@ public: virtual ~SalomeApp_Notebook(); bool isParameter( const QString& theName ) const; - void set( const QString& theName, const QVariant& theValue ); + void set( const QString& theName, const QVariant& theValue, bool theIsNew = false ); QVariant get( const QString& theName ) const; + QString expression( const QString& theName ) const; QVariant calculate( const QString& theExpr ); void update( bool theOnlyParameters ); @@ -60,6 +63,8 @@ public: QStringList absentParameters( const QString& theExpr ) const; void setParameters( SALOME::ParameterizedObject_ptr theObject, int theCount, QAbstractSpinBox* theFirstSpin, ... ); + void setParameters( SALOME::ParameterizedObject_ptr theObject, QList theSpinList ); + void setParameters( SALOME::ParameterizedObject_ptr theObject, const QStringList& theParameters ); char* dump(); diff --git a/src/SalomeApp/resources/SalomeApp_msg_en.ts b/src/SalomeApp/resources/SalomeApp_msg_en.ts index 024aeca03..0b543362a 100644 --- a/src/SalomeApp/resources/SalomeApp_msg_en.ts +++ b/src/SalomeApp/resources/SalomeApp_msg_en.ts @@ -91,7 +91,7 @@ Python file must include only letters, digits and underscores and start from let ERR_NO_VARIABLE - Variable with name "%1" doesn't exist + These variables have to be defined: "%1" @@ -378,64 +378,71 @@ Do you want to reload it ? NoteBook_Table - - REMOVE_VARIABLE_IS_USED - Variable with name "%1" is used in the study. -Do you really want to remove it? - - - RENAME_VARIABLE_IS_USED - Variable with name "%1" is used in the study. -Do you really want to rename it? - - - VARNAME_COLUMN - Variable Name - - - VARVALUE_COLUMN - Variable Value - - - VARVALUE_INCORRECT - Variable Value Incorrect: %1 - - - VARNAME_INCORRECT - Valiable Name Incorrect :%1 - - - VARNAME_EXISTS - Valiable with name "%1" exists - + + VARIABLE + Variable + + + EXPRESSION + Expression + + + VALUE + Value + SalomeApp_NoteBookDlg - - NOTEBOOK_TITLE - Salome NoteBook - - - BUT_UPDATE_STUDY - &Update Study - - - BUT_REMOVE - &Remove - - - BUT_HELP - &Help - - - CLOSE_CAPTION - Close NoteBook - - - INCORRECT_DATA - Some variables are defined incorrectly and will not be saved. + + NOTEBOOK_TITLE + Salome NoteBook + + + NOTEBOOK_ERROR + NoteBook error + + + EXPRESSION_ERROR + Expression error + + + CALCULATION_ERROR + Calculation error + + + TYPE_ERROR + Type error + + + BUT_UPDATE_STUDY + &Update Study + + + BUT_REMOVE + &Remove + + + BUT_HELP + &Help + + + BUT_DUMP + &Dump + + + CLOSE_CAPTION + Close NoteBook + + + INCORRECT_DATA_ON_CLOSE + Some variables have been defined incorrectly and will not be saved. If you want to close the notebook anyway, click Ok. Otherwise click Cancel and correct these variables. - + + + INCORRECT_DATA_ON_UPDATE + Some variables have been defined incorrectly. +Please correct these variables before study update. +