///////////////////////////////////////////////////////////////////////////////// // // 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 "RimContextCommandBuilder.h" #include "RimCalcScript.h" #include "RimCaseCollection.h" #include "RimCellRangeFilter.h" #include "RimCellRangeFilterCollection.h" #include "RimEclipseCase.h" #include "RimEclipseCaseCollection.h" #include "RimEclipseCellColors.h" #include "RimEclipseInputProperty.h" #include "RimEclipseInputPropertyCollection.h" #include "RimEclipsePropertyFilter.h" #include "RimEclipsePropertyFilterCollection.h" #include "RimEclipseStatisticsCase.h" #include "RimEclipseView.h" #include "RimEclipseWell.h" #include "RimFault.h" #include "RimFlowDiagSolution.h" #include "RimFlowPlotCollection.h" #include "RimFormationNames.h" #include "RimFormationNamesCollection.h" #include "RimGeoMechCase.h" #include "RimGeoMechPropertyFilter.h" #include "RimGeoMechPropertyFilterCollection.h" #include "RimGeoMechView.h" #include "RimIdenticalGridCaseGroup.h" #include "RimIntersection.h" #include "RimIntersectionBox.h" #include "RimIntersectionCollection.h" #include "RimScriptCollection.h" #include "RimSummaryCase.h" #include "RimSummaryCurve.h" #include "RimSummaryCurveFilter.h" #include "RimSummaryPlot.h" #include "RimSummaryPlotCollection.h" #include "RimViewController.h" #include "RimViewLinker.h" #include "RimWellAllocationPlot.h" #include "RimWellLogCurve.h" #include "RimWellLogFileChannel.h" #include "RimWellLogPlot.h" #include "RimWellLogPlotCollection.h" #include "RimWellLogTrack.h" #include "RimWellPath.h" #include "RimWellPathCollection.h" #include "ToggleCommands/RicToggleItemsFeatureImpl.h" #include "cafPdmUiItem.h" #include "cafSelectionManager.h" #include "cvfAssert.h" #include "cafCmdFeatureManager.h" #include "cafCmdFeature.h" #include #include //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- QStringList RimContextCommandBuilder::commandsFromSelection() { QStringList commandIds; std::vector uiItems; caf::SelectionManager::instance()->selectedItems(uiItems); if (uiItems.size() == 0) { commandIds << "RicNewWellLogPlotFeature"; commandIds << "RicNewSummaryPlotFeature"; } else if (uiItems.size() == 1) { caf::PdmUiItem* uiItem = uiItems[0]; CVF_ASSERT(uiItem); if (dynamic_cast(uiItem)) { commandIds << "RicImportEclipseCaseFeature"; commandIds << "RicImportInputEclipseCaseFeature"; commandIds << "RicCreateGridCaseGroupFeature"; commandIds << "RicEclipseCaseNewGroupFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicPasteGeoMechViewsFeature"; commandIds << "Separator"; commandIds << "RicNewViewFeature"; commandIds << "Separator"; commandIds << "RicCopyReferencesToClipboardFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicPasteEclipseViewsFeature"; commandIds << "Separator"; commandIds << "RicNewViewFeature"; commandIds << "Separator"; commandIds << "RicCopyReferencesToClipboardFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicPasteEclipseCasesFeature"; commandIds << "Separator"; commandIds << "RicNewStatisticsCaseFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicNewViewFeature"; commandIds << "RicComputeStatisticsFeature"; commandIds << "Separator"; } else if (dynamic_cast(uiItem)) { commandIds << "RicPasteEclipseCasesFeature"; commandIds << "RicPasteEclipseViewsFeature"; commandIds << "Separator"; commandIds << "RicNewViewFeature"; commandIds << "RicShowFlowCharacteristicsPlotFeature"; commandIds << "RicEclipseCaseNewGroupFeature"; commandIds << "Separator"; commandIds << "RicCopyReferencesToClipboardFeature"; commandIds << "Separator"; } else if (dynamic_cast(uiItem)) { commandIds << "RicPasteGeoMechViewsFeature"; commandIds << "Separator"; commandIds << "RicNewViewFeature"; commandIds << "Separator"; } else if (dynamic_cast(uiItem)) { commandIds << "RicPasteEclipseCasesFeature"; commandIds << "Separator"; commandIds << "RicEclipseCaseNewGroupFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicSaveEclipseResultAsInputPropertyFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicAddEclipseInputPropertyFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicSaveEclipseInputPropertyFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicRangeFilterNewFeature"; commandIds << "RicRangeFilterNewSliceIFeature"; commandIds << "RicRangeFilterNewSliceJFeature"; commandIds << "RicRangeFilterNewSliceKFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicRangeFilterInsertFeature"; commandIds << "RicRangeFilterNewSliceIFeature"; commandIds << "RicRangeFilterNewSliceJFeature"; commandIds << "RicRangeFilterNewSliceKFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicEclipsePropertyFilterNewFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicEclipsePropertyFilterInsertFeature"; commandIds << "RicApplyPropertyFilterAsCellResultFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicGeoMechPropertyFilterNewFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicGeoMechPropertyFilterInsertFeature"; commandIds << "RicApplyPropertyFilterAsCellResultFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicWellPathsImportFileFeature"; commandIds << "RicWellPathsImportSsihubFeature"; commandIds << "RicWellLogsImportFileFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicNewWellLogFileCurveFeature"; commandIds << "RicNewWellLogCurveExtractionFeature"; commandIds << "RicNewWellPathIntersectionFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicEditScriptFeature"; commandIds << "Separator"; commandIds << "RicNewScriptFeature"; commandIds << "Separator"; commandIds << "RicExecuteScriptFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicNewScriptFeature"; commandIds << "Separator"; commandIds << "RicAddScriptPathFeature"; commandIds << "RicRefreshScriptsFeature"; commandIds << "Separator"; commandIds << "RicDeleteScriptPathFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicShowAllLinkedViewsFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicShowAllLinkedViewsFeature"; commandIds << "Separator"; commandIds << "RicDeleteAllLinkedViewsFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicPasteWellLogPlotFeature"; commandIds << "Separator"; commandIds << "RicNewWellLogPlotFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicPasteSummaryPlotFeature"; commandIds << "Separator"; commandIds << "RicNewSummaryPlotFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicPasteWellLogPlotFeature"; commandIds << "RicPasteWellLogTrackFeature"; commandIds << "Separator"; commandIds << "RicNewWellLogPlotTrackFeature"; commandIds << "RicAsciiExportWellLogPlotFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicPasteWellLogTrackFeature"; commandIds << "RicPasteWellLogCurveFeature"; commandIds << "Separator"; commandIds << "RicNewWellLogCurveExtractionFeature"; commandIds << "RicNewWellLogFileCurveFeature"; commandIds << "Separator"; commandIds << "RicDeleteWellLogPlotTrackFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicPasteWellLogCurveFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicPasteSummaryCurveFeature"; commandIds << "RicPasteSummaryCurveFilterFeature"; commandIds << "RicPasteSummaryPlotFeature"; commandIds << "Separator"; commandIds << "RicNewSummaryPlotFeature"; commandIds << "RicNewSummaryCurveFilterFeature"; commandIds << "RicNewSummaryCurveFeature"; commandIds << "RicAsciiExportSummaryPlotFeature"; commandIds << "Separator"; commandIds << "RicCopyReferencesToClipboardFeature"; commandIds << "Separator"; commandIds << "RicViewZoomAllFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicPasteSummaryCurveFeature"; commandIds << "Separator"; commandIds << "RicNewSummaryCurveFilterFeature"; commandIds << "RicNewSummaryCurveFeature"; commandIds << "Separator"; commandIds << "RicCopyReferencesToClipboardFeature"; } else if(dynamic_cast(uiItem)) { commandIds << "RicPasteSummaryCurveFilterFeature"; commandIds << "Separator"; commandIds << "RicNewSummaryCurveFilterFeature"; commandIds << "RicNewSummaryCurveFeature"; commandIds << "Separator"; commandIds << "RicCopyReferencesToClipboardFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicNewSummaryPlotFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicAddWellLogToPlotFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicAppendIntersectionFeature"; commandIds << "RicAppendIntersectionBoxFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicAppendIntersectionFeature"; commandIds << "RicAppendIntersectionBoxFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicAppendIntersectionFeature"; commandIds << "RicAppendIntersectionBoxFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicNewWellLogCurveExtractionFeature"; commandIds << "RicNewSimWellIntersectionFeature"; commandIds << "RicShowWellAllocationPlotFeature"; } else if(dynamic_cast(uiItem)) { commandIds << "RicImportFormationNamesFeature"; commandIds << "RicReloadFormationNamesFeature"; } else if(dynamic_cast(uiItem)) { commandIds << "RicImportFormationNamesFeature"; commandIds << "Separator"; commandIds << "RicReloadFormationNamesFeature"; } else if ( dynamic_cast(uiItem) ) { commandIds << "RicExportFaultsFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicAddStoredWellAllocationPlotFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicShowFlowCharacteristicsPlotFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicShowFlowCharacteristicsPlotFeature"; } if (dynamic_cast(uiItem)) { commandIds << "Separator"; commandIds << "RicLinkVisibleViewsFeature"; commandIds << "RicLinkViewFeature"; commandIds << "RicShowLinkOptionsFeature"; commandIds << "RicSetMasterViewFeature"; commandIds << "RicUnLinkViewFeature"; } } // Command supporting multiple selected objects if (uiItems.size() > 0) { // Work in progress -- Start // All commands should be aware of selection of multiple objects // Based on the selection, the command feature can decide if the command // can be executed, communicated by isCommandEnabled(). When a command feature // is aware of multiple selected items, move the command to this list // without using dyncamic_cast. commandIds << "RicPasteTimeHistoryCurveFeature"; commandIds << "RicCopyReferencesToClipboardFeature"; commandIds << "RicShowPlotDataFeature"; commandIds << "RicShowTotalAllocationDataFeature"; commandIds << "RicSummaryCurveSwitchAxisFeature"; // Work in progress -- End caf::PdmUiItem* uiItem = uiItems[0]; if (dynamic_cast(uiItem)) { commandIds << "RicAddWellLogToPlotFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicExecuteScriptForCasesFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicReloadCaseFeature"; commandIds << "RicExecuteScriptForCasesFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicAsciiExportSummaryPlotFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicAsciiExportWellLogPlotFeature"; } else if (dynamic_cast(uiItem) || dynamic_cast(uiItem) || dynamic_cast(uiItem)) { commandIds << "RicExportToLasFileFeature"; commandIds << "RicChangeDataSourceFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicExportToLasFileFeature"; } else if (dynamic_cast(uiItem) ) { commandIds << "RicExportFaultsFeature"; } else if (dynamic_cast(uiItem)) { commandIds << "RicPlotProductionRateFeature"; commandIds << "RicShowContributingWellsFeature"; commandIds << "Separator"; commandIds << "RicEclipseWellShowLabelFeature"; commandIds << "RicEclipseWellShowHeadFeature"; commandIds << "RicEclipseWellShowPipeFeature"; commandIds << "RicEclipseWellShowSpheresFeature"; commandIds << "RicEclipseWellShowWellCellsFeature"; commandIds << "RicEclipseWellShowWellCellFenceFeature"; } } if (RicToggleItemsFeatureImpl::isToggleCommandsAvailable()) { commandIds << "Separator"; commandIds << "RicToggleItemsOnFeature"; commandIds << "RicToggleItemsOffFeature"; commandIds << "RicToggleItemsFeature"; } if ( caf::CmdFeatureManager::instance()->getCommandFeature("RicDeleteItemFeature")->canFeatureBeExecuted() ) { commandIds << "Separator"; commandIds << "RicDeleteItemFeature"; } if (caf::CmdFeatureManager::instance()->getCommandFeature("RicDeleteSubItemsFeature")->canFeatureBeExecuted()) { commandIds << "Separator"; commandIds << "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"; } if ( caf::CmdFeatureManager::instance()->getCommandFeature("RicCloseCaseFeature")->canFeatureBeExecuted() ) { commandIds << "Separator"; commandIds << "RicCloseCaseFeature"; } return commandIds; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimContextCommandBuilder::appendCommandsToMenu(const QStringList& commandIds, QMenu* menu) { CVF_ASSERT(menu); caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance(); for (int i = 0; i < commandIds.size(); i++) { if (commandIds[i] == "Separator") { menu->addSeparator(); } else { caf::CmdFeature* feature = commandManager->getCommandFeature(commandIds[i].toStdString()); CVF_ASSERT(feature); if (feature->canFeatureBeExecuted()) { QAction* act = commandManager->action(commandIds[i]); CVF_ASSERT(act); for (QAction* existingAct : menu->actions()) { // If action exist, continue to make sure the action is positioned at the first // location of a command ID if (existingAct == act) continue; } menu->addAction(act); } } } }