mirror of
https://github.com/OPM/ResInsight.git
synced 2026-11-13 09:37:29 -06:00
Add RimViewWindow::setContainingViewWindow/activationWindow, set explicitly by multi plots, depth track plots, and the correlation, RFT correlation, well allocation and well distribution plots. RiuPlotMainWindow resolves the selected window through activationWindow, and the duplicated multi plot activation code is merged.
476 lines
17 KiB
C++
476 lines
17 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// 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 "RimWellDistributionPlotCollection.h"
|
|
|
|
#include "RiaColorTools.h"
|
|
#include "RiaPreferences.h"
|
|
|
|
#include "RimEclipseCaseTools.h"
|
|
#include "RimEclipseResultCase.h"
|
|
#include "RimFlowDiagSolution.h"
|
|
#include "RimPlot.h"
|
|
#include "RimTools.h"
|
|
#include "RimWellDistributionPlot.h"
|
|
|
|
#include "RigEclipseCaseData.h"
|
|
#include "RigTofWellDistributionCalculator.h"
|
|
|
|
#include "RiuMultiPlotPage.h"
|
|
#include "RiuPlotWidget.h"
|
|
#include "RiuQwtPlotTools.h"
|
|
#include "RiuQwtPlotWidget.h"
|
|
|
|
#include "qwt_legend.h"
|
|
#include "qwt_plot.h"
|
|
#include "qwt_plot_curve.h"
|
|
|
|
#include "cafAssert.h"
|
|
|
|
#include <QGridLayout>
|
|
#include <QTextBrowser>
|
|
#include <QWidget>
|
|
|
|
//==================================================================================================
|
|
//
|
|
//
|
|
//
|
|
//==================================================================================================
|
|
|
|
CAF_PDM_SOURCE_INIT( RimWellDistributionPlotCollection, "WellDistributionPlotCollection" );
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimWellDistributionPlotCollection::RimWellDistributionPlotCollection()
|
|
{
|
|
// cvf::Trace::show("RimWellDistributionPlotCollection::RimWellDistributionPlotCollection()");
|
|
|
|
CAF_PDM_InitObject( "Cumulative Phase Distribution Plot", ":/CumulativePhaseDist16x16.png" );
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_case, "Case", "Case" );
|
|
CAF_PDM_InitField( &m_timeStepIndex, "TimeStepIndex", -1, "Time Step" );
|
|
CAF_PDM_InitField( &m_wellName, "WellName", QString( "None" ), "Well" );
|
|
CAF_PDM_InitField( &m_groupSmallContributions, "GroupSmallContributions", true, "Group Small Contributions" );
|
|
CAF_PDM_InitField( &m_smallContributionsRelativeThreshold, "SmallContributionsRelativeThreshold", 0.005, "Relative Threshold [0, 1]" );
|
|
|
|
CAF_PDM_InitField( &m_maximumTof, "MaximumTOF", 20.0, "Maximum Time of Flight [0, 200]" );
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_plots, "Plots", "" );
|
|
m_plots.uiCapability()->setUiTreeChildrenHidden( true );
|
|
|
|
CAF_PDM_InitField( &m_showOil, "ShowOil", true, "Show Oil" );
|
|
CAF_PDM_InitField( &m_showGas, "ShowGas", true, "Show Gas" );
|
|
CAF_PDM_InitField( &m_showWater, "ShowWater", true, "Show Water" );
|
|
|
|
CAF_PDM_InitField( &m_plotWindowTitle, "PlotDescription", QString( "Cumulative Phase Distribution Plots" ), "Name" );
|
|
|
|
m_showWindow = false;
|
|
|
|
dockAsPlotWindow();
|
|
|
|
addPlot( new RimWellDistributionPlot( RiaDefines::PhaseType::OIL_PHASE ) );
|
|
addPlot( new RimWellDistributionPlot( RiaDefines::PhaseType::GAS_PHASE ) );
|
|
addPlot( new RimWellDistributionPlot( RiaDefines::PhaseType::WATER_PHASE ) );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimWellDistributionPlotCollection::~RimWellDistributionPlotCollection()
|
|
{
|
|
removeWindowFromDock();
|
|
m_plots.deleteChildren();
|
|
|
|
cleanupBeforeClose();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellDistributionPlotCollection::setData( RimEclipseResultCase* eclipseCase, QString wellName, int timeStepIndex )
|
|
{
|
|
m_case = eclipseCase;
|
|
m_wellName = wellName;
|
|
m_timeStepIndex = timeStepIndex;
|
|
|
|
applyPlotParametersToContainedPlots();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellDistributionPlotCollection::setWellName( const QString& wellName )
|
|
{
|
|
m_wellName = wellName;
|
|
applyPlotParametersToContainedPlots();
|
|
loadDataAndUpdate();
|
|
if ( m_viewer ) m_viewer->scheduleUpdate();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellDistributionPlotCollection::setTimeStep( int timeStep )
|
|
{
|
|
if ( timeStep < 0 ) return;
|
|
|
|
m_timeStepIndex = timeStep;
|
|
applyPlotParametersToContainedPlots();
|
|
loadDataAndUpdate();
|
|
if ( m_viewer ) m_viewer->scheduleUpdate();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QWidget* RimWellDistributionPlotCollection::viewWidget()
|
|
{
|
|
return m_viewer;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QString RimWellDistributionPlotCollection::description() const
|
|
{
|
|
return m_plotWindowTitle;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QImage RimWellDistributionPlotCollection::snapshotWindowContent()
|
|
{
|
|
QImage image;
|
|
|
|
if ( m_viewer )
|
|
{
|
|
QPixmap pix( m_viewer->size() );
|
|
m_viewer->renderTo( &pix );
|
|
image = pix.toImage();
|
|
}
|
|
|
|
return image;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellDistributionPlotCollection::zoomAll()
|
|
{
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
caf::PdmFieldHandle* RimWellDistributionPlotCollection::userDescriptionField()
|
|
{
|
|
return &m_plotWindowTitle;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellDistributionPlotCollection::onLoadDataAndUpdate()
|
|
{
|
|
// cvf::Trace::show("RimWellDistributionPlotCollection::onLoadDataAndUpdate()");
|
|
updateDockWindowVisibility();
|
|
updatePlots();
|
|
updateLayout();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QWidget* RimWellDistributionPlotCollection::createViewWidget( QWidget* mainWindowParent )
|
|
{
|
|
m_viewer = new RiuMultiPlotPage( this, mainWindowParent );
|
|
m_viewer->setPlotTitle( m_plotWindowTitle );
|
|
|
|
auto pointSize =
|
|
caf::FontTools::absolutePointSize( RiaPreferences::current()->defaultPlotFontSize(), caf::FontTools::RelativeSize::XLarge );
|
|
|
|
m_viewer->setTitleFontSizes( pointSize, pointSize );
|
|
|
|
recreatePlotWidgets();
|
|
|
|
return m_viewer;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellDistributionPlotCollection::deleteViewWidget()
|
|
{
|
|
cleanupBeforeClose();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellDistributionPlotCollection::doRenderWindowContent( QPaintDevice* paintDevice )
|
|
{
|
|
if ( m_viewer )
|
|
{
|
|
m_viewer->renderTo( paintDevice );
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellDistributionPlotCollection::initAfterRead()
|
|
{
|
|
for ( RimPlot* plot : m_plots )
|
|
{
|
|
plot->setContainingViewWindow( this );
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellDistributionPlotCollection::addPlot( RimPlot* plot )
|
|
{
|
|
if ( plot )
|
|
{
|
|
size_t index = m_plots.size();
|
|
m_plots.insert( index, plot );
|
|
plot->setContainingViewWindow( this );
|
|
|
|
if ( m_viewer )
|
|
{
|
|
plot->createPlotWidget();
|
|
m_viewer->insertPlot( plot->plotWidget(), index );
|
|
}
|
|
plot->setShowWindow( true );
|
|
plot->setLegendsVisible( false );
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellDistributionPlotCollection::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
|
{
|
|
uiOrdering.add( &m_case );
|
|
uiOrdering.add( &m_timeStepIndex );
|
|
uiOrdering.add( &m_wellName );
|
|
uiOrdering.add( &m_groupSmallContributions );
|
|
uiOrdering.add( &m_smallContributionsRelativeThreshold );
|
|
uiOrdering.add( &m_maximumTof );
|
|
|
|
uiOrdering.add( &m_showOil );
|
|
uiOrdering.add( &m_showGas );
|
|
uiOrdering.add( &m_showWater );
|
|
|
|
m_smallContributionsRelativeThreshold.uiCapability()->setUiReadOnly( m_groupSmallContributions == false );
|
|
|
|
// RimMultiPlotWindow::defineUiOrdering(uiConfigName, uiOrdering);
|
|
uiOrdering.skipRemainingFields();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QList<caf::PdmOptionItemInfo> RimWellDistributionPlotCollection::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions )
|
|
{
|
|
QList<caf::PdmOptionItemInfo> options = RimPlotWindow::calculateValueOptions( fieldNeedingOptions );
|
|
|
|
if ( fieldNeedingOptions == &m_case )
|
|
{
|
|
auto resultCases = RimEclipseCaseTools::eclipseResultCases();
|
|
for ( RimEclipseResultCase* c : resultCases )
|
|
{
|
|
options.push_back( caf::PdmOptionItemInfo( c->caseUserDescription(), c, true, c->uiIconProvider() ) );
|
|
}
|
|
}
|
|
|
|
else if ( fieldNeedingOptions == &m_timeStepIndex )
|
|
{
|
|
RimTools::timeStepsForCase( m_case, &options );
|
|
|
|
if ( options.empty() )
|
|
{
|
|
options.push_back( caf::PdmOptionItemInfo( "None", -1 ) );
|
|
}
|
|
}
|
|
|
|
else if ( fieldNeedingOptions == &m_wellName )
|
|
{
|
|
if ( m_case && m_case->eclipseCaseData() )
|
|
{
|
|
caf::IconProvider simWellIcon( ":/Well.svg" );
|
|
const std::set<QString> sortedWellNameSet = m_case->eclipseCaseData()->findSortedWellNames();
|
|
for ( const QString& name : sortedWellNameSet )
|
|
{
|
|
options.push_back( caf::PdmOptionItemInfo( name, name, true, simWellIcon ) );
|
|
}
|
|
}
|
|
|
|
if ( options.empty() )
|
|
{
|
|
options.push_back( caf::PdmOptionItemInfo( "None", QVariant() ) );
|
|
}
|
|
}
|
|
|
|
return options;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellDistributionPlotCollection::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
|
|
const QVariant& oldValue,
|
|
const QVariant& newValue )
|
|
{
|
|
if ( changedField == &m_case )
|
|
{
|
|
fixupDependentFieldsAfterCaseChange();
|
|
}
|
|
|
|
bool shouldRecalculatePlotData = false;
|
|
if ( changedField == &m_case || changedField == &m_timeStepIndex || changedField == &m_wellName ||
|
|
changedField == &m_groupSmallContributions || changedField == &m_smallContributionsRelativeThreshold || changedField == &m_maximumTof ||
|
|
changedField == &m_showOil || changedField == &m_showGas || changedField == &m_showWater || changedField == &m_showWindow )
|
|
{
|
|
applyPlotParametersToContainedPlots();
|
|
shouldRecalculatePlotData = true;
|
|
|
|
if ( changedField == &m_showOil || changedField == &m_showGas || changedField == &m_showWater || changedField == &m_showWindow )
|
|
{
|
|
if ( m_viewer ) m_viewer->scheduleUpdate();
|
|
}
|
|
}
|
|
|
|
RimPlotWindow::fieldChangedByUi( changedField, oldValue, newValue );
|
|
|
|
if ( shouldRecalculatePlotData )
|
|
{
|
|
loadDataAndUpdate();
|
|
updateLayout();
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellDistributionPlotCollection::applyPlotParametersToContainedPlots()
|
|
{
|
|
const size_t numPlots = m_plots.size();
|
|
for ( size_t i = 0; i < numPlots; i++ )
|
|
{
|
|
// Dirty usage of dyn_cast, but type is lost when adding the plots to our base class
|
|
RimWellDistributionPlot* aPlot = dynamic_cast<RimWellDistributionPlot*>( m_plots[i] );
|
|
if ( aPlot )
|
|
{
|
|
if ( aPlot->phase() == RiaDefines::PhaseType::OIL_PHASE )
|
|
{
|
|
aPlot->setShowWindow( m_showOil );
|
|
}
|
|
else if ( aPlot->phase() == RiaDefines::PhaseType::GAS_PHASE )
|
|
{
|
|
aPlot->setShowWindow( m_showGas );
|
|
}
|
|
else if ( aPlot->phase() == RiaDefines::PhaseType::WATER_PHASE )
|
|
{
|
|
aPlot->setShowWindow( m_showWater );
|
|
}
|
|
|
|
aPlot->setDataSourceParameters( m_case, m_timeStepIndex, m_wellName );
|
|
aPlot->setPlotOptions( m_groupSmallContributions, m_smallContributionsRelativeThreshold, m_maximumTof );
|
|
}
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellDistributionPlotCollection::updatePlots()
|
|
{
|
|
if ( m_showWindow )
|
|
{
|
|
for ( RimPlot* plot : m_plots() )
|
|
{
|
|
plot->loadDataAndUpdate();
|
|
plot->updatePlotWidgetFromAxisRanges();
|
|
}
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellDistributionPlotCollection::cleanupBeforeClose()
|
|
{
|
|
auto plotVector = m_plots.childrenByType();
|
|
for ( size_t tIdx = 0; tIdx < plotVector.size(); ++tIdx )
|
|
{
|
|
plotVector[tIdx]->detachAllCurves();
|
|
}
|
|
|
|
if ( m_viewer )
|
|
{
|
|
m_viewer->setParent( nullptr );
|
|
delete m_viewer;
|
|
m_viewer = nullptr;
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellDistributionPlotCollection::recreatePlotWidgets()
|
|
{
|
|
CAF_ASSERT( m_viewer );
|
|
|
|
for ( auto plot : m_plots() )
|
|
{
|
|
plot->createPlotWidget();
|
|
m_viewer->addPlot( plot->plotWidget() );
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimWellDistributionPlotCollection::fixupDependentFieldsAfterCaseChange()
|
|
{
|
|
int newTimeStepIndex = -1;
|
|
QString newWellName;
|
|
|
|
if ( m_case )
|
|
{
|
|
const int timeStepCount = m_case->timeStepStrings().size();
|
|
if ( timeStepCount > 0 )
|
|
{
|
|
newTimeStepIndex = timeStepCount - 1;
|
|
}
|
|
|
|
const std::set<QString> sortedWellNameSet = m_case->eclipseCaseData()->findSortedWellNames();
|
|
if ( !sortedWellNameSet.empty() )
|
|
{
|
|
newWellName = *sortedWellNameSet.begin();
|
|
}
|
|
}
|
|
|
|
m_timeStepIndex = newTimeStepIndex;
|
|
m_wellName = newWellName;
|
|
}
|