From b3e845ed5efc12df6146336baa1b26bed9bf4cad Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 10 Feb 2017 18:53:14 +0100 Subject: [PATCH] #1178 Use well colors for Max Fraction Tracer --- .../Flow/RimFlowDiagSolution.cpp | 28 +++++++++++++++---- .../ProjectDataModel/RimEclipseCellColors.cpp | 11 +++++++- .../ProjectDataModel/RimLegendConfig.cpp | 25 ++++++++++++++++- .../ProjectDataModel/RimLegendConfig.h | 2 ++ 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/Flow/RimFlowDiagSolution.cpp b/ApplicationCode/ProjectDataModel/Flow/RimFlowDiagSolution.cpp index 12882e5f1f..673989e841 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimFlowDiagSolution.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimFlowDiagSolution.cpp @@ -18,6 +18,7 @@ #include "RimFlowDiagSolution.h" +#include "RiaApplication.h" #include "RiaColorTables.h" #include "RigActiveCellInfo.h" @@ -28,6 +29,7 @@ #include "RigSingleWellResultsData.h" #include "RimEclipseResultCase.h" +#include "RimEclipseWell.h" #include "RimEclipseWellCollection.h" CAF_PDM_SOURCE_INIT(RimFlowDiagSolution, "FlowDiagSolution"); @@ -283,15 +285,29 @@ cvf::Color3f RimFlowDiagSolution::tracerColor(QString tracerName) if ( eclCase ) { - const cvf::Collection& wellResults = eclCase->reservoirData()->wellResults(); + RimEclipseView* activeView = dynamic_cast(RiaApplication::instance()->activeReservoirView()); - const caf::ColorTable& colorTable = RiaColorTables::wellsPaletteColors(); - - for ( size_t wIdx = 0; wIdx < wellResults.size(); ++wIdx ) + if (activeView) { - if ( wellResults[wIdx]->m_wellName == tracerName ) + RimEclipseWell* well = activeView->wellCollection->findWell(tracerName); + if (well) { - return colorTable.cycledColor3f(wIdx); + return well->wellPipeColor(); + } + } + else + { + // If we do not find a well color, use index in well result data to be able to get variation of tracer colors + // This can be the case if we do not have any views at all + + const cvf::Collection& wellResults = eclCase->reservoirData()->wellResults(); + + for ( size_t wIdx = 0; wIdx < wellResults.size(); ++wIdx ) + { + if ( wellResults[wIdx]->m_wellName == tracerName ) + { + return RiaColorTables::wellsPaletteColors().cycledColor3f(wIdx); + } } } } diff --git a/ApplicationCode/ProjectDataModel/RimEclipseCellColors.cpp b/ApplicationCode/ProjectDataModel/RimEclipseCellColors.cpp index f861d5d880..6fb5cd646c 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseCellColors.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseCellColors.cpp @@ -281,7 +281,16 @@ void RimEclipseCellColors::updateLegendData(size_t currentTimeStep) if (this->hasCategoryResult()) { - this->legendConfig()->setNamedCategories(this->flowDiagSolution()->tracerNames()); + std::vector categoryColors; + + std::vector tracerNames = this->flowDiagSolution()->tracerNames(); + for (const auto& tracerName : tracerNames) + { + categoryColors.push_back(cvf::Color3ub(this->flowDiagSolution()->tracerColor(tracerName))); + } + + this->legendConfig()->setNamedCategories(tracerNames); + this->legendConfig()->setCategoryColors(categoryColors); } } else diff --git a/ApplicationCode/ProjectDataModel/RimLegendConfig.cpp b/ApplicationCode/ProjectDataModel/RimLegendConfig.cpp index e8dbcc588d..dfa427e675 100644 --- a/ApplicationCode/ProjectDataModel/RimLegendConfig.cpp +++ b/ApplicationCode/ProjectDataModel/RimLegendConfig.cpp @@ -308,7 +308,15 @@ void RimLegendConfig::updateLegend() break; case CATEGORY_INTEGER: m_categoryMapper->setCategoriesWithNames(m_categories, m_categoryNames); - m_categoryMapper->setInterpolateColors(legendColors); + + if (m_categoryColors.size() > 0) + { + m_categoryMapper->setCycleColors(m_categoryColors); + } + else + { + m_categoryMapper->setInterpolateColors(legendColors); + } m_currentScalarMapper = m_categoryMapper.p(); break; default: @@ -570,6 +578,7 @@ void RimLegendConfig::setIntegerCategories(const std::vector& categories) { m_categories = categories; m_categoryNames.clear(); + m_categoryColors.clear(); updateLegend(); } @@ -589,6 +598,7 @@ void RimLegendConfig::setNamedCategoriesInverse(const std::vector& cate m_categories = nameIndices; m_categoryNames = names; + m_categoryColors.clear(); updateLegend(); } @@ -609,10 +619,23 @@ void RimLegendConfig::setNamedCategories(const std::vector& categoryNam m_categories = nameIndices; m_categoryNames = names; + m_categoryColors.clear(); updateLegend(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimLegendConfig::setCategoryColors(const std::vector& categoryColors) +{ + if (m_categoryNames.size() == categoryColors.size()) + { + m_categoryColors = cvf::Color3ubArray(categoryColors); + updateLegend(); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimLegendConfig.h b/ApplicationCode/ProjectDataModel/RimLegendConfig.h index ee92eef894..f470e9d352 100644 --- a/ApplicationCode/ProjectDataModel/RimLegendConfig.h +++ b/ApplicationCode/ProjectDataModel/RimLegendConfig.h @@ -108,6 +108,7 @@ public: void setIntegerCategories(const std::vector& categories); void setNamedCategoriesInverse(const std::vector& categoryNames); void setNamedCategories(const std::vector& categoryNames); + void setCategoryColors(const std::vector& categoryColors); void setTitle(const cvf::String& title); @@ -156,6 +157,7 @@ private: std::vector m_categories; std::vector m_categoryNames; + cvf::Color3ubArray m_categoryColors; // Fields caf::PdmField m_numLevels;