From eeec7c7e071e1c7cedc1cb9af6eb2e42c7bbcda9 Mon Sep 17 00:00:00 2001 From: abn Date: Mon, 19 Oct 2015 14:25:23 +0200 Subject: [PATCH] 0023191: [CEA 1607] REGRESSION : the file hdf does not save the data PARAVIS --- src/PVGUI/PVGUI_DataModel.cxx | 327 ++++++++++++++++++++++++-- src/PVGUI/PVGUI_DataModel.h | 8 + src/PVGUI/PVGUI_Module.cxx | 10 +- src/PVGUI/PVGUI_Module.h | 5 +- src/PVGUI/resources/PARAVIS_msg_en.ts | 4 +- src/PVGUI/resources/PARAVIS_msg_fr.ts | 4 +- src/PVGUI/resources/PARAVIS_msg_ja.ts | 6 +- 7 files changed, 331 insertions(+), 33 deletions(-) diff --git a/src/PVGUI/PVGUI_DataModel.cxx b/src/PVGUI/PVGUI_DataModel.cxx index 6c563e8d..7917899b 100644 --- a/src/PVGUI/PVGUI_DataModel.cxx +++ b/src/PVGUI/PVGUI_DataModel.cxx @@ -25,19 +25,166 @@ // GUI includes #include +#include +#include +#include #include +#include +#include +#include + +// KERNEL +#include // Qt includes #include +#include #include +#include + +// ParaView include +#include +#include +#include + +const QString PVGUI_DataModel::RESTORE_FLAG_FILE = "do_restore_paravis_references.par"; + +/*! + * XML processing functions to handle the PV state file. + */ +namespace { + + void processElements(QDomNode& thePropertyNode, QStringList& theFileNames, + const QString& theNewPath, bool theRestore) + { + QDomNode aElementNode = thePropertyNode.firstChild(); + while (aElementNode.isElement()) { + QDomElement aElement = aElementNode.toElement(); + if (aElement.tagName() == "Element") { + QString aIndex = aElement.attribute("index"); + if (aIndex == "0") { + QString aValue = aElement.attribute("value"); + if (!aValue.isNull()) { + if (theNewPath.isEmpty()) { + QFileInfo aFInfo(aValue); + if (aFInfo.exists()) { + theFileNames<( theStudy ); + CAM_ModuleObject *aModelRoot = dynamic_cast( root()); + if( study && aModelRoot == NULL ) { + aModelRoot = createModuleObject( theStudy->root() ); + aModelRoot->setDataModel( this ); + setRoot(aModelRoot); + } +} + bool PVGUI_DataModel::dumpPython( const QString& path, CAM_Study* std, bool isMultiFile, QStringList& listOfFiles) { @@ -80,26 +227,170 @@ bool PVGUI_DataModel::dumpPython( const QString& path, CAM_Study* std, return true; } -/*-----------------------------------------------------------------------------------------*/ -bool PVGUI_DataModel::open( const QString& theName, CAM_Study* theStudy, QStringList theList) { - bool res = LightApp_DataModel::open(theName, theStudy, theList); +/*! + \brief Open data model (read ParaView pipeline state from the files). + \param theName study file path + \param theStudy study pointer + \param theList list of the (temporary) files with data + \return operation status (\c true on success and \c false on error) +*/ +bool PVGUI_DataModel::open( const QString& theName, CAM_Study* theStudy, QStringList theList) +{ + bool ret = false; + LightApp_Study* aDoc = dynamic_cast( theStudy ); + if ( !aDoc ) + return false; + + LightApp_DataModel::open( theName, aDoc, theList ); publishComponent(theStudy); - return res; + + // The first list item contains path to a temporary + // directory, where the persistent files was placed + if ( theList.count() > 0 ) { + QString aTmpDir ( theList[0] ); + + if ( theList.size() >= 2 ) { + myStudyURL = theName; + QString aFullPath = SUIT_Tools::addSlash( aTmpDir ) + theList[1]; +// std::cout << "open: tmp dir is" << aFullPath.toStdString() << std::endl; + PVGUI_Module * mod = dynamic_cast(getModule()); + if (mod) + { + bool doRestore = false; + QStringList srcFilesEmpty; + createAndCheckRestoreFlag(aTmpDir, srcFilesEmpty, /*out*/doRestore); + if(doRestore) + { + // Update state file so that it points to new dir: + processAllFilesInState(aFullPath, srcFilesEmpty, aTmpDir.toStdString().c_str(), true); + } + + pqFixPathsInStateFilesBehavior::blockDialog(true); + mod->loadParaviewState(aFullPath); + pqFixPathsInStateFilesBehavior::blockDialog(false); + ret = true; + } + ret = true; + } + } + + return ret; } -/*-----------------------------------------------------------------------------------------*/ -bool PVGUI_DataModel::create( CAM_Study* theStudy) { - bool res = LightApp_DataModel::create(theStudy); - publishComponent(theStudy); - return res; +/*! + * Create an empty file indicating whether source files in the pipeline should be restored. + */ +bool PVGUI_DataModel::createAndCheckRestoreFlag(const QString& tmpdir, QStringList& listOfFiles, bool & alreadyThere) +{ + QString aFullPath = SUIT_Tools::addSlash( tmpdir ) + RESTORE_FLAG_FILE; + QFile f(aFullPath); + if (f.exists()) + { + alreadyThere = true; + return true; + } + else + { + bool ret = f.open(QFile::WriteOnly); + if (ret) + { + f.close(); + listOfFiles << RESTORE_FLAG_FILE; + } + return ret; + } } -/*-----------------------------------------------------------------------------------------*/ -void PVGUI_DataModel::publishComponent( CAM_Study* theStudy ) { - LightApp_Study* study = dynamic_cast( theStudy ); - CAM_ModuleObject *aModelRoot = dynamic_cast( root()); - if( study && aModelRoot == NULL ) { - aModelRoot = createModuleObject( theStudy->root() ); - aModelRoot->setDataModel( this ); - setRoot(aModelRoot); + + +/*! + \brief Save data model (write ParaView pipeline to the files). + \param listOfFiles returning list of the (temporary) files with saved data + \return operation status (\c true on success and \c false on error) +*/ +bool PVGUI_DataModel::save( QStringList& theListOfFiles) +{ + bool isMultiFile = false; // TODO: decide, how to access this parameter + bool ret = false; + + LightApp_DataModel::save( theListOfFiles ); + + LightApp_Study* study = dynamic_cast( getModule()->getApp()->activeStudy() ); + QString aTmpDir = study->GetTmpDir( myStudyURL.toLatin1(), isMultiFile ).c_str(); +// std::cout << "save: tmp dir is" << aTmpDir.toStdString() << std::endl; + + QString aFileName = SUIT_Tools::file( myStudyURL, false ) + "_PARAVIS.pvsm"; + QString aFullPath = aTmpDir + aFileName; + + PVGUI_Module * mod = dynamic_cast(getModule()); + QStringList srcFiles; + if (mod) + { + // Create ParaView state file: + mod->saveParaviewState(aFullPath.toStdString().c_str()); + + // add this to the list to be saved: + theListOfFiles << aTmpDir; + theListOfFiles << aFileName; + + // Potentially save referenced files: + SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); + int aSavingType = aResourceMgr->integerValue( "PARAVIS", "savestate_type", 0 ); + + bool unused; + bool isBuiltIn = false; + pqServer* aServer; + QString nullS; + + switch (aSavingType) { + case 0: // Save referenced files when they are accessible + createAndCheckRestoreFlag(aTmpDir, theListOfFiles ,unused); + processAllFilesInState(aFullPath, srcFiles, nullS, false); + break; + case 1: // Save referenced files only if this is the builtin server + aServer = pqApplicationCore::instance()->getActiveServer(); + if (aServer) + isBuiltIn != aServer->isRemote(); + if(isBuiltIn) + { + createAndCheckRestoreFlag(aTmpDir, theListOfFiles, unused); + processAllFilesInState(aFullPath, srcFiles, nullS, false); + } + break; + case 2: // Do not save referenced file + break; + default: + break; + } + + ret = true; + } + // Copying valid source files to the temp directory and adding them to the list + foreach(QString fName, srcFiles) + { + QFile fSrc(fName); + if (fSrc.exists()) + { + QFileInfo inf(fSrc); + QString newPth(SUIT_Tools::addSlash( aTmpDir ) + inf.fileName()); + if (fSrc.copy(newPth)) + { + theListOfFiles << inf.fileName(); + } + } } + + return ret; +} + +/*! + \brief Save data model (write ParaView pipeline state to the files). + \param url study file path + \param study study pointer + \param listOfFiles returning list of the (temporary) files with saved data + \return operation status (\c true on success and \c false on error) +*/ +bool PVGUI_DataModel::saveAs( const QString& url, CAM_Study* study, QStringList& theListOfFiles) +{ + myStudyURL = url; + return save( theListOfFiles ); } diff --git a/src/PVGUI/PVGUI_DataModel.h b/src/PVGUI/PVGUI_DataModel.h index 755e0e28..16220c62 100644 --- a/src/PVGUI/PVGUI_DataModel.h +++ b/src/PVGUI/PVGUI_DataModel.h @@ -41,10 +41,18 @@ public: virtual bool dumpPython( const QString&, CAM_Study*, bool, QStringList& ); virtual bool open( const QString&, CAM_Study*, QStringList ); + virtual bool save( QStringList& ); + virtual bool saveAs( const QString&, CAM_Study*, QStringList& ); virtual bool create( CAM_Study* ); private: void publishComponent(CAM_Study*); + + bool createAndCheckRestoreFlag(const QString& tmpdir, QStringList& listOfFiles, bool & alreadyThere); + + QString myStudyURL; + + static const QString RESTORE_FLAG_FILE; }; #endif /* PVGUIDATAMODEL_H_ */ diff --git a/src/PVGUI/PVGUI_Module.cxx b/src/PVGUI/PVGUI_Module.cxx index 247f4b69..b11dc186 100644 --- a/src/PVGUI/PVGUI_Module.cxx +++ b/src/PVGUI/PVGUI_Module.cxx @@ -837,9 +837,9 @@ void PVGUI_Module::saveTrace( const char* theName ) /*! \brief Saves ParaView state to a disk file */ -void PVGUI_Module::saveParaviewState( const char* theFileName ) +void PVGUI_Module::saveParaviewState( const QString& theFileName ) { - pqApplicationCore::instance()->saveState( theFileName ); + pqApplicationCore::instance()->saveState( theFileName.toStdString().c_str() ); } /*! @@ -856,9 +856,9 @@ void PVGUI_Module::clearParaviewState() /*! \brief Restores ParaView state from a disk file */ -void PVGUI_Module::loadParaviewState( const char* theFileName ) +void PVGUI_Module::loadParaviewState( const QString& theFileName ) { - pqApplicationCore::instance()->loadState( theFileName, getActiveServer() ); + pqApplicationCore::instance()->loadState( theFileName.toStdString().c_str(), getActiveServer() ); } /*! @@ -893,7 +893,6 @@ void PVGUI_Module::createPreferences() addPreference( tr( "PREF_NO_EXT_PVSERVER" ), aParaVisSettingsTab, LightApp_Preferences::Bool, PARAVIS_MODULE_NAME, "no_ext_pv_server" ); - /* VSR: not used int aSaveType = addPreference( tr( "PREF_SAVE_TYPE_LBL" ), aParaVisSettingsTab, LightApp_Preferences::Selector, PARAVIS_MODULE_NAME, "savestate_type" ); @@ -904,7 +903,6 @@ void PVGUI_Module::createPreferences() aStrings << tr("PREF_SAVE_TYPE_0") << tr("PREF_SAVE_TYPE_1") << tr("PREF_SAVE_TYPE_2"); setPreferenceProperty( aSaveType, "strings", aStrings ); setPreferenceProperty( aSaveType, "indexes", aIndices ); - */ // ... "Language" group <> int traceGroup = addPreference( tr( "PREF_GROUP_TRACE" ), aParaVisSettingsTab ); diff --git a/src/PVGUI/PVGUI_Module.h b/src/PVGUI/PVGUI_Module.h index 3cac7f89..929293b2 100644 --- a/src/PVGUI/PVGUI_Module.h +++ b/src/PVGUI/PVGUI_Module.h @@ -122,8 +122,9 @@ public: void openFile( const char* ); // not used inside PARAVIS void executeScript( const char* ); // not used inside PARAVIS - void saveParaviewState( const char* ); // not used inside PARAVIS - void loadParaviewState( const char* ); // not used inside PARAVIS + + void saveParaviewState( const QString& ); + void loadParaviewState( const QString& ); void clearParaviewState(); QString getTraceString(); diff --git a/src/PVGUI/resources/PARAVIS_msg_en.ts b/src/PVGUI/resources/PARAVIS_msg_en.ts index fd6d323c..55e4ba6a 100644 --- a/src/PVGUI/resources/PARAVIS_msg_en.ts +++ b/src/PVGUI/resources/PARAVIS_msg_en.ts @@ -1215,11 +1215,11 @@ PREF_SAVE_TYPE_0 - Save referenced files only for builtin server + Always save referenced files when they are accessible PREF_SAVE_TYPE_1 - Always save referenced files when they are accessible + Save referenced files only for builtin server PREF_SAVE_TYPE_2 diff --git a/src/PVGUI/resources/PARAVIS_msg_fr.ts b/src/PVGUI/resources/PARAVIS_msg_fr.ts index 7f149ccb..7b143016 100644 --- a/src/PVGUI/resources/PARAVIS_msg_fr.ts +++ b/src/PVGUI/resources/PARAVIS_msg_fr.ts @@ -1215,11 +1215,11 @@ PREF_SAVE_TYPE_0 - N'enregistrer les fichiers de référence qu'au serveur de babillard + Toujours enregistrer les fichiers de référence s'ils sont accessibles PREF_SAVE_TYPE_1 - Toujours enregistrer les fichiers de référence s'ils sont accessibles + N'enregistrer les fichiers de référence que pour le serveur builtin PREF_SAVE_TYPE_2 diff --git a/src/PVGUI/resources/PARAVIS_msg_ja.ts b/src/PVGUI/resources/PARAVIS_msg_ja.ts index 5dde22f1..34f554ce 100644 --- a/src/PVGUI/resources/PARAVIS_msg_ja.ts +++ b/src/PVGUI/resources/PARAVIS_msg_ja.ts @@ -1215,12 +1215,12 @@ PREF_SAVE_TYPE_0 - 掲示板サーバーだけに参照ファイルを保存します。 + アクセス可能な場合は常に参照のファイルを保存します。 PREF_SAVE_TYPE_1 - アクセス可能な場合は常に参照のファイルを保存します。 - + 掲示板サーバーだけに参照ファイルを保存します。 + PREF_SAVE_TYPE_2 参照ファイルを保存します。 -- 2.39.2