]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Old version of "update study" mechanism has been temporarily returned.
authorouv <ouv@opencascade.com>
Fri, 4 Dec 2009 11:44:44 +0000 (11:44 +0000)
committerouv <ouv@opencascade.com>
Fri, 4 Dec 2009 11:44:44 +0000 (11:44 +0000)
src/SalomeApp/SalomeApp_NoteBookDlg.cxx
src/SalomeApp/resources/SalomeApp_msg_en.ts

index 51565bdbd60c283b7a4198480135a714fd5bb804..eaf946f9459ab7401a3097f3439c1578e65a5cc9 100644 (file)
 // 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"
@@ -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<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();
+}
index 87c31c97335e23362df5d231c2d1272e12b87136..400c9e794d530c3bda801fbc88f8fb1e63713b77 100644 (file)
@@ -454,5 +454,9 @@ Otherwise click Cancel and correct these variables.</translation>
         <translation>Some variables have been defined incorrectly.
 Please correct these variables before study update.</translation>
     </message>
+    <message>
+        <source>ERR_UPDATE_STUDY_FAILED</source>
+        <translation>Failed to update study!</translation>
+    </message>
 </context>
 </TS>