2016-10-10 04:05:45 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2016 Statoil ASA
|
2019-04-09 02:50:51 -05:00
|
|
|
//
|
2016-10-10 04:05:45 -05:00
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2019-04-09 02:50:51 -05:00
|
|
|
//
|
2016-10-10 04:05:45 -05:00
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
2019-04-09 02:50:51 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2016-10-10 04:05:45 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-11-29 07:00:22 -06:00
|
|
|
#include "RimSummaryPlotAxisFormatter.h"
|
2016-10-10 04:05:45 -05:00
|
|
|
|
2017-06-13 08:41:52 -05:00
|
|
|
#include "RiaDefines.h"
|
2019-04-09 02:50:51 -05:00
|
|
|
|
2020-02-28 07:51:21 -06:00
|
|
|
#include "RifSummaryReaderInterface.h"
|
|
|
|
|
2017-08-17 07:24:49 -05:00
|
|
|
#include "RimAsciiDataCurve.h"
|
2019-04-09 02:50:51 -05:00
|
|
|
#include "RimPlotAxisProperties.h"
|
2020-02-28 07:51:21 -06:00
|
|
|
#include "RimSummaryCase.h"
|
|
|
|
#include "RimSummaryCaseCollection.h"
|
2019-04-09 02:50:51 -05:00
|
|
|
#include "RimSummaryCurve.h"
|
2016-10-10 04:05:45 -05:00
|
|
|
|
2019-10-18 07:28:02 -05:00
|
|
|
#include "RiuSummaryQuantityNameInfoProvider.h"
|
2016-10-10 04:05:45 -05:00
|
|
|
#include "RiuSummaryQwtPlot.h"
|
|
|
|
|
2019-12-17 12:29:51 -06:00
|
|
|
#include "qwt_date_scale_engine.h"
|
2016-10-10 04:05:45 -05:00
|
|
|
#include "qwt_plot_curve.h"
|
|
|
|
#include "qwt_scale_draw.h"
|
|
|
|
#include "qwt_scale_engine.h"
|
|
|
|
|
2019-04-09 02:50:51 -05:00
|
|
|
#include <cmath>
|
2016-10-10 04:05:45 -05:00
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-03-12 05:12:39 -05:00
|
|
|
// e format as [-]9.9e[+|-]999
|
|
|
|
// E format as[-]9.9E[+| -]999
|
|
|
|
// f format as[-]9.9
|
|
|
|
// g use e or f format, whichever is the most concise
|
|
|
|
// G use E or f format, whichever is the most concise
|
2016-10-10 04:05:45 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-07-26 04:37:58 -05:00
|
|
|
class SummaryScaleDraw : public QwtScaleDraw
|
2016-10-10 04:05:45 -05:00
|
|
|
{
|
|
|
|
public:
|
2019-09-06 03:40:57 -05:00
|
|
|
SummaryScaleDraw( double scaleFactor,
|
|
|
|
int numberOfDecimals,
|
|
|
|
RimPlotAxisProperties::NumberFormatType numberFormat = RimPlotAxisProperties::NUMBER_FORMAT_AUTO )
|
2017-12-11 04:37:31 -06:00
|
|
|
{
|
2019-04-09 02:50:51 -05:00
|
|
|
m_scaleFactor = scaleFactor;
|
2017-12-11 04:37:31 -06:00
|
|
|
m_numberOfDecimals = numberOfDecimals;
|
2019-07-26 04:37:58 -05:00
|
|
|
m_numberFormat = numberFormat;
|
2017-12-11 04:37:31 -06:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
QwtText label( double value ) const override
|
2016-10-10 04:05:45 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( qFuzzyCompare( scaledValue( value ) + 1.0, 1.0 ) ) value = 0.0;
|
2016-10-10 04:05:45 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
return QString::number( scaledValue( value ), numberFormat(), m_numberOfDecimals );
|
2016-10-10 04:05:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-07-26 04:37:58 -05:00
|
|
|
char numberFormat() const
|
2016-10-10 04:05:45 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
switch ( m_numberFormat )
|
2019-07-26 04:37:58 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
case RimPlotAxisProperties::NUMBER_FORMAT_AUTO:
|
|
|
|
return 'g';
|
|
|
|
case RimPlotAxisProperties::NUMBER_FORMAT_DECIMAL:
|
|
|
|
return 'f';
|
|
|
|
case RimPlotAxisProperties::NUMBER_FORMAT_SCIENTIFIC:
|
|
|
|
return 'e';
|
|
|
|
default:
|
|
|
|
return 'g';
|
2019-07-26 04:37:58 -05:00
|
|
|
}
|
2017-12-11 04:37:31 -06:00
|
|
|
}
|
|
|
|
|
2020-02-12 04:13:38 -06:00
|
|
|
double scaledValue( double value ) const { return value / m_scaleFactor; }
|
2017-12-11 04:37:31 -06:00
|
|
|
|
2019-07-26 04:37:58 -05:00
|
|
|
private:
|
|
|
|
double m_scaleFactor;
|
|
|
|
int m_numberOfDecimals;
|
|
|
|
RimPlotAxisProperties::NumberFormatType m_numberFormat;
|
2016-10-10 04:05:45 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-04-09 02:50:51 -05:00
|
|
|
///
|
2016-10-10 04:05:45 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-28 07:51:21 -06:00
|
|
|
RimSummaryPlotAxisFormatter::RimSummaryPlotAxisFormatter( RimPlotAxisProperties* axisProperties,
|
|
|
|
const std::vector<RimSummaryCurve*>& summaryCurves,
|
|
|
|
const std::vector<RiaSummaryCurveDefinition>& curveDefinitions,
|
|
|
|
const std::vector<RimAsciiDataCurve*>& asciiCurves,
|
2019-11-29 07:00:22 -06:00
|
|
|
const std::set<QString>& timeHistoryCurveQuantities )
|
2019-09-06 03:40:57 -05:00
|
|
|
: m_axisProperties( axisProperties )
|
|
|
|
, m_summaryCurves( summaryCurves )
|
2020-02-28 07:51:21 -06:00
|
|
|
, m_curveDefinitions( curveDefinitions )
|
2019-09-06 03:40:57 -05:00
|
|
|
, m_asciiDataCurves( asciiCurves )
|
|
|
|
, m_timeHistoryCurveQuantities( timeHistoryCurveQuantities )
|
2016-10-10 04:05:45 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-04-09 02:50:51 -05:00
|
|
|
///
|
2016-10-10 04:05:45 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-28 07:51:21 -06:00
|
|
|
void RimSummaryPlotAxisFormatter::applyAxisPropertiesToPlot( RiuQwtPlotWidget* qwtPlot )
|
2016-10-10 04:05:45 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !qwtPlot ) return;
|
2016-10-10 04:05:45 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
QString axisTitle = m_axisProperties->customTitle;
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( m_axisProperties->useAutoTitle() ) axisTitle = autoAxisTitle();
|
2016-10-10 04:05:45 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
QwtText axisTitleY = qwtPlot->axisTitle( m_axisProperties->qwtPlotAxisType() );
|
2016-10-10 04:05:45 -05:00
|
|
|
|
2019-10-31 09:37:30 -05:00
|
|
|
Qt::AlignmentFlag titleAlignment = Qt::AlignCenter;
|
|
|
|
if ( m_axisProperties->titlePosition() == RimPlotAxisPropertiesInterface::AXIS_TITLE_END )
|
2016-11-18 08:03:35 -06:00
|
|
|
{
|
2019-10-31 09:37:30 -05:00
|
|
|
titleAlignment = Qt::AlignRight;
|
2016-11-18 08:03:35 -06:00
|
|
|
}
|
2020-01-07 05:03:40 -06:00
|
|
|
qwtPlot->setAxisTitleText( m_axisProperties->qwtPlotAxisType(), axisTitle );
|
2019-10-31 07:48:40 -05:00
|
|
|
qwtPlot->setAxisFontsAndAlignment( m_axisProperties->qwtPlotAxisType(),
|
2020-06-02 10:23:54 -05:00
|
|
|
m_axisProperties->titleFontSize(),
|
|
|
|
m_axisProperties->valuesFontSize(),
|
2019-10-31 07:48:40 -05:00
|
|
|
true,
|
|
|
|
titleAlignment );
|
2019-11-29 03:13:39 -06:00
|
|
|
qwtPlot->setAxisTitleEnabled( m_axisProperties->qwtPlotAxisType(), true );
|
2016-10-10 04:05:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( m_axisProperties->numberFormat == RimPlotAxisProperties::NUMBER_FORMAT_AUTO &&
|
|
|
|
m_axisProperties->scaleFactor() == 1.0 )
|
2016-10-10 04:05:45 -05:00
|
|
|
{
|
2019-07-26 04:37:58 -05:00
|
|
|
// Default to Qwt's own scale draw to avoid changing too much for default values
|
2019-09-06 03:40:57 -05:00
|
|
|
qwtPlot->setAxisScaleDraw( m_axisProperties->qwtPlotAxisType(), new QwtScaleDraw );
|
2016-10-10 04:05:45 -05:00
|
|
|
}
|
2019-07-26 04:37:58 -05:00
|
|
|
else
|
2016-10-10 04:05:45 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
qwtPlot->setAxisScaleDraw( m_axisProperties->qwtPlotAxisType(),
|
|
|
|
new SummaryScaleDraw( m_axisProperties->scaleFactor(),
|
|
|
|
m_axisProperties->numberOfDecimals(),
|
|
|
|
m_axisProperties->numberFormat() ) );
|
2016-10-10 04:05:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( m_axisProperties->isLogarithmicScaleEnabled )
|
2016-10-10 04:05:45 -05:00
|
|
|
{
|
2020-02-12 04:43:15 -06:00
|
|
|
QwtLogScaleEngine* currentScaleEngine =
|
|
|
|
dynamic_cast<QwtLogScaleEngine*>( qwtPlot->axisScaleEngine( m_axisProperties->qwtPlotAxisType() ) );
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !currentScaleEngine )
|
2016-10-10 04:05:45 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
qwtPlot->setAxisScaleEngine( m_axisProperties->qwtPlotAxisType(), new QwtLogScaleEngine );
|
|
|
|
qwtPlot->setAxisMaxMinor( m_axisProperties->qwtPlotAxisType(), 5 );
|
2016-10-10 04:05:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-12 04:43:15 -06:00
|
|
|
QwtLinearScaleEngine* currentScaleEngine =
|
|
|
|
dynamic_cast<QwtLinearScaleEngine*>( qwtPlot->axisScaleEngine( m_axisProperties->qwtPlotAxisType() ) );
|
2019-12-17 12:29:51 -06:00
|
|
|
QwtDateScaleEngine* dateScaleEngine = dynamic_cast<QwtDateScaleEngine*>( currentScaleEngine );
|
|
|
|
if ( !currentScaleEngine || dateScaleEngine )
|
2016-10-10 04:05:45 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
qwtPlot->setAxisScaleEngine( m_axisProperties->qwtPlotAxisType(), new QwtLinearScaleEngine );
|
|
|
|
qwtPlot->setAxisMaxMinor( m_axisProperties->qwtPlotAxisType(), 3 );
|
2016-10-10 04:05:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-04-09 02:50:51 -05:00
|
|
|
///
|
2016-10-10 04:05:45 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-11-29 07:00:22 -06:00
|
|
|
QString RimSummaryPlotAxisFormatter::autoAxisTitle() const
|
2016-10-10 04:05:45 -05:00
|
|
|
{
|
2017-12-11 09:41:18 -06:00
|
|
|
std::map<std::string, std::set<std::string>> unitToQuantityNameMap;
|
2016-10-10 04:05:45 -05:00
|
|
|
|
2020-02-28 07:51:21 -06:00
|
|
|
// clang-format off
|
|
|
|
auto addToUnitToQuantityMap =[&]( const std::string& unitText,
|
|
|
|
const RifEclipseSummaryAddress& sumAddress )
|
|
|
|
{
|
|
|
|
std::string quantityNameForDisplay;
|
|
|
|
const std::string& quantityName = sumAddress.quantityName();
|
|
|
|
|
|
|
|
if ( sumAddress.category() == RifEclipseSummaryAddress::SUMMARY_CALCULATED )
|
|
|
|
{
|
|
|
|
quantityNameForDisplay = shortCalculationName( quantityName );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( m_axisProperties->showDescription() )
|
|
|
|
{
|
|
|
|
quantityNameForDisplay =
|
|
|
|
RiuSummaryQuantityNameInfoProvider::instance()->longNameFromQuantityName( quantityName );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_axisProperties->showAcronym() )
|
|
|
|
{
|
|
|
|
if ( !quantityNameForDisplay.empty() )
|
|
|
|
{
|
|
|
|
quantityNameForDisplay += " (";
|
|
|
|
quantityNameForDisplay += quantityName;
|
|
|
|
quantityNameForDisplay += ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( quantityNameForDisplay.empty() )
|
|
|
|
{
|
|
|
|
quantityNameForDisplay = quantityName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unitToQuantityNameMap[unitText].insert( quantityNameForDisplay );
|
|
|
|
};
|
|
|
|
|
|
|
|
// clang-format on
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( RimSummaryCurve* rimCurve : m_summaryCurves )
|
2016-10-10 04:05:45 -05:00
|
|
|
{
|
2017-12-11 09:41:18 -06:00
|
|
|
RifEclipseSummaryAddress sumAddress;
|
|
|
|
std::string unitText;
|
2017-12-11 07:44:16 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( rimCurve->summaryAddressY().category() == RifEclipseSummaryAddress::SUMMARY_ENSEMBLE_STATISTICS )
|
2018-06-26 03:27:41 -05:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-04-24 00:13:33 -05:00
|
|
|
else if ( m_axisProperties->plotAxisType() == RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM )
|
2017-12-11 09:41:18 -06:00
|
|
|
{
|
|
|
|
sumAddress = rimCurve->summaryAddressX();
|
|
|
|
unitText = rimCurve->unitNameX();
|
2017-11-15 04:36:33 -06:00
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
else if ( rimCurve->axisY() == this->m_axisProperties->plotAxisType() )
|
2017-12-11 09:41:18 -06:00
|
|
|
{
|
|
|
|
sumAddress = rimCurve->summaryAddressY();
|
|
|
|
unitText = rimCurve->unitNameY();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-02-28 07:51:21 -06:00
|
|
|
addToUnitToQuantityMap( unitText, sumAddress );
|
|
|
|
}
|
2017-12-11 09:41:18 -06:00
|
|
|
|
2020-02-28 07:51:21 -06:00
|
|
|
for ( const RiaSummaryCurveDefinition& curveDef : m_curveDefinitions )
|
|
|
|
{
|
|
|
|
RifEclipseSummaryAddress sumAddress = curveDef.summaryAddress();
|
|
|
|
std::string unitText;
|
|
|
|
if ( curveDef.summaryCase() && curveDef.summaryCase()->summaryReader() )
|
|
|
|
{
|
|
|
|
unitText = curveDef.summaryCase()->summaryReader()->unitName( sumAddress );
|
|
|
|
}
|
|
|
|
else if ( curveDef.ensemble() )
|
|
|
|
{
|
|
|
|
std::vector<RimSummaryCase*> sumCases = curveDef.ensemble()->allSummaryCases();
|
|
|
|
if ( sumCases.size() && sumCases[0] && sumCases[0]->summaryReader() )
|
2017-11-15 04:36:33 -06:00
|
|
|
{
|
2020-02-28 07:51:21 -06:00
|
|
|
unitText = sumCases[0]->summaryReader()->unitName( sumAddress );
|
2017-11-15 04:36:33 -06:00
|
|
|
}
|
2016-11-21 04:30:34 -06:00
|
|
|
}
|
2020-02-28 07:51:21 -06:00
|
|
|
|
|
|
|
addToUnitToQuantityMap( unitText, sumAddress );
|
2016-10-10 04:05:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QString assembledYAxisText;
|
2017-12-11 04:37:31 -06:00
|
|
|
QString scaleFactorText = "";
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( m_axisProperties->scaleFactor() != 1.0 )
|
2017-12-11 04:37:31 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
int exponent = std::log10( m_axisProperties->scaleFactor() );
|
|
|
|
scaleFactorText = QString( " x 10<sup>%1</sup> " ).arg( QString::number( exponent ) );
|
2017-12-11 04:37:31 -06:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( auto unitIt : unitToQuantityNameMap )
|
2016-10-10 04:05:45 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( const auto& quantIt : unitIt.second )
|
2016-11-21 04:30:34 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
assembledYAxisText += QString::fromStdString( quantIt ) + " ";
|
2016-11-21 04:30:34 -06:00
|
|
|
}
|
2017-12-11 07:54:54 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( m_axisProperties->showUnitText() )
|
2017-12-11 07:54:54 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QString unitAndScaleText = QString::fromStdString( unitIt.first ) + scaleFactorText;
|
2019-04-09 01:45:21 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !unitAndScaleText.isEmpty() )
|
2019-04-09 01:45:21 -05:00
|
|
|
{
|
|
|
|
assembledYAxisText += "[" + unitAndScaleText + "] ";
|
|
|
|
}
|
2017-12-11 07:54:54 -06:00
|
|
|
}
|
2016-10-10 04:05:45 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !m_timeHistoryCurveQuantities.empty() )
|
2017-03-19 02:45:29 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !assembledYAxisText.isEmpty() )
|
2017-03-19 02:45:29 -05:00
|
|
|
{
|
|
|
|
assembledYAxisText += " : ";
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( const auto& timeQuantity : m_timeHistoryCurveQuantities )
|
2017-03-19 02:45:29 -05:00
|
|
|
{
|
|
|
|
assembledYAxisText += timeQuantity + " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-10 04:05:45 -05:00
|
|
|
return assembledYAxisText;
|
|
|
|
}
|
|
|
|
|
2017-12-11 07:44:16 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-04-09 02:50:51 -05:00
|
|
|
///
|
2017-12-11 07:44:16 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-11-29 07:00:22 -06:00
|
|
|
std::string RimSummaryPlotAxisFormatter::shortCalculationName( const std::string& calculationName )
|
2017-12-11 07:44:16 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QString calculationShortName = QString::fromStdString( calculationName );
|
2016-11-18 08:03:35 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
int indexOfFirstSpace = calculationShortName.indexOf( ' ' );
|
|
|
|
if ( indexOfFirstSpace > -1 && indexOfFirstSpace < calculationShortName.size() )
|
2017-12-11 07:44:16 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
calculationShortName = calculationShortName.left( indexOfFirstSpace );
|
2017-12-11 07:44:16 -06:00
|
|
|
}
|
2016-11-18 08:03:35 -06:00
|
|
|
|
2017-12-11 07:44:16 -06:00
|
|
|
return calculationShortName.toStdString();
|
|
|
|
}
|