Janitor: Make sure the default legend is configured for intersection results

This commit is contained in:
Magne Sjaastad
2022-01-05 21:44:56 +01:00
parent 0cb7a157c9
commit dfd8b9986f
9 changed files with 123 additions and 71 deletions

View File

@@ -404,25 +404,7 @@ void RimRegularLegendConfig::updateLegend()
if ( m_resetUserDefinedValues && m_globalAutoMax != cvf::UNDEFINED_DOUBLE )
{
if ( m_mappingMode() == MappingType::LOG10_CONTINUOUS || m_mappingMode() == MappingType::LOG10_DISCRETE )
{
double exponentMax = computeTenExponentCeil( m_globalAutoMax );
double exponentMin = computeTenExponentFloor( m_globalAutoPosClosestToZero );
m_userDefinedMaxValue = pow( 10, exponentMax );
m_userDefinedMinValue = pow( 10, exponentMin );
int numLevels = exponentMax - exponentMin;
if ( numLevels > 0 )
{
m_numLevels = numLevels;
}
}
else if ( m_mappingMode() == MappingType::LINEAR_CONTINUOUS || m_mappingMode() == MappingType::LINEAR_DISCRETE )
{
m_userDefinedMaxValue = m_globalAutoMax;
m_userDefinedMinValue = m_globalAutoMin;
}
updateTickCountAndUserDefinedRange();
m_resetUserDefinedValues = false;
}
@@ -881,6 +863,36 @@ void RimRegularLegendConfig::configureCategoryMapper()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimRegularLegendConfig::updateTickCountAndUserDefinedRange()
{
if ( m_globalAutoMax != cvf::UNDEFINED_DOUBLE )
{
if ( m_mappingMode() == MappingType::LOG10_CONTINUOUS || m_mappingMode() == MappingType::LOG10_DISCRETE )
{
double exponentMax = computeTenExponentCeil( m_globalAutoMax );
double exponentMin = computeTenExponentFloor( m_globalAutoPosClosestToZero );
m_userDefinedMaxValue = pow( 10, exponentMax );
m_userDefinedMinValue = pow( 10, exponentMin );
int numLevels = exponentMax - exponentMin;
if ( numLevels > 0 )
{
m_numLevels = numLevels;
}
}
else if ( m_mappingMode() == MappingType::LINEAR_CONTINUOUS || m_mappingMode() == MappingType::LINEAR_DISCRETE )
{
m_userDefinedMaxValue = m_globalAutoMax;
m_userDefinedMinValue = m_globalAutoMin;
m_numLevels = 8;
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -1206,6 +1218,67 @@ QString RimRegularLegendConfig::valueToText( double value ) const
return RiaNumberFormat::valueToText( value, m_tickNumberFormat(), m_significantDigitsInData );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimRegularLegendConfig::setDefaultConfigForResultName( const QString& resultName,
bool useDiscreteLogLevels,
bool isCategoryResult )
{
bool useLog = RiaResultNames::isLogarithmicResult( resultName );
RimRegularLegendConfig::MappingType mappingType = MappingType::LINEAR_CONTINUOUS;
RimLegendConfig::RangeModeType rangeType = RimLegendConfig::RangeModeType::AUTOMATIC_ALLTIMESTEPS;
RiaNumberFormat::NumberFormatType numberFormat = RiaNumberFormat::NumberFormatType::FIXED;
if ( useLog )
{
if ( useDiscreteLogLevels )
mappingType = RimRegularLegendConfig::MappingType::LOG10_DISCRETE;
else
mappingType = RimRegularLegendConfig::MappingType::LOG10_CONTINUOUS;
numberFormat = RiaNumberFormat::NumberFormatType::AUTO;
rangeType = RimLegendConfig::RangeModeType::USER_DEFINED;
}
bool centerLegendAroundZero = false;
RimRegularLegendConfig::ColorRangesType colorRangeType = RimRegularLegendConfig::ColorRangesType::UNDEFINED;
if ( isCategoryResult )
{
colorRangeType = RimRegularLegendConfig::ColorRangesType::CATEGORY;
mappingType = RimRegularLegendConfig::MappingType::CATEGORY_INTEGER;
}
else if ( resultName == RiaResultNames::swat() )
{
colorRangeType = RimRegularLegendConfig::ColorRangesType::OPPOSITE_NORMAL;
}
else if ( RiaResultNames::isFlowResultWithBothPosAndNegValues( resultName ) )
{
colorRangeType = RimRegularLegendConfig::ColorRangesType::BLUE_WHITE_RED;
centerLegendAroundZero = true;
}
else if ( resultName != RiaResultNames::undefinedResultName() )
{
colorRangeType = RimRegularLegendConfig::ColorRangesType::NORMAL;
}
resetUserDefinedValues();
setRangeMode( rangeType );
setMappingMode( mappingType );
setCenterLegendAroundZero( centerLegendAroundZero );
setTickNumberFormat( numberFormat );
updateTickCountAndUserDefinedRange();
if ( colorRangeType != RimRegularLegendConfig::ColorRangesType::UNDEFINED )
{
RimColorLegend* colorLegend = RimRegularLegendConfig::mapToColorLegend( colorRangeType );
setColorLegend( colorLegend );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------