From f0be8214b090facb53bd2c85270993dbfed43416 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Fri, 11 May 2018 13:18:53 +0200 Subject: [PATCH] #2448 Summary plot: Retain auto zoom for axes you haven't modified the range for. --- .../Summary/RimSummaryAxisProperties.cpp | 21 +- .../Summary/RimSummaryAxisProperties.h | 3 + .../Summary/RimSummaryPlot.cpp | 245 ++++++++++-------- .../ProjectDataModel/Summary/RimSummaryPlot.h | 12 +- .../Summary/RimSummaryTimeAxisProperties.cpp | 23 +- .../Summary/RimSummaryTimeAxisProperties.h | 4 + 6 files changed, 182 insertions(+), 126 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryAxisProperties.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryAxisProperties.cpp index c9506375a0..82b66119b2 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryAxisProperties.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryAxisProperties.cpp @@ -83,6 +83,7 @@ RimSummaryAxisProperties::RimSummaryAxisProperties() numberOfDecimals.uiCapability()->setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName()); + CAF_PDM_InitField(&m_isAutoZoom, "AutoZoom", true, "Set Range Automatically", "", "", ""); CAF_PDM_InitField(&isLogarithmicScaleEnabled, "LogarithmicScale", false, "Logarithmic Scale", "", "", ""); updateOptionSensitivity(); @@ -251,6 +252,22 @@ bool RimSummaryAxisProperties::showUnitText() const return m_displayUnitText(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimSummaryAxisProperties::isAutoZoom() const +{ + return m_isAutoZoom(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSummaryAxisProperties::setAutoZoom(bool enableAutoZoom) +{ + m_isAutoZoom = enableAutoZoom; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -278,13 +295,13 @@ void RimSummaryAxisProperties::fieldChangedByUi(const caf::PdmFieldHandle* chang { if (visibleRangeMin > visibleRangeMax) visibleRangeMax = oldValue.toDouble(); - rimSummaryPlot->disableAutoZoom(); + m_isAutoZoom = false; } else if (changedField == &visibleRangeMin) { if (visibleRangeMin > visibleRangeMax) visibleRangeMin = oldValue.toDouble(); - rimSummaryPlot->disableAutoZoom(); + m_isAutoZoom = false; } if (changedField == &isLogarithmicScaleEnabled) diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryAxisProperties.h b/ApplicationCode/ProjectDataModel/Summary/RimSummaryAxisProperties.h index 8b33b27e7b..2c56271a18 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryAxisProperties.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryAxisProperties.h @@ -61,6 +61,8 @@ public: bool showDescription() const; bool showAcronym() const; bool showUnitText() const; + bool isAutoZoom() const; + void setAutoZoom(bool enableAutoZoom); caf::PdmField customTitle; caf::PdmField titleFontSize; @@ -98,6 +100,7 @@ private: caf::PdmField m_displayShortName; caf::PdmField m_displayLongName; caf::PdmField m_displayUnitText; + caf::PdmField m_isAutoZoom; caf::PdmField m_name; QwtPlot::Axis m_axis; diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp index 3f46ecfae3..76199aacdc 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp @@ -120,9 +120,9 @@ RimSummaryPlot::RimSummaryPlot() m_timeAxisProperties.uiCapability()->setUiTreeHidden(true); m_timeAxisProperties = new RimSummaryTimeAxisProperties; - CAF_PDM_InitField(&m_isAutoZoom, "AutoZoom", true, "Auto Zoom", "", "", ""); - m_isAutoZoom.uiCapability()->setUiHidden(true); - + CAF_PDM_InitField(&m_isAutoZoom_OBSOLETE, "AutoZoom", true, "Auto Zoom", "", "", ""); + m_isAutoZoom_OBSOLETE.uiCapability()->setUiHidden(true); + m_isAutoZoom_OBSOLETE.xmlCapability()->setIOWritable(false); setAsPlotMdiWindow(); m_isCrossPlot = false; @@ -153,8 +153,6 @@ void RimSummaryPlot::updateAxes() updateAxis(RiaDefines::PLOT_AXIS_LEFT); updateAxis(RiaDefines::PLOT_AXIS_RIGHT); - updateZoomInQwt(); - if (m_isCrossPlot) { updateBottomXAxis(); @@ -163,6 +161,8 @@ void RimSummaryPlot::updateAxes() { updateTimeAxis(); } + + updateZoomInQwt(); } //-------------------------------------------------------------------------------------------------- @@ -619,43 +619,79 @@ void RimSummaryPlot::updateAxis(RiaDefines::PlotAxis plotAxis) //-------------------------------------------------------------------------------------------------- void RimSummaryPlot::updateZoomForAxis(RiaDefines::PlotAxis plotAxis) { - RimSummaryAxisProperties* yAxisProps = yAxisPropertiesLeftOrRight(plotAxis); - - if (yAxisProps->isLogarithmicScaleEnabled) + if (plotAxis == RiaDefines::PLOT_AXIS_BOTTOM) { - std::vector yValues; - std::vector plotCurves; - - for (RimSummaryCurve* c : visibleSummaryCurvesForAxis(plotAxis)) + if (m_isCrossPlot) { - std::vector curveValues = c->valuesY(); - yValues.insert(yValues.end(), curveValues.begin(), curveValues.end()); - plotCurves.push_back(c->qwtPlotCurve()); + if (m_bottomAxisProperties->isAutoZoom()) + { + m_qwtPlot->setAxisAutoScale(QwtPlot::xBottom, true); + } + else + { + m_qwtPlot->setAxisScale(QwtPlot::xBottom, m_bottomAxisProperties->visibleRangeMin(), m_bottomAxisProperties->visibleRangeMax()); + } } - - for (RimGridTimeHistoryCurve* c : visibleTimeHistoryCurvesForAxis(plotAxis)) + else { - std::vector curveValues = c->yValues(); - yValues.insert(yValues.end(), curveValues.begin(), curveValues.end()); - plotCurves.push_back(c->qwtPlotCurve()); + if (m_timeAxisProperties->isAutoZoom()) + { + m_qwtPlot->setAxisAutoScale(QwtPlot::xBottom, true); + } + else + { + m_qwtPlot->setAxisScale(QwtPlot::xBottom, m_timeAxisProperties->visibleRangeMin(), m_timeAxisProperties->visibleRangeMax()); + } + } - - for (RimAsciiDataCurve* c : visibleAsciiDataCurvesForAxis(plotAxis)) - { - std::vector curveValues = c->yValues(); - yValues.insert(yValues.end(), curveValues.begin(), curveValues.end()); - plotCurves.push_back(c->qwtPlotCurve()); - } - - double min, max; - RimSummaryPlotYAxisRangeCalculator calc(plotCurves, yValues); - calc.computeYRange(&min, &max); - - m_qwtPlot->setAxisScale(yAxisProps->qwtPlotAxisType(), min, max); } else { - m_qwtPlot->setAxisAutoScale(yAxisProps->qwtPlotAxisType(), true); + RimSummaryAxisProperties* yAxisProps = yAxisPropertiesLeftOrRight(plotAxis); + + if (yAxisProps->isAutoZoom()) + { + if (yAxisProps->isLogarithmicScaleEnabled) + { + std::vector yValues; + std::vector plotCurves; + + for (RimSummaryCurve* c : visibleSummaryCurvesForAxis(plotAxis)) + { + std::vector curveValues = c->valuesY(); + yValues.insert(yValues.end(), curveValues.begin(), curveValues.end()); + plotCurves.push_back(c->qwtPlotCurve()); + } + + for (RimGridTimeHistoryCurve* c : visibleTimeHistoryCurvesForAxis(plotAxis)) + { + std::vector curveValues = c->yValues(); + yValues.insert(yValues.end(), curveValues.begin(), curveValues.end()); + plotCurves.push_back(c->qwtPlotCurve()); + } + + for (RimAsciiDataCurve* c : visibleAsciiDataCurvesForAxis(plotAxis)) + { + std::vector curveValues = c->yValues(); + yValues.insert(yValues.end(), curveValues.begin(), curveValues.end()); + plotCurves.push_back(c->qwtPlotCurve()); + } + + double min, max; + RimSummaryPlotYAxisRangeCalculator calc(plotCurves, yValues); + calc.computeYRange(&min, &max); + + m_qwtPlot->setAxisScale(yAxisProps->qwtPlotAxisType(), min, max); + } + else + { + m_qwtPlot->setAxisAutoScale(yAxisProps->qwtPlotAxisType(), true); + } + } + else + { + m_qwtPlot->setAxisScale(yAxisProps->qwtPlotAxisType(), yAxisProps->visibleRangeMin(), yAxisProps->visibleRangeMax()); + } } } @@ -895,53 +931,15 @@ void RimSummaryPlot::updateCaseNameHasChanged() } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimSummaryPlot::setZoomWindow(const QwtInterval& leftAxis, const QwtInterval& rightAxis, const QwtInterval& timeAxis) -{ - m_leftYAxisProperties->visibleRangeMax = leftAxis.maxValue(); - m_leftYAxisProperties->visibleRangeMin = leftAxis.minValue(); - m_leftYAxisProperties->updateConnectedEditors(); - - m_rightYAxisProperties->visibleRangeMax = rightAxis.maxValue(); - m_rightYAxisProperties->visibleRangeMin = rightAxis.minValue(); - m_rightYAxisProperties->updateConnectedEditors(); - - if (m_isCrossPlot) - { - m_bottomAxisProperties->visibleRangeMax = timeAxis.maxValue(); - m_bottomAxisProperties->visibleRangeMin = timeAxis.minValue(); - m_bottomAxisProperties->updateConnectedEditors(); - } - else - { - m_timeAxisProperties->setVisibleRangeMin(timeAxis.minValue()); - m_timeAxisProperties->setVisibleRangeMax(timeAxis.maxValue()); - m_timeAxisProperties->updateConnectedEditors(); - } - - disableAutoZoom(); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimSummaryPlot::zoomAll() { - if (m_qwtPlot) - { - m_qwtPlot->setAxisAutoScale(QwtPlot::xBottom, true); + setAutoZoomForAllAxes(true); + updateZoomInQwt(); + updateAxisRangesFromQwt(); - updateZoomForAxis(RiaDefines::PLOT_AXIS_LEFT); - updateZoomForAxis(RiaDefines::PLOT_AXIS_RIGHT); - - m_qwtPlot->replot(); - } - - updateZoomWindowFromQwt(); - - m_isAutoZoom = true; } //-------------------------------------------------------------------------------------------------- @@ -1260,42 +1258,15 @@ void RimSummaryPlot::onLoadDataAndUpdate() //-------------------------------------------------------------------------------------------------- void RimSummaryPlot::updateZoomInQwt() { - if (!m_qwtPlot) return; - - if (m_isAutoZoom) + if (m_qwtPlot) { - zoomAll(); - } - else - { - setZoomIntervalsInQwtPlot(); - } -} -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimSummaryPlot::setZoomIntervalsInQwtPlot() -{ - QwtInterval left, right, time; + updateZoomForAxis(RiaDefines::PLOT_AXIS_BOTTOM); + updateZoomForAxis(RiaDefines::PLOT_AXIS_LEFT); + updateZoomForAxis(RiaDefines::PLOT_AXIS_RIGHT); - left.setMinValue(m_leftYAxisProperties->visibleRangeMin()); - left.setMaxValue(m_leftYAxisProperties->visibleRangeMax()); - right.setMinValue(m_rightYAxisProperties->visibleRangeMin()); - right.setMaxValue(m_rightYAxisProperties->visibleRangeMax()); - - if (m_isCrossPlot) - { - time.setMinValue(m_bottomAxisProperties->visibleRangeMin()); - time.setMaxValue(m_bottomAxisProperties->visibleRangeMax()); + m_qwtPlot->replot(); } - else - { - time.setMinValue(m_timeAxisProperties->visibleRangeMin()); - time.setMaxValue(m_timeAxisProperties->visibleRangeMax()); - } - - m_qwtPlot->setZoomWindow(left, right, time); } //-------------------------------------------------------------------------------------------------- @@ -1303,20 +1274,59 @@ void RimSummaryPlot::setZoomIntervalsInQwtPlot() //-------------------------------------------------------------------------------------------------- void RimSummaryPlot::updateZoomWindowFromQwt() { - if (!m_qwtPlot) return; - - QwtInterval left, right, time; - m_qwtPlot->currentVisibleWindow(&left, &right, &time); - - setZoomWindow(left, right, time); + updateAxisRangesFromQwt(); + setAutoZoomForAllAxes(false); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimSummaryPlot::disableAutoZoom() +void RimSummaryPlot::updateAxisRangesFromQwt() { - m_isAutoZoom = false; + if (!m_qwtPlot) return; + + QwtInterval leftAxis, rightAxis, timeAxis; + m_qwtPlot->currentVisibleWindow(&leftAxis, &rightAxis, &timeAxis); + + m_leftYAxisProperties->visibleRangeMax = leftAxis.maxValue(); + m_leftYAxisProperties->visibleRangeMin = leftAxis.minValue(); + m_leftYAxisProperties->updateConnectedEditors(); + + m_rightYAxisProperties->visibleRangeMax = rightAxis.maxValue(); + m_rightYAxisProperties->visibleRangeMin = rightAxis.minValue(); + m_rightYAxisProperties->updateConnectedEditors(); + + if (m_isCrossPlot) + { + m_bottomAxisProperties->visibleRangeMax = timeAxis.maxValue(); + m_bottomAxisProperties->visibleRangeMin = timeAxis.minValue(); + m_bottomAxisProperties->updateConnectedEditors(); + } + else + { + m_timeAxisProperties->setVisibleRangeMin(timeAxis.minValue()); + m_timeAxisProperties->setVisibleRangeMax(timeAxis.maxValue()); + m_timeAxisProperties->updateConnectedEditors(); + } + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSummaryPlot::setAutoZoomForAllAxes(bool enableAutoZoom) +{ + m_leftYAxisProperties->setAutoZoom(enableAutoZoom); + m_rightYAxisProperties->setAutoZoom(enableAutoZoom); + + if (m_isCrossPlot) + { + m_bottomAxisProperties->setAutoZoom(enableAutoZoom); + } + else + { + m_timeAxisProperties->setAutoZoom(enableAutoZoom); + } } //-------------------------------------------------------------------------------------------------- @@ -1458,6 +1468,11 @@ void RimSummaryPlot::initAfterRead() m_summaryCurveCollection->addCurve(curve); } + if (!m_isAutoZoom_OBSOLETE()) + { + setAutoZoomForAllAxes(false); + } + RimProject* proj = nullptr; this->firstAncestorOrThisOfType(proj); if (proj) diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h index 226a830a7b..13bc433faa 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h @@ -89,13 +89,9 @@ public: void updateAxes(); virtual void zoomAll() override; - void setZoomWindow(const QwtInterval& leftAxis, - const QwtInterval& rightAxis, - const QwtInterval& timeAxis); void updateZoomInQwt(); void updateZoomWindowFromQwt(); - void disableAutoZoom(); bool isLogarithmicScaleEnabled(RiaDefines::PlotAxis plotAxis) const; @@ -154,11 +150,14 @@ private: RimSummaryAxisProperties* yAxisPropertiesLeftOrRight(RiaDefines::PlotAxis leftOrRightPlotAxis) const; void updateAxis(RiaDefines::PlotAxis plotAxis); + void updateZoomForAxis(RiaDefines::PlotAxis plotAxis); void updateTimeAxis(); void updateBottomXAxis(); - void setZoomIntervalsInQwtPlot(); + + void updateAxisRangesFromQwt(); + void setAutoZoomForAllAxes(bool enableAutoZoom); private: caf::PdmField m_showPlotTitle; @@ -174,7 +173,6 @@ private: caf::PdmChildArrayField m_asciiDataCurves; - caf::PdmField m_isAutoZoom; caf::PdmChildField m_leftYAxisProperties; caf::PdmChildField m_rightYAxisProperties; @@ -191,4 +189,6 @@ private: // Obsolete fields caf::PdmChildArrayField m_summaryCurves_OBSOLETE; caf::PdmChildArrayField m_curveFilters_OBSOLETE; + caf::PdmField m_isAutoZoom_OBSOLETE; + }; diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryTimeAxisProperties.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryTimeAxisProperties.cpp index 320cd2c864..c6af806b1a 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryTimeAxisProperties.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryTimeAxisProperties.cpp @@ -82,6 +82,7 @@ RimSummaryTimeAxisProperties::RimSummaryTimeAxisProperties() CAF_PDM_InitField(&titleFontSize, "FontSize", 11, "Font Size", "", "", ""); CAF_PDM_InitField(&valuesFontSize, "ValuesFontSize", 11, "Font Size", "", "", ""); + CAF_PDM_InitField(&m_isAutoZoom, "AutoZoom", true, "Set Range Automatically", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_timeMode, "TimeMode", "Time Mode", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_timeUnit, "TimeUnit", "Time Unit", "", "", ""); @@ -158,6 +159,22 @@ void RimSummaryTimeAxisProperties::setVisibleRangeMax(double value) auto s = m_visibleDateRangeMax().toString(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimSummaryTimeAxisProperties::isAutoZoom() const +{ + return m_isAutoZoom; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSummaryTimeAxisProperties::setAutoZoom(bool enableAutoZoom) +{ + m_isAutoZoom = enableAutoZoom; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -362,7 +379,7 @@ void RimSummaryTimeAxisProperties::fieldChangedByUi(const caf::PdmFieldHandle* c } updateTimeVisibleRange(); - rimSummaryPlot->disableAutoZoom(); + m_isAutoZoom = false; } else if (changedField == &m_visibleDateRangeMin) { @@ -373,12 +390,12 @@ void RimSummaryTimeAxisProperties::fieldChangedByUi(const caf::PdmFieldHandle* c } updateTimeVisibleRange(); - rimSummaryPlot->disableAutoZoom(); + m_isAutoZoom = false; } else if (changedField == &m_visibleTimeRangeMin || changedField == &m_visibleTimeRangeMax) { updateDateVisibleRange(); - rimSummaryPlot->disableAutoZoom(); + m_isAutoZoom = false; } else if (changedField == &m_timeMode) { diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryTimeAxisProperties.h b/ApplicationCode/ProjectDataModel/Summary/RimSummaryTimeAxisProperties.h index b476775466..451236dca2 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryTimeAxisProperties.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryTimeAxisProperties.h @@ -78,6 +78,9 @@ public: void setVisibleRangeMin(double value); void setVisibleRangeMax(double value); + bool isAutoZoom() const; + void setAutoZoom(bool enableAutoZoom); + bool isActive() const; protected: @@ -100,4 +103,5 @@ private: caf::PdmField m_visibleDateRangeMax; caf::PdmField m_visibleTimeRangeMin; caf::PdmField m_visibleTimeRangeMax; + caf::PdmField m_isAutoZoom; };