From 1c6c82af852631662710eb32cadb31001f2ceebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Thu, 12 Dec 2019 16:15:24 +0100 Subject: [PATCH] #5147 Fix RimFileWellPath::setupBeforeSave addressing the filePath Needs to copy the cached wellpaths on save. Split the cached filePath and the uncached filePath to only list the external well paths in the global path list, and to be able to copy the cached files on save. --- ...cWellPathFractureTextReportFeatureImpl.cpp | 2 +- .../ProjectDataModel/RimFileWellPath.cpp | 68 ++++++++++++++----- .../ProjectDataModel/RimFileWellPath.h | 7 +- .../ProjectDataModel/RimWellLogFile.cpp | 4 +- .../RimWellPathCollection.cpp | 10 +-- 5 files changed, 62 insertions(+), 29 deletions(-) diff --git a/ApplicationCode/Commands/CompletionExportCommands/RicWellPathFractureTextReportFeatureImpl.cpp b/ApplicationCode/Commands/CompletionExportCommands/RicWellPathFractureTextReportFeatureImpl.cpp index c2cc5193d7..1d74f807fc 100644 --- a/ApplicationCode/Commands/CompletionExportCommands/RicWellPathFractureTextReportFeatureImpl.cpp +++ b/ApplicationCode/Commands/CompletionExportCommands/RicWellPathFractureTextReportFeatureImpl.cpp @@ -254,7 +254,7 @@ QString RicWellPathFractureTextReportFeatureImpl::createWellFileLocationText( co if ( fileWellPath ) { formatter.add( wellPath->name() ); - formatter.add( fileWellPath->filepath() ); + formatter.add( fileWellPath->filePath() ); formatter.rowCompleted(); } } diff --git a/ApplicationCode/ProjectDataModel/RimFileWellPath.cpp b/ApplicationCode/ProjectDataModel/RimFileWellPath.cpp index bd9e466cd7..408b74252d 100644 --- a/ApplicationCode/ProjectDataModel/RimFileWellPath.cpp +++ b/ApplicationCode/ProjectDataModel/RimFileWellPath.cpp @@ -33,8 +33,11 @@ RimFileWellPath::RimFileWellPath() m_surveyType.uiCapability()->setUiReadOnly( true ); m_surveyType.xmlCapability()->disableIO(); - CAF_PDM_InitFieldNoDefault( &m_filepath, "WellPathFilepath", "File Path", "", "", "" ); - m_filepath.uiCapability()->setUiReadOnly( true ); + CAF_PDM_InitFieldNoDefault( &m_filePath, "WellPathFilepath", "File Path", "", "", "" ); + m_filePath.uiCapability()->setUiReadOnly( true ); + CAF_PDM_InitFieldNoDefault( &m_filePathInCache, "WellPathFilePathInCache", "File Name", "", "", "" ); + m_filePathInCache.uiCapability()->setUiReadOnly( true ); + CAF_PDM_InitField( &m_wellPathIndexInFile, "WellPathNumberInFile", -1, "Well Number in File", "", "", "" ); m_wellPathIndexInFile.uiCapability()->setUiReadOnly( true ); } @@ -47,9 +50,16 @@ RimFileWellPath::~RimFileWellPath() {} //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -QString RimFileWellPath::filepath() const +QString RimFileWellPath::filePath() const { - return m_filepath().path(); + if ( isStoredInCache() || m_filePath().path().isEmpty() ) + { + return m_filePathInCache(); + } + else + { + return m_filePath().path(); + } } //-------------------------------------------------------------------------------------------------- @@ -57,7 +67,7 @@ QString RimFileWellPath::filepath() const //-------------------------------------------------------------------------------------------------- void RimFileWellPath::setFilepath( const QString& path ) { - m_filepath = path; + m_filePath = path; } //-------------------------------------------------------------------------------------------------- @@ -96,7 +106,16 @@ void RimFileWellPath::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering RimWellPath::defineUiOrdering( uiConfigName, uiOrdering ); caf::PdmUiGroup* fileInfoGroup = uiOrdering.createGroupBeforeGroup( "Simulation Well", "File" ); - fileInfoGroup->add( &m_filepath ); + + if ( isStoredInCache() ) + { + fileInfoGroup->add( &m_filePathInCache ); + } + else + { + fileInfoGroup->add( &m_filePath ); + } + fileInfoGroup->add( &m_wellPathIndexInFile ); if ( !id().isEmpty() ) uiOrdering.insertBeforeItem( m_datumElevation.uiCapability(), &id ); @@ -112,12 +131,12 @@ void RimFileWellPath::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering //-------------------------------------------------------------------------------------------------- bool RimFileWellPath::readWellPathFile( QString* errorMessage, RifWellPathImporter* wellPathImporter ) { - if ( caf::Utils::fileExists( m_filepath().path() ) ) + if ( caf::Utils::fileExists( this->filePath() ) ) { - RifWellPathImporter::WellData wellData = wellPathImporter->readWellData( m_filepath().path(), + RifWellPathImporter::WellData wellData = wellPathImporter->readWellData( this->filePath(), m_wellPathIndexInFile() ); - RifWellPathImporter::WellMetaData wellMetaData = wellPathImporter->readWellMetaData( m_filepath().path(), + RifWellPathImporter::WellMetaData wellMetaData = wellPathImporter->readWellMetaData( this->filePath(), m_wellPathIndexInFile() ); // General well info @@ -130,11 +149,22 @@ bool RimFileWellPath::readWellPathFile( QString* errorMessage, RifWellPathImport updateDate = wellMetaData.m_updateDate.toString( "d MMMM yyyy" ); setWellPathGeometry( wellData.m_wellPathGeometry.p() ); + + // Now that the data is read, we know if this is an SSIHUB wellpath that needs to be stored in the + // cache folder along with the project file. If it is, move the pathfile reference to the m_filePathInCache + // in order to avoid it being handled as an externalFilePath by the RimProject class + + if ( isStoredInCache() && !m_filePath().path().isEmpty() ) + { + m_filePathInCache = m_filePath().path(); + m_filePath = QString( "" ); + } + return true; } else { - if ( errorMessage ) ( *errorMessage ) = "Could not find the well path file: " + m_filepath().path(); + if ( errorMessage ) ( *errorMessage ) = "Could not find the well path file: " + this->filePath(); return false; } } @@ -154,7 +184,7 @@ QString RimFileWellPath::getCacheDirectoryPath() //-------------------------------------------------------------------------------------------------- QString RimFileWellPath::getCacheFileName() { - if ( m_filepath().path().isEmpty() ) + if ( m_filePathInCache().isEmpty() ) { return ""; } @@ -162,8 +192,9 @@ QString RimFileWellPath::getCacheFileName() QString cacheFileName; // Make the path correct related to the possibly new project filename + QString newCacheDirPath = getCacheDirectoryPath(); - QFileInfo oldCacheFile( m_filepath().path() ); + QFileInfo oldCacheFile( m_filePathInCache() ); cacheFileName = newCacheDirPath + "/" + oldCacheFile.fileName(); @@ -175,13 +206,14 @@ QString RimFileWellPath::getCacheFileName() //-------------------------------------------------------------------------------------------------- void RimFileWellPath::setupBeforeSave() { + // Copy the possibly "cached" SSIHUB wellpath, stored in the folder along the project file // SSIHUB is the only source for populating Id, use text in this field to decide if the cache file must be copied to new project cache location if ( !isStoredInCache() ) { return; } - if ( m_filepath().path().isEmpty() ) + if ( m_filePathInCache().isEmpty() ) { return; } @@ -191,21 +223,21 @@ void RimFileWellPath::setupBeforeSave() QString newCacheFileName = getCacheFileName(); // Use QFileInfo to get same string representation to avoid issues with mix of forward and backward slashes - QFileInfo prevFileInfo( m_filepath().path() ); + QFileInfo prevFileInfo( m_filePathInCache() ); QFileInfo currentFileInfo( newCacheFileName ); if ( prevFileInfo.absoluteFilePath().compare( currentFileInfo.absoluteFilePath() ) != 0 ) { - QFile::copy( m_filepath().path(), newCacheFileName ); + QFile::copy( m_filePathInCache(), newCacheFileName ); - m_filepath = newCacheFileName; + m_filePathInCache = newCacheFileName; } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RimFileWellPath::isStoredInCache() +bool RimFileWellPath::isStoredInCache() const { // SSIHUB is the only source for populating Id, use text in this field to decide if the cache file must be copied to new project cache location return !id().isEmpty(); @@ -224,7 +256,7 @@ void RimFileWellPath::updateFilePathsFromProjectPath( const QString& newProjectP if ( caf::Utils::fileExists( newCacheFileName ) ) { - m_filepath = newCacheFileName; + m_filePathInCache = newCacheFileName; } } // else diff --git a/ApplicationCode/ProjectDataModel/RimFileWellPath.h b/ApplicationCode/ProjectDataModel/RimFileWellPath.h index 00e36d5320..62b52bc730 100644 --- a/ApplicationCode/ProjectDataModel/RimFileWellPath.h +++ b/ApplicationCode/ProjectDataModel/RimFileWellPath.h @@ -26,7 +26,7 @@ public: RimFileWellPath(); ~RimFileWellPath() override; - QString filepath() const; + QString filePath() const; void setFilepath( const QString& path ); bool readWellPathFile( QString* errorMessage, RifWellPathImporter* wellPathImporter ); int wellPathIndexInFile() const; // -1 means none. @@ -40,12 +40,13 @@ private: return m_surveyType; } void setSurveyType( QString surveyType ); - bool isStoredInCache(); + bool isStoredInCache() const; QString getCacheFileName(); void setupBeforeSave() override; - caf::PdmField m_filepath; + caf::PdmField m_filePath; + caf::PdmField m_filePathInCache; // Used for SSIHUB imported well paths caf::PdmField m_wellPathIndexInFile; // -1 means none. caf::PdmField id; diff --git a/ApplicationCode/ProjectDataModel/RimWellLogFile.cpp b/ApplicationCode/ProjectDataModel/RimWellLogFile.cpp index 6690c9d9ef..e9481ea864 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogFile.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogFile.cpp @@ -191,7 +191,7 @@ bool RimWellLogFile::readFile( QString* errorMessage ) this->firstAncestorOrThisOfType( wellPath ); if ( wellPath ) { - if ( wellPath->filepath().isEmpty() ) // Has dummy wellpath + if ( wellPath->filePath().isEmpty() ) // Has dummy wellpath { wellPath->setName( m_wellName ); } @@ -244,7 +244,7 @@ void RimWellLogFile::updateFilePathsFromProjectPath( const QString& newProjectPa { // bool foundFile = false; // std::vector searchedPaths; - // + // // QString fileNameCandidate = // RimTools::relocateFile( m_fileName(), newProjectPath, oldProjectPath, &foundFile, &searchedPaths ); // if ( foundFile ) diff --git a/ApplicationCode/ProjectDataModel/RimWellPathCollection.cpp b/ApplicationCode/ProjectDataModel/RimWellPathCollection.cpp index 15d27099b8..579aee84de 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellPathCollection.cpp @@ -148,7 +148,7 @@ void RimWellPathCollection::loadDataAndUpdate() RimModeledWellPath* mWPath = dynamic_cast( wellPaths[wpIdx] ); if ( fWPath ) { - if ( !fWPath->filepath().isEmpty() ) + if ( !fWPath->filePath().isEmpty() ) { QString errorMessage; if ( !fWPath->readWellPathFile( &errorMessage, m_wellPathImporter ) ) @@ -221,7 +221,7 @@ std::vector RimWellPathCollection::addWellPaths( QStringList fileP f1.setFileName( filePath ); QString s1 = f1.fileName(); QFile f2; - f2.setFileName( fWPath->filepath() ); + f2.setFileName( fWPath->filePath() ); QString s2 = f2.fileName(); if ( s1 == s2 ) { @@ -285,7 +285,7 @@ void RimWellPathCollection::readAndAddWellPaths( std::vector& RimFileWellPath* existingWellPath = dynamic_cast( tryFindMatchingWellPath( wellPath->name() ) ); if ( existingWellPath ) { - existingWellPath->setFilepath( wellPath->filepath() ); + existingWellPath->setFilepath( wellPath->filePath() ); existingWellPath->setWellPathIndexInFile( wellPath->wellPathIndexInFile() ); existingWellPath->readWellPathFile( nullptr, m_wellPathImporter ); @@ -596,7 +596,7 @@ void RimWellPathCollection::removeWellPath( RimWellPath* wellPath ) for ( size_t i = 0; i < wellPaths.size(); i++ ) { RimFileWellPath* fWPath = dynamic_cast( wellPaths[i] ); - if ( fWPath && fWPath->filepath() == fileWellPath->filepath() ) + if ( fWPath && fWPath->filePath() == fileWellPath->filePath() ) { isFilePathUsed = true; break; @@ -607,7 +607,7 @@ void RimWellPathCollection::removeWellPath( RimWellPath* wellPath ) { // One file can have multiple well paths // If no other well paths are referencing the filepath, remove cached data from the file reader - m_wellPathImporter->removeFilePath( fileWellPath->filepath() ); + m_wellPathImporter->removeFilePath( fileWellPath->filePath() ); } } updateAllRequiredEditors();