mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#6974 Color Legend : Improve default settings for user defined values
This commit is contained in:
parent
9884d531bb
commit
68153c836a
@ -167,8 +167,10 @@ void RimEclipseCellColors::changeLegendConfig( QString resultVarNameOfNewLegend
|
|||||||
|
|
||||||
if ( useLog )
|
if ( useLog )
|
||||||
{
|
{
|
||||||
newLegend->setMappingMode( RimRegularLegendConfig::MappingType::LOG10_CONTINUOUS );
|
newLegend->setMappingMode( RimRegularLegendConfig::MappingType::LOG10_DISCRETE );
|
||||||
newLegend->setTickNumberFormat( RimRegularLegendConfig::NumberFormatType::AUTO );
|
newLegend->setTickNumberFormat( RimRegularLegendConfig::NumberFormatType::AUTO );
|
||||||
|
newLegend->setRangeMode( RimLegendConfig::RangeModeType::USER_DEFINED );
|
||||||
|
newLegend->resetUserDefinedValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( this->hasCategoryResult() )
|
if ( this->hasCategoryResult() )
|
||||||
|
@ -58,6 +58,7 @@
|
|||||||
#include "cafPdmFieldCvfMat4d.h"
|
#include "cafPdmFieldCvfMat4d.h"
|
||||||
#include "cafPdmUiComboBoxEditor.h"
|
#include "cafPdmUiComboBoxEditor.h"
|
||||||
#include "cafPdmUiLineEditor.h"
|
#include "cafPdmUiLineEditor.h"
|
||||||
|
#include "cafPdmUiPushButtonEditor.h"
|
||||||
#include "cafPdmUiToolButtonEditor.h"
|
#include "cafPdmUiToolButtonEditor.h"
|
||||||
|
|
||||||
#include "cvfMath.h"
|
#include "cvfMath.h"
|
||||||
@ -149,6 +150,7 @@ RimRegularLegendConfig::RimRegularLegendConfig()
|
|||||||
, m_localAutoPosClosestToZero( 0 )
|
, m_localAutoPosClosestToZero( 0 )
|
||||||
, m_localAutoNegClosestToZero( 0 )
|
, m_localAutoNegClosestToZero( 0 )
|
||||||
, m_isAllTimeStepsRangeDisabled( false )
|
, m_isAllTimeStepsRangeDisabled( false )
|
||||||
|
, m_resetUserDefinedValues( false )
|
||||||
{
|
{
|
||||||
CAF_PDM_InitObject( "Color Legend", ":/Legend.png", "", "" );
|
CAF_PDM_InitObject( "Color Legend", ":/Legend.png", "", "" );
|
||||||
CAF_PDM_InitField( &m_showLegend, "ShowLegend", true, "Show Legend", "", "", "" );
|
CAF_PDM_InitField( &m_showLegend, "ShowLegend", true, "Show Legend", "", "", "" );
|
||||||
@ -222,6 +224,10 @@ RimRegularLegendConfig::RimRegularLegendConfig()
|
|||||||
m_scalarMapperLegend = new caf::OverlayScalarMapperLegend( standardFont );
|
m_scalarMapperLegend = new caf::OverlayScalarMapperLegend( standardFont );
|
||||||
m_categoryLegend = new caf::CategoryLegend( standardFont, m_categoryMapper.p() );
|
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();
|
updateFieldVisibility();
|
||||||
updateLegend();
|
updateLegend();
|
||||||
}
|
}
|
||||||
@ -300,6 +306,13 @@ void RimRegularLegendConfig::fieldChangedByUi( const caf::PdmFieldHandle* change
|
|||||||
updateCategoryItems();
|
updateCategoryItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( changedField == &m_resetUserDefinedValuesButton )
|
||||||
|
{
|
||||||
|
resetUserDefinedValues();
|
||||||
|
|
||||||
|
m_resetUserDefinedValuesButton = false;
|
||||||
|
}
|
||||||
|
|
||||||
updateLegend();
|
updateLegend();
|
||||||
|
|
||||||
RimGridView* view = nullptr;
|
RimGridView* view = nullptr;
|
||||||
@ -359,6 +372,31 @@ void RimRegularLegendConfig::updateLegend()
|
|||||||
{
|
{
|
||||||
m_significantDigitsInData = m_precision;
|
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 adjustedMin = cvf::UNDEFINED_DOUBLE;
|
||||||
double adjustedMax = cvf::UNDEFINED_DOUBLE;
|
double adjustedMax = cvf::UNDEFINED_DOUBLE;
|
||||||
|
|
||||||
@ -540,6 +578,14 @@ void RimRegularLegendConfig::setTickNumberFormat( NumberFormatType numberFormat
|
|||||||
m_tickNumberFormat = numberFormat;
|
m_tickNumberFormat = numberFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RimRegularLegendConfig::resetUserDefinedValues()
|
||||||
|
{
|
||||||
|
m_resetUserDefinedValues = true;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -612,6 +658,23 @@ caf::PdmFieldHandle* RimRegularLegendConfig::objectToggleField()
|
|||||||
return &m_showLegend;
|
return &m_showLegend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RimRegularLegendConfig::defineEditorAttribute( const caf::PdmFieldHandle* field,
|
||||||
|
QString uiConfigName,
|
||||||
|
caf::PdmUiEditorAttribute* attribute )
|
||||||
|
{
|
||||||
|
if ( &m_resetUserDefinedValuesButton == field )
|
||||||
|
{
|
||||||
|
caf::PdmUiPushButtonEditorAttribute* attrib = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>( 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 ) );
|
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_userDefinedMinValue );
|
||||||
mappingGr->add( &m_categoryColorMode );
|
mappingGr->add( &m_categoryColorMode );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uiOrdering.add( &m_resetUserDefinedValuesButton );
|
||||||
|
|
||||||
updateFieldVisibility();
|
updateFieldVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +125,7 @@ public:
|
|||||||
void setMappingMode( MappingType mappingType );
|
void setMappingMode( MappingType mappingType );
|
||||||
MappingType mappingMode() { return m_mappingMode(); }
|
MappingType mappingMode() { return m_mappingMode(); }
|
||||||
void setTickNumberFormat( NumberFormatType numberFormat );
|
void setTickNumberFormat( NumberFormatType numberFormat );
|
||||||
|
void resetUserDefinedValues();
|
||||||
|
|
||||||
void disableAllTimeStepsRange( bool doDisable );
|
void disableAllTimeStepsRange( bool doDisable );
|
||||||
|
|
||||||
@ -153,16 +154,24 @@ public:
|
|||||||
caf::TitledOverlayFrame* titledOverlayFrame() override;
|
caf::TitledOverlayFrame* titledOverlayFrame() override;
|
||||||
RiuAbstractLegendFrame* makeLegendFrame();
|
RiuAbstractLegendFrame* makeLegendFrame();
|
||||||
|
|
||||||
RangeModeType rangeMode() const;
|
void setRangeMode( RangeModeType rangeMode );
|
||||||
|
RangeModeType rangeMode() const;
|
||||||
|
|
||||||
static cvf::Color3ubArray colorArrayFromColorType( ColorRangesType colorType );
|
static cvf::Color3ubArray colorArrayFromColorType( ColorRangesType colorType );
|
||||||
static RimColorLegend* mapToColorLegend( ColorRangesType colorType );
|
static RimColorLegend* mapToColorLegend( ColorRangesType colorType );
|
||||||
|
|
||||||
|
static double computeTenExponentCeil( double value );
|
||||||
|
static double computeTenExponentFloor( double value );
|
||||||
|
|
||||||
void updateFonts() override;
|
void updateFonts() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
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;
|
||||||
void initAfterRead() override;
|
void initAfterRead() override;
|
||||||
caf::PdmFieldHandle* objectToggleField() 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;
|
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
|
||||||
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
|
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
|
||||||
@ -216,10 +225,13 @@ private:
|
|||||||
caf::PdmField<caf::AppEnum<ColorRangesType>> m_colorRangeMode_OBSOLETE;
|
caf::PdmField<caf::AppEnum<ColorRangesType>> m_colorRangeMode_OBSOLETE;
|
||||||
caf::PdmField<caf::AppEnum<MappingType>> m_mappingMode;
|
caf::PdmField<caf::AppEnum<MappingType>> m_mappingMode;
|
||||||
caf::PdmField<caf::AppEnum<CategoryColorModeType>> m_categoryColorMode;
|
caf::PdmField<caf::AppEnum<CategoryColorModeType>> m_categoryColorMode;
|
||||||
|
caf::PdmField<bool> m_resetUserDefinedValuesButton;
|
||||||
|
|
||||||
caf::PdmPtrField<RimColorLegend*> m_colorLegend;
|
caf::PdmPtrField<RimColorLegend*> m_colorLegend;
|
||||||
caf::PdmField<bool> m_selectColorLegendButton;
|
caf::PdmField<bool> m_selectColorLegendButton;
|
||||||
|
|
||||||
|
bool m_resetUserDefinedValues;
|
||||||
|
|
||||||
QString m_title;
|
QString m_title;
|
||||||
int m_significantDigitsInData;
|
int m_significantDigitsInData;
|
||||||
};
|
};
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
#include "RiaTestDataDirectory.h"
|
||||||
#include "RifColorLegendData.h"
|
#include "RifColorLegendData.h"
|
||||||
#include "RigFormationNames.h"
|
#include "RigFormationNames.h"
|
||||||
|
#include "RimRegularLegendConfig.h"
|
||||||
#include "QDir"
|
|
||||||
#include "RiaTestDataDirectory.h"
|
|
||||||
#include <QString>
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
#include "cvfColor3.h"
|
#include "cvfColor3.h"
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
TEST( RifColorLegendData, ReadLYRFileWithoutColor )
|
TEST( RifColorLegendData, ReadLYRFileWithoutColor )
|
||||||
{
|
{
|
||||||
QDir baseFolder( TEST_DATA_DIR );
|
QDir baseFolder( TEST_DATA_DIR );
|
||||||
@ -83,3 +84,47 @@ TEST( RifColorLegendData, ReadLYRFileWithColorHTML )
|
|||||||
EXPECT_EQ( 0.0f, formationColor.g() );
|
EXPECT_EQ( 0.0f, formationColor.g() );
|
||||||
EXPECT_EQ( 0.0f, formationColor.b() );
|
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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user