X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_DataModel.cxx;h=6f1adada33b9121c81a475262fb6489338014aa0;hb=81c9f5cdf82909d0aebd2c491c50fa7516cc80b7;hp=cb445127bd4694ca6f75093699e15852d3b2b8a3;hpb=677e8367763ad6f2e08e9c0d4799b7ad7ef389ac;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index cb445127..6f1adada 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -48,8 +48,6 @@ #include #include -#include -#include #include #include @@ -57,7 +55,6 @@ #include #include -#include #include #include #include @@ -79,6 +76,9 @@ static HYDROData_SequenceOfObjects myCopyingObjects; +const int ENTRY_COLUMN = 2; + + HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule ) : LightApp_DataModel( theModule ) { @@ -97,17 +97,19 @@ bool HYDROGUI_DataModel::open( const QString& theURL, const int aStudyId = theStudy->id(); Data_DocError res = DocError_UnknownProblem; - if( theFileList.count() == 2 ) + if( theFileList.count() >= 2 ) { QString aTmpDir = theFileList[0]; - QString aFileName = theFileList[1]; + QString aDataFileName = theFileList[1]; + QString aStatesFileName = theFileList.count() == 3 ? theFileList[2] : ""; myStudyURL = theURL; - QString aFullPath = SUIT_Tools::addSlash( aTmpDir ) + aFileName; + QString aDataFullPath = SUIT_Tools::addSlash( aTmpDir ) + aDataFileName; + QString aStatesFullPath = aStatesFileName.isEmpty() ? "" : SUIT_Tools::addSlash( aTmpDir ) + aStatesFileName; try { - res = HYDROData_Document::Load( (char*)aFullPath.toLatin1().constData(), aStudyId ); + res = HYDROData_Document::Load( (char*)aDataFullPath.toLatin1().constData(), aStudyId ); } catch(...) { @@ -118,6 +120,16 @@ bool HYDROGUI_DataModel::open( const QString& theURL, module()->application()->putInfo( tr( "LOAD_ERROR" ) ); return false; } + + if( !aStatesFullPath.isEmpty() ) + { + QFile aFile( aStatesFullPath ); + if( aFile.open( QFile::ReadOnly ) ) + { + myStates = aFile.readAll(); + aFile.close(); + } + } } // if the document open was successful, the data model update happens @@ -136,27 +148,41 @@ bool HYDROGUI_DataModel::save( QStringList& theFileList ) LightApp_DataModel::save( theFileList ); QString aTmpDir; - QString aFileName; SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr(); bool isMultiFile = false; if( resMgr ) isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ); - // save data to temporary files + // save module data to temporary files LightApp_Study* aStudy = dynamic_cast( module()->application()->activeStudy() ); aTmpDir = aStudy->GetTmpDir( myStudyURL.toLatin1().constData(), isMultiFile ).c_str(); - aFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO.cbf"; - - QString aFullPath = aTmpDir + aFileName; - Data_DocError res = getDocument()->Save( (char*)aFullPath.toLatin1().constData() ); + + // save OCAF data to a temporary file + QString aDataFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO.cbf"; + QString aDataFullPath = aTmpDir + aDataFileName; + Data_DocError res = getDocument()->Save( (char*)aDataFullPath.toLatin1().constData() ); if( res != DocError_OK ) { module()->application()->putInfo( tr( "SAVE_ERROR" ) ); return false; } + // save tree state data to a temporary file + LightApp_Application* anApp = dynamic_cast( module()->application() ); + QByteArray aStatesData = anApp->objectBrowser()->getOpenStates( ENTRY_COLUMN ); + QString aStatesFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO_tree_states.txt"; + QString aStatesFullPath = aTmpDir + aStatesFileName; + QFile aFile( aStatesFullPath ); + if( aFile.open( QFile::WriteOnly ) ) + { + aFile.write( aStatesData ); + aFile.close(); + } + + // add temporary files to the list theFileList.append( aTmpDir ); - theFileList.append( aFileName ); + theFileList.append( aDataFileName ); + theFileList.append( aStatesFileName ); return true; } @@ -409,10 +435,20 @@ void HYDROGUI_DataModel::update( const int theStudyId ) HYDROGUI_DataModelSync aSync( aNewRootObj ); SUIT_DataObject* aRoot = root(); - if( !aRoot ) + bool isNewDoc = aRoot==0; + if( isNewDoc ) aRoot = createRootModuleObject( aStudyRoot ); ::synchronize < suitPtr, suitPtr, HYDROGUI_DataModelSync > ( aNewRootObj, aRoot, aSync ); + + + if( !myStates.isEmpty() ) + { + LightApp_Application* anApp = dynamic_cast( module()->application() ); + anApp->objectBrowser()->updateTree(); + anApp->objectBrowser()->setOpenStates( myStates, ENTRY_COLUMN ); + myStates.clear(); + } } HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject )