mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Merge pull request #5081 from OPM/move-error-bar-curve
Curve Error Bars : Move to RimPlotCurve
This commit is contained in:
@@ -18,7 +18,9 @@
|
||||
|
||||
#include "RimPlotCurve.h"
|
||||
|
||||
#include "RiaCurveDataTools.h"
|
||||
#include "RiaGuiApplication.h"
|
||||
|
||||
#include "RimEnsembleCurveSet.h"
|
||||
#include "RimEnsembleCurveSetCollection.h"
|
||||
#include "RimNameConfig.h"
|
||||
@@ -35,12 +37,16 @@
|
||||
|
||||
#include "cvfAssert.h"
|
||||
|
||||
#include "qwt_date.h"
|
||||
#include "qwt_interval_symbol.h"
|
||||
#include "qwt_plot.h"
|
||||
#include "qwt_symbol.h"
|
||||
|
||||
// NB! Special macro for pure virtual class
|
||||
CAF_PDM_XML_ABSTRACT_SOURCE_INIT( RimPlotCurve, "PlotCurve" );
|
||||
|
||||
#define DOUBLE_INF std::numeric_limits<double>::infinity()
|
||||
|
||||
namespace caf
|
||||
{
|
||||
template <>
|
||||
@@ -147,7 +153,12 @@ RimPlotCurve::RimPlotCurve()
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_symbolLabelPosition, "SymbolLabelPosition", "Symbol Label Position", "", "", "" );
|
||||
|
||||
m_qwtPlotCurve = new RiuRimQwtPlotCurve( this );
|
||||
m_qwtPlotCurve = new RiuRimQwtPlotCurve( this );
|
||||
m_qwtCurveErrorBars = new QwtPlotIntervalCurve();
|
||||
m_qwtCurveErrorBars->setStyle( QwtPlotIntervalCurve::CurveStyle::NoCurve );
|
||||
m_qwtCurveErrorBars->setSymbol( new QwtIntervalSymbol( QwtIntervalSymbol::Bar ) );
|
||||
m_qwtCurveErrorBars->setItemAttribute( QwtPlotItem::Legend, false );
|
||||
m_qwtCurveErrorBars->setZ( RiuQwtPlotCurve::Z_ERROR_BARS );
|
||||
|
||||
m_parentQwtPlot = nullptr;
|
||||
}
|
||||
@@ -164,6 +175,13 @@ RimPlotCurve::~RimPlotCurve()
|
||||
m_qwtPlotCurve = nullptr;
|
||||
}
|
||||
|
||||
if ( m_qwtCurveErrorBars )
|
||||
{
|
||||
m_qwtCurveErrorBars->detach();
|
||||
delete m_qwtCurveErrorBars;
|
||||
m_qwtCurveErrorBars = nullptr;
|
||||
}
|
||||
|
||||
if ( m_parentQwtPlot )
|
||||
{
|
||||
m_parentQwtPlot->replot();
|
||||
@@ -220,7 +238,6 @@ void RimPlotCurve::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
|
||||
}
|
||||
else if ( changedField == &m_showErrorBars )
|
||||
{
|
||||
m_qwtPlotCurve->showErrorBars( m_showErrorBars );
|
||||
updateCurveAppearance();
|
||||
}
|
||||
RiuPlotMainWindowTools::refreshToolbars();
|
||||
@@ -271,11 +288,12 @@ void RimPlotCurve::updateCurveVisibility( bool updateParentPlot )
|
||||
{
|
||||
if ( canCurveBeAttached() )
|
||||
{
|
||||
m_qwtPlotCurve->attach( m_parentQwtPlot );
|
||||
attachCurveAndErrorBars();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_qwtPlotCurve->detach();
|
||||
m_qwtCurveErrorBars->detach();
|
||||
}
|
||||
|
||||
if ( updateParentPlot )
|
||||
@@ -323,7 +341,8 @@ void RimPlotCurve::setParentQwtPlotAndReplot( QwtPlot* plot )
|
||||
m_parentQwtPlot = plot;
|
||||
if ( canCurveBeAttached() )
|
||||
{
|
||||
m_qwtPlotCurve->attach( m_parentQwtPlot );
|
||||
attachCurveAndErrorBars();
|
||||
|
||||
m_parentQwtPlot->replot();
|
||||
}
|
||||
}
|
||||
@@ -336,11 +355,12 @@ void RimPlotCurve::setParentQwtPlotNoReplot( QwtPlot* plot )
|
||||
m_parentQwtPlot = plot;
|
||||
if ( canCurveBeAttached() )
|
||||
{
|
||||
m_qwtPlotCurve->attach( m_parentQwtPlot );
|
||||
attachCurveAndErrorBars();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_qwtPlotCurve->detach();
|
||||
m_qwtCurveErrorBars->detach();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,6 +386,7 @@ void RimPlotCurve::setColor( const cvf::Color3f& color )
|
||||
void RimPlotCurve::detachQwtCurve()
|
||||
{
|
||||
m_qwtPlotCurve->detach();
|
||||
m_qwtCurveErrorBars->detach();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -376,7 +397,7 @@ void RimPlotCurve::reattachQwtCurve()
|
||||
detachQwtCurve();
|
||||
if ( canCurveBeAttached() )
|
||||
{
|
||||
m_qwtPlotCurve->attach( m_parentQwtPlot );
|
||||
attachCurveAndErrorBars();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -486,6 +507,75 @@ void RimPlotCurve::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& u
|
||||
throw std::logic_error( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPlotCurve::setSamplesFromXYErrorValues(
|
||||
const std::vector<double>& xValues,
|
||||
const std::vector<double>& yValues,
|
||||
const std::vector<double>& errorValues,
|
||||
bool keepOnlyPositiveValues,
|
||||
RiaCurveDataTools::ErrorAxis errorAxis /*= RiuQwtPlotCurve::ERROR_ALONG_Y_AXIS */ )
|
||||
{
|
||||
CVF_ASSERT( xValues.size() == yValues.size() );
|
||||
CVF_ASSERT( xValues.size() == errorValues.size() );
|
||||
|
||||
auto intervalsOfValidValues = RiaCurveDataTools::calculateIntervalsOfValidValues( yValues, keepOnlyPositiveValues );
|
||||
std::vector<double> filteredYValues;
|
||||
std::vector<double> filteredXValues;
|
||||
|
||||
RiaCurveDataTools::getValuesByIntervals( yValues, intervalsOfValidValues, &filteredYValues );
|
||||
RiaCurveDataTools::getValuesByIntervals( xValues, intervalsOfValidValues, &filteredXValues );
|
||||
|
||||
std::vector<double> filteredErrorValues;
|
||||
RiaCurveDataTools::getValuesByIntervals( errorValues, intervalsOfValidValues, &filteredErrorValues );
|
||||
|
||||
QVector<QwtIntervalSample> errorIntervals;
|
||||
|
||||
errorIntervals.reserve( static_cast<int>( filteredXValues.size() ) );
|
||||
|
||||
for ( size_t i = 0; i < filteredXValues.size(); i++ )
|
||||
{
|
||||
if ( filteredYValues[i] != DOUBLE_INF && filteredErrorValues[i] != DOUBLE_INF )
|
||||
{
|
||||
if ( errorAxis == RiaCurveDataTools::ERROR_ALONG_Y_AXIS )
|
||||
{
|
||||
errorIntervals << QwtIntervalSample( filteredXValues[i],
|
||||
filteredYValues[i] - filteredErrorValues[i],
|
||||
filteredYValues[i] + filteredErrorValues[i] );
|
||||
}
|
||||
else
|
||||
{
|
||||
errorIntervals << QwtIntervalSample( filteredYValues[i],
|
||||
filteredXValues[i] - filteredErrorValues[i],
|
||||
filteredXValues[i] + filteredErrorValues[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_qwtPlotCurve )
|
||||
{
|
||||
m_qwtPlotCurve->setSamples( filteredXValues.data(),
|
||||
filteredYValues.data(),
|
||||
static_cast<int>( filteredXValues.size() ) );
|
||||
|
||||
m_qwtPlotCurve->setLineSegmentStartStopIndices( intervalsOfValidValues );
|
||||
}
|
||||
|
||||
if ( m_qwtCurveErrorBars )
|
||||
{
|
||||
m_qwtCurveErrorBars->setSamples( errorIntervals );
|
||||
if ( errorAxis == RiaCurveDataTools::ERROR_ALONG_Y_AXIS )
|
||||
{
|
||||
m_qwtCurveErrorBars->setOrientation( Qt::Vertical );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_qwtCurveErrorBars->setOrientation( Qt::Horizontal );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -557,6 +647,19 @@ bool RimPlotCurve::canCurveBeAttached() const
|
||||
return isVisibleInPossibleParent;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPlotCurve::attachCurveAndErrorBars()
|
||||
{
|
||||
m_qwtPlotCurve->attach( m_parentQwtPlot );
|
||||
|
||||
if ( m_showErrorBars )
|
||||
{
|
||||
m_qwtCurveErrorBars->attach( m_parentQwtPlot );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -585,7 +688,11 @@ void RimPlotCurve::updateCurveAppearance()
|
||||
m_qwtPlotCurve->setSymbol( symbol );
|
||||
m_qwtPlotCurve->setSymbolSkipPixelDistance( m_symbolSkipPixelDistance() );
|
||||
|
||||
m_qwtPlotCurve->setErrorBarsColor( curveColor );
|
||||
{
|
||||
QwtIntervalSymbol* newSymbol = new QwtIntervalSymbol( QwtIntervalSymbol::Bar );
|
||||
newSymbol->setPen( QPen( curveColor ) );
|
||||
m_qwtCurveErrorBars->setSymbol( newSymbol );
|
||||
}
|
||||
|
||||
// Make sure the legend lines are long enough to distinguish between line types.
|
||||
// Standard width in Qwt is 8 which is too short.
|
||||
|
||||
Reference in New Issue
Block a user