Files
ResInsight/ApplicationCode/ProjectDataModel/RimCellRangeFilterCollection.cpp
T

265 lines
11 KiB
C++
Raw Normal View History

2012-05-18 09:45:23 +02:00
/////////////////////////////////////////////////////////////////////////////////
//
2014-09-23 15:04:57 +02:00
// Copyright (C) 2011- Statoil ASA
// Copyright (C) 2013- Ceetron Solutions AS
// Copyright (C) 2011-2012 Ceetron AS
//
2012-05-18 09:45:23 +02:00
// 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.
//
2012-05-18 09:45:23 +02:00
// 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>
2012-05-18 09:45:23 +02:00
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RimCellRangeFilterCollection.h"
2014-07-24 10:11:43 +02:00
2018-01-09 10:11:28 +01:00
#include "Rim3dView.h"
#include "RimCellRangeFilter.h"
2015-10-13 10:24:11 +02:00
#include "RimViewController.h"
#include "RimViewLinker.h"
2015-08-12 11:30:27 +02:00
#include "cafPdmUiEditorHandle.h"
#include "cvfStructGridGeometryGenerator.h"
CAF_PDM_SOURCE_INIT( RimCellRangeFilterCollection, "CellRangeFilterCollection" );
2012-05-18 09:45:23 +02:00
//--------------------------------------------------------------------------------------------------
///
2012-05-18 09:45:23 +02:00
//--------------------------------------------------------------------------------------------------
RimCellRangeFilterCollection::RimCellRangeFilterCollection()
{
CAF_PDM_InitObject( "Range Filters", ":/CellFilter_Range.png", "", "" );
2012-05-18 09:45:23 +02:00
CAF_PDM_InitFieldNoDefault( &rangeFilters, "RangeFilters", "Range Filters", "", "", "" );
rangeFilters.uiCapability()->setUiHidden( true );
CAF_PDM_InitField( &isActive, "Active", true, "Active", "", "", "" );
isActive.uiCapability()->setUiHidden( true );
2012-05-18 09:45:23 +02:00
}
//--------------------------------------------------------------------------------------------------
///
2012-05-18 09:45:23 +02:00
//--------------------------------------------------------------------------------------------------
RimCellRangeFilterCollection::~RimCellRangeFilterCollection()
{
2015-07-31 18:58:23 +02:00
rangeFilters.deleteAllChildObjects();
2012-05-18 09:45:23 +02:00
}
//--------------------------------------------------------------------------------------------------
/// RimCellRangeFilter is using Eclipse 1-based indexing, adjust filter values before
2012-05-18 09:45:23 +02:00
// populating cvf::CellRangeFilter (which is 0-based)
//--------------------------------------------------------------------------------------------------
void RimCellRangeFilterCollection::compoundCellRangeFilter( cvf::CellRangeFilter* cellRangeFilter, size_t gridIndex ) const
2012-05-18 09:45:23 +02:00
{
CVF_ASSERT( cellRangeFilter );
2012-05-18 09:45:23 +02:00
for ( size_t i = 0; i < rangeFilters.size(); i++ )
2012-05-18 09:45:23 +02:00
{
2015-07-31 18:58:23 +02:00
RimCellRangeFilter* rangeFilter = rangeFilters[i];
2012-05-18 09:45:23 +02:00
if ( rangeFilter && rangeFilter->isActive() && static_cast<size_t>( rangeFilter->gridIndex() ) == gridIndex )
2012-05-18 09:45:23 +02:00
{
if ( rangeFilter->filterMode == RimCellFilter::INCLUDE )
2012-05-18 09:45:23 +02:00
{
if ( rangeFilter->useIndividualCellIndices() )
{
for ( const auto& cellIndex : rangeFilter->individualCellIndices() )
{
cellRangeFilter->addCellInclude( cellIndex.x() - 1,
cellIndex.y() - 1,
cellIndex.z() - 1,
rangeFilter->propagateToSubGrids() );
}
}
else
{
cellRangeFilter->addCellIncludeRange( rangeFilter->startIndexI - 1,
rangeFilter->startIndexJ - 1,
rangeFilter->startIndexK - 1,
rangeFilter->startIndexI - 1 + rangeFilter->cellCountI,
rangeFilter->startIndexJ - 1 + rangeFilter->cellCountJ,
rangeFilter->startIndexK - 1 + rangeFilter->cellCountK,
rangeFilter->propagateToSubGrids() );
}
2012-05-18 09:45:23 +02:00
}
else
{
if ( rangeFilter->useIndividualCellIndices() )
{
for ( const auto& cellIndex : rangeFilter->individualCellIndices() )
{
cellRangeFilter->addCellExclude( cellIndex.x() - 1,
cellIndex.y() - 1,
cellIndex.z() - 1,
rangeFilter->propagateToSubGrids() );
}
}
else
{
cellRangeFilter->addCellExcludeRange( rangeFilter->startIndexI - 1,
rangeFilter->startIndexJ - 1,
rangeFilter->startIndexK - 1,
rangeFilter->startIndexI - 1 + rangeFilter->cellCountI,
rangeFilter->startIndexJ - 1 + rangeFilter->cellCountJ,
rangeFilter->startIndexK - 1 + rangeFilter->cellCountK,
rangeFilter->propagateToSubGrids() );
}
2012-05-18 09:45:23 +02:00
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
2012-05-18 09:45:23 +02:00
//--------------------------------------------------------------------------------------------------
void RimCellRangeFilterCollection::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue )
2012-05-18 09:45:23 +02:00
{
updateIconState();
uiCapability()->updateConnectedEditors();
updateDisplayModeNotifyManagedViews( nullptr );
2012-05-18 09:45:23 +02:00
}
//--------------------------------------------------------------------------------------------------
2020-05-18 16:02:27 +02:00
///
//--------------------------------------------------------------------------------------------------
void RimCellRangeFilterCollection::onChildDeleted( caf::PdmChildArrayFieldHandle* childArray,
std::vector<caf::PdmObjectHandle*>& referringObjects )
{
updateDisplayModeNotifyManagedViews( nullptr );
}
//--------------------------------------------------------------------------------------------------
///
2012-05-18 09:45:23 +02:00
//--------------------------------------------------------------------------------------------------
void RimCellRangeFilterCollection::updateDisplayModeNotifyManagedViews( RimCellRangeFilter* changedRangeFilter )
2012-05-18 09:45:23 +02:00
{
2018-02-18 18:56:43 +01:00
Rim3dView* view = nullptr;
firstAncestorOrThisOfType( view );
if ( !view ) return;
2012-05-18 09:45:23 +02:00
if ( view->isMasterView() )
{
RimViewLinker* viewLinker = view->assosiatedViewLinker();
if ( viewLinker )
{
// Update data for range filter
// Update of display model is handled by view->scheduleGeometryRegen, also for managed views
viewLinker->updateRangeFilters( changedRangeFilter );
}
}
view->scheduleGeometryRegen( VISIBLE_WELL_CELLS );
view->scheduleGeometryRegen( RANGE_FILTERED );
view->scheduleGeometryRegen( RANGE_FILTERED_INACTIVE );
view->scheduleCreateDisplayModelAndRedraw();
2012-05-18 09:45:23 +02:00
}
//--------------------------------------------------------------------------------------------------
///
2012-05-18 09:45:23 +02:00
//--------------------------------------------------------------------------------------------------
bool RimCellRangeFilterCollection::hasActiveFilters() const
{
if ( !isActive() ) return false;
for ( size_t i = 0; i < rangeFilters.size(); i++ )
2012-05-18 09:45:23 +02:00
{
if ( rangeFilters[i]->isActive() ) return true;
2012-05-18 09:45:23 +02:00
}
return false;
}
2013-02-12 14:00:39 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimCellRangeFilterCollection::objectToggleField()
{
2013-09-06 15:05:41 +02:00
return &isActive;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimCellRangeFilterCollection::hasActiveIncludeFilters() const
{
if ( !isActive ) return false;
for ( size_t i = 0; i < rangeFilters.size(); i++ )
{
if ( rangeFilters[i]->isActive() && rangeFilters[i]->filterMode() == RimCellFilter::INCLUDE ) return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-01-09 10:11:28 +01:00
Rim3dView* RimCellRangeFilterCollection::baseView() const
{
2018-02-18 18:56:43 +01:00
Rim3dView* rimView = nullptr;
firstAncestorOrThisOfType( rimView );
return rimView;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCellRangeFilterCollection::updateIconState()
{
bool activeIcon = true;
RimViewController* viewController = baseView()->viewController();
if ( viewController && ( viewController->isRangeFiltersControlled() || viewController->isVisibleCellsOveridden() ) )
{
activeIcon = false;
}
if ( !isActive )
{
activeIcon = false;
}
updateUiIconFromState( activeIcon );
for ( size_t i = 0; i < rangeFilters.size(); i++ )
{
RimCellRangeFilter* rangeFilter = rangeFilters[i];
rangeFilter->updateActiveState();
rangeFilter->updateIconState();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCellRangeFilterCollection::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName )
{
PdmObject::defineUiTreeOrdering( uiTreeOrdering, uiConfigName );
RimViewController* viewController = baseView()->viewController();
if ( viewController && viewController->isRangeFiltersControlled() )
{
isActive.uiCapability()->setUiReadOnly( true );
}
else
{
isActive.uiCapability()->setUiReadOnly( false );
}
updateIconState();
}