From ab8f90d783c8e4b9d1d8952a393b806941c3ffa8 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 17 Dec 2024 08:54:28 +0100 Subject: [PATCH] #11994 Allow property filter to be linked to cell result --- .../EclipseCommands/CMakeLists_files.cmake | 2 + ...cAddLinkedEclipsePropertyFilterFeature.cpp | 70 +++++++++++++++++++ ...RicAddLinkedEclipsePropertyFilterFeature.h | 34 +++++++++ .../CellFilters/RimEclipsePropertyFilter.cpp | 33 ++++++++- .../CellFilters/RimEclipsePropertyFilter.h | 10 ++- .../RimEclipsePropertyFilterCollection.cpp | 53 ++++++++++++++ .../RimEclipsePropertyFilterCollection.h | 5 ++ .../RimContextCommandBuilder.cpp | 5 -- .../ProjectDataModel/RimEclipseView.cpp | 2 + 9 files changed, 205 insertions(+), 9 deletions(-) create mode 100644 ApplicationLibCode/Commands/EclipseCommands/RicAddLinkedEclipsePropertyFilterFeature.cpp create mode 100644 ApplicationLibCode/Commands/EclipseCommands/RicAddLinkedEclipsePropertyFilterFeature.h diff --git a/ApplicationLibCode/Commands/EclipseCommands/CMakeLists_files.cmake b/ApplicationLibCode/Commands/EclipseCommands/CMakeLists_files.cmake index b829a33814..013f875647 100644 --- a/ApplicationLibCode/Commands/EclipseCommands/CMakeLists_files.cmake +++ b/ApplicationLibCode/Commands/EclipseCommands/CMakeLists_files.cmake @@ -22,6 +22,7 @@ set(SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RicImportRoffCaseFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicAddGridCalculationFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicCreateGridCaseEnsemblesFromFilesFeature.h + ${CMAKE_CURRENT_LIST_DIR}/RicAddLinkedEclipsePropertyFilterFeature.h ) set(SOURCE_GROUP_SOURCE_FILES @@ -48,6 +49,7 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RicImportRoffCaseFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicAddGridCalculationFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicCreateGridCaseEnsemblesFromFilesFeature.cpp + ${CMAKE_CURRENT_LIST_DIR}/RicAddLinkedEclipsePropertyFilterFeature.cpp ) list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) diff --git a/ApplicationLibCode/Commands/EclipseCommands/RicAddLinkedEclipsePropertyFilterFeature.cpp b/ApplicationLibCode/Commands/EclipseCommands/RicAddLinkedEclipsePropertyFilterFeature.cpp new file mode 100644 index 0000000000..48c6ef1cc9 --- /dev/null +++ b/ApplicationLibCode/Commands/EclipseCommands/RicAddLinkedEclipsePropertyFilterFeature.cpp @@ -0,0 +1,70 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2024- 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 "RicAddLinkedEclipsePropertyFilterFeature.h" + +#include "RicEclipsePropertyFilterFeatureImpl.h" + +#include "RimEclipsePropertyFilter.h" +#include "RimEclipsePropertyFilterCollection.h" + +#include "Riu3DMainWindowTools.h" + +#include + +CAF_CMD_SOURCE_INIT( RicAddLinkedEclipsePropertyFilterFeature, "RicAddLinkedEclipsePropertyFilterFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicAddLinkedEclipsePropertyFilterFeature::isCommandEnabled() const +{ + auto filterCollections = RicEclipsePropertyFilterFeatureImpl::selectedPropertyFilterCollections(); + if ( filterCollections.size() == 1 ) + { + return RicEclipsePropertyFilterFeatureImpl::isPropertyFilterCommandAvailable( filterCollections[0] ); + } + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicAddLinkedEclipsePropertyFilterFeature::onActionTriggered( bool isChecked ) +{ + auto filterCollections = RicEclipsePropertyFilterFeatureImpl::selectedPropertyFilterCollections(); + + if ( filterCollections.size() == 1 ) + { + auto coll = filterCollections[0]; + auto filter = coll->addFilterLinkedToCellResult(); + coll->updateAllRequiredEditors(); + + Riu3DMainWindowTools::setExpanded( filter ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicAddLinkedEclipsePropertyFilterFeature::setupActionLook( QAction* actionToSetup ) +{ + actionToSetup->setIcon( QIcon( ":/CellFilter_Values.png" ) ); + actionToSetup->setText( "Add Property Filter Linked to Cell Result" ); +} diff --git a/ApplicationLibCode/Commands/EclipseCommands/RicAddLinkedEclipsePropertyFilterFeature.h b/ApplicationLibCode/Commands/EclipseCommands/RicAddLinkedEclipsePropertyFilterFeature.h new file mode 100644 index 0000000000..fa7624920c --- /dev/null +++ b/ApplicationLibCode/Commands/EclipseCommands/RicAddLinkedEclipsePropertyFilterFeature.h @@ -0,0 +1,34 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2024- 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 RicAddLinkedEclipsePropertyFilterFeature : 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/CellFilters/RimEclipsePropertyFilter.cpp b/ApplicationLibCode/ProjectDataModel/CellFilters/RimEclipsePropertyFilter.cpp index d11da52660..429d7705cc 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimEclipsePropertyFilter.cpp +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimEclipsePropertyFilter.cpp @@ -40,6 +40,7 @@ #include "RiuMainWindow.h" +#include "cafPdmUiCheckBoxEditor.h" #include "cafPdmUiDoubleSliderEditor.h" #include "cafPdmUiSliderEditor.h" #include "cafPdmUiTreeAttributes.h" @@ -65,6 +66,13 @@ RimEclipsePropertyFilter::RimEclipsePropertyFilter() // Fields in this object are displayed using defineUiOrdering() m_resultDefinition.uiCapability()->setUiTreeChildrenHidden( true ); + CAF_PDM_InitFieldNoDefault( &m_linkedWithCellResult, + "LinkedWithCellResult", + "Linked With Cell Result", + "", + "The selected cell result is automatically used to update the property filter." ); + caf::PdmUiNativeCheckBoxEditor::configureFieldForEditor( &m_linkedWithCellResult ); + CAF_PDM_InitField( &m_rangeLabelText, "Dummy_keyword", QString( "Range Type" ), "Range Type" ); m_rangeLabelText.xmlCapability()->disableIO(); m_rangeLabelText.uiCapability()->setUiReadOnly( true ); @@ -119,6 +127,22 @@ RimEclipseResultDefinition* RimEclipsePropertyFilter::resultDefinition() const return m_resultDefinition; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimEclipsePropertyFilter::isLinkedWithCellResult() const +{ + return m_linkedWithCellResult(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimEclipsePropertyFilter::setLinkedWithCellResult( bool linkedWithCellResult ) +{ + m_linkedWithCellResult = linkedWithCellResult; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -161,7 +185,7 @@ void RimEclipsePropertyFilter::fieldChangedByUi( const caf::PdmFieldHandle* chan if ( &m_lowerBound == changedField || &m_upperBound == changedField || &m_isActive == changedField || &m_filterMode == changedField || &m_selectedCategoryValues == changedField || &m_useCategorySelection == changedField || &m_integerUpperBound == changedField || - &m_integerLowerBound == changedField ) + &m_integerLowerBound == changedField || &m_linkedWithCellResult == changedField ) { m_isDuplicatedFromLinkedView = false; @@ -207,6 +231,13 @@ void RimEclipsePropertyFilter::defineUiOrdering( QString uiConfigName, caf::PdmU // Fields declared in RimCellFilter uiOrdering.add( &m_name ); + uiOrdering.add( &m_linkedWithCellResult ); + if ( m_linkedWithCellResult ) + { + uiOrdering.skipRemainingFields( true ); + return; + } + // Fields declared in Rimm_resultDefinition caf::PdmUiGroup* group1 = uiOrdering.addNewGroup( "Result" ); m_resultDefinition->uiOrdering( uiConfigName, *group1 ); diff --git a/ApplicationLibCode/ProjectDataModel/CellFilters/RimEclipsePropertyFilter.h b/ApplicationLibCode/ProjectDataModel/CellFilters/RimEclipsePropertyFilter.h index 18e88bb3f1..f542d1fc34 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimEclipsePropertyFilter.h +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimEclipsePropertyFilter.h @@ -41,6 +41,8 @@ class RimEclipsePropertyFilter : public RimPropertyFilter, public RimFieldQuickA ~RimEclipsePropertyFilter() override; RimEclipseResultDefinition* resultDefinition() const; + bool isLinkedWithCellResult() const; + void setLinkedWithCellResult( bool linkedWithCellResult ); void rangeValues( double* lower, double* upper ) const; bool isCategorySelectionActive() const; @@ -84,10 +86,12 @@ class RimEclipsePropertyFilter : public RimPropertyFilter, public RimFieldQuickA private: caf::PdmChildField m_resultDefinition; - caf::PdmField m_rangeLabelText; - caf::PdmField m_lowerBound; - caf::PdmField m_upperBound; + caf::PdmField m_linkedWithCellResult; + + caf::PdmField m_rangeLabelText; + caf::PdmField m_lowerBound; + caf::PdmField m_upperBound; caf::PdmProxyValueField m_integerLowerBound; caf::PdmProxyValueField m_integerUpperBound; diff --git a/ApplicationLibCode/ProjectDataModel/CellFilters/RimEclipsePropertyFilterCollection.cpp b/ApplicationLibCode/ProjectDataModel/CellFilters/RimEclipsePropertyFilterCollection.cpp index 3774fedfa0..ebfc12f989 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimEclipsePropertyFilterCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimEclipsePropertyFilterCollection.cpp @@ -29,6 +29,7 @@ #include "RimViewController.h" #include "RimViewLinker.h" +#include "cafCmdFeatureMenuBuilder.h" #include "cafPdmUiEditorHandle.h" CAF_PDM_SOURCE_INIT( RimEclipsePropertyFilterCollection, "CellPropertyFilters" ); @@ -191,3 +192,55 @@ void RimEclipsePropertyFilterCollection::updateFromCurrentTimeStep() cellFilter->updateFromCurrentTimeStep(); } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimEclipsePropertyFilterCollection::updateDefaultResult( const RimEclipseCellColors* result ) +{ + if ( !result ) return; + if ( m_propertyFilters.empty() ) return; + + auto view = reservoirView(); + for ( auto filter : m_propertyFilters ) + { + if ( !filter->isLinkedWithCellResult() ) continue; + + if ( view && view->eclipseCase() ) + { + filter->resultDefinition()->setEclipseCase( view->eclipseCase() ); + } + + filter->resultDefinition()->simpleCopy( result ); + filter->resultDefinition()->loadResult(); + filter->setToDefaultValues(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimEclipsePropertyFilter* RimEclipsePropertyFilterCollection::addFilterLinkedToCellResult() +{ + RimEclipsePropertyFilter* propertyFilter = new RimEclipsePropertyFilter(); + propertyFilter->setLinkedWithCellResult( true ); + m_propertyFilters.push_back( propertyFilter ); + + auto view = reservoirView(); + if ( view && view->eclipseCase() ) + { + propertyFilter->resultDefinition()->setEclipseCase( view->eclipseCase() ); + updateDefaultResult( view->cellResult() ); + } + + return propertyFilter; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimEclipsePropertyFilterCollection::appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const +{ + menuBuilder << "RicEclipsePropertyFilterNewFeature"; + menuBuilder << "RicAddLinkedEclipsePropertyFilterFeature"; +} diff --git a/ApplicationLibCode/ProjectDataModel/CellFilters/RimEclipsePropertyFilterCollection.h b/ApplicationLibCode/ProjectDataModel/CellFilters/RimEclipsePropertyFilterCollection.h index 594c070c13..66e9d47b1d 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimEclipsePropertyFilterCollection.h +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimEclipsePropertyFilterCollection.h @@ -26,6 +26,7 @@ class RimEclipsePropertyFilter; class RimEclipseView; +class RimEclipseCellColors; //================================================================================================== /// @@ -53,8 +54,12 @@ class RimEclipsePropertyFilterCollection : public RimPropertyFilterCollection void updateIconState() override; void updateFromCurrentTimeStep(); + void updateDefaultResult( const RimEclipseCellColors* result ); + RimEclipsePropertyFilter* addFilterLinkedToCellResult(); + protected: void initAfterRead() override; + void appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const override; private: caf::PdmChildArrayField m_propertyFilters; diff --git a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp index 78d82cbf86..361b643613 100644 --- a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -51,7 +51,6 @@ #include "RimEclipseFaultColors.h" #include "RimEclipseInputProperty.h" #include "RimEclipsePropertyFilter.h" -#include "RimEclipsePropertyFilterCollection.h" #include "RimEclipseResultAddress.h" #include "RimEclipseStatisticsCase.h" #include "RimEclipseView.h" @@ -317,10 +316,6 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() { menuBuilder << "RicSaveEclipseInputPropertyFeature"; } - else if ( dynamic_cast( firstUiItem ) ) - { - menuBuilder << "RicEclipsePropertyFilterNewFeature"; - } else if ( dynamic_cast( firstUiItem ) ) { menuBuilder << "RicEclipsePropertyFilterInsertFeature"; diff --git a/ApplicationLibCode/ProjectDataModel/RimEclipseView.cpp b/ApplicationLibCode/ProjectDataModel/RimEclipseView.cpp index 6a9f632724..cc279e62cf 100644 --- a/ApplicationLibCode/ProjectDataModel/RimEclipseView.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimEclipseView.cpp @@ -542,6 +542,8 @@ void RimEclipseView::childFieldChangedByUi( const caf::PdmFieldHandle* changedCh if ( changedChildField == &m_cellResult ) { updateMdiWindowTitle(); + + m_propertyFilterCollection->updateDefaultResult( m_cellResult() ); } }