Salome HOME
Added menu items and corresponding slots to handle Catalog Generator and Registry...
[modules/gui.git] / src / SalomeApp / SalomeApp_Study.cxx
index 8b6f9019350346dbe664bd054a0abb256f9a80a3..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 )
 {
@@ -91,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 )
 {
@@ -104,34 +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() ); 
+  setRoot( new SalomeApp_RootObject( this ) ); // create myRoot
 
-    if ( aComponent->ComponentDataType() == "Interface Applicative" )
-      continue; // skip the magic "Interface Applicative" component
+  //SRN: BugID IPAL9021, put there the same code as in a method openDocument
 
-    SalomeApp_DataModel::BuildTree( aComponent, root(), this );
-  }
+  // 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 ); 
 
-  // TODO: potentially unsafe call, since base study's openDocument() might try to access the file directly - to be improved
-  //bool res = true;
   bool res = CAM_Study::openDocument( theStudyName );
+  emit opened( this );
 
-  //emit opened( this );
+  //SRN: BugID IPAL9021: End
 
   return res;
 }
 
 //=======================================================================
 // name    : saveDocumentAs
-// Purpose : Save document
+/*! Purpose : Save document */
 //=======================================================================
 bool SalomeApp_Study::saveDocumentAs( const QString& theFileName )
 {
@@ -142,9 +155,14 @@ bool SalomeApp_Study::saveDocumentAs( const QString& theFileName )
     aModel->saveAs( theFileName, this );
 
   // save SALOMEDS document
-  bool isMultiFile = false, isAscii = false;// TODO: This information should be taken from preferences afterwards!
-   /* bool res = */isAscii ? SalomeApp_Application::studyMgr()->SaveAsASCII( theFileName.latin1(), studyDS(), isMultiFile ) :
-                  SalomeApp_Application::studyMgr()->SaveAs     ( theFileName.latin1(), studyDS(), isMultiFile );
+  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 );
 
   bool res = CAM_Study::saveDocumentAs( theFileName );  //SRN: BugID IPAL9377, removed usage of uninitialized variable <res>
 
@@ -156,7 +174,7 @@ bool SalomeApp_Study::saveDocumentAs( const QString& theFileName )
 
 //=======================================================================
 // name    : saveDocument
-// Purpose : Save document
+/*! Purpose : Save document */
 //=======================================================================
 void SalomeApp_Study::saveDocument()
 {
@@ -169,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 );
 
@@ -178,7 +201,7 @@ void SalomeApp_Study::saveDocument()
 
 //================================================================
 // Function : closeDocument
-// Purpose  : 
+/*! Purpose  : Close document */
 //================================================================
 void SalomeApp_Study::closeDocument(bool permanently)
 {
@@ -200,7 +223,7 @@ void SalomeApp_Study::closeDocument(bool permanently)
 
 //================================================================
 // Function : isModified
-// Purpose  : 
+/*! Purpose  : Check data model on modifications.*/
 //================================================================
 bool SalomeApp_Study::isModified() const
 {
@@ -218,7 +241,7 @@ bool SalomeApp_Study::isModified() const
 
 //================================================================
 // Function : isSaved
-// Purpose  : 
+/*! Purpose  : Check: data model is saved?*/
 //================================================================
 bool SalomeApp_Study::isSaved() const
 {
@@ -234,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());
@@ -264,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)
@@ -279,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();