diff --git a/ApplicationLibCode/Application/Tools/RiaImportEclipseCaseTools.h b/ApplicationLibCode/Application/Tools/RiaImportEclipseCaseTools.h index 34fc2d4268..684c5c94a9 100644 --- a/ApplicationLibCode/Application/Tools/RiaImportEclipseCaseTools.h +++ b/ApplicationLibCode/Application/Tools/RiaImportEclipseCaseTools.h @@ -43,7 +43,8 @@ public: static bool addEclipseCases( const QStringList& fileNames, RimIdenticalGridCaseGroup** resultingCaseGroup = nullptr ); -private: static int openEclipseCaseFromFile( const QString& fileName ); + +private: static int openEclipseCaseShowTimeStepFilterImpl( const QString& fileName, bool showTimeStepFilter ); }; diff --git a/ApplicationLibCode/Commands/CMakeLists_files.cmake b/ApplicationLibCode/Commands/CMakeLists_files.cmake index 4cd702e993..51e3d1033d 100644 --- a/ApplicationLibCode/Commands/CMakeLists_files.cmake +++ b/ApplicationLibCode/Commands/CMakeLists_files.cmake @@ -78,6 +78,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RicNewCustomObjectiveFunctionFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicNewCustomObjectiveFunctionWeightFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicNewPressureTableItemFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicDeletePressureTableItemFeature.h +${CMAKE_CURRENT_LIST_DIR}/RicImportGridModelFromSummaryCaseFeature.h +${CMAKE_CURRENT_LIST_DIR}/RicImportGridModelFromSummaryCurveFeature.h ) @@ -160,6 +162,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RicNewCustomObjectiveFunctionFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicNewCustomObjectiveFunctionWeightFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicNewPressureTableItemFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicDeletePressureTableItemFeature.cpp +${CMAKE_CURRENT_LIST_DIR}/RicImportGridModelFromSummaryCaseFeature.cpp +${CMAKE_CURRENT_LIST_DIR}/RicImportGridModelFromSummaryCurveFeature.cpp ) if(Qt5Charts_FOUND) diff --git a/ApplicationLibCode/Commands/RicImportGridModelFromSummaryCaseFeature.cpp b/ApplicationLibCode/Commands/RicImportGridModelFromSummaryCaseFeature.cpp new file mode 100644 index 0000000000..e4921a4a1c --- /dev/null +++ b/ApplicationLibCode/Commands/RicImportGridModelFromSummaryCaseFeature.cpp @@ -0,0 +1,143 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2021 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 "RicImportGridModelFromSummaryCaseFeature.h" + +#include "RiaEclipseFileNameTools.h" +#include "RiaImportEclipseCaseTools.h" +#include "RiaLogging.h" + +#include "RimEclipseCase.h" +#include "RimFileSummaryCase.h" +#include "RimGridView.h" +#include "RimProject.h" + +#include "Riu3DMainWindowTools.h" + +#include "cafSelectionManager.h" + +#include +#include + +CAF_CMD_SOURCE_INIT( RicImportGridModelFromSummaryCaseFeature, "RicImportGridModelFromSummaryCaseFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicImportGridModelFromSummaryCaseFeature::openOrImportGridModelFromSummaryCase( const RimFileSummaryCase* summaryCase ) +{ + if ( !summaryCase ) return false; + + if ( findAndActivateFirstView( summaryCase ) ) return true; + + QString summaryFileName = summaryCase->summaryHeaderFilename(); + RiaEclipseFileNameTools fileHelper( summaryFileName ); + auto candidateGridFileName = fileHelper.findRelatedGridFile(); + + if ( QFileInfo::exists( candidateGridFileName ) ) + { + auto id = RiaImportEclipseCaseTools::openEclipseCaseFromFile( candidateGridFileName ); + if ( id > -1 ) + { + RiaLogging::info( QString( "Imported %1" ).arg( candidateGridFileName ) ); + + return true; + } + } + + RiaLogging::info( QString( "No grid case found based on summary file %1" ).arg( summaryFileName ) ); + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicImportGridModelFromSummaryCaseFeature::isCommandEnabled() +{ + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicImportGridModelFromSummaryCaseFeature::onActionTriggered( bool isChecked ) +{ + RimFileSummaryCase* summaryCase = caf::SelectionManager::instance()->selectedItemOfType(); + + openOrImportGridModelFromSummaryCase( summaryCase ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicImportGridModelFromSummaryCaseFeature::setupActionLook( QAction* actionToSetup ) +{ + actionToSetup->setIcon( QIcon( ":/3DWindow.svg" ) ); + + RimFileSummaryCase* summaryCase = caf::SelectionManager::instance()->selectedItemOfType(); + + auto gridCase = gridModelFromSummaryCase( summaryCase ); + if ( gridCase ) + { + actionToSetup->setText( "Open Grid Model View" ); + } + else + { + actionToSetup->setText( "Import Grid Model" ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicImportGridModelFromSummaryCaseFeature::findAndActivateFirstView( const RimFileSummaryCase* summaryCase ) +{ + auto gridCase = gridModelFromSummaryCase( summaryCase ); + if ( gridCase ) + { + if ( !gridCase->gridViews().empty() ) + { + Riu3DMainWindowTools::selectAsCurrentItem( gridCase->gridViews().front() ); + + return true; + } + } + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimEclipseCase* RicImportGridModelFromSummaryCaseFeature::gridModelFromSummaryCase( const RimFileSummaryCase* summaryCase ) +{ + if ( summaryCase ) + { + QString summaryFileName = summaryCase->summaryHeaderFilename(); + RiaEclipseFileNameTools fileHelper( summaryFileName ); + auto candidateGridFileName = fileHelper.findRelatedGridFile(); + + RimProject* project = RimProject::current(); + auto gridCase = project->eclipseCaseFromGridFileName( candidateGridFileName ); + + return gridCase; + } + + return nullptr; +} diff --git a/ApplicationLibCode/Commands/RicImportGridModelFromSummaryCaseFeature.h b/ApplicationLibCode/Commands/RicImportGridModelFromSummaryCaseFeature.h new file mode 100644 index 0000000000..cbbb4a81f7 --- /dev/null +++ b/ApplicationLibCode/Commands/RicImportGridModelFromSummaryCaseFeature.h @@ -0,0 +1,43 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2021 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 RimEclipseCase; +class RimFileSummaryCase; + +//================================================================================================== +/// +//================================================================================================== +class RicImportGridModelFromSummaryCaseFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +public: + static bool openOrImportGridModelFromSummaryCase( const RimFileSummaryCase* summaryCase ); + +protected: + bool isCommandEnabled() override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; + + static bool findAndActivateFirstView( const RimFileSummaryCase* summaryCase ); + static RimEclipseCase* gridModelFromSummaryCase( const RimFileSummaryCase* summaryCase ); +}; diff --git a/ApplicationLibCode/Commands/RicImportGridModelFromSummaryCurveFeature.cpp b/ApplicationLibCode/Commands/RicImportGridModelFromSummaryCurveFeature.cpp new file mode 100644 index 0000000000..734a03b3b5 --- /dev/null +++ b/ApplicationLibCode/Commands/RicImportGridModelFromSummaryCurveFeature.cpp @@ -0,0 +1,77 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2021 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 "RicImportGridModelFromSummaryCurveFeature.h" + +#include "RicImportGridModelFromSummaryCaseFeature.h" + +#include "RimFileSummaryCase.h" +#include "RimProject.h" + +#include "cafSelectionManager.h" + +#include + +CAF_CMD_SOURCE_INIT( RicImportGridModelFromSummaryCurveFeature, "RicImportGridModelFromSummaryCurveFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicImportGridModelFromSummaryCurveFeature::isCommandEnabled() +{ + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicImportGridModelFromSummaryCurveFeature::onActionTriggered( bool isChecked ) +{ + QVariant userData = this->userData(); + if ( !userData.isNull() && userData.canConvert() ) + { + int summaryCaseId = userData.value(); + + auto sumCases = RimProject::current()->allSummaryCases(); + for ( auto sumCase : sumCases ) + { + if ( sumCase->caseId() == summaryCaseId ) + { + auto fileSummaryCase = dynamic_cast( sumCase ); + + if ( fileSummaryCase ) + { + RicImportGridModelFromSummaryCaseFeature::openOrImportGridModelFromSummaryCase( fileSummaryCase ); + + return; + } + } + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicImportGridModelFromSummaryCurveFeature::setupActionLook( QAction* actionToSetup ) +{ + actionToSetup->setIcon( QIcon( ":/3DWindow.svg" ) ); + + // No action text is given here, as the custom text is defined in + // RiuSummaryQwtPlot::contextMenuEvent +} diff --git a/ApplicationLibCode/Commands/RicImportGridModelFromSummaryCurveFeature.h b/ApplicationLibCode/Commands/RicImportGridModelFromSummaryCurveFeature.h new file mode 100644 index 0000000000..3bc235eb20 --- /dev/null +++ b/ApplicationLibCode/Commands/RicImportGridModelFromSummaryCurveFeature.h @@ -0,0 +1,34 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2021 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 RicImportGridModelFromSummaryCurveFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + bool isCommandEnabled() override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; +}; diff --git a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp index f7b64eec4e..e949c81f43 100644 --- a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -760,6 +760,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "RicNewDefaultSummaryPlotFeature"; menuBuilder << "RicNewSummaryCrossPlotFeature"; menuBuilder.addSeparator(); + menuBuilder << "RicImportGridModelFromSummaryCaseFeature"; if ( !dynamic_cast( firstUiItem ) ) { diff --git a/ApplicationLibCode/UserInterface/RiuSummaryQwtPlot.cpp b/ApplicationLibCode/UserInterface/RiuSummaryQwtPlot.cpp index 47e669a060..d2cb25b1f3 100644 --- a/ApplicationLibCode/UserInterface/RiuSummaryQwtPlot.cpp +++ b/ApplicationLibCode/UserInterface/RiuSummaryQwtPlot.cpp @@ -254,6 +254,19 @@ void RiuSummaryQwtPlot::contextMenuEvent( QContextMenuEvent* event ) } } + { + auto summaryCase = summaryCurve->summaryCaseY(); + if ( summaryCase ) + { + int summaryCaseId = summaryCase->caseId(); + QVariant summaryCaseIdVariant( summaryCaseId ); + + menuBuilder.addCmdFeatureWithUserData( "RicImportGridModelFromSummaryCurveFeature", + "Open Grid Model", + summaryCaseIdVariant ); + } + } + if ( !curveClicked ) { RimSummaryPlot* summaryPlot = static_cast( plotDefinition() ); diff --git a/Fwk/AppFwk/cafCommand/cafCmdFeatureMenuBuilder.cpp b/Fwk/AppFwk/cafCommand/cafCmdFeatureMenuBuilder.cpp index 86a5606fb1..6ee608ad6f 100644 --- a/Fwk/AppFwk/cafCommand/cafCmdFeatureMenuBuilder.cpp +++ b/Fwk/AppFwk/cafCommand/cafCmdFeatureMenuBuilder.cpp @@ -82,6 +82,8 @@ CmdFeatureMenuBuilder& CmdFeatureMenuBuilder::operator<<( const QString& command //-------------------------------------------------------------------------------------------------- CmdFeatureMenuBuilder& CmdFeatureMenuBuilder::addCmdFeature( const QString commandId, const QString& uiText ) { + CAF_ASSERT( !commandId.isEmpty() ); + MenuItem i; i.itemType = MenuItem::COMMAND; i.itemName = commandId;