From 9449bbff20a797d45a86c84bd0926e9810cd324e Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 16 Oct 2017 22:04:00 +0200 Subject: [PATCH] #1977 Curve Calculator : Get summary values from summary reader --- .../Application/RiaSummaryCurveDefinition.cpp | 19 +++++++ .../Application/RiaSummaryCurveDefinition.h | 4 ++ .../ProjectDataModel/RimCalculation.cpp | 50 ++++++++++++++++--- .../RimCalculationVariable.cpp | 16 ++++++ .../ProjectDataModel/RimCalculationVariable.h | 3 ++ 5 files changed, 86 insertions(+), 6 deletions(-) diff --git a/ApplicationCode/Application/RiaSummaryCurveDefinition.cpp b/ApplicationCode/Application/RiaSummaryCurveDefinition.cpp index b94f6066b5..8558d8457a 100644 --- a/ApplicationCode/Application/RiaSummaryCurveDefinition.cpp +++ b/ApplicationCode/Application/RiaSummaryCurveDefinition.cpp @@ -18,6 +18,9 @@ #include "RiaSummaryCurveDefinition.h" +#include "RifSummaryReaderInterface.h" +#include "RimSummaryCase.h" + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -42,6 +45,22 @@ const RifEclipseSummaryAddress& RiaSummaryCurveDefinition::summaryAddress() cons return m_curveDefinition.second; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaSummaryCurveDefinition::resultValues(const RiaSummaryCurveDefinition& curveDefinition, std::vector* 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); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Application/RiaSummaryCurveDefinition.h b/ApplicationCode/Application/RiaSummaryCurveDefinition.h index 5e81022c41..24c51a2e8d 100644 --- a/ApplicationCode/Application/RiaSummaryCurveDefinition.h +++ b/ApplicationCode/Application/RiaSummaryCurveDefinition.h @@ -21,6 +21,7 @@ #include "RifEclipseSummaryAddress.h" #include +#include class RimSummaryCase; @@ -37,6 +38,9 @@ public: bool operator < (const RiaSummaryCurveDefinition& other) const; + // TODO: Consider moving to a separate tools class + static void resultValues(const RiaSummaryCurveDefinition& curveDefinition, std::vector* values); + private: std::pair m_curveDefinition; }; diff --git a/ApplicationCode/ProjectDataModel/RimCalculation.cpp b/ApplicationCode/ProjectDataModel/RimCalculation.cpp index 45b538d188..61108dde95 100644 --- a/ApplicationCode/ProjectDataModel/RimCalculation.cpp +++ b/ApplicationCode/ProjectDataModel/RimCalculation.cpp @@ -21,12 +21,15 @@ #include "expressionparser/ExpressionParser.h" #include "RiaLogging.h" +#include "RiaSummaryCurveDefinition.h" + #include "RimCalculationVariable.h" +#include "RimSummaryCurve.h" #include "cafPdmUiTextEditor.h" -#include #include +#include CAF_PDM_SOURCE_INIT(RimCalculation, "RimCalculation"); @@ -173,15 +176,50 @@ bool RimCalculation::calculate() ExpressionParser parser; - std::vector a(10); - std::iota(a.begin(), a.end(), 0); + std::vector> variableValues; + variableValues.resize(m_variables.size()); size_t itemCount = 0; - for (RimCalculationVariable* v : m_variables) + for (size_t i = 0; i < m_variables.size(); i++) { - itemCount = a.size(); - parser.assignVector(v->name(), a); + RimCalculationVariable* v = m_variables[i]; + + if (!v->summaryCase()) + { + RiaLogging::error("No summary case defined."); + + return false; + } + + if (!v->summaryAddress()) + { + RiaLogging::error("No summary address defined."); + + return false; + } + + RimSummaryAddress* sumAdr = v->summaryAddress(); + RiaSummaryCurveDefinition curveDef(v->summaryCase(), v->summaryAddress()->address()); + + std::vector& curveValues = variableValues[i]; + RiaSummaryCurveDefinition::resultValues(curveDef, &curveValues); + + if (itemCount == 0) + { + itemCount = curveValues.size(); + } + else + { + if (itemCount != curveValues.size()) + { + RiaLogging::error("Not able to evaluate expression varying vector size."); + + return false; + } + } + + parser.assignVector(v->name(), curveValues); } if (itemCount == 0) diff --git a/ApplicationCode/ProjectDataModel/RimCalculationVariable.cpp b/ApplicationCode/ProjectDataModel/RimCalculationVariable.cpp index bf5fe4f664..039de78b53 100644 --- a/ApplicationCode/ProjectDataModel/RimCalculationVariable.cpp +++ b/ApplicationCode/ProjectDataModel/RimCalculationVariable.cpp @@ -145,6 +145,22 @@ QString RimCalculationVariable::summaryAddressDisplayString() const return txt; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimSummaryCase* RimCalculationVariable::summaryCase() +{ + return m_case(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimSummaryAddress* RimCalculationVariable::summaryAddress() +{ + return m_summaryAddress(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimCalculationVariable.h b/ApplicationCode/ProjectDataModel/RimCalculationVariable.h index 56a9c33f6a..362b51b17c 100644 --- a/ApplicationCode/ProjectDataModel/RimCalculationVariable.h +++ b/ApplicationCode/ProjectDataModel/RimCalculationVariable.h @@ -45,6 +45,9 @@ public: QString summaryAddressDisplayString() const; + RimSummaryCase* summaryCase(); + RimSummaryAddress* summaryAddress(); + private: virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;