diff --git a/ApplicationCode/ProjectDataModel/RimProject.cpp b/ApplicationCode/ProjectDataModel/RimProject.cpp index fbf8cffe88..56436e0227 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.cpp +++ b/ApplicationCode/ProjectDataModel/RimProject.cpp @@ -28,7 +28,6 @@ #include "RigGridBase.h" #include "RimCalcScript.h" -#include "RimSummaryCalculationCollection.h" #include "RimCase.h" #include "RimCaseCollection.h" #include "RimCommandObject.h" @@ -38,6 +37,7 @@ #include "RimEclipseCaseCollection.h" #include "RimFlowPlotCollection.h" #include "RimFormationNamesCollection.h" +#include "RimSummaryCalculationCollection.h" #ifdef USE_PROTOTYPE_FEATURE_FRACTURES #include "RimFractureTemplateCollection.h" @@ -47,6 +47,7 @@ #include "RimGeoMechCase.h" #include "RimGeoMechModels.h" #include "RimGridSummaryCase.h" +#include "RimGridView.h" #include "RimIdenticalGridCaseGroup.h" #include "RimMainPlotCollection.h" #include "RimMultiSnapshotDefinition.h" @@ -58,7 +59,7 @@ #include "RimSummaryCaseMainCollection.h" #include "RimSummaryCrossPlotCollection.h" #include "RimSummaryPlotCollection.h" -#include "RimGridView.h" +#include "RimTools.h" #include "RimViewLinker.h" #include "RimViewLinkerCollection.h" #include "RimWellLogFile.h" @@ -67,15 +68,15 @@ #include "RimWellPathCollection.h" #include "RimWellPathImport.h" -#include "RiuMainWindow.h" #include "RiuMainPlotWindow.h" +#include "RiuMainWindow.h" #include "OctaveScriptCommands/RicExecuteScriptForCasesFeature.h" #include "cafCmdFeature.h" #include "cafCmdFeatureManager.h" -#include "cafPdmUiTreeOrdering.h" #include "cafCmdFeatureMenuBuilder.h" +#include "cafPdmUiTreeOrdering.h" #include "cvfBoundingBox.h" #include @@ -440,6 +441,18 @@ void RimProject::setProjectFileNameAndUpdateDependencies(const QString& fileName QFileInfo fileInfoOld(oldProjectFileName); QString oldProjectPath = fileInfoOld.path(); + + std::vector filePaths; + fieldsByType(this, filePaths); + + for (caf::FilePath* filePath : filePaths) + { + bool foundFile = false; + std::vector searchedPaths; + + QString newFilePath = RimTools::relocateFile(filePath->path(), newProjectPath, oldProjectPath, &foundFile, &searchedPaths); + filePath->setPath(newFilePath); + } // Loop over all cases and update file path diff --git a/ApplicationCode/ProjectDataModel/RimProject.h b/ApplicationCode/ProjectDataModel/RimProject.h index c29a17dc13..427324a4ec 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.h +++ b/ApplicationCode/ProjectDataModel/RimProject.h @@ -151,6 +151,10 @@ protected: virtual void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = ""); +private: + template + void fieldsByType(caf::PdmObjectHandle* object, std::vector& typedFields); + private: caf::PdmField m_projectFileVersionString; @@ -166,3 +170,39 @@ private: caf::PdmChildArrayField casesObsolete; // obsolete caf::PdmChildArrayField caseGroupsObsolete; // obsolete }; + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +template +void RimProject::fieldsByType(caf::PdmObjectHandle* object, std::vector& typedFields) +{ + if (!object) return; + + std::vector allFieldsInObject; + object->fields(allFieldsInObject); + + std::vector children; + + for (const auto& field : allFieldsInObject) + { + caf::PdmField* typedField = dynamic_cast*>(field); + if (typedField) typedFields.push_back(&typedField->v()); + + caf::PdmField< std::vector >* typedFieldInVector = dynamic_cast >*>(field); + if (typedFieldInVector) + { + for (T& typedFieldFromVector : typedFieldInVector->v()) + { + typedFields.push_back(&typedFieldFromVector); + } + } + + field->childObjects(&children); + } + + for (const auto& child : children) + { + fieldsByType(child, typedFields); + } +} diff --git a/ApplicationCode/UnitTests/RimRelocatePath-Test.cpp b/ApplicationCode/UnitTests/RimRelocatePath-Test.cpp index 32fa925bf8..7a54760e80 100644 --- a/ApplicationCode/UnitTests/RimRelocatePath-Test.cpp +++ b/ApplicationCode/UnitTests/RimRelocatePath-Test.cpp @@ -16,9 +16,8 @@ /// //-------------------------------------------------------------------------------------------------- template -void fieldsByType(caf::PdmObjectHandle* object, std::vector* typedFields) +void fieldsByType(caf::PdmObjectHandle* object, std::vector& typedFields) { - if (!typedFields) return; if (!object) return; std::vector allFieldsInObject; @@ -29,14 +28,14 @@ void fieldsByType(caf::PdmObjectHandle* object, std::vector* typedFields) for (const auto& field : allFieldsInObject) { caf::PdmField* typedField = dynamic_cast*>(field); - if (typedField) typedFields->push_back(&typedField->v()); + if (typedField) typedFields.push_back(&typedField->v()); caf::PdmField< std::vector >* typedFieldInVector = dynamic_cast >*>(field); if (typedFieldInVector) { for (T& typedFieldFromVector : typedFieldInVector->v()) { - typedFields->push_back(&typedFieldFromVector); + typedFields.push_back(&typedFieldFromVector); } } @@ -65,7 +64,7 @@ TEST(RimRelocatePathTest, findPathsInProjectFile) std::vector< caf::FilePath* > filePaths; - fieldsByType(&project, &filePaths); + fieldsByType(&project, filePaths); for (auto filePath : filePaths) {