From 82155ae779fff3754b8859f232e531d06cb78bee Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Sat, 30 Nov 2019 10:23:24 +0100 Subject: [PATCH] #5106 Fix crash when importing multiple well paths with the same name --- ApplicationCode/Application/RiaApplication.cpp | 8 ++++---- ApplicationCode/Application/RiaApplication.h | 6 +++--- .../Commands/WellPathCommands/RicImportWellPaths.cpp | 10 +++++----- .../Commands/WellPathCommands/RicImportWellPaths.h | 7 +++---- .../ProjectDataModel/RimWellPathCollection.cpp | 7 ++++--- .../ProjectDataModel/RimWellPathCollection.h | 4 ++-- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index 0958f875e3..19babbd370 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -316,7 +316,7 @@ bool RiaApplication::openFile( const QString& fileName ) } else if ( fileType & RiaDefines::ANY_ECLIPSE_FILE ) { - loadingSucceded = RicImportGeneralDataFeature::openEclipseFilesFromFileNames( QStringList{fileName}, true ); + loadingSucceded = RicImportGeneralDataFeature::openEclipseFilesFromFileNames( QStringList{ fileName }, true ); lastUsedDialogTag = RiaDefines::defaultDirectoryLabel( fileType ); } @@ -849,8 +849,8 @@ bool RiaApplication::openOdbCaseFromFile( const QString& fileName, bool applyTim //-------------------------------------------------------------------------------------------------- /// Add a list of well path file paths (JSON files) to the well path collection //-------------------------------------------------------------------------------------------------- -std::vector RiaApplication::addWellPathsToModel( QList wellPathFilePaths, - QStringList* errorMessages ) +std::vector RiaApplication::addWellPathsToModel( QList wellPathFilePaths, + QStringList* errorMessages ) { CAF_ASSERT( errorMessages ); @@ -867,7 +867,7 @@ std::vector RiaApplication::addWellPathsToModel( QListupdateConnectedEditors(); } - std::vector wellPaths; + std::vector wellPaths; if ( oilField->wellPathCollection ) { wellPaths = oilField->wellPathCollection->addWellPaths( wellPathFilePaths, errorMessages ); diff --git a/ApplicationCode/Application/RiaApplication.h b/ApplicationCode/Application/RiaApplication.h index 622349afba..c6db277d32 100644 --- a/ApplicationCode/Application/RiaApplication.h +++ b/ApplicationCode/Application/RiaApplication.h @@ -54,7 +54,7 @@ class RigEclipseCaseData; class RimCommandObject; class RimEclipseCase; class RimEclipseView; -class RimFileWellPath; +class RimWellPath; class RimGridView; class RimProject; class RimSummaryPlot; @@ -144,8 +144,8 @@ public: bool openOdbCaseFromFile( const QString& fileName, bool applyTimeStepFilter = false ); - std::vector addWellPathsToModel( QList wellPathFilePaths, QStringList* errorMessages ); - void addWellPathFormationsToModel( QList wellPathFilePaths ); + std::vector addWellPathsToModel( QList wellPathFilePaths, QStringList* errorMessages ); + void addWellPathFormationsToModel( QList wellPathFilePaths ); std::vector addWellLogsToModel( const QList& wellLogFilePaths, QStringList* errorMessages ); QString scriptDirectories() const; diff --git a/ApplicationCode/Commands/WellPathCommands/RicImportWellPaths.cpp b/ApplicationCode/Commands/WellPathCommands/RicImportWellPaths.cpp index bce8f6a941..c4eaa34a82 100644 --- a/ApplicationCode/Commands/WellPathCommands/RicImportWellPaths.cpp +++ b/ApplicationCode/Commands/WellPathCommands/RicImportWellPaths.cpp @@ -103,11 +103,11 @@ RicfCommandResponse RicImportWellPaths::execute() RicfCommandResponse response; if ( !wellPathFiles.empty() ) { - std::vector importedWellPaths = importWellPaths( wellPathFiles, &warningMessages ); + std::vector importedWellPaths = importWellPaths( wellPathFiles, &warningMessages ); if ( !importedWellPaths.empty() ) { RicImportWellPathsResult* wellPathsResult = new RicImportWellPathsResult; - for ( RimFileWellPath* wellPath : importedWellPaths ) + for ( RimWellPath* wellPath : importedWellPaths ) { wellPathsResult->wellPathNames.v().push_back( wellPath->name() ); } @@ -136,15 +136,15 @@ RicfCommandResponse RicImportWellPaths::execute() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RicImportWellPaths::importWellPaths( const QStringList& wellPathFilePaths, - QStringList* errorMessages ) +std::vector RicImportWellPaths::importWellPaths( const QStringList& wellPathFilePaths, + QStringList* errorMessages ) { RiaApplication* app = RiaApplication::instance(); // Remember the path to next time app->setLastUsedDialogDirectory( "WELLPATH_DIR", QFileInfo( wellPathFilePaths.last() ).absolutePath() ); - std::vector wellPaths = app->addWellPathsToModel( wellPathFilePaths, errorMessages ); + std::vector wellPaths = app->addWellPathsToModel( wellPathFilePaths, errorMessages ); RimProject* project = app->project(); diff --git a/ApplicationCode/Commands/WellPathCommands/RicImportWellPaths.h b/ApplicationCode/Commands/WellPathCommands/RicImportWellPaths.h index fdf1da5ea8..d0e1933432 100644 --- a/ApplicationCode/Commands/WellPathCommands/RicImportWellPaths.h +++ b/ApplicationCode/Commands/WellPathCommands/RicImportWellPaths.h @@ -29,7 +29,7 @@ #include -class RimFileWellPath; +class RimWellPath; //================================================================================================== /// @@ -43,9 +43,8 @@ public: RicfCommandResponse execute() override; protected: - static std::vector importWellPaths( const QStringList& wellPathFilePaths, - QStringList* errorMessages ); - static QStringList wellPathNameFilters(); + static std::vector importWellPaths( const QStringList& wellPathFilePaths, QStringList* errorMessages ); + static QStringList wellPathNameFilters(); // Overrides bool isCommandEnabled() override; diff --git a/ApplicationCode/ProjectDataModel/RimWellPathCollection.cpp b/ApplicationCode/ProjectDataModel/RimWellPathCollection.cpp index cb845f1790..bb2e028c81 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellPathCollection.cpp @@ -198,7 +198,7 @@ void RimWellPathCollection::loadDataAndUpdate() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RimWellPathCollection::addWellPaths( QStringList filePaths, QStringList* errorMessages ) +std::vector RimWellPathCollection::addWellPaths( QStringList filePaths, QStringList* errorMessages ) { CAF_ASSERT( errorMessages ); @@ -254,11 +254,12 @@ std::vector RimWellPathCollection::addWellPaths( QStringList f } readAndAddWellPaths( wellPathArray ); + CAF_ASSERT( wellPathArray.empty() ); scheduleRedrawAffectedViews(); updateAllRequiredEditors(); - return wellPathArray; + return wellPaths.childObjects(); } //-------------------------------------------------------------------------------------------------- @@ -299,7 +300,7 @@ void RimWellPathCollection::readAndAddWellPaths( std::vector& progress.incrementProgress(); } - + wellPathArray.clear(); // This should not be used again. We may have deleted items this->sortWellsByName(); } diff --git a/ApplicationCode/ProjectDataModel/RimWellPathCollection.h b/ApplicationCode/ProjectDataModel/RimWellPathCollection.h index 4d406638a5..649bc9308c 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathCollection.h +++ b/ApplicationCode/ProjectDataModel/RimWellPathCollection.h @@ -88,8 +88,8 @@ public: caf::PdmChildArrayField wellPaths; - void loadDataAndUpdate(); - std::vector addWellPaths( QStringList filePaths, QStringList* errorMessages ); + void loadDataAndUpdate(); + std::vector addWellPaths( QStringList filePaths, QStringList* errorMessages ); void removeWellPath( RimWellPath* wellPath ); void deleteAllWellPaths();