mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 06:38:13 -05:00
#11172: Create decline curves with distinct colors and tree-ordered legend
This commit is contained in:
1 parent
56944d8b1b
commit
393d32578e
4 files changed
+64
-10
No files matched your search
@@ -18,9 +18,11 @@
|
||||
|
||||
#include "RicCreateDeclineCurvesFeature.h"
|
||||
|
||||
#include "RiaColorTables.h"
|
||||
#include "Summary/RiaSummaryTools.h"
|
||||
|
||||
#include "RimSummaryCurve.h"
|
||||
#include "RimSummaryCurveCollection.h"
|
||||
#include "RimSummaryDeclineCurve.h"
|
||||
#include "RimSummaryMultiPlot.h"
|
||||
#include "RimSummaryPlot.h"
|
||||
@@ -32,6 +34,8 @@
|
||||
|
||||
#include <QAction>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
CAF_CMD_SOURCE_INIT( RicCreateDeclineCurvesFeature, "RicCreateDeclineCurvesFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -54,6 +58,17 @@ void RicCreateDeclineCurvesFeature::onActionTriggered( bool isChecked )
|
||||
RimSummaryDeclineCurve::DeclineCurveType::HYPERBOLIC,
|
||||
RimSummaryDeclineCurve::DeclineCurveType::HARMONIC };
|
||||
|
||||
if ( auto plot = curve->firstAncestorOrThisOfType<RimSummaryPlot>() )
|
||||
{
|
||||
// Initialize the equation box position from the first decline curves: cumulative upper left, rate upper right
|
||||
if ( !plot->hasDeclineCurves() )
|
||||
{
|
||||
const bool isCumulative = curve->curveType() == RifEclipseSummaryAddressDefines::CurveType::ACCUMULATED;
|
||||
plot->setEquationBoxPosition( isCumulative ? RimSummaryPlot::EquationBoxPosition::UPPER_LEFT
|
||||
: RimSummaryPlot::EquationBoxPosition::UPPER_RIGHT );
|
||||
}
|
||||
}
|
||||
|
||||
for ( auto declineCurveType : declineCurveTypes )
|
||||
{
|
||||
RimSummaryDeclineCurve* newCurve = createDeclineCurveAndAddToPlot( curve, declineCurveType );
|
||||
@@ -61,6 +76,12 @@ void RicCreateDeclineCurvesFeature::onActionTriggered( bool isChecked )
|
||||
RiuPlotMainWindowTools::showPlotMainWindow();
|
||||
RiuPlotMainWindowTools::selectAsCurrentItem( newCurve );
|
||||
}
|
||||
|
||||
// Re-attach all curves in project tree order to get a consistent legend order
|
||||
if ( auto curveCollection = curve->firstAncestorOrThisOfType<RimSummaryCurveCollection>() )
|
||||
{
|
||||
curveCollection->updateCurveOrder();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,19 +94,35 @@ void RicCreateDeclineCurvesFeature::setupActionLook( QAction* actionToSetup )
|
||||
actionToSetup->setIcon( QIcon( ":/decline-curve.svg" ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Pick the next color in the default summary palette that is not used by any curve in the plot
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3f RicCreateDeclineCurvesFeature::createDistinctColor( RimSummaryPlot* summaryPlot, RimSummaryCurve* sourceCurve )
|
||||
{
|
||||
const auto& palette = RiaColorTables::summaryCurveDefaultPaletteColors();
|
||||
|
||||
std::vector<cvf::Color3f> usedColors = { sourceCurve->color() };
|
||||
for ( auto curve : summaryPlot->summaryCurves() )
|
||||
{
|
||||
usedColors.push_back( curve->color() );
|
||||
}
|
||||
|
||||
const size_t startIndex = summaryPlot->curveCount();
|
||||
for ( size_t i = 0; i < palette.size(); i++ )
|
||||
{
|
||||
cvf::Color3f candidate = palette.cycledColor3f( startIndex + i );
|
||||
if ( std::find( usedColors.begin(), usedColors.end(), candidate ) == usedColors.end() ) return candidate;
|
||||
}
|
||||
|
||||
return palette.cycledColor3f( startIndex );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSummaryDeclineCurve* RicCreateDeclineCurvesFeature::createDeclineCurveAndAddToPlot( RimSummaryCurve* sourceCurve,
|
||||
RimSummaryDeclineCurve::DeclineCurveType declineCurveType )
|
||||
{
|
||||
auto mapToLineStyle = []( RimSummaryDeclineCurve::DeclineCurveType t )
|
||||
{
|
||||
if ( t == RimSummaryDeclineCurve::DeclineCurveType::HARMONIC ) return RiuQwtPlotCurveDefines::LineStyleEnum::STYLE_DOT;
|
||||
if ( t == RimSummaryDeclineCurve::DeclineCurveType::HYPERBOLIC ) return RiuQwtPlotCurveDefines::LineStyleEnum::STYLE_DASH;
|
||||
return RiuQwtPlotCurveDefines::LineStyleEnum::STYLE_DASH_DOT;
|
||||
};
|
||||
|
||||
RimSummaryPlot* summaryPlot = caf::firstAncestorOfTypeFromSelectedObject<RimSummaryPlot>();
|
||||
|
||||
RimSummaryDeclineCurve* newCurve = new RimSummaryDeclineCurve();
|
||||
@@ -95,8 +132,8 @@ RimSummaryDeclineCurve* RicCreateDeclineCurvesFeature::createDeclineCurveAndAddT
|
||||
|
||||
newCurve->setDeclineCurveType( declineCurveType );
|
||||
|
||||
newCurve->setColor( sourceCurve->color() );
|
||||
newCurve->setLineStyle( mapToLineStyle( declineCurveType ) );
|
||||
newCurve->setColor( createDistinctColor( summaryPlot, sourceCurve ) );
|
||||
newCurve->setLineStyle( RiuQwtPlotCurveDefines::LineStyleEnum::STYLE_SOLID );
|
||||
|
||||
summaryPlot->addCurveAndUpdate( newCurve );
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
#include "RimSummaryDeclineCurve.h"
|
||||
|
||||
#include "cvfColor3.h"
|
||||
|
||||
class RimSummaryPlot;
|
||||
class RimSummaryCurve;
|
||||
|
||||
@@ -37,6 +39,8 @@ protected:
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
|
||||
static cvf::Color3f createDistinctColor( RimSummaryPlot* summaryPlot, RimSummaryCurve* sourceCurve );
|
||||
|
||||
static RimSummaryDeclineCurve* createDeclineCurveAndAddToPlot( RimSummaryCurve* sourceCurve,
|
||||
RimSummaryDeclineCurve::DeclineCurveType declineCurveType );
|
||||
};
|
||||
Reference in new issue
Block a user