mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Depth plot as docking widget (#9909)
* Add docked depth result plot for eclipse data * Update dock layout defaults
This commit is contained in:
309
ApplicationLibCode/UserInterface/RiuDepthQwtPlot.cpp
Normal file
309
ApplicationLibCode/UserInterface/RiuDepthQwtPlot.cpp
Normal file
@@ -0,0 +1,309 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2023 Equinor ASA
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RiuDepthQwtPlot.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaCurveDataTools.h"
|
||||
|
||||
#include "RimCase.h"
|
||||
#include "RimContextCommandBuilder.h"
|
||||
|
||||
#include "RiuQwtLinearScaleEngine.h"
|
||||
#include "RiuQwtPlotCurve.h"
|
||||
#include "RiuQwtPlotTools.h"
|
||||
#include "RiuQwtSymbol.h"
|
||||
#include "RiuTextDialog.h"
|
||||
|
||||
#include "cvfColor3.h"
|
||||
|
||||
#include "qwt_legend.h"
|
||||
#include "qwt_plot_curve.h"
|
||||
#include "qwt_plot_grid.h"
|
||||
#include "qwt_plot_layout.h"
|
||||
#include "qwt_scale_engine.h"
|
||||
|
||||
#include <QContextMenuEvent>
|
||||
#include <QMenu>
|
||||
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuDepthQwtPlot::RiuDepthQwtPlot( QWidget* parent )
|
||||
: RiuDockedQwtPlot( parent )
|
||||
, m_bShowDepth( true )
|
||||
{
|
||||
setAutoFillBackground( true );
|
||||
setDefaults();
|
||||
resetRanges();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuDepthQwtPlot::~RiuDepthQwtPlot()
|
||||
{
|
||||
deleteAllCurves();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuDepthQwtPlot::resetRanges()
|
||||
{
|
||||
m_minX = std::numeric_limits<double>::max();
|
||||
m_minY = std::numeric_limits<double>::max();
|
||||
m_maxX = std::numeric_limits<double>::lowest();
|
||||
m_maxY = std::numeric_limits<double>::lowest();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuDepthQwtPlot::addCurve( const RimCase* rimCase,
|
||||
const QString& curveName,
|
||||
const cvf::Color3f& curveColor,
|
||||
const std::vector<int>& kIndexes,
|
||||
const std::vector<double>& depthValues,
|
||||
const std::vector<double>& resultValues )
|
||||
{
|
||||
if ( kIndexes.empty() || resultValues.empty() || depthValues.empty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<double> kValues;
|
||||
|
||||
if ( m_bShowDepth )
|
||||
{
|
||||
kValues = depthValues;
|
||||
setAxisTitle( QwtAxis::YLeft, "Depth" );
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( auto k : kIndexes )
|
||||
{
|
||||
kValues.push_back( 1.0 * k + 1.0 ); // adjust to eclipse index
|
||||
}
|
||||
setAxisTitle( QwtAxis::YLeft, "K" );
|
||||
}
|
||||
|
||||
double yMax = *std::max_element( kValues.begin(), kValues.end() );
|
||||
double yMin = *std::min_element( kValues.begin(), kValues.end() );
|
||||
m_maxY = std::max( yMax, m_maxY );
|
||||
m_minY = std::min( yMin, m_minY );
|
||||
|
||||
std::vector<double> tmpResultValues;
|
||||
|
||||
for ( auto val : resultValues )
|
||||
{
|
||||
if ( std::isinf( val ) )
|
||||
tmpResultValues.push_back( std::nan( "" ) );
|
||||
else
|
||||
{
|
||||
if ( val > m_maxX ) m_maxX = val;
|
||||
if ( val < m_minX ) m_minX = val;
|
||||
tmpResultValues.push_back( val );
|
||||
}
|
||||
}
|
||||
|
||||
RiuQwtPlotCurve* plotCurve = new RiuQwtPlotCurve( nullptr );
|
||||
|
||||
plotCurve->setSamplesFromXValuesAndYValues( tmpResultValues, kValues, false );
|
||||
plotCurve->setTitle( curveName );
|
||||
plotCurve->setAxes( QwtAxis::XTop, QwtAxis::YLeft );
|
||||
|
||||
auto color = QColor( curveColor.rByte(), curveColor.gByte(), curveColor.bByte() );
|
||||
|
||||
plotCurve->setPen( QPen( color ) );
|
||||
|
||||
RiuQwtSymbol* symbol = new RiuQwtSymbol( RiuPlotCurveSymbol::SYMBOL_XCROSS, "" );
|
||||
symbol->setSize( 6, 6 );
|
||||
symbol->setColor( color );
|
||||
plotCurve->setSymbol( symbol );
|
||||
|
||||
plotCurve->attach( this );
|
||||
m_plotCurves.push_back( plotCurve );
|
||||
|
||||
updateAxisScaling();
|
||||
|
||||
this->applyFontSizes( false );
|
||||
|
||||
this->replot();
|
||||
|
||||
int caseId = rimCase->caseId();
|
||||
|
||||
m_caseNames[caseId] = rimCase->caseUserDescription();
|
||||
m_curveNames[caseId].push_back( curveName );
|
||||
m_curveData[caseId].push_back( resultValues );
|
||||
m_kSteps[caseId] = kIndexes;
|
||||
m_depthValues[caseId] = depthValues;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuDepthQwtPlot::deleteAllCurves()
|
||||
{
|
||||
for ( size_t i = 0; i < m_plotCurves.size(); i++ )
|
||||
{
|
||||
m_plotCurves[i]->detach();
|
||||
delete m_plotCurves[i];
|
||||
}
|
||||
|
||||
m_plotCurves.clear();
|
||||
|
||||
m_caseNames.clear();
|
||||
m_curveNames.clear();
|
||||
m_curveData.clear();
|
||||
m_kSteps.clear();
|
||||
m_depthValues.clear();
|
||||
|
||||
resetRanges();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QSize RiuDepthQwtPlot::sizeHint() const
|
||||
{
|
||||
return QSize( 100, 100 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QSize RiuDepthQwtPlot::minimumSizeHint() const
|
||||
{
|
||||
return QSize( 0, 0 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuDepthQwtPlot::contextMenuEvent( QContextMenuEvent* event )
|
||||
{
|
||||
QMenu menu;
|
||||
|
||||
const int curveCount = this->itemList( QwtPlotItem::Rtti_PlotCurve ).count();
|
||||
|
||||
QAction* act = menu.addAction( "Show Plot Data", this, SLOT( slotCurrentPlotDataInTextDialog() ) );
|
||||
act->setEnabled( curveCount > 0 );
|
||||
|
||||
if ( !menu.actions().empty() )
|
||||
{
|
||||
menu.exec( event->globalPos() );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuDepthQwtPlot::setDefaults()
|
||||
{
|
||||
RiuQwtPlotTools::setCommonPlotBehaviour( this );
|
||||
|
||||
setAxesCount( QwtAxis::XTop, 1 );
|
||||
setAxesCount( QwtAxis::YLeft, 1 );
|
||||
|
||||
setAxisVisible( QwtAxis::XTop, true );
|
||||
setAxisVisible( QwtAxis::XBottom, false );
|
||||
|
||||
setAxisMaxMinor( QwtAxis::XTop, 2 );
|
||||
setAxisMaxMinor( QwtAxis::YLeft, 6 );
|
||||
|
||||
applyFontSizes( false );
|
||||
|
||||
QwtLegend* legend = new QwtLegend( this );
|
||||
insertLegend( legend, BottomLegend );
|
||||
|
||||
RiuQwtPlotTools::enableGridLines( this, QwtAxis::XBottom, false, false );
|
||||
RiuQwtPlotTools::enableGridLines( this, QwtAxis::XTop, true, true );
|
||||
RiuQwtPlotTools::enableGridLines( this, QwtAxis::YLeft, true, true );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiuDepthQwtPlot::asciiDataForUiSelectedCurves() const
|
||||
{
|
||||
QString out;
|
||||
|
||||
for ( std::pair<int, QString> caseIdAndName : m_caseNames )
|
||||
{
|
||||
int caseId = caseIdAndName.first;
|
||||
out += "Case: " + caseIdAndName.second;
|
||||
out += "\n";
|
||||
|
||||
for ( size_t i = 0; i < m_kSteps.at( caseId ).size(); i++ ) // time steps & data points
|
||||
{
|
||||
if ( i == 0 )
|
||||
{
|
||||
out += "K Index";
|
||||
out += "\tDepth";
|
||||
for ( QString curveName : m_curveNames.at( caseId ) )
|
||||
{
|
||||
out += "\t" + curveName;
|
||||
}
|
||||
}
|
||||
out += "\n";
|
||||
|
||||
QString kString = QString::number( m_kSteps.at( caseId )[i] );
|
||||
|
||||
out += kString;
|
||||
|
||||
QString depthString = QString::number( m_depthValues.at( caseId )[i], 'f', 2 );
|
||||
out += "\t" + depthString;
|
||||
|
||||
for ( size_t j = 0; j < m_curveData.at( caseId ).size(); j++ ) // curves
|
||||
{
|
||||
out += "\t" + QString::number( m_curveData.at( caseId )[j][i], 'g', 6 );
|
||||
}
|
||||
}
|
||||
out += "\n\n";
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuDepthQwtPlot::slotCurrentPlotDataInTextDialog()
|
||||
{
|
||||
QString outTxt = asciiDataForUiSelectedCurves();
|
||||
|
||||
RiuTextDialog* textDialog = new RiuTextDialog( this );
|
||||
textDialog->setMinimumSize( 600, 600 );
|
||||
textDialog->setWindowTitle( "Depth Plot Data" );
|
||||
textDialog->setText( outTxt );
|
||||
textDialog->show();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuDepthQwtPlot::updateAxisScaling()
|
||||
{
|
||||
double valRangeX = m_maxX - m_minX;
|
||||
this->setAxisScale( QwtAxis::YLeft, m_maxY + 0.1, m_minY - 0.1 );
|
||||
this->setAxisScale( QwtAxis::XTop, m_minX - 0.02 * valRangeX, m_maxX + 0.1 * valRangeX );
|
||||
}
|
||||
Reference in New Issue
Block a user