From ca9140900266f5629600995a99242aafd7bec9b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Jensen?= Date: Mon, 11 Dec 2017 11:37:31 +0100 Subject: [PATCH] #969, #2240 Summary curve axis. New fields, scaleFactor and numberOfDigits --- .../Summary/RimSummaryAxisProperties.cpp | 29 ++++++++ .../Summary/RimSummaryAxisProperties.h | 2 + .../Summary/RimSummaryCurvesCalculator.cpp | 74 ++++++++++++------- 3 files changed, 77 insertions(+), 28 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryAxisProperties.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryAxisProperties.cpp index b6dcecb473..89a18b3329 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryAxisProperties.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryAxisProperties.cpp @@ -21,6 +21,10 @@ #include "RimSummaryPlot.h" #include "RiaDefines.h" +#include "cafPdmUiSliderEditor.h" + +#include + namespace caf { @@ -72,6 +76,11 @@ RimSummaryAxisProperties::RimSummaryAxisProperties() CAF_PDM_InitField(&visibleRangeMin, "VisibleRangeMin", RiaDefines::minimumDefaultValuePlot(), "Min", "", "", ""); CAF_PDM_InitFieldNoDefault(&numberFormat, "NumberFormat", "Number Format", "", "", ""); + CAF_PDM_InitField(&numberOfDecimals, "Decimals", 2, "Number of Decimals", "", "", ""); + CAF_PDM_InitField(&scaleFactor, "ScaleFactor", 1.0, "Scale Factor", "", "", ""); + + numberOfDecimals.uiCapability()->setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName()); + CAF_PDM_InitField(&isLogarithmicScaleEnabled, "LogarithmicScale", false, "Logarithmic Scale", "", "", ""); @@ -109,6 +118,18 @@ QList RimSummaryAxisProperties::calculateValueOptions(co options.push_back(caf::PdmOptionItemInfo(text, value)); } } + else if (fieldNeedingOptions == &scaleFactor) + { + for (int exp = -12; exp <= 12; exp += 3) + { + QString uiText = + exp == 0 ? "1" : + QString("10 ^ %1").arg(exp); + double value = std::pow(10, exp); + + options.push_back(caf::PdmOptionItemInfo(uiText, value)); + } + } return options; } @@ -127,9 +148,17 @@ void RimSummaryAxisProperties::defineUiOrdering(QString uiConfigName, caf::PdmUi caf::PdmUiGroup& scaleGroup = *(uiOrdering.addNewGroup("Axis Values")); scaleGroup.add(&isLogarithmicScaleEnabled); scaleGroup.add(&numberFormat); + + if (numberFormat() != NUMBER_FORMAT_AUTO) + { + scaleGroup.add(&numberOfDecimals); + scaleGroup.add(&scaleFactor); + } + scaleGroup.add(&visibleRangeMin); scaleGroup.add(&visibleRangeMax); + uiOrdering.skipRemainingFields(true); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryAxisProperties.h b/ApplicationCode/ProjectDataModel/Summary/RimSummaryAxisProperties.h index f86be9008e..cc66800f49 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryAxisProperties.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryAxisProperties.h @@ -70,6 +70,8 @@ public: caf::PdmField visibleRangeMax; caf::PdmField< caf::AppEnum< NumberFormatType > > numberFormat; + caf::PdmField numberOfDecimals; + caf::PdmField scaleFactor; caf::PdmField isLogarithmicScaleEnabled; diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCurvesCalculator.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCurvesCalculator.cpp index 5a4aecf0ea..60b4e905db 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCurvesCalculator.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCurvesCalculator.cpp @@ -46,51 +46,58 @@ class DecimalScaleDraw : public QwtScaleDraw { public: + DecimalScaleDraw(double scaleFactor, int numberOfDecimals) + { + m_scaleFactor = scaleFactor; + m_numberOfDecimals = numberOfDecimals; + } + virtual QwtText label(double value) const override { - if (qFuzzyCompare(value + 1.0, 1.0)) + if (qFuzzyCompare(scaledValue(value) + 1.0, 1.0)) value = 0.0; - int precision = DecimalScaleDraw::calculatePrecision(value); - - return QString::number(value, 'f', precision); + return QString::number(scaledValue(value), 'f', m_numberOfDecimals); } private: - static int calculatePrecision(double value) + double scaledValue(double value) const { - double absVal = fabs(value); - - const int numberOfDigits = 2; - - if (1e-16 < absVal && absVal < 1.0e3) - { - int logVal = static_cast(log10(absVal)); - int numDigitsAfterPoint = abs(logVal - numberOfDigits); - return numDigitsAfterPoint; - } - else - { - return numberOfDigits; - } + return value / m_scaleFactor; } -}; + double m_scaleFactor; + int m_numberOfDecimals; +}; //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- class ScientificScaleDraw : public QwtScaleDraw { - public: + ScientificScaleDraw(double scaleFactor, int numberOfDecimals) + { + m_scaleFactor = scaleFactor; + m_numberOfDecimals = numberOfDecimals; + } + virtual QwtText label(double value) const override { - if (qFuzzyCompare(value + 1.0, 1.0)) + if (qFuzzyCompare(scaledValue(value) + 1.0, 1.0)) value = 0.0; - return QString::number(value, 'e', 2); + return QString::number(scaledValue(value), 'e', m_numberOfDecimals); } + +private: + double scaledValue(double value) const + { + return value / m_scaleFactor; + } + + double m_scaleFactor; + int m_numberOfDecimals; }; @@ -108,7 +115,6 @@ RimSummaryPlotYAxisFormatter::RimSummaryPlotYAxisFormatter(RimSummaryAxisPropert { } - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -156,13 +162,14 @@ void RimSummaryPlotYAxisFormatter::applyYAxisPropertiesToPlot(RiuSummaryQwtPlot* } else if (m_axisProperties->numberFormat == RimSummaryAxisProperties::NUMBER_FORMAT_DECIMAL) { - qwtPlot->setAxisScaleDraw(m_axisProperties->qwtPlotAxisType(), new DecimalScaleDraw); + qwtPlot->setAxisScaleDraw(m_axisProperties->qwtPlotAxisType(), + new DecimalScaleDraw(m_axisProperties->scaleFactor(), m_axisProperties->numberOfDecimals())); } else if (m_axisProperties->numberFormat == RimSummaryAxisProperties::NUMBER_FORMAT_SCIENTIFIC) { - qwtPlot->setAxisScaleDraw(m_axisProperties->qwtPlotAxisType(), new ScientificScaleDraw()); + qwtPlot->setAxisScaleDraw(m_axisProperties->qwtPlotAxisType(), + new ScientificScaleDraw(m_axisProperties->scaleFactor(), m_axisProperties->numberOfDecimals())); } - } { @@ -214,6 +221,17 @@ QString RimSummaryPlotYAxisFormatter::autoAxisTitle() const } QString assembledYAxisText; + QString scaleFactorText = ""; + + if (m_axisProperties->numberFormat() != RimSummaryAxisProperties::NUMBER_FORMAT_AUTO) + { + if (m_axisProperties->scaleFactor() != 1.0) + { + int exponent = std::log10(m_axisProperties->scaleFactor()); + scaleFactorText = QString(" x 10%1 ").arg(QString::number(exponent)); + } + } + for ( auto unitIt : unitToQuantityNameMap ) { @@ -221,7 +239,7 @@ QString RimSummaryPlotYAxisFormatter::autoAxisTitle() const { assembledYAxisText += QString::fromStdString(quantIt) + " "; } - assembledYAxisText += "[" + QString::fromStdString(unitIt.first) + "] "; + assembledYAxisText += "[" + QString::fromStdString(unitIt.first) + scaleFactorText + "] "; } if (m_timeHistoryCurveQuantities.size() > 0)