Salome HOME
Merge branch 'master' into agy/NewPV1_For_850
[modules/gui.git] / src / SalomeApp / SalomeApp_Study.cxx
index f081af349a2ae8fb8a2d3d5fddbdc2f64ab19734..b60de1a8a0d93a4a544f82f5cdad2f5b72642599 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -161,6 +161,12 @@ public:
             if (oldFather) {
               oldFather->removeChild(suit_obj, false);
               SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( myStudy->application() );
+//              MESSAGE("myStudy: " << myStudy->id() << " app " << app);
+//              MESSAGE("objectBrowser: "<< app->objectBrowser());
+              if (!app->objectBrowser()) {
+                MESSAGE("Object Browser not found. Problem ??");
+                return;
+              }
               SUIT_AbstractModel* model = dynamic_cast<SUIT_AbstractModel*>(app->objectBrowser()->model());
               model->forgetObject( suit_obj );
                 
@@ -190,22 +196,22 @@ public:
           //aFatherDO->insertChild(suit_obj, pos);
           aFatherDO->updateItem();
 
-         /* Define visibility state */
-         bool isComponent = dynamic_cast<SalomeApp_ModuleObject*>( suit_obj ) != 0;
-         if ( suit_obj && !isComponent && myStudy->visibilityState( theID.c_str() ) == Qtx::UnpresentableState ) {
-           QString moduleTitle = ((CAM_Application*)myStudy->application())->moduleTitle(suit_obj->componentDataType());
-           if (!moduleTitle.isEmpty()) {
-             LightApp_Displayer* aDisplayer = LightApp_Displayer::FindDisplayer(moduleTitle,false);
-             if (aDisplayer) {
-               if(aDisplayer->canBeDisplayed(theID.c_str())) {
-                 myStudy->setVisibilityState( theID.c_str(), Qtx::HiddenState ); //hide the just added object
-                 //MESSAGE("Object with entry : "<< theID <<" CAN be displayed !!!");
-               }
-               else
-                 MESSAGE("Object with entry : "<< theID <<" CAN'T be displayed !!!");
-             }
-           }
-         }
+          /* Define visibility state */
+          bool isComponent = dynamic_cast<SalomeApp_ModuleObject*>( suit_obj ) != 0;
+          if ( suit_obj && !isComponent && myStudy->visibilityState( theID.c_str() ) == Qtx::UnpresentableState ) {
+            QString moduleTitle = ((CAM_Application*)myStudy->application())->moduleTitle(suit_obj->componentDataType());
+            if (!moduleTitle.isEmpty()) {
+              LightApp_Displayer* aDisplayer = LightApp_Displayer::FindDisplayer(moduleTitle,false);
+              if (aDisplayer) {
+                if(aDisplayer->canBeDisplayed(theID.c_str())) {
+                  myStudy->setVisibilityState( theID.c_str(), Qtx::HiddenState ); //hide the just added object
+                  //MESSAGE("Object with entry : "<< theID <<" CAN be displayed !!!");
+                }
+                //else
+                  //MESSAGE("Object with entry : "<< theID <<" CAN'T be displayed !!!");
+              }
+            }
+          }
         } // END: work with tree nodes structure
         else { // BEGIN: work with study structure
           EntryMapIter it = entry2SuitObject.find( theID );
@@ -255,12 +261,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 +275,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;
@@ -331,8 +340,8 @@ public:
                 myStudy->setVisibilityState( theID.c_str(), Qtx::HiddenState );
                 //MESSAGE("Object with entry : "<< theID <<" CAN be displayed !!!");
               }
-              else
-                MESSAGE("Object with entry : "<< theID <<" CAN'T be displayed !!!");
+              //else
+                //MESSAGE("Object with entry : "<< theID <<" CAN'T be displayed !!!");
             }
           }
         }
@@ -341,8 +350,8 @@ public:
 #ifndef DISABLE_PYCONSOLE
     case 6: //NoteBook variables were modified
       {
-       myStudy->onNoteBookVarUpdate( QString( theID.c_str() ) );
-       break;
+        myStudy->onNoteBookVarUpdate( QString( theID.c_str() ) );
+        break;
       }
 #endif
     default:MESSAGE("Unknown event: "  << event);break;
@@ -464,17 +473,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 +529,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;
   }
 
@@ -1098,6 +1119,8 @@ bool SalomeApp_Study::openDataModel( const QString& studyName, CAM_DataModel* dm
     // for this module by LightApp_Engine_i::Load()
     bool isMultiFile = false; // TODO: decide, how to access this parameter
     RemoveTemporaryFiles( dm->module()->name().toStdString().c_str(), isMultiFile );
+    std::vector<std::string> listOfFiles   ;
+    SetListOfFiles( dm->module()->name().toStdString().c_str(), listOfFiles );
 
     // Something has been read -> create data model tree
     LightApp_DataModel* aDM = dynamic_cast<LightApp_DataModel*>( dm );