From 31a84181e637af98af4b4a25a03fcb0e9e4847b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Jensen?= Date: Sun, 19 Nov 2017 01:12:39 +0100 Subject: [PATCH] #2020 Move LAS files. Support for submenus and command features with custom name and user data --- .../RicExecuteScriptForCasesFeature.cpp | 30 +- .../RicExecuteScriptForCasesFeature.h | 3 - .../WellLogCommands/CMakeLists_files.cmake | 2 + .../RicMoveWellLogFilesFeature.cpp | 75 +++ .../RicMoveWellLogFilesFeature.h | 37 ++ .../RimContextCommandBuilder.cpp | 619 ++++++++++-------- .../RimContextCommandBuilder.h | 15 +- .../ProjectDataModel/RimProject.cpp | 95 +-- ApplicationCode/ProjectDataModel/RimProject.h | 3 - .../ProjectDataModel/RimWellPath.cpp | 10 +- .../ProjectDataModel/RimWellPath.h | 1 + .../UserInterface/RiuContextMenuLauncher.cpp | 6 +- .../UserInterface/RiuContextMenuLauncher.h | 5 +- .../UserInterface/RiuResultQwtPlot.cpp | 8 +- .../UserInterface/RiuSummaryQwtPlot.cpp | 7 +- .../UserInterface/RiuViewerCommands.cpp | 65 +- .../UserInterface/RiuWellAllocationPlot.cpp | 14 +- .../UserInterface/RiuWellLogPlot.cpp | 9 +- Fwk/AppFwk/cafCommand/CMakeLists.txt | 2 + Fwk/AppFwk/cafCommand/cafCmdFeature.cpp | 28 +- Fwk/AppFwk/cafCommand/cafCmdFeature.h | 4 +- .../cafCommand/cafCmdFeatureManager.cpp | 16 +- Fwk/AppFwk/cafCommand/cafCmdFeatureManager.h | 4 +- .../cafCommand/cafCmdFeatureMenuBuilder.cpp | 209 ++++++ .../cafCommand/cafCmdFeatureMenuBuilder.h | 110 ++++ 25 files changed, 920 insertions(+), 457 deletions(-) create mode 100644 ApplicationCode/Commands/WellLogCommands/RicMoveWellLogFilesFeature.cpp create mode 100644 ApplicationCode/Commands/WellLogCommands/RicMoveWellLogFilesFeature.h create mode 100644 Fwk/AppFwk/cafCommand/cafCmdFeatureMenuBuilder.cpp create mode 100644 Fwk/AppFwk/cafCommand/cafCmdFeatureMenuBuilder.h diff --git a/ApplicationCode/Commands/OctaveScriptCommands/RicExecuteScriptForCasesFeature.cpp b/ApplicationCode/Commands/OctaveScriptCommands/RicExecuteScriptForCasesFeature.cpp index f9a35557ca..c86253283a 100644 --- a/ApplicationCode/Commands/OctaveScriptCommands/RicExecuteScriptForCasesFeature.cpp +++ b/ApplicationCode/Commands/OctaveScriptCommands/RicExecuteScriptForCasesFeature.cpp @@ -53,27 +53,7 @@ bool RicExecuteScriptForCasesFeature::isCommandEnabled() //-------------------------------------------------------------------------------------------------- void RicExecuteScriptForCasesFeature::onActionTriggered(bool isChecked) { - // Dummy - handled by slotExecuteScriptForSelectedCases() -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicExecuteScriptForCasesFeature::setupActionLook(QAction* actionToSetup) -{ - actionToSetup->setText("Execute script"); -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicExecuteScriptForCasesFeature::slotExecuteScriptForSelectedCases() -{ - QAction* action = qobject_cast(sender()); - if (!action) return; - - QString scriptAbsolutePath = action->data().toString(); + QString scriptAbsolutePath = userData().toString(); RiuMainWindow* mainWindow = RiuMainWindow::instance(); mainWindow->showProcessMonitorDockPanel(); @@ -110,3 +90,11 @@ void RicExecuteScriptForCasesFeature::slotExecuteScriptForSelectedCases() } } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicExecuteScriptForCasesFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Execute script"); +} diff --git a/ApplicationCode/Commands/OctaveScriptCommands/RicExecuteScriptForCasesFeature.h b/ApplicationCode/Commands/OctaveScriptCommands/RicExecuteScriptForCasesFeature.h index 270131ddb0..8f72dabbb5 100644 --- a/ApplicationCode/Commands/OctaveScriptCommands/RicExecuteScriptForCasesFeature.h +++ b/ApplicationCode/Commands/OctaveScriptCommands/RicExecuteScriptForCasesFeature.h @@ -35,9 +35,6 @@ protected: virtual bool isCommandEnabled(); virtual void onActionTriggered( bool isChecked ); virtual void setupActionLook( QAction* actionToSetup ); - -private slots: - void slotExecuteScriptForSelectedCases(); }; diff --git a/ApplicationCode/Commands/WellLogCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/WellLogCommands/CMakeLists_files.cmake index 89da6b44b7..05eb69c4d6 100644 --- a/ApplicationCode/Commands/WellLogCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/WellLogCommands/CMakeLists_files.cmake @@ -27,6 +27,7 @@ ${CEE_CURRENT_LIST_DIR}RicChangeDataSourceFeature.h ${CEE_CURRENT_LIST_DIR}RicChangeDataSourceFeatureUi.h ${CEE_CURRENT_LIST_DIR}RicAsciiExportWellLogPlotFeature.h ${CEE_CURRENT_LIST_DIR}RicWellLogFileCloseFeature.h +${CEE_CURRENT_LIST_DIR}RicMoveWellLogFilesFeature.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -52,6 +53,7 @@ ${CEE_CURRENT_LIST_DIR}RicChangeDataSourceFeature.cpp ${CEE_CURRENT_LIST_DIR}RicChangeDataSourceFeatureUi.cpp ${CEE_CURRENT_LIST_DIR}RicAsciiExportWellLogPlotFeature.cpp ${CEE_CURRENT_LIST_DIR}RicWellLogFileCloseFeature.cpp +${CEE_CURRENT_LIST_DIR}RicMoveWellLogFilesFeature.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/Commands/WellLogCommands/RicMoveWellLogFilesFeature.cpp b/ApplicationCode/Commands/WellLogCommands/RicMoveWellLogFilesFeature.cpp new file mode 100644 index 0000000000..d4b6920bad --- /dev/null +++ b/ApplicationCode/Commands/WellLogCommands/RicMoveWellLogFilesFeature.cpp @@ -0,0 +1,75 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2015- Statoil ASA +// Copyright (C) 2015- Ceetron Solutions AS +// +// 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 "RicMoveWellLogFilesFeature.h" + +#include "RiaApplication.h" +#include "RimProject.h" +#include "RimWellPath.h" +#include "RimWellLogFile.h" +#include "RiuMainWindow.h" + +#include "cafPdmUiObjectEditorHandle.h" +#include "cafSelectionManagerTools.h" + +#include +#include + +CAF_CMD_SOURCE_INIT(RicMoveWellLogFilesFeature, "RicMoveWellLogFilesFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicMoveWellLogFilesFeature::isCommandEnabled() +{ + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicMoveWellLogFilesFeature::onActionTriggered(bool isChecked) +{ + const QVariant userData = this->userData(); + if (!userData.isNull() && userData.type() == QVariant::String) + { + RimProject* proj = RiaApplication::instance()->project(); + + RimWellPath* destWellPath = proj->wellPathByName(userData.toString()); + RimWellLogFile* wellLogFile = caf::firstAncestorOfTypeFromSelectedObject(); + RimWellPath* sourceWellPath = caf::firstAncestorOfTypeFromSelectedObject(); + + if (!destWellPath || !wellLogFile || !sourceWellPath) return; + + sourceWellPath->detachWellLogFile(wellLogFile); + destWellPath->addWellLogFile(wellLogFile); + + sourceWellPath->updateConnectedEditors(); + destWellPath->updateConnectedEditors(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicMoveWellLogFilesFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Move Well Log File(s)"); + actionToSetup->setIcon(QIcon(":/Well.png")); +} diff --git a/ApplicationCode/Commands/WellLogCommands/RicMoveWellLogFilesFeature.h b/ApplicationCode/Commands/WellLogCommands/RicMoveWellLogFilesFeature.h new file mode 100644 index 0000000000..f2b4d35997 --- /dev/null +++ b/ApplicationCode/Commands/WellLogCommands/RicMoveWellLogFilesFeature.h @@ -0,0 +1,37 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2015- Statoil ASA +// Copyright (C) 2015- Ceetron Solutions AS +// +// 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 "cafCmdFeature.h" + +//================================================================================================== +/// +//================================================================================================== +class RicMoveWellLogFilesFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + + // Overrides + virtual bool isCommandEnabled() override; + virtual void onActionTriggered( bool isChecked ) override; + virtual void setupActionLook( QAction* actionToSetup ) override; +}; diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index 94556be1fd..6a32fb0053 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -19,6 +19,8 @@ #include "RimContextCommandBuilder.h" +#include "RiaApplication.h" + #include "RimCalcScript.h" #include "RimCaseCollection.h" #include "RimCellRangeFilter.h" @@ -47,6 +49,7 @@ #include "RimIntersectionBox.h" #include "RimIntersectionCollection.h" #include "RimObservedData.h" +#include "RimProject.h" #include "RimScriptCollection.h" #include "RimSimWellInView.h" #include "RimSimWellInViewCollection.h" @@ -84,24 +87,30 @@ #include "RimWellPathFractureCollection.h" #endif // USE_PROTOTYPE_FEATURE_FRACTURES +#include "RiuMainWindow.h" + #include "ToggleCommands/RicToggleItemsFeatureImpl.h" #include "cafCmdFeature.h" #include "cafCmdFeatureManager.h" +#include "cafCmdFeatureMenuBuilder.h" #include "cafPdmUiItem.h" #include "cafSelectionManager.h" - +#include "cafSelectionManagerTools.h" #include "cvfAssert.h" #include #include +#include +#include "OctaveScriptCommands/RicExecuteScriptForCasesFeature.h" //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -QStringList RimContextCommandBuilder::commandsFromSelection() +caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() { - QStringList commandIds; + //QStringList commandIds; + caf::CmdFeatureMenuBuilder menuBuilder; std::vector uiItems; caf::SelectionManager::instance()->selectedItems(uiItems); @@ -113,366 +122,382 @@ QStringList RimContextCommandBuilder::commandsFromSelection() if (dynamic_cast(uiItem)) { - commandIds << "RicImportEclipseCaseFeature"; - commandIds << "RicImportInputEclipseCaseFeature"; - commandIds << "RicCreateGridCaseGroupFeature"; - commandIds << "RicEclipseCaseNewGroupFeature"; - commandIds << "RicCalculateNumberOfFloodedPoreVolumes"; + menuBuilder << "RicImportEclipseCaseFeature"; + menuBuilder << "RicImportInputEclipseCaseFeature"; + menuBuilder << "RicCreateGridCaseGroupFeature"; + menuBuilder << "RicEclipseCaseNewGroupFeature"; + menuBuilder << "RicCalculateNumberOfFloodedPoreVolumes"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicPasteGeoMechViewsFeature"; - commandIds << "Separator"; + menuBuilder << "RicPasteGeoMechViewsFeature"; + menuBuilder << "Separator"; - commandIds << "RicNewViewFeature"; - commandIds << "Separator"; - commandIds << "RicCopyReferencesToClipboardFeature"; + menuBuilder << "RicNewViewFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicCopyReferencesToClipboardFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicPasteEclipseViewsFeature"; - commandIds << "Separator"; - commandIds << "RicNewViewFeature"; - commandIds << "Separator"; - commandIds << "RicCopyReferencesToClipboardFeature"; - commandIds << "RicSaveEclipseInputVisibleCellsFeature"; + menuBuilder << "RicPasteEclipseViewsFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicNewViewFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicCopyReferencesToClipboardFeature"; + menuBuilder << "RicSaveEclipseInputVisibleCellsFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicPasteEclipseCasesFeature"; - commandIds << "Separator"; - commandIds << "RicNewStatisticsCaseFeature"; + menuBuilder << "RicPasteEclipseCasesFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicNewStatisticsCaseFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicNewViewFeature"; - commandIds << "RicComputeStatisticsFeature"; - commandIds << "Separator"; + menuBuilder << "RicNewViewFeature"; + menuBuilder << "RicComputeStatisticsFeature"; + menuBuilder << "Separator"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicPasteEclipseCasesFeature"; - commandIds << "RicPasteEclipseViewsFeature"; - commandIds << "Separator"; + menuBuilder << "RicPasteEclipseCasesFeature"; + menuBuilder << "RicPasteEclipseViewsFeature"; + menuBuilder << "Separator"; - commandIds << "RicNewViewFeature"; - commandIds << "RicShowFlowCharacteristicsPlotFeature"; - commandIds << "RicEclipseCaseNewGroupFeature"; - commandIds << "Separator"; - commandIds << "RicCopyReferencesToClipboardFeature"; - commandIds << "Separator"; + menuBuilder << "RicNewViewFeature"; + menuBuilder << "RicShowFlowCharacteristicsPlotFeature"; + menuBuilder << "RicEclipseCaseNewGroupFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicCopyReferencesToClipboardFeature"; + menuBuilder << "Separator"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicPasteGeoMechViewsFeature"; - commandIds << "Separator"; - commandIds << "RicNewViewFeature"; - commandIds << "Separator"; + menuBuilder << "RicPasteGeoMechViewsFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicNewViewFeature"; + menuBuilder << "Separator"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicPasteEclipseCasesFeature"; - commandIds << "Separator"; - commandIds << "RicEclipseCaseNewGroupFeature"; + menuBuilder << "RicPasteEclipseCasesFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicEclipseCaseNewGroupFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicSaveEclipseResultAsInputPropertyFeature"; + menuBuilder << "RicSaveEclipseResultAsInputPropertyFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicAddEclipseInputPropertyFeature"; + menuBuilder << "RicAddEclipseInputPropertyFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicSaveEclipseInputPropertyFeature"; + menuBuilder << "RicSaveEclipseInputPropertyFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicRangeFilterNewFeature"; - commandIds << "RicRangeFilterNewSliceIFeature"; - commandIds << "RicRangeFilterNewSliceJFeature"; - commandIds << "RicRangeFilterNewSliceKFeature"; + menuBuilder << "RicRangeFilterNewFeature"; + menuBuilder << "RicRangeFilterNewSliceIFeature"; + menuBuilder << "RicRangeFilterNewSliceJFeature"; + menuBuilder << "RicRangeFilterNewSliceKFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicRangeFilterInsertFeature"; - commandIds << "RicRangeFilterNewSliceIFeature"; - commandIds << "RicRangeFilterNewSliceJFeature"; - commandIds << "RicRangeFilterNewSliceKFeature"; + menuBuilder << "RicRangeFilterInsertFeature"; + menuBuilder << "RicRangeFilterNewSliceIFeature"; + menuBuilder << "RicRangeFilterNewSliceJFeature"; + menuBuilder << "RicRangeFilterNewSliceKFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicEclipsePropertyFilterNewFeature"; + menuBuilder << "RicEclipsePropertyFilterNewFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicEclipsePropertyFilterInsertFeature"; - commandIds << "RicApplyPropertyFilterAsCellResultFeature"; + menuBuilder << "RicEclipsePropertyFilterInsertFeature"; + menuBuilder << "RicApplyPropertyFilterAsCellResultFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicGeoMechPropertyFilterNewFeature"; + menuBuilder << "RicGeoMechPropertyFilterNewFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicGeoMechPropertyFilterInsertFeature"; - commandIds << "RicApplyPropertyFilterAsCellResultFeature"; + menuBuilder << "RicGeoMechPropertyFilterInsertFeature"; + menuBuilder << "RicApplyPropertyFilterAsCellResultFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicWellPathsImportFileFeature"; - commandIds << "RicWellPathsImportSsihubFeature"; - commandIds << "RicWellLogsImportFileFeature"; - commandIds << "Separator"; + menuBuilder << "RicWellPathsImportFileFeature"; + menuBuilder << "RicWellPathsImportSsihubFeature"; + menuBuilder << "RicWellLogsImportFileFeature"; + menuBuilder << "Separator"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicWellPathsImportFileFeature"; - commandIds << "RicWellLogsImportFileFeature"; - commandIds << "Separator"; - commandIds << "RicNewRftPlotFeature"; - commandIds << "RicNewPltPlotFeature"; - commandIds << "RicNewWellLogFileCurveFeature"; - commandIds << "RicNewWellLogCurveExtractionFeature"; - commandIds << "RicNewWellPathIntersectionFeature"; + menuBuilder << "RicWellPathsImportFileFeature"; + menuBuilder << "RicWellLogsImportFileFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicNewRftPlotFeature"; + menuBuilder << "RicNewPltPlotFeature"; + menuBuilder << "RicNewWellLogFileCurveFeature"; + menuBuilder << "RicNewWellLogCurveExtractionFeature"; + menuBuilder << "RicNewWellPathIntersectionFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicWellPathsImportFileFeature"; - commandIds << "RicWellLogsImportFileFeature"; + menuBuilder << "RicWellPathsImportFileFeature"; + menuBuilder << "RicWellLogsImportFileFeature"; + + menuBuilder << "Separator"; + + menuBuilder.subMenuStart("Move LAS file to well path"); + + RimWellPath* parentWellPath = caf::firstAncestorOfTypeFromSelectedObject(); + QString parentWellPathName = parentWellPath ? parentWellPath->name() : ""; + + for (RimWellPath* wellPath : allWellPaths()) + { + if (wellPath->name() != parentWellPathName) + { + menuBuilder.addCmdFeatureWithUserData("RicMoveWellLogFilesFeature", wellPath->name(), wellPath->name()); + } + } + menuBuilder.subMenuEnd(); } else if (dynamic_cast(uiItem)) { - commandIds << "RicDeleteRftPlotFeature"; + menuBuilder << "RicDeleteRftPlotFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicDeletePltPlotFeature"; + menuBuilder << "RicDeletePltPlotFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicEditScriptFeature"; - commandIds << "Separator"; - commandIds << "RicNewScriptFeature"; - commandIds << "Separator"; - commandIds << "RicExecuteScriptFeature"; + menuBuilder << "RicEditScriptFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicNewScriptFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicExecuteScriptFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicNewScriptFeature"; - commandIds << "Separator"; - commandIds << "RicAddScriptPathFeature"; - commandIds << "RicRefreshScriptsFeature"; - commandIds << "Separator"; - commandIds << "RicDeleteScriptPathFeature"; + menuBuilder << "RicNewScriptFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicAddScriptPathFeature"; + menuBuilder << "RicRefreshScriptsFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicDeleteScriptPathFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicShowAllLinkedViewsFeature"; + menuBuilder << "RicShowAllLinkedViewsFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicShowAllLinkedViewsFeature"; - commandIds << "Separator"; - commandIds << "RicDeleteAllLinkedViewsFeature"; + menuBuilder << "RicShowAllLinkedViewsFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicDeleteAllLinkedViewsFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicPasteWellLogPlotFeature"; - commandIds << "Separator"; - commandIds << "RicNewWellLogPlotFeature"; + menuBuilder << "RicPasteWellLogPlotFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicNewWellLogPlotFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicNewRftPlotFeature"; + menuBuilder << "RicNewRftPlotFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicNewPltPlotFeature"; + menuBuilder << "RicNewPltPlotFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicPasteSummaryPlotFeature"; - commandIds << "RicPasteAsciiDataToSummaryPlotFeature"; - commandIds << "Separator"; - commandIds << "RicNewSummaryPlotFeature"; - commandIds << "Separator"; - commandIds << "RicShowSummaryCurveCalculatorFeature"; + menuBuilder << "RicPasteSummaryPlotFeature"; + menuBuilder << "RicPasteAsciiDataToSummaryPlotFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicNewSummaryPlotFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicShowSummaryCurveCalculatorFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicNewSummaryCrossPlotFeature"; + menuBuilder << "RicNewSummaryCrossPlotFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicPasteWellLogPlotFeature"; - commandIds << "RicPasteWellLogTrackFeature"; - commandIds << "Separator"; - commandIds << "RicNewWellLogPlotTrackFeature"; - commandIds << "RicAsciiExportWellLogPlotFeature"; + menuBuilder << "RicPasteWellLogPlotFeature"; + menuBuilder << "RicPasteWellLogTrackFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicNewWellLogPlotTrackFeature"; + menuBuilder << "RicAsciiExportWellLogPlotFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicPasteWellLogTrackFeature"; - commandIds << "RicPasteWellLogCurveFeature"; - commandIds << "Separator"; - commandIds << "RicNewWellLogCurveExtractionFeature"; - commandIds << "RicNewWellLogRftCurveFeature"; - commandIds << "RicNewWellLogFileCurveFeature"; - commandIds << "Separator"; - commandIds << "RicDeleteWellLogPlotTrackFeature"; + menuBuilder << "RicPasteWellLogTrackFeature"; + menuBuilder << "RicPasteWellLogCurveFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicNewWellLogCurveExtractionFeature"; + menuBuilder << "RicNewWellLogRftCurveFeature"; + menuBuilder << "RicNewWellLogFileCurveFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicDeleteWellLogPlotTrackFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicPasteWellLogCurveFeature"; + menuBuilder << "RicPasteWellLogCurveFeature"; } else if (dynamic_cast(uiItem)) // This is also the definition for RimSummaryCrossPlot { - commandIds << "RicPasteSummaryCurveFeature"; - commandIds << "RicPasteSummaryCurveFilterFeature"; - commandIds << "RicPasteSummaryPlotFeature"; - commandIds << "RicPasteAsciiDataToSummaryPlotFeature"; - commandIds << "Separator"; - commandIds << "RicEditSummaryPlotFeature"; - commandIds << "RicNewSummaryPlotFeature"; - commandIds << "RicNewSummaryCurveFeature"; - commandIds << "RicNewSummaryCrossPlotCurveFeature"; - commandIds << "Separator"; - commandIds << "RicShowSummaryCurveCalculatorFeature"; - commandIds << "Separator"; - commandIds << "RicAsciiExportSummaryPlotFeature"; - commandIds << "Separator"; - commandIds << "RicCopyReferencesToClipboardFeature"; - commandIds << "Separator"; - commandIds << "RicViewZoomAllFeature"; + menuBuilder << "RicPasteSummaryCurveFeature"; + menuBuilder << "RicPasteSummaryCurveFilterFeature"; + menuBuilder << "RicPasteSummaryPlotFeature"; + menuBuilder << "RicPasteAsciiDataToSummaryPlotFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicEditSummaryPlotFeature"; + menuBuilder << "RicNewSummaryPlotFeature"; + menuBuilder << "RicNewSummaryCurveFeature"; + menuBuilder << "RicNewSummaryCrossPlotCurveFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicShowSummaryCurveCalculatorFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicAsciiExportSummaryPlotFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicCopyReferencesToClipboardFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicViewZoomAllFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicPasteSummaryCurveFeature"; - commandIds << "Separator"; - commandIds << "RicNewSummaryCurveFeature"; - commandIds << "RicNewSummaryCrossPlotCurveFeature"; - commandIds << "Separator"; - commandIds << "RicCopyReferencesToClipboardFeature"; - commandIds << "Separator"; - commandIds << "RicEditSummaryCurveCalculationFeature"; + menuBuilder << "RicPasteSummaryCurveFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicNewSummaryCurveFeature"; + menuBuilder << "RicNewSummaryCrossPlotCurveFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicCopyReferencesToClipboardFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicEditSummaryCurveCalculationFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicEditSummaryPlotFeature"; + menuBuilder << "RicEditSummaryPlotFeature"; } else if(dynamic_cast(uiItem)) { - commandIds << "RicPasteSummaryCurveFilterFeature"; - commandIds << "Separator"; - commandIds << "RicNewSummaryCurveFeature"; - commandIds << "Separator"; - commandIds << "RicCopyReferencesToClipboardFeature"; + menuBuilder << "RicPasteSummaryCurveFilterFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicNewSummaryCurveFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicCopyReferencesToClipboardFeature"; } else if (dynamic_cast(uiItem)) { if (!dynamic_cast(uiItem)) { - commandIds << "RicShowSummaryCurveCalculatorFeature"; - commandIds << "RicNewSummaryPlotFeature"; + menuBuilder << "RicShowSummaryCurveCalculatorFeature"; + menuBuilder << "RicNewSummaryPlotFeature"; } } else if (dynamic_cast(uiItem)) { - commandIds << "RicAddWellLogToPlotFeature"; + menuBuilder << "RicAddWellLogToPlotFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicAppendIntersectionFeature"; - commandIds << "RicAppendIntersectionBoxFeature"; + menuBuilder << "RicAppendIntersectionFeature"; + menuBuilder << "RicAppendIntersectionBoxFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicAppendIntersectionFeature"; - commandIds << "RicAppendIntersectionBoxFeature"; + menuBuilder << "RicAppendIntersectionFeature"; + menuBuilder << "RicAppendIntersectionBoxFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicAppendIntersectionFeature"; - commandIds << "RicAppendIntersectionBoxFeature"; + menuBuilder << "RicAppendIntersectionFeature"; + menuBuilder << "RicAppendIntersectionBoxFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicNewWellLogCurveExtractionFeature"; - commandIds << "RicNewWellLogRftCurveFeature"; - commandIds << "RicNewSimWellIntersectionFeature"; - commandIds << "RicNewRftPlotFeature"; - commandIds << "RicNewPltPlotFeature"; - commandIds << "RicShowWellAllocationPlotFeature"; + menuBuilder << "RicNewWellLogCurveExtractionFeature"; + menuBuilder << "RicNewWellLogRftCurveFeature"; + menuBuilder << "RicNewSimWellIntersectionFeature"; + menuBuilder << "RicNewRftPlotFeature"; + menuBuilder << "RicNewPltPlotFeature"; + menuBuilder << "RicShowWellAllocationPlotFeature"; } else if(dynamic_cast(uiItem)) { - commandIds << "RicImportFormationNamesFeature"; - commandIds << "RicReloadFormationNamesFeature"; + menuBuilder << "RicImportFormationNamesFeature"; + menuBuilder << "RicReloadFormationNamesFeature"; } else if(dynamic_cast(uiItem)) { - commandIds << "RicImportFormationNamesFeature"; - commandIds << "Separator"; - commandIds << "RicReloadFormationNamesFeature"; + menuBuilder << "RicImportFormationNamesFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicReloadFormationNamesFeature"; } else if ( dynamic_cast(uiItem) ) { - commandIds << "RicExportFaultsFeature"; + menuBuilder << "RicExportFaultsFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicAddStoredWellAllocationPlotFeature"; + menuBuilder << "RicAddStoredWellAllocationPlotFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicAddStoredFlowCharacteristicsPlotFeature"; + menuBuilder << "RicAddStoredFlowCharacteristicsPlotFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicShowFlowCharacteristicsPlotFeature"; + menuBuilder << "RicShowFlowCharacteristicsPlotFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicShowFlowCharacteristicsPlotFeature"; + menuBuilder << "RicShowFlowCharacteristicsPlotFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicShowGridStatisticsFeature"; + menuBuilder << "RicShowGridStatisticsFeature"; } #ifdef USE_PROTOTYPE_FEATURE_FRACTURES else if (dynamic_cast(uiItem)) { - commandIds << "RicNewSimWellFractureFeature"; + menuBuilder << "RicNewSimWellFractureFeature"; } else if (dynamic_cast(uiItem) || dynamic_cast(uiItem)) { - commandIds << "RicNewEllipseFractureTemplateFeature"; - commandIds << "RicNewStimPlanFractureTemplateFeature"; - commandIds << "Separator"; - commandIds << "RicConvertAllFractureTemplatesToMetricFeature"; - commandIds << "RicConvertAllFractureTemplatesToFieldFeature"; + menuBuilder << "RicNewEllipseFractureTemplateFeature"; + menuBuilder << "RicNewStimPlanFractureTemplateFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicConvertAllFractureTemplatesToMetricFeature"; + menuBuilder << "RicConvertAllFractureTemplatesToFieldFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicNewEllipseFractureTemplateFeature"; - commandIds << "RicNewStimPlanFractureTemplateFeature"; - commandIds << "Separator"; - commandIds << "RicConvertFractureTemplateUnitFeature"; + menuBuilder << "RicNewEllipseFractureTemplateFeature"; + menuBuilder << "RicNewStimPlanFractureTemplateFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicConvertFractureTemplateUnitFeature"; } #endif // USE_PROTOTYPE_FEATURE_FRACTURES if (dynamic_cast(uiItem)) { - commandIds << "Separator"; - commandIds << "RicLinkVisibleViewsFeature"; - commandIds << "RicLinkViewFeature"; - commandIds << "RicShowLinkOptionsFeature"; - commandIds << "RicSetMasterViewFeature"; - commandIds << "RicUnLinkViewFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicLinkVisibleViewsFeature"; + menuBuilder << "RicLinkViewFeature"; + menuBuilder << "RicShowLinkOptionsFeature"; + menuBuilder << "RicSetMasterViewFeature"; + menuBuilder << "RicUnLinkViewFeature"; } } @@ -487,41 +512,41 @@ QStringList RimContextCommandBuilder::commandsFromSelection() // without using dyncamic_cast. - commandIds << "RicPasteTimeHistoryCurveFeature"; - commandIds << "RicPasteAsciiDataCurveFeature"; - commandIds << "RicCopyReferencesToClipboardFeature"; + menuBuilder << "RicPasteTimeHistoryCurveFeature"; + menuBuilder << "RicPasteAsciiDataCurveFeature"; + menuBuilder << "RicCopyReferencesToClipboardFeature"; - commandIds << "RicShowPlotDataFeature"; - commandIds << "RicShowTotalAllocationDataFeature"; + menuBuilder << "RicShowPlotDataFeature"; + menuBuilder << "RicShowTotalAllocationDataFeature"; - commandIds << "RicSummaryCurveSwitchAxisFeature"; + menuBuilder << "RicSummaryCurveSwitchAxisFeature"; - commandIds << "RicNewFishbonesSubsFeature"; - commandIds << "RicNewPerforationIntervalFeature"; - commandIds << "RicEditPerforationCollectionFeature"; - commandIds << "RicExportFishbonesLateralsFeature"; - commandIds << "RicExportFishbonesWellSegmentsFeature"; - commandIds << "RicWellPathImportPerforationIntervalsFeature"; - commandIds << "RicWellPathExportCompletionDataFeature"; - commandIds << "RicWellPathImportCompletionsFileFeature"; - commandIds << "RicFlyToObjectFeature"; - commandIds << "RicExportCarfin"; + menuBuilder << "RicNewFishbonesSubsFeature"; + menuBuilder << "RicNewPerforationIntervalFeature"; + menuBuilder << "RicEditPerforationCollectionFeature"; + menuBuilder << "RicExportFishbonesLateralsFeature"; + menuBuilder << "RicExportFishbonesWellSegmentsFeature"; + menuBuilder << "RicWellPathImportPerforationIntervalsFeature"; + menuBuilder << "RicWellPathExportCompletionDataFeature"; + menuBuilder << "RicWellPathImportCompletionsFileFeature"; + menuBuilder << "RicFlyToObjectFeature"; + menuBuilder << "RicExportCarfin"; - commandIds << "RicImportObservedDataFeature"; - commandIds << "RicPasteSummaryCaseFeature"; - commandIds << "RicReloadSummaryCaseFeature"; - commandIds << "RicCreateSummaryCaseCollectionFeature"; - commandIds << "Separator"; - commandIds << "RicCutReferencesToClipboardFeature"; - commandIds << "Separator"; - commandIds << "RicCloseSummaryCaseFeature"; - commandIds << "RicCloseSummaryCaseInCollectionFeature"; - commandIds << "RicDeleteSummaryCaseCollectionFeature"; - commandIds << "RicCloseObservedDataFeature"; + menuBuilder << "RicImportObservedDataFeature"; + menuBuilder << "RicPasteSummaryCaseFeature"; + menuBuilder << "RicReloadSummaryCaseFeature"; + menuBuilder << "RicCreateSummaryCaseCollectionFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicCutReferencesToClipboardFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicCloseSummaryCaseFeature"; + menuBuilder << "RicCloseSummaryCaseInCollectionFeature"; + menuBuilder << "RicDeleteSummaryCaseCollectionFeature"; + menuBuilder << "RicCloseObservedDataFeature"; // Fracture commands #ifdef USE_PROTOTYPE_FEATURE_FRACTURES - commandIds << "RicNewWellPathFractureFeature"; + menuBuilder << "RicNewWellPathFractureFeature"; #endif // USE_PROTOTYPE_FEATURE_FRACTURES // Work in progress -- End @@ -529,55 +554,55 @@ QStringList RimContextCommandBuilder::commandsFromSelection() caf::PdmUiItem* uiItem = uiItems[0]; if (dynamic_cast(uiItem)) { - commandIds << "RicAddWellLogToPlotFeature"; + menuBuilder << "RicAddWellLogToPlotFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicExecuteScriptForCasesFeature"; + createExecuteScriptForCasesFeatureMenu(menuBuilder); } else if (dynamic_cast(uiItem)) { - commandIds << "RicReloadCaseFeature"; - commandIds << "RicExecuteScriptForCasesFeature"; - commandIds << "RicCloseSourSimDataFeature"; + menuBuilder << "RicReloadCaseFeature"; + createExecuteScriptForCasesFeatureMenu(menuBuilder); + menuBuilder << "RicCloseSourSimDataFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicAsciiExportSummaryPlotFeature"; + menuBuilder << "RicAsciiExportSummaryPlotFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicAsciiExportWellLogPlotFeature"; + menuBuilder << "RicAsciiExportWellLogPlotFeature"; } else if (dynamic_cast(uiItem) || dynamic_cast(uiItem) || dynamic_cast(uiItem)) { - commandIds << "RicExportToLasFileFeature"; - commandIds << "RicChangeDataSourceFeature"; + menuBuilder << "RicExportToLasFileFeature"; + menuBuilder << "RicChangeDataSourceFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicExportToLasFileFeature"; + menuBuilder << "RicExportToLasFileFeature"; } else if (dynamic_cast(uiItem) ) { - commandIds << "RicExportFaultsFeature"; + menuBuilder << "RicExportFaultsFeature"; } else if (dynamic_cast(uiItem)) { - commandIds << "RicPlotProductionRateFeature"; - commandIds << "RicShowContributingWellsFeature"; - commandIds << "Separator"; - commandIds << "RicEclipseWellShowLabelFeature"; - commandIds << "RicEclipseWellShowHeadFeature"; - commandIds << "RicEclipseWellShowPipeFeature"; - commandIds << "RicEclipseWellShowSpheresFeature"; - commandIds << "RicEclipseWellShowWellCellsFeature"; - commandIds << "RicEclipseWellShowWellCellFenceFeature"; + menuBuilder << "RicPlotProductionRateFeature"; + menuBuilder << "RicShowContributingWellsFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicEclipseWellShowLabelFeature"; + menuBuilder << "RicEclipseWellShowHeadFeature"; + menuBuilder << "RicEclipseWellShowPipeFeature"; + menuBuilder << "RicEclipseWellShowSpheresFeature"; + menuBuilder << "RicEclipseWellShowWellCellsFeature"; + menuBuilder << "RicEclipseWellShowWellCellFenceFeature"; #ifdef USE_PROTOTYPE_FEATURE_FRACTURES - commandIds << "Separator"; - commandIds << "RicNewSimWellFractureFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicNewSimWellFractureFeature"; #endif // USE_PROTOTYPE_FEATURE_FRACTURES } } @@ -585,83 +610,129 @@ QStringList RimContextCommandBuilder::commandsFromSelection() if (RicToggleItemsFeatureImpl::isToggleCommandsAvailable()) { - commandIds << "Separator"; - commandIds << "RicToggleItemsOnFeature"; - commandIds << "RicToggleItemsOffFeature"; - commandIds << "RicToggleItemsFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicToggleItemsOnFeature"; + menuBuilder << "RicToggleItemsOffFeature"; + menuBuilder << "RicToggleItemsFeature"; } if ( caf::CmdFeatureManager::instance()->getCommandFeature("RicDeleteItemFeature")->canFeatureBeExecuted() ) { - commandIds << "Separator"; - commandIds << "RicDeleteItemFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicDeleteItemFeature"; } if (caf::CmdFeatureManager::instance()->getCommandFeature("RicDeleteSubItemsFeature")->canFeatureBeExecuted()) { - commandIds << "Separator"; - commandIds << "RicDeleteSubItemsFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicDeleteSubItemsFeature"; } if (caf::CmdFeatureManager::instance()->getCommandFeature("RicWellPathDeleteFeature")->canFeatureBeExecuted()) { // Special delete command for Well paths // Placed here to fit context menu location of general delete feature - commandIds << "Separator"; - commandIds << "RicWellPathDeleteFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicWellPathDeleteFeature"; } if (caf::CmdFeatureManager::instance()->getCommandFeature("RicWellLogFileCloseFeature")->canFeatureBeExecuted()) { // Special delete command for Well paths // Placed here to fit context menu location of general delete feature - commandIds << "Separator"; - commandIds << "RicWellLogFileCloseFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicWellLogFileCloseFeature"; } if ( caf::CmdFeatureManager::instance()->getCommandFeature("RicCloseCaseFeature")->canFeatureBeExecuted() ) { - commandIds << "Separator"; - commandIds << "RicCloseCaseFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicCloseCaseFeature"; } - return commandIds; + return menuBuilder; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimContextCommandBuilder::appendCommandsToMenu(const QStringList& commandIds, QMenu* menu) +std::vector RimContextCommandBuilder::allWellPaths() { - CVF_ASSERT(menu); + RimProject* proj = RiaApplication::instance()->project(); + return proj->allWellPaths(); +} - caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance(); - for (int i = 0; i < commandIds.size(); i++) +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimContextCommandBuilder::createExecuteScriptForCasesFeatureMenu(caf::CmdFeatureMenuBuilder& menuBuilder) +{ + //menuBuilder << "RicExecuteScriptForCasesFeature"; + + // Execute script on selection of cases + RiuMainWindow* ruiMainWindow = RiuMainWindow::instance(); + if (ruiMainWindow) { - if (commandIds[i] == "Separator") - { - menu->addSeparator(); - } - else - { - caf::CmdFeature* feature = commandManager->getCommandFeature(commandIds[i].toStdString()); - CVF_ASSERT(feature); + std::vector cases; + ruiMainWindow->selectedCases(cases); - if (feature->canFeatureBeExecuted()) + if (cases.size() > 0) + { + menuBuilder.subMenuStart("Execute script"); + + RiaApplication* app = RiaApplication::instance(); + RimProject* proj = app->project(); + if (proj && proj->scriptCollection()) { - QAction* act = commandManager->action(commandIds[i]); - CVF_ASSERT(act); + RimScriptCollection* rootScriptCollection = proj->scriptCollection(); - for (QAction* existingAct : menu->actions()) + // Root script collection holds a list of subdirectories of user defined script folders + for (size_t i = 0; i < rootScriptCollection->subDirectories.size(); i++) { - // If action exist, continue to make sure the action is positioned at the first - // location of a command ID - if (existingAct == act) continue; - } + RimScriptCollection* subDir = rootScriptCollection->subDirectories[i]; - menu->addAction(act); + if (subDir) + { + appendScriptItems(menuBuilder, subDir); + } + } } + + menuBuilder.addSeparator(); + menuBuilder.subMenuEnd(); } } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimContextCommandBuilder::appendScriptItems(caf::CmdFeatureMenuBuilder& menuBuilder, RimScriptCollection* scriptCollection) +{ + QDir dir(scriptCollection->directory); + menuBuilder.subMenuStart(dir.dirName()); + + caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance(); + CVF_ASSERT(commandManager); + + RicExecuteScriptForCasesFeature* executeScriptFeature = dynamic_cast(commandManager->getCommandFeature("RicExecuteScriptForCasesFeature")); + CVF_ASSERT(executeScriptFeature); + + for (size_t i = 0; i < scriptCollection->calcScripts.size(); i++) + { + RimCalcScript* calcScript = scriptCollection->calcScripts[i]; + QFileInfo fi(calcScript->absolutePath()); + + QString menuText = fi.baseName(); + menuBuilder.addCmdFeatureWithUserData("RicExecuteScriptForCasesFeature", menuText, QVariant(calcScript->absolutePath())); + } + + for (size_t i = 0; i < scriptCollection->subDirectories.size(); i++) + { + RimScriptCollection* subDir = scriptCollection->subDirectories[i]; + + appendScriptItems(menuBuilder, subDir); + } + + menuBuilder.subMenuEnd(); +} diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.h b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.h index abe8fd2947..3cee744d61 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.h +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.h @@ -19,9 +19,14 @@ #pragma once -#include +#include +namespace caf { + class CmdFeatureMenuBuilder; +} class QMenu; +class RimWellPath; +class RimScriptCollection; //================================================================================================== /// @@ -30,6 +35,10 @@ class QMenu; class RimContextCommandBuilder { public: - static QStringList commandsFromSelection(); - static void appendCommandsToMenu(const QStringList& commandIds, QMenu* menu); + static caf::CmdFeatureMenuBuilder commandsFromSelection(); + +private: + static std::vector allWellPaths(); + static void createExecuteScriptForCasesFeatureMenu(caf::CmdFeatureMenuBuilder& menuBuilder); + static void appendScriptItems(caf::CmdFeatureMenuBuilder& menuBuilder, RimScriptCollection* scriptCollection); }; diff --git a/ApplicationCode/ProjectDataModel/RimProject.cpp b/ApplicationCode/ProjectDataModel/RimProject.cpp index c5778bba1a..6b168b6bbe 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.cpp +++ b/ApplicationCode/ProjectDataModel/RimProject.cpp @@ -75,7 +75,7 @@ #include "cafCmdFeature.h" #include "cafCmdFeatureManager.h" #include "cafPdmUiTreeOrdering.h" - +#include "cafCmdFeatureMenuBuilder.h" #include "cvfBoundingBox.h" #include @@ -754,63 +754,9 @@ void RimProject::computeUtmAreaOfInterest() //-------------------------------------------------------------------------------------------------- void RimProject::actionsBasedOnSelection(QMenu& contextMenu) { - QStringList commandIds = RimContextCommandBuilder::commandsFromSelection(); + caf::CmdFeatureMenuBuilder menuBuilder = RimContextCommandBuilder::commandsFromSelection(); - caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance(); - for (int i = 0; i < commandIds.size(); i++) - { - if (commandIds[i] == "Separator") - { - contextMenu.addSeparator(); - } - else if (commandIds[i] == "RicExecuteScriptForCasesFeature") - { - // Execute script on selection of cases - RiuMainWindow* ruiMainWindow = RiuMainWindow::instance(); - if (ruiMainWindow) - { - std::vector cases; - ruiMainWindow->selectedCases(cases); - - if (cases.size() > 0) - { - QMenu* executeMenu = contextMenu.addMenu("Execute script"); - - RiaApplication* app = RiaApplication::instance(); - RimProject* proj = app->project(); - if (proj && proj->scriptCollection()) - { - RimScriptCollection* rootScriptCollection = proj->scriptCollection(); - - // Root script collection holds a list of subdirectories of user defined script folders - for (size_t i = 0; i < rootScriptCollection->subDirectories.size(); i++) - { - RimScriptCollection* subDir = rootScriptCollection->subDirectories[i]; - - if (subDir) - { - appendScriptItems(executeMenu, subDir); - } - } - } - - contextMenu.addSeparator(); - contextMenu.addMenu(executeMenu); - } - } - } - else - { - caf::CmdFeature* feature = commandManager->getCommandFeature(commandIds[i].toStdString()); - if (feature->canFeatureBeExecuted()) - { - QAction* act = commandManager->action(commandIds[i]); - CVF_ASSERT(act); - - contextMenu.addAction(act); - } - } - } + menuBuilder.appendToMenu(&contextMenu); } //-------------------------------------------------------------------------------------------------- @@ -985,41 +931,6 @@ void RimProject::reloadCompletionTypeResultsForEclipseCase(RimEclipseCase* eclip RiaApplication::instance()->scheduleRecalculateCompletionTypeAndRedrawEclipseCase(eclipseCase); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimProject::appendScriptItems(QMenu* menu, RimScriptCollection* scriptCollection) -{ - CVF_ASSERT(menu); - - QDir dir(scriptCollection->directory); - QMenu* subMenu = menu->addMenu(dir.dirName()); - - caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance(); - CVF_ASSERT(commandManager); - - RicExecuteScriptForCasesFeature* executeScriptFeature = dynamic_cast(commandManager->getCommandFeature("RicExecuteScriptForCasesFeature")); - CVF_ASSERT(executeScriptFeature); - - for (size_t i = 0; i < scriptCollection->calcScripts.size(); i++) - { - RimCalcScript* calcScript = scriptCollection->calcScripts[i]; - QFileInfo fi(calcScript->absolutePath()); - - QString menuText = fi.baseName(); - QAction* scriptAction = subMenu->addAction(menuText, executeScriptFeature, SLOT(slotExecuteScriptForSelectedCases())); - - scriptAction->setData(QVariant(calcScript->absolutePath())); - } - - for (size_t i = 0; i < scriptCollection->subDirectories.size(); i++) - { - RimScriptCollection* subDir = scriptCollection->subDirectories[i]; - - appendScriptItems(subMenu, subDir); - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimProject.h b/ApplicationCode/ProjectDataModel/RimProject.h index 19bad2752c..f8a80852c2 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.h +++ b/ApplicationCode/ProjectDataModel/RimProject.h @@ -140,9 +140,6 @@ protected: virtual void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = ""); -private: - void appendScriptItems(QMenu* menu, RimScriptCollection* scriptCollection); - private: caf::PdmField m_projectFileVersionString; diff --git a/ApplicationCode/ProjectDataModel/RimWellPath.cpp b/ApplicationCode/ProjectDataModel/RimWellPath.cpp index da8e7e9d26..2da535dd0f 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPath.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellPath.cpp @@ -656,6 +656,15 @@ void RimWellPath::addWellLogFile(RimWellLogFile* logFileInfo) /// //-------------------------------------------------------------------------------------------------- void RimWellPath::deleteWellLogFile(RimWellLogFile* logFileInfo) +{ + detachWellLogFile(logFileInfo); + delete logFileInfo; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellPath::detachWellLogFile(RimWellLogFile* logFileInfo) { auto pdmObject = dynamic_cast(logFileInfo); for (size_t i = 0; i < m_wellLogFiles.size(); i++) @@ -663,7 +672,6 @@ void RimWellPath::deleteWellLogFile(RimWellLogFile* logFileInfo) if (m_wellLogFiles[i] == pdmObject) { m_wellLogFiles.removeChildObject(pdmObject); - delete pdmObject; break; } } diff --git a/ApplicationCode/ProjectDataModel/RimWellPath.h b/ApplicationCode/ProjectDataModel/RimWellPath.h index 1dbf7382cc..18f66a47eb 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPath.h +++ b/ApplicationCode/ProjectDataModel/RimWellPath.h @@ -68,6 +68,7 @@ public: void addWellLogFile(RimWellLogFile* logFileInfo); void deleteWellLogFile(RimWellLogFile* logFileInfo); + void detachWellLogFile(RimWellLogFile* logFileInfo); virtual caf::PdmFieldHandle* userDescriptionField(); virtual caf::PdmFieldHandle* objectToggleField(); diff --git a/ApplicationCode/UserInterface/RiuContextMenuLauncher.cpp b/ApplicationCode/UserInterface/RiuContextMenuLauncher.cpp index 5ebe6ec8c0..342138e0b9 100644 --- a/ApplicationCode/UserInterface/RiuContextMenuLauncher.cpp +++ b/ApplicationCode/UserInterface/RiuContextMenuLauncher.cpp @@ -31,9 +31,9 @@ //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RiuContextMenuLauncher::RiuContextMenuLauncher(QWidget* widget, const QStringList& commandIds) : +RiuContextMenuLauncher::RiuContextMenuLauncher(QWidget* widget, const caf::CmdFeatureMenuBuilder& commandIds) : QObject(widget), - m_commandIds(commandIds) + m_menuBuilder(commandIds) { widget->installEventFilter(this); } @@ -46,7 +46,7 @@ bool RiuContextMenuLauncher::eventFilter(QObject* watchedObject, QEvent* event) if (event->type() == QEvent::ContextMenu) { QMenu menu; - RimContextCommandBuilder::appendCommandsToMenu(m_commandIds, &menu); + m_menuBuilder.appendToMenu(&menu); if (menu.actions().size() > 0) { diff --git a/ApplicationCode/UserInterface/RiuContextMenuLauncher.h b/ApplicationCode/UserInterface/RiuContextMenuLauncher.h index 6267158981..2f6104ad8e 100644 --- a/ApplicationCode/UserInterface/RiuContextMenuLauncher.h +++ b/ApplicationCode/UserInterface/RiuContextMenuLauncher.h @@ -18,6 +18,7 @@ #pragma once +#include "cafCmdFeatureMenuBuilder.h" #include #include @@ -32,12 +33,12 @@ class QWidget; class RiuContextMenuLauncher : public QObject { public: - explicit RiuContextMenuLauncher(QWidget* widget, const QStringList& commandIds); + explicit RiuContextMenuLauncher(QWidget* widget, const caf::CmdFeatureMenuBuilder& commandIds); protected: bool eventFilter(QObject* watched, QEvent* event) override; private: - QStringList m_commandIds; + caf::CmdFeatureMenuBuilder m_menuBuilder; }; diff --git a/ApplicationCode/UserInterface/RiuResultQwtPlot.cpp b/ApplicationCode/UserInterface/RiuResultQwtPlot.cpp index 1bc5a01d78..0cef8c26c6 100644 --- a/ApplicationCode/UserInterface/RiuResultQwtPlot.cpp +++ b/ApplicationCode/UserInterface/RiuResultQwtPlot.cpp @@ -25,6 +25,8 @@ #include "RiuLineSegmentQwtPlotCurve.h" +#include "cafCmdFeatureMenuBuilder.h" + #include "cvfBase.h" #include "cvfAssert.h" #include "cvfColor3.h" @@ -130,11 +132,11 @@ QSize RiuResultQwtPlot::minimumSizeHint() const void RiuResultQwtPlot::contextMenuEvent(QContextMenuEvent* event) { QMenu menu; - QStringList commandIds; + caf::CmdFeatureMenuBuilder menuBuilder; - commandIds << "RicNewGridTimeHistoryCurveFeature"; + menuBuilder << "RicNewGridTimeHistoryCurveFeature"; - RimContextCommandBuilder::appendCommandsToMenu(commandIds, &menu); + menuBuilder.appendToMenu(&menu); if (menu.actions().size() > 0) { diff --git a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp index e423793b06..b7474fa4f5 100644 --- a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp +++ b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp @@ -32,6 +32,7 @@ #include "RiuQwtScalePicker.h" #include "cafSelectionManager.h" +#include "cafCmdFeatureMenuBuilder.h" #include "qwt_date_scale_draw.h" #include "qwt_date_scale_engine.h" @@ -166,13 +167,13 @@ QSize RiuSummaryQwtPlot::minimumSizeHint() const void RiuSummaryQwtPlot::contextMenuEvent(QContextMenuEvent* event) { QMenu menu; - QStringList commandIds; + caf::CmdFeatureMenuBuilder menuBuilder; caf::SelectionManager::instance()->setSelectedItem(ownerPlotDefinition()); - commandIds << "RicShowPlotDataFeature"; + menuBuilder << "RicShowPlotDataFeature"; - RimContextCommandBuilder::appendCommandsToMenu(commandIds, &menu); + menuBuilder.appendToMenu(&menu); if (menu.actions().size() > 0) { diff --git a/ApplicationCode/UserInterface/RiuViewerCommands.cpp b/ApplicationCode/UserInterface/RiuViewerCommands.cpp index 38614d9a05..0d4c9a7184 100644 --- a/ApplicationCode/UserInterface/RiuViewerCommands.cpp +++ b/ApplicationCode/UserInterface/RiuViewerCommands.cpp @@ -73,6 +73,7 @@ #include "cafCmdFeatureManager.h" #include "cafDisplayCoordTransform.h" #include "cafSelectionManager.h" +#include "cafCmdFeatureMenuBuilder.h" #include "cvfDrawableGeo.h" #include "cvfHitItemCollection.h" @@ -279,7 +280,7 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event) } } - QStringList commandIds; + caf::CmdFeatureMenuBuilder menuBuilder; // Well log curve creation commands if (firstHitPart && firstHitPart->sourceInfo()) @@ -297,21 +298,21 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event) RiuSelectionManager::instance()->setSelectedItem(selItem, RiuSelectionManager::RUI_TEMPORARY); #ifdef USE_PROTOTYPE_FEATURE_FRACTURES - commandIds << "RicNewWellPathFractureAtPosFeature"; + menuBuilder << "RicNewWellPathFractureAtPosFeature"; #endif // USE_PROTOTYPE_FEATURE_FRACTURES //TODO: Update so these also use RiuWellPathSelectionItem caf::SelectionManager::instance()->setSelectedItem(wellPath); - commandIds << "RicNewWellLogCurveExtractionFeature"; - commandIds << "RicNewWellLogFileCurveFeature"; - commandIds << "RicNewRftPlotFeature"; - commandIds << "RicNewPltPlotFeature"; - commandIds << "Separator"; - commandIds << "RicNewWellPathIntersectionFeature"; - commandIds << "RicNewFishbonesSubsAtMeasuredDepthFeature"; - commandIds << "RicNewPerforationIntervalAtMeasuredDepthFeature"; + menuBuilder << "RicNewWellLogCurveExtractionFeature"; + menuBuilder << "RicNewWellLogFileCurveFeature"; + menuBuilder << "RicNewRftPlotFeature"; + menuBuilder << "RicNewPltPlotFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicNewWellPathIntersectionFeature"; + menuBuilder << "RicNewFishbonesSubsAtMeasuredDepthFeature"; + menuBuilder << "RicNewPerforationIntervalAtMeasuredDepthFeature"; } } @@ -326,19 +327,19 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event) RiuSelectionItem* selItem = new RiuSimWellSelectionItem(eclipseWellSourceInfo->well(), m_currentPickPositionInDomainCoords, eclipseWellSourceInfo->branchIndex()); RiuSelectionManager::instance()->setSelectedItem(selItem, RiuSelectionManager::RUI_TEMPORARY); - commandIds << "RicNewWellLogCurveExtractionFeature"; - commandIds << "RicNewWellLogRftCurveFeature"; - commandIds << "RicNewRftPlotFeature"; - commandIds << "RicNewPltPlotFeature"; - commandIds << "RicShowWellAllocationPlotFeature"; - commandIds << "RicPlotProductionRateFeature"; - commandIds << "Separator"; - commandIds << "RicShowContributingWellsFeature"; - commandIds << "Separator"; - commandIds << "RicNewSimWellIntersectionFeature"; - commandIds << "RicPlotProductionRateFeature"; + menuBuilder << "RicNewWellLogCurveExtractionFeature"; + menuBuilder << "RicNewWellLogRftCurveFeature"; + menuBuilder << "RicNewRftPlotFeature"; + menuBuilder << "RicNewPltPlotFeature"; + menuBuilder << "RicShowWellAllocationPlotFeature"; + menuBuilder << "RicPlotProductionRateFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicShowContributingWellsFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicNewSimWellIntersectionFeature"; + menuBuilder << "RicPlotProductionRateFeature"; #ifdef USE_PROTOTYPE_FEATURE_FRACTURES - commandIds << "RicNewSimWellFractureAtPosFeature"; + menuBuilder << "RicNewSimWellFractureAtPosFeature"; #endif // USE_PROTOTYPE_FEATURE_FRACTURES } } @@ -348,19 +349,19 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event) // View Link commands if (!firstHitPart) { - commandIds << "RicLinkViewFeature"; - commandIds << "RicShowLinkOptionsFeature"; - commandIds << "RicSetMasterViewFeature"; - commandIds << "RicUnLinkViewFeature"; + menuBuilder << "RicLinkViewFeature"; + menuBuilder << "RicShowLinkOptionsFeature"; + menuBuilder << "RicSetMasterViewFeature"; + menuBuilder << "RicUnLinkViewFeature"; } - commandIds << "Separator"; - commandIds << "RicNewGridTimeHistoryCurveFeature"; - commandIds << "RicShowFlowCharacteristicsPlotFeature"; - commandIds << "RicSaveEclipseInputVisibleCellsFeature"; - commandIds << "RicShowGridStatisticsFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicNewGridTimeHistoryCurveFeature"; + menuBuilder << "RicShowFlowCharacteristicsPlotFeature"; + menuBuilder << "RicSaveEclipseInputVisibleCellsFeature"; + menuBuilder << "RicShowGridStatisticsFeature"; - RimContextCommandBuilder::appendCommandsToMenu(commandIds, &menu); + menuBuilder.appendToMenu(&menu); if (!menu.isEmpty()) { diff --git a/ApplicationCode/UserInterface/RiuWellAllocationPlot.cpp b/ApplicationCode/UserInterface/RiuWellAllocationPlot.cpp index c7b7b21e2b..2a9615f1ec 100644 --- a/ApplicationCode/UserInterface/RiuWellAllocationPlot.cpp +++ b/ApplicationCode/UserInterface/RiuWellAllocationPlot.cpp @@ -79,16 +79,16 @@ RiuWellAllocationPlot::RiuWellAllocationPlot(RimWellAllocationPlot* plotDefiniti m_legendWidget = new RiuNightchartsWidget(this); new RiuPlotObjectPicker(m_legendWidget, m_plotDefinition->plotLegend()); - QStringList commandIds; - commandIds << "RicShowTotalAllocationDataFeature"; - new RiuContextMenuLauncher(m_legendWidget, commandIds); + caf::CmdFeatureMenuBuilder menuBuilder; + menuBuilder << "RicShowTotalAllocationDataFeature"; + new RiuContextMenuLauncher(m_legendWidget, menuBuilder); rightColumnLayout->addWidget(m_legendWidget); m_legendWidget->showPie(false); QWidget* totalFlowAllocationWidget = m_plotDefinition->totalWellFlowPlot()->createViewWidget(this); new RiuPlotObjectPicker(totalFlowAllocationWidget, m_plotDefinition->totalWellFlowPlot()); - new RiuContextMenuLauncher(totalFlowAllocationWidget, commandIds); + new RiuContextMenuLauncher(totalFlowAllocationWidget, menuBuilder); rightColumnLayout->addWidget(totalFlowAllocationWidget, Qt::AlignTop); rightColumnLayout->addWidget(m_plotDefinition->tofAccumulatedPhaseFractionsPlot()->createViewWidget(this), Qt::AlignTop); @@ -193,11 +193,11 @@ QSize RiuWellAllocationPlot::minimumSizeHint() const void RiuWellAllocationPlot::contextMenuEvent(QContextMenuEvent* event) { QMenu menu; - QStringList commandIds; + caf::CmdFeatureMenuBuilder menuBuilder; - commandIds << "RicShowContributingWellsFromPlotFeature"; + menuBuilder << "RicShowContributingWellsFromPlotFeature"; - RimContextCommandBuilder::appendCommandsToMenu(commandIds, &menu); + menuBuilder.appendToMenu(&menu); if (menu.actions().size() > 0) { diff --git a/ApplicationCode/UserInterface/RiuWellLogPlot.cpp b/ApplicationCode/UserInterface/RiuWellLogPlot.cpp index 159a840581..eaa8fb7819 100644 --- a/ApplicationCode/UserInterface/RiuWellLogPlot.cpp +++ b/ApplicationCode/UserInterface/RiuWellLogPlot.cpp @@ -27,6 +27,7 @@ #include "RiuWellLogTrack.h" #include "cafSelectionManager.h" +#include "cafCmdFeatureMenuBuilder.h" #include "cvfAssert.h" @@ -214,14 +215,14 @@ QSize RiuWellLogPlot::sizeHint() const void RiuWellLogPlot::contextMenuEvent(QContextMenuEvent* event) { QMenu menu; - QStringList commandIds; + caf::CmdFeatureMenuBuilder menuBuilder; caf::SelectionManager::instance()->setSelectedItem(ownerPlotDefinition()); - commandIds << "RicShowPlotDataFeature"; - commandIds << "RicShowContributingWellsFromPlotFeature"; + menuBuilder << "RicShowPlotDataFeature"; + menuBuilder << "RicShowContributingWellsFromPlotFeature"; - RimContextCommandBuilder::appendCommandsToMenu(commandIds, &menu); + menuBuilder.appendToMenu(&menu); if (menu.actions().size() > 0) { diff --git a/Fwk/AppFwk/cafCommand/CMakeLists.txt b/Fwk/AppFwk/cafCommand/CMakeLists.txt index 21131db0fa..c0dcef9c9b 100644 --- a/Fwk/AppFwk/cafCommand/CMakeLists.txt +++ b/Fwk/AppFwk/cafCommand/CMakeLists.txt @@ -61,6 +61,8 @@ set( PROJECT_FILES cafCmdFeature.h cafCmdFeatureManager.cpp cafCmdFeatureManager.h + cafCmdFeatureMenuBuilder.cpp + cafCmdFeatureMenuBuilder.h ) diff --git a/Fwk/AppFwk/cafCommand/cafCmdFeature.cpp b/Fwk/AppFwk/cafCommand/cafCmdFeature.cpp index 1e31c33914..e0521051df 100644 --- a/Fwk/AppFwk/cafCommand/cafCmdFeature.cpp +++ b/Fwk/AppFwk/cafCommand/cafCmdFeature.cpp @@ -68,13 +68,21 @@ CmdFeature::~CmdFeature() //-------------------------------------------------------------------------------------------------- QAction* CmdFeature::action() { - return this->action(QString("")); + return this->actionWithCustomText(QString("")); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -QAction* CmdFeature::action(QString customText) +QAction* CmdFeature::actionWithCustomText(const QString& customText) +{ + return actionWithUserData(customText, QVariant()); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QAction* CmdFeature::actionWithUserData(const QString& customText, const QVariant& userData) { QAction* action = NULL; @@ -88,6 +96,11 @@ QAction* CmdFeature::action(QString customText) else { action = new QAction(this); + + if (!userData.isNull()) + { + action->setData(userData); + } connect(action, SIGNAL(triggered(bool)), SLOT(actionTriggered(bool))); m_customTextToActionMap[customText]= action; } @@ -170,4 +183,15 @@ void CmdFeature::disableModelChangeContribution() m_triggerModelChange = false; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const QVariant CmdFeature::userData() const +{ + QAction* action = qobject_cast(sender()); + if (!action) return QVariant(); + + return action->data(); +} + } // end namespace caf diff --git a/Fwk/AppFwk/cafCommand/cafCmdFeature.h b/Fwk/AppFwk/cafCommand/cafCmdFeature.h index 70e36dee8a..db4c8856af 100644 --- a/Fwk/AppFwk/cafCommand/cafCmdFeature.h +++ b/Fwk/AppFwk/cafCommand/cafCmdFeature.h @@ -77,7 +77,8 @@ public: virtual ~CmdFeature(); QAction* action(); - QAction* action(QString customText); + QAction* actionWithCustomText(const QString& customText); + QAction* actionWithUserData(const QString& customText, const QVariant& userData); void refreshEnabledState(); void refreshCheckedState(); @@ -93,6 +94,7 @@ protected: virtual bool isCommandChecked(); void disableModelChangeContribution(); + const QVariant userData() const; private: std::map m_customTextToActionMap; diff --git a/Fwk/AppFwk/cafCommand/cafCmdFeatureManager.cpp b/Fwk/AppFwk/cafCommand/cafCmdFeatureManager.cpp index 91049771ca..0758645d05 100644 --- a/Fwk/AppFwk/cafCommand/cafCmdFeatureManager.cpp +++ b/Fwk/AppFwk/cafCommand/cafCmdFeatureManager.cpp @@ -108,7 +108,21 @@ QAction* CmdFeatureManager::action(const QString& commandId, const QString& cust { std::pair featurePair = createFeature(commandId.toStdString()); - QAction* act = featurePair.first->action(customActionText); + QAction* act = featurePair.first->actionWithCustomText(customActionText); + m_actionToFeatureIdxMap[act] = featurePair.second; + + return act; +} + +//-------------------------------------------------------------------------------------------------- +/// Get action for the specified command, with custom action text +/// The action is owned by the PdmCommandItemManager +//-------------------------------------------------------------------------------------------------- +QAction* CmdFeatureManager::actionWithUserData(const QString& commandId, const QString& customActionText, const QVariant& userData) +{ + std::pair featurePair = createFeature(commandId.toStdString()); + + QAction* act = featurePair.first->actionWithUserData(customActionText, userData); m_actionToFeatureIdxMap[act] = featurePair.second; return act; diff --git a/Fwk/AppFwk/cafCommand/cafCmdFeatureManager.h b/Fwk/AppFwk/cafCommand/cafCmdFeatureManager.h index 40dea4101e..5053985847 100644 --- a/Fwk/AppFwk/cafCommand/cafCmdFeatureManager.h +++ b/Fwk/AppFwk/cafCommand/cafCmdFeatureManager.h @@ -63,8 +63,8 @@ public: virtual ~CmdFeatureManager(); QAction* action(const QString& commandId); - QAction* action(const QString& commandId, const QString& actionText); - + QAction* action(const QString& commandId, const QString& customActionText); + QAction* actionWithUserData(const QString& commandId, const QString& customActionText, const QVariant& userData); void refreshStates(const QStringList& commandIdList = QStringList()); void refreshEnabledState(const QStringList& commandIdList = QStringList()); void refreshCheckedState(const QStringList& commandIdList = QStringList()); diff --git a/Fwk/AppFwk/cafCommand/cafCmdFeatureMenuBuilder.cpp b/Fwk/AppFwk/cafCommand/cafCmdFeatureMenuBuilder.cpp new file mode 100644 index 0000000000..717cb66c94 --- /dev/null +++ b/Fwk/AppFwk/cafCommand/cafCmdFeatureMenuBuilder.cpp @@ -0,0 +1,209 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2013 Ceetron AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library 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. +// +// This library 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. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library 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 Lesser General Public License at <> +// for more details. +// +//################################################################################################## + + +#include "cafCmdFeatureMenuBuilder.h" + +#include "cafCmdFeature.h" +#include "cafCmdFeatureManager.h" +#include "cafCmdSelectionHelper.h" +#include "cafFactory.h" + +#include "cvfAssert.h" + +#include "defaultfeatures/cafCmdDeleteItemFeature.h" +#include "defaultfeatures/cafCmdAddItemFeature.h" + +#include +#include + +namespace caf +{ + +// typedef Factory CommandFeatureFactory; +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +CmdFeatureMenuBuilder::CmdFeatureMenuBuilder() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +CmdFeatureMenuBuilder::~CmdFeatureMenuBuilder() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +CmdFeatureMenuBuilder& CmdFeatureMenuBuilder::operator<<(const QString& commandId) +{ + if (commandId == "Separator") + { + addSeparator(); + } + else + { + addCmdFeature(commandId); + } + return *this; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +CmdFeatureMenuBuilder& CmdFeatureMenuBuilder::addCmdFeature(const QString commandId, const QString& uiText) +{ + MenuItem i; + i.itemType = MenuItem::COMMAND; + i.itemName = commandId; + i.uiText = uiText; + m_items.push_back(i); + return *this; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +CmdFeatureMenuBuilder& CmdFeatureMenuBuilder::addCmdFeatureWithUserData(const QString commandId, const QString& uiText, const QVariant& userData) +{ + MenuItem i; + i.itemType = MenuItem::COMMAND; + i.itemName = commandId; + i.uiText = uiText; + i.userData = userData; + m_items.push_back(i); + return *this; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +CmdFeatureMenuBuilder& CmdFeatureMenuBuilder::addSeparator() +{ + MenuItem i; + i.itemType = MenuItem::SEPARATOR; + m_items.push_back(i); + return *this; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +CmdFeatureMenuBuilder& CmdFeatureMenuBuilder::subMenuStart(const QString& menuName) +{ + MenuItem i; + i.itemType = MenuItem::SUBMENU_START; + i.itemName = menuName; + m_items.push_back(i); + return *this; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +CmdFeatureMenuBuilder& CmdFeatureMenuBuilder::subMenuEnd() +{ + MenuItem i; + i.itemType = MenuItem::SUBMENU_END; + m_items.push_back(i); + return *this; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void CmdFeatureMenuBuilder::appendToMenu(QMenu* menu) +{ + CVF_ASSERT(menu); + + std::vector menus = { menu }; + for (int i = 0; i < m_items.size(); i++) + { + if (m_items[i].itemType == MenuItem::SEPARATOR) + { + menu->addSeparator(); + } + else if (m_items[i].itemType == MenuItem::SUBMENU_START) + { + QMenu* subMenu = menus.back()->addMenu(m_items[i].itemName); + menus.push_back(subMenu); + } + else if (m_items[i].itemType == MenuItem::SUBMENU_END) + { + if (menus.size() > 1) + { + menus.pop_back(); + } + } + else + { + CmdFeatureManager* commandManager = CmdFeatureManager::instance(); + QMenu* currentMenu = menus.back(); + caf::CmdFeature* feature = commandManager->getCommandFeature(m_items[i].itemName.toStdString()); + CVF_ASSERT(feature); + + if (feature->canFeatureBeExecuted()) + { + const QAction* act; + if (!m_items[i].userData.isNull()) + { + act = commandManager->actionWithUserData(m_items[i].itemName, m_items[i].uiText, m_items[i].userData); + } + else + { + act = commandManager->action(m_items[i].itemName); + } + + CVF_ASSERT(act); + + for (QAction* existingAct : currentMenu->actions()) + { + // If action exist, continue to make sure the action is positioned at the first + // location of a command ID + if (existingAct == act) continue; + } + + currentMenu->addAction(const_cast(act)); + } + } + } +} + +} // end namespace caf diff --git a/Fwk/AppFwk/cafCommand/cafCmdFeatureMenuBuilder.h b/Fwk/AppFwk/cafCommand/cafCmdFeatureMenuBuilder.h new file mode 100644 index 0000000000..d8a24da5d1 --- /dev/null +++ b/Fwk/AppFwk/cafCommand/cafCmdFeatureMenuBuilder.h @@ -0,0 +1,110 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2013 Ceetron AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library 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. +// +// This library 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. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library 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 Lesser General Public License at <> +// for more details. +// +//################################################################################################## + + +#pragma once + +#include +#include +#include + +#include +#include + +class QAction; +class QMenu; + +namespace caf +{ + +class CmdFeature; + +//================================================================================================== +/// +//================================================================================================== +class CmdFeatureMenuBuilder +{ +public: + CmdFeatureMenuBuilder(); + //CmdFeatureMenuBuilder(const CmdFeatureMenuBuilder& other); + virtual ~CmdFeatureMenuBuilder(); + + CmdFeatureMenuBuilder& operator<<(const QString& commandIdOrSeparator); + CmdFeatureMenuBuilder& addCmdFeature(const QString commandId, const QString& customUiText = ""); + CmdFeatureMenuBuilder& addCmdFeatureWithUserData(const QString commandId, const QString& customUiText, const QVariant& userData); + + CmdFeatureMenuBuilder& addSeparator(); + + CmdFeatureMenuBuilder& subMenuStart(const QString& menuName); + CmdFeatureMenuBuilder& subMenuEnd(); + + void appendToMenu(QMenu* menu); + +// const std::vector items() const; + +private: + struct MenuItem + { + public: + enum ItemType { COMMAND, SEPARATOR, SUBMENU_START, SUBMENU_END }; + + ItemType itemType; + QString itemName; + QString uiText; + QVariant userData; + }; + + std::vector m_items; +}; + +} // end namespace caf + + + +//static MenuItem command(QString commandName) +//{ +// MenuItem i; +// i.itemType = COMMAND; +// i.itemName = commandName; +// return i; +//} +// +//static MenuItem separator() +//{ +// MenuItem i; +// i.itemType = SEPARATOR; +// return i; +//}