Salome HOME
Merge branch 'ASL_TREE_STATE' into asl/hydro_porting_741
[modules/gui.git] / src / SalomeApp / SalomeApp_Study.cxx
index 2427203b32e44b90ba83f473c773d87e2496b981..70bd944cbdf7458bfc2b35f49957c6cbf107c4e3 100644 (file)
@@ -41,6 +41,9 @@
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_TreeModel.h>
 #include <SUIT_DataBrowser.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_Session.h>
+#include <SUIT_Desktop.h>
 
 #include <LightApp_Displayer.h>
 
@@ -334,11 +337,13 @@ public:
         }
         break;
       }
+#ifndef DISABLE_PYCONSOLE
     case 6: //NoteBook variables were modified
       {
        myStudy->onNoteBookVarUpdate( QString( theID.c_str() ) );
        break;
       }
+#endif
     default:MESSAGE("Unknown event: "  << event);break;
     } //switch
   } //notifyObserverID_real
@@ -402,10 +407,12 @@ SalomeApp_Study::~SalomeApp_Study()
   }
 }
 
+#ifndef DISABLE_PYCONSOLE
 void SalomeApp_Study::onNoteBookVarUpdate( QString theVarName)
 {
   emit notebookVarUpdated( theVarName );
 }
+#endif
 
 /*!
   Gets study id.
@@ -454,7 +461,22 @@ bool SalomeApp_Study::createDocument( const QString& theStr )
 
   // initialize myStudyDS, read HDF file
   QString aName = newStudyName();
-  _PTR(Study) study ( SalomeApp_Application::studyMgr()->NewStudy( aName.toUtf8().data() ) );
+
+  _PTR(Study) study;
+  try {
+    study = _PTR(Study)( SalomeApp_Application::studyMgr()->NewStudy( aName.toUtf8().data() ) );
+  }
+  catch(const SALOME_Exception& ex) {
+    SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
+                               tr("ERR_ERROR"), tr(ex.what()));
+    return false;
+  } 
+  catch(...) {
+    SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
+                               tr("ERR_ERROR"), tr("CREATE_DOCUMENT_PROBLEM"));
+    return false;
+  }
+
   if ( !study )
     return false;
 
@@ -490,7 +512,21 @@ bool SalomeApp_Study::openDocument( const QString& theFileName )
   MESSAGE( "openDocument" );
 
   // initialize myStudyDS, read HDF file
-  _PTR(Study) study ( SalomeApp_Application::studyMgr()->Open( theFileName.toUtf8().data() ) );
+  _PTR(Study) study;
+  try {
+    study = _PTR(Study) ( SalomeApp_Application::studyMgr()->Open( theFileName.toUtf8().data() ) );
+  }
+  catch(const SALOME_Exception& ex) {
+    SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
+                               tr("ERR_ERROR"), tr(ex.what()));
+    return false;
+  } 
+  catch(...) {
+    SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
+                               tr("ERR_ERROR"), tr("OPEN_DOCUMENT_PROBLEM"));
+    return false;
+  }
+
   if ( !study )
     return false;
 
@@ -690,7 +726,9 @@ void SalomeApp_Study::closeDocument(bool permanently)
   _PTR(Study) studyPtr = studyDS();
   if ( studyPtr )
   {
-    if(permanently) {
+    if ( myObserver )
+      myStudyDS->detach( myObserver->_this() );
+    if ( permanently ) {
       SalomeApp_Application::studyMgr()->Close( studyPtr );
     }
     SALOMEDSClient_Study* aStudy = 0;
@@ -1150,6 +1188,7 @@ void SalomeApp_Study::RemoveTemporaryFiles ( const char* theModuleName, const bo
   }
 }
 
+#ifndef DISABLE_PYCONSOLE
 /*!
   Mark the study as saved in the file
   \param theFileName - the name of file
@@ -1160,6 +1199,7 @@ void SalomeApp_Study::updateFromNotebook( const QString& theFileName, bool isSav
   studyDS()->Name(theFileName.toStdString());
   setIsSaved( isSaved );
 }
+#endif
 
 LightApp_DataObject* SalomeApp_Study::findObjectByEntry( const QString& theEntry )
 {