Merge remote-tracking branch 'origin/2020.10-patch-01' into dev

This commit is contained in:
Magne Sjaastad
2020-11-20 15:34:35 +01:00
6 changed files with 227 additions and 54 deletions

View File

@@ -25,6 +25,8 @@
#include "cafPdmFieldReorderCapability.h"
#include <algorithm>
CAF_PDM_SOURCE_INIT( RimColorLegend, "ColorLegend" );
//--------------------------------------------------------------------------------------------------
@@ -94,6 +96,7 @@ void RimColorLegend::addReorderCapability()
void RimColorLegend::appendColorLegendItem( RimColorLegendItem* colorLegendItem )
{
m_colorLegendItems.push_back( colorLegendItem );
onColorLegendItemHasChanged();
}
//--------------------------------------------------------------------------------------------------
@@ -143,11 +146,18 @@ void RimColorLegend::orderChanged( const caf::SignalEmitter* emitter )
cvf::Color3ubArray RimColorLegend::colorArray() const
{
std::vector<RimColorLegendItem*> legendItems = colorLegendItems();
cvf::Color3ubArray colorArray( legendItems.size() );
// The interpolation algorithm requires minimum two levels
size_t colorCount = std::max( size_t( 2 ), legendItems.size() );
cvf::Color3ubArray colorArray( colorCount );
colorArray.setAll( cvf::Color3ub::GRAY );
for ( size_t i = 0; i < legendItems.size(); i++ )
{
colorArray.set( i, cvf::Color3ub( legendItems[i]->color() ) );
}
return colorArray;
}

View File

@@ -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() )

View File

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

View File

@@ -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<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
@@ -216,10 +225,13 @@ private:
caf::PdmField<caf::AppEnum<ColorRangesType>> m_colorRangeMode_OBSOLETE;
caf::PdmField<caf::AppEnum<MappingType>> m_mappingMode;
caf::PdmField<caf::AppEnum<CategoryColorModeType>> m_categoryColorMode;
caf::PdmField<bool> m_resetUserDefinedValuesButton;
caf::PdmPtrField<RimColorLegend*> m_colorLegend;
caf::PdmField<bool> m_selectColorLegendButton;
bool m_resetUserDefinedValues;
QString m_title;
int m_significantDigitsInData;
};