From a97dd087d62f45fc587c4fd73fcc01125a494eae Mon Sep 17 00:00:00 2001 From: Rebecca Cox Date: Fri, 12 Jan 2018 14:39:15 +0100 Subject: [PATCH] #2349 Elm Props: Use caf::FilePath instead of QString --- .../RicImportElementPropertyFeature.cpp | 6 +-- .../ProjectDataModel/RimGeoMechCase.cpp | 41 +++++++++++++++---- .../ProjectDataModel/RimGeoMechCase.h | 19 +++++---- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/ApplicationCode/Commands/RicImportElementPropertyFeature.cpp b/ApplicationCode/Commands/RicImportElementPropertyFeature.cpp index 1c1c59bbc4..72bda624e3 100644 --- a/ApplicationCode/Commands/RicImportElementPropertyFeature.cpp +++ b/ApplicationCode/Commands/RicImportElementPropertyFeature.cpp @@ -55,10 +55,10 @@ void RicImportElementPropertyFeature::onActionTriggered(bool isChecked) defaultDir = QFileInfo(fileNames.last()).absolutePath(); } - std::vector fileNamesStd; + std::vector filePaths; for (QString filename : fileNames) { - fileNamesStd.push_back(filename); + filePaths.push_back(caf::FilePath(filename)); } app->setLastUsedDialogDirectory("ELM_PROPS", defaultDir); @@ -71,7 +71,7 @@ void RicImportElementPropertyFeature::onActionTriggered(bool isChecked) if (activeGmv->geoMechCase()) { - activeGmv->geoMechCase()->addElementPropertyFiles(fileNamesStd); + activeGmv->geoMechCase()->addElementPropertyFiles(filePaths); } } diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechCase.cpp b/ApplicationCode/ProjectDataModel/RimGeoMechCase.cpp index 89ff2bc2fd..efd2f81319 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimGeoMechCase.cpp @@ -61,6 +61,9 @@ RimGeoMechCase::RimGeoMechCase(void) CAF_PDM_InitField(&m_frictionAngleDeg, "FrctionAngleDeg", 30.0, "Friction Angle [Deg]", "", "Used to calculate the SE:SFI result", ""); CAF_PDM_InitFieldNoDefault(&m_elementPropertyFileNames, "ElementPropertyFileNames", "Element Property Files", "", "", ""); + + CAF_PDM_InitFieldNoDefault(&m_elementPropertyFileNameUiSelection, "ElementPropertyFileNameSelection", "", "", "", ""); + m_elementPropertyFileNameUiSelection.xmlCapability()->disableIO(); } //-------------------------------------------------------------------------------------------------- @@ -172,7 +175,12 @@ bool RimGeoMechCase::openGeoMechCase(std::string* errorMessage) if (m_geoMechCaseData.notNull()) { - geoMechData()->femPartResults()->addElementPropertyFiles(m_elementPropertyFileNames); + std::vector fileNames; + for (const caf::FilePath& fileName : m_elementPropertyFileNames.v()) + { + fileNames.push_back(fileName.path()); + } + geoMechData()->femPartResults()->addElementPropertyFiles(fileNames); } return fileOpenSuccess; @@ -189,9 +197,9 @@ void RimGeoMechCase::updateFilePathsFromProjectPath(const QString& newProjectPat // Update filename and folder paths when opening project from a different file location m_caseFileName = RimTools::relocateFile(m_caseFileName(), newProjectPath, oldProjectPath, &foundFile, &searchedPaths); - for (QString& fileName : m_elementPropertyFileNames.v()) + for (caf::FilePath& fileName : m_elementPropertyFileNames.v()) { - fileName = RimTools::relocateFile(fileName, newProjectPath, oldProjectPath, &foundFile, &searchedPaths); + fileName = RimTools::relocateFile(fileName.path(), newProjectPath, oldProjectPath, &foundFile, &searchedPaths); } #if 0 // Output the search path for debugging @@ -330,15 +338,15 @@ void RimGeoMechCase::setFormationNames(RimFormationNames* formationNames) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimGeoMechCase::addElementPropertyFiles(const std::vector& fileNames) +void RimGeoMechCase::addElementPropertyFiles(const std::vector& fileNames) { std::vector newFileNames; - for (const QString& newFileNameToPossiblyAdd : fileNames) + for (const caf::FilePath& newFileNameToPossiblyAdd : fileNames) { bool fileAlreadyAdded = false; - for (const QString& existingFileName : m_elementPropertyFileNames.v()) + for (const caf::FilePath& existingFileName : m_elementPropertyFileNames()) { if (existingFileName == newFileNameToPossiblyAdd) { @@ -348,7 +356,7 @@ void RimGeoMechCase::addElementPropertyFiles(const std::vector& fileNam } if (!fileAlreadyAdded) { - newFileNames.push_back(newFileNameToPossiblyAdd); + newFileNames.push_back(newFileNameToPossiblyAdd.path()); m_elementPropertyFileNames.v().push_back(newFileNameToPossiblyAdd); } } @@ -521,6 +529,23 @@ void RimGeoMechCase::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& caseGroup->add(&m_frictionAngleDeg); caf::PdmUiGroup* elmPropGroup = uiOrdering.addNewGroup("Element Properties"); - elmPropGroup->add(&m_elementPropertyFileNames); + elmPropGroup->add(&m_elementPropertyFileNameUiSelection); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QList RimGeoMechCase::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) +{ + QList options; + + if (fieldNeedingOptions == &m_elementPropertyFileNameUiSelection) + { + for (const caf::FilePath& fileName : m_elementPropertyFileNames.v()) + { + options.push_back(caf::PdmOptionItemInfo(fileName.path(), fileName.path() , true, QIcon())); + } + } + + return options; +} diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechCase.h b/ApplicationCode/ProjectDataModel/RimGeoMechCase.h index 278cd32bf5..b5eb24a002 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechCase.h +++ b/ApplicationCode/ProjectDataModel/RimGeoMechCase.h @@ -21,6 +21,7 @@ #include "RimCase.h" +#include "cafFilePath.h" #include "cafPdmChildArrayField.h" #include "cafPdmField.h" #include "cafPdmObject.h" @@ -69,7 +70,7 @@ public: virtual void setFormationNames(RimFormationNames* formationNames) override; - void addElementPropertyFiles(const std::vector& filenames); + void addElementPropertyFiles(const std::vector& filenames); // Fields: caf::PdmChildArrayField geoMechViews; @@ -80,16 +81,20 @@ private: virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override; + virtual QList calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) override; virtual void updateFormationNamesData() override; - virtual void initAfterRead(); + virtual void initAfterRead() override; static QString subStringOfDigits(const QString& timeStepString, int numberOfDigitsToFind); private: - cvf::ref m_geoMechCaseData; - caf::PdmField m_caseFileName; - caf::PdmField m_cohesion; - caf::PdmField m_frictionAngleDeg; - caf::PdmField > m_elementPropertyFileNames; + cvf::ref m_geoMechCaseData; + caf::PdmField m_caseFileName; + caf::PdmField m_cohesion; + caf::PdmField m_frictionAngleDeg; + caf::PdmField> m_elementPropertyFileNames; + caf::PdmField > m_elementPropertyFileNameUiSelection; + caf::PdmField m_closeElementPropertyFileCommand; + caf::PdmField m_reloadElementPropertyFileCommand; };