diff --git a/ApplicationLibCode/Application/Tools/RiaImportEclipseCaseTools.cpp b/ApplicationLibCode/Application/Tools/RiaImportEclipseCaseTools.cpp index ab48a0e0bd..b3df717e2e 100644 --- a/ApplicationLibCode/Application/Tools/RiaImportEclipseCaseTools.cpp +++ b/ApplicationLibCode/Application/Tools/RiaImportEclipseCaseTools.cpp @@ -115,8 +115,10 @@ bool RiaImportEclipseCaseTools::openEclipseCasesFromFile( const QStringList& project->activeOilField() ? project->activeOilField()->summaryCaseMainCollection() : nullptr; if ( sumCaseColl ) { - std::vector newSumCases = sumCaseColl->createSummaryCasesFromFileInfos( summaryFileInfos ); - for ( RimSummaryCase* newSumCase : newSumCases ) + std::vector candidateCases = sumCaseColl->createSummaryCasesFromFileInfos( summaryFileInfos ); + std::vector duplicatedCases; + + for ( RimSummaryCase* newSumCase : candidateCases ) { RimSummaryCaseCollection* existingCollection = nullptr; QString gridCaseFile = @@ -130,7 +132,7 @@ bool RiaImportEclipseCaseTools::openEclipseCasesFromFile( const QStringList& auto* existingFileSummaryCase = dynamic_cast( existingSummaryCase ); if ( existingGridSummaryCase ) { - delete newSumCase; // No need to add anything new. Already have one. + duplicatedCases.push_back( newSumCase ); continue; } else if ( existingFileSummaryCase ) @@ -183,7 +185,8 @@ bool RiaImportEclipseCaseTools::openEclipseCasesFromFile( const QStringList& // Remove existing case sumCaseColl->removeCase( existingFileSummaryCase ); - delete existingFileSummaryCase; + + duplicatedCases.push_back( existingFileSummaryCase ); } } if ( existingCollection ) @@ -197,10 +200,18 @@ bool RiaImportEclipseCaseTools::openEclipseCasesFromFile( const QStringList& sumCaseColl->updateAllRequiredEditors(); } - if ( !newSumCases.empty() ) + // Delete cases that already was present + for ( auto duplicateCase : duplicatedCases ) { - RicSummaryPlotBuilder::createAndAppendDefaultSummaryMultiPlot( { newSumCases.front() }, {} ); - RiuPlotMainWindowTools::setExpanded( newSumCases.front() ); + candidateCases.erase( std::remove( candidateCases.begin(), candidateCases.end(), duplicateCase ), + candidateCases.end() ); + delete duplicateCase; + } + + if ( !candidateCases.empty() ) + { + RicSummaryPlotBuilder::createAndAppendDefaultSummaryMultiPlot( { candidateCases.front() }, {} ); + RiuPlotMainWindowTools::setExpanded( candidateCases.front() ); } } } diff --git a/GrpcInterface/Python/rips/tests/test_cases.py b/GrpcInterface/Python/rips/tests/test_cases.py index 2e8e056676..1cfd19c6ac 100644 --- a/GrpcInterface/Python/rips/tests/test_cases.py +++ b/GrpcInterface/Python/rips/tests/test_cases.py @@ -220,3 +220,11 @@ def test_selected_cells(rips_instance, initialize_test): # Try to read for SOIL the time step (will be empty since nothing is selected) soil_results = case.selected_cell_property("DYNAMIC_NATIVE", "SOIL", tidx) assert len(soil_results) == 0 + + +def test_multiple_load_of_same_case(rips_instance, initialize_test): + # Test related to issue https://github.com/OPM/ResInsight/issues/9332 + path_name = dataroot.PATH + "/flow_diagnostics_test/SIMPLE_SUMMARY2.EGRID" + case_count = 3 + for i in range(case_count): + case = rips_instance.project.load_case(path_name)