From a878d947e82ac29b7e65330dba5ff82b03006cc9 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Wed, 25 Jun 2025 13:04:50 +0200 Subject: [PATCH] Curve Appearance: add transparency slider. --- .../Commands/RicHistogramPlotTools.cpp | 2 +- .../Histogram/RimHistogramCurve.cpp | 11 ++++++ .../Histogram/RimHistogramCurve.h | 2 + .../Histogram/RimHistogramPlot.cpp | 8 ++++ .../ProjectDataModel/RimPlotCurve.cpp | 11 +++++- .../ProjectDataModel/RimPlotCurve.h | 1 + .../RimPlotCurveAppearance.cpp | 39 ++++++++++++++++++- .../ProjectDataModel/RimPlotCurveAppearance.h | 8 +++- 8 files changed, 76 insertions(+), 6 deletions(-) diff --git a/ApplicationLibCode/Commands/RicHistogramPlotTools.cpp b/ApplicationLibCode/Commands/RicHistogramPlotTools.cpp index 59c421b6fe..dfc2568d87 100644 --- a/ApplicationLibCode/Commands/RicHistogramPlotTools.cpp +++ b/ApplicationLibCode/Commands/RicHistogramPlotTools.cpp @@ -44,10 +44,10 @@ void RicHistogramPlotTools::createHistogramCurve( RimHistogramPlot* plot, RimHis RimHistogramCurve* newCurve = new RimHistogramCurve(); newCurve->setDataSource( dataSource ); + newCurve->setAppearanceFromGraphType( plot->graphType() ); cvf::Color3f curveColor = RiaColorTables::summaryCurveDefaultPaletteColors().cycledColor3f( plot->curveCount() ); newCurve->setColor( curveColor ); - newCurve->setIsStacked( true ); newCurve->setFillColor( curveColor ); plot->addCurveNoUpdate( newCurve ); diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.cpp b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.cpp index 72ab860c22..3865b164ab 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.cpp +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.cpp @@ -405,3 +405,14 @@ void RimHistogramCurve::onDataSourceChanged( const caf::SignalEmitter* emitter ) { loadAndUpdateDataAndPlot(); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimHistogramCurve::setAppearanceFromGraphType( RimHistogramPlot::GraphType graphType ) +{ + auto fillType = graphType == RimHistogramPlot::GraphType::BAR_GRAPH ? Qt::SolidPattern : Qt::NoBrush; + setFillStyle( fillType ); + float transparency = graphType == RimHistogramPlot::GraphType::BAR_GRAPH ? 0.2 : 1.0; + setFillColorTransparency( transparency ); +} diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.h b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.h index d88f1a7bbd..a5724f73e4 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.h +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.h @@ -23,6 +23,7 @@ #include "cafPdmObject.h" #include "cafPdmPtrField.h" +#include "RimHistogramPlot.h" #include "RimStackablePlotCurve.h" class RimPlotAxisPropertiesInterface; @@ -56,6 +57,7 @@ public: void updateLegendEntryVisibilityNoPlotUpdate() override; void setDataSource( RimHistogramDataSource* dataSource ); + void setAppearanceFromGraphType( RimHistogramPlot::GraphType graphType ); protected: // RimPlotCurve overrides diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramPlot.cpp b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramPlot.cpp index 09ca444e3a..449053f299 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramPlot.cpp @@ -545,6 +545,14 @@ void RimHistogramPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedField if ( changedField == &m_showPlotLegends ) updateLegend(); + if ( changedField == &m_graphType ) + { + for ( auto c : histogramCurves() ) + { + c->setAppearanceFromGraphType( m_graphType() ); + } + } + if ( changedField == &m_normalizeCurveYValues || changedField == &m_histogramFrequencyType || changedField == &m_graphType ) { loadDataAndUpdate(); diff --git a/ApplicationLibCode/ProjectDataModel/RimPlotCurve.cpp b/ApplicationLibCode/ProjectDataModel/RimPlotCurve.cpp index 5a8140a065..a38cbf96c5 100644 --- a/ApplicationLibCode/ProjectDataModel/RimPlotCurve.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimPlotCurve.cpp @@ -724,6 +724,14 @@ void RimPlotCurve::setFillColor( const cvf::Color3f& fillColor ) m_curveAppearance->setFillColor( fillColor ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPlotCurve::setFillColorTransparency( float fillColorTransparency ) +{ + m_curveAppearance->setFillColorTransparency( fillColorTransparency ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1007,9 +1015,8 @@ void RimPlotCurve::updateCurveAppearance() QColor fillColor = RiaColorTools::toQColor( m_curveAppearance->fillColor() ); fillColor = RiaColorTools::blendQColors( fillColor, QColor( Qt::white ), 3, 1 ); + fillColor.setAlphaF( m_curveAppearance->fillColorTransparency() ); - // TODO: this is a workaround. Create proper api for setting fill color transparency. - fillColor.setAlphaF( 0.5 ); QBrush fillBrush( fillColor, fillStyle() ); m_plotCurve->setAppearance( m_curveAppearance->lineStyle(), m_curveAppearance->interpolation(), diff --git a/ApplicationLibCode/ProjectDataModel/RimPlotCurve.h b/ApplicationLibCode/ProjectDataModel/RimPlotCurve.h index cb6cef5407..88e11b9e62 100644 --- a/ApplicationLibCode/ProjectDataModel/RimPlotCurve.h +++ b/ApplicationLibCode/ProjectDataModel/RimPlotCurve.h @@ -77,6 +77,7 @@ public: virtual Qt::BrushStyle fillStyle() const; void setFillStyle( Qt::BrushStyle brushStyle ); void setFillColor( const cvf::Color3f& fillColor ); + void setFillColorTransparency( float fillColorTransparency ); bool isChecked() const; void setCheckState( bool isChecked ); diff --git a/ApplicationLibCode/ProjectDataModel/RimPlotCurveAppearance.cpp b/ApplicationLibCode/ProjectDataModel/RimPlotCurveAppearance.cpp index b48508aeec..352b8b66bf 100644 --- a/ApplicationLibCode/ProjectDataModel/RimPlotCurveAppearance.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimPlotCurveAppearance.cpp @@ -22,8 +22,7 @@ #include "cafPdmUiComboBoxEditor.h" #include "cafPdmUiCommandSystemProxy.h" - -#include "cvfAssert.h" +#include "cafPdmUiDoubleSliderEditor.h" CAF_PDM_XML_ABSTRACT_SOURCE_INIT( RimPlotCurveAppearance, "PlotCurveAppearance" ); @@ -89,6 +88,8 @@ RimPlotCurveAppearance::RimPlotCurveAppearance() CAF_PDM_InitField( &m_curveColor, "Color", RiaColorTools::textColor3f(), "Color" ); CAF_PDM_InitField( &m_fillColor, "FillColor", cvf::Color3f( -1.0, -1.0, -1.0 ), "Fill Color" ); + CAF_PDM_InitField( &m_fillColorTransparency, "FillColorTransparency", 1.0f, "Fill Color Transparency" ); + m_fillColorTransparency.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleSliderEditor::uiEditorTypeName() ); CAF_PDM_InitField( &m_curveThickness, "Thickness", 1, "Line Thickness" ); m_curveThickness.uiCapability()->setUiEditorTypeName( caf::PdmUiComboBoxEditor::uiEditorTypeName() ); @@ -144,6 +145,22 @@ void RimPlotCurveAppearance::fieldChangedByUi( const caf::PdmFieldHandle* change appearanceChanged.send(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPlotCurveAppearance ::defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) +{ + if ( field == &m_fillColorTransparency ) + { + caf::PdmUiDoubleSliderEditorAttribute* myAttr = dynamic_cast( attribute ); + if ( myAttr ) + { + myAttr->m_minimum = 0.0; + myAttr->m_maximum = 1.0; + } + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -207,8 +224,10 @@ void RimPlotCurveAppearance::defineUiOrdering( QString uiConfigName, caf::PdmUiO if ( m_fillStyle != Qt::BrushStyle::NoBrush ) { uiOrdering.add( &m_fillColor ); + uiOrdering.add( &m_fillColorTransparency ); } m_fillColor.uiCapability()->setUiHidden( !m_fillOptionsVisible ); + m_fillColorTransparency.uiCapability()->setUiHidden( !m_fillOptionsVisible ); uiOrdering.add( &m_curveInterpolation ); m_curveInterpolation.uiCapability()->setUiHidden( !m_interpolationVisible ); @@ -416,6 +435,22 @@ void RimPlotCurveAppearance::setFillColor( const cvf::Color3f& fillColor ) m_fillColor = fillColor; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPlotCurveAppearance::setFillColorTransparency( float fillColorTransparency ) +{ + m_fillColorTransparency = fillColorTransparency; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +float RimPlotCurveAppearance::fillColorTransparency() const +{ + return m_fillColorTransparency; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/RimPlotCurveAppearance.h b/ApplicationLibCode/ProjectDataModel/RimPlotCurveAppearance.h index 4050d47117..7be5b2f262 100644 --- a/ApplicationLibCode/ProjectDataModel/RimPlotCurveAppearance.h +++ b/ApplicationLibCode/ProjectDataModel/RimPlotCurveAppearance.h @@ -86,6 +86,9 @@ public: void setFillColor( const cvf::Color3f& fillColor ); cvf::Color3f fillColor() const; + void setFillColorTransparency( float fillColorTransparency ); + float fillColorTransparency() const; + float curveFittingTolerance() const; void setInterpolation( RiuQwtPlotCurveDefines::CurveInterpolationEnum ); @@ -101,7 +104,9 @@ protected: // Overridden PDM methods void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override; - void initAfterRead() override; + void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; + + void initAfterRead() override; protected: caf::PdmField m_symbolLabel; @@ -117,6 +122,7 @@ protected: caf::PdmField m_lineStyle; caf::PdmField m_fillStyle; caf::PdmField m_fillColor; + caf::PdmField m_fillColorTransparency; caf::PdmField m_curveInterpolation; caf::PdmField m_symbolLabelPosition; caf::PdmField m_symbolEdgeColor;