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

@ -32,7 +32,6 @@
#include "RimGeoMechCase.h"
#include "RimGeoMechCellColors.h"
#include "RimGeoMechView.h"
#include "RimIntersectionResultDefinition.h"
#include "RivBoxIntersectionSourceInfo.h"
#include "RivExtrudedCurveIntersectionPartMgr.h"

View File

@ -29,8 +29,6 @@
#include "RimEclipseView.h"
#include "RimExtrudedCurveIntersection.h"
#include "RimGridView.h"
#include "RimIntersectionResultDefinition.h"
#include "RimIntersectionResultsDefinitionCollection.h"
#include "RimSimWellInView.h"
#include "Riu3DMainWindowTools.h"

View File

@ -387,6 +387,24 @@ void RimIntersectionResultDefinition::update2dIntersectionViews()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimIntersectionResultDefinition::setDefaultEclipseLegendConfig()
{
bool useDiscreteLogLevels = false;
bool isCategoryResult = m_eclipseResultDefinition->hasCategoryResult();
auto eclResultDef = this->eclipseResultDefinition();
eclResultDef->updateRangesForExplicitLegends( this->regularLegendConfig(),
this->ternaryLegendConfig(),
this->timeStep() );
m_legendConfig->setDefaultConfigForResultName( m_eclipseResultDefinition->resultVariable(),
useDiscreteLogLevels,
isCategoryResult );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -59,18 +59,17 @@ public:
bool isUsingOverrideViewer );
void update2dIntersectionViews();
void setDefaultEclipseLegendConfig();
protected:
caf::PdmFieldHandle* userDescriptionField() override;
caf::PdmFieldHandle* objectToggleField() override;
void fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue ) override;
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
bool* useOptionsOnly ) override;
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
bool* useOptionsOnly ) override;
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "" ) override;
void initAfterRead() override;

View File

@ -181,49 +181,10 @@ RimRegularLegendConfig* RimEclipseCellColors::createLegendForResult( const QStri
bool useDiscreteLogLevels,
bool isCategoryResult )
{
bool useLog = RiaResultNames::isLogarithmicResult( resultName );
auto* newLegend = new RimRegularLegendConfig;
newLegend->resultVariableName = resultName;
RimRegularLegendConfig::ColorRangesType colorRangeType = RimRegularLegendConfig::ColorRangesType::UNDEFINED;
if ( isCategoryResult )
{
colorRangeType = RimRegularLegendConfig::ColorRangesType::CATEGORY;
}
else if ( resultName == RiaResultNames::swat() )
{
colorRangeType = RimRegularLegendConfig::ColorRangesType::OPPOSITE_NORMAL;
}
RimRegularLegendConfig* newLegend = new RimRegularLegendConfig;
newLegend->resultVariableName = resultName;
if ( useLog )
{
if ( useDiscreteLogLevels )
newLegend->setMappingMode( RimRegularLegendConfig::MappingType::LOG10_DISCRETE );
else
newLegend->setMappingMode( RimRegularLegendConfig::MappingType::LOG10_CONTINUOUS );
newLegend->setTickNumberFormat( RiaNumberFormat::NumberFormatType::AUTO );
newLegend->setRangeMode( RimLegendConfig::RangeModeType::USER_DEFINED );
newLegend->resetUserDefinedValues();
}
if ( RiaResultNames::isFlowResultWithBothPosAndNegValues( resultName ) )
{
colorRangeType = RimRegularLegendConfig::ColorRangesType::BLUE_WHITE_RED;
newLegend->setCenterLegendAroundZero( true );
}
if ( colorRangeType != RimRegularLegendConfig::ColorRangesType::UNDEFINED )
{
RimColorLegend* colorLegend = RimRegularLegendConfig::mapToColorLegend( colorRangeType );
if ( isCategoryResult )
{
newLegend->setMappingMode( RimRegularLegendConfig::MappingType::CATEGORY_INTEGER );
}
newLegend->setColorLegend( colorLegend );
}
newLegend->setDefaultConfigForResultName( resultName, useDiscreteLogLevels, isCategoryResult );
return newLegend;
}

View File

@ -478,6 +478,7 @@ void RimEclipseResultDefinition::updateAnyFieldHasChanged()
this->firstAncestorOrThisOfType( intersectResDef );
if ( intersectResDef )
{
intersectResDef->setDefaultEclipseLegendConfig();
intersectResDef->updateConnectedEditors();
}

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 );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -170,6 +170,8 @@ public:
QString valueToText( double value ) const;
void setDefaultConfigForResultName( const QString& resultName, bool useDiscreteLogLevels, bool isCategoryResult );
private:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void sendChangedSignal( const caf::PdmFieldHandle* changedField );
@ -189,6 +191,7 @@ private:
void updateCategoryItems();
void configureCategoryMapper();
void updateTickCountAndUserDefinedRange();
friend class RimViewLinker;

View File

@ -19,6 +19,7 @@
#include "RiuResultTextBuilder.h"
#include "RigAllanDiagramData.h"
#include "RigCaseCellResultsData.h"
#include "RigEclipseCaseData.h"
#include "RigFormationNames.h"
@ -37,13 +38,12 @@
#include "RimEclipseView.h"
#include "RimExtrudedCurveIntersection.h"
#include "RimFormationNames.h"
#include "RimIntersectionResultDefinition.h"
#include "RimRegularLegendConfig.h"
#include "RimReservoirCellResultsStorage.h"
#include "RivExtrudedCurveIntersectionPartMgr.h"
#include "RigAllanDiagramData.h"
#include "RimIntersectionResultDefinition.h"
#include "cafDisplayCoordTransform.h"
//--------------------------------------------------------------------------------------------------