mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 22:50:25 -05:00
#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.
This commit is contained in:
1 parent
5e17f9986d
commit
6d7959d150
4 files changed
+48
-9
No files matched your search
@@ -555,15 +555,23 @@ void RimProject::setProjectFileNameAndUpdateDependencies( const QString& project
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimProject::assignCaseIdToSummaryCase( RimSummaryCase* summaryCase )
|
||||
{
|
||||
if ( summaryCase )
|
||||
{
|
||||
int nextValidId = 1;
|
||||
for ( RimSummaryCase* s : allSummaryCases() )
|
||||
{
|
||||
nextValidId = std::max( nextValidId, s->caseId() + 1 );
|
||||
}
|
||||
assignCaseIdsToSummaryCases( { summaryCase } );
|
||||
}
|
||||
|
||||
summaryCase->setCaseId( nextValidId );
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimProject::assignCaseIdsToSummaryCases( const std::vector<RimSummaryCase*>& summaryCases )
|
||||
{
|
||||
int nextValidId = 1;
|
||||
for ( RimSummaryCase* s : allSummaryCases() )
|
||||
{
|
||||
nextValidId = std::max( nextValidId, s->caseId() + 1 );
|
||||
}
|
||||
|
||||
for ( RimSummaryCase* summaryCase : summaryCases )
|
||||
{
|
||||
if ( summaryCase ) summaryCase->setCaseId( nextValidId++ );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,6 +132,7 @@ public:
|
||||
void assignViewIdToView( Rim3dView* view );
|
||||
void assignPlotIdToPlotWindow( RimPlotWindow* plotWindow );
|
||||
void assignCaseIdToSummaryCase( RimSummaryCase* summaryCase );
|
||||
void assignCaseIdsToSummaryCases( const std::vector<RimSummaryCase*>& summaryCases );
|
||||
void assignIdToEnsemble( RimSummaryEnsemble* summaryCaseCollection );
|
||||
|
||||
[[nodiscard]] std::vector<RimCase*> allGridCases() const;
|
||||
|
||||
@@ -755,7 +755,6 @@ std::vector<RimSummaryCase*>
|
||||
}
|
||||
|
||||
newSumCase->setSummaryHeaderFileName( smspecFileName );
|
||||
project->assignCaseIdToSummaryCase( newSumCase );
|
||||
|
||||
sumCases.push_back( newSumCase );
|
||||
}
|
||||
@@ -772,6 +771,10 @@ std::vector<RimSummaryCase*>
|
||||
QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
|
||||
}
|
||||
|
||||
// Assign case ids for the complete set of new cases. The cases are not yet part of the project, so the ids must be
|
||||
// assigned in one operation to make sure they are unique. See https://github.com/OPM/ResInsight/issues/14542
|
||||
project->assignCaseIdsToSummaryCases( sumCases );
|
||||
|
||||
RimSummaryCaseMainCollection::loadSummaryCaseData( sumCases, readStateFromFirstFile );
|
||||
|
||||
return sumCases;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "RimDeltaSummaryEnsemble.h"
|
||||
#include "RimMockSummaryCase.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimSummaryCaseMainCollection.h"
|
||||
#include "RimSummaryCaseUpdateBatch.h"
|
||||
#include "RimSummaryEnsemble.h"
|
||||
@@ -11,6 +12,7 @@
|
||||
#include "cafPdmPointer.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -71,3 +73,28 @@ TEST( RimSummaryCaseMainCollection, RemoveCases_NoDanglingInCallerVector )
|
||||
delete ensemble1;
|
||||
delete ensemble2;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Summary cases are created before they are added to the project. Case ids must be assigned for the
|
||||
/// complete set of new cases, as cases not yet part of the project are invisible to the id search.
|
||||
/// https://github.com/OPM/ResInsight/issues/14542
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RimSummaryCaseMainCollection, AssignUniqueCaseIdsToCasesNotInProject )
|
||||
{
|
||||
std::vector<RimSummaryCase*> newCases = { createMockCase( 0 ), createMockCase( 1 ), createMockCase( 2 ) };
|
||||
|
||||
RimProject::current()->assignCaseIdsToSummaryCases( newCases );
|
||||
|
||||
std::set<int> caseIds;
|
||||
for ( auto* summaryCase : newCases )
|
||||
{
|
||||
caseIds.insert( summaryCase->caseId() );
|
||||
}
|
||||
|
||||
EXPECT_EQ( newCases.size(), caseIds.size() );
|
||||
|
||||
for ( auto* summaryCase : newCases )
|
||||
{
|
||||
delete summaryCase;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user