From 39650415509ff4c8b6844a7ddde7b5ae937d46d7 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 23 Apr 2024 11:34:39 +0200 Subject: [PATCH] Set a max limit for number of categories sent to category mapper It is not possible to use the category mapper for a large number of categories. --- .../RimEclipseResultDefinitionTools.cpp | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/RimEclipseResultDefinitionTools.cpp b/ApplicationLibCode/ProjectDataModel/RimEclipseResultDefinitionTools.cpp index 59d16e6b99..084fc9f70b 100644 --- a/ApplicationLibCode/ProjectDataModel/RimEclipseResultDefinitionTools.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimEclipseResultDefinitionTools.cpp @@ -20,6 +20,7 @@ #include "RiaColorTables.h" #include "RiaColorTools.h" +#include "RiaLogging.h" #include "RigAllanDiagramData.h" #include "RigCaseCellResultsData.h" @@ -633,12 +634,6 @@ void RimEclipseResultDefinitionTools::updateCellResultLegend( const RimEclipseRe std::iota( uniqueValues.begin(), uniqueValues.end(), 0 ); } - cvf::Color3ubArray legendBaseColors = legendConfigToUpdate->colorLegend()->colorArray(); - - cvf::ref categoryMapper = new caf::CategoryMapper; - categoryMapper->setCategories( uniqueValues ); - categoryMapper->setInterpolateColors( legendBaseColors ); - std::vector visibleCategoryValues = uniqueValues; if ( resultDefinition->showOnlyVisibleCategoriesInLegend() ) @@ -658,6 +653,26 @@ void RimEclipseResultDefinitionTools::updateCellResultLegend( const RimEclipseRe } } } + + const size_t maxCategoryCount = 500; + if ( legendConfigToUpdate->mappingMode() == RimRegularLegendConfig::MappingType::CATEGORY_INTEGER && + visibleCategoryValues.size() > maxCategoryCount ) + { + QString txt = QString( "Detected %1 category values. Maximum number of categories is %2. Only the first %2 " + "categories will be displayed. Please use a different color mapping." ) + .arg( visibleCategoryValues.size() ) + .arg( maxCategoryCount ); + RiaLogging::error( txt ); + + visibleCategoryValues.resize( maxCategoryCount ); + } + + cvf::Color3ubArray legendBaseColors = legendConfigToUpdate->colorLegend()->colorArray(); + + cvf::ref categoryMapper = new caf::CategoryMapper; + categoryMapper->setCategories( visibleCategoryValues ); + categoryMapper->setInterpolateColors( legendBaseColors ); + std::vector> categoryVector; for ( auto value : visibleCategoryValues )