X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSalomeApp%2FSalomeApp_Study.cxx;h=d01cdd9f8c6421863209f96e634d0b354e7fd606;hb=44d45358f18c76cb8a376a4b7cae9cdd8a33d7a3;hp=aa812a9748269d2397610c8de246c13cad61bbe6;hpb=5c8f7ba108c5e500913c24612c1ea695b443ba7e;p=modules%2Fgui.git diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index aa812a974..d01cdd9f8 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -12,15 +12,24 @@ #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,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 ) { @@ -146,11 +155,16 @@ 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 res = res && CAM_Study::saveDocumentAs( theFileName ); + 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 if ( res ) emit saved( this ); @@ -160,7 +174,7 @@ bool SalomeApp_Study::saveDocumentAs( const QString& theFileName ) //======================================================================= // name : saveDocument -// Purpose : Save document +/*! Purpose : Save document */ //======================================================================= void SalomeApp_Study::saveDocument() { @@ -173,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 ); @@ -182,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 @@ -194,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 { @@ -222,7 +241,7 @@ bool SalomeApp_Study::isModified() const //================================================================ // Function : isSaved -// Purpose : +/*! Purpose : Check: data model is saved?*/ //================================================================ bool SalomeApp_Study::isSaved() const { @@ -238,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()); @@ -268,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) @@ -283,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 studies = SalomeApp_Application::studyMgr()->GetOpenStudies();