// Author : Roman NIKOLAEV, Open CASCADE S.A.S.
// Module : GUI
+// tmp includes
+#include <PyConsole_Interp.h> // this include must be first (see PyInterp_base.h)!
+#include <PyConsole_Console.h>
+
+#include "SALOMEDSClient_ClientFactory.hxx"
+#include CORBA_SERVER_HEADER(SALOMEDS)
+
+#include "SalomeApp_VisualState.h"
+#include <SUIT_Desktop.h>
+#include <SALOMEDS_Tool.hxx>
+#include <QDir>
+// end of tmp includes
+
#include "SalomeApp_NoteBookDlg.h"
#include "SalomeApp_Application.h"
#include "SalomeApp_Notebook.h"
}
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();
}
arg( aHelpFileName ) );
}
}
+
+//============================================================================
+/*! Function : updateStudy
+ * Purpose :
+ */
+//============================================================================
+bool SalomeApp_NoteBookDlg::updateStudy()
+{
+ SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
+ if( !app )
+ return false;
+
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( 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<SalomeApp_Application*>( 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<SalomeApp_Study*>( 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<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
+ if( !app )
+ return;
+
+ QList<SUIT_Application*> 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<SalomeApp_Application*>( aList[ anIndex - 1 ] );
+ else if(anIndex == 0 && aList.count() > 1)
+ app = dynamic_cast<SalomeApp_Application*>( aList[ 1 ] );
+
+ if( !app )
+ return;
+
+ app->onNewDoc();
+
+ app = dynamic_cast<SalomeApp_Application*>( 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();
+}