From d9973743ee6703ebeec6e4c0040f949d9ab1a59c Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Sat, 6 Aug 2016 08:44:49 +0200 Subject: [PATCH] #272 Improved meta data for custom cell edge results --- .../ProjectDataModel/RimCellEdgeColors.cpp | 90 +++++++++++++++---- .../ProjectDataModel/RimCellEdgeColors.h | 18 +++- .../ProjectDataModel/RimEclipseCase.cpp | 4 +- .../RimEclipseResultDefinition.cpp | 23 ++++- .../ProjectDataModel/RimEclipseView.cpp | 2 +- .../RimIdenticalGridCaseGroup.cpp | 2 +- .../UserInterface/RiuResultTextBuilder.cpp | 26 ++++-- 7 files changed, 133 insertions(+), 32 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimCellEdgeColors.cpp b/ApplicationCode/ProjectDataModel/RimCellEdgeColors.cpp index 41042e5122..a40db810e7 100644 --- a/ApplicationCode/ProjectDataModel/RimCellEdgeColors.cpp +++ b/ApplicationCode/ProjectDataModel/RimCellEdgeColors.cpp @@ -28,6 +28,8 @@ #include "RimReservoirCellResultsStorage.h" #include "cafPdmUiListEditor.h" +#include "cafPdmUiTreeOrdering.h" + #include "cvfMath.h" @@ -41,21 +43,18 @@ RimCellEdgeColors::RimCellEdgeColors() CAF_PDM_InitObject("Cell Edge Result", ":/EdgeResult_1.png", "", ""); CAF_PDM_InitField(&enableCellEdgeColors, "EnableCellEdgeColors", true, "Enable cell edge results", "", "", ""); - enableCellEdgeColors.uiCapability()->setUiHidden(true); - CAF_PDM_InitFieldNoDefault(&resultVariable, "CellEdgeVariable", "Result property", "", "", ""); + CAF_PDM_InitFieldNoDefault(&m_resultVariable, "CellEdgeVariable", "Result property", "", "", ""); CAF_PDM_InitField(&useXVariable, "UseXVariable", true, "Use X values", "", "", ""); CAF_PDM_InitField(&useYVariable, "UseYVariable", true, "Use Y values", "", "", ""); CAF_PDM_InitField(&useZVariable, "UseZVariable", true, "Use Z values", "", "", ""); CAF_PDM_InitFieldNoDefault(&legendConfig, "LegendDefinition", "Legend Definition", ":/Legend.png", "", ""); - legendConfig.uiCapability()->setUiHidden(true); CAF_PDM_InitFieldNoDefault(&m_customFaultResultColors, "CustomEdgeResult", "Custom Edge Result", ":/CellResult.png", "", ""); m_customFaultResultColors = new RimEclipseCellColors(); - m_customFaultResultColors.uiCapability()->setUiHidden(true); - resultVariable.uiCapability()->setUiEditorTypeName(caf::PdmUiListEditor::uiEditorTypeName()); + m_resultVariable.uiCapability()->setUiEditorTypeName(caf::PdmUiListEditor::uiEditorTypeName()); legendConfig = new RimLegendConfig(); @@ -89,9 +88,9 @@ void RimCellEdgeColors::loadResult() { CVF_ASSERT(m_reservoirView && m_reservoirView->currentGridCellResults()); - if (resultVariable == RimCellEdgeColors::customEdgeResultUiText()) + if (m_resultVariable == RimCellEdgeColors::customEdgeResultUiText()) { - size_t resultindex = m_reservoirView->currentGridCellResults()->findOrLoadScalarResult(RimDefines::STATIC_NATIVE, m_customFaultResultColors->resultVariable()); + size_t resultindex = m_reservoirView->currentGridCellResults()->findOrLoadScalarResult(m_customFaultResultColors->resultType(), m_customFaultResultColors->resultVariable()); for (int cubeFaceIdx = 0; cubeFaceIdx < 6; ++cubeFaceIdx) { @@ -172,7 +171,7 @@ namespace caf QList RimCellEdgeColors::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) { - if (fieldNeedingOptions == &resultVariable) + if (fieldNeedingOptions == &m_resultVariable) { if (m_reservoirView && m_reservoirView->currentGridCellResults()) { @@ -251,9 +250,9 @@ QList RimCellEdgeColors::calculateValueOptions(const caf //-------------------------------------------------------------------------------------------------- void RimCellEdgeColors::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) { - uiOrdering.add(&resultVariable); + uiOrdering.add(&m_resultVariable); - if (resultVariable().compare(RimCellEdgeColors::customEdgeResultUiText()) == 0) + if (m_resultVariable().compare(RimCellEdgeColors::customEdgeResultUiText()) == 0) { caf::PdmUiGroup* group1 = uiOrdering.addNewGroup("Custom Edge Result"); group1->add(&(m_customFaultResultColors->m_resultTypeUiField)); @@ -267,7 +266,16 @@ void RimCellEdgeColors::defineUiOrdering(QString uiConfigName, caf::PdmUiOrderin uiOrdering.add(&useZVariable); } - uiOrdering.forgetRemainingFields(); + uiOrdering.setForgetRemainingFields(true); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCellEdgeColors::defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName /*= ""*/) +{ + uiTreeOrdering.add(legendConfig()); + uiTreeOrdering.setForgetRemainingFields(true); } //-------------------------------------------------------------------------------------------------- @@ -277,7 +285,7 @@ QStringList RimCellEdgeColors::findResultVariableNames() { QStringList varNames; - if (m_reservoirView && m_reservoirView->currentGridCellResults() && !resultVariable().isEmpty()) + if (m_reservoirView && m_reservoirView->currentGridCellResults() && !m_resultVariable().isEmpty()) { QStringList varList; varList = m_reservoirView->currentGridCellResults()->cellResults()->resultNames(RimDefines::STATIC_NATIVE); @@ -288,7 +296,7 @@ QStringList RimCellEdgeColors::findResultVariableNames() { if (RimDefines::isPerCellFaceResult(varList[i])) continue; - if (varList[i].startsWith(resultVariable)) + if (varList[i].startsWith(m_resultVariable)) { varNames.append(varList[i]); } @@ -314,7 +322,7 @@ void RimCellEdgeColors::gridScalarIndices(size_t resultIndices[6]) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimCellEdgeColors::gridScalarResultNames(QStringList* resultNames) +void RimCellEdgeColors::gridScalarResultNames(std::vector* resultNames) { CVF_ASSERT(resultNames); @@ -323,7 +331,36 @@ void RimCellEdgeColors::gridScalarResultNames(QStringList* resultNames) { resultNames->push_back(m_resultNameToIndexPairs[cubeFaceIndex].first); } +} +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCellEdgeColors::cellEdgeMetaData(std::vector* metaDataVector) +{ + CVF_ASSERT(metaDataVector); + + size_t resultIndices[6]; + this->gridScalarIndices(resultIndices); + + std::vector resultNames; + this->gridScalarResultNames(&resultNames); + + bool isStatic = true; + if (m_resultVariable == RimCellEdgeColors::customEdgeResultUiText()) + { + isStatic = m_customFaultResultColors->resultType() == RimDefines::STATIC_NATIVE; + } + + for (size_t i = 0; i < 6; i++) + { + RimCellEdgeMetaData metaData; + metaData.m_resultIndex = resultIndices[i]; + metaData.m_resultVariable = resultNames[i]; + metaData.m_isStatic = isStatic; + + metaDataVector->push_back(metaData); + } } //-------------------------------------------------------------------------------------------------- @@ -368,7 +405,7 @@ bool RimCellEdgeColors::hasResult() const //-------------------------------------------------------------------------------------------------- void RimCellEdgeColors::updateIgnoredScalarValue() { - if (resultVariable == "MULT" || resultVariable == "riMULT") + if (m_resultVariable == "MULT" || m_resultVariable == "riMULT") { m_ignoredResultScalar = 1.0; } @@ -443,6 +480,29 @@ void RimCellEdgeColors::setEclipseCase(RimEclipseCase* eclipseCase) m_customFaultResultColors->setEclipseCase(eclipseCase); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCellEdgeColors::setResultVariable(const QString& variableName) +{ + m_resultVariable = variableName; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimCellEdgeColors::resultVariable() const +{ + if (m_resultVariable == RimCellEdgeColors::customEdgeResultUiText()) + { + return m_customFaultResultColors->resultVariable(); + } + else + { + return m_resultVariable; + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimCellEdgeColors.h b/ApplicationCode/ProjectDataModel/RimCellEdgeColors.h index f3e93b003d..24e7a76ae1 100644 --- a/ApplicationCode/ProjectDataModel/RimCellEdgeColors.h +++ b/ApplicationCode/ProjectDataModel/RimCellEdgeColors.h @@ -34,6 +34,14 @@ class RimEclipseCellColors; class RimEclipseView; class RimLegendConfig; +class RimCellEdgeMetaData +{ +public: + size_t m_resultIndex; + QString m_resultVariable; + bool m_isStatic; +}; + //================================================================================================== /// /// @@ -57,13 +65,16 @@ public: void setReservoirView(RimEclipseView* ownerReservoirView); void setEclipseCase(RimEclipseCase* eclipseCase); - caf::PdmField resultVariable; + void setResultVariable(const QString& variableName); + QString resultVariable() const; + caf::PdmField enableCellEdgeColors; caf::PdmChildField legendConfig; double ignoredScalarValue() { return m_ignoredResultScalar; } void gridScalarIndices(size_t resultIndices[6]); - void gridScalarResultNames(QStringList* resultNames); + void cellEdgeMetaData(std::vector* metaData); + void loadResult(); bool hasResult() const; @@ -75,6 +86,7 @@ protected: virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue); virtual QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly ); virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering); + virtual void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = ""); QStringList findResultVariableNames(); @@ -84,10 +96,12 @@ private: void resetResultIndices(); void updateIgnoredScalarValue(); + void gridScalarResultNames(std::vector* resultNames); static QString customEdgeResultUiText() { return "Custom Edge Result"; } virtual caf::PdmFieldHandle* objectToggleField(); + caf::PdmField m_resultVariable; caf::PdmField useXVariable; caf::PdmField useYVariable; caf::PdmField useZVariable; diff --git a/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp b/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp index 511b5f09f8..e774a2fa46 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp @@ -157,7 +157,7 @@ RimEclipseView* RimEclipseCase::createAndAddReservoirView() { RimEclipseView* riv = new RimEclipseView(); riv->setEclipseCase(this); - riv->cellEdgeResult()->resultVariable = "MULT"; + riv->cellEdgeResult()->setResultVariable("MULT"); riv->cellEdgeResult()->enableCellEdgeColors = false; caf::PdmDocument::updateUiIconStateRecursively(riv); @@ -243,7 +243,7 @@ void RimEclipseCase::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c RimCellEdgeColors* cellEdgeResult = reservoirView->cellEdgeResult; CVF_ASSERT(cellEdgeResult); - cellEdgeResult->resultVariable.v() = RimDefines::undefinedResultName(); + cellEdgeResult->setResultVariable(RimDefines::undefinedResultName()); cellEdgeResult->loadResult(); reservoirView->createDisplayModelAndRedraw(); diff --git a/ApplicationCode/ProjectDataModel/RimEclipseResultDefinition.cpp b/ApplicationCode/ProjectDataModel/RimEclipseResultDefinition.cpp index cf1a29e0bc..337d0cac2f 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseResultDefinition.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseResultDefinition.cpp @@ -132,6 +132,9 @@ void RimEclipseResultDefinition::fieldChangedByUi(const caf::PdmFieldHandle* cha RimWellLogCurve* curve = NULL; this->firstAnchestorOrThisOfType(curve); + RimCellEdgeColors* cellEdgeColors = NULL; + this->firstAnchestorOrThisOfType(cellEdgeColors); + if (&m_resultVariableUiField == changedField) { m_porosityModel = m_porosityModelUiField; @@ -164,6 +167,16 @@ void RimEclipseResultDefinition::fieldChangedByUi(const caf::PdmFieldHandle* cha } } + if (cellEdgeColors) + { + cellEdgeColors->loadResult(); + + if (view) + { + view->scheduleCreateDisplayModelAndRedraw(); + } + } + if (curve) { curve->updatePlotData(); @@ -181,7 +194,6 @@ void RimEclipseResultDefinition::fieldChangedByUi(const caf::PdmFieldHandle* cha faultColors->updateConnectedEditors(); } - RimCellEdgeColors* cellEdgeColors = dynamic_cast(this->parentField()->ownerObject()); if (cellEdgeColors) { cellEdgeColors->updateConnectedEditors(); @@ -210,8 +222,13 @@ QList RimEclipseResultDefinition::calculateValueOptions( RimWellLogCurve* curve = NULL; this->firstAnchestorOrThisOfType(curve); - RimEclipsePropertyFilter* propFilter = dynamic_cast(this->parentField()->ownerObject()); - if (propFilter || curve) + RimEclipsePropertyFilter* propFilter = NULL; + this->firstAnchestorOrThisOfType(propFilter); + + RimCellEdgeColors* cellEdge = NULL; + this->firstAnchestorOrThisOfType(cellEdge); + + if (propFilter || curve || cellEdge) { removePerCellFaceOptionItems(optionItems); } diff --git a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp index 383a49b14b..af345d0980 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp @@ -943,7 +943,7 @@ void RimEclipseView::updateLegends() this->cellEdgeResult()->legendConfig->setAutomaticRanges(globalMin, globalMax, globalMin, globalMax); m_viewer->addColorLegendToBottomLeftCorner(this->cellEdgeResult()->legendConfig->legend()); - this->cellEdgeResult()->legendConfig->legend()->setTitle(cvfqt::Utils::toString(QString("Edge Results: \n") + this->cellEdgeResult()->resultVariable)); + this->cellEdgeResult()->legendConfig->legend()->setTitle(cvfqt::Utils::toString(QString("Edge Results: \n") + this->cellEdgeResult()->resultVariable())); } else { diff --git a/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp b/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp index 2631f77305..7d777bf6c7 100644 --- a/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp +++ b/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp @@ -428,7 +428,7 @@ void RimIdenticalGridCaseGroup::clearStatisticsResults() { RimEclipseView* rimReservoirView = rimStaticsCase->reservoirViews[j]; rimReservoirView->cellResult()->setResultVariable(RimDefines::undefinedResultName()); - rimReservoirView->cellEdgeResult()->resultVariable = RimDefines::undefinedResultName(); + rimReservoirView->cellEdgeResult()->setResultVariable(RimDefines::undefinedResultName()); rimReservoirView->loadDataAndUpdate(); } } diff --git a/ApplicationCode/UserInterface/RiuResultTextBuilder.cpp b/ApplicationCode/UserInterface/RiuResultTextBuilder.cpp index 69eda45ffd..87365b9634 100644 --- a/ApplicationCode/UserInterface/RiuResultTextBuilder.cpp +++ b/ApplicationCode/UserInterface/RiuResultTextBuilder.cpp @@ -463,23 +463,33 @@ QString RiuResultTextBuilder::cellEdgeResultDetails() if (m_reservoirView->cellEdgeResult()->hasResult()) { - size_t resultIndices[6]; - QStringList resultNames; - m_reservoirView->cellEdgeResult()->gridScalarIndices(resultIndices); - m_reservoirView->cellEdgeResult()->gridScalarResultNames(&resultNames); + std::vector metaData; + m_reservoirView->cellEdgeResult()->cellEdgeMetaData(&metaData); + + std::set uniqueResultIndices; text += "-- Cell edge result data --\n"; for (int idx = 0; idx < 6; idx++) { - if (resultIndices[idx] == cvf::UNDEFINED_SIZE_T) continue; + size_t resultIndex = metaData[idx].m_resultIndex; + if (resultIndex == cvf::UNDEFINED_SIZE_T) continue; + + if (uniqueResultIndices.find(resultIndex) != uniqueResultIndices.end()) continue; + + size_t adjustedTimeStep = m_timeStepIndex; + if (metaData[idx].m_isStatic) + { + adjustedTimeStep = 0; + } - // Cell edge results are static, results are loaded for first time step only RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(m_reservoirView->cellResult()->porosityModel()); - cvf::ref resultAccessor = RigResultAccessorFactory::createResultAccessor(m_reservoirView->eclipseCase()->reservoirData(), m_gridIndex, porosityModel, 0, resultIndices[idx]); + cvf::ref resultAccessor = RigResultAccessorFactory::createResultAccessor(m_reservoirView->eclipseCase()->reservoirData(), m_gridIndex, porosityModel, adjustedTimeStep, resultIndex); if (resultAccessor.notNull()) { double scalarValue = resultAccessor->cellScalar(m_cellIndex); - text.append(QString("%1 : %2\n").arg(resultNames[idx]).arg(scalarValue)); + text.append(QString("%1 : %2\n").arg(metaData[idx].m_resultVariable).arg(scalarValue)); + + uniqueResultIndices.insert(resultIndex); } } }