#1174 Use well ordering when creating category legend colors max tracer

This commit is contained in:
Magne Sjaastad 2017-02-15 15:21:13 +01:00
parent 9a7f187765
commit 037c7c1f73
3 changed files with 37 additions and 31 deletions

View File

@ -29,6 +29,8 @@
#include "RimEclipseCase.h"
#include "RimEclipseFaultColors.h"
#include "RimEclipseView.h"
#include "RimEclipseWell.h"
#include "RimEclipseWellCollection.h"
#include "RimLegendConfig.h"
#include "RimTernaryLegendConfig.h"
#include "RimViewController.h"
@ -281,16 +283,32 @@ void RimEclipseCellColors::updateLegendData(size_t currentTimeStep)
if (this->hasCategoryResult())
{
std::vector<cvf::Color3ub> categoryColors;
std::vector<std::tuple<QString, int, cvf::Color3ub>> categories;
std::vector<QString> tracerNames = this->flowDiagSolution()->tracerNames();
for (const auto& tracerName : tracerNames)
// Loop through the wells to get same ordering as the wells in tree view
for (size_t i = 0; i < m_reservoirView->wellCollection()->wells().size(); i++)
{
categoryColors.push_back(cvf::Color3ub(this->flowDiagSolution()->tracerColor(tracerName)));
size_t reverseIndex = m_reservoirView->wellCollection()->wells().size() - i - 1;
RimEclipseWell* well = m_reservoirView->wellCollection()->wells()[reverseIndex];
QString wellName = well->name();
auto tracer = std::find(begin(tracerNames), end(tracerNames), wellName);
if (tracer != end(tracerNames))
{
// The category value is defined as the index of the tracer name in the tracer name vector
size_t categoryValue = std::distance(begin(tracerNames), tracer);
cvf::Color3ub color(cvf::Color3::SEA_GREEN);
color = cvf::Color3ub(well->wellPipeColor());
categories.push_back(std::make_tuple(wellName, static_cast<int>(categoryValue), color));
}
}
this->legendConfig()->setNamedCategories(tracerNames);
this->legendConfig()->setCategoryColors(categoryColors);
this->legendConfig()->setCategoryItems(categories);
}
}
else

View File

@ -606,36 +606,23 @@ void RimLegendConfig::setNamedCategoriesInverse(const std::vector<QString>& cate
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimLegendConfig::setNamedCategories(const std::vector<QString>& categoryNames)
void RimLegendConfig::setCategoryItems(const std::vector< std::tuple<QString, int, cvf::Color3ub> >& categories)
{
std::vector<int> nameIndices;
std::vector<cvf::String> names;
for ( size_t i = 0; i < categoryNames.size(); ++i )
{
nameIndices.push_back(static_cast<int>(i));
names.push_back(cvfqt::Utils::toString(categoryNames[i]));
}
m_categories = nameIndices;
m_categoryNames = names;
m_categories.clear();
m_categoryNames.clear();
m_categoryColors.clear();
m_categoryColors.reserve(categories.size());
for (auto item : categories)
{
m_categoryNames.push_back(cvfqt::Utils::toString(std::get<0>(item)));
m_categories.push_back(std::get<1>(item));
m_categoryColors.add(std::get<2>(item));
}
updateLegend();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimLegendConfig::setCategoryColors(const std::vector<cvf::Color3ub>& categoryColors)
{
if (m_categoryNames.size() == categoryColors.size())
{
m_categoryColors = cvf::Color3ubArray(categoryColors);
updateLegend();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -26,6 +26,8 @@
#include "cafPdmObject.h"
#include "cafPdmField.h"
#include <tuple>
namespace cvf
{
class ScalarMapperContinuousLog;
@ -108,8 +110,7 @@ public:
void setIntegerCategories(const std::vector<int>& categories);
void setNamedCategoriesInverse(const std::vector<QString>& categoryNames);
void setNamedCategories(const std::vector<QString>& categoryNames);
void setCategoryColors(const std::vector<cvf::Color3ub>& categoryColors);
void setCategoryItems(const std::vector<std::tuple<QString, int, cvf::Color3ub>>& categories);
QString categoryNameFromCategoryValue(int categoryValue) const;
void setTitle(const cvf::String& title);