From f77b3673b01b8e9bff149b32468423a34f3260a9 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 4 Nov 2022 10:11:08 +0100 Subject: [PATCH] Well path import improvements * #9432 Clean file cache when all wells are deleted * Key Events: Avoid eating Delete key events Do not use a key short cut on menu actions that are always enabled. Will eat events from other actions. * #9433 Well Path Import: Keep prefix when trying to match existing well path --- .../RicDeleteSubPlotCtxFeature.cpp | 11 +++++++ .../RicDeleteSubPlotCtxFeature.h | 1 + .../FileInterface/RifWellPathImporter.h | 24 ++++++++------- .../WellPath/RimWellPathCollection.cpp | 29 +++++++++++-------- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicDeleteSubPlotCtxFeature.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicDeleteSubPlotCtxFeature.cpp index b9b107e2c7..12ca362f8e 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicDeleteSubPlotCtxFeature.cpp +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicDeleteSubPlotCtxFeature.cpp @@ -18,6 +18,8 @@ #include "RicDeleteSubPlotCtxFeature.h" +#include + CAF_CMD_SOURCE_INIT( RicDeleteSubPlotCtxFeature, "RicDeleteSubPlotCtxFeature" ); //-------------------------------------------------------------------------------------------------- @@ -27,3 +29,12 @@ bool RicDeleteSubPlotCtxFeature::isCommandEnabled() { return true; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicDeleteSubPlotCtxFeature::setupActionLook( QAction* actionToSetup ) +{ + RicDeleteSubPlotFeature::setupActionLook( actionToSetup ); + actionToSetup->setShortcut( QKeySequence() ); +} diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicDeleteSubPlotCtxFeature.h b/ApplicationLibCode/Commands/SummaryPlotCommands/RicDeleteSubPlotCtxFeature.h index e0643f4783..bf0cc88b31 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicDeleteSubPlotCtxFeature.h +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicDeleteSubPlotCtxFeature.h @@ -29,4 +29,5 @@ class RicDeleteSubPlotCtxFeature : public RicDeleteSubPlotFeature protected: bool isCommandEnabled() override; + void setupActionLook( QAction* actionToSetup ) override; }; diff --git a/ApplicationLibCode/FileInterface/RifWellPathImporter.h b/ApplicationLibCode/FileInterface/RifWellPathImporter.h index aeaa43094d..9ecba0f384 100644 --- a/ApplicationLibCode/FileInterface/RifWellPathImporter.h +++ b/ApplicationLibCode/FileInterface/RifWellPathImporter.h @@ -53,23 +53,25 @@ public: QDateTime m_updateDate; }; - WellData readWellData( const QString& filePath, size_t indexInFile ); - WellData readWellData( const QString& filePath ); - WellMetaData readWellMetaData( const QString& filePath, size_t indexInFile ); - WellMetaData readWellMetaData( const QString& filePath ); - size_t wellDataCount( const QString& filePath ); + WellData readWellData( const QString& filePath, size_t indexInFile ); + WellData readWellData( const QString& filePath ); + size_t wellDataCount( const QString& filePath ); void clear(); void removeFilePath( const QString& filePath ); + static WellMetaData readWellMetaData( const QString& filePath, size_t indexInFile ); + static WellMetaData readWellMetaData( const QString& filePath ); + private: - WellData readJsonWellData( const QString& filePath ); - WellMetaData readJsonWellMetaData( const QString& filePath ); - WellData readAsciiWellData( const QString& filePath, size_t indexInFile ); - WellMetaData readAsciiWellMetaData( const QString& filePath, size_t indexInFile ); - void readAllAsciiWellData( const QString& filePath ); + WellData readAsciiWellData( const QString& filePath, size_t indexInFile ); + void readAllAsciiWellData( const QString& filePath ); - inline bool isJsonFile( const QString& filePath ); + static WellData readJsonWellData( const QString& filePath ); + static WellMetaData readJsonWellMetaData( const QString& filePath ); + static WellMetaData readAsciiWellMetaData( const QString& filePath, size_t indexInFile ); + static bool isJsonFile( const QString& filePath ); +private: std::map> m_fileNameToWellDataGroupMap; }; diff --git a/ApplicationLibCode/ProjectDataModel/WellPath/RimWellPathCollection.cpp b/ApplicationLibCode/ProjectDataModel/WellPath/RimWellPathCollection.cpp index e5631a986a..bbf79d8702 100644 --- a/ApplicationLibCode/ProjectDataModel/WellPath/RimWellPathCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/WellPath/RimWellPathCollection.cpp @@ -305,16 +305,17 @@ void RimWellPathCollection::readAndAddWellPaths( std::vector& caf::ProgressInfo progress( wellPathArray.size(), "Reading well paths from file" ); std::vector wellPathsToGroup; - for ( size_t wpIdx = 0; wpIdx < wellPathArray.size(); wpIdx++ ) + for ( RimFileWellPath* wellPath : wellPathArray ) { - RimFileWellPath* wellPath = wellPathArray[wpIdx]; wellPath->readWellPathFile( nullptr, m_wellPathImporter.get(), true ); progress.setProgressDescription( QString( "Reading file %1" ).arg( wellPath->name() ) ); - // If a well path with this name exists already, make it read the well path file - RimFileWellPath* existingWellPath = dynamic_cast( tryFindMatchingWellPath( wellPath->name() ) ); - + // If a well path with this name exists already, make it read the well path file. This is useful if a well log + // file has been imported before a well path file containing the full geometry for the well path. + // NB! Do not use tryFindMatchingWellPath(), as this function will remove the prefix and will return an false + // match in many cases. + auto* existingWellPath = dynamic_cast( wellPathByName( wellPath->name() ) ); if ( existingWellPath ) { existingWellPath->setFilepath( wellPath->filePath() ); @@ -584,6 +585,8 @@ void RimWellPathCollection::deleteAllWellPaths() //-------------------------------------------------------------------------------------------------- void RimWellPathCollection::deleteWell( RimWellPath* wellPath ) { + removeWellPath( wellPath ); + m_wellPaths.removeChild( wellPath ); delete wellPath; } @@ -703,16 +706,18 @@ void RimWellPathCollection::reloadAllWellPathFormations() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimWellPathCollection::removeWellPath( gsl::not_null wellPath ) +void RimWellPathCollection::removeWellPath( gsl::not_null wellToRemove ) { - RimFileWellPath* fileWellPath = dynamic_cast( wellPath.get() ); - if ( fileWellPath ) + auto* fileWellToRemove = dynamic_cast( wellToRemove.get() ); + if ( fileWellToRemove ) { bool isFilePathUsed = false; - for ( auto wellPath : m_wellPaths ) + for ( const auto& well : m_wellPaths ) { - RimFileWellPath* fWPath = dynamic_cast( wellPath.p() ); - if ( fWPath && fWPath->filePath() == fileWellPath->filePath() ) + auto fileWell = dynamic_cast( well.p() ); + if ( fileWell == fileWellToRemove ) continue; + + if ( fileWell && fileWell->filePath() == fileWellToRemove->filePath() ) { isFilePathUsed = true; break; @@ -723,7 +728,7 @@ void RimWellPathCollection::removeWellPath( gsl::not_null 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( fileWellToRemove->filePath() ); } } updateAllRequiredEditors();