diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake b/ApplicationLibCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake index 0d368a7bca..d7571f18dd 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake @@ -1,6 +1,7 @@ set (SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryPlotFeature.h +${CMAKE_CURRENT_LIST_DIR}/RicNewDefaultSummaryPlotFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryCrossPlotFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryCurveFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicSummaryPlotFeatureImpl.h @@ -47,6 +48,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicNewDerivedSummaryFeature.h set (SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryPlotFeature.cpp +${CMAKE_CURRENT_LIST_DIR}/RicNewDefaultSummaryPlotFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryCrossPlotFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryCurveFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicSummaryPlotFeatureImpl.cpp diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewDefaultSummaryPlotFeature.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewDefaultSummaryPlotFeature.cpp new file mode 100644 index 0000000000..a2ef7faa38 --- /dev/null +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewDefaultSummaryPlotFeature.cpp @@ -0,0 +1,192 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2016- Statoil 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicNewDefaultSummaryPlotFeature.h" + +#include "RiaPreferences.h" +#include "RiaSummaryTools.h" + +#include "RicEditSummaryPlotFeature.h" +#include "RicNewSummaryCurveFeature.h" +#include "RicNewSummaryEnsembleCurveSetFeature.h" +#include "RicSummaryPlotEditorDialog.h" +#include "RicSummaryPlotEditorUi.h" +#include "RicSummaryPlotFeatureImpl.h" + +#include "RimCustomObjectiveFunctionCollection.h" +#include "RimEnsembleCurveFilter.h" +#include "RimEnsembleCurveFilterCollection.h" +#include "RimMainPlotCollection.h" +#include "RimProject.h" +#include "RimRegularLegendConfig.h" +#include "RimSummaryCase.h" +#include "RimSummaryCaseCollection.h" +#include "RimSummaryCaseMainCollection.h" +#include "RimSummaryCurveFilter.h" +#include "RimSummaryPlot.h" +#include "RimSummaryPlotCollection.h" + +#include "RiuPlotMainWindow.h" +#include "RiuPlotMainWindowTools.h" + +#include "cafSelectionManagerTools.h" +#include "cvfAssert.h" + +#include + +CAF_CMD_SOURCE_INIT( RicNewDefaultSummaryPlotFeature, "RicNewDefaultSummaryPlotFeature" ); + +void extractPlotObjectsFromSelection( std::vector* selectedIndividualSummaryCases, + std::vector* selectedEnsembles ) +{ + CAF_ASSERT( selectedIndividualSummaryCases && selectedEnsembles ); + + // First try selected ensembles + caf::SelectionManager::instance()->objectsByTypeStrict( selectedEnsembles ); + if ( !selectedEnsembles->empty() ) + { + return; + } + // Second try selected summary cases + caf::SelectionManager::instance()->objectsByTypeStrict( selectedIndividualSummaryCases ); + if ( !selectedIndividualSummaryCases->empty() ) + { + return; + } + + RimSummaryPlotCollection* sumPlotColl = + caf::SelectionManager::instance()->selectedItemAncestorOfType(); + + if ( sumPlotColl ) + { + RimSummaryCase* firstIndividualSummaryCase = nullptr; + RimSummaryCaseCollection* firstEnsemble = nullptr; + + auto sumCaseVector = RimProject::current()->allSummaryCases(); + for ( RimSummaryCase* summaryCase : sumCaseVector ) + { + RimSummaryCaseCollection* parentEnsemble = nullptr; + summaryCase->firstAncestorOrThisOfType( parentEnsemble ); + if ( !parentEnsemble && !firstIndividualSummaryCase ) + { + firstIndividualSummaryCase = summaryCase; + break; + } + else if ( parentEnsemble && !firstEnsemble ) + { + firstEnsemble = parentEnsemble; + } + } + if ( firstIndividualSummaryCase ) + { + selectedIndividualSummaryCases->push_back( firstIndividualSummaryCase ); + } + else if ( firstEnsemble ) + { + selectedEnsembles->push_back( firstEnsemble ); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimSummaryPlot* RicNewDefaultSummaryPlotFeature::createFromSummaryCases( RimSummaryPlotCollection* plotCollection, + const std::vector& summaryCases ) +{ + RimSummaryPlot* newPlot = plotCollection->createSummaryPlotWithAutoTitle(); + + for ( RimSummaryCase* sumCase : summaryCases ) + { + RicSummaryPlotFeatureImpl::addDefaultCurvesToPlot( newPlot, sumCase ); + } + + newPlot->applyDefaultCurveAppearances(); + newPlot->loadDataAndUpdate(); + + plotCollection->updateConnectedEditors(); + + RiuPlotMainWindowTools::setExpanded( newPlot ); + RiuPlotMainWindowTools::selectAsCurrentItem( newPlot ); + return newPlot; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicNewDefaultSummaryPlotFeature::isCommandEnabled() +{ + std::vector selectedIndividualSummaryCases; + std::vector selectedEnsembles; + + extractPlotObjectsFromSelection( &selectedIndividualSummaryCases, &selectedEnsembles ); + + RimCustomObjectiveFunctionCollection* customObjFuncCollection = nullptr; + RimEnsembleCurveFilter* curveFilter = nullptr; + caf::PdmObject* selObj = dynamic_cast( caf::SelectionManager::instance()->selectedItem() ); + if ( selObj ) + { + selObj->firstAncestorOrThisOfType( customObjFuncCollection ); + selObj->firstAncestorOrThisOfType( curveFilter ); + } + if ( customObjFuncCollection || curveFilter ) return false; + + return !( selectedIndividualSummaryCases.empty() && selectedEnsembles.empty() ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicNewDefaultSummaryPlotFeature::onActionTriggered( bool isChecked ) +{ + std::vector selectedIndividualSummaryCases; + std::vector selectedEnsembles; + extractPlotObjectsFromSelection( &selectedIndividualSummaryCases, &selectedEnsembles ); + + if ( !selectedIndividualSummaryCases.empty() ) + { + RimSummaryPlotCollection* sumPlotColl = RimProject::current()->mainPlotCollection()->summaryPlotCollection(); + createFromSummaryCases( sumPlotColl, selectedIndividualSummaryCases ); + } + else + { + CAF_ASSERT( !selectedEnsembles.empty() ); + RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetsAndUpdate( selectedEnsembles ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicNewDefaultSummaryPlotFeature::setupActionLook( QAction* actionToSetup ) +{ + std::vector selectedIndividualSummaryCases; + std::vector selectedEnsembles; + + extractPlotObjectsFromSelection( &selectedIndividualSummaryCases, &selectedEnsembles ); + + if ( !selectedIndividualSummaryCases.empty() ) + { + actionToSetup->setText( "New Summary Plot" ); + } + else + { + actionToSetup->setText( "New Ensemble Summary Plot" ); + } + actionToSetup->setIcon( QIcon( ":/SummaryPlotLight16x16.png" ) ); +} diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewDefaultSummaryPlotFeature.h b/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewDefaultSummaryPlotFeature.h new file mode 100644 index 0000000000..9c49add0a5 --- /dev/null +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewDefaultSummaryPlotFeature.h @@ -0,0 +1,44 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2016- Statoil 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "RicfCommandObject.h" + +#include "cafCmdFeature.h" + +class RimSummaryPlotCollection; +class RimSummaryCase; +class RimSummaryPlot; + +//================================================================================================== +/// +//================================================================================================== +class RicNewDefaultSummaryPlotFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +public: + static RimSummaryPlot* createFromSummaryCases( RimSummaryPlotCollection* plotCollection, + const std::vector& summaryCases ); + +protected: + bool isCommandEnabled() override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; +}; diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewSummaryCurveFeature.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewSummaryCurveFeature.cpp index 14a04a014d..d77449b522 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewSummaryCurveFeature.cpp +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewSummaryCurveFeature.cpp @@ -23,6 +23,8 @@ #include "RiaSummaryTools.h" #include "RimMainPlotCollection.h" +#include "RimObservedDataCollection.h" +#include "RimObservedSummaryData.h" #include "RimOilField.h" #include "RimProject.h" #include "RimSummaryCaseMainCollection.h" @@ -67,10 +69,6 @@ void RicNewSummaryCurveFeature::onActionTriggered( bool isChecked ) { defaultCase = plot->summaryCurves().back()->summaryCaseY(); } - else if ( project->activeOilField()->summaryCaseMainCollection()->summaryCaseCount() > 0 ) - { - defaultCase = project->activeOilField()->summaryCaseMainCollection()->summaryCase( 0 ); - } if ( !defaultCase ) { @@ -83,6 +81,16 @@ void RicNewSummaryCurveFeature::onActionTriggered( bool isChecked ) } } + if ( !defaultCase ) + { + auto allSummaryCases = project->activeOilField()->observedDataCollection()->allObservedSummaryData(); + + if ( !allSummaryCases.empty() ) + { + defaultCase = allSummaryCases.front(); + } + } + RimSummaryCurve* newCurve = new RimSummaryCurve(); // Use same counting as RicNewSummaryEnsembleCurveSetFeature::onActionTriggered diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewSummaryPlotFeature.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewSummaryPlotFeature.cpp index 3f596a66e3..4bbad31a79 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewSummaryPlotFeature.cpp +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewSummaryPlotFeature.cpp @@ -147,154 +147,3 @@ void RicNewSummaryPlotFeature::setupActionLook( QAction* actionToSetup ) actionToSetup->setText( "Open Summary Plot Editor" ); actionToSetup->setIcon( QIcon( ":/SummaryPlotLight16x16.png" ) ); } - -//================================================================================================== -/// -//================================================================================================== - -#include "RicNewSummaryCurveFeature.h" -#include "RicSummaryPlotFeatureImpl.h" -#include "RimMainPlotCollection.h" -#include "RiuPlotMainWindowTools.h" - -CAF_CMD_SOURCE_INIT( RicNewDefaultSummaryPlotFeature, "RicNewDefaultSummaryPlotFeature" ); - -void extractPlotObjectsFromSelection( std::vector* selectedIndividualSummaryCases, - std::vector* selectedEnsembles ) -{ - CAF_ASSERT( selectedIndividualSummaryCases && selectedEnsembles ); - - // First try selected ensembles - caf::SelectionManager::instance()->objectsByTypeStrict( selectedEnsembles ); - if ( !selectedEnsembles->empty() ) - { - return; - } - // Second try selected summary cases - caf::SelectionManager::instance()->objectsByTypeStrict( selectedIndividualSummaryCases ); - if ( !selectedIndividualSummaryCases->empty() ) - { - return; - } - - RimSummaryPlotCollection* sumPlotColl = - caf::SelectionManager::instance()->selectedItemAncestorOfType(); - - if ( sumPlotColl ) - { - RimSummaryCase* firstIndividualSummaryCase = nullptr; - RimSummaryCaseCollection* firstEnsemble = nullptr; - - auto sumCaseVector = RimProject::current()->allSummaryCases(); - for ( RimSummaryCase* summaryCase : sumCaseVector ) - { - RimSummaryCaseCollection* parentEnsemble = nullptr; - summaryCase->firstAncestorOrThisOfType( parentEnsemble ); - if ( !parentEnsemble && !firstIndividualSummaryCase ) - { - firstIndividualSummaryCase = summaryCase; - break; - } - else if ( parentEnsemble && !firstEnsemble ) - { - firstEnsemble = parentEnsemble; - } - } - if ( firstIndividualSummaryCase ) - { - selectedIndividualSummaryCases->push_back( firstIndividualSummaryCase ); - } - else if ( firstEnsemble ) - { - selectedEnsembles->push_back( firstEnsemble ); - } - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RimSummaryPlot* RicNewDefaultSummaryPlotFeature::createFromSummaryCases( RimSummaryPlotCollection* plotCollection, - const std::vector& summaryCases ) -{ - RimSummaryPlot* newPlot = plotCollection->createSummaryPlotWithAutoTitle(); - - for ( RimSummaryCase* sumCase : summaryCases ) - { - RicSummaryPlotFeatureImpl::addDefaultCurvesToPlot( newPlot, sumCase ); - } - - newPlot->applyDefaultCurveAppearances(); - newPlot->loadDataAndUpdate(); - - plotCollection->updateConnectedEditors(); - - RiuPlotMainWindowTools::setExpanded( newPlot ); - RiuPlotMainWindowTools::selectAsCurrentItem( newPlot ); - return newPlot; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RicNewDefaultSummaryPlotFeature::isCommandEnabled() -{ - std::vector selectedIndividualSummaryCases; - std::vector selectedEnsembles; - - extractPlotObjectsFromSelection( &selectedIndividualSummaryCases, &selectedEnsembles ); - - RimCustomObjectiveFunctionCollection* customObjFuncCollection = nullptr; - RimEnsembleCurveFilter* curveFilter = nullptr; - caf::PdmObject* selObj = dynamic_cast( caf::SelectionManager::instance()->selectedItem() ); - if ( selObj ) - { - selObj->firstAncestorOrThisOfType( customObjFuncCollection ); - selObj->firstAncestorOrThisOfType( curveFilter ); - } - if ( customObjFuncCollection || curveFilter ) return false; - - return !( selectedIndividualSummaryCases.empty() && selectedEnsembles.empty() ); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicNewDefaultSummaryPlotFeature::onActionTriggered( bool isChecked ) -{ - std::vector selectedIndividualSummaryCases; - std::vector selectedEnsembles; - extractPlotObjectsFromSelection( &selectedIndividualSummaryCases, &selectedEnsembles ); - - if ( !selectedIndividualSummaryCases.empty() ) - { - RimSummaryPlotCollection* sumPlotColl = RimProject::current()->mainPlotCollection()->summaryPlotCollection(); - createFromSummaryCases( sumPlotColl, selectedIndividualSummaryCases ); - } - else - { - CAF_ASSERT( !selectedEnsembles.empty() ); - RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetsAndUpdate( selectedEnsembles ); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicNewDefaultSummaryPlotFeature::setupActionLook( QAction* actionToSetup ) -{ - std::vector selectedIndividualSummaryCases; - std::vector selectedEnsembles; - - extractPlotObjectsFromSelection( &selectedIndividualSummaryCases, &selectedEnsembles ); - - if ( !selectedIndividualSummaryCases.empty() ) - { - actionToSetup->setText( "New Summary Plot" ); - } - else - { - actionToSetup->setText( "New Ensemble Summary Plot" ); - } - actionToSetup->setIcon( QIcon( ":/SummaryPlotLight16x16.png" ) ); -} diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewSummaryPlotFeature.h b/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewSummaryPlotFeature.h index 622c0bdf79..fbffd769fe 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewSummaryPlotFeature.h +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewSummaryPlotFeature.h @@ -22,11 +22,6 @@ #include "cafCmdFeature.h" -class RimSummaryPlotCollection; -class RimSummaryCase; -class RimSummaryCaseCollection; -class RimSummaryPlot; - //================================================================================================== /// //================================================================================================== @@ -40,21 +35,3 @@ protected: void onActionTriggered( bool isChecked ) override; void setupActionLook( QAction* actionToSetup ) override; }; - -//================================================================================================== -/// -//================================================================================================== -class RicNewDefaultSummaryPlotFeature : public caf::CmdFeature -{ - CAF_CMD_HEADER_INIT; - -public: - static RimSummaryPlot* createFromSummaryCases( RimSummaryPlotCollection* plotCollection, - const std::vector& summaryCases ); - -protected: - // Overrides - bool isCommandEnabled() override; - void onActionTriggered( bool isChecked ) override; - void setupActionLook( QAction* actionToSetup ) override; -}; diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp index f083d9a332..ffebcd0690 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp @@ -118,7 +118,9 @@ std::vector RicSummaryPlotFeatureImpl::addDefaultCurvesToPlot( QString curvesTextFilter = RiaApplication::instance()->preferences()->defaultSummaryCurvesTextFilter; QStringList curveFilters = curvesTextFilter.split( ";", QString::SkipEmptyParts ); - return addCurvesFromAddressFiltersToPlot( curveFilters, plot, summaryCase, false ); + bool addHistoryCurve = false; + + return addCurvesFromAddressFiltersToPlot( curveFilters, plot, summaryCase, addHistoryCurve ); } //-------------------------------------------------------------------------------------------------- @@ -840,6 +842,13 @@ std::vector RicSummaryPlotFeatureImpl::addCurvesFromAddressFil curveAddressesToUse.insert( historyAddressesToUse.begin(), historyAddressesToUse.end() ); } + if ( !curveFilters.isEmpty() && curveAddressesToUse.empty() && !addrs.empty() ) + { + // The curve filter returns no match, use first available address + + curveAddressesToUse.insert( *addrs.begin() ); + } + for ( const auto& addr : curveAddressesToUse ) { RimSummaryCurve* newCurve = new RimSummaryCurve(); diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCurve.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCurve.cpp index d0afd0713f..183b5f8e1b 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCurve.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCurve.cpp @@ -171,10 +171,10 @@ void RimSummaryCurve::setSummaryCaseY( RimSummaryCase* sumCase ) m_qwtCurveErrorBars->setSamples( nullptr ); } - if ( m_isEnsembleCurve().isPartiallyTrue() ) - { - setIsEnsembleCurve( sumCase->ensemble() ); - } + bool isEnsembleCurve = false; + if ( sumCase && sumCase->ensemble() ) isEnsembleCurve = true; + + setIsEnsembleCurve( isEnsembleCurve ); m_yValuesSummaryCase = sumCase; } @@ -427,10 +427,10 @@ void RimSummaryCurve::setSummaryCaseX( RimSummaryCase* sumCase ) { m_xValuesSummaryCase = sumCase; - if ( m_isEnsembleCurve().isPartiallyTrue() ) - { - setIsEnsembleCurve( sumCase->ensemble() ); - } + bool isEnsembleCurve = false; + if ( sumCase && sumCase->ensemble() ) isEnsembleCurve = true; + + setIsEnsembleCurve( isEnsembleCurve ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModelCommands/RimcSummaryPlotCollection.cpp b/ApplicationLibCode/ProjectDataModelCommands/RimcSummaryPlotCollection.cpp index 5abf052db9..8caa9c5f3c 100644 --- a/ApplicationLibCode/ProjectDataModelCommands/RimcSummaryPlotCollection.cpp +++ b/ApplicationLibCode/ProjectDataModelCommands/RimcSummaryPlotCollection.cpp @@ -15,8 +15,10 @@ // for more details. // ///////////////////////////////////////////////////////////////////////////////// + #include "RimcSummaryPlotCollection.h" +#include "SummaryPlotCommands/RicNewDefaultSummaryPlotFeature.h" #include "SummaryPlotCommands/RicNewSummaryEnsembleCurveSetFeature.h" #include "SummaryPlotCommands/RicNewSummaryPlotFeature.h" #include "SummaryPlotCommands/RicSummaryPlotFeatureImpl.h"