diff --git a/ApplicationLibCode/Application/RiaDefines.cpp b/ApplicationLibCode/Application/RiaDefines.cpp index 14b776c50a..fc77aa4405 100644 --- a/ApplicationLibCode/Application/RiaDefines.cpp +++ b/ApplicationLibCode/Application/RiaDefines.cpp @@ -135,6 +135,26 @@ void AppEnum::setUp() setDefault( RiaDefines::RINavigationPolicy::NAVIGATION_POLICY_RMS ); } +template <> +void caf::AppEnum::setUp() +{ + addItem( RiaDefines::ColumnCount::COLUMNS_1, "1", "1 Column" ); + addItem( RiaDefines::ColumnCount::COLUMNS_2, "2", "2 Columns" ); + addItem( RiaDefines::ColumnCount::COLUMNS_3, "3", "3 Columns" ); + addItem( RiaDefines::ColumnCount::COLUMNS_4, "4", "4 Columns" ); + setDefault( RiaDefines::ColumnCount::COLUMNS_2 ); +} + +template <> +void caf::AppEnum::setUp() +{ + addItem( RiaDefines::RowCount::ROWS_1, "1", "1 Row" ); + addItem( RiaDefines::RowCount::ROWS_2, "2", "2 Rows" ); + addItem( RiaDefines::RowCount::ROWS_3, "3", "3 Rows" ); + addItem( RiaDefines::RowCount::ROWS_4, "4", "4 Rows" ); + setDefault( RiaDefines::RowCount::ROWS_2 ); +} + } // namespace caf //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/Application/RiaDefines.h b/ApplicationLibCode/Application/RiaDefines.h index 6bf6a1e3a9..29893e8960 100644 --- a/ApplicationLibCode/Application/RiaDefines.h +++ b/ApplicationLibCode/Application/RiaDefines.h @@ -187,4 +187,21 @@ bool isInjector( WellProductionType wellProductionType ); QString stringListSeparator(); +enum class ColumnCount +{ + COLUMNS_1 = 1, + COLUMNS_2 = 2, + COLUMNS_3 = 3, + COLUMNS_4 = 4, + COLUMNS_UNLIMITED = 1000, +}; + +enum class RowCount +{ + ROWS_1 = 1, + ROWS_2 = 2, + ROWS_3 = 3, + ROWS_4 = 4, +}; + }; // namespace RiaDefines diff --git a/ApplicationLibCode/Application/RiaPreferences.cpp b/ApplicationLibCode/Application/RiaPreferences.cpp index 07f57ac13c..39d0254929 100644 --- a/ApplicationLibCode/Application/RiaPreferences.cpp +++ b/ApplicationLibCode/Application/RiaPreferences.cpp @@ -288,6 +288,7 @@ void RiaPreferences::defineEditorAttribute( const caf::PdmFieldHandle* field, caf::PdmUiEditorAttribute* attribute ) { m_readerSettings->defineEditorAttribute( field, uiConfigName, attribute ); + m_summaryPreferences->defineEditorAttribute( field, uiConfigName, attribute ); { caf::PdmUiFilePathEditorAttribute* myAttr = dynamic_cast( attribute ); diff --git a/ApplicationLibCode/Application/RiaPreferencesSummary.cpp b/ApplicationLibCode/Application/RiaPreferencesSummary.cpp index c3f3ff2c9b..91c3a17a0e 100644 --- a/ApplicationLibCode/Application/RiaPreferencesSummary.cpp +++ b/ApplicationLibCode/Application/RiaPreferencesSummary.cpp @@ -22,6 +22,7 @@ #include "RiaPreferences.h" #include "cafPdmUiCheckBoxEditor.h" +#include "cafPdmUiComboBoxEditor.h" #include @@ -55,6 +56,7 @@ void RiaPreferencesSummary::SummaryReaderModeType::setUp() addItem( RiaPreferencesSummary::SummaryReaderMode::OPM_COMMON, "OPM_COMMON", "ESMRY (opm-common)" ); setDefault( RiaPreferencesSummary::SummaryReaderMode::HDF5_OPM_COMMON ); } + } // namespace caf CAF_PDM_SOURCE_INIT( RiaPreferencesSummary, "RiaPreferencesSummary" ); @@ -137,6 +139,11 @@ RiaPreferencesSummary::RiaPreferencesSummary() true, "Use Multiple Threads for Import of Summary Files" ); caf::PdmUiNativeCheckBoxEditor::configureFieldForEditor( &m_useMultipleThreadsWhenLoadingSummaryCases ); + + CAF_PDM_InitFieldNoDefault( &m_defaultColumnCount, "DefaultNumberOfColumns", "Columns" ); + m_defaultColumnCount = RiaDefines::ColumnCount::COLUMNS_2; + CAF_PDM_InitFieldNoDefault( &m_defaultRowsPerPage, "DefaultRowsPerPage", "Rows per Page" ); + m_defaultRowsPerPage = RiaDefines::RowCount::ROWS_2; } //-------------------------------------------------------------------------------------------------- @@ -221,6 +228,11 @@ void RiaPreferencesSummary::appendItemsToPlottingGroup( caf::PdmUiOrdering& uiOr uiOrdering.add( &m_defaultSummaryCurvesTextFilter ); uiOrdering.add( &m_defaultSummaryHistoryCurveStyle ); uiOrdering.add( &m_showSummaryTimeAsLongString ); + + auto multiGroup = uiOrdering.addNewGroup( "Multi Plot Defaults" ); + + multiGroup->add( &m_defaultColumnCount ); + multiGroup->add( &m_defaultRowsPerPage ); } //-------------------------------------------------------------------------------------------------- @@ -316,6 +328,23 @@ void RiaPreferencesSummary::defineUiOrdering( QString uiConfigName, caf::PdmUiOr uiOrdering.skipRemainingFields(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaPreferencesSummary::defineEditorAttribute( const caf::PdmFieldHandle* field, + QString uiConfigName, + caf::PdmUiEditorAttribute* attribute ) +{ + if ( field == &m_defaultRowsPerPage || field == &m_defaultColumnCount ) + { + auto myattr = dynamic_cast( attribute ); + if ( myattr ) + { + myattr->iconSize = QSize( 24, 16 ); + } + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -362,6 +391,49 @@ QList options.push_back( caf::PdmOptionItemInfo( allowImport.uiText(), RiaPreferencesSummary::SummaryRestartFilesImportMode::IMPORT ) ); } + else if ( fieldNeedingOptions == &m_defaultColumnCount ) + { + for ( size_t i = 0; i < ColumnCountEnum::size(); ++i ) + { + RiaDefines::ColumnCount enumVal = ColumnCountEnum::fromIndex( i ); + QString columnCountString = ( enumVal == RiaDefines::ColumnCount::COLUMNS_UNLIMITED ) + ? "Unlimited" + : QString( "%1" ).arg( static_cast( enumVal ) ); + QString iconPath = QString( ":/Columns%1.png" ).arg( columnCountString ); + options.push_back( caf::PdmOptionItemInfo( ColumnCountEnum::uiText( enumVal ), + enumVal, + false, + caf::IconProvider( iconPath, QSize( 24, 16 ) ) ) ); + } + } + else if ( fieldNeedingOptions == &m_defaultRowsPerPage ) + { + for ( size_t i = 0; i < RowCountEnum::size(); ++i ) + { + RiaDefines::RowCount enumVal = RowCountEnum::fromIndex( i ); + QString iconPath = QString( ":/Rows%1.png" ).arg( static_cast( enumVal ) ); + options.push_back( caf::PdmOptionItemInfo( RowCountEnum::uiText( enumVal ), + enumVal, + false, + caf::IconProvider( iconPath, QSize( 24, 16 ) ) ) ); + } + } return options; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiaDefines::ColumnCount RiaPreferencesSummary::defaultMultiPlotColumnCount() const +{ + return m_defaultColumnCount(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiaDefines::RowCount RiaPreferencesSummary::defaultMultiPlotRowCount() const +{ + return m_defaultRowsPerPage(); +} diff --git a/ApplicationLibCode/Application/RiaPreferencesSummary.h b/ApplicationLibCode/Application/RiaPreferencesSummary.h index a7d267cc77..3824c13fc7 100644 --- a/ApplicationLibCode/Application/RiaPreferencesSummary.h +++ b/ApplicationLibCode/Application/RiaPreferencesSummary.h @@ -22,6 +22,8 @@ #include "cafPdmField.h" #include "cafPdmObject.h" +#include "RiaDefines.h" + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -54,6 +56,9 @@ public: }; using SummaryHistoryCurveStyleModeType = caf::AppEnum; + using ColumnCountEnum = caf::AppEnum; + using RowCountEnum = caf::AppEnum; + public: RiaPreferencesSummary(); @@ -80,6 +85,13 @@ public: SummaryHistoryCurveStyleMode defaultSummaryHistoryCurveStyle() const; + RiaDefines::ColumnCount defaultMultiPlotColumnCount() const; + RiaDefines::RowCount defaultMultiPlotRowCount() const; + + void defineEditorAttribute( const caf::PdmFieldHandle* field, + QString uiConfigName, + caf::PdmUiEditorAttribute* attribute ) override; + protected: void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, @@ -104,4 +116,7 @@ private: caf::PdmField m_createH5SummaryFileThreadCount; caf::PdmField m_summaryReader; + + caf::PdmField m_defaultColumnCount; + caf::PdmField m_defaultRowsPerPage; }; diff --git a/ApplicationLibCode/Application/Tools/RiaImportEclipseCaseTools.cpp b/ApplicationLibCode/Application/Tools/RiaImportEclipseCaseTools.cpp index aa24155225..4059b437ba 100644 --- a/ApplicationLibCode/Application/Tools/RiaImportEclipseCaseTools.cpp +++ b/ApplicationLibCode/Application/Tools/RiaImportEclipseCaseTools.cpp @@ -20,6 +20,7 @@ #include "ApplicationCommands/RicShowMainWindowFeature.h" +#include "PlotBuilderCommands/RicSummaryPlotBuilder.h" #include "SummaryPlotCommands/RicNewSummaryCurveFeature.h" #include "SummaryPlotCommands/RicSummaryPlotFeatureImpl.h" @@ -195,10 +196,7 @@ bool RiaImportEclipseCaseTools::openEclipseCasesFromFile( const QStringList& if ( !newSumCases.empty() ) { - RimSummaryPlotCollection* summaryPlotColl = project->mainPlotCollection()->summaryPlotCollection(); - - RicSummaryPlotFeatureImpl::ensureAtLeastOnePlot( summaryPlotColl, newSumCases.front() ); - + RicSummaryPlotBuilder::createAndAppendDefaultSummaryMultiPlot( { newSumCases.front() }, {} ); RiuPlotMainWindowTools::setExpanded( newSumCases.front() ); } } diff --git a/ApplicationLibCode/Commands/PlotBuilderCommands/RicNewSummaryMultiPlotFeature.cpp b/ApplicationLibCode/Commands/PlotBuilderCommands/RicNewSummaryMultiPlotFeature.cpp index decf510dd2..efcda8508f 100644 --- a/ApplicationLibCode/Commands/PlotBuilderCommands/RicNewSummaryMultiPlotFeature.cpp +++ b/ApplicationLibCode/Commands/PlotBuilderCommands/RicNewSummaryMultiPlotFeature.cpp @@ -18,8 +18,12 @@ #include "RicNewSummaryMultiPlotFeature.h" -#include "RimMultiPlotCollection.h" +#include "RicSummaryPlotBuilder.h" + +#include "RimSummaryCase.h" +#include "RimSummaryCaseCollection.h" #include "RimSummaryMultiPlot.h" +#include "RimSummaryMultiPlotCollection.h" #include "RimSummaryPlot.h" #include "RicSummaryPlotBuilder.h" @@ -29,27 +33,23 @@ #include -RICF_SOURCE_INIT( RicNewSummaryMultiPlotFeature, "RicNewSummaryMultiPlotFeature", "createSummaryMultiPlot" ); - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RicNewSummaryMultiPlotFeature::RicNewSummaryMultiPlotFeature() -{ - CAF_PDM_InitFieldNoDefault( &m_plots, "plots", "Plots" ); -} +CAF_CMD_SOURCE_INIT( RicNewSummaryMultiPlotFeature, "RicNewSummaryMultiPlotFeature" ); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RicNewSummaryMultiPlotFeature::isCommandEnabled() { - auto plots = selectedPlots(); - std::vector selectedUiItems; caf::SelectionManager::instance()->selectedItems( selectedUiItems ); - return !plots.empty() && plots.size() == selectedUiItems.size(); + if ( selectedCollection( selectedUiItems ) ) return true; + + std::vector selectedIndividualSummaryCases; + std::vector selectedEnsembles; + if ( selectedCases( &selectedIndividualSummaryCases, &selectedEnsembles ) ) return true; + + return false; } //-------------------------------------------------------------------------------------------------- @@ -57,13 +57,25 @@ bool RicNewSummaryMultiPlotFeature::isCommandEnabled() //-------------------------------------------------------------------------------------------------- void RicNewSummaryMultiPlotFeature::onActionTriggered( bool isChecked ) { - m_plots.v().clear(); - auto plots = selectedPlots(); - for ( RimPlot* plot : plots ) + std::vector selectedUiItems; + caf::SelectionManager::instance()->selectedItems( selectedUiItems ); + + RimSummaryMultiPlotCollection* coll = selectedCollection( selectedUiItems ); + if ( coll ) { - m_plots.v().push_back( reinterpret_cast( plot ) ); + std::vector objects = {}; + RimSummaryMultiPlot* multiPlot = RicSummaryPlotBuilder::createAndAppendSummaryMultiPlot( objects ); + + return; + } + + std::vector selectedIndividualSummaryCases; + std::vector selectedEnsembles; + + if ( selectedCases( &selectedIndividualSummaryCases, &selectedEnsembles ) ) + { + RicSummaryPlotBuilder::createAndAppendDefaultSummaryMultiPlot( selectedIndividualSummaryCases, selectedEnsembles ); } - execute(); } //-------------------------------------------------------------------------------------------------- @@ -71,47 +83,42 @@ void RicNewSummaryMultiPlotFeature::onActionTriggered( bool isChecked ) //-------------------------------------------------------------------------------------------------- void RicNewSummaryMultiPlotFeature::setupActionLook( QAction* actionToSetup ) { - actionToSetup->setText( "Create Summary Multi Plot from Selected Plots" ); + actionToSetup->setText( "New Summary Plot" ); actionToSetup->setIcon( QIcon( ":/MultiPlot16x16.png" ) ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RicNewSummaryMultiPlotFeature::selectedPlots() +RimSummaryMultiPlotCollection* RicNewSummaryMultiPlotFeature::selectedCollection( std::vector& items ) { - std::vector uiItems; - caf::SelectionManager::instance()->selectedItems( uiItems ); - - std::vector plots; - for ( caf::PdmUiItem* uiItem : uiItems ) + for ( caf::PdmUiItem* uiItem : items ) { - RimSummaryPlot* summaryPlot = dynamic_cast( uiItem ); - if ( summaryPlot ) - { - plots.push_back( summaryPlot ); - } + RimSummaryMultiPlotCollection* coll = dynamic_cast( uiItem ); + if ( coll ) return coll; } - return plots; + return nullptr; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -caf::PdmScriptResponse RicNewSummaryMultiPlotFeature::execute() +bool RicNewSummaryMultiPlotFeature::selectedCases( std::vector* selectedIndividualSummaryCases, + std::vector* selectedEnsembles ) { - if ( !m_plots().empty() ) + CAF_ASSERT( selectedIndividualSummaryCases && selectedEnsembles ); + + caf::SelectionManager::instance()->objectsByTypeStrict( selectedEnsembles ); + if ( !selectedEnsembles->empty() ) { - std::vector plots; - for ( auto ptr : m_plots() ) - { - plots.push_back( reinterpret_cast( ptr ) ); - } - - auto copyOfPlots = RicSummaryPlotBuilder::duplicateSummaryPlots( plots ); - - RicSummaryPlotBuilder::createAndAppendSummaryMultiPlot( copyOfPlots ); + return true; + } + // Second try selected summary cases + caf::SelectionManager::instance()->objectsByTypeStrict( selectedIndividualSummaryCases ); + if ( !selectedIndividualSummaryCases->empty() ) + { + return true; } - return caf::PdmScriptResponse(); + return false; } diff --git a/ApplicationLibCode/Commands/PlotBuilderCommands/RicNewSummaryMultiPlotFeature.h b/ApplicationLibCode/Commands/PlotBuilderCommands/RicNewSummaryMultiPlotFeature.h index 67c9370ce1..bc16de116b 100644 --- a/ApplicationLibCode/Commands/PlotBuilderCommands/RicNewSummaryMultiPlotFeature.h +++ b/ApplicationLibCode/Commands/PlotBuilderCommands/RicNewSummaryMultiPlotFeature.h @@ -18,26 +18,22 @@ #pragma once -#include "RicfCommandObject.h" - #include "cafCmdFeature.h" #include "cafPdmField.h" +#include "cafPdmUiItem.h" #include -class RimSummaryPlot; +class RimSummaryMultiPlotCollection; +class RimSummaryCase; +class RimSummaryCaseCollection; //================================================================================================== /// //================================================================================================== -class RicNewSummaryMultiPlotFeature : public caf::CmdFeature, public RicfCommandObject +class RicNewSummaryMultiPlotFeature : public caf::CmdFeature { - RICF_HEADER_INIT; - -public: - RicNewSummaryMultiPlotFeature(); - - caf::PdmScriptResponse execute() override; + CAF_CMD_HEADER_INIT; protected: bool isCommandEnabled() override; @@ -45,7 +41,8 @@ protected: void setupActionLook( QAction* actionToSetup ) override; private: - static std::vector selectedPlots(); + RimSummaryMultiPlotCollection* selectedCollection( std::vector& items ); - caf::PdmField> m_plots; + bool selectedCases( std::vector* selectedIndividualSummaryCases, + std::vector* selectedEnsembles ); }; diff --git a/ApplicationLibCode/Commands/PlotBuilderCommands/RicNewSummaryMultiPlotFromDataVectorFeature.cpp b/ApplicationLibCode/Commands/PlotBuilderCommands/RicNewSummaryMultiPlotFromDataVectorFeature.cpp index 0ef4b3f488..24baa42c6b 100644 --- a/ApplicationLibCode/Commands/PlotBuilderCommands/RicNewSummaryMultiPlotFromDataVectorFeature.cpp +++ b/ApplicationLibCode/Commands/PlotBuilderCommands/RicNewSummaryMultiPlotFromDataVectorFeature.cpp @@ -110,6 +110,6 @@ void RicNewSummaryMultiPlotFromDataVectorFeature::onActionTriggered( bool isChec //-------------------------------------------------------------------------------------------------- void RicNewSummaryMultiPlotFromDataVectorFeature::setupActionLook( QAction* actionToSetup ) { - actionToSetup->setText( "New Multi Summary Plot" ); + actionToSetup->setText( "New Summary Plot" ); actionToSetup->setIcon( QIcon( ":/SummaryPlotLight16x16.png" ) ); } diff --git a/ApplicationLibCode/Commands/PlotBuilderCommands/RicSummaryPlotBuilder.cpp b/ApplicationLibCode/Commands/PlotBuilderCommands/RicSummaryPlotBuilder.cpp index 690c3bb457..58a10c87a4 100644 --- a/ApplicationLibCode/Commands/PlotBuilderCommands/RicSummaryPlotBuilder.cpp +++ b/ApplicationLibCode/Commands/PlotBuilderCommands/RicSummaryPlotBuilder.cpp @@ -18,6 +18,9 @@ #include "RicSummaryPlotBuilder.h" +#include "SummaryPlotCommands/RicNewSummaryEnsembleCurveSetFeature.h" +#include "SummaryPlotCommands/RicSummaryPlotFeatureImpl.h" + #include "RiaSummaryAddressAnalyzer.h" #include "RiaSummaryTools.h" @@ -357,7 +360,8 @@ RimSummaryMultiPlot* plotCollection->updateAllRequiredEditors(); plotWindow->loadDataAndUpdate(); - RiuPlotMainWindowTools::selectAsCurrentItem( plotWindow, true ); + RiuPlotMainWindowTools::selectAsCurrentItem( plotWindow ); + RiuPlotMainWindowTools::setExpanded( plotWindow, true ); return plotWindow; } @@ -369,7 +373,7 @@ void RicSummaryPlotBuilder::appendPlotsToMultiPlot( RimMultiPlot* multiPlot, con { for ( auto plot : plots ) { - // Remove the currently window controller, as this will be managed by the multi plot + // Remove the current window controller, as this will be managed by the multi plot // This must be done before adding the plot to the multi plot to ensure that the viewer widget is recreated plot->revokeMdiWindowStatus(); @@ -382,6 +386,50 @@ void RicSummaryPlotBuilder::appendPlotsToMultiPlot( RimMultiPlot* multiPlot, con } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimSummaryMultiPlot* + RicSummaryPlotBuilder::createAndAppendDefaultSummaryMultiPlot( const std::vector& cases, + const std::vector& ensembles ) +{ + RimProject* project = RimProject::current(); + auto* plotCollection = project->mainPlotCollection()->summaryMultiPlotCollection(); + + auto* plotWindow = new RimSummaryMultiPlot(); + plotWindow->setAsPlotMdiWindow(); + plotCollection->addSummaryMultiPlot( plotWindow ); + + RimSummaryPlot* plot = new RimSummaryPlot(); + plot->setAsPlotMdiWindow(); + plot->enableAutoPlotTitle( true ); + + for ( auto sumCase : cases ) + { + RicSummaryPlotFeatureImpl::addDefaultCurvesToPlot( plot, sumCase ); + } + + for ( auto ensemble : ensembles ) + { + RicNewSummaryEnsembleCurveSetFeature::addDefaultCurveSets( plot, ensemble ); + } + + plot->applyDefaultCurveAppearances(); + plot->loadDataAndUpdate(); + + plotCollection->updateConnectedEditors(); + + appendPlotsToSummaryMultiPlot( plotWindow, { plot } ); + + plotCollection->updateAllRequiredEditors(); + plotWindow->loadDataAndUpdate(); + plotWindow->updateAllRequiredEditors(); + + RiuPlotMainWindowTools::selectAsCurrentItem( plotWindow ); + + return plotWindow; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -391,7 +439,6 @@ RimSummaryMultiPlot* RicSummaryPlotBuilder::createAndAppendSummaryMultiPlot( con auto* plotCollection = project->mainPlotCollection()->summaryMultiPlotCollection(); auto* plotWindow = new RimSummaryMultiPlot(); - plotWindow->setMultiPlotTitle( QString( "Multi Summary Plot %1" ).arg( plotCollection->multiPlots().size() + 1 ) ); plotWindow->setAsPlotMdiWindow(); plotCollection->addSummaryMultiPlot( plotWindow ); @@ -399,10 +446,10 @@ RimSummaryMultiPlot* RicSummaryPlotBuilder::createAndAppendSummaryMultiPlot( con plotCollection->updateAllRequiredEditors(); plotWindow->loadDataAndUpdate(); - - RiuPlotMainWindowTools::selectAsCurrentItem( plotWindow, true ); plotWindow->updateAllRequiredEditors(); + RiuPlotMainWindowTools::selectAsCurrentItem( plotWindow ); + return plotWindow; } diff --git a/ApplicationLibCode/Commands/PlotBuilderCommands/RicSummaryPlotBuilder.h b/ApplicationLibCode/Commands/PlotBuilderCommands/RicSummaryPlotBuilder.h index 2328846a74..aebc65cce7 100644 --- a/ApplicationLibCode/Commands/PlotBuilderCommands/RicSummaryPlotBuilder.h +++ b/ApplicationLibCode/Commands/PlotBuilderCommands/RicSummaryPlotBuilder.h @@ -75,6 +75,10 @@ public: static RimMultiPlot* createAndAppendMultiPlot( const std::vector& plots ); static void appendPlotsToMultiPlot( RimMultiPlot* multiPlot, const std::vector& plots ); + static RimSummaryMultiPlot* + createAndAppendDefaultSummaryMultiPlot( const std::vector& cases, + const std::vector& ensembles ); + static RimSummaryMultiPlot* createAndAppendSummaryMultiPlot( const std::vector& plots ); static RimSummaryMultiPlot* createAndAppendSummaryMultiPlot( const std::vector& objects ); static void appendPlotsToSummaryMultiPlot( RimSummaryMultiPlot* multiPlot, const std::vector& plots ); diff --git a/ApplicationLibCode/Commands/RicImportEnsembleFeature.cpp b/ApplicationLibCode/Commands/RicImportEnsembleFeature.cpp index 5a24a893bf..96a0433e7d 100644 --- a/ApplicationLibCode/Commands/RicImportEnsembleFeature.cpp +++ b/ApplicationLibCode/Commands/RicImportEnsembleFeature.cpp @@ -44,6 +44,7 @@ #include "RiuMainWindow.h" #include "RiuPlotMainWindow.h" +#include "PlotBuilderCommands/RicSummaryPlotBuilder.h" #include "SummaryPlotCommands/RicNewSummaryEnsembleCurveSetFeature.h" #include @@ -123,7 +124,7 @@ void RicImportEnsembleFeature::importSingleEnsemble( const QStringList& summaryCase->updateAutoShortName(); } - RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetsAndUpdate( { ensemble } ); + RicSummaryPlotBuilder::createAndAppendDefaultSummaryMultiPlot( {}, { ensemble } ); } std::vector allCases; diff --git a/ApplicationLibCode/Commands/RicImportSummaryCasesFeature.cpp b/ApplicationLibCode/Commands/RicImportSummaryCasesFeature.cpp index 8cc3c057ce..d0d94415a6 100644 --- a/ApplicationLibCode/Commands/RicImportSummaryCasesFeature.cpp +++ b/ApplicationLibCode/Commands/RicImportSummaryCasesFeature.cpp @@ -36,6 +36,7 @@ #include "RimSummaryCase.h" #include "RimSummaryCaseCollection.h" #include "RimSummaryCaseMainCollection.h" +#include "RimSummaryMultiPlot.h" #include "RimSummaryPlot.h" #include "RimSummaryPlotCollection.h" @@ -43,6 +44,7 @@ #include "RiuPlotMainWindow.h" #include "RiuPlotMainWindowTools.h" +#include "PlotBuilderCommands/RicSummaryPlotBuilder.h" #include "SummaryPlotCommands/RicNewSummaryEnsembleCurveSetFeature.h" #include "SummaryPlotCommands/RicSummaryPlotFeatureImpl.h" @@ -83,11 +85,9 @@ void RicImportSummaryCasesFeature::onActionTriggered( bool isChecked ) addSummaryCases( cases ); if ( !cases.empty() ) { - auto objectToSelect = RicSummaryPlotFeatureImpl::createDefaultSummaryPlot( cases.front() ); - if ( objectToSelect ) + for ( auto sumcase : cases ) { - RiuPlotMainWindowTools::setExpanded( objectToSelect ); - RiuPlotMainWindowTools::selectAsCurrentItem( objectToSelect ); + RicSummaryPlotBuilder::createAndAppendDefaultSummaryMultiPlot( { sumcase }, {} ); } } @@ -136,7 +136,8 @@ bool RicImportSummaryCasesFeature::createAndAddSummaryCasesFromFiles( const QStr addSummaryCases( *cases ); if ( !cases->empty() && doCreateDefaultPlot ) { - auto objectToSelect = RicSummaryPlotFeatureImpl::createDefaultSummaryPlot( cases->back() ); + auto objectToSelect = RicSummaryPlotBuilder::createAndAppendDefaultSummaryMultiPlot( { cases->back() }, {} ); + if ( objectToSelect ) { RiuPlotMainWindowTools::setExpanded( objectToSelect ); diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewDefaultSummaryPlotFeature.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewDefaultSummaryPlotFeature.cpp index 25b78cc2df..f759e2f163 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewDefaultSummaryPlotFeature.cpp +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewDefaultSummaryPlotFeature.cpp @@ -20,6 +20,7 @@ #include "RiaSummaryTools.h" +#include "PlotBuilderCommands/RicSummaryPlotBuilder.h" #include "RicEditSummaryPlotFeature.h" #include "RicNewSummaryCurveFeature.h" #include "RicNewSummaryEnsembleCurveSetFeature.h" @@ -36,6 +37,7 @@ #include "RimSummaryCase.h" #include "RimSummaryCaseCollection.h" #include "RimSummaryCaseMainCollection.h" +#include "RimSummaryMultiPlot.h" #include "RimSummaryPlot.h" #include "RimSummaryPlotCollection.h" @@ -129,6 +131,13 @@ RimSummaryPlot* RicNewDefaultSummaryPlotFeature::createFromSummaryCases( RimSumm //-------------------------------------------------------------------------------------------------- bool RicNewDefaultSummaryPlotFeature::isCommandEnabled() { + RimSummaryMultiPlot* multiPlot = + dynamic_cast( caf::SelectionManager::instance()->selectedItem() ); + if ( multiPlot ) + { + return true; + } + std::vector selectedIndividualSummaryCases; std::vector selectedEnsembles; @@ -152,6 +161,16 @@ bool RicNewDefaultSummaryPlotFeature::isCommandEnabled() //-------------------------------------------------------------------------------------------------- void RicNewDefaultSummaryPlotFeature::onActionTriggered( bool isChecked ) { + RimSummaryMultiPlot* multiPlot = + dynamic_cast( caf::SelectionManager::instance()->selectedItem() ); + if ( multiPlot ) + { + RimSummaryPlot* plot = new RimSummaryPlot(); + plot->enableAutoPlotTitle( true ); + RicSummaryPlotBuilder::appendPlotsToSummaryMultiPlot( multiPlot, { plot } ); + return; + } + std::vector selectedIndividualSummaryCases; std::vector selectedEnsembles; extractPlotObjectsFromSelection( &selectedIndividualSummaryCases, &selectedEnsembles ); @@ -178,13 +197,13 @@ void RicNewDefaultSummaryPlotFeature::setupActionLook( QAction* actionToSetup ) extractPlotObjectsFromSelection( &selectedIndividualSummaryCases, &selectedEnsembles ); - if ( !selectedIndividualSummaryCases.empty() ) + if ( !selectedEnsembles.empty() ) { - actionToSetup->setText( "New Summary Plot" ); + actionToSetup->setText( "Add Ensemble Summary Plot" ); } else { - actionToSetup->setText( "New Ensemble Summary Plot" ); + actionToSetup->setText( "Add Summary Plot" ); } actionToSetup->setIcon( QIcon( ":/SummaryPlotLight16x16.png" ) ); } diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewSummaryEnsembleCurveSetFeature.h b/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewSummaryEnsembleCurveSetFeature.h index 4089320943..8612987488 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewSummaryEnsembleCurveSetFeature.h +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewSummaryEnsembleCurveSetFeature.h @@ -35,15 +35,13 @@ class RicNewSummaryEnsembleCurveSetFeature : public caf::CmdFeature public: static RimSummaryPlot* createPlotForCurveSetsAndUpdate( std::vector ensembles ); + static std::vector addDefaultCurveSets( RimSummaryPlot* plot, RimSummaryCaseCollection* ensemble ); protected: bool isCommandEnabled() override; void onActionTriggered( bool isChecked ) override; void setupActionLook( QAction* actionToSetup ) override; -private: - static std::vector addDefaultCurveSets( RimSummaryPlot* plot, RimSummaryCaseCollection* ensemble ); - private: RimSummaryPlot* selectedSummaryPlot() const; }; diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotEditorUi.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotEditorUi.cpp index 6d485b7b33..34fffe857f 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotEditorUi.cpp +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotEditorUi.cpp @@ -42,6 +42,7 @@ #include "RimSummaryCurve.h" #include "RimSummaryCurveAutoName.h" #include "RimSummaryCurveCollection.h" +#include "RimSummaryMultiPlot.h" #include "RimSummaryPlot.h" #include "RimSummaryPlotCollection.h" @@ -83,6 +84,7 @@ std::vector toVector( const std::set& set ); /// //-------------------------------------------------------------------------------------------------- RicSummaryPlotEditorUi::RicSummaryPlotEditorUi() + : m_plotContainer( nullptr ) { CAF_PDM_InitFieldNoDefault( &m_targetPlot, "TargetPlot", "Target Plot" ); @@ -162,6 +164,7 @@ void RicSummaryPlotEditorUi::updateFromSummaryPlot( RimSummaryPlot* if ( m_targetPlot ) { + targetPlot->firstAncestorOfType( m_plotContainer ); populateCurveCreator( *m_targetPlot ); syncPreviewCurvesFromUiSelection(); setInitialCurveVisibility( targetPlot ); @@ -172,6 +175,7 @@ void RicSummaryPlotEditorUi::updateFromSummaryPlot( RimSummaryPlot* setDefaultCurveSelection( defaultSources ); m_previewPlot->enableAutoPlotTitle( true ); syncPreviewCurvesFromUiSelection(); + m_plotContainer = nullptr; } caf::PdmUiItem::updateConnectedEditors(); @@ -262,19 +266,25 @@ QList { QList options; - if ( fieldNeedingOptions == &m_targetPlot ) + if ( m_targetPlot && ( fieldNeedingOptions == &m_targetPlot ) ) { - RimProject* proj = RimProject::current(); - - RimSummaryPlotCollection* summaryPlotColl = proj->mainPlotCollection()->summaryPlotCollection(); - // Create New Plot item QString displayName = "( New Plot )"; options.push_back( caf::PdmOptionItemInfo( displayName, nullptr ) ); - if ( summaryPlotColl ) + if ( m_plotContainer ) { - summaryPlotColl->summaryPlotItemInfos( &options ); + m_plotContainer->summaryPlotItemInfos( &options ); + } + else + { + RimProject* proj = RimProject::current(); + + RimSummaryPlotCollection* summaryPlotColl = proj->mainPlotCollection()->summaryPlotCollection(); + if ( summaryPlotColl ) + { + summaryPlotColl->summaryPlotItemInfos( &options ); + } } } @@ -841,52 +851,39 @@ void RicSummaryPlotEditorUi::createNewPlot() { RimProject* proj = RimProject::current(); + RimSummaryPlot* newSummaryPlot = nullptr; + RimSummaryPlotCollection* summaryPlotColl = proj->mainPlotCollection()->summaryPlotCollection(); - if ( summaryPlotColl ) + + if ( m_plotContainer ) { - RimSummaryPlot* newSummaryPlot = nullptr; - if ( m_useAutoPlotTitleProxy() ) + newSummaryPlot = new RimSummaryPlot(); + newSummaryPlot->setAsPlotMdiWindow(); + newSummaryPlot->enableAutoPlotTitle( true ); + m_plotContainer->addPlot( newSummaryPlot ); + } + else if ( summaryPlotColl ) + { + newSummaryPlot = summaryPlotColl->createSummaryPlotWithAutoTitle(); + } + + if ( newSummaryPlot ) + { + newSummaryPlot->loadDataAndUpdate(); + + if ( m_plotContainer ) { - newSummaryPlot = summaryPlotColl->createSummaryPlotWithAutoTitle(); + m_plotContainer->updateConnectedEditors(); } - else + else if ( summaryPlotColl ) { - QString candidatePlotName; - if ( m_previewPlot ) - { - candidatePlotName = m_previewPlot->generatedPlotTitleFromAllCurves(); - } - - { - bool ok = false; - candidatePlotName = QInputDialog::getText( nullptr, - "New Summary Plot Name", - "New Summary Plot Name", - QLineEdit::Normal, - candidatePlotName, - &ok, - RiuTools::defaultDialogFlags() ); - if ( !ok ) - { - return; - } - - newSummaryPlot = summaryPlotColl->createNamedSummaryPlot( candidatePlotName ); - } - } - - if ( newSummaryPlot ) - { - newSummaryPlot->loadDataAndUpdate(); - summaryPlotColl->updateConnectedEditors(); - - m_targetPlot = newSummaryPlot; - updateTargetPlot(); - - RiuPlotMainWindow* mainPlotWindow = RiaGuiApplication::instance()->mainPlotWindow(); - mainPlotWindow->updateSummaryPlotToolBar(); } + + m_targetPlot = newSummaryPlot; + + RiuPlotMainWindow* mainPlotWindow = RiaGuiApplication::instance()->mainPlotWindow(); + mainPlotWindow->updateSummaryPlotToolBar(); } } diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotEditorUi.h b/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotEditorUi.h index 850d071660..668015bc94 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotEditorUi.h +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotEditorUi.h @@ -41,6 +41,7 @@ class PdmObject; }; class RimSummaryCase; +class RimSummaryMultiPlot; class RimSummaryCurveAutoName; class RimSummaryPlot; class RiaSummaryCurveDefinition; @@ -133,4 +134,6 @@ private: caf::PdmField m_closeButtonField; std::unique_ptr m_summaryCurveSelectionEditor; + + RimSummaryMultiPlot* m_plotContainer; }; diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp index 3a8ff1bcd1..8e5cdd0da7 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp @@ -51,6 +51,7 @@ #include "RimProject.h" #include "RimSummaryCase.h" #include "RimSummaryCurve.h" +#include "RimSummaryMultiPlotCollection.h" #include "RimSummaryPlot.h" #include "RimSummaryPlotCollection.h" @@ -78,61 +79,6 @@ std::vector RicSummaryPlotFeatureImpl::addDefaultCurvesToPlot( return addCurvesFromAddressFiltersToPlot( curveFilters, plot, summaryCase, addHistoryCurve ); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicSummaryPlotFeatureImpl::ensureAtLeastOnePlot( RimSummaryPlotCollection* summaryPlotCollection, - RimSummaryCase* summaryCase ) -{ - if ( summaryPlotCollection && summaryCase ) - { - if ( summaryPlotCollection->plots().empty() ) - { - auto objectToSelect = createDefaultSummaryPlot( summaryCase ); - if ( objectToSelect ) - { - RiuPlotMainWindowTools::setExpanded( objectToSelect ); - RiuPlotMainWindowTools::selectAsCurrentItem( objectToSelect ); - } - } - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -caf::PdmObject* RicSummaryPlotFeatureImpl::createDefaultSummaryPlot( RimSummaryCase* summaryCase ) -{ - RimSummaryPlotCollection* summaryPlotCollection = RimProject::current()->mainPlotCollection->summaryPlotCollection(); - - RiaPreferencesSummary* prefs = RiaPreferencesSummary::current(); - - caf::PdmObject* itemToSelect = nullptr; - - if ( summaryPlotCollection && summaryCase && !prefs->defaultSummaryCurvesTextFilter().isEmpty() ) - { - auto plot = summaryPlotCollection->createSummaryPlotWithAutoTitle(); - - std::vector curves = RicSummaryPlotFeatureImpl::addDefaultCurvesToPlot( plot, summaryCase ); - - plot->applyDefaultCurveAppearances(); - plot->loadDataAndUpdate(); - - summaryPlotCollection->updateConnectedEditors(); - - if ( curves.size() ) - { - itemToSelect = curves[0]; - } - else - { - itemToSelect = plot; - } - } - - return itemToSelect; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/Commands/WellLogCommands/RicDeleteSubPlotFeature.cpp b/ApplicationLibCode/Commands/WellLogCommands/RicDeleteSubPlotFeature.cpp index 46e328c56c..ec5b74e0f2 100644 --- a/ApplicationLibCode/Commands/WellLogCommands/RicDeleteSubPlotFeature.cpp +++ b/ApplicationLibCode/Commands/WellLogCommands/RicDeleteSubPlotFeature.cpp @@ -77,6 +77,12 @@ void RicDeleteSubPlotFeature::onActionTriggered( bool isChecked ) caf::SelectionManager::instance()->objectsByType( &selection ); std::set alteredPlotWindows; + for ( RimPlot* plot : selection ) + { + if ( !plot ) continue; + caf::SelectionManager::instance()->removeObjectFromAllSelections( plot ); + } + for ( RimPlot* plot : selection ) { if ( !plot ) continue; @@ -89,8 +95,6 @@ void RicDeleteSubPlotFeature::onActionTriggered( bool isChecked ) { alteredPlotWindows.insert( multiPlot ); multiPlot->removePlot( plot ); - caf::SelectionManager::instance()->removeObjectFromAllSelections( plot ); - multiPlot->updateConnectedEditors(); delete plot; } @@ -98,8 +102,6 @@ void RicDeleteSubPlotFeature::onActionTriggered( bool isChecked ) { alteredPlotWindows.insert( wellLogPlot ); wellLogPlot->removePlot( plot ); - caf::SelectionManager::instance()->removeObjectFromAllSelections( plot ); - wellLogPlot->updateConnectedEditors(); delete plot; } diff --git a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp index 8880f2fa59..32de1ab957 100644 --- a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -126,6 +126,8 @@ #include "RimSummaryCrossPlotCollection.h" #include "RimSummaryCurve.h" #include "RimSummaryCurveCollection.h" +#include "RimSummaryMultiPlot.h" +#include "RimSummaryMultiPlotCollection.h" #include "RimSummaryPlot.h" #include "RimSummaryPlotCollection.h" #include "RimSurface.h" @@ -564,6 +566,10 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "Separator"; menuBuilder << "RicShowSummaryCurveCalculatorFeature"; } + else if ( dynamic_cast( firstUiItem ) ) + { + menuBuilder << "RicNewSummaryMultiPlotFeature"; + } else if ( dynamic_cast( firstUiItem ) ) { menuBuilder << "RicNewAnalysisPlotFeature"; @@ -768,6 +774,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "RicImportEnsembleFeature"; menuBuilder.subMenuEnd(); menuBuilder.addSeparator(); + menuBuilder << "RicNewSummaryMultiPlotFeature"; menuBuilder << "RicNewDerivedEnsembleFeature"; menuBuilder << "RicOpenSummaryPlotEditorFeature"; menuBuilder << "RicNewDefaultSummaryPlotFeature"; @@ -785,6 +792,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "RicImportEnsembleFeature"; menuBuilder.subMenuEnd(); menuBuilder.addSeparator(); + menuBuilder << "RicNewSummaryMultiPlotFeature"; menuBuilder << "RicOpenSummaryPlotEditorFeature"; menuBuilder << "RicNewDefaultSummaryPlotFeature"; menuBuilder << "RicNewSummaryCrossPlotFeature"; @@ -1023,6 +1031,12 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() { menuBuilder << "RicReloadPlotTemplatesFeature"; } + else if ( dynamic_cast( firstUiItem ) ) + { + menuBuilder << "RicNewDefaultSummaryPlotFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicSnapshotViewToPdfFeature"; + } else if ( dynamic_cast( firstUiItem ) ) { menuBuilder << "RicSnapshotViewToPdfFeature"; @@ -1062,10 +1076,10 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "RicShowPlotDataFeature"; menuBuilder << "RicShowTotalAllocationDataFeature"; + menuBuilder << "RicNewSummaryMultiPlotFeature"; menuBuilder << "RicNewDerivedEnsembleFeature"; menuBuilder << "RicOpenSummaryPlotEditorFeature"; menuBuilder << "RicNewDefaultSummaryPlotFeature"; - menuBuilder << "RicNewSummaryMultiPlotFeature"; menuBuilder << "RicNewSummaryCrossPlotFeature"; menuBuilder << "RicSummaryCurveSwitchAxisFeature"; menuBuilder << "RicNewDerivedSummaryFeature"; @@ -1188,7 +1202,6 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() } else if ( dynamic_cast( firstUiItem ) ) { - menuBuilder << "RicNewSummaryPlotFromDataVectorFeature"; menuBuilder << "RicNewSummaryMultiPlotFromDataVectorFeature"; } #ifdef USE_ODB_API diff --git a/ApplicationLibCode/ProjectDataModel/RimMultiPlot.cpp b/ApplicationLibCode/ProjectDataModel/RimMultiPlot.cpp index a32eaa7530..59bd6ea1a5 100644 --- a/ApplicationLibCode/ProjectDataModel/RimMultiPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimMultiPlot.cpp @@ -19,6 +19,7 @@ #include "RimMultiPlot.h" #include "RiaPreferences.h" +#include "RiaPreferencesSummary.h" #include "RimPlot.h" #include "RimProject.h" @@ -37,29 +38,6 @@ #include -namespace caf -{ -template <> -void RimMultiPlot::ColumnCountEnum::setUp() -{ - addItem( RimMultiPlot::ColumnCount::COLUMNS_1, "1", "1 Column" ); - addItem( RimMultiPlot::ColumnCount::COLUMNS_2, "2", "2 Columns" ); - addItem( RimMultiPlot::ColumnCount::COLUMNS_3, "3", "3 Columns" ); - addItem( RimMultiPlot::ColumnCount::COLUMNS_4, "4", "4 Columns" ); - setDefault( RimMultiPlot::ColumnCount::COLUMNS_2 ); -} -template <> -void RimMultiPlot::RowCountEnum::setUp() -{ - addItem( RimMultiPlot::RowCount::ROWS_1, "1", "1 Row" ); - addItem( RimMultiPlot::RowCount::ROWS_2, "2", "2 Rows" ); - addItem( RimMultiPlot::RowCount::ROWS_3, "3", "3 Rows" ); - addItem( RimMultiPlot::RowCount::ROWS_4, "4", "4 Rows" ); - setDefault( RimMultiPlot::RowCount::ROWS_2 ); -} - -} // namespace caf - CAF_PDM_SOURCE_INIT( RimMultiPlot, "MultiPlot" ); //-------------------------------------------------------------------------------------------------- @@ -77,8 +55,11 @@ RimMultiPlot::RimMultiPlot() auto reorderability = caf::PdmFieldReorderCapability::addToField( &m_plots ); reorderability->orderChanged.connect( this, &RimMultiPlot::onPlotsReordered ); + RiaPreferencesSummary* sumPrefs = RiaPreferencesSummary::current(); CAF_PDM_InitFieldNoDefault( &m_columnCount, "NumberOfColumns", "Number of Columns" ); + m_columnCount = sumPrefs->defaultMultiPlotColumnCount(); CAF_PDM_InitFieldNoDefault( &m_rowsPerPage, "RowsPerPage", "Rows per Page" ); + m_rowsPerPage = sumPrefs->defaultMultiPlotRowCount(); CAF_PDM_InitField( &m_showIndividualPlotTitles, "ShowPlotTitles", true, "Show Sub Plot Titles" ); CAF_PDM_InitFieldNoDefault( &m_majorTickmarkCount, "MajorTickmarkCount", "Major Tickmark Count" ); @@ -401,7 +382,7 @@ void RimMultiPlot::setAutoScaleYEnabled( bool enabled ) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimMultiPlot::setColumnCount( RiuMultiPlotPage::ColumnCount columnCount ) +void RimMultiPlot::setColumnCount( RiaDefines::ColumnCount columnCount ) { m_columnCount = columnCount; } @@ -409,7 +390,7 @@ void RimMultiPlot::setColumnCount( RiuMultiPlotPage::ColumnCount columnCount ) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimMultiPlot::setRowCount( RowCount rowCount ) +void RimMultiPlot::setRowCount( RiaDefines::RowCount rowCount ) { m_rowsPerPage = rowCount; } @@ -440,7 +421,7 @@ void RimMultiPlot::setTickmarkCount( RimPlot* plot, RimPlotAxisPropertiesInterfa //-------------------------------------------------------------------------------------------------- int RimMultiPlot::columnCount() const { - if ( m_columnCount() == ColumnCount::COLUMNS_UNLIMITED ) + if ( m_columnCount() == RiaDefines::ColumnCount::COLUMNS_UNLIMITED ) { return std::numeric_limits::max(); } @@ -452,22 +433,22 @@ int RimMultiPlot::columnCount() const //-------------------------------------------------------------------------------------------------- int RimMultiPlot::rowsPerPage() const { - RimMultiPlot::RowCount rowEnum = m_rowsPerPage().value(); + RiaDefines::RowCount rowEnum = m_rowsPerPage().value(); int rowCount = 2; switch ( rowEnum ) { - case RimMultiPlot::RowCount::ROWS_1: + case RiaDefines::RowCount::ROWS_1: rowCount = 1; break; - case RimMultiPlot::RowCount::ROWS_2: + case RiaDefines::RowCount::ROWS_2: rowCount = 2; break; - case RimMultiPlot::RowCount::ROWS_3: + case RiaDefines::RowCount::ROWS_3: rowCount = 3; break; - case RimMultiPlot::RowCount::ROWS_4: + case RiaDefines::RowCount::ROWS_4: rowCount = 4; break; default: @@ -754,8 +735,8 @@ QList RimMultiPlot::calculateValueOptions( const caf::Pd { for ( size_t i = 0; i < ColumnCountEnum::size(); ++i ) { - ColumnCount enumVal = ColumnCountEnum::fromIndex( i ); - QString columnCountString = ( enumVal == ColumnCount::COLUMNS_UNLIMITED ) + RiaDefines::ColumnCount enumVal = ColumnCountEnum::fromIndex( i ); + QString columnCountString = ( enumVal == RiaDefines::ColumnCount::COLUMNS_UNLIMITED ) ? "Unlimited" : QString( "%1" ).arg( static_cast( enumVal ) ); QString iconPath = QString( ":/Columns%1.png" ).arg( columnCountString ); @@ -769,8 +750,8 @@ QList RimMultiPlot::calculateValueOptions( const caf::Pd { for ( size_t i = 0; i < RowCountEnum::size(); ++i ) { - RowCount enumVal = RowCountEnum::fromIndex( i ); - QString iconPath = QString( ":/Rows%1.png" ).arg( static_cast( enumVal ) ); + RiaDefines::RowCount enumVal = RowCountEnum::fromIndex( i ); + QString iconPath = QString( ":/Rows%1.png" ).arg( static_cast( enumVal ) ); options.push_back( caf::PdmOptionItemInfo( RowCountEnum::uiText( enumVal ), enumVal, false, diff --git a/ApplicationLibCode/ProjectDataModel/RimMultiPlot.h b/ApplicationLibCode/ProjectDataModel/RimMultiPlot.h index 7107db02ae..0a1b0e3f95 100644 --- a/ApplicationLibCode/ProjectDataModel/RimMultiPlot.h +++ b/ApplicationLibCode/ProjectDataModel/RimMultiPlot.h @@ -18,6 +18,8 @@ #pragma once +#include "RiaDefines.h" + #include "RimAbstractPlotCollection.h" #include "RimPlot.h" #include "RimPlotAxisPropertiesInterface.h" @@ -44,19 +46,8 @@ class RimMultiPlot : public RimPlotWindow, public RimTypedPlotCollection; - - enum class RowCount - { - ROWS_1 = 1, - ROWS_2 = 2, - ROWS_3 = 3, - ROWS_4 = 4, - }; - using RowCountEnum = caf::AppEnum; - - friend class RimSummaryMultiPlot; + using ColumnCountEnum = caf::AppEnum; + using RowCountEnum = caf::AppEnum; public: RimMultiPlot(); @@ -90,8 +81,8 @@ public: void setAutoScaleXEnabled( bool enabled ); void setAutoScaleYEnabled( bool enabled ); - void setColumnCount( RiuMultiPlotPage::ColumnCount columnCount ); - void setRowCount( RimMultiPlot::RowCount rowCount ); + void setColumnCount( RiaDefines::ColumnCount columnCount ); + void setRowCount( RiaDefines::RowCount rowCount ); void setTickmarkCount( RimPlotAxisPropertiesInterface::LegendTickmarkCountEnum tickmarkCount ); int columnCount() const override; diff --git a/ApplicationLibCode/ProjectDataModel/RimPlotWindow.cpp b/ApplicationLibCode/ProjectDataModel/RimPlotWindow.cpp index 90da745a7f..a6bc804aa8 100644 --- a/ApplicationLibCode/ProjectDataModel/RimPlotWindow.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimPlotWindow.cpp @@ -211,7 +211,7 @@ void RimPlotWindow::updateParentLayout() //-------------------------------------------------------------------------------------------------- int RimPlotWindow::columnCount() const { - return static_cast( RiuMultiPlotPage::ColumnCount::COLUMNS_UNLIMITED ); + return static_cast( RiaDefines::ColumnCount::COLUMNS_UNLIMITED ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp index 1e999d1ca3..f89cfa52e4 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp @@ -327,6 +327,7 @@ void RimSummaryMultiPlot::updatePlotWindowTitle() populateNameHelper( m_nameHelper.get() ); auto title = m_nameHelper->plotTitle(); + if ( title.isEmpty() ) title = "Empty Plot"; setMultiPlotTitle( title ); } @@ -386,62 +387,6 @@ std::vector RimSummaryMultiPlot::summaryPlots() const return typedPlots; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimSummaryMultiPlot::insertGraphsIntoPlot( RimSummaryMultiPlot* plot, const std::vector& graphs ) -{ - auto columnCount = RiuMultiPlotPage::ColumnCount::COLUMNS_2; - auto rowCount = RimMultiPlot::RowCount::ROWS_2; - auto tickmarkCount = RimPlotAxisPropertiesInterface::LegendTickmarkCount::TICKMARK_DEFAULT; - - bool showTitleSubGraph = true; - if ( graphs.size() == 1 ) - { - showTitleSubGraph = false; - tickmarkCount = RimPlotAxisPropertiesInterface::LegendTickmarkCount::TICKMARK_MANY; - } - else if ( 4 < graphs.size() && graphs.size() <= 6 ) - { - columnCount = RiuMultiPlotPage::ColumnCount::COLUMNS_3; - rowCount = RimMultiPlot::RowCount::ROWS_2; - tickmarkCount = RimPlotAxisPropertiesInterface::LegendTickmarkCount::TICKMARK_FEW; - } - else if ( 6 < graphs.size() && graphs.size() <= 12 ) - { - columnCount = RiuMultiPlotPage::ColumnCount::COLUMNS_4; - rowCount = RimMultiPlot::RowCount::ROWS_3; - tickmarkCount = RimPlotAxisPropertiesInterface::LegendTickmarkCount::TICKMARK_VERY_FEW; - } - else - { - columnCount = RiuMultiPlotPage::ColumnCount::COLUMNS_4; - rowCount = RimMultiPlot::RowCount::ROWS_4; - tickmarkCount = RimPlotAxisPropertiesInterface::LegendTickmarkCount::TICKMARK_VERY_FEW; - } - - plot->setAutoTitlePlot( true ); - plot->setAutoTitleGraphs( showTitleSubGraph ); - - plot->setColumnCount( columnCount ); - plot->setRowCount( rowCount ); - plot->setShowPlotTitles( showTitleSubGraph ); - plot->setTickmarkCount( tickmarkCount ); - - for ( auto graph : graphs ) - { - plot->addPlot( graph ); - - graph->resolveReferencesRecursively(); - graph->revokeMdiWindowStatus(); - graph->setShowWindow( true ); - - graph->loadDataAndUpdate(); - } - - plot->loadDataAndUpdate(); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -570,6 +515,18 @@ void RimSummaryMultiPlot::syncAxisRanges() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSummaryMultiPlot::summaryPlotItemInfos( QList* optionInfos ) const +{ + for ( RimSummaryPlot* plot : summaryPlots() ) + { + QString displayName = plot->description(); + optionInfos->push_back( caf::PdmOptionItemInfo( displayName, plot, false, plot->uiCapability()->uiIconProvider() ) ); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.h b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.h index 6e5b821757..b7d11d8b44 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.h +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.h @@ -24,8 +24,11 @@ #include "cafPdmChildField.h" #include "cafPdmObject.h" #include "cafPdmPtrArrayField.h" +#include "cafPdmUiItem.h" #include "cafSignal.h" +#include + #include class RimSummaryPlot; @@ -68,6 +71,8 @@ public: void addPlot( const std::vector& objects ); + void summaryPlotItemInfos( QList* optionInfos ) const; + protected: bool handleGlobalKeyEvent( QKeyEvent* keyEvent ) override; bool handleGlobalWheelEvent( QWheelEvent* wheelEvent ) override; @@ -85,8 +90,6 @@ private: std::vector summaryPlots() const; - static void insertGraphsIntoPlot( RimSummaryMultiPlot* plot, const std::vector& graphs ); - void updatePlotWindowTitle() override; void duplicate(); diff --git a/ApplicationLibCode/UserInterface/RiuDragDrop.cpp b/ApplicationLibCode/UserInterface/RiuDragDrop.cpp index 2db478ede0..9db74aaae8 100644 --- a/ApplicationLibCode/UserInterface/RiuDragDrop.cpp +++ b/ApplicationLibCode/UserInterface/RiuDragDrop.cpp @@ -778,6 +778,8 @@ bool RiuDragDrop::handleGenericDropEvent( QEvent* event, std::vectortype() == QEvent::Drop ) { // These drop events come from Qwt @@ -788,6 +790,8 @@ bool RiuDragDrop::handleGenericDropEvent( QEvent* event, std::vectorkeyboardModifiers(); dropEvent->acceptProposedAction(); + dropEvent->accept(); + bResult = true; } } else if ( event->type() == QEvent::GraphicsSceneDrop ) @@ -799,6 +803,8 @@ bool RiuDragDrop::handleGenericDropEvent( QEvent* event, std::vector( dropEvent->mimeData() ); dropEvent->acceptProposedAction(); + dropEvent->accept(); + bResult = true; } } @@ -819,8 +825,8 @@ bool RiuDragDrop::handleGenericDropEvent( QEvent* event, std::vectorshow(); - dw->raise(); } } diff --git a/ApplicationLibCode/UserInterface/RiuMultiPlotBook.cpp b/ApplicationLibCode/UserInterface/RiuMultiPlotBook.cpp index ad3437ae0f..6f3860218f 100644 --- a/ApplicationLibCode/UserInterface/RiuMultiPlotBook.cpp +++ b/ApplicationLibCode/UserInterface/RiuMultiPlotBook.cpp @@ -104,6 +104,8 @@ RiuMultiPlotBook::RiuMultiPlotBook( RimMultiPlot* plotDefinition, QWidget* paren , m_subTitlesVisible( true ) , m_previewMode( true ) , m_currentPageIndex( 0 ) + , m_goToLastPageAfterUpdate( false ) + , m_pageTimerId( -1 ) { const int spacing = 8; @@ -168,6 +170,7 @@ void RiuMultiPlotBook::addPlot( RiuPlotWidget* plotWidget ) void RiuMultiPlotBook::insertPlot( RiuPlotWidget* plotWidget, size_t index ) { m_plotWidgets.insert( static_cast( index ), plotWidget ); + m_goToLastPageAfterUpdate = true; scheduleUpdate(); } @@ -461,6 +464,24 @@ void RiuMultiPlotBook::performUpdate() deleteAllPages(); createPages(); updateGeometry(); + // use a timer to trigger a viewer page change, if needed + if ( m_goToLastPageAfterUpdate ) + { + m_pageTimerId = startTimer( 100 ); + m_goToLastPageAfterUpdate = false; + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMultiPlotBook::timerEvent( QTimerEvent* event ) +{ + if ( event->timerId() == m_pageTimerId ) + { + killTimer( m_pageTimerId ); + goToLastPage(); + } } //-------------------------------------------------------------------------------------------------- @@ -501,8 +522,8 @@ void RiuMultiPlotBook::createPages() { CAF_ASSERT( m_plotDefinition ); - QList> plotWidgets = this->visiblePlotWidgets(); - auto rowAndColumnCount = this->rowAndColumnCount( plotWidgets.size() ); + QList> plotWidgets = this->visiblePlotWidgets(); + auto [rowCount, columnCount] = this->rowAndColumnCount( plotWidgets.size() ); int rowsPerPage = m_plotDefinition->rowsPerPage(); int row = 0; @@ -514,9 +535,9 @@ void RiuMultiPlotBook::createPages() for ( int visibleIndex = 0; visibleIndex < plotWidgets.size(); ++visibleIndex ) { int expectedColSpan = static_cast( plotWidgets[visibleIndex]->colSpan() ); - int colSpan = std::min( expectedColSpan, rowAndColumnCount.second ); + int colSpan = std::min( expectedColSpan, columnCount ); - std::tie( row, column ) = page->findAvailableRowAndColumn( row, column, colSpan, rowAndColumnCount.second ); + std::tie( row, column ) = page->findAvailableRowAndColumn( row, column, colSpan, columnCount ); if ( row >= rowsPerPage ) { page = createPage(); @@ -609,7 +630,7 @@ void RiuMultiPlotBook::applyLook() void RiuMultiPlotBook::changeCurrentPage( int pageNumber ) { m_currentPageIndex = pageNumber; - if ( m_currentPageIndex >= (int)m_pages.size() ) m_currentPageIndex = (int)m_pages.size() - 1; + if ( m_currentPageIndex >= m_pages.size() ) m_currentPageIndex = m_pages.size() - 1; if ( m_currentPageIndex < 0 ) m_currentPageIndex = 0; if ( !m_pages.isEmpty() ) m_scrollArea->ensureWidgetVisible( m_pages[m_currentPageIndex] ); } diff --git a/ApplicationLibCode/UserInterface/RiuMultiPlotBook.h b/ApplicationLibCode/UserInterface/RiuMultiPlotBook.h index ace642a8ec..3c07c42668 100644 --- a/ApplicationLibCode/UserInterface/RiuMultiPlotBook.h +++ b/ApplicationLibCode/UserInterface/RiuMultiPlotBook.h @@ -53,9 +53,6 @@ class RiuMultiPlotBook : public QWidget, public RiuInterfaceToViewWindow { Q_OBJECT -public: - using ColumnCount = RiuMultiPlotPage::ColumnCount; - public: RiuMultiPlotBook( RimMultiPlot* plotDefinition, QWidget* parent = nullptr ); ~RiuMultiPlotBook() override; @@ -108,6 +105,8 @@ protected: void dragEnterEvent( QDragEnterEvent* event ) override; void dropEvent( QDropEvent* event ) override; + void timerEvent( QTimerEvent* event ) override; + private: void deleteAllPages(); void createPages(); @@ -136,4 +135,7 @@ protected: bool m_subTitlesVisible; bool m_previewMode; int m_currentPageIndex; + + bool m_goToLastPageAfterUpdate; + int m_pageTimerId; }; diff --git a/ApplicationLibCode/UserInterface/RiuMultiPlotPage.cpp b/ApplicationLibCode/UserInterface/RiuMultiPlotPage.cpp index dc635d6158..3cb72dc1f1 100644 --- a/ApplicationLibCode/UserInterface/RiuMultiPlotPage.cpp +++ b/ApplicationLibCode/UserInterface/RiuMultiPlotPage.cpp @@ -537,7 +537,7 @@ void RiuMultiPlotPage::onSelectionManagerSelectionChanged( const std::set& for ( RiuPlotWidget* plotWidget : m_plotWidgets ) { - CAF_ASSERT( plotWidget ); + if ( !plotWidget ) continue; RimPlot* plot = plotWidget->plotDefinition(); if ( !plot ) continue; diff --git a/ApplicationLibCode/UserInterface/RiuMultiPlotPage.h b/ApplicationLibCode/UserInterface/RiuMultiPlotPage.h index 525c9e3585..9c1f3c66a5 100644 --- a/ApplicationLibCode/UserInterface/RiuMultiPlotPage.h +++ b/ApplicationLibCode/UserInterface/RiuMultiPlotPage.h @@ -53,16 +53,6 @@ class RiuMultiPlotPage : public QWidget, public caf::SelectionChangedReceiver, p { Q_OBJECT -public: - enum class ColumnCount - { - COLUMNS_1 = 1, - COLUMNS_2 = 2, - COLUMNS_3 = 3, - COLUMNS_4 = 4, - COLUMNS_UNLIMITED = 1000, - }; - public: RiuMultiPlotPage( RimPlotWindow* plotDefinition, QWidget* parent = nullptr ); ~RiuMultiPlotPage() override; diff --git a/ApplicationLibCode/UserInterface/RiuPlotMainWindow.cpp b/ApplicationLibCode/UserInterface/RiuPlotMainWindow.cpp index 44a1b780b9..fa32515631 100644 --- a/ApplicationLibCode/UserInterface/RiuPlotMainWindow.cpp +++ b/ApplicationLibCode/UserInterface/RiuPlotMainWindow.cpp @@ -1025,7 +1025,6 @@ void RiuPlotMainWindow::selectedObjectsChanged() // The only way to get to this code is by selection change initiated from the project tree view // As we are activating an MDI-window, the focus is given to this MDI-window // Set focus back to the tree view to be able to continue keyboard tree view navigation - projectTree->raise(); projectTree->treeView()->setFocus(); } }