mirror of
https://github.com/OPM/ResInsight.git
synced 2026-08-27 05:37:21 -05:00
Combined filters used to always show whatever literal string the user passed in (or the default "Combined Filter"). For programmatic creation without a name, that string never reflected the children, leaving the case-level "Data Filters" tree row stale when child bounds changed. Add an m_autoDeriveName flag (default true) to RimCombinedFilter. When on, the display name is recomputed on every relevant change — addFilter, removeFilter, onChildAdded, onChildFilterChanged, and combineMode toggle — by joining children's name() with " AND " / " OR ". The flag flips to false the first time the user renames the filter via the UI property panel or via Python (combined.user_description = "..."), preserving any explicitly typed name verbatim from then on. Two child-creation paths needed an extra triggerFilterChanged() so the combined parent recomputes after the child's final name is set: addPropertyFilterToCombinedFilter (setDefaults updates name without a signal) and RimcCombinedFilter_addRangeFilter (Rimc applies user params after addNewFilter). The Rimc factory passes setAutoDeriveName(false) only when a name is supplied. The Python example demonstrates both modes side by side, and test_combined_filter.py adds three cases: named filter preserves its name, auto-derived filter tracks bound mutations, and Python rename locks the auto-derived filter.
154 lines
6.2 KiB
C++
154 lines
6.2 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2026 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 <http://www.gnu.org/licenses/gpl.html>
|
|
// for more details.
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "RimcCombinedFilter.h"
|
|
|
|
#include "RiaDefines.h"
|
|
|
|
#include "RicEclipsePropertyFilterFeatureImpl.h"
|
|
|
|
#include "RimCellRangeFilter.h"
|
|
#include "RimCombinedFilter.h"
|
|
#include "RimEclipsePropertyFilter.h"
|
|
#include "RimEclipseResultDefinition.h"
|
|
|
|
#include "Rim3dView.h"
|
|
|
|
#include "cafAppEnum.h"
|
|
#include "cafPdmAbstractFieldScriptingCapability.h"
|
|
#include "cafPdmFieldScriptingCapability.h"
|
|
|
|
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimCombinedFilter, RimcCombinedFilter_addPropertyFilter, "AddPropertyFilter" );
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimcCombinedFilter_addPropertyFilter::RimcCombinedFilter_addPropertyFilter( caf::PdmObjectHandle* self )
|
|
: caf::PdmObjectCreationMethod( self )
|
|
{
|
|
CAF_PDM_InitObject( "Add Property Filter", "", "", "Add a new property filter as a child of this combined filter" );
|
|
|
|
CAF_PDM_InitScriptableFieldNoDefault( &m_resultVariable, "ResultVariable", "Result Variable" );
|
|
CAF_PDM_InitScriptableFieldNoDefault( &m_resultType, "ResultType", "Result Type" );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::expected<caf::PdmObjectHandle*, QString> RimcCombinedFilter_addPropertyFilter::execute()
|
|
{
|
|
auto* combined = self<RimCombinedFilter>();
|
|
if ( !combined ) return std::unexpected( QString( "Self is not a RimCombinedFilter" ) );
|
|
|
|
RimEclipsePropertyFilter* pf = RicEclipsePropertyFilterFeatureImpl::addPropertyFilterToCombinedFilter( combined );
|
|
if ( !pf ) return std::unexpected( QString( "Failed to create property filter" ) );
|
|
|
|
const bool hasType = !m_resultType().isEmpty();
|
|
const bool hasVar = !m_resultVariable().isEmpty();
|
|
|
|
if ( hasType )
|
|
{
|
|
const auto cat = caf::AppEnum<RiaDefines::ResultCatType>::fromText( m_resultType() );
|
|
pf->resultDefinition()->setResultType( cat );
|
|
}
|
|
if ( hasVar )
|
|
{
|
|
pf->resultDefinition()->setResultVariable( m_resultVariable() );
|
|
}
|
|
if ( hasType || hasVar )
|
|
{
|
|
pf->resultDefinition()->loadResult();
|
|
pf->setToDefaultValues();
|
|
pf->updateFilterName();
|
|
}
|
|
|
|
pf->updateConnectedEditors();
|
|
|
|
return pf;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QString RimcCombinedFilter_addPropertyFilter::classKeywordReturnedType() const
|
|
{
|
|
return RimEclipsePropertyFilter::classKeywordStatic();
|
|
}
|
|
|
|
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimCombinedFilter, RimcCombinedFilter_addRangeFilter, "AddRangeFilter" );
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimcCombinedFilter_addRangeFilter::RimcCombinedFilter_addRangeFilter( caf::PdmObjectHandle* self )
|
|
: caf::PdmObjectCreationMethod( self )
|
|
{
|
|
CAF_PDM_InitObject( "Add Range Filter", "", "", "Add a new IJK range filter as a child of this combined filter" );
|
|
|
|
CAF_PDM_InitScriptableFieldNoDefault( &m_name, "Name", "Name" );
|
|
CAF_PDM_InitScriptableField( &m_startI, "StartI", -1, "Start I" );
|
|
CAF_PDM_InitScriptableField( &m_startJ, "StartJ", -1, "Start J" );
|
|
CAF_PDM_InitScriptableField( &m_startK, "StartK", -1, "Start K" );
|
|
CAF_PDM_InitScriptableField( &m_cellCountI, "CellCountI", -1, "Cell Count I" );
|
|
CAF_PDM_InitScriptableField( &m_cellCountJ, "CellCountJ", -1, "Cell Count J" );
|
|
CAF_PDM_InitScriptableField( &m_cellCountK, "CellCountK", -1, "Cell Count K" );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::expected<caf::PdmObjectHandle*, QString> RimcCombinedFilter_addRangeFilter::execute()
|
|
{
|
|
auto* combined = self<RimCombinedFilter>();
|
|
if ( !combined ) return std::unexpected( QString( "Self is not a RimCombinedFilter" ) );
|
|
|
|
auto* rf = combined->addNewFilter<RimCellRangeFilter>(
|
|
[]( RimCellRangeFilter* f )
|
|
{
|
|
f->setGridIndex( 0 );
|
|
f->setDefaultValues( -1, -1 );
|
|
} );
|
|
|
|
if ( !rf ) return std::unexpected( QString( "Failed to create range filter" ) );
|
|
|
|
if ( !m_name().isEmpty() ) rf->setName( m_name() );
|
|
|
|
if ( m_startI() > 0 ) rf->startIndexI = m_startI();
|
|
if ( m_startJ() > 0 ) rf->startIndexJ = m_startJ();
|
|
if ( m_startK() > 0 ) rf->startIndexK = m_startK();
|
|
if ( m_cellCountI() > 0 ) rf->cellCountI = m_cellCountI();
|
|
if ( m_cellCountJ() > 0 ) rf->cellCountJ = m_cellCountJ();
|
|
if ( m_cellCountK() > 0 ) rf->cellCountK = m_cellCountK();
|
|
|
|
rf->updateConnectedEditors();
|
|
|
|
// After the final name is set, notify the combined parent so it can refresh its
|
|
// auto-derived display name.
|
|
rf->triggerFilterChanged();
|
|
|
|
return rf;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QString RimcCombinedFilter_addRangeFilter::classKeywordReturnedType() const
|
|
{
|
|
return RimCellRangeFilter::classKeywordStatic();
|
|
}
|