Skip to content

Commit 6d7959d

Browse files
committed
#14542 Summary: Assign unique case ids when importing multiple cases
Summary cases are created and given a case id before they are added to the project. The id search only sees cases already in the project, so every case in a batch import was given the same id. The Data Sources tree stores the owning case id in each summary address, and all lookups resolve to the first case with that id. Selecting the same vector from several cases therefore produced a single curve, and dropping a vector from one of the other cases hit the duplicate check and did nothing.
1 parent 5e17f99 commit 6d7959d

4 files changed

Lines changed: 47 additions & 8 deletions

File tree

ApplicationLibCode/ProjectDataModel/RimProject.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -555,15 +555,23 @@ void RimProject::setProjectFileNameAndUpdateDependencies( const QString& project
555555
//--------------------------------------------------------------------------------------------------
556556
void RimProject::assignCaseIdToSummaryCase( RimSummaryCase* summaryCase )
557557
{
558-
if ( summaryCase )
558+
assignCaseIdsToSummaryCases( { summaryCase } );
559+
}
560+
561+
//--------------------------------------------------------------------------------------------------
562+
///
563+
//--------------------------------------------------------------------------------------------------
564+
void RimProject::assignCaseIdsToSummaryCases( const std::vector<RimSummaryCase*>& summaryCases )
565+
{
566+
int nextValidId = 1;
567+
for ( RimSummaryCase* s : allSummaryCases() )
559568
{
560-
int nextValidId = 1;
561-
for ( RimSummaryCase* s : allSummaryCases() )
562-
{
563-
nextValidId = std::max( nextValidId, s->caseId() + 1 );
564-
}
569+
nextValidId = std::max( nextValidId, s->caseId() + 1 );
570+
}
565571

566-
summaryCase->setCaseId( nextValidId );
572+
for ( RimSummaryCase* summaryCase : summaryCases )
573+
{
574+
if ( summaryCase ) summaryCase->setCaseId( nextValidId++ );
567575
}
568576
}
569577

ApplicationLibCode/ProjectDataModel/RimProject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class RimProject : public caf::PdmDocument
132132
void assignViewIdToView( Rim3dView* view );
133133
void assignPlotIdToPlotWindow( RimPlotWindow* plotWindow );
134134
void assignCaseIdToSummaryCase( RimSummaryCase* summaryCase );
135+
void assignCaseIdsToSummaryCases( const std::vector<RimSummaryCase*>& summaryCases );
135136
void assignIdToEnsemble( RimSummaryEnsemble* summaryCaseCollection );
136137

137138
[[nodiscard]] std::vector<RimCase*> allGridCases() const;

ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseMainCollection.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,6 @@ std::vector<RimSummaryCase*>
755755
}
756756

757757
newSumCase->setSummaryHeaderFileName( smspecFileName );
758-
project->assignCaseIdToSummaryCase( newSumCase );
759758

760759
sumCases.push_back( newSumCase );
761760
}
@@ -772,6 +771,10 @@ std::vector<RimSummaryCase*>
772771
QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
773772
}
774773

774+
// Assign case ids for the complete set of new cases. The cases are not yet part of the project, so the ids must be
775+
// assigned in one operation to make sure they are unique. See https://github.com/OPM/ResInsight/issues/14542
776+
project->assignCaseIdsToSummaryCases( sumCases );
777+
775778
RimSummaryCaseMainCollection::loadSummaryCaseData( sumCases, readStateFromFirstFile );
776779

777780
return sumCases;

ApplicationLibCode/UnitTests/RimSummaryCaseMainCollection-Test.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
#include "RimDeltaSummaryEnsemble.h"
66
#include "RimMockSummaryCase.h"
7+
#include "RimProject.h"
78
#include "RimSummaryCaseMainCollection.h"
89
#include "RimSummaryCaseUpdateBatch.h"
910
#include "RimSummaryEnsemble.h"
1011

1112
#include "cafPdmPointer.h"
1213

1314
#include <algorithm>
15+
#include <set>
1416
#include <vector>
1517

1618
//--------------------------------------------------------------------------------------------------
@@ -71,3 +73,28 @@ TEST( RimSummaryCaseMainCollection, RemoveCases_NoDanglingInCallerVector )
7173
delete ensemble1;
7274
delete ensemble2;
7375
}
76+
77+
//--------------------------------------------------------------------------------------------------
78+
/// Summary cases are created before they are added to the project. Case ids must be assigned for the
79+
/// complete set of new cases, as cases not yet part of the project are invisible to the id search.
80+
/// https://github.com/OPM/ResInsight/issues/14542
81+
//--------------------------------------------------------------------------------------------------
82+
TEST( RimSummaryCaseMainCollection, AssignUniqueCaseIdsToCasesNotInProject )
83+
{
84+
std::vector<RimSummaryCase*> newCases = { createMockCase( 0 ), createMockCase( 1 ), createMockCase( 2 ) };
85+
86+
RimProject::current()->assignCaseIdsToSummaryCases( newCases );
87+
88+
std::set<int> caseIds;
89+
for ( auto* summaryCase : newCases )
90+
{
91+
caseIds.insert( summaryCase->caseId() );
92+
}
93+
94+
EXPECT_EQ( newCases.size(), caseIds.size() );
95+
96+
for ( auto* summaryCase : newCases )
97+
{
98+
delete summaryCase;
99+
}
100+
}

0 commit comments

Comments
 (0)