Skip to content

Commit

Permalink
Cell filter uses polygon from global list
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Feb 20, 2024
1 parent bf4bd42 commit 0aee8bb
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "Polygons/RimPolygonInView.h"

#include "RiaApplication.h"
#include "RicNewPolygonFilterFeature.h"

#include "RimCase.h"
#include "RimCellFilterCollection.h"
#include "RimGridView.h"
Expand All @@ -39,20 +41,13 @@ CAF_CMD_SOURCE_INIT( RicNewPolygonFilter3dviewFeature, "RicNewPolygonFilter3dvie
//--------------------------------------------------------------------------------------------------
void RicNewPolygonFilter3dviewFeature::onActionTriggered( bool isChecked )
{
// Get the selected Cell Filter Collection
RimGridView* viewOrComparisonView = RiaApplication::instance()->activeMainOrComparisonGridView();
if ( !viewOrComparisonView ) return;

RimCellFilterCollection* filtColl = viewOrComparisonView->cellFilterCollection();

// and the case to use
RimCase* sourceCase = viewOrComparisonView->ownerCase();
RimCellFilterCollection* filtColl = viewOrComparisonView->cellFilterCollection();
RimCase* sourceCase = viewOrComparisonView->ownerCase();

RimPolygonFilter* lastCreatedOrUpdated = filtColl->addNewPolygonFilter( sourceCase );
if ( lastCreatedOrUpdated )
{
Riu3DMainWindowTools::selectAsCurrentItem( lastCreatedOrUpdated->polygonEditor() );
}
RicNewPolygonFilterFeature::appendNewPolygonFilter( sourceCase, filtColl );
}

//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "RicNewPolygonFilterFeature.h"

#include "Polygons/RimPolygonInView.h"
#include "Polygons/RimPolygonTools.h"

#include "RimCase.h"
#include "RimCellFilterCollection.h"
Expand All @@ -33,24 +34,41 @@

CAF_CMD_SOURCE_INIT( RicNewPolygonFilterFeature, "RicNewPolygonFilterFeature" );

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPolygonFilter* RicNewPolygonFilterFeature::appendNewPolygonFilter( RimCase* sourceCase, RimCellFilterCollection* cellFilterCollection )
{
if ( !sourceCase || !cellFilterCollection )
{
return nullptr;
}

RimPolygonFilter* polygonFilter = cellFilterCollection->addNewPolygonFilter( sourceCase );
if ( polygonFilter )
{
auto polygon = RimPolygonTools::createNewPolygon();
polygonFilter->setPolygon( polygon );

RimPolygonTools::selectPolygonInView( polygon, polygonFilter );
return polygonFilter;
}

return nullptr;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewPolygonFilterFeature::onActionTriggered( bool isChecked )
{
// Find the selected Cell Filter Collection
std::vector<RimCellFilterCollection*> colls = caf::selectedObjectsByTypeStrict<RimCellFilterCollection*>();
if ( colls.empty() ) return;
RimCellFilterCollection* filtColl = colls[0];

// and the case to use
RimCase* sourceCase = filtColl->firstAncestorOrThisOfTypeAsserted<RimCase>();

RimPolygonFilter* lastCreatedOrUpdated = filtColl->addNewPolygonFilter( sourceCase );
if ( lastCreatedOrUpdated )
{
Riu3DMainWindowTools::selectAsCurrentItem( lastCreatedOrUpdated->polygonEditor() );
}
appendNewPolygonFilter( sourceCase, filtColl );
}

//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@

#include "cafCmdFeature.h"

class RimCellFilterCollection;
class RimCase;
class RimPolygonFilter;

//==================================================================================================
///
//==================================================================================================
class RicNewPolygonFilterFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;

public:
static RimPolygonFilter* appendNewPolygonFilter( RimCase* sourceCase, RimCellFilterCollection* cellFilterCollection );

protected:
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
Expand Down
19 changes: 11 additions & 8 deletions ApplicationLibCode/ModelVisualization/RivCellFilterPartMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ void RivCellFilterPartMgr::appendGeometryPartsToModel( cvf::ModelBasicList*
const caf::DisplayCoordTransform* displayCoordTransform,
const cvf::BoundingBox& boundingBox )
{
std::vector<RimCellFilterCollection*> colls = m_rimView->descendantsIncludingThisOfType<RimCellFilterCollection>();
return;
/*
std::vector<RimCellFilterCollection*> colls = m_rimView->descendantsIncludingThisOfType<RimCellFilterCollection>();
if ( colls.empty() ) return;
auto coll = colls.front();
if ( colls.empty() ) return;
auto coll = colls.front();
for ( auto filter : coll->filters() )
{
if ( auto polyFilter = dynamic_cast<RimPolygonFilter*>( filter ) )
for ( auto filter : coll->filters() )
{
polyFilter->appendPartsToModel( model, displayCoordTransform, boundingBox );
if ( auto polyFilter = dynamic_cast<RimPolygonFilter*>( filter ) )
{
polyFilter->appendPartsToModel( model, displayCoordTransform, boundingBox );
}
}
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ RimPolygonFilter* RimCellFilterCollection::addNewPolygonFilter( RimCase* srcCase
RimPolygonFilter* pFilter = new RimPolygonFilter();
pFilter->setCase( srcCase );
addFilter( pFilter );
pFilter->configurePolygonEditor();
pFilter->enablePicking( true );
onFilterUpdated( pFilter );
return pFilter;
}
Expand Down
109 changes: 20 additions & 89 deletions ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@

#include "Polygons/RimPolygon.h"
#include "Polygons/RimPolygonInView.h"
#include "Polygons/RimPolygonTools.h"

#include "RimEclipseCase.h"
#include "RimGeoMechCase.h"
#include "RimPolylineTarget.h"
#include "RimTools.h"

#include "Riu3DMainWindowTools.h"
Expand Down Expand Up @@ -76,22 +77,12 @@ RimPolygonFilter::RimPolygonFilter()

CAF_PDM_InitFieldNoDefault( &m_polyIncludeType, "PolyIncludeType", "Cells to include" );

CAF_PDM_InitFieldNoDefault( &m_internalPolygon, "InternalPolygon", "Polygon For Filter" );
m_internalPolygon = new RimPolygon;
m_internalPolygon->setName( "Polygon For Filter" );
m_internalPolygon->uiCapability()->setUiTreeHidden( true );

CAF_PDM_InitFieldNoDefault( &m_cellFilterPolygon, "Polygon", "Polygon" );
m_cellFilterPolygon = m_internalPolygon;

CAF_PDM_InitFieldNoDefault( &m_polygonEditor, "PolygonEditor", "Polygon Editor" );
m_polygonEditor = new RimPolygonInView;

CAF_PDM_InitField( &m_enableFiltering, "EnableFiltering", false, "Enable Filter" );

CAF_PDM_InitField( &m_enableKFilter, "EnableKFilter", false, "Enable K Range Filter" );
CAF_PDM_InitFieldNoDefault( &m_kFilterStr, "KRangeFilter", "K Range Filter", "", "Example: 2,4-6,10-20:2", "" );

CAF_PDM_InitFieldNoDefault( &m_cellFilterPolygon, "Polygon", "Polygon" );
CAF_PDM_InitField( &m_editPolygonButton, "EditPolygonButton", false, "Edit" );
m_editPolygonButton.uiCapability()->setUiEditorTypeName( caf::PdmUiPushButtonEditor::uiEditorTypeName() );
m_editPolygonButton.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
Expand All @@ -118,6 +109,15 @@ void RimPolygonFilter::enableKFilter( bool bEnable )
m_enableKFilter = bEnable;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonFilter::setPolygon( RimPolygon* polygon )
{
setPolygonAndConnectSignals( polygon );
updateCells();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -149,8 +149,6 @@ QString RimPolygonFilter::fullName() const
void RimPolygonFilter::initAfterRead()
{
RimCellFilter::initAfterRead();

configurePolygonEditor();
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -175,15 +173,11 @@ void RimPolygonFilter::defineUiOrdering( QString uiConfigName, caf::PdmUiOrderin
uiOrdering.add( &m_name );

auto group = uiOrdering.addNewGroup( "General" );
group->add( &m_cellFilterPolygon );
group->add( &m_editPolygonButton, { .newRow = false } );
group->add( &m_filterMode );
group->add( &m_enableFiltering );

uiOrdering.add( &m_cellFilterPolygon );
if ( m_cellFilterPolygon() != m_internalPolygon() )
{
uiOrdering.add( &m_editPolygonButton, { .newRow = false } );
}

auto group1 = uiOrdering.addNewGroup( "Polygon Selection" );
group1->add( &m_polyFilterMode );

Expand Down Expand Up @@ -221,23 +215,6 @@ void RimPolygonFilter::defineUiOrdering( QString uiConfigName, caf::PdmUiOrderin
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonFilter::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName /*= "" */ )
{
RimCellFilter::defineUiTreeOrdering( uiTreeOrdering, uiConfigName );

bool showPolygonEditor = ( m_cellFilterPolygon() == m_internalPolygon() );

if ( showPolygonEditor )
{
uiTreeOrdering.add( m_polygonEditor() );
}

uiTreeOrdering.skipRemainingChildren();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand All @@ -247,13 +224,6 @@ QList<caf::PdmOptionItemInfo> RimPolygonFilter::calculateValueOptions( const caf
if ( fieldNeedingOptions == &m_cellFilterPolygon )
{
RimTools::polygonOptionItems( &options );
if ( !options.empty() )
{
options.push_front( caf::PdmOptionItemInfo( "Project Polygons", nullptr ) );
}

options.push_front(
caf::PdmOptionItemInfo( m_internalPolygon()->name(), m_internalPolygon(), false, m_internalPolygon->uiIconProvider() ) );
}

return options;
Expand All @@ -266,7 +236,7 @@ void RimPolygonFilter::fieldChangedByUi( const caf::PdmFieldHandle* changedField
{
if ( changedField == &m_editPolygonButton )
{
if ( m_cellFilterPolygon() ) Riu3DMainWindowTools::selectAsCurrentItem( m_cellFilterPolygon() );
RimPolygonTools::selectPolygonInView( m_cellFilterPolygon(), this );

m_editPolygonButton = false;

Expand All @@ -275,7 +245,7 @@ void RimPolygonFilter::fieldChangedByUi( const caf::PdmFieldHandle* changedField

if ( changedField == &m_cellFilterPolygon )
{
configurePolygonEditor();
setPolygonAndConnectSignals( m_cellFilterPolygon() );
updateAllRequiredEditors();
}

Expand All @@ -287,15 +257,6 @@ void RimPolygonFilter::fieldChangedByUi( const caf::PdmFieldHandle* changedField
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonFilter::enablePicking( bool enable )
{
m_polygonEditor->enablePicking( enable );
updateConnectedEditors();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -698,9 +659,9 @@ void RimPolygonFilter::updateCells()
// get polyline as vector
std::vector<cvf::Vec3d> points;

for ( auto target : m_polygonEditor->activeTargets() )
if ( m_cellFilterPolygon() )
{
points.push_back( target->targetPointXYZ() );
points = m_cellFilterPolygon->pointsInDomainCoords();
}

// We need at least three points to make a closed polygon, or just 2 for a polyline
Expand All @@ -722,36 +683,6 @@ void RimPolygonFilter::updateCells()
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonFilter::configurePolygonEditor()
{
m_polygonEditor->setPolygon( m_cellFilterPolygon() );

// Must connect the signals after polygon is assigned to the polygon editor
// When assigning an object to a ptr field, all signals are disconnected
connectObjectSignals( m_cellFilterPolygon() );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonFilter::appendPartsToModel( cvf::ModelBasicList* model,
const caf::DisplayCoordTransform* scaleTransform,
const cvf::BoundingBox& boundingBox )
{
return m_polygonEditor->appendPartsToModel( model, scaleTransform, boundingBox );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPolygonInView* RimPolygonFilter::polygonEditor() const
{
return m_polygonEditor();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand All @@ -771,15 +702,15 @@ void RimPolygonFilter::initializeCellList()
//--------------------------------------------------------------------------------------------------
bool RimPolygonFilter::isPolygonClosed() const
{
if ( m_polygonEditor->polygon() ) return m_polygonEditor->polygon()->isClosed();
if ( m_cellFilterPolygon() ) return m_cellFilterPolygon->isClosed();

return false;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonFilter::connectObjectSignals( RimPolygon* polygon )
void RimPolygonFilter::setPolygonAndConnectSignals( RimPolygon* polygon )
{
if ( m_cellFilterPolygon() )
{
Expand Down
Loading

0 comments on commit 0aee8bb

Please sign in to comment.