From 04135f487693a4a9a879af697b706526466583c0 Mon Sep 17 00:00:00 2001 From: asl Date: Fri, 15 Aug 2014 10:27:03 +0000 Subject: [PATCH] refs #416: store/restore the tree state in HDF files --- src/HYDROGUI/HYDROGUI_DataModel.cxx | 66 ++++++++++++++++++++++------- src/HYDROGUI/HYDROGUI_DataModel.h | 1 + 2 files changed, 52 insertions(+), 15 deletions(-) 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 ) diff --git a/src/HYDROGUI/HYDROGUI_DataModel.h b/src/HYDROGUI/HYDROGUI_DataModel.h index 019350e1..dde52d05 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.h +++ b/src/HYDROGUI/HYDROGUI_DataModel.h @@ -363,6 +363,7 @@ protected: protected: QString myStudyURL; ///< the saved/opened document URL + QByteArray myStates; }; #endif -- 2.39.2