diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicViewZoomAllFeature.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicViewZoomAllFeature.cpp index da86f7ee92..8e31643879 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicViewZoomAllFeature.cpp +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicViewZoomAllFeature.cpp @@ -51,7 +51,7 @@ void RicViewZoomAllFeature::onActionTriggered( bool isChecked ) { if ( auto activePlotView = plotMainWin->activeViewer() ) { - activePlotView->zoomAll(); + activePlotView->zoomAllAndReleaseUserDefinedRanges(); } } } diff --git a/ApplicationLibCode/ProjectDataModel/RimPlotAxisProperties.cpp b/ApplicationLibCode/ProjectDataModel/RimPlotAxisProperties.cpp index 47e2abdef5..793d3f6a52 100644 --- a/ApplicationLibCode/ProjectDataModel/RimPlotAxisProperties.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimPlotAxisProperties.cpp @@ -586,14 +586,14 @@ double RimPlotAxisProperties::visibleRangeMax() const //-------------------------------------------------------------------------------------------------- void RimPlotAxisProperties::enableAutoValueMinMax( bool enable ) { + // Never replace a range defined by the user by an automatically computed range + const bool useAutoValue = enable && !isRangeUserDefined(); + m_visibleRangeMin.uiCapability()->enableAutoValueSupport( enable ); m_visibleRangeMax.uiCapability()->enableAutoValueSupport( enable ); - if ( enable ) - { - m_visibleRangeMin.uiCapability()->enableAutoValue( enable ); - m_visibleRangeMax.uiCapability()->enableAutoValue( enable ); - } + m_visibleRangeMin.uiCapability()->enableAutoValue( useAutoValue ); + m_visibleRangeMax.uiCapability()->enableAutoValue( useAutoValue ); } //-------------------------------------------------------------------------------------------------- @@ -711,12 +711,22 @@ void RimPlotAxisProperties::fieldChangedByUi( const caf::PdmFieldHandle* changed if ( m_visibleRangeMin > m_visibleRangeMax ) m_visibleRangeMax = oldValue.toDouble(); m_isAutoZoom = false; + + // The range is defined by the user unless the value comes from the auto value of the field + setRangeUserDefined( !m_visibleRangeMax.uiCapability()->isAutoValueEnabled() ); } else if ( changedField == &m_visibleRangeMin ) { if ( m_visibleRangeMin > m_visibleRangeMax ) m_visibleRangeMin = oldValue.toDouble(); m_isAutoZoom = false; + + // The range is defined by the user unless the value comes from the auto value of the field + setRangeUserDefined( !m_visibleRangeMin.uiCapability()->isAutoValueEnabled() ); + } + else if ( changedField == &m_isAutoZoom ) + { + setRangeUserDefined( !m_isAutoZoom() ); } if ( changedField == &m_isLogarithmicScaleEnabled ) diff --git a/ApplicationLibCode/ProjectDataModel/RimPlotAxisPropertiesInterface.cpp b/ApplicationLibCode/ProjectDataModel/RimPlotAxisPropertiesInterface.cpp index dd0dba3c2c..ba0d67b0a0 100644 --- a/ApplicationLibCode/ProjectDataModel/RimPlotAxisPropertiesInterface.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimPlotAxisPropertiesInterface.cpp @@ -51,6 +51,26 @@ RimPlotAxisPropertiesInterface::RimPlotAxisPropertiesInterface() : settingsChanged( this ) { CAF_PDM_InitObject( "Plot Axis Properties Interface" ); + + CAF_PDM_InitField( &m_isRangeUserDefined, "IsRangeUserDefined", false, "Is Range Defined by User" ); + m_isRangeUserDefined.uiCapability()->setUiHidden( true ); +} + +//-------------------------------------------------------------------------------------------------- +/// A user defined axis range is kept when the data source of a plot is changed, and is released when the user asks for +/// automatic range computation (Zoom All or "Set Range Automatically"). +//-------------------------------------------------------------------------------------------------- +bool RimPlotAxisPropertiesInterface::isRangeUserDefined() const +{ + return m_isRangeUserDefined(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPlotAxisPropertiesInterface::setRangeUserDefined( bool isUserDefined ) +{ + m_isRangeUserDefined = isUserDefined; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/RimPlotAxisPropertiesInterface.h b/ApplicationLibCode/ProjectDataModel/RimPlotAxisPropertiesInterface.h index f180411bd0..e886e70943 100644 --- a/ApplicationLibCode/ProjectDataModel/RimPlotAxisPropertiesInterface.h +++ b/ApplicationLibCode/ProjectDataModel/RimPlotAxisPropertiesInterface.h @@ -65,6 +65,9 @@ class RimPlotAxisPropertiesInterface : public caf::PdmObject virtual bool isAutoZoom() const = 0; virtual void setAutoZoom( bool enableAutoZoom ) = 0; + bool isRangeUserDefined() const; + void setRangeUserDefined( bool isUserDefined ); + virtual bool isActive() const = 0; virtual const QString objectName() const = 0; @@ -83,4 +86,7 @@ class RimPlotAxisPropertiesInterface : public caf::PdmObject virtual AxisTitlePositionType titlePosition() const = 0; virtual int titleFontSize() const = 0; virtual int valuesFontSize() const = 0; + +private: + caf::PdmField m_isRangeUserDefined; }; diff --git a/ApplicationLibCode/ProjectDataModel/RimViewWindow.cpp b/ApplicationLibCode/ProjectDataModel/RimViewWindow.cpp index 7cd3dad2be..fd827af2f2 100644 --- a/ApplicationLibCode/ProjectDataModel/RimViewWindow.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimViewWindow.cpp @@ -226,6 +226,14 @@ QImage RimViewWindow::snapshotWindowContent() return image; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimViewWindow::zoomAllAndReleaseUserDefinedRanges() +{ + zoomAll(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/RimViewWindow.h b/ApplicationLibCode/ProjectDataModel/RimViewWindow.h index 27f524d3fe..4b35770d62 100644 --- a/ApplicationLibCode/ProjectDataModel/RimViewWindow.h +++ b/ApplicationLibCode/ProjectDataModel/RimViewWindow.h @@ -72,6 +72,9 @@ class RimViewWindow : public caf::PdmObject, public caf::FontHolderInterface virtual QImage snapshotWindowContent(); virtual void zoomAll() = 0; + // Zoom all triggered explicitly by the user. This will also release any axis ranges defined by the user. + virtual void zoomAllAndReleaseUserDefinedRanges(); + void viewNavigationChanged(); virtual void updateWindowTitle(); diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp index 3b12e83fe2..03182a20cb 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp @@ -470,6 +470,15 @@ void RimSummaryMultiPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedFi } else if ( changedField == &m_axisRangeAggregation ) { + // The user has asked for a new computation of the Y axis range, release any user defined ranges + for ( auto p : summaryPlots() ) + { + for ( auto axis : p->plotAxes( RimPlotAxisProperties::Orientation::VERTICAL ) ) + { + axis->setRangeUserDefined( false ); + } + } + setAutoValueStates(); syncAxisRanges(); analyzePlotsAndAdjustAppearanceSettings(); @@ -798,6 +807,19 @@ void RimSummaryMultiPlot::zoomAll() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSummaryMultiPlot::zoomAllAndReleaseUserDefinedRanges() +{ + for ( auto p : summaryPlots() ) + { + p->releaseUserDefinedAxisRanges(); + } + + zoomAll(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.h b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.h index 7fdb44f2ca..9f96959152 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.h +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.h @@ -98,6 +98,7 @@ class RimSummaryMultiPlot : public RimMultiPlot, public RimSummaryDataSourceStep std::pair gridLayoutInfoForSubPlot( RimSummaryPlot* summaryPlot ) const; void zoomAll() override; + void zoomAllAndReleaseUserDefinedRanges() override; void setDefaultRangeAggregationSteppingDimension(); void analyzePlotsAndAdjustAppearanceSettings(); diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp index 7d1f8e6d8a..0e71b21cd2 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp @@ -1404,6 +1404,28 @@ void RimSummaryPlot::zoomAll() axisChanged.send( this ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSummaryPlot::zoomAllAndReleaseUserDefinedRanges() +{ + releaseUserDefinedAxisRanges(); + + zoomAll(); +} + +//-------------------------------------------------------------------------------------------------- +/// Axis ranges defined by the user are kept when the data source of the plot is changed. Release the user defined +/// ranges to make the axes follow the data again. +//-------------------------------------------------------------------------------------------------- +void RimSummaryPlot::releaseUserDefinedAxisRanges() +{ + for ( const auto& ap : m_axisPropertiesArray ) + { + ap->setRangeUserDefined( false ); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1602,7 +1624,7 @@ void RimSummaryPlot::zoomAllForMultiPlot() { if ( auto multiPlot = firstAncestorOrThisOfType() ) { - multiPlot->zoomAll(); + multiPlot->zoomAllAndReleaseUserDefinedRanges(); } } @@ -2628,6 +2650,13 @@ void RimSummaryPlot::onPlotZoomed() setAutoScaleXEnabled( false ); setAutoScaleYEnabled( false ); + // The user has defined the visible range by interactive zoom, and the range is kept when the data source of the + // plot is changed + for ( const auto& ap : m_axisPropertiesArray ) + { + ap->setRangeUserDefined( true ); + } + // Disable auto value for min/max fields for ( auto p : plotAxes( RimPlotAxisProperties::Orientation::ANY ) ) { @@ -2998,6 +3027,8 @@ void RimSummaryPlot::setAutoScaleXEnabled( bool enabled ) { if ( ap->plotAxis().axis() == RiaDefines::PlotAxis::PLOT_AXIS_TOP || ap->plotAxis().axis() == RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM ) { + if ( enabled && ap->isRangeUserDefined() ) continue; + ap->setAutoZoom( enabled ); } } @@ -3012,6 +3043,8 @@ void RimSummaryPlot::setAutoScaleYEnabled( bool enabled ) { if ( ap->plotAxis().axis() == RiaDefines::PlotAxis::PLOT_AXIS_LEFT || ap->plotAxis().axis() == RiaDefines::PlotAxis::PLOT_AXIS_RIGHT ) { + if ( enabled && ap->isRangeUserDefined() ) continue; + ap->setAutoZoom( enabled ); } } diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h index 31a34833d9..82ca8df9a2 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h @@ -186,6 +186,8 @@ class RimSummaryPlot : public RimPlot, public RimSummaryDataSourceStepping, publ RiuPlotWidget* plotWidget() override; RiuSummaryPlot* summaryPlotWidget() const; void zoomAll() override; + void zoomAllAndReleaseUserDefinedRanges() override; + void releaseUserDefinedAxisRanges(); void updatePlotWidgetFromAxisRanges() override; void updateAxisRangesFromPlotWidget() override; diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryTimeAxisProperties.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryTimeAxisProperties.cpp index b718d829fd..704d084b9c 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryTimeAxisProperties.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryTimeAxisProperties.cpp @@ -932,6 +932,7 @@ void RimSummaryTimeAxisProperties::fieldChangedByUi( const caf::PdmFieldHandle* updateTimeVisibleRange(); m_isAutoZoom = false; + setRangeUserDefined( true ); } else if ( changedField == &m_visibleTimeRangeMax ) { @@ -943,6 +944,7 @@ void RimSummaryTimeAxisProperties::fieldChangedByUi( const caf::PdmFieldHandle* updateTimeVisibleRange(); m_isAutoZoom = false; + setRangeUserDefined( true ); } else if ( changedField == &m_visibleDateRangeMin ) { @@ -954,6 +956,7 @@ void RimSummaryTimeAxisProperties::fieldChangedByUi( const caf::PdmFieldHandle* updateTimeVisibleRange(); m_isAutoZoom = false; + setRangeUserDefined( true ); } else if ( changedField == &m_visibleTimeRangeMin ) { @@ -965,11 +968,17 @@ void RimSummaryTimeAxisProperties::fieldChangedByUi( const caf::PdmFieldHandle* updateTimeVisibleRange(); m_isAutoZoom = false; + setRangeUserDefined( true ); } else if ( changedField == &m_visibleTimeSinceStartRangeMin || changedField == &m_visibleTimeSinceStartRangeMax ) { updateDateVisibleRange(); m_isAutoZoom = false; + setRangeUserDefined( true ); + } + else if ( changedField == &m_isAutoZoom ) + { + setRangeUserDefined( !m_isAutoZoom() ); } else if ( changedField == &m_timeMode ) {