Salome HOME
Added menu items and corresponding slots to handle Catalog Generator and Registry...
[modules/gui.git] / src / SalomeApp / SalomeApp_Study.cxx
index 0ba477280f0f016308cc045ff753a1b85cb8ddbe..d01cdd9f8c6421863209f96e634d0b354e7fd606 100644 (file)
 
 #include "utilities.h"
 
+/*!
+  Constructor.
+*/
 SalomeApp_Study::SalomeApp_Study( SUIT_Application* app )
 : CAM_Study( app )
 {
 }  
 
+/*!
+  Destructor.
+*/
 SalomeApp_Study::~SalomeApp_Study()
 {
 }
 
+/*!
+  Gets study id.
+*/
 int SalomeApp_Study::id() const
 {
   int id = -1;
@@ -29,11 +38,17 @@ int SalomeApp_Study::id() const
   return id;
 }
 
+/*!
+  Gets studyDS pointer.
+*/
 _PTR(Study) SalomeApp_Study::studyDS() const
 {
   return myStudyDS;
 }
 
+/*!
+  Create document.
+*/
 void SalomeApp_Study::createDocument()
 {
   MESSAGE( "openDocument" );
@@ -57,7 +72,7 @@ void SalomeApp_Study::createDocument()
 
 //=======================================================================
 // name    : openDocument
-// Purpose : Open document
+/*! Purpose : Open document*/
 //=======================================================================
 bool SalomeApp_Study::openDocument( const QString& theFileName )
 {
@@ -70,24 +85,20 @@ bool SalomeApp_Study::openDocument( const QString& theFileName )
 
   setStudyDS( study );
 
-  // build a SUIT_DataObject-s tree under myRoot member field
-  // 1. create myRoot
-  setRoot( new SalomeApp_RootObject( this ) );
-  // 2. iterate through all components and create corresponding sub-trees under them
-  _PTR(SComponentIterator) it ( studyDS()->NewComponentIterator() );
-  for ( ; it->More(); it->Next() ) {
-    // don't use shared_ptr here, for Data Object will take 
-    // ownership of this pointer
-    _PTR(SComponent) aComponent ( it->Value() ); 
-
-    if ( aComponent->ComponentDataType() == "Interface Applicative" )
-      continue; // skip the magic "Interface Applicative" component
-    
-    SalomeApp_DataModel::BuildTree( aComponent, root(), this );
-  }
+  setRoot( new SalomeApp_RootObject( this ) ); // create myRoot
 
-  bool res = CAM_Study::openDocument( theFileName );
+  // update loaded data models: call open() and update() on them.
+  ModelList dm_s;
+  dataModels( dm_s );
+  for ( ModelListIterator it( dm_s ); it.current(); ++it )
+    openDataModel( studyName(), it.current() );
 
+  // this will build a SUIT_DataObject-s tree under myRoot member field
+  // passing "false" in order NOT to rebuild existing data models' trees - it was done in previous step
+  // but tree that corresponds to not-loaded data models will be updated any way. 
+  ((SalomeApp_Application*)application())->updateObjectBrowser( false ); 
+
+  bool res = CAM_Study::openDocument( theFileName );
   emit opened( this );
 
   return res;
@@ -95,7 +106,7 @@ bool SalomeApp_Study::openDocument( const QString& theFileName )
 
 //=======================================================================
 // name    : loadDocument
-// Purpose : Connects GUI study to SALOMEDS one already loaded into StudyManager
+/*! Purpose : Connects GUI study to SALOMEDS one already loaded into StudyManager*/
 //=======================================================================
 bool SalomeApp_Study::loadDocument( const QString& theStudyName )
 {
@@ -108,33 +119,32 @@ bool SalomeApp_Study::loadDocument( const QString& theStudyName )
 
   setStudyDS( study );
 
-  // build a SUIT_DataObject-s tree under myRoot member field
-  // 1. create myRoot
-  setRoot( new SalomeApp_RootObject( this ) );
-  // 2. iterate through all components and create corresponding sub-trees under them
-  _PTR(SComponentIterator) it ( studyDS()->NewComponentIterator() );
-  for ( ; it->More(); it->Next() ) {
-    // don't use shared_ptr here, for Data Object will take 
-    // ownership of this pointer
-    _PTR(SComponent) aComponent ( it->Value() ); 
-
-    if ( aComponent->ComponentDataType() == "Interface Applicative" )
-      continue; // skip the magic "Interface Applicative" component
-    
-    SalomeApp_DataModel::BuildTree( aComponent, root(), this );
-  }
+  setRoot( new SalomeApp_RootObject( this ) ); // create myRoot
 
-  // TODO: potentially unsafe call, since base study's openDocument() might try to access the file directly - to be improved
-  bool res = CAM_Study::openDocument( theStudyName );
+  //SRN: BugID IPAL9021, put there the same code as in a method openDocument
+
+  // update loaded data models: call open() and update() on them.
+  ModelList dm_s;
+  dataModels( dm_s );
+  for ( ModelListIterator it( dm_s ); it.current(); ++it )
+    openDataModel( studyName(), it.current() );
 
+  // this will build a SUIT_DataObject-s tree under myRoot member field
+  // passing "false" in order NOT to rebuild existing data models' trees - it was done in previous step
+  // but tree that corresponds to not-loaded data models will be updated any way. 
+  ((SalomeApp_Application*)application())->updateObjectBrowser( false ); 
+
+  bool res = CAM_Study::openDocument( theStudyName );
   emit opened( this );
 
-  return res;  
+  //SRN: BugID IPAL9021: End
+
+  return res;
 }
 
 //=======================================================================
 // name    : saveDocumentAs
-// Purpose : Save document
+/*! Purpose : Save document */
 //=======================================================================
 bool SalomeApp_Study::saveDocumentAs( const QString& theFileName )
 {
@@ -144,21 +154,27 @@ bool SalomeApp_Study::saveDocumentAs( const QString& theFileName )
   for ( ; aModel; aModel = (SalomeApp_DataModel*)list.next() )
     aModel->saveAs( theFileName, this );
 
-  bool res = CAM_Study::saveDocumentAs( theFileName );
-
   // save SALOMEDS document
-  bool isMultiFile = false, isAscii = false;// TODO: This information should be taken from preferences afterwards!
+  SUIT_ResourceMgr* resMgr = application()->resourceMgr();
+  if( !resMgr )
+    return false;
+
+  bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ),
+       isAscii = resMgr->booleanValue( "Study", "ascii_file", true );
   isAscii ? SalomeApp_Application::studyMgr()->SaveAsASCII( theFileName.latin1(), studyDS(), isMultiFile ) :
             SalomeApp_Application::studyMgr()->SaveAs     ( theFileName.latin1(), studyDS(), isMultiFile );
 
-  emit saved( this );
+  bool res = CAM_Study::saveDocumentAs( theFileName );  //SRN: BugID IPAL9377, removed usage of uninitialized variable <res>
+
+  if ( res )
+    emit saved( this );
 
   return res;
 }
 
 //=======================================================================
 // name    : saveDocument
-// Purpose : Save document
+/*! Purpose : Save document */
 //=======================================================================
 void SalomeApp_Study::saveDocument()
 {
@@ -171,7 +187,12 @@ void SalomeApp_Study::saveDocument()
   CAM_Study::saveDocument();
 
   // save SALOMEDS document
-  bool isMultiFile = false, isAscii = false;// TODO: This information should be taken from preferences afterwards!
+  SUIT_ResourceMgr* resMgr = application()->resourceMgr();
+  if( !resMgr )
+    return;
+  
+  bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ),
+       isAscii = resMgr->booleanValue( "Study", "ascii_file", true );
   isAscii ? SalomeApp_Application::studyMgr()->SaveASCII( studyDS(), isMultiFile ) :
             SalomeApp_Application::studyMgr()->Save     ( studyDS(), isMultiFile );
 
@@ -180,9 +201,9 @@ void SalomeApp_Study::saveDocument()
 
 //================================================================
 // Function : closeDocument
-// Purpose  : 
+/*! Purpose  : Close document */
 //================================================================
-void SalomeApp_Study::closeDocument()
+void SalomeApp_Study::closeDocument(bool permanently)
 {
   // Inform everybody that this study is going to close when it's most safe to,
   // i.e. in the very beginning
@@ -192,17 +213,17 @@ void SalomeApp_Study::closeDocument()
   _PTR(Study) studyPtr = studyDS();
   if ( studyPtr )
   {
-    SalomeApp_Application::studyMgr()->Close( studyPtr );
+    if(permanently) SalomeApp_Application::studyMgr()->Close( studyPtr );
     SALOMEDSClient_Study* aStudy = 0;
     setStudyDS( _PTR(Study)(aStudy) );
   }
 
-  CAM_Study::closeDocument();
+  CAM_Study::closeDocument(permanently);
 }
 
 //================================================================
 // Function : isModified
-// Purpose  : 
+/*! Purpose  : Check data model on modifications.*/
 //================================================================
 bool SalomeApp_Study::isModified() const
 {
@@ -220,7 +241,7 @@ bool SalomeApp_Study::isModified() const
 
 //================================================================
 // Function : isSaved
-// Purpose  : 
+/*! Purpose  : Check: data model is saved?*/
 //================================================================
 bool SalomeApp_Study::isSaved() const
 {
@@ -236,11 +257,17 @@ bool SalomeApp_Study::isSaved() const
   return isAllSaved; 
 }
 
+/*!
+  Set studyDS.
+*/
 void SalomeApp_Study::setStudyDS( const _PTR(Study)& s )
 {
   myStudyDS = s;
 }
 
+/*!
+  Insert data model.
+*/
 void SalomeApp_Study::dataModelInserted (const CAM_DataModel* dm)
 {
   MESSAGE("SalomeApp_Study::dataModelInserted() : module name() = " << dm->module()->name());
@@ -266,6 +293,9 @@ void SalomeApp_Study::dataModelInserted (const CAM_DataModel* dm)
   }
 }
 
+/*!
+  Open data model
+*/
 bool SalomeApp_Study::openDataModel( const QString& studyName, CAM_DataModel* dm )
 {
   if (!dm)
@@ -281,12 +311,9 @@ bool SalomeApp_Study::openDataModel( const QString& studyName, CAM_DataModel* dm
   return false;
 }
 
-void SalomeApp_Study::updateModelRoot( const CAM_DataModel* dm )
-{
-  CAM_Study::updateModelRoot( dm );
-  ((SalomeApp_Application*)application())->objectBrowser()->updateTree();
-}
-
+/*!
+  Create new study name.
+*/
 QString SalomeApp_Study::newStudyName() const
 {
   std::vector<std::string> studies = SalomeApp_Application::studyMgr()->GetOpenStudies();