From 7903a62cc5f87aff4936d03d97ae05131acf9de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Jensen?= Date: Mon, 7 May 2018 09:45:50 +0200 Subject: [PATCH] #2818 Summary. Add new-plot-commands to context menus --- .../RicNewSummaryCrossPlotFeature.cpp | 23 ++++++++++++++++ .../RicNewSummaryPlotFeature.cpp | 27 ++++++++++++++++--- .../RicSummaryCurveCreator.cpp | 8 +++--- .../RicSummaryCurveCreator.h | 5 ++-- .../RicSummaryCurveCreatorDialog.cpp | 9 +++++++ .../RicSummaryCurveCreatorDialog.h | 2 ++ .../RicSummaryCurveCreatorSplitterUi.cpp | 8 ++++++ .../RicSummaryCurveCreatorSplitterUi.h | 2 ++ .../RimContextCommandBuilder.cpp | 13 +++++++-- .../RiuSummaryCurveDefSelection.cpp | 20 +++++++------- .../RiuSummaryCurveDefSelection.h | 2 +- 11 files changed, 96 insertions(+), 23 deletions(-) diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicNewSummaryCrossPlotFeature.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicNewSummaryCrossPlotFeature.cpp index ccb09a87c2..55803c2e12 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicNewSummaryCrossPlotFeature.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicNewSummaryCrossPlotFeature.cpp @@ -20,6 +20,7 @@ #include "RiaApplication.h" #include "RiaPreferences.h" +#include "RiaSummaryTools.h" #include "RicEditSummaryPlotFeature.h" #include "RicSummaryCurveCreator.h" @@ -30,9 +31,13 @@ #include "RimSummaryCrossPlotCollection.h" #include "RimSummaryCurveFilter.h" #include "RimSummaryPlot.h" +#include "RimSummaryCase.h" +#include "RimSummaryCaseCollection.h" #include "RiuPlotMainWindowTools.h" +#include "cafSelectionManagerTools.h" + #include "cvfAssert.h" #include @@ -45,6 +50,24 @@ CAF_CMD_SOURCE_INIT(RicNewSummaryCrossPlotFeature, "RicNewSummaryCrossPlotFeatur //-------------------------------------------------------------------------------------------------- bool RicNewSummaryCrossPlotFeature::isCommandEnabled() { + RimSummaryCrossPlotCollection* sumPlotColl = nullptr; + + caf::PdmObject* selObj = dynamic_cast(caf::SelectionManager::instance()->selectedItem()); + if (selObj) + { + sumPlotColl = RiaSummaryTools::parentCrossPlotCollection(selObj); + } + + if (sumPlotColl) return true; + + // Multiple case selections + std::vector selectedItems = caf::selectedObjectsByTypeStrict(); + + for (auto item : selectedItems) + { + if (!dynamic_cast(item) && !dynamic_cast(item)) + return false; + } return true; } diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicNewSummaryPlotFeature.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicNewSummaryPlotFeature.cpp index 4c6848a513..6a95c1067e 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicNewSummaryPlotFeature.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicNewSummaryPlotFeature.cpp @@ -29,11 +29,14 @@ #include "RimSummaryCurveFilter.h" #include "RimSummaryPlot.h" #include "RimSummaryPlotCollection.h" +#include "RimSummaryCase.h" +#include "RimSummaryCaseCollection.h" #include "RiuPlotMainWindow.h" #include "cvfAssert.h" -#include "cafSelectionManager.h" +#include "cafSelectionManagerTools.h" +//#include "cafPdmUiItem.h" #include @@ -55,7 +58,15 @@ bool RicNewSummaryPlotFeature::isCommandEnabled() if (sumPlotColl) return true; - return false; + // Multiple case selections + std::vector selectedItems = caf::selectedObjectsByTypeStrict(); + + for (auto item : selectedItems) + { + if (!dynamic_cast(item) && !dynamic_cast(item)) + return false; + } + return true; } //-------------------------------------------------------------------------------------------------- @@ -66,6 +77,16 @@ void RicNewSummaryPlotFeature::onActionTriggered(bool isChecked) RimProject* project = RiaApplication::instance()->project(); CVF_ASSERT(project); + std::vector selectedCases = caf::selectedObjectsByType(); + std::vector selectedGroups = caf::selectedObjectsByType(); + + // Append grouped cases + for (auto group : selectedGroups) + { + auto groupCases = group->allSummaryCases(); + selectedCases.insert(selectedCases.end(), groupCases.begin(), groupCases.end()); + } + auto dialog = RicEditSummaryPlotFeature::curveCreatorDialog(); if (!dialog->isVisible()) @@ -77,7 +98,7 @@ void RicNewSummaryPlotFeature::onActionTriggered(bool isChecked) dialog->raise(); } - dialog->updateFromSummaryPlot(nullptr); + dialog->updateFromDefaultCases(selectedCases); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.cpp index c4a0ace6bf..39f63962f1 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.cpp @@ -129,7 +129,7 @@ RimSummaryPlot* RicSummaryCurveCreator::previewPlot() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicSummaryCurveCreator::updateFromSummaryPlot(RimSummaryPlot* targetPlot) +void RicSummaryCurveCreator::updateFromSummaryPlot(RimSummaryPlot* targetPlot, const std::vector& defaultCases) { if (targetPlot == nullptr || m_targetPlot != targetPlot) { @@ -145,7 +145,7 @@ void RicSummaryCurveCreator::updateFromSummaryPlot(RimSummaryPlot* targetPlot) } else { - setDefaultCurveSelection(); + setDefaultCurveSelection(defaultCases); m_previewPlot->enableAutoPlotTitle(true); } @@ -616,9 +616,9 @@ void RicSummaryCurveCreator::copyEnsembleCurveAndAddToPlot(const RimSummaryCurve //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicSummaryCurveCreator::setDefaultCurveSelection() +void RicSummaryCurveCreator::setDefaultCurveSelection(const std::vector& defaultCases) { - m_summaryCurveSelectionEditor->summaryAddressSelection()->setDefaultSelection(); + m_summaryCurveSelectionEditor->summaryAddressSelection()->setDefaultSelection(defaultCases); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.h b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.h index c12ef90a2d..096ff70f2d 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.h +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.h @@ -59,7 +59,8 @@ public: virtual ~RicSummaryCurveCreator(); RimSummaryPlot* previewPlot() const; - void updateFromSummaryPlot(RimSummaryPlot* targetPlot); + void updateFromSummaryPlot(RimSummaryPlot* targetPlot, + const std::vector& defaultCases = std::vector()); QWidget* addressSelectionWidget(QWidget* parent); @@ -87,7 +88,7 @@ private: void updateTargetPlot(); static void copyCurveAndAddToPlot(const RimSummaryCurve *curve, RimSummaryPlot *plot, bool forceVisible = false); static void copyEnsembleCurveAndAddToPlot(const RimSummaryCurve *curve, RimEnsembleCurveSet* curveSet, bool forceVisible = false); - void setDefaultCurveSelection(); + void setDefaultCurveSelection(const std::vector& defaultCases); void resetAllFields(); void initCurveAppearanceCalculator(RimSummaryCurveAppearanceCalculator& curveAppearanceCalc); diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorDialog.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorDialog.cpp index 52ad89ddc3..4ccfd05e8f 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorDialog.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorDialog.cpp @@ -65,6 +65,15 @@ void RicSummaryCurveCreatorDialog::updateFromSummaryPlot(RimSummaryPlot* summary m_curveCreatorSplitterUi->updateUi(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSummaryCurveCreatorDialog::updateFromDefaultCases(const std::vector defaultCases) +{ + m_curveCreatorSplitterUi->updateFromDefaultCases(defaultCases); + m_curveCreatorSplitterUi->updateUi(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorDialog.h b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorDialog.h index 75097a328f..7ffb7194f0 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorDialog.h +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorDialog.h @@ -22,6 +22,7 @@ class RicSummaryCurveCreatorSplitterUi; class RimSummaryPlot; +class RimSummaryCase; //================================================================================================== /// @@ -35,6 +36,7 @@ public: ~RicSummaryCurveCreatorDialog(); void updateFromSummaryPlot(RimSummaryPlot* summaryPlot); + void updateFromDefaultCases(const std::vector defaultCases); private slots: void slotDialogFinished(); diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorSplitterUi.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorSplitterUi.cpp index a9974dd82b..84401ca1e0 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorSplitterUi.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorSplitterUi.cpp @@ -66,6 +66,14 @@ void RicSummaryCurveCreatorSplitterUi::updateFromSummaryPlot(RimSummaryPlot* sum m_summaryCurveCreator->updateFromSummaryPlot(summaryPlot); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSummaryCurveCreatorSplitterUi::updateFromDefaultCases(const std::vector defaultCases) +{ + m_summaryCurveCreator->updateFromSummaryPlot(nullptr, defaultCases); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorSplitterUi.h b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorSplitterUi.h index cca921ccbf..b7872fbbc2 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorSplitterUi.h +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorSplitterUi.h @@ -24,6 +24,7 @@ #include class RimSummaryPlot; +class RimSummaryCase; class RicSummaryCurveCreator; class QMinimizePanel; @@ -52,6 +53,7 @@ public: ~RicSummaryCurveCreatorSplitterUi(); void updateFromSummaryPlot(RimSummaryPlot* summaryPlot); + void updateFromDefaultCases(const std::vector defaultCases); private: virtual void recursivelyConfigureAndUpdateTopLevelUiItems(const std::vector& topLevelUiItems, diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index 500983847f..2ada56675b 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -485,17 +485,23 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "RicImportSummaryCaseFeature"; menuBuilder << "RicImportSummaryCasesFeature"; menuBuilder << "RicImportEnsembleFeature"; + menuBuilder << "RicNewSummaryPlotFeature"; + menuBuilder << "RicNewSummaryCrossPlotFeature"; + menuBuilder.addSeparator(); } else if (dynamic_cast(uiItem)) { menuBuilder << "RicImportSummaryCaseFeature"; menuBuilder << "RicImportSummaryCasesFeature"; menuBuilder << "RicImportEnsembleFeature"; + menuBuilder << "RicNewSummaryPlotFeature"; + menuBuilder << "RicNewSummaryCrossPlotFeature"; + menuBuilder.addSeparator(); if (!dynamic_cast(uiItem)) { menuBuilder << "RicShowSummaryCurveCalculatorFeature"; - menuBuilder << "RicNewSummaryPlotFeature"; + //menuBuilder << "RicNewSummaryPlotFeature"; } } else if (dynamic_cast(uiItem)) @@ -652,8 +658,11 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "RicShowPlotDataFeature"; menuBuilder << "RicShowTotalAllocationDataFeature"; + menuBuilder << "RicNewSummaryPlotFeature"; + menuBuilder << "RicNewSummaryCrossPlotFeature"; menuBuilder << "RicSummaryCurveSwitchAxisFeature"; - + menuBuilder.addSeparator(); + if (!menuBuilder.isCmdFeatureAdded("RicNewFishbonesSubsFeature")) { menuBuilder << "RicNewFishbonesSubsFeature"; diff --git a/ApplicationCode/UserInterface/RiuSummaryCurveDefSelection.cpp b/ApplicationCode/UserInterface/RiuSummaryCurveDefSelection.cpp index 363864bd72..07695e097e 100644 --- a/ApplicationCode/UserInterface/RiuSummaryCurveDefSelection.cpp +++ b/ApplicationCode/UserInterface/RiuSummaryCurveDefSelection.cpp @@ -296,7 +296,7 @@ void RiuSummaryCurveDefSelection::setFieldChangedHandler(const std::function& defaultCases) { RimProject* proj = RiaApplication::instance()->project(); auto allSumCases = proj->allSummaryCases(); @@ -304,17 +304,15 @@ void RiuSummaryCurveDefSelection::setDefaultSelection() { RifEclipseSummaryAddress defaultAddress = RifEclipseSummaryAddress::fieldVarAddress("FOPT"); - RiaSummaryCurveDefinition curveDef(allSumCases[0], defaultAddress); + std::vector selectTheseCases = defaultCases; + if (selectTheseCases.empty()) selectTheseCases.push_back(allSumCases[0]); + std::vector curveDefs; - curveDefs.push_back(curveDef); - - // DEBUG - //{ - // RifEclipseSummaryAddress defaultAddress = RifEclipseSummaryAddress::fieldVarAddress("FOPTH"); - - // RiaSummaryCurveDefinition curveDef(allSumCases[0], defaultAddress); - // curveDefs.push_back(curveDef); - //} + for(RimSummaryCase* c : selectTheseCases) + { + RiaSummaryCurveDefinition curveDef(c, defaultAddress); + curveDefs.push_back(curveDef); + } setSelectedCurveDefinitions(curveDefs); } diff --git a/ApplicationCode/UserInterface/RiuSummaryCurveDefSelection.h b/ApplicationCode/UserInterface/RiuSummaryCurveDefSelection.h index 4cdda0670b..46eb4118ed 100644 --- a/ApplicationCode/UserInterface/RiuSummaryCurveDefSelection.h +++ b/ApplicationCode/UserInterface/RiuSummaryCurveDefSelection.h @@ -55,7 +55,7 @@ public: void setMultiSelectionMode(bool multiSelectionMode); void setFieldChangedHandler(const std::function& handlerFunc); - void setDefaultSelection(); + void setDefaultSelection(const std::vector& defaultCases); private: virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField,