diff --git a/ApplicationCode/ProjectDataModel/RimEclipseCellColors.cpp b/ApplicationCode/ProjectDataModel/RimEclipseCellColors.cpp index 47172f63d5..d53aa958a8 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseCellColors.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseCellColors.cpp @@ -167,8 +167,10 @@ void RimEclipseCellColors::changeLegendConfig( QString resultVarNameOfNewLegend if ( useLog ) { - newLegend->setMappingMode( RimRegularLegendConfig::MappingType::LOG10_CONTINUOUS ); + newLegend->setMappingMode( RimRegularLegendConfig::MappingType::LOG10_DISCRETE ); newLegend->setTickNumberFormat( RimRegularLegendConfig::NumberFormatType::AUTO ); + newLegend->setRangeMode( RimLegendConfig::RangeModeType::USER_DEFINED ); + newLegend->resetUserDefinedValues(); } if ( this->hasCategoryResult() ) diff --git a/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.cpp b/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.cpp index 2233aa242d..1ad08793bf 100644 --- a/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.cpp +++ b/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.cpp @@ -58,6 +58,7 @@ #include "cafPdmFieldCvfMat4d.h" #include "cafPdmUiComboBoxEditor.h" #include "cafPdmUiLineEditor.h" +#include "cafPdmUiPushButtonEditor.h" #include "cafPdmUiToolButtonEditor.h" #include "cvfMath.h" @@ -149,6 +150,7 @@ RimRegularLegendConfig::RimRegularLegendConfig() , m_localAutoPosClosestToZero( 0 ) , m_localAutoNegClosestToZero( 0 ) , m_isAllTimeStepsRangeDisabled( false ) + , m_resetUserDefinedValues( false ) { CAF_PDM_InitObject( "Color Legend", ":/Legend.png", "", "" ); CAF_PDM_InitField( &m_showLegend, "ShowLegend", true, "Show Legend", "", "", "" ); @@ -222,6 +224,10 @@ RimRegularLegendConfig::RimRegularLegendConfig() m_scalarMapperLegend = new caf::OverlayScalarMapperLegend( standardFont ); m_categoryLegend = new caf::CategoryLegend( standardFont, m_categoryMapper.p() ); + CAF_PDM_InitField( &m_resetUserDefinedValuesButton, "ResetDefaultValues", false, "Reset Default Values", "", "", "" ); + m_resetUserDefinedValuesButton.uiCapability()->setUiEditorTypeName( caf::PdmUiPushButtonEditor::uiEditorTypeName() ); + m_resetUserDefinedValuesButton.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN ); + updateFieldVisibility(); updateLegend(); } @@ -300,6 +306,13 @@ void RimRegularLegendConfig::fieldChangedByUi( const caf::PdmFieldHandle* change updateCategoryItems(); } + if ( changedField == &m_resetUserDefinedValuesButton ) + { + resetUserDefinedValues(); + + m_resetUserDefinedValuesButton = false; + } + updateLegend(); RimGridView* view = nullptr; @@ -359,6 +372,31 @@ void RimRegularLegendConfig::updateLegend() { m_significantDigitsInData = m_precision; + 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; + } + + m_resetUserDefinedValues = false; + } + double adjustedMin = cvf::UNDEFINED_DOUBLE; double adjustedMax = cvf::UNDEFINED_DOUBLE; @@ -540,6 +578,14 @@ void RimRegularLegendConfig::setTickNumberFormat( NumberFormatType numberFormat m_tickNumberFormat = numberFormat; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimRegularLegendConfig::resetUserDefinedValues() +{ + m_resetUserDefinedValues = true; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -612,6 +658,23 @@ caf::PdmFieldHandle* RimRegularLegendConfig::objectToggleField() return &m_showLegend; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimRegularLegendConfig::defineEditorAttribute( const caf::PdmFieldHandle* field, + QString uiConfigName, + caf::PdmUiEditorAttribute* attribute ) +{ + if ( &m_resetUserDefinedValuesButton == field ) + { + caf::PdmUiPushButtonEditorAttribute* attrib = dynamic_cast( attribute ); + if ( attrib ) + { + attrib->m_buttonText = "Reset User Defined Values"; + } + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -954,6 +1017,14 @@ RiuAbstractLegendFrame* RimRegularLegendConfig::makeLegendFrame() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimRegularLegendConfig::setRangeMode( RangeModeType rangeMode ) +{ + m_rangeMode = rangeMode; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1036,6 +1107,32 @@ RimColorLegend* RimRegularLegendConfig::mapToColorLegend( ColorRangesType colorT return project->colorLegendCollection()->findByName( RimRegularLegendConfig::ColorRangeEnum::uiText( colorType ) ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +double RimRegularLegendConfig::computeTenExponentCeil( double value ) +{ + if ( value < 0.0 ) return 0.0; + + double logDecValueMax = log10( value ); + logDecValueMax = cvf::Math::ceil( logDecValueMax ); + + return logDecValueMax; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +double RimRegularLegendConfig::computeTenExponentFloor( double value ) +{ + if ( value < 0.0 ) return 0.0; + + double logDecValueMin = log10( value ); + logDecValueMin = cvf::Math::floor( logDecValueMin ); + + return logDecValueMin; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1087,6 +1184,9 @@ void RimRegularLegendConfig::defineUiOrdering( QString uiConfigName, caf::PdmUiO mappingGr->add( &m_userDefinedMinValue ); mappingGr->add( &m_categoryColorMode ); } + + uiOrdering.add( &m_resetUserDefinedValuesButton ); + updateFieldVisibility(); } diff --git a/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.h b/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.h index 1a486e7ebd..97b8bc589a 100644 --- a/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.h +++ b/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.h @@ -125,6 +125,7 @@ public: void setMappingMode( MappingType mappingType ); MappingType mappingMode() { return m_mappingMode(); } void setTickNumberFormat( NumberFormatType numberFormat ); + void resetUserDefinedValues(); void disableAllTimeStepsRange( bool doDisable ); @@ -153,16 +154,24 @@ public: caf::TitledOverlayFrame* titledOverlayFrame() override; RiuAbstractLegendFrame* makeLegendFrame(); - RangeModeType rangeMode() const; + void setRangeMode( RangeModeType rangeMode ); + RangeModeType rangeMode() const; + static cvf::Color3ubArray colorArrayFromColorType( ColorRangesType colorType ); static RimColorLegend* mapToColorLegend( ColorRangesType colorType ); + static double computeTenExponentCeil( double value ); + static double computeTenExponentFloor( double value ); + void updateFonts() override; private: void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; void initAfterRead() override; caf::PdmFieldHandle* objectToggleField() override; + void defineEditorAttribute( const caf::PdmFieldHandle* field, + QString uiConfigName, + caf::PdmUiEditorAttribute* attribute ) override; void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, @@ -216,10 +225,13 @@ private: caf::PdmField> m_colorRangeMode_OBSOLETE; caf::PdmField> m_mappingMode; caf::PdmField> m_categoryColorMode; + caf::PdmField m_resetUserDefinedValuesButton; caf::PdmPtrField m_colorLegend; caf::PdmField m_selectColorLegendButton; + bool m_resetUserDefinedValues; + QString m_title; int m_significantDigitsInData; }; diff --git a/ApplicationCode/UnitTests/RifColorLegendData-Test.cpp b/ApplicationCode/UnitTests/RifColorLegendData-Test.cpp index ff072ee1a5..1e2af76430 100644 --- a/ApplicationCode/UnitTests/RifColorLegendData-Test.cpp +++ b/ApplicationCode/UnitTests/RifColorLegendData-Test.cpp @@ -1,15 +1,16 @@ #include "gtest/gtest.h" +#include "RiaTestDataDirectory.h" #include "RifColorLegendData.h" #include "RigFormationNames.h" - -#include "QDir" -#include "RiaTestDataDirectory.h" -#include -#include +#include "RimRegularLegendConfig.h" #include "cvfColor3.h" +#include +#include +#include + TEST( RifColorLegendData, ReadLYRFileWithoutColor ) { QDir baseFolder( TEST_DATA_DIR ); @@ -83,3 +84,47 @@ TEST( RifColorLegendData, ReadLYRFileWithColorHTML ) EXPECT_EQ( 0.0f, formationColor.g() ); EXPECT_EQ( 0.0f, formationColor.b() ); } + +TEST( RimRegularLegendConfig, LogTenFunctions ) +{ + { + // Negative values will return zero + double value = -0.0015; + + auto exponentCeil = RimRegularLegendConfig::computeTenExponentCeil( value ); + EXPECT_EQ( 0.0f, exponentCeil ); + + auto exponentFloor = RimRegularLegendConfig::computeTenExponentFloor( value ); + EXPECT_EQ( 0.0f, exponentFloor ); + } + + { + double value = 0.15; + + auto exponentCeil = RimRegularLegendConfig::computeTenExponentCeil( value ); + EXPECT_EQ( 0.0f, exponentCeil ); + + auto exponentFloor = RimRegularLegendConfig::computeTenExponentFloor( value ); + EXPECT_EQ( -1.0f, exponentFloor ); + } + + { + double value = 1.5; + + auto exponentCeil = RimRegularLegendConfig::computeTenExponentCeil( value ); + EXPECT_EQ( 1.0f, exponentCeil ); + + auto exponentFloor = RimRegularLegendConfig::computeTenExponentFloor( value ); + EXPECT_EQ( 0.0f, exponentFloor ); + } + + { + double value = 15; + + auto exponentCeil = RimRegularLegendConfig::computeTenExponentCeil( value ); + EXPECT_EQ( 2.0f, exponentCeil ); + + auto exponentFloor = RimRegularLegendConfig::computeTenExponentFloor( value ); + EXPECT_EQ( 1.0f, exponentFloor ); + } +}