mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-01 03:37:15 -06:00
Fix selection of multiple pressure/depth sources in plot
Use spaceship operator to fix issue for multiple pressure/depth curves It was not possible to show two pressure/drop curves at the same time. This was caused by inconsistent implementation of operator< and operator==. Implement operator <=> to simplify the code.
This commit is contained in:
parent
c8ebca6041
commit
40c329f3ac
@ -55,23 +55,26 @@ const QDateTime& RiaRftPltCurveDefinition::timeStep() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaRftPltCurveDefinition::operator<( const RiaRftPltCurveDefinition& other ) const
|
||||
auto RiaRftPltCurveDefinition::operator<=>( const RiaRftPltCurveDefinition& other ) const -> std::strong_ordering
|
||||
{
|
||||
if ( m_curveAddress.ensemble() != other.m_curveAddress.ensemble() )
|
||||
{
|
||||
// Sort by ensemble first, to make sure the ensemble curves are created and plotted before the single curves
|
||||
RimSummaryCaseCollection* thisEnsemble = m_curveAddress.ensemble();
|
||||
RimSummaryCaseCollection* otherEnsemble = other.m_curveAddress.ensemble();
|
||||
|
||||
if ( m_curveAddress.ensemble() ) return true;
|
||||
return false;
|
||||
if ( ( thisEnsemble && !otherEnsemble ) || ( !thisEnsemble && otherEnsemble ) )
|
||||
{
|
||||
// If one is an ensemble and the other is not, the ensemble should be first to make sure the ensemble curves are created and plotted
|
||||
// before the single summary curves
|
||||
|
||||
return m_curveAddress.ensemble() <=> other.m_curveAddress.ensemble();
|
||||
}
|
||||
|
||||
if ( m_curveAddress == other.m_curveAddress )
|
||||
if ( ( m_curveAddress <=> other.m_curveAddress ) == std::strong_ordering::equal )
|
||||
{
|
||||
if ( m_wellName == other.m_wellName )
|
||||
{
|
||||
return m_timeStep < other.m_timeStep;
|
||||
return m_timeStep.toTime_t() <=> other.m_timeStep.toTime_t();
|
||||
}
|
||||
return m_wellName < other.m_wellName;
|
||||
return m_wellName.toStdString() <=> other.m_wellName.toStdString();
|
||||
}
|
||||
return m_curveAddress < other.m_curveAddress;
|
||||
return m_curveAddress <=> other.m_curveAddress;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
const QString& wellName() const;
|
||||
const QDateTime& timeStep() const;
|
||||
|
||||
bool operator<( const RiaRftPltCurveDefinition& other ) const;
|
||||
auto operator<=>( const RiaRftPltCurveDefinition& rhs ) const -> std::strong_ordering;
|
||||
|
||||
private:
|
||||
RifDataSourceForRftPlt m_curveAddress;
|
||||
|
@ -154,6 +154,81 @@ std::vector<RiaDefines::EclipseUnitSystem> RifDataSourceForRftPlt::availableUnit
|
||||
|
||||
return systems;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
auto RifDataSourceForRftPlt::operator<=>( const RifDataSourceForRftPlt& addr2 ) const -> std::strong_ordering
|
||||
{
|
||||
if ( m_sourceType != addr2.m_sourceType )
|
||||
{
|
||||
return m_sourceType <=> addr2.m_sourceType;
|
||||
}
|
||||
|
||||
if ( m_sourceType == RifDataSourceForRftPlt::SourceType::NONE ) return std::strong_ordering::less;
|
||||
|
||||
if ( m_sourceType == RifDataSourceForRftPlt::SourceType::OBSERVED_LAS_FILE )
|
||||
{
|
||||
if ( wellLogFile() && addr2.wellLogFile() )
|
||||
{
|
||||
return wellLogFile()->fileName().toStdString() <=> addr2.wellLogFile()->fileName().toStdString();
|
||||
}
|
||||
return wellLogFile() <=> addr2.wellLogFile();
|
||||
}
|
||||
else if ( m_sourceType == RifDataSourceForRftPlt::SourceType::SUMMARY_RFT )
|
||||
{
|
||||
if ( summaryCase() && addr2.summaryCase() )
|
||||
{
|
||||
if ( summaryCase()->displayCaseName() == addr2.summaryCase()->displayCaseName() )
|
||||
{
|
||||
if ( ensemble() && addr2.ensemble() )
|
||||
{
|
||||
return ensemble()->name().toStdString() <=> addr2.ensemble()->name().toStdString();
|
||||
}
|
||||
return ensemble() <=> addr2.ensemble();
|
||||
}
|
||||
return summaryCase()->displayCaseName().toStdString() <=> addr2.summaryCase()->displayCaseName().toStdString();
|
||||
}
|
||||
return summaryCase() <=> addr2.summaryCase();
|
||||
}
|
||||
else if ( m_sourceType == RifDataSourceForRftPlt::SourceType::ENSEMBLE_RFT )
|
||||
{
|
||||
if ( ensemble() && addr2.ensemble() )
|
||||
{
|
||||
return ensemble()->name().toStdString() <=> addr2.ensemble()->name().toStdString();
|
||||
}
|
||||
return ensemble() <=> addr2.ensemble();
|
||||
}
|
||||
else if ( m_sourceType == RifDataSourceForRftPlt::SourceType::OBSERVED_FMU_RFT )
|
||||
{
|
||||
if ( observedFmuRftData() || addr2.observedFmuRftData() )
|
||||
{
|
||||
if ( observedFmuRftData() && addr2.observedFmuRftData() )
|
||||
{
|
||||
return observedFmuRftData()->name().toStdString() <=> addr2.observedFmuRftData()->name().toStdString();
|
||||
}
|
||||
return observedFmuRftData() <=> addr2.observedFmuRftData();
|
||||
}
|
||||
if ( pressureDepthData() || addr2.pressureDepthData() )
|
||||
{
|
||||
if ( pressureDepthData() && addr2.pressureDepthData() )
|
||||
{
|
||||
return pressureDepthData()->name().toStdString() <=> addr2.pressureDepthData()->name().toStdString();
|
||||
}
|
||||
return pressureDepthData() <=> addr2.pressureDepthData();
|
||||
}
|
||||
return std::strong_ordering::less;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( eclCase() && addr2.eclCase() )
|
||||
{
|
||||
return eclCase()->caseId() <=> addr2.eclCase()->caseId();
|
||||
}
|
||||
return eclCase() <=> addr2.eclCase();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -248,16 +323,6 @@ QString RifDataSourceForRftPlt::sourceTypeUiText( SourceType sourceType )
|
||||
return QString();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool operator==( const RifDataSourceForRftPlt& addr1, const RifDataSourceForRftPlt& addr2 )
|
||||
{
|
||||
return addr1.sourceType() == addr2.sourceType() && addr1.eclCase() == addr2.eclCase() && addr1.wellLogFile() == addr2.wellLogFile() &&
|
||||
addr1.summaryCase() == addr2.summaryCase() && addr1.ensemble() == addr2.ensemble() &&
|
||||
addr1.observedFmuRftData() == addr2.observedFmuRftData();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -277,79 +342,3 @@ QTextStream& operator>>( QTextStream& str, RifDataSourceForRftPlt& source )
|
||||
CVF_ASSERT( false );
|
||||
return str;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// This sort order controls the plot order in PLT plot. (Layer-wise)
|
||||
/// Observed data is supposed to be the bottom layers (first)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool operator<( const RifDataSourceForRftPlt& addr1, const RifDataSourceForRftPlt& addr2 )
|
||||
{
|
||||
if ( addr1.m_sourceType != addr2.m_sourceType )
|
||||
{
|
||||
return addr1.m_sourceType < addr2.m_sourceType;
|
||||
}
|
||||
|
||||
if ( addr1.m_sourceType == RifDataSourceForRftPlt::SourceType::NONE ) return false; //
|
||||
|
||||
if ( addr1.m_sourceType == RifDataSourceForRftPlt::SourceType::OBSERVED_LAS_FILE )
|
||||
{
|
||||
if ( addr1.wellLogFile() && addr2.wellLogFile() )
|
||||
{
|
||||
return addr1.wellLogFile()->fileName() < addr2.wellLogFile()->fileName();
|
||||
}
|
||||
return addr1.wellLogFile() < addr2.wellLogFile();
|
||||
}
|
||||
else if ( addr1.m_sourceType == RifDataSourceForRftPlt::SourceType::SUMMARY_RFT )
|
||||
{
|
||||
if ( addr1.summaryCase() && addr2.summaryCase() )
|
||||
{
|
||||
if ( addr1.summaryCase()->displayCaseName() == addr2.summaryCase()->displayCaseName() )
|
||||
{
|
||||
if ( addr1.ensemble() && addr2.ensemble() )
|
||||
{
|
||||
return addr1.ensemble()->name() < addr2.ensemble()->name();
|
||||
}
|
||||
return addr1.ensemble() < addr2.ensemble();
|
||||
}
|
||||
return addr1.summaryCase()->displayCaseName() < addr2.summaryCase()->displayCaseName();
|
||||
}
|
||||
return addr1.summaryCase() < addr2.summaryCase();
|
||||
}
|
||||
else if ( addr1.m_sourceType == RifDataSourceForRftPlt::SourceType::ENSEMBLE_RFT )
|
||||
{
|
||||
if ( addr1.ensemble() && addr2.ensemble() )
|
||||
{
|
||||
return addr1.ensemble()->name() < addr2.ensemble()->name();
|
||||
}
|
||||
return addr1.ensemble() < addr2.ensemble();
|
||||
}
|
||||
else if ( addr1.m_sourceType == RifDataSourceForRftPlt::SourceType::OBSERVED_FMU_RFT )
|
||||
{
|
||||
if ( addr1.observedFmuRftData() && addr2.observedFmuRftData() )
|
||||
{
|
||||
return addr1.observedFmuRftData()->name() < addr2.observedFmuRftData()->name();
|
||||
}
|
||||
return addr1.observedFmuRftData() < addr2.observedFmuRftData();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( addr1.eclCase() && addr2.eclCase() )
|
||||
{
|
||||
return addr1.eclCase()->caseId() < addr2.eclCase()->caseId();
|
||||
}
|
||||
return addr1.eclCase() < addr2.eclCase();
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool operator<(const RifWellRftAddress& addr1, const RifWellRftAddress& addr2)
|
||||
{
|
||||
return (addr1.m_sourceType < addr2.m_sourceType) ||
|
||||
(addr1.m_sourceType == addr2.m_sourceType &&
|
||||
addr1.eclCase() != nullptr && addr2.eclCase() != nullptr ? addr1.eclCase()->caseId() < addr2.eclCase()->caseId() :
|
||||
addr1.wellLogFile() != nullptr && addr2.wellLogFile() != nullptr ? addr1.wellLogFile()->fileName() < addr2.wellLogFile()->fileName() :
|
||||
addr1.wellLogFile() < addr2.wellLogFile());
|
||||
}
|
||||
#endif
|
||||
|
@ -79,7 +79,12 @@ public:
|
||||
std::vector<RiaDefines::EclipseUnitSystem> availableUnitSystems() const;
|
||||
|
||||
friend QTextStream& operator>>( QTextStream& str, RifDataSourceForRftPlt& addr );
|
||||
friend bool operator<( const RifDataSourceForRftPlt& addr1, const RifDataSourceForRftPlt& addr2 );
|
||||
|
||||
auto operator<=>( const RifDataSourceForRftPlt& rhs ) const -> std::strong_ordering;
|
||||
|
||||
// When operator<=>() is overloaded, no operator==() nor operator!=() are defined by default by the compiler
|
||||
// https://ggulgulia.medium.com/c-20-three-way-comparison-operator-part-2-fd520fb75e00
|
||||
bool operator==( const RifDataSourceForRftPlt& rhs ) const = default;
|
||||
|
||||
private:
|
||||
SourceType m_sourceType;
|
||||
@ -92,7 +97,5 @@ private:
|
||||
caf::PdmPointer<RimPressureDepthData> m_pressureDepthData;
|
||||
};
|
||||
|
||||
bool operator==( const RifDataSourceForRftPlt& addr1, const RifDataSourceForRftPlt& addr2 );
|
||||
QTextStream& operator<<( QTextStream& str, const RifDataSourceForRftPlt& addr );
|
||||
QTextStream& operator>>( QTextStream& str, RifDataSourceForRftPlt& addr );
|
||||
bool operator<( const RifDataSourceForRftPlt& addr1, const RifDataSourceForRftPlt& addr2 );
|
||||
|
Loading…
Reference in New Issue
Block a user