From c507f89da45d6b96596c720b54f09183fe18e544 Mon Sep 17 00:00:00 2001 From: dmv Date: Thu, 8 Oct 2009 14:06:46 +0000 Subject: [PATCH] 0020523: String notebook support --- src/SalomeApp/SalomeApp_DoubleSpinBox.cxx | 24 ++++++++++++- src/SalomeApp/SalomeApp_IntSpinBox.cxx | 24 ++++++++++++- src/SalomeApp/SalomeApp_NoteBookDlg.cxx | 43 ++++++++++++++++++++--- src/SalomeApp/SalomeApp_NoteBookDlg.h | 1 + 4 files changed, 86 insertions(+), 6 deletions(-) diff --git a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx index 559da7272..c784b6a26 100644 --- a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx +++ b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx @@ -19,6 +19,9 @@ // 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" @@ -31,6 +34,8 @@ #include #include +#include + /*! \class SalomeApp_DoubleSpinBox */ @@ -320,8 +325,25 @@ SalomeApp_DoubleSpinBox::SearchState SalomeApp_DoubleSpinBox::findVariable( cons std::string aName = name.toStdString(); if( studyDS->IsVariable( aName ) ) { - if( studyDS->IsReal( aName ) || studyDS->IsInteger( aName ) ) + if( studyDS->IsReal( aName ) || studyDS->IsInteger( aName ) || studyDS->IsString( aName ) ) { + if( studyDS->IsString( aName ) ) + { + 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; + } + } value = studyDS->GetReal( aName ); return Found; } diff --git a/src/SalomeApp/SalomeApp_IntSpinBox.cxx b/src/SalomeApp/SalomeApp_IntSpinBox.cxx index 4d3460a3b..27427d2e6 100644 --- a/src/SalomeApp/SalomeApp_IntSpinBox.cxx +++ b/src/SalomeApp/SalomeApp_IntSpinBox.cxx @@ -19,6 +19,9 @@ // 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" @@ -31,6 +34,8 @@ #include #include +#include + /*! \class SalomeApp_IntSpinBox */ @@ -278,8 +283,25 @@ SalomeApp_IntSpinBox::SearchState SalomeApp_IntSpinBox::findVariable( const QStr std::string aName = name.toStdString(); if( studyDS->IsVariable( aName ) ) { - if( studyDS->IsInteger( aName ) ) + if( studyDS->IsInteger( aName ) || studyDS->IsString( aName ) ) { + if( studyDS->IsString( aName ) ) + { + 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; + } + } value = studyDS->GetInteger( aName ); return Found; } diff --git a/src/SalomeApp/SalomeApp_NoteBookDlg.cxx b/src/SalomeApp/SalomeApp_NoteBookDlg.cxx index c4cd89edb..347d6a771 100644 --- a/src/SalomeApp/SalomeApp_NoteBookDlg.cxx +++ b/src/SalomeApp/SalomeApp_NoteBookDlg.cxx @@ -20,6 +20,9 @@ // Author : Roman NIKOLAEV, Open CASCADE S.A.S. // Module : GUI +#include // this include must be first (see PyInterp_base.h)! +#include + #include "SalomeApp_NoteBookDlg.h" #include "SalomeApp_Application.h" #include "SalomeApp_Study.h" @@ -34,8 +37,6 @@ #include #include -#include - #include #include @@ -174,7 +175,8 @@ bool NoteBook_TableRow::CheckValue() if(!aValue.isEmpty() && (IsRealValue(aValue) || IsIntegerValue(aValue) || - IsBooleanValue(aValue))) + IsBooleanValue(aValue) || + IsValidStringValue(aValue))) aResult = true; return aResult; @@ -267,6 +269,18 @@ bool NoteBook_TableRow::IsIntegerValue(const QString theValue, int* theResult) return aResult; } +//============================================================================ +/*! Function : IsValidStringValue + * Purpose : Return true if theValue string is valid, otherwise return + * false + * The string are always valid for the moment + * The whole notebook is verified on apply + */ +//============================================================================ +bool NoteBook_TableRow::IsValidStringValue(const QString theValue) +{ + return true; +} /////////////////////////////////////////////////////////////////////////// // NoteBook_Table class // @@ -397,6 +411,8 @@ QString NoteBook_Table::Variable2String(const string& theVarName, aResult = QString::number(theStudy->GetInteger(theVarName)); else if( theStudy->IsBoolean(theVarName) ) aResult = theStudy->GetBoolean(theVarName) ? QString("True") : QString("False"); + else if( theStudy->IsString(theVarName) ) + aResult = theStudy->GetString(theVarName).c_str(); return aResult; } @@ -419,7 +435,23 @@ bool NoteBook_Table::IsValid() const if( !myRows[i]->CheckName() || !IsUniqueName( myRows[i] ) || !myRows[i]->CheckValue() ) return false; - return true; + SalomeApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ); + PyConsole_Console* pyConsole = app->pythonConsole(); + PyConsole_Interp* pyInterp = pyConsole->getInterp(); + PyLockWrapper aLock = pyInterp->GetLockWrapper(); + string command = "import salome_notebook ; "; + command += "salome_notebook.checkThisNoteBook("; + for( int i = 0, n = aLastRowIsEmpty ? aNumRows - 1 : aNumRows; i < n; i++ ) + { + command += myRows[i]->GetName().toStdString(); + command += "=\""; + command += myRows[i]->GetValue().toStdString(); + command += "\","; + } + command += ")"; + bool aResult = pyInterp->run(command.c_str()); + aResult = !aResult; + return aResult; } //============================================================================ @@ -886,6 +918,9 @@ void SalomeApp_NoteBookDlg::onApply() else if( NoteBook_TableRow::IsBooleanValue(aValue,&aBVal) ) myStudy->SetBoolean(string(aName.toLatin1().constData()),aBVal); + + else if( NoteBook_TableRow::IsValidStringValue(aValue) ) + myStudy->SetString(string(aName.toLatin1().constData()),aValue.toStdString()); } } myTable->ResetMaps(); diff --git a/src/SalomeApp/SalomeApp_NoteBookDlg.h b/src/SalomeApp/SalomeApp_NoteBookDlg.h index 431b50ced..2f1e815cc 100644 --- a/src/SalomeApp/SalomeApp_NoteBookDlg.h +++ b/src/SalomeApp/SalomeApp_NoteBookDlg.h @@ -76,6 +76,7 @@ class SALOMEAPP_EXPORT NoteBook_TableRow : public QWidget 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; -- 2.39.2