mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Merge pull request #8387 from OPM/qtcharts-summary-plots
Closes #8228 Major refactoring of summary plotting. Now possible to create plots both with Qwt and QtChart as plotting tool.
This commit is contained in:
committed by
GitHub
parent
d9bb82de91
commit
258fbddc10
198
ApplicationLibCode/UserInterface/RiuSummaryPlot.cpp
Normal file
198
ApplicationLibCode/UserInterface/RiuSummaryPlot.cpp
Normal file
@@ -0,0 +1,198 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2019- 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 "RiuSummaryPlot.h"
|
||||
|
||||
#include "Commands/CorrelationPlotCommands/RicNewCorrelationPlotFeature.h"
|
||||
|
||||
#include "RimEnsembleCurveSet.h"
|
||||
#include "RimPlot.h"
|
||||
#include "RimSummaryCurve.h"
|
||||
#include "RimSummaryPlot.h"
|
||||
|
||||
#include "RiuPlotCurve.h"
|
||||
#include "RiuPlotWidget.h"
|
||||
|
||||
#include "cafCmdFeatureMenuBuilder.h"
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuSummaryPlot::RiuSummaryPlot( RimSummaryPlot* plot, QWidget* parent )
|
||||
: QWidget( parent )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuSummaryPlot::~RiuSummaryPlot()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuSummaryPlot::showContextMenu( QPoint pos )
|
||||
{
|
||||
QMenu menu;
|
||||
caf::CmdFeatureMenuBuilder menuBuilder;
|
||||
|
||||
menuBuilder << "RicShowPlotDataFeature";
|
||||
menuBuilder << "RicSavePlotTemplateFeature";
|
||||
|
||||
double distanceFromClick = std::numeric_limits<double>::infinity();
|
||||
|
||||
auto [plotCurve, closestCurvePoint] = plotWidget()->findClosestCurve( pos, distanceFromClick );
|
||||
|
||||
if ( plotCurve && closestCurvePoint >= 0 )
|
||||
{
|
||||
RimSummaryCurve* summaryCurve = dynamic_cast<RimSummaryCurve*>( plotCurve->ownerRimCurve() );
|
||||
if ( summaryCurve && closestCurvePoint < (int)summaryCurve->timeStepsY().size() )
|
||||
{
|
||||
std::time_t timeStep = summaryCurve->timeStepsY()[closestCurvePoint];
|
||||
|
||||
RimSummaryCaseCollection* ensemble = nullptr;
|
||||
QString clickedQuantityName;
|
||||
QStringList allQuantityNamesInPlot;
|
||||
|
||||
RimEnsembleCurveSet* clickedEnsembleCurveSet = nullptr;
|
||||
summaryCurve->firstAncestorOrThisOfType( clickedEnsembleCurveSet );
|
||||
|
||||
bool curveClicked = distanceFromClick < 50;
|
||||
|
||||
if ( clickedEnsembleCurveSet )
|
||||
{
|
||||
ensemble = clickedEnsembleCurveSet->summaryCaseCollection();
|
||||
if ( ensemble && ensemble->isEnsemble() )
|
||||
{
|
||||
clickedQuantityName = QString::fromStdString( clickedEnsembleCurveSet->summaryAddress().uiText() );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto summaryCase = summaryCurve->summaryCaseY();
|
||||
if ( summaryCase )
|
||||
{
|
||||
int summaryCaseId = summaryCase->caseId();
|
||||
QVariant summaryCaseIdVariant( summaryCaseId );
|
||||
auto modelName = summaryCase->nativeCaseName();
|
||||
|
||||
menuBuilder.addCmdFeatureWithUserData( "RicImportGridModelFromSummaryCurveFeature",
|
||||
QString( "Open Grid Model '%1'" ).arg( modelName ),
|
||||
summaryCaseIdVariant );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !curveClicked )
|
||||
{
|
||||
RimSummaryPlot* summaryPlot = static_cast<RimSummaryPlot*>( plotWidget()->plotDefinition() );
|
||||
std::vector<RimEnsembleCurveSet*> allCurveSetsInPlot;
|
||||
summaryPlot->descendantsOfType( allCurveSetsInPlot );
|
||||
for ( auto curveSet : allCurveSetsInPlot )
|
||||
{
|
||||
allQuantityNamesInPlot.push_back( QString::fromStdString( curveSet->summaryAddress().uiText() ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
allQuantityNamesInPlot.push_back( clickedQuantityName );
|
||||
}
|
||||
|
||||
if ( !clickedQuantityName.isEmpty() || !allQuantityNamesInPlot.isEmpty() )
|
||||
{
|
||||
if ( ensemble && ensemble->isEnsemble() )
|
||||
{
|
||||
EnsemblePlotParams params( ensemble, allQuantityNamesInPlot, clickedQuantityName, timeStep );
|
||||
QVariant variant = QVariant::fromValue( params );
|
||||
|
||||
menuBuilder.addCmdFeatureWithUserData( "RicNewAnalysisPlotFeature", "New Analysis Plot", variant );
|
||||
|
||||
QString subMenuName = "Create Correlation Plot";
|
||||
if ( curveClicked )
|
||||
{
|
||||
subMenuName = "Create Correlation Plot From Curve Point";
|
||||
}
|
||||
menuBuilder.subMenuStart( subMenuName, *caf::IconProvider( ":/CorrelationPlots16x16.png" ).icon() );
|
||||
|
||||
{
|
||||
if ( curveClicked )
|
||||
{
|
||||
menuBuilder.addCmdFeatureWithUserData( "RicNewCorrelationPlotFeature",
|
||||
"New Tornado Plot",
|
||||
variant );
|
||||
}
|
||||
menuBuilder.addCmdFeatureWithUserData( "RicNewCorrelationMatrixPlotFeature",
|
||||
"New Matrix Plot",
|
||||
variant );
|
||||
menuBuilder.addCmdFeatureWithUserData( "RicNewCorrelationReportPlotFeature",
|
||||
"New Report Plot",
|
||||
variant );
|
||||
if ( curveClicked )
|
||||
{
|
||||
menuBuilder.subMenuStart( "Cross Plots",
|
||||
*caf::IconProvider( ":/CorrelationCrossPlot16x16.png" ).icon() );
|
||||
std::vector<std::pair<RigEnsembleParameter, double>> ensembleParameters =
|
||||
ensemble->parameterCorrelations( clickedEnsembleCurveSet->summaryAddress(), timeStep );
|
||||
std::sort( ensembleParameters.begin(),
|
||||
ensembleParameters.end(),
|
||||
[]( const std::pair<RigEnsembleParameter, double>& lhs,
|
||||
const std::pair<RigEnsembleParameter, double>& rhs ) {
|
||||
return std::fabs( lhs.second ) > std::fabs( rhs.second );
|
||||
} );
|
||||
|
||||
for ( const auto& param : ensembleParameters )
|
||||
{
|
||||
if ( std::fabs( param.second ) >= 1.0e-6 )
|
||||
{
|
||||
params.ensembleParameter = param.first.name;
|
||||
variant = QVariant::fromValue( params );
|
||||
menuBuilder.addCmdFeatureWithUserData( "RicNewParameterResultCrossPlotFeature",
|
||||
QString( "New Cross Plot Against %1 "
|
||||
"(Correlation: %2)" )
|
||||
.arg( param.first.name )
|
||||
.arg( param.second, 5, 'f', 2 ),
|
||||
variant );
|
||||
}
|
||||
}
|
||||
menuBuilder.subMenuEnd();
|
||||
}
|
||||
}
|
||||
menuBuilder.subMenuEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
menuBuilder.appendToMenu( &menu );
|
||||
|
||||
if ( menu.actions().size() > 0 )
|
||||
{
|
||||
menu.exec( mapToGlobal( pos ) );
|
||||
|
||||
// Parts of progress dialog GUI can be present after menu has closed related to
|
||||
// RicImportGridModelFromSummaryCurveFeature. Make sure the plot is updated, and call processEvents() to make
|
||||
// sure all GUI events are processed
|
||||
plotWidget()->update();
|
||||
QApplication::processEvents();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user