mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#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.
This commit is contained in:
parent
e4eea67a4e
commit
1c6c82af85
@ -254,7 +254,7 @@ QString RicWellPathFractureTextReportFeatureImpl::createWellFileLocationText( co
|
|||||||
if ( fileWellPath )
|
if ( fileWellPath )
|
||||||
{
|
{
|
||||||
formatter.add( wellPath->name() );
|
formatter.add( wellPath->name() );
|
||||||
formatter.add( fileWellPath->filepath() );
|
formatter.add( fileWellPath->filePath() );
|
||||||
formatter.rowCompleted();
|
formatter.rowCompleted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,11 @@ RimFileWellPath::RimFileWellPath()
|
|||||||
m_surveyType.uiCapability()->setUiReadOnly( true );
|
m_surveyType.uiCapability()->setUiReadOnly( true );
|
||||||
m_surveyType.xmlCapability()->disableIO();
|
m_surveyType.xmlCapability()->disableIO();
|
||||||
|
|
||||||
CAF_PDM_InitFieldNoDefault( &m_filepath, "WellPathFilepath", "File Path", "", "", "" );
|
CAF_PDM_InitFieldNoDefault( &m_filePath, "WellPathFilepath", "File Path", "", "", "" );
|
||||||
m_filepath.uiCapability()->setUiReadOnly( true );
|
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", "", "", "" );
|
CAF_PDM_InitField( &m_wellPathIndexInFile, "WellPathNumberInFile", -1, "Well Number in File", "", "", "" );
|
||||||
m_wellPathIndexInFile.uiCapability()->setUiReadOnly( true );
|
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 )
|
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 );
|
RimWellPath::defineUiOrdering( uiConfigName, uiOrdering );
|
||||||
|
|
||||||
caf::PdmUiGroup* fileInfoGroup = uiOrdering.createGroupBeforeGroup( "Simulation Well", "File" );
|
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 );
|
fileInfoGroup->add( &m_wellPathIndexInFile );
|
||||||
|
|
||||||
if ( !id().isEmpty() ) uiOrdering.insertBeforeItem( m_datumElevation.uiCapability(), &id );
|
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 )
|
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() );
|
m_wellPathIndexInFile() );
|
||||||
|
|
||||||
RifWellPathImporter::WellMetaData wellMetaData = wellPathImporter->readWellMetaData( m_filepath().path(),
|
RifWellPathImporter::WellMetaData wellMetaData = wellPathImporter->readWellMetaData( this->filePath(),
|
||||||
m_wellPathIndexInFile() );
|
m_wellPathIndexInFile() );
|
||||||
// General well info
|
// General well info
|
||||||
|
|
||||||
@ -130,11 +149,22 @@ bool RimFileWellPath::readWellPathFile( QString* errorMessage, RifWellPathImport
|
|||||||
updateDate = wellMetaData.m_updateDate.toString( "d MMMM yyyy" );
|
updateDate = wellMetaData.m_updateDate.toString( "d MMMM yyyy" );
|
||||||
|
|
||||||
setWellPathGeometry( wellData.m_wellPathGeometry.p() );
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,7 +184,7 @@ QString RimFileWellPath::getCacheDirectoryPath()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
QString RimFileWellPath::getCacheFileName()
|
QString RimFileWellPath::getCacheFileName()
|
||||||
{
|
{
|
||||||
if ( m_filepath().path().isEmpty() )
|
if ( m_filePathInCache().isEmpty() )
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -162,8 +192,9 @@ QString RimFileWellPath::getCacheFileName()
|
|||||||
QString cacheFileName;
|
QString cacheFileName;
|
||||||
|
|
||||||
// Make the path correct related to the possibly new project filename
|
// Make the path correct related to the possibly new project filename
|
||||||
|
|
||||||
QString newCacheDirPath = getCacheDirectoryPath();
|
QString newCacheDirPath = getCacheDirectoryPath();
|
||||||
QFileInfo oldCacheFile( m_filepath().path() );
|
QFileInfo oldCacheFile( m_filePathInCache() );
|
||||||
|
|
||||||
cacheFileName = newCacheDirPath + "/" + oldCacheFile.fileName();
|
cacheFileName = newCacheDirPath + "/" + oldCacheFile.fileName();
|
||||||
|
|
||||||
@ -175,13 +206,14 @@ QString RimFileWellPath::getCacheFileName()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RimFileWellPath::setupBeforeSave()
|
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
|
// 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() )
|
if ( !isStoredInCache() )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_filepath().path().isEmpty() )
|
if ( m_filePathInCache().isEmpty() )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -191,21 +223,21 @@ void RimFileWellPath::setupBeforeSave()
|
|||||||
QString newCacheFileName = getCacheFileName();
|
QString newCacheFileName = getCacheFileName();
|
||||||
|
|
||||||
// Use QFileInfo to get same string representation to avoid issues with mix of forward and backward slashes
|
// 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 );
|
QFileInfo currentFileInfo( newCacheFileName );
|
||||||
|
|
||||||
if ( prevFileInfo.absoluteFilePath().compare( currentFileInfo.absoluteFilePath() ) != 0 )
|
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
|
// 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();
|
return !id().isEmpty();
|
||||||
@ -224,7 +256,7 @@ void RimFileWellPath::updateFilePathsFromProjectPath( const QString& newProjectP
|
|||||||
|
|
||||||
if ( caf::Utils::fileExists( newCacheFileName ) )
|
if ( caf::Utils::fileExists( newCacheFileName ) )
|
||||||
{
|
{
|
||||||
m_filepath = newCacheFileName;
|
m_filePathInCache = newCacheFileName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else
|
// else
|
||||||
|
@ -26,7 +26,7 @@ public:
|
|||||||
RimFileWellPath();
|
RimFileWellPath();
|
||||||
~RimFileWellPath() override;
|
~RimFileWellPath() override;
|
||||||
|
|
||||||
QString filepath() const;
|
QString filePath() const;
|
||||||
void setFilepath( const QString& path );
|
void setFilepath( const QString& path );
|
||||||
bool readWellPathFile( QString* errorMessage, RifWellPathImporter* wellPathImporter );
|
bool readWellPathFile( QString* errorMessage, RifWellPathImporter* wellPathImporter );
|
||||||
int wellPathIndexInFile() const; // -1 means none.
|
int wellPathIndexInFile() const; // -1 means none.
|
||||||
@ -40,12 +40,13 @@ private:
|
|||||||
return m_surveyType;
|
return m_surveyType;
|
||||||
}
|
}
|
||||||
void setSurveyType( QString surveyType );
|
void setSurveyType( QString surveyType );
|
||||||
bool isStoredInCache();
|
bool isStoredInCache() const;
|
||||||
QString getCacheFileName();
|
QString getCacheFileName();
|
||||||
|
|
||||||
void setupBeforeSave() override;
|
void setupBeforeSave() override;
|
||||||
|
|
||||||
caf::PdmField<caf::FilePath> m_filepath;
|
caf::PdmField<caf::FilePath> m_filePath;
|
||||||
|
caf::PdmField<QString> m_filePathInCache; // Used for SSIHUB imported well paths
|
||||||
caf::PdmField<int> m_wellPathIndexInFile; // -1 means none.
|
caf::PdmField<int> m_wellPathIndexInFile; // -1 means none.
|
||||||
|
|
||||||
caf::PdmField<QString> id;
|
caf::PdmField<QString> id;
|
||||||
|
@ -191,7 +191,7 @@ bool RimWellLogFile::readFile( QString* errorMessage )
|
|||||||
this->firstAncestorOrThisOfType( wellPath );
|
this->firstAncestorOrThisOfType( wellPath );
|
||||||
if ( wellPath )
|
if ( wellPath )
|
||||||
{
|
{
|
||||||
if ( wellPath->filepath().isEmpty() ) // Has dummy wellpath
|
if ( wellPath->filePath().isEmpty() ) // Has dummy wellpath
|
||||||
{
|
{
|
||||||
wellPath->setName( m_wellName );
|
wellPath->setName( m_wellName );
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ void RimWellPathCollection::loadDataAndUpdate()
|
|||||||
RimModeledWellPath* mWPath = dynamic_cast<RimModeledWellPath*>( wellPaths[wpIdx] );
|
RimModeledWellPath* mWPath = dynamic_cast<RimModeledWellPath*>( wellPaths[wpIdx] );
|
||||||
if ( fWPath )
|
if ( fWPath )
|
||||||
{
|
{
|
||||||
if ( !fWPath->filepath().isEmpty() )
|
if ( !fWPath->filePath().isEmpty() )
|
||||||
{
|
{
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
if ( !fWPath->readWellPathFile( &errorMessage, m_wellPathImporter ) )
|
if ( !fWPath->readWellPathFile( &errorMessage, m_wellPathImporter ) )
|
||||||
@ -221,7 +221,7 @@ std::vector<RimWellPath*> RimWellPathCollection::addWellPaths( QStringList fileP
|
|||||||
f1.setFileName( filePath );
|
f1.setFileName( filePath );
|
||||||
QString s1 = f1.fileName();
|
QString s1 = f1.fileName();
|
||||||
QFile f2;
|
QFile f2;
|
||||||
f2.setFileName( fWPath->filepath() );
|
f2.setFileName( fWPath->filePath() );
|
||||||
QString s2 = f2.fileName();
|
QString s2 = f2.fileName();
|
||||||
if ( s1 == s2 )
|
if ( s1 == s2 )
|
||||||
{
|
{
|
||||||
@ -285,7 +285,7 @@ void RimWellPathCollection::readAndAddWellPaths( std::vector<RimFileWellPath*>&
|
|||||||
RimFileWellPath* existingWellPath = dynamic_cast<RimFileWellPath*>( tryFindMatchingWellPath( wellPath->name() ) );
|
RimFileWellPath* existingWellPath = dynamic_cast<RimFileWellPath*>( tryFindMatchingWellPath( wellPath->name() ) );
|
||||||
if ( existingWellPath )
|
if ( existingWellPath )
|
||||||
{
|
{
|
||||||
existingWellPath->setFilepath( wellPath->filepath() );
|
existingWellPath->setFilepath( wellPath->filePath() );
|
||||||
existingWellPath->setWellPathIndexInFile( wellPath->wellPathIndexInFile() );
|
existingWellPath->setWellPathIndexInFile( wellPath->wellPathIndexInFile() );
|
||||||
existingWellPath->readWellPathFile( nullptr, m_wellPathImporter );
|
existingWellPath->readWellPathFile( nullptr, m_wellPathImporter );
|
||||||
|
|
||||||
@ -596,7 +596,7 @@ void RimWellPathCollection::removeWellPath( RimWellPath* wellPath )
|
|||||||
for ( size_t i = 0; i < wellPaths.size(); i++ )
|
for ( size_t i = 0; i < wellPaths.size(); i++ )
|
||||||
{
|
{
|
||||||
RimFileWellPath* fWPath = dynamic_cast<RimFileWellPath*>( wellPaths[i] );
|
RimFileWellPath* fWPath = dynamic_cast<RimFileWellPath*>( wellPaths[i] );
|
||||||
if ( fWPath && fWPath->filepath() == fileWellPath->filepath() )
|
if ( fWPath && fWPath->filePath() == fileWellPath->filePath() )
|
||||||
{
|
{
|
||||||
isFilePathUsed = true;
|
isFilePathUsed = true;
|
||||||
break;
|
break;
|
||||||
@ -607,7 +607,7 @@ void RimWellPathCollection::removeWellPath( RimWellPath* wellPath )
|
|||||||
{
|
{
|
||||||
// One file can have multiple well paths
|
// One file can have multiple well paths
|
||||||
// If no other well paths are referencing the filepath, remove cached data from the file reader
|
// 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();
|
updateAllRequiredEditors();
|
||||||
|
Loading…
Reference in New Issue
Block a user