#5874 Allow user defined color legends in result objects.

This commit is contained in:
Kristian Bendiksen 2020-05-22 09:01:08 +02:00 committed by Magne Sjaastad
parent 8da32eddc1
commit 5295dbe299
8 changed files with 136 additions and 88 deletions

View File

@ -105,3 +105,17 @@ void RimColorLegend::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& newValue )
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Color3ubArray RimColorLegend::colorArray() const
{
std::vector<RimColorLegendItem*> legendItems = colorLegendItems();
cvf::Color3ubArray colorArray( legendItems.size() );
for ( size_t i = 0; i < legendItems.size(); i++ )
{
colorArray.set( i, cvf::Color3ub( legendItems[i]->color() ) );
}
return colorArray;
}

View File

@ -22,6 +22,8 @@
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cvfArray.h"
class RimColorLegendItem;
namespace caf
@ -52,6 +54,8 @@ public:
std::vector<RimColorLegendItem*> colorLegendItems() const;
cvf::Color3ubArray colorArray() const;
public:
caf::PdmFieldHandle* userDescriptionField() override;

View File

@ -88,26 +88,29 @@ void RimColorLegendCollection::createStandardColorLegends()
for ( size_t typeIdx = 0; typeIdx < ColorRangeEnum::size(); typeIdx++ )
{
QString legendName = ColorRangeEnum::uiTextFromIndex( typeIdx );
cvf::Color3ubArray colorArray =
RimRegularLegendConfig::colorArrayFromColorType( ColorRangeEnum::fromIndex( typeIdx ) );
RimColorLegend* colorLegend = new RimColorLegend;
colorLegend->setColorLegendName( legendName );
for ( int i = (int)colorArray.size() - 1; i > -1; i-- ) // reverse to assign last color to top of legend
if ( ColorRangeEnum::fromIndex( typeIdx ) != RimRegularLegendConfig::ColorRangesType::UNDEFINED )
{
cvf::Color3f color3f( colorArray[i] );
QColor colorQ( colorArray[i].r(), colorArray[i].g(), colorArray[i].b() );
QString legendName = ColorRangeEnum::uiTextFromIndex( typeIdx );
cvf::Color3ubArray colorArray =
RimRegularLegendConfig::colorArrayFromColorType( ColorRangeEnum::fromIndex( typeIdx ) );
RimColorLegendItem* colorLegendItem = new RimColorLegendItem;
colorLegendItem->setValues( colorQ.name(), i, color3f );
RimColorLegend* colorLegend = new RimColorLegend;
colorLegend->setColorLegendName( legendName );
colorLegend->appendColorLegendItem( colorLegendItem );
colorLegend->setReadOnly( true );
for ( int i = (int)colorArray.size() - 1; i > -1; i-- ) // reverse to assign last color to top of legend
{
cvf::Color3f color3f( colorArray[i] );
QColor colorQ( colorArray[i].r(), colorArray[i].g(), colorArray[i].b() );
RimColorLegendItem* colorLegendItem = new RimColorLegendItem;
colorLegendItem->setValues( colorQ.name(), i, color3f );
colorLegend->appendColorLegendItem( colorLegendItem );
colorLegend->setReadOnly( true );
}
m_standardColorLegends.push_back( colorLegend );
}
m_standardColorLegends.push_back( colorLegend );
}
this->updateConnectedEditors();
@ -143,3 +146,20 @@ void RimColorLegendCollection::fieldChangedByUi( const caf::PdmFieldHandle* chan
const QVariant& newValue )
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimColorLegend* RimColorLegendCollection::findByName( const QString& name ) const
{
std::vector<RimColorLegend*> allLegends = customColorLegends();
for ( auto legend : allLegends )
{
if ( legend->colorLegendName() == name )
{
return legend;
}
}
return nullptr;
}

View File

@ -53,6 +53,8 @@ public:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
RimColorLegend* findByName( const QString& name ) const;
private:
caf::PdmChildArrayField<RimColorLegend*> m_standardColorLegends; // ResInsight standard (built-in) legends
caf::PdmChildArrayField<RimColorLegend*> m_customColorLegends; // user specified legends

View File

@ -25,6 +25,9 @@
#include "RiaPreferences.h"
#include "RimCellEdgeColors.h"
#include "RimColorLegend.h"
#include "RimColorLegendCollection.h"
#include "RimColorLegendItem.h"
#include "RimEclipseCellColors.h"
#include "RimEclipseView.h"
#include "RimEnsembleCurveSet.h"
@ -33,11 +36,13 @@
#include "RimGeoMechResultDefinition.h"
#include "RimGridCrossPlotDataSet.h"
#include "RimIntersectionCollection.h"
#include "RimProject.h"
#include "RimStimPlanColors.h"
#include "RimViewLinker.h"
#include "RimWellMeasurementInView.h"
#include "RimWellRftEnsembleCurveSet.h"
#include "RimWellRftPlot.h"
#include "RiuCategoryLegendFrame.h"
#include "RiuScalarMapperLegendFrame.h"
@ -89,7 +94,8 @@ void RimRegularLegendConfig::ColorRangeEnum::setUp()
addItem( RimRegularLegendConfig::BLUE_LIGHT_DARK, "BLUE_DARK_LIGHT", "Blue Light to Dark" );
addItem( RimRegularLegendConfig::GREEN_RED, "GREEN_RED", "Green to Red" );
addItem( RimRegularLegendConfig::BLUE_MAGENTA, "BLUE_MAGENTA", "Blue to Magenta" );
setDefault( RimRegularLegendConfig::NORMAL );
addItem( RimRegularLegendConfig::UNDEFINED, "UNDEFINED", "Undefined" );
setDefault( RimRegularLegendConfig::UNDEFINED );
}
} // namespace caf
@ -153,7 +159,13 @@ RimRegularLegendConfig::RimRegularLegendConfig()
"",
"" );
CAF_PDM_InitField( &m_colorRangeMode, "ColorRangeMode", ColorRangeEnum( NORMAL ), "Colors", "", "", "" );
CAF_PDM_InitField( &m_colorRangeMode_OBSOLETE, "ColorRangeMode", ColorRangeEnum( UNDEFINED ), "Colors", "", "", "" );
m_colorRangeMode_OBSOLETE.uiCapability()->setUiHidden( true );
m_colorRangeMode_OBSOLETE.xmlCapability()->setIOWritable( false );
CAF_PDM_InitFieldNoDefault( &m_colorLegend, "ColorLegend", "Colors", "", "", "" );
m_colorLegend = mapToColorLegend( ColorRangeEnum( NORMAL ) );
CAF_PDM_InitField( &m_mappingMode, "MappingMode", MappingEnum( LINEAR_CONTINUOUS ), "Mapping", "", "", "" );
CAF_PDM_InitField( &m_rangeMode,
"RangeType",
@ -389,7 +401,7 @@ void RimRegularLegendConfig::updateLegend()
m_logDiscreteScalarMapper->setRange( adjustedMin, adjustedMax );
m_logSmoothScalarMapper->setRange( adjustedMin, adjustedMax );
cvf::Color3ubArray legendColors = colorArrayFromColorType( m_colorRangeMode() );
cvf::Color3ubArray legendColors = m_colorLegend()->colorArray();
m_linDiscreteScalarMapper->setColors( legendColors );
m_logDiscreteScalarMapper->setColors( legendColors );
@ -550,6 +562,11 @@ void RimRegularLegendConfig::initAfterRead()
resultVariableName = RiaDefines::formationAllanResultName();
}
if ( m_colorRangeMode_OBSOLETE() != RimRegularLegendConfig::UNDEFINED )
{
m_colorLegend = RimRegularLegendConfig::mapToColorLegend( m_colorRangeMode_OBSOLETE() );
}
updateFieldVisibility();
this->updateUiIconFromToggleField();
@ -592,7 +609,8 @@ void RimRegularLegendConfig::updateFieldVisibility()
//--------------------------------------------------------------------------------------------------
void RimRegularLegendConfig::setColorRange( ColorRangesType colorMode )
{
m_colorRangeMode = colorMode;
m_colorRangeMode_OBSOLETE = colorMode;
m_colorLegend = mapToColorLegend( colorMode );
updateLegend();
}
@ -907,10 +925,18 @@ cvf::Color3ubArray RimRegularLegendConfig::colorArrayFromColorType( ColorRangesT
return ColorManager::EnsembleColorRanges().at( colorType );
break;
}
return RiaColorTables::normalPaletteColors().color3ubArray();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimColorLegend* RimRegularLegendConfig::mapToColorLegend( ColorRangesType colorType )
{
RimProject* project = RimProject::current();
return project->colorLegendCollection()->findByName( RimRegularLegendConfig::ColorRangeEnum::uiText( colorType ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -933,7 +959,7 @@ void RimRegularLegendConfig::defineUiOrdering( QString uiConfigName, caf::PdmUiO
formatGr->add( &m_numLevels );
formatGr->add( &m_precision );
formatGr->add( &m_tickNumberFormat );
formatGr->add( &m_colorRangeMode );
formatGr->add( &m_colorLegend );
caf::PdmUiOrdering* mappingGr = uiOrdering.addNewGroup( "Mapping" );
mappingGr->add( &m_mappingMode );
@ -1027,44 +1053,15 @@ QList<caf::PdmOptionItemInfo>
options.push_back( caf::PdmOptionItemInfo( MappingEnum::uiText( mapType ), mapType ) );
}
}
else if ( fieldNeedingOptions == &m_colorRangeMode )
else if ( fieldNeedingOptions == &m_colorLegend )
{
// This is an app enum field, see cafInternalPdmFieldTypeSpecializations.h for the default specialization of
// this type
std::vector<ColorRangesType> rangeTypes;
if ( !isAllanDiagram )
{
if ( !hasEnsembleCurveSetParent && !hasRftPlotParent )
{
rangeTypes.push_back( NORMAL );
rangeTypes.push_back( OPPOSITE_NORMAL );
rangeTypes.push_back( WHITE_PINK );
rangeTypes.push_back( PINK_WHITE );
rangeTypes.push_back( BLUE_WHITE_RED );
rangeTypes.push_back( RED_WHITE_BLUE );
rangeTypes.push_back( WHITE_BLACK );
rangeTypes.push_back( BLACK_WHITE );
rangeTypes.push_back( ANGULAR );
}
else
{
for ( const auto& col : ColorManager::EnsembleColorRanges() )
{
rangeTypes.push_back( col.first );
}
}
RimProject* project = RimProject::current();
RimColorLegendCollection* colorLegendCollection = project->colorLegendCollection();
std::vector<RimColorLegend*> colorLegends = colorLegendCollection->customColorLegends();
if ( hasStimPlanParent ) rangeTypes.push_back( STIMPLAN );
}
if ( isCategoryResult )
for ( RimColorLegend* colorLegend : colorLegends )
{
rangeTypes.push_back( CATEGORY );
}
for ( ColorRangesType colType : rangeTypes )
{
options.push_back( caf::PdmOptionItemInfo( ColorRangeEnum::uiText( colType ), colType ) );
options.push_back( caf::PdmOptionItemInfo( colorLegend->colorLegendName(), colorLegend ) );
}
}
else if ( fieldNeedingOptions == &m_rangeMode )

View File

@ -25,6 +25,8 @@
#include "cvfArray.h"
#include "cvfObject.h"
#include "cafPdmPtrField.h"
#include <tuple>
namespace cvf
@ -49,6 +51,7 @@ class OverlayScalarMapperLegend;
class Rim3dView;
class RimEnsembleCurveSet;
class RiuAbstractLegendFrame;
class RimColorLegend;
//==================================================================================================
///
@ -82,7 +85,8 @@ public:
BLUE_MAGENTA,
RED_LIGHT_DARK,
GREEN_LIGHT_DARK,
BLUE_LIGHT_DARK
BLUE_LIGHT_DARK,
UNDEFINED
};
typedef caf::AppEnum<ColorRangesType> ColorRangeEnum;
@ -106,7 +110,9 @@ public:
void recreateLegend();
void setColorRange( ColorRangesType colorMode );
ColorRangesType colorRange() { return m_colorRangeMode(); }
ColorRangesType colorRange() { return m_colorRangeMode_OBSOLETE(); }
void setColorLegend( RimColorLegend* colorLegend );
RimColorLegend* colorLegend() const;
void setMappingMode( MappingType mappingType );
MappingType mappingMode() { return m_mappingMode(); }
void setTickNumberFormat( NumberFormatType numberFormat );
@ -141,6 +147,7 @@ public:
RangeModeType rangeMode() const;
static cvf::Color3ubArray colorArrayFromColorType( ColorRangesType colorType );
static RimColorLegend* mapToColorLegend( ColorRangesType colorType );
private:
void setNamedCategories( const std::vector<QString>& categoryNames, bool inverse );
@ -194,8 +201,9 @@ private:
caf::PdmField<RangeModeEnum> m_rangeMode;
caf::PdmField<double> m_userDefinedMaxValue;
caf::PdmField<double> m_userDefinedMinValue;
caf::PdmField<caf::AppEnum<ColorRangesType>> m_colorRangeMode;
caf::PdmField<caf::AppEnum<ColorRangesType>> m_colorRangeMode_OBSOLETE;
caf::PdmField<caf::AppEnum<MappingType>> m_mappingMode;
caf::PdmPtrField<RimColorLegend*> m_colorLegend;
QString m_title;
int m_significantDigitsInData;

View File

@ -201,8 +201,13 @@ RimWellLogTrack::RimWellLogTrack()
CAF_PDM_InitFieldNoDefault( &m_regionAnnotationType, "AnnotationType", "Region Annotations", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_regionAnnotationDisplay, "RegionDisplay", "Region Display", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_colorShadingPalette, "ColorShadingPalette", "Colors", "", "", "" );
m_colorShadingPalette = RimRegularLegendConfig::CATEGORY;
CAF_PDM_InitFieldNoDefault( &m_colorShadingPalette_OBSOLETE, "ColorShadingPalette", "Colors", "", "", "" );
m_colorShadingPalette_OBSOLETE.xmlCapability()->setIOWritable( false );
m_colorShadingPalette_OBSOLETE = RimRegularLegendConfig::UNDEFINED;
m_colorShadingPalette_OBSOLETE.uiCapability()->setUiHidden( true );
CAF_PDM_InitFieldNoDefault( &m_colorShadingLegend, "ColorShadingLegend", "Colors", "", "", "" );
m_colorShadingLegend = RimRegularLegendConfig::mapToColorLegend( RimRegularLegendConfig::NORMAL );
CAF_PDM_InitField( &m_colorShadingTransparency, "ColorShadingTransparency", 50, "Color Transparency", "", "", "" );
m_colorShadingTransparency.uiCapability()->setUiEditorTypeName( caf::PdmUiSliderEditor::uiEditorTypeName() );
@ -583,7 +588,7 @@ void RimWellLogTrack::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
}
else if ( changedField == &m_regionAnnotationType || changedField == &m_regionAnnotationDisplay ||
changedField == &m_formationSource || changedField == &m_colorShadingTransparency ||
changedField == &m_colorShadingPalette )
changedField == &m_colorShadingPalette_OBSOLETE || changedField == &m_colorShadingLegend )
{
if ( changedField == &m_formationSource && m_formationSource == WELL_PICK_FILTER )
{
@ -1029,24 +1034,15 @@ QList<caf::PdmOptionItemInfo> RimWellLogTrack::calculateValueOptions( const caf:
RimTools::wellPathOptionItems( &options );
options.push_front( caf::PdmOptionItemInfo( "None", nullptr ) );
}
else if ( fieldNeedingOptions == &m_colorShadingPalette )
else if ( fieldNeedingOptions == &m_colorShadingLegend )
{
std::vector<RimRegularLegendConfig::ColorRangesType> rangeTypes;
rangeTypes.push_back( RimRegularLegendConfig::NORMAL );
rangeTypes.push_back( RimRegularLegendConfig::OPPOSITE_NORMAL );
rangeTypes.push_back( RimRegularLegendConfig::WHITE_PINK );
rangeTypes.push_back( RimRegularLegendConfig::PINK_WHITE );
rangeTypes.push_back( RimRegularLegendConfig::BLUE_WHITE_RED );
rangeTypes.push_back( RimRegularLegendConfig::RED_WHITE_BLUE );
rangeTypes.push_back( RimRegularLegendConfig::WHITE_BLACK );
rangeTypes.push_back( RimRegularLegendConfig::BLACK_WHITE );
rangeTypes.push_back( RimRegularLegendConfig::ANGULAR );
rangeTypes.push_back( RimRegularLegendConfig::CATEGORY );
RimProject* project = RimProject::current();
RimColorLegendCollection* colorLegendCollection = project->colorLegendCollection();
std::vector<RimColorLegend*> colorLegends = colorLegendCollection->customColorLegends();
for ( RimRegularLegendConfig::ColorRangesType colType : rangeTypes )
for ( RimColorLegend* colorLegend : colorLegends )
{
options.push_back(
caf::PdmOptionItemInfo( RimRegularLegendConfig::ColorRangeEnum::uiText( colType ), colType ) );
options.push_back( caf::PdmOptionItemInfo( colorLegend->colorLegendName(), colorLegend ) );
}
}
@ -1732,7 +1728,7 @@ void RimWellLogTrack::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering
if ( m_regionAnnotationDisplay() & RiuPlotAnnotationTool::COLOR_SHADING ||
m_regionAnnotationDisplay() & RiuPlotAnnotationTool::COLORED_LINES )
{
annotationGroup->add( &m_colorShadingPalette );
annotationGroup->add( &m_colorShadingLegend );
if ( m_regionAnnotationDisplay() & RiuPlotAnnotationTool::COLOR_SHADING )
{
annotationGroup->add( &m_colorShadingTransparency );
@ -1829,6 +1825,11 @@ void RimWellLogTrack::initAfterRead()
{
m_showWindow = true;
}
if ( m_colorShadingPalette_OBSOLETE() != RimRegularLegendConfig::UNDEFINED )
{
m_colorShadingLegend = RimRegularLegendConfig::mapToColorLegend( m_colorShadingPalette_OBSOLETE() );
}
}
//--------------------------------------------------------------------------------------------------
@ -2298,7 +2299,8 @@ void RimWellLogTrack::setFormationFieldsUiReadOnly( bool readOnly /*= true*/ )
m_formationLevel.uiCapability()->setUiReadOnly( readOnly );
m_showformationFluids.uiCapability()->setUiReadOnly( readOnly );
m_colorShadingTransparency.uiCapability()->setUiReadOnly( readOnly );
m_colorShadingPalette.uiCapability()->setUiReadOnly( readOnly );
m_colorShadingPalette_OBSOLETE.uiCapability()->setUiReadOnly( readOnly );
m_colorShadingLegend.uiCapability()->setUiReadOnly( readOnly );
}
//--------------------------------------------------------------------------------------------------
@ -2463,8 +2465,7 @@ void RimWellLogTrack::updateFormationNamesOnPlot()
&formationNamesToPlot,
&yValues );
caf::ColorTable colorTable( RimRegularLegendConfig::colorArrayFromColorType( m_colorShadingPalette() ) );
caf::ColorTable colorTable( m_colorShadingLegend->colorArray() );
m_annotationTool->attachNamedRegions( m_plotWidget,
formationNamesToPlot,
xRange,
@ -2609,7 +2610,7 @@ void RimWellLogTrack::updateCurveDataRegionsOnPlot()
std::vector<double> ucsSourceRegions = geoMechWellLogExtractor->ucsSourceRegions( timeStep );
{
caf::ColorTable colorTable( RimRegularLegendConfig::colorArrayFromColorType( m_colorShadingPalette() ) );
caf::ColorTable colorTable( m_colorShadingLegend->colorArray() );
std::vector<QString> sourceNames =
RigWbsParameter::PP_Reservoir().allSourceUiLabels( "\n",
@ -2635,7 +2636,7 @@ void RimWellLogTrack::updateCurveDataRegionsOnPlot()
RiuPlotAnnotationTool::TrackSpan::LEFT_COLUMN );
}
{
caf::ColorTable colorTable( RimRegularLegendConfig::colorArrayFromColorType( m_colorShadingPalette() ) );
caf::ColorTable colorTable( m_colorShadingLegend->colorArray() );
std::vector<QString> sourceNames =
RigWbsParameter::poissonRatio().allSourceUiLabels( "\n",
@ -2661,7 +2662,7 @@ void RimWellLogTrack::updateCurveDataRegionsOnPlot()
RiuPlotAnnotationTool::TrackSpan::CENTRE_COLUMN );
}
{
caf::ColorTable colorTable( RimRegularLegendConfig::colorArrayFromColorType( m_colorShadingPalette() ) );
caf::ColorTable colorTable( m_colorShadingLegend->colorArray() );
std::vector<QString> sourceNames =
RigWbsParameter::UCS().allSourceUiLabels( "\n", wbsPlot->userDefinedValue( RigWbsParameter::UCS() ) );

View File

@ -56,6 +56,7 @@ class RigResultAccessor;
class RigFemResultAddress;
class RigWellLogExtractor;
class RimEclipseResultDefinition;
class RimColorLegend;
class QwtPlotCurve;
@ -309,7 +310,7 @@ private:
caf::PdmField<RegionAnnotationTypeEnum> m_regionAnnotationType;
caf::PdmField<RegionAnnotationDisplayEnum> m_regionAnnotationDisplay;
caf::PdmField<RimRegularLegendConfig::ColorRangeEnum> m_colorShadingPalette;
caf::PdmPtrField<RimColorLegend*> m_colorShadingLegend;
caf::PdmField<int> m_colorShadingTransparency;
caf::PdmField<bool> m_showRegionLabels;
caf::PdmField<caf::AppEnum<FormationSource>> m_formationSource;
@ -332,8 +333,9 @@ private:
caf::PdmPtrField<RimWellPathAttributeCollection*> m_wellPathAttributeCollection;
caf::PdmChildField<RimEclipseResultDefinition*> m_resultDefinition;
caf::PdmField<bool> m_showFormations_OBSOLETE;
caf::PdmField<bool> m_show_OBSOLETE;
caf::PdmField<bool> m_showFormations_OBSOLETE;
caf::PdmField<bool> m_show_OBSOLETE;
caf::PdmField<RimRegularLegendConfig::ColorRangeEnum> m_colorShadingPalette_OBSOLETE;
std::vector<std::unique_ptr<RiuWellPathComponentPlotItem>> m_wellPathAttributePlotObjects;