Salome HOME
getting access to Python plugin helpers in other modules
[modules/gui.git] / src / SalomeApp / SalomeApp_Study.cxx
index 7575c3cadf0193a9dbbc82cbd2e24d1a2e2255e8..8598e2bdb9b52c409bd9c5708a1f90e564e096f0 100644 (file)
@@ -255,12 +255,13 @@ public:
               std::string::size_type debut = 0;
               std::string::size_type fin;
               SalomeApp_DataObject* anObj = dynamic_cast<SalomeApp_DataObject*>( myStudy->root() );
-              while ( 1 ) {
+              while ( anObj ) {
                 fin = obj_id.find_first_of( ':', debut );
                 if ( fin == std::string::npos ) {
                   //last id
                   anObj = dynamic_cast<SalomeApp_DataObject*>(anObj->childObject(atoi(obj_id.substr(debut).c_str())-1));
-                  entry2SuitObject[parent_id] = anObj;
+                  if ( anObj )
+                    entry2SuitObject[parent_id] = anObj;
                   break;
                 }
                 anID = root_id + obj_id.substr( 0, fin );
@@ -268,13 +269,15 @@ public:
                 if ( it2 == entry2SuitObject.end() ) {
                   //the ID is not known in entry2SuitObject
                   anObj = dynamic_cast<SalomeApp_DataObject*>(anObj->childObject(atoi(obj_id.substr(debut, fin-debut).c_str())-1));
-                  entry2SuitObject[anID] = anObj;
+                  if ( anObj )
+                    entry2SuitObject[anID] = anObj;
                 }
                 else
                   anObj = it2->second;
                 debut = fin+1;
               }
-              anObj->insertChildAtTag( suit_obj, tag );
+              if ( anObj )
+                anObj->insertChildAtTag( suit_obj, tag );
             }
           }
           entry2SuitObject[theID] = suit_obj;
@@ -464,17 +467,23 @@ bool SalomeApp_Study::createDocument( const QString& theStr )
   QString aName = newStudyName();
 
   _PTR(Study) study;
+  bool showError = !application()->property("open_study_from_command_line").isValid() || 
+    !application()->property("open_study_from_command_line").toBool();
   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()));
+    application()->putInfo(tr(ex.what()));
+    if ( showError )
+      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"));
+    application()->putInfo(tr("CREATE_DOCUMENT_PROBLEM"));
+    if ( showError )
+      SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
+                                 tr("ERR_ERROR"), tr("CREATE_DOCUMENT_PROBLEM"));
     return false;
   }
 
@@ -514,17 +523,23 @@ bool SalomeApp_Study::openDocument( const QString& theFileName )
 
   // initialize myStudyDS, read HDF file
   _PTR(Study) study;
+  bool showError = !application()->property("open_study_from_command_line").isValid() || 
+    !application()->property("open_study_from_command_line").toBool();
   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()));
+    application()->putInfo(tr(ex.what()));
+    if ( showError )
+      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"));
+    application()->putInfo(tr("OPEN_DOCUMENT_PROBLEM"));
+    if ( showError )
+      SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
+                                 tr("ERR_ERROR"), tr("OPEN_DOCUMENT_PROBLEM"));
     return false;
   }