diff --git a/ApplicationLibCode/Application/RiaPlotDefines.cpp b/ApplicationLibCode/Application/RiaPlotDefines.cpp index a3c23c0812..5405da79f5 100644 --- a/ApplicationLibCode/Application/RiaPlotDefines.cpp +++ b/ApplicationLibCode/Application/RiaPlotDefines.cpp @@ -169,6 +169,14 @@ QString RiaDefines::namingVariableWaterDepth() return "$WATER_DEPTH"; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RiaDefines::selectionTextNone() +{ + return "None"; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/Application/RiaPlotDefines.h b/ApplicationLibCode/Application/RiaPlotDefines.h index 9cae9e693c..0ecaeeb8bc 100644 --- a/ApplicationLibCode/Application/RiaPlotDefines.h +++ b/ApplicationLibCode/Application/RiaPlotDefines.h @@ -93,6 +93,8 @@ QString namingVariableTimestep(); QString namingVariableAirGap(); QString namingVariableWaterDepth(); +QString selectionTextNone(); + double minimumDefaultValuePlot(); double minimumDefaultLogValuePlot(); double maximumDefaultValuePlot(); diff --git a/ApplicationLibCode/Application/Tools/RiaImportEclipseCaseTools.cpp b/ApplicationLibCode/Application/Tools/RiaImportEclipseCaseTools.cpp index 5785197e37..1bd15d442f 100644 --- a/ApplicationLibCode/Application/Tools/RiaImportEclipseCaseTools.cpp +++ b/ApplicationLibCode/Application/Tools/RiaImportEclipseCaseTools.cpp @@ -358,6 +358,8 @@ int RiaImportEclipseCaseTools::openEclipseCaseShowTimeStepFilterImpl( const QStr return -1; } + RimMainPlotCollection::current()->ensureDefaultFlowPlotsAreCreated(); + if ( createView ) { RimEclipseView* riv = rimResultReservoir->createAndAddReservoirView(); diff --git a/ApplicationLibCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationLibCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index 9c72a90eea..00c28d44e1 100644 --- a/ApplicationLibCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -19,10 +19,12 @@ #include "RimWellAllocationPlot.h" #include "RiaNumericalTools.h" +#include "RiaPlotDefines.h" #include "RiaPreferences.h" #include "RigAccWellFlowCalculator.h" #include "RigEclipseCaseData.h" +#include "RigEclipseCaseDataTools.h" #include "RigFlowDiagResultAddress.h" #include "RigFlowDiagResults.h" #include "RigSimWellData.h" @@ -95,7 +97,7 @@ RimWellAllocationPlot::RimWellAllocationPlot() m_case.uiCapability()->setUiTreeChildrenHidden( true ); CAF_PDM_InitField( &m_timeStep, "PlotTimeStep", 0, "Time Step" ); - CAF_PDM_InitField( &m_wellName, "WellName", QString( "None" ), "Well" ); + CAF_PDM_InitField( &m_wellName, "WellName", RiaDefines::selectionTextNone(), "Well" ); CAF_PDM_InitFieldNoDefault( &m_flowDiagSolution, "FlowDiagSolution", "Plot Type" ); CAF_PDM_InitFieldNoDefault( &m_flowType, "FlowType", "Flow Type" ); CAF_PDM_InitField( &m_groupSmallContributions, "GroupSmallContributions", true, "Group Small Contributions" ); @@ -219,6 +221,57 @@ void RimWellAllocationPlot::deleteViewWidget() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellAllocationPlot::setCase( RimEclipseResultCase* eclipseCase ) +{ + bool emptyPreviousCase = !m_case; + + m_case = eclipseCase; + + if ( m_case ) + { + m_flowDiagSolution = m_case->defaultFlowDiagSolution(); + } + else + { + m_flowDiagSolution = nullptr; + m_timeStep = 0; + } + + if ( !m_case ) + m_timeStep = 0; + else + { + if ( emptyPreviousCase ) + { + m_timeStep = (int)( m_case->timeStepDates().size() - 1 ); + } + + m_timeStep = std::min( m_timeStep(), ( (int)m_case->timeStepDates().size() ) - 1 ); + } + + if ( m_wellName().isEmpty() || m_wellName() == RiaDefines::selectionTextNone() ) + { + auto firstProducer = RigEclipseCaseDataTools::firstProducer( m_case->eclipseCaseData() ); + if ( !firstProducer.isEmpty() ) + { + m_wellName = firstProducer; + } + else + { + std::set sortedWellNames = findSortedWellNames(); + if ( sortedWellNames.empty() ) + m_wellName = RiaDefines::selectionTextNone(); + else if ( sortedWellNames.count( m_wellName() ) == 0 ) + { + m_wellName = *sortedWellNames.begin(); + } + } + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -732,36 +785,26 @@ void RimWellAllocationPlot::fieldChangedByUi( const caf::PdmFieldHandle* changed { RimViewWindow::fieldChangedByUi( changedField, oldValue, newValue ); + if ( changedField == &m_showWindow ) + { + if ( !m_case ) + { + auto resultCases = RimEclipseCaseTools::eclipseResultCases(); + if ( !resultCases.empty() ) + { + setCase( resultCases.front() ); + onLoadDataAndUpdate(); + } + } + } + if ( changedField == &m_userName || changedField == &m_showPlotTitle ) { updateWidgetTitleWindowTitle(); } else if ( changedField == &m_case ) { - if ( m_flowDiagSolution && m_case ) - { - m_flowDiagSolution = m_case->defaultFlowDiagSolution(); - } - else - { - m_flowDiagSolution = nullptr; - } - - if ( !m_case ) - m_timeStep = 0; - else if ( m_timeStep >= static_cast( m_case->timeStepDates().size() ) ) - { - m_timeStep = std::max( 0, ( (int)m_case->timeStepDates().size() ) - 1 ); - } - - std::set sortedWellNames = findSortedWellNames(); - if ( sortedWellNames.empty() ) - m_wellName = ""; - else if ( sortedWellNames.count( m_wellName() ) == 0 ) - { - m_wellName = *sortedWellNames.begin(); - } - + setCase( m_case ); onLoadDataAndUpdate(); } else if ( changedField == &m_wellName || changedField == &m_timeStep || changedField == &m_flowDiagSolution || @@ -849,7 +892,11 @@ void RimWellAllocationPlot::onLoadDataAndUpdate() { updateMdiWindowVisibility(); - if ( !m_case ) return; + if ( !m_case ) + { + m_flowDiagSolution = nullptr; + return; + } // If no 3D view is open, we have to make sure the case is opened if ( !m_case->ensureReservoirCaseIsOpen() ) diff --git a/ApplicationLibCode/ProjectDataModel/Flow/RimWellAllocationPlot.h b/ApplicationLibCode/ProjectDataModel/Flow/RimWellAllocationPlot.h index 410be11526..2f5b25459e 100644 --- a/ApplicationLibCode/ProjectDataModel/Flow/RimWellAllocationPlot.h +++ b/ApplicationLibCode/ProjectDataModel/Flow/RimWellAllocationPlot.h @@ -109,6 +109,7 @@ class RimWellAllocationPlot : public RimViewWindow void onLoadDataAndUpdate() override; private: + void setCase( RimEclipseResultCase* eclipseCase); void updateFromWell(); void updateWellFlowPlotXAxisTitle( RimWellLogTrack* plotTrack ); diff --git a/ApplicationLibCode/UserInterface/RiuPlotMainWindow.cpp b/ApplicationLibCode/UserInterface/RiuPlotMainWindow.cpp index 7219ffe40d..191e99e855 100644 --- a/ApplicationLibCode/UserInterface/RiuPlotMainWindow.cpp +++ b/ApplicationLibCode/UserInterface/RiuPlotMainWindow.cpp @@ -174,6 +174,9 @@ void RiuPlotMainWindow::initializeGuiNewProjectLoaded() setPdmRoot( RimProject::current() ); restoreTreeViewState(); + RimMainPlotCollection* mainPlotColl = RimMainPlotCollection::current(); + mainPlotColl->ensureDefaultFlowPlotsAreCreated(); + auto sumPlotManager = dynamic_cast( m_summaryPlotManager.get() ); if ( sumPlotManager ) {