From 46bad03c4a14dbd4b1675249c97a54b10e13d243 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 8 Dec 2017 10:23:36 +0100 Subject: [PATCH] #2127 Clamp sim well branch index to valid range --- .../Tools/RiaSimWellBranchTools.cpp | 20 +++++++++++++++++++ .../Application/Tools/RiaSimWellBranchTools.h | 13 +++++++----- .../ProjectDataModel/Flow/RimWellRftPlot.cpp | 3 +++ .../RimWellLogExtractionCurve.cpp | 9 ++++----- .../ProjectDataModel/RimWellLogRftCurve.cpp | 4 ++++ .../ProjectDataModel/RimWellLogTrack.cpp | 2 ++ 6 files changed, 41 insertions(+), 10 deletions(-) diff --git a/ApplicationCode/Application/Tools/RiaSimWellBranchTools.cpp b/ApplicationCode/Application/Tools/RiaSimWellBranchTools.cpp index 94e69c3644..a9dde4266b 100644 --- a/ApplicationCode/Application/Tools/RiaSimWellBranchTools.cpp +++ b/ApplicationCode/Application/Tools/RiaSimWellBranchTools.cpp @@ -106,3 +106,23 @@ void RiaSimWellBranchTools::appendSimWellBranchFieldsIfRequiredFromSimWellName(c } } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +int RiaSimWellBranchTools::clampBranchIndex(const QString& simWellName, int branchIndexValue, bool branchDetection) +{ + auto branches = RiaSimWellBranchTools::simulationWellBranches(simWellName, branchDetection); + + if (branches.size() == 0) + { + return -1; + } + + if (branchIndexValue >= branches.size()) + { + branchIndexValue = static_cast(branches.size()) - 1; + } + + return branchIndexValue; +} diff --git a/ApplicationCode/Application/Tools/RiaSimWellBranchTools.h b/ApplicationCode/Application/Tools/RiaSimWellBranchTools.h index ea0cd58f5e..14e318704b 100644 --- a/ApplicationCode/Application/Tools/RiaSimWellBranchTools.h +++ b/ApplicationCode/Application/Tools/RiaSimWellBranchTools.h @@ -44,11 +44,14 @@ public: static QList valueOptionsForBranchIndexField(const std::vector& simulationWellPaths); - static void appendSimWellBranchFieldsIfRequiredFromWellName(caf::PdmUiOrdering* uiOrdering, const QString& wellPathOrSimWellName, - const caf::PdmField& branchDetectionField, - const caf::PdmField& branchIndexField); + static void appendSimWellBranchFieldsIfRequiredFromWellName(caf::PdmUiOrdering* uiOrdering, + const QString& wellPathOrSimWellName, + const caf::PdmField& branchDetectionField, + const caf::PdmField& branchIndexField); static void appendSimWellBranchFieldsIfRequiredFromSimWellName(caf::PdmUiOrdering* uiOrdering, const QString& simWellName, - const caf::PdmField& branchDetectionField, - const caf::PdmField& branchIndexField); + const caf::PdmField& branchDetectionField, + const caf::PdmField& branchIndexField); + + static int clampBranchIndex(const QString& simWellName, int branchIndexValue, bool branchDetection); }; diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.cpp index 386f7b7d52..ffd5e8b502 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.cpp @@ -704,6 +704,9 @@ void RimWellRftPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c else if (changedField == &m_branchIndex || changedField == &m_branchDetection) { + const QString simWellName = associatedSimWellName(); + m_branchIndex = RiaSimWellBranchTools::clampBranchIndex(simWellName, m_branchIndex, m_branchDetection); + updateFormationsOnPlot(); syncCurvesFromUiSelection(); diff --git a/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.cpp b/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.cpp index 85e8c5683e..24f8822ecf 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.cpp @@ -581,12 +581,11 @@ void RimWellLogExtractionCurve::defineUiOrdering(QString uiConfigName, caf::PdmU else { curveDataGroup->add(&m_simWellName); - curveDataGroup->add(&m_branchDetection); - if ( simulationWellBranches().size() > 1 ) - { - curveDataGroup->add(&m_branchIndex); - } + RiaSimWellBranchTools::appendSimWellBranchFieldsIfRequiredFromSimWellName(curveDataGroup, + m_simWellName, + m_branchDetection, + m_branchIndex); } if (eclipseCase) diff --git a/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.cpp b/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.cpp index 88733d59ff..dd412385e9 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.cpp @@ -467,6 +467,10 @@ void RimWellLogRftCurve::fieldChangedByUi(const caf::PdmFieldHandle* changedFiel else if (changedField == &m_branchDetection || changedField == &m_branchIndex) { + QString simWellName = RimWellPlotTools::simWellName(m_wellName); + + m_branchIndex = RiaSimWellBranchTools::clampBranchIndex(simWellName, m_branchIndex, m_branchDetection); + updateWellChannelNameAndTimeStep(); this->loadDataAndUpdate(true); } diff --git a/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp b/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp index a10fc5504a..7a684baab5 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp @@ -281,6 +281,8 @@ void RimWellLogTrack::fieldChangedByUi(const caf::PdmFieldHandle* changedField, else if (changedField == &m_formationBranchIndex || changedField == &m_formationBranchDetection) { + m_formationBranchIndex = RiaSimWellBranchTools::clampBranchIndex(m_formationSimWellName, m_formationBranchIndex, m_formationBranchDetection); + loadDataAndUpdate(); } }