From 040bde7c53d186fba7633076606d533787a4b21e Mon Sep 17 00:00:00 2001 From: ouv Date: Fri, 4 Dec 2009 11:44:44 +0000 Subject: [PATCH] Old version of "update study" mechanism has been temporarily returned. --- src/SalomeApp/SalomeApp_NoteBookDlg.cxx | 159 ++++++++++++++++++++ src/SalomeApp/resources/SalomeApp_msg_en.ts | 4 + 2 files changed, 163 insertions(+) diff --git a/src/SalomeApp/SalomeApp_NoteBookDlg.cxx b/src/SalomeApp/SalomeApp_NoteBookDlg.cxx index 51565bdbd..eaf946f94 100644 --- a/src/SalomeApp/SalomeApp_NoteBookDlg.cxx +++ b/src/SalomeApp/SalomeApp_NoteBookDlg.cxx @@ -20,6 +20,19 @@ // Author : Roman NIKOLAEV, Open CASCADE S.A.S. // Module : GUI +// tmp includes +#include // this include must be first (see PyInterp_base.h)! +#include + +#include "SALOMEDSClient_ClientFactory.hxx" +#include CORBA_SERVER_HEADER(SALOMEDS) + +#include "SalomeApp_VisualState.h" +#include +#include +#include +// end of tmp includes + #include "SalomeApp_NoteBookDlg.h" #include "SalomeApp_Application.h" #include "SalomeApp_Notebook.h" @@ -932,7 +945,14 @@ void SalomeApp_NoteBookDlg::onUpdateStudy() } QApplication::setOverrideCursor( Qt::WaitCursor ); + myTable->updateNoteBook( false ); + + // tmp code + if( !updateStudy() ) + SUIT_MessageBox::warning( this, tr( "ERROR" ), tr( "ERR_UPDATE_STUDY_FAILED" ) ); + // end of tmp code + QApplication::restoreOverrideCursor(); } @@ -981,3 +1001,142 @@ void SalomeApp_NoteBookDlg::onHelp() arg( aHelpFileName ) ); } } + +//============================================================================ +/*! Function : updateStudy + * Purpose : + */ +//============================================================================ +bool SalomeApp_NoteBookDlg::updateStudy() +{ + SalomeApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ); + if( !app ) + return false; + + SalomeApp_Study* study = dynamic_cast( app->activeStudy() ); + if( !study ) + return false; + + bool isStudySaved = study->isSaved(); + QString aStudyName = study->studyName(); + + _PTR(Study) studyDS = study->studyDS(); + + // get unique temporary directory name + QString aTmpDir = QString::fromStdString( SALOMEDS_Tool::GetTmpDir() ); + if( aTmpDir.isEmpty() ) + return false; + + if( aTmpDir.right( 1 ).compare( QDir::separator() ) == 0 ) + aTmpDir.remove( aTmpDir.length() - 1, 1 ); + + // dump study to the temporary directory + QString aFileName( "notebook" ); + bool toPublish = true; + bool toSaveGUI = true; + + int savePoint; + _PTR(AttributeParameter) ap; + _PTR(IParameters) ip = ClientFactory::getIParameters(ap); + if(ip->isDumpPython(studyDS)) ip->setDumpPython(studyDS); //Unset DumpPython flag. + if ( toSaveGUI ) { //SRN: Store a visual state of the study at the save point for DumpStudy method + ip->setDumpPython(studyDS); + savePoint = SalomeApp_VisualState( app ).storeState(); //SRN: create a temporary save point + } + bool ok = studyDS->DumpStudy( aTmpDir.toStdString(), aFileName.toStdString(), toPublish ); + if ( toSaveGUI ) + study->removeSavePoint(savePoint); //SRN: remove the created temporary save point. + + if( !ok ) + return false; + + // clear a study (delete all objects) + clearStudy(); + + // get active application + app = dynamic_cast( SUIT_Session::session()->activeApplication() ); + + // load study from the temporary directory + QString command = QString( "execfile(r\"%1\")" ).arg( aTmpDir + QDir::separator() + aFileName + ".py" ); + + PyConsole_Console* pyConsole = app->pythonConsole(); + if ( pyConsole ) + pyConsole->execAndWait( command ); + + // remove temporary directory + QDir aDir( aTmpDir ); + QStringList aFiles = aDir.entryList( QStringList( "*.py*" ) ); + for( QStringList::iterator it = aFiles.begin(), itEnd = aFiles.end(); it != itEnd; ++it ) + ok = aDir.remove( *it ) && ok; + if( ok ) + ok = aDir.rmdir( aTmpDir ); + + if( SalomeApp_Study* newStudy = dynamic_cast( app->activeStudy() ) ) + { + if( myNoteBook ) + delete myNoteBook; + + myNoteBook = new SalomeApp_Notebook( newStudy ); + myTable->init( myNoteBook ); + //myStudy = newStudy->studyDS(); + //myTable->Init(myStudy); + if(isStudySaved) { + newStudy->markAsSavedIn(aStudyName); + } + } + else + ok = false; + + return ok; +} + +//============================================================================ +/*! Function : clearStudy + * Purpose : + */ +//============================================================================ +void SalomeApp_NoteBookDlg::clearStudy() +{ + SalomeApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ); + if( !app ) + return; + + QList aList = SUIT_Session::session()->applications(); + int anIndex = aList.indexOf( app ); + + //Store position and size of the this dialog + int aW = width(); + int aH = height(); + int aX = x(); + int aY = y(); + + // Disconnect dialog from application desktop in case if: + // 1) Application is not the first application in the session + // 2) Application is the first application in session but not the only. + bool changeDesktop = ((anIndex > 0) || (anIndex == 0 && aList.count() > 1)); + + if( changeDesktop ) + setParent( 0 ); + + app->onCloseDoc( false ); + + if( anIndex > 0 && anIndex < aList.count() ) + app = dynamic_cast( aList[ anIndex - 1 ] ); + else if(anIndex == 0 && aList.count() > 1) + app = dynamic_cast( aList[ 1 ] ); + + if( !app ) + return; + + app->onNewDoc(); + + app = dynamic_cast( SUIT_Session::session()->activeApplication() ); + if( changeDesktop && app ) { + setParent( app->desktop(), Qt::Dialog ); + app->setNoteBook(this); + } + //Set position and size of the this dialog + resize( aW, aH ); + move( aX, aY ); + show(); +} diff --git a/src/SalomeApp/resources/SalomeApp_msg_en.ts b/src/SalomeApp/resources/SalomeApp_msg_en.ts index 87c31c973..400c9e794 100644 --- a/src/SalomeApp/resources/SalomeApp_msg_en.ts +++ b/src/SalomeApp/resources/SalomeApp_msg_en.ts @@ -454,5 +454,9 @@ Otherwise click Cancel and correct these variables. Some variables have been defined incorrectly. Please correct these variables before study update. + + ERR_UPDATE_STUDY_FAILED + Failed to update study! + -- 2.39.2