Refactored ensemble parameter legends

This commit is contained in:
Gaute Lindkvist
2019-12-02 14:05:41 +01:00
parent c4951a5a03
commit f56a34843a
17 changed files with 249 additions and 220 deletions

View File

@@ -37,6 +37,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimEnsembleStatisticsCase.h
${CMAKE_CURRENT_LIST_DIR}/RimDerivedEnsembleCase.h
${CMAKE_CURRENT_LIST_DIR}/RimDerivedEnsembleCaseCollection.h
${CMAKE_CURRENT_LIST_DIR}/RimSummaryPlotFilterTextCurveSetEditor.h
${CMAKE_CURRENT_LIST_DIR}/RimEnsembleParameterColorHandlerInterface.h
)
set (SOURCE_GROUP_SOURCE_FILES
@@ -77,6 +78,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimEnsembleStatisticsCase.cpp
${CMAKE_CURRENT_LIST_DIR}/RimDerivedEnsembleCase.cpp
${CMAKE_CURRENT_LIST_DIR}/RimDerivedEnsembleCaseCollection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimSummaryPlotFilterTextCurveSetEditor.cpp
${CMAKE_CURRENT_LIST_DIR}/RimEnsembleParameterColorHandlerInterface.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@@ -140,8 +140,8 @@ QList<caf::PdmOptionItemInfo>
auto nameParameterPairs = curveSet->ensembleParameters();
for ( auto& nameParamPair : nameParameterPairs )
{
options.push_back( caf::PdmOptionItemInfo( RimEnsembleCurveSet::ensembleParameterUiName( nameParamPair ),
nameParamPair.first ) );
options.push_back(
caf::PdmOptionItemInfo( EnsembleParameter::uiName( nameParamPair ), nameParamPair.first ) );
}
}
}

View File

@@ -46,6 +46,7 @@
#include "RimSummaryFilter.h"
#include "RimSummaryPlot.h"
#include "RiuCvfOverlayItemWidget.h"
#include "RiuPlotMainWindow.h"
#include "RiuQwtPlotCurve.h"
#include "RiuSummaryCurveDefSelectionDialog.h"
@@ -56,6 +57,7 @@
#include "cafPdmUiListEditor.h"
#include "cafPdmUiPushButtonEditor.h"
#include "cafPdmUiTreeOrdering.h"
#include "cafTitledOverlayFrame.h"
#include "cvfScalarMapper.h"
@@ -75,20 +77,6 @@
RiuQwtSymbol::PointSymbolEnum statisticsCurveSymbolFromAddress( const RifEclipseSummaryAddress& address );
int statisticsCurveSymbolSize( RiuQwtSymbol::PointSymbolEnum symbol );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
namespace caf
{
template <>
void AppEnum<RimEnsembleCurveSet::ColorMode>::setUp()
{
addItem( RimEnsembleCurveSet::SINGLE_COLOR, "SINGLE_COLOR", "Single Color" );
addItem( RimEnsembleCurveSet::BY_ENSEMBLE_PARAM, "BY_ENSEMBLE_PARAM", "By Ensemble Parameter" );
setDefault( RimEnsembleCurveSet::SINGLE_COLOR );
}
} // namespace caf
CAF_PDM_SOURCE_INIT( RimEnsembleCurveSet, "RimEnsembleCurveSet" );
//--------------------------------------------------------------------------------------------------
@@ -124,7 +112,13 @@ RimEnsembleCurveSet::RimEnsembleCurveSet()
m_yPushButtonSelectSummaryAddress.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
m_yPushButtonSelectSummaryAddress = false;
CAF_PDM_InitField( &m_colorMode, "ColorMode", caf::AppEnum<ColorMode>( SINGLE_COLOR ), "Coloring Mode", "", "", "" );
CAF_PDM_InitField( &m_colorMode,
"ColorMode",
caf::AppEnum<ColorMode>( ColorMode::SINGLE_COLOR ),
"Coloring Mode",
"",
"",
"" );
CAF_PDM_InitField( &m_color, "Color", cvf::Color3f( cvf::Color3::BLACK ), "Color", "", "", "" );
@@ -189,7 +183,12 @@ RimEnsembleCurveSet::~RimEnsembleCurveSet()
if ( parentPlot && parentPlot->viewer() )
{
m_qwtPlotCurveForLegendText->detach();
parentPlot->removeEnsembleCurveSetLegend( this );
parentPlot->viewer()->removeOverlayFrame( m_legendOverlayFrame );
}
if ( m_legendOverlayFrame )
{
m_legendOverlayFrame->setParent( nullptr );
delete m_legendOverlayFrame;
}
delete m_qwtPlotCurveForLegendText;
@@ -381,6 +380,14 @@ RimRegularLegendConfig* RimEnsembleCurveSet::legendConfig()
return m_legendConfig;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QFrame* RimEnsembleCurveSet::legendFrame() const
{
return m_legendOverlayFrame;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -442,7 +449,7 @@ void RimEnsembleCurveSet::setEnsembleParameter( const QString& parameterName )
//--------------------------------------------------------------------------------------------------
EnsembleParameter::Type RimEnsembleCurveSet::currentEnsembleParameterType() const
{
if ( m_colorMode() == BY_ENSEMBLE_PARAM )
if ( m_colorMode() == ColorMode::BY_ENSEMBLE_PARAM )
{
RimSummaryCaseCollection* group = m_yValuesSummaryCaseCollection();
QString parameterName = m_ensembleParameter();
@@ -456,29 +463,6 @@ EnsembleParameter::Type RimEnsembleCurveSet::currentEnsembleParameterType() cons
return EnsembleParameter::TYPE_NONE;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimEnsembleCurveSet::ensembleParameterUiName( const RimEnsembleCurveSet::NameParameterPair& paramPair )
{
QString stem = paramPair.first;
QString variationString;
if ( paramPair.second.isNumeric() )
{
switch ( paramPair.second.variationBin )
{
case EnsembleParameter::LOW_VARIATION:
variationString = QString( " (Low variation)" );
case EnsembleParameter::MEDIUM_VARIATION:
break;
case EnsembleParameter::HIGH_VARIATION:
variationString = QString( " (High variation)" );
break;
}
}
return QString( "%1%2" ).arg( stem ).arg( variationString );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -669,11 +653,11 @@ void RimEnsembleCurveSet::appendColorGroup( caf::PdmUiOrdering& uiOrdering )
m_colorMode.uiCapability()->setUiReadOnly( !m_yValuesSummaryCaseCollection() );
colorsGroup->add( &m_colorMode );
if ( m_colorMode == SINGLE_COLOR )
if ( m_colorMode == ColorMode::SINGLE_COLOR )
{
colorsGroup->add( &m_color );
}
else if ( m_colorMode == BY_ENSEMBLE_PARAM )
else if ( m_colorMode == ColorMode::BY_ENSEMBLE_PARAM )
{
m_ensembleParameter.uiCapability()->setUiReadOnly( !m_yValuesSummaryCaseCollection() );
colorsGroup->add( &m_ensembleParameter );
@@ -685,7 +669,7 @@ void RimEnsembleCurveSet::appendColorGroup( caf::PdmUiOrdering& uiOrdering )
//--------------------------------------------------------------------------------------------------
void RimEnsembleCurveSet::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName /*= ""*/ )
{
if ( m_colorMode == BY_ENSEMBLE_PARAM )
if ( m_colorMode == ColorMode::BY_ENSEMBLE_PARAM )
{
uiTreeOrdering.add( m_legendConfig() );
}
@@ -779,21 +763,21 @@ QList<caf::PdmOptionItemInfo> RimEnsembleCurveSet::calculateValueOptions( const
}
else if ( fieldNeedingOptions == &m_colorMode )
{
auto singleColorOption = caf::AppEnum<RimEnsembleCurveSet::ColorMode>( RimEnsembleCurveSet::SINGLE_COLOR );
auto byEnsParamOption = caf::AppEnum<RimEnsembleCurveSet::ColorMode>( RimEnsembleCurveSet::BY_ENSEMBLE_PARAM );
auto singleColorOption = ColorModeEnum( ColorMode::SINGLE_COLOR );
auto byEnsParamOption = ColorModeEnum( ColorMode::BY_ENSEMBLE_PARAM );
options.push_back( caf::PdmOptionItemInfo( singleColorOption.uiText(), RimEnsembleCurveSet::SINGLE_COLOR ) );
options.push_back( caf::PdmOptionItemInfo::fromEnumClass( singleColorOption.uiText(), ColorMode::SINGLE_COLOR ) );
if ( !ensembleParameters().empty() )
{
options.push_back(
caf::PdmOptionItemInfo( byEnsParamOption.uiText(), RimEnsembleCurveSet::BY_ENSEMBLE_PARAM ) );
caf::PdmOptionItemInfo::fromEnumClass( byEnsParamOption.uiText(), ColorMode::BY_ENSEMBLE_PARAM ) );
}
}
else if ( fieldNeedingOptions == &m_ensembleParameter )
{
for ( const auto& paramPair : ensembleParameters() )
{
options.push_back( caf::PdmOptionItemInfo( ensembleParameterUiName( paramPair ), paramPair.first ) );
options.push_back( caf::PdmOptionItemInfo( EnsembleParameter::uiName( paramPair ), paramPair.first ) );
}
}
else if ( fieldNeedingOptions == &m_yValuesSummaryAddressUiField )
@@ -841,7 +825,7 @@ void RimEnsembleCurveSet::appendOptionItemsForSummaryAddresses( QList<caf::PdmOp
//--------------------------------------------------------------------------------------------------
void RimEnsembleCurveSet::updateCurveColors()
{
if ( m_colorMode == BY_ENSEMBLE_PARAM )
if ( m_colorMode == ColorMode::BY_ENSEMBLE_PARAM )
{
RimSummaryCaseCollection* group = m_yValuesSummaryCaseCollection();
@@ -938,7 +922,7 @@ void RimEnsembleCurveSet::updateCurveColors()
}
}
}
else if ( m_colorMode == SINGLE_COLOR )
else if ( m_colorMode == ColorMode::SINGLE_COLOR )
{
for ( auto& curve : m_curves )
{
@@ -954,14 +938,22 @@ void RimEnsembleCurveSet::updateCurveColors()
firstAncestorOrThisOfType( plot );
if ( plot && plot->viewer() )
{
if ( m_yValuesSummaryCaseCollection() && isCurvesVisible() && m_colorMode == BY_ENSEMBLE_PARAM &&
if ( m_yValuesSummaryCaseCollection() && isCurvesVisible() && m_colorMode == ColorMode::BY_ENSEMBLE_PARAM &&
m_legendConfig->showLegend() )
{
plot->addOrUpdateEnsembleCurveSetLegend( this );
if ( !m_legendOverlayFrame )
{
m_legendOverlayFrame = new RiuCvfOverlayItemWidget( plot->viewer(), plot->viewer()->canvas() );
}
m_legendOverlayFrame->updateFromOverlayItem( m_legendConfig()->titledOverlayFrame() );
plot->viewer()->addOverlayFrame( m_legendOverlayFrame );
}
else
{
plot->removeEnsembleCurveSetLegend( this );
if ( !m_legendOverlayFrame.isNull() )
{
plot->viewer()->removeOverlayFrame( m_legendOverlayFrame );
}
}
plot->viewer()->scheduleReplot();
}
@@ -1278,7 +1270,7 @@ void RimEnsembleCurveSet::updateEnsembleLegendItem()
{
QwtSymbol* symbol = nullptr;
if ( m_colorMode == SINGLE_COLOR )
if ( m_colorMode == ColorMode::SINGLE_COLOR )
{
symbol = new QwtSymbol( QwtSymbol::HLine );
@@ -1289,7 +1281,7 @@ void RimEnsembleCurveSet::updateEnsembleLegendItem()
symbol->setPen( curvePen );
symbol->setSize( 6, 6 );
}
else if ( m_colorMode == BY_ENSEMBLE_PARAM )
else if ( m_colorMode == ColorMode::BY_ENSEMBLE_PARAM )
{
QPixmap p = QPixmap( ":/Legend.png" );

View File

@@ -37,10 +37,11 @@
#include "cafPdmPtrField.h"
#include "RifEclipseSummaryAddressQMetaType.h"
#include "RimEnsembleParameterColorHandlerInterface.h"
#include "cafPdmProxyValueField.h"
class QwtPlot;
class QwtPlotCurve;
#include <QPointer>
class RimSummaryCase;
class RimSummaryCaseCollection;
class RimSummaryCurve;
@@ -50,25 +51,21 @@ class RimSummaryPlotSourceStepping;
class RimSummaryCurveAutoName;
class RimEnsembleCurveFilterCollection;
class RimEnsembleStatistics;
class QKeyEvent;
class RimEnsembleStatisticsCase;
class RiuCvfOverlayItemWidget;
class QwtPlot;
class QwtPlotCurve;
class QKeyEvent;
//==================================================================================================
///
//==================================================================================================
class RimEnsembleCurveSet : public caf::PdmObject
class RimEnsembleCurveSet : public caf::PdmObject, public RimEnsembleParameterColorHandlerInterface
{
CAF_PDM_HEADER_INIT;
public:
enum ColorMode
{
SINGLE_COLOR,
BY_ENSEMBLE_PARAM
};
typedef std::pair<QString, EnsembleParameter> NameParameterPair;
RimEnsembleCurveSet();
~RimEnsembleCurveSet() override;
@@ -90,20 +87,21 @@ public:
void deleteEnsembleCurves();
void deleteStatisticsCurves();
RimRegularLegendConfig* legendConfig();
void onLegendDefinitionChanged();
void onLegendDefinitionChanged();
void setSummaryCaseCollection( RimSummaryCaseCollection* sumCaseCollection );
RimSummaryCaseCollection* summaryCaseCollection() const;
RimEnsembleCurveFilterCollection* filterCollection() const;
ColorMode colorMode() const;
void setColorMode( ColorMode mode );
void setEnsembleParameter( const QString& parameterName );
void updateEnsembleLegendItem();
ColorMode colorMode() const override;
void setColorMode( ColorMode mode ) override;
void setEnsembleParameter( const QString& parameterName ) override;
void updateEnsembleLegendItem() override;
RimRegularLegendConfig* legendConfig() override;
QFrame* legendFrame() const override;
EnsembleParameter::Type currentEnsembleParameterType() const;
static QString ensembleParameterUiName( const NameParameterPair& paramPair );
void updateAllCurves();
void updateStatisticsCurves();
@@ -169,9 +167,9 @@ private:
caf::PdmField<RifEclipseSummaryAddress> m_yValuesSummaryAddressUiField;
caf::PdmField<bool> m_yPushButtonSelectSummaryAddress;
caf::PdmField<caf::AppEnum<ColorMode>> m_colorMode;
caf::PdmField<cvf::Color3f> m_color;
caf::PdmField<QString> m_ensembleParameter;
caf::PdmField<ColorModeEnum> m_colorMode;
caf::PdmField<cvf::Color3f> m_color;
caf::PdmField<QString> m_ensembleParameter;
caf::PdmField<caf::AppEnum<RiaDefines::PlotAxis>> m_plotAxis;
@@ -184,7 +182,8 @@ private:
caf::PdmProxyValueField<QString> m_autoGeneratedName;
caf::PdmChildField<RimSummaryCurveAutoName*> m_summaryAddressNameTools;
QwtPlotCurve* m_qwtPlotCurveForLegendText;
QwtPlotCurve* m_qwtPlotCurveForLegendText;
QPointer<RiuCvfOverlayItemWidget> m_legendOverlayFrame;
std::unique_ptr<RimEnsembleStatisticsCase> m_ensembleStatCase;

View File

@@ -0,0 +1,17 @@
#include "RimEnsembleParameterColorHandlerInterface.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
namespace caf
{
template <>
void AppEnum<RimEnsembleParameterColorHandlerInterface::ColorMode>::setUp()
{
addItem( RimEnsembleParameterColorHandlerInterface::ColorMode::SINGLE_COLOR, "SINGLE_COLOR", "Single Color" );
addItem( RimEnsembleParameterColorHandlerInterface::ColorMode::BY_ENSEMBLE_PARAM,
"BY_ENSEMBLE_PARAM",
"By Ensemble Parameter" );
setDefault( RimEnsembleParameterColorHandlerInterface::ColorMode::SINGLE_COLOR );
}
} // namespace caf

View File

@@ -0,0 +1,49 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Statoil ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RimSummaryCaseCollection.h"
#include "cafAppEnum.h"
#include <utility>
class RimRegularLegendConfig;
class RiuCvfOverlayItemWidget;
class QFrame;
class RimEnsembleParameterColorHandlerInterface
{
public:
enum class ColorMode
{
SINGLE_COLOR,
BY_ENSEMBLE_PARAM
};
using ColorModeEnum = caf::AppEnum<ColorMode>;
using NameParameterPair = EnsembleParameter::NameParameterPair;
public:
virtual ColorMode colorMode() const = 0;
virtual void setColorMode( ColorMode mode ) = 0;
virtual void setEnsembleParameter( const QString& parameterName ) = 0;
virtual void updateEnsembleLegendItem() = 0;
virtual RimRegularLegendConfig* legendConfig() = 0;
virtual QFrame* legendFrame() const = 0;
};

View File

@@ -127,6 +127,30 @@ void EnsembleParameter::sortByBinnedVariation( std::vector<NameParameterPair>& p
return lhs.second.variationBin > rhs.second.variationBin;
} );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString EnsembleParameter::uiName( const NameParameterPair& paramPair )
{
QString stem = paramPair.first;
QString variationString;
if ( paramPair.second.isNumeric() )
{
switch ( paramPair.second.variationBin )
{
case LOW_VARIATION:
variationString = QString( " (Low variation)" );
case MEDIUM_VARIATION:
break;
case HIGH_VARIATION:
variationString = QString( " (High variation)" );
break;
}
}
return QString( "%1%2" ).arg( stem ).arg( variationString );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -89,6 +89,8 @@ public:
static void sortByBinnedVariation( std::vector<NameParameterPair>& parameterVector );
static QString uiName( const NameParameterPair& paramPair );
private:
double stdDeviation() const;
};

View File

@@ -683,7 +683,7 @@ size_t RimSummaryPlot::singleColorCurveCount() const
{
auto allCurveSets = ensembleCurveSetCollection()->curveSets();
size_t colorIndex = std::count_if( allCurveSets.begin(), allCurveSets.end(), []( RimEnsembleCurveSet* curveSet ) {
return curveSet->colorMode() == RimEnsembleCurveSet::SINGLE_COLOR;
return curveSet->colorMode() == RimEnsembleCurveSet::ColorMode::SINGLE_COLOR;
} );
colorIndex += curveCount();
@@ -711,7 +711,7 @@ void RimSummaryPlot::applyDefaultCurveAppearances()
int colorIndex = 0;
for ( auto& curveSet : this->ensembleCurveSetCollection()->curveSets() )
{
if ( curveSet->colorMode() != RimEnsembleCurveSet::SINGLE_COLOR ) continue;
if ( curveSet->colorMode() != RimEnsembleCurveSet::ColorMode::SINGLE_COLOR ) continue;
curveSet->setColor( RiaColorTables::summaryCurveDefaultPaletteColors().cycledColor3f( colorIndex++ ) );
}
}
@@ -1227,9 +1227,10 @@ void RimSummaryPlot::deleteCurves( const std::vector<RimSummaryCurve*>& curves )
curveSet->deleteCurve( curve );
if ( curveSet->curves().empty() )
{
if ( curveSet->colorMode() == RimEnsembleCurveSet::BY_ENSEMBLE_PARAM && m_plotWidget )
if ( curveSet->colorMode() == RimEnsembleCurveSet::ColorMode::BY_ENSEMBLE_PARAM &&
m_plotWidget )
{
m_plotWidget->removeEnsembleCurveSetLegend( curveSet );
m_plotWidget->removeOverlayFrame( curveSet->legendFrame() );
}
m_ensembleCurveSetCollection->deleteCurveSet( curveSet );
}
@@ -1526,28 +1527,6 @@ void RimSummaryPlot::cleanupBeforeClose()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::addOrUpdateEnsembleCurveSetLegend( RimEnsembleCurveSet* curveSet )
{
if ( m_plotWidget )
{
m_plotWidget->addOrUpdateEnsembleCurveSetLegend( curveSet );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::removeEnsembleCurveSetLegend( RimEnsembleCurveSet* curveSet )
{
if ( m_plotWidget )
{
m_plotWidget->removeEnsembleCurveSetLegend( curveSet );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -170,9 +170,6 @@ public:
void onAxisSelected( int axis, bool toggle ) override;
void addOrUpdateEnsembleCurveSetLegend( RimEnsembleCurveSet* curveSet );
void removeEnsembleCurveSetLegend( RimEnsembleCurveSet* curveSet );
public:
// RimViewWindow overrides
QWidget* createViewWidget( QWidget* mainWindowParent = nullptr ) override;