diff --git a/ApplicationLibCode/Commands/CMakeLists_files.cmake b/ApplicationLibCode/Commands/CMakeLists_files.cmake index 4ab065a136..d7dc16d21d 100644 --- a/ApplicationLibCode/Commands/CMakeLists_files.cmake +++ b/ApplicationLibCode/Commands/CMakeLists_files.cmake @@ -42,7 +42,6 @@ set(SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RicReloadCaseFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicReplaceCaseFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicReloadSummaryCaseFeature.h - ${CMAKE_CURRENT_LIST_DIR}/RicReplaceSummaryCaseFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicFlyToObjectFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicGridStatisticsDialog.h ${CMAKE_CURRENT_LIST_DIR}/RicShowGridStatisticsFeature.h @@ -148,7 +147,6 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RicReloadCaseFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicReplaceCaseFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicReloadSummaryCaseFeature.cpp - ${CMAKE_CURRENT_LIST_DIR}/RicReplaceSummaryCaseFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicFlyToObjectFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicGridStatisticsDialog.cpp ${CMAKE_CURRENT_LIST_DIR}/RicShowGridStatisticsFeature.cpp diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake b/ApplicationLibCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake index 87bd5ffb87..97fade50b6 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake @@ -48,6 +48,8 @@ set(SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RicCreateDeclineCurvesFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicCreateRegressionAnalysisCurveFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicCreateCrossPlotFeature.h + ${CMAKE_CURRENT_LIST_DIR}/RicReplaceSummaryEnsembleFeature.h + ${CMAKE_CURRENT_LIST_DIR}/RicReplaceSummaryCaseFeature.h ) set(SOURCE_GROUP_SOURCE_FILES @@ -100,6 +102,8 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RicCreateDeclineCurvesFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicCreateRegressionAnalysisCurveFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicCreateCrossPlotFeature.cpp + ${CMAKE_CURRENT_LIST_DIR}/RicReplaceSummaryEnsembleFeature.cpp + ${CMAKE_CURRENT_LIST_DIR}/RicReplaceSummaryCaseFeature.cpp ) list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) diff --git a/ApplicationLibCode/Commands/RicReplaceSummaryCaseFeature.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryCaseFeature.cpp similarity index 100% rename from ApplicationLibCode/Commands/RicReplaceSummaryCaseFeature.cpp rename to ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryCaseFeature.cpp diff --git a/ApplicationLibCode/Commands/RicReplaceSummaryCaseFeature.h b/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryCaseFeature.h similarity index 100% rename from ApplicationLibCode/Commands/RicReplaceSummaryCaseFeature.h rename to ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryCaseFeature.h diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryEnsembleFeature.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryEnsembleFeature.cpp new file mode 100644 index 0000000000..01c780ae7a --- /dev/null +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryEnsembleFeature.cpp @@ -0,0 +1,102 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2025 Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicReplaceSummaryEnsembleFeature.h" + +#include "Summary/RiaSummaryTools.h" + +#include "RicImportSummaryCasesFeature.h" + +#include "RimSummaryCase.h" +#include "RimSummaryCaseMainCollection.h" +#include "RimSummaryEnsemble.h" + +#include "cafPdmObject.h" +#include "cafSelectionManager.h" + +#include + +CAF_CMD_SOURCE_INIT( RicReplaceSummaryEnsembleFeature, "RicReplaceSummaryEnsembleFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicReplaceSummaryEnsembleFeature::isCommandEnabled() const +{ + auto summaryEnsemble = caf::SelectionManager::instance()->selectedItemOfType(); + return summaryEnsemble != nullptr; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicReplaceSummaryEnsembleFeature::onActionTriggered( bool isChecked ) +{ + auto summaryEnsemble = caf::SelectionManager::instance()->selectedItemOfType(); + if ( !summaryEnsemble ) return; + + QString pathCacheName = "ENSEMBLE_FILES"; + auto result = RicImportSummaryCasesFeature::runRecursiveSummaryCaseFileSearchDialogWithGrouping( "Import Ensemble", pathCacheName ); + QStringList fileNames = result.files; + RiaDefines::FileType fileType = RicRecursiveFileSearchDialog::mapSummaryFileType( result.fileType ); + + if ( fileNames.isEmpty() ) return; + if ( fileType != RiaDefines::FileType::SMSPEC ) return; + + RicImportSummaryCasesFeature::CreateConfig createConfig{ .fileType = fileType, .ensembleOrGroup = false, .allowDialogs = false }; + auto [isOk, newCases] = RicImportSummaryCasesFeature::createSummaryCasesFromFiles( fileNames, createConfig ); + if ( !isOk ) return; + + // Remove cases first, delegate delete to a separate thread + auto casesToBeDeleted = summaryEnsemble->allSummaryCases(); + for ( auto summaryCase : casesToBeDeleted ) + { + summaryEnsemble->removeCase( summaryCase ); + } + + // Add the summary case + for ( auto summaryCase : newCases ) + { + summaryEnsemble->addCase( summaryCase ); + } + + // Update name of cases and ensemble after all cases are added + for ( auto summaryCase : newCases ) + { + summaryCase->updateAutoShortName(); + } + + summaryEnsemble->ensureNameIsUpdated(); + + if ( auto sumCaseMainColl = RiaSummaryTools::summaryCaseMainCollection() ) + { + sumCaseMainColl->updateAllRequiredEditors(); + } + + // Delete previous cases in a separate thread, as this operation can be time-consuming + caf::AsyncPdmObjectVectorDeleter summaryCaseDeleter( casesToBeDeleted ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicReplaceSummaryEnsembleFeature::setupActionLook( QAction* actionToSetup ) +{ + actionToSetup->setText( "Replace" ); + actionToSetup->setIcon( QIcon( ":/ReplaceCase16x16.png" ) ); +} diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryEnsembleFeature.h b/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryEnsembleFeature.h new file mode 100644 index 0000000000..4cf5b0d02d --- /dev/null +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryEnsembleFeature.h @@ -0,0 +1,31 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2025 Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" + +class RicReplaceSummaryEnsembleFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + bool isCommandEnabled() const override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; +}; diff --git a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp index 8c69f203aa..caa6c1bd7c 100644 --- a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -124,7 +124,6 @@ #include "RimSummaryCaseMainCollection.h" #include "RimSummaryCurve.h" #include "RimSummaryCurveCollection.h" -#include "RimSummaryEnsemble.h" #include "RimSummaryMultiPlot.h" #include "RimSummaryMultiPlotCollection.h" #include "RimSummaryPlot.h" @@ -765,24 +764,6 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "Separator"; menuBuilder << "RicShowSummaryCurveCalculatorFeature"; } - else if ( dynamic_cast( firstUiItem ) ) - { - menuBuilder.subMenuStart( "Import" ); - menuBuilder << "RicImportSummaryCaseFeature"; - menuBuilder << "RicImportSummaryCasesFeature"; - menuBuilder << "RicImportSummaryGroupFeature"; - menuBuilder << "RicImportEnsembleFeature"; - menuBuilder.subMenuEnd(); - menuBuilder.addSeparator(); - menuBuilder << "RicNewSummaryMultiPlotFeature"; - menuBuilder << "RicNewDerivedEnsembleFeature"; - menuBuilder << "RicOpenSummaryPlotEditorFeature"; - menuBuilder << "RicAppendSummaryCurvesForSummaryCasesFeature"; - menuBuilder << "RicAppendSummaryPlotsForSummaryCasesFeature"; - menuBuilder.addSeparator(); - menuBuilder << "RicConvertGroupToEnsembleFeature"; - menuBuilder.addSeparator(); - } else if ( dynamic_cast( firstUiItem ) ) { menuBuilder << "RicAddWellLogToPlotFeature"; @@ -1123,7 +1104,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "RicDeleteWellPathFeature"; menuBuilder << "RicLinkWellPathFeature"; - if ( dynamic_cast( firstUiItem ) || dynamic_cast( firstUiItem ) ) + if ( dynamic_cast( firstUiItem ) ) { menuBuilder << "RicAppendSummaryCurvesForSummaryCasesFeature"; menuBuilder << "RicAppendSummaryPlotsForSummaryCasesFeature"; diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseMainCollection.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseMainCollection.cpp index 2a1419a168..4db584039a 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseMainCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseMainCollection.cpp @@ -590,6 +590,7 @@ std::vector { auto sumCase = new RimFileSummaryCase(); sumCase->setIncludeRestartFiles( fileInfo.includeRestartFiles() ); + sumCase->setDisplayNameOption( RimCaseDisplayNameTools::DisplayName::SHORT_CASE_NAME ); newSumCase = sumCase; } else diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryEnsemble.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryEnsemble.cpp index 8011bb44b5..3ed601cff8 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryEnsemble.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryEnsemble.cpp @@ -37,6 +37,7 @@ #include "RimSummaryEnsembleTools.h" #include "RimSummaryPlot.h" +#include "cafCmdFeatureMenuBuilder.h" #include "cafPdmFieldScriptingCapability.h" #include "cafPdmObjectScriptingCapability.h" #include "cafPdmUiLineEditor.h" @@ -865,6 +866,33 @@ void RimSummaryEnsemble::onCaseNameChanged( const SignalEmitter* emitter ) caseNameChanged.send(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSummaryEnsemble::appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const +{ + menuBuilder.subMenuStart( "Import" ); + menuBuilder << "RicImportSummaryCaseFeature"; + menuBuilder << "RicImportSummaryCasesFeature"; + menuBuilder << "RicImportSummaryGroupFeature"; + menuBuilder << "RicImportEnsembleFeature"; + menuBuilder.subMenuEnd(); + menuBuilder.addSeparator(); + menuBuilder << "RicReplaceSummaryEnsembleFeature"; + menuBuilder << "RicNewSummaryMultiPlotFeature"; + menuBuilder << "RicNewDerivedEnsembleFeature"; + menuBuilder << "RicOpenSummaryPlotEditorFeature"; + menuBuilder << "RicAppendSummaryCurvesForSummaryCasesFeature"; + menuBuilder << "RicAppendSummaryPlotsForSummaryCasesFeature"; + menuBuilder.addSeparator(); + menuBuilder << "RicConvertGroupToEnsembleFeature"; + menuBuilder.addSeparator(); + menuBuilder << "RicAppendSummaryCurvesForSummaryCasesFeature"; + menuBuilder << "RicAppendSummaryPlotsForSummaryCasesFeature"; + menuBuilder << "RicCreateMultiPlotFromSelectionFeature"; + menuBuilder << "RicCreatePlotFromTemplateByShortcutFeature"; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryEnsemble.h b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryEnsemble.h index 0b022752de..21c36b0003 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryEnsemble.h +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryEnsemble.h @@ -118,6 +118,7 @@ protected: void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; void buildMetaData(); + void appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const override; private: caf::PdmFieldHandle* userDescriptionField() override;