mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-21 22:13:25 -06:00
38c2c9c237
* The issue is sorting on pointer address for ensembles and summary cases. Instead sort by name. * The crucial changes are in RiaSummaryCurveDefinition.cpp, RimSummaryCase and RimSummaryCaseCollection. * The rest of the changes are just fallout from changing the pure virtual method RimSummaryCase::caseName to be const. The rest just follows. * RimGridSummaryCase::caseName does alter something, but this variable was already declared mutable.
170 lines
6.4 KiB
C++
170 lines
6.4 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2017 Statoil ASA
|
|
//
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
//
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
// for more details.
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "RiaSummaryCurveDefinition.h"
|
|
|
|
#include "RifSummaryReaderInterface.h"
|
|
#include "RimSummaryCase.h"
|
|
#include "RimSummaryCaseCollection.h"
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RiaSummaryCurveDefinition::RiaSummaryCurveDefinition()
|
|
: m_summaryCase(nullptr)
|
|
, m_ensemble(nullptr)
|
|
|
|
{
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RiaSummaryCurveDefinition::RiaSummaryCurveDefinition(RimSummaryCase* summaryCase,
|
|
const RifEclipseSummaryAddress& summaryAddress,
|
|
RimSummaryCaseCollection* ensemble)
|
|
: m_summaryCase(summaryCase)
|
|
, m_ensemble(ensemble)
|
|
, m_summaryAddress(summaryAddress)
|
|
{
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimSummaryCase* RiaSummaryCurveDefinition::summaryCase() const
|
|
{
|
|
return m_summaryCase;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimSummaryCaseCollection* RiaSummaryCurveDefinition::ensemble() const
|
|
{
|
|
return m_ensemble;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
const RifEclipseSummaryAddress& RiaSummaryCurveDefinition::summaryAddress() const
|
|
{
|
|
return m_summaryAddress;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RiaSummaryCurveDefinition::isEnsembleCurve() const
|
|
{
|
|
return m_ensemble != nullptr;
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RiaSummaryCurveDefinition::resultValues(const RiaSummaryCurveDefinition& curveDefinition, std::vector<double>* values)
|
|
{
|
|
CVF_ASSERT(values);
|
|
|
|
if (!curveDefinition.summaryAddress().isValid()) return;
|
|
if (!curveDefinition.summaryCase()) return;
|
|
|
|
RifSummaryReaderInterface* reader = curveDefinition.summaryCase()->summaryReader();
|
|
if (!reader) return;
|
|
|
|
reader->values(curveDefinition.summaryAddress(), values);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
const std::vector<time_t>& RiaSummaryCurveDefinition::timeSteps(const RiaSummaryCurveDefinition& curveDefinition)
|
|
{
|
|
static std::vector<time_t> dummy;
|
|
|
|
if (!curveDefinition.summaryAddress().isValid()) return dummy;
|
|
if (!curveDefinition.summaryCase()) return dummy;
|
|
|
|
RifSummaryReaderInterface* reader = curveDefinition.summaryCase()->summaryReader();
|
|
if (!reader) return dummy;
|
|
|
|
return reader->timeSteps(curveDefinition.summaryAddress());
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QString RiaSummaryCurveDefinition::curveDefinitionText() const
|
|
{
|
|
QString caseName;
|
|
if (summaryCase() ) caseName = summaryCase()->caseName();
|
|
else if (ensemble()) caseName = ensemble()->name();
|
|
|
|
return RiaSummaryCurveDefinition::curveDefinitionText(caseName, summaryAddress());
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QString RiaSummaryCurveDefinition::curveDefinitionText(const QString& caseName, const RifEclipseSummaryAddress& summaryAddress)
|
|
{
|
|
QString txt;
|
|
|
|
txt += caseName;
|
|
txt += ", ";
|
|
|
|
txt += QString::fromStdString(summaryAddress.uiText());
|
|
|
|
return txt;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RiaSummaryCurveDefinition::operator<(const RiaSummaryCurveDefinition& other) const
|
|
{
|
|
if (m_summaryCase != other.summaryCase())
|
|
{
|
|
// Try comparing the dereferenced objects first. They have a predictable sorting operator.
|
|
if (m_summaryCase && other.summaryCase())
|
|
{
|
|
return *m_summaryCase < *other.summaryCase();
|
|
}
|
|
// Sorting by pointer address, which may appear random to the user.
|
|
return m_summaryCase < other.summaryCase();
|
|
}
|
|
|
|
if (m_ensemble != other.ensemble())
|
|
{
|
|
// Try comparing the dereferenced objects first. They have a predictable sorting operator.
|
|
if (m_ensemble && other.ensemble())
|
|
{
|
|
return *m_ensemble < *other.ensemble();
|
|
}
|
|
// Sorting by pointer address, which may appear random to the user.
|
|
return (m_ensemble < other.ensemble());
|
|
}
|
|
|
|
return (m_summaryAddress < other.summaryAddress());
|
|
}
|
|
|