Skip to content

Commit

Permalink
Propagate existing polygon targets to polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Feb 20, 2024
1 parent 8152ade commit ee8743f
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "RicNewPolygonFilterFeature.h"

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

Expand Down Expand Up @@ -48,6 +49,7 @@ RimPolygonFilter* RicNewPolygonFilterFeature::appendNewPolygonFilter( RimCase* s
if ( polygonFilter )
{
auto polygon = RimPolygonTools::createNewPolygon();
polygon->setIsClosed( true );
polygonFilter->setPolygon( polygon );

RimPolygonTools::selectPolygonInView( polygon, polygonFilter );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

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

#include "Riu3DMainWindowTools.h"
Expand Down Expand Up @@ -87,6 +88,16 @@ RimPolygonFilter::RimPolygonFilter()
m_editPolygonButton.uiCapability()->setUiEditorTypeName( caf::PdmUiPushButtonEditor::uiEditorTypeName() );
m_editPolygonButton.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );

CAF_PDM_InitFieldNoDefault( &m_targets, "Targets", "Targets" );
m_targets.uiCapability()->setUiTreeChildrenHidden( true );
m_targets.uiCapability()->setUiTreeHidden( true );
m_targets.uiCapability()->setUiHidden( true );
m_targets.xmlCapability()->setIOWritable( false );

CAF_PDM_InitFieldNoDefault( &m_closePolygon, "ClosePolygon", "Closed Polygon" );
m_closePolygon.registerGetMethod( this, &RimPolygonFilter::isPolygonClosed );
m_closePolygon.registerSetMethod( this, &RimPolygonFilter::setIsPolygonClosed );

m_propagateToSubGrids = false;

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

// Move existing polygons to global polygon
if ( !m_targets.empty() )
{
std::vector<cvf::Vec3d> points;
for ( const auto& target : m_targets )
{
points.push_back( target->targetPointXYZ() );
}

auto polygon = RimPolygonTools::createNewPolygon();
polygon->setPointsInDomainCoords( points );

polygon->setIsClosed( true );

setPolygonAndConnectSignals( polygon );

auto polygonInView = RimPolygonTools::findPolygonInView( polygon, this );
if ( polygonInView )
{
polygonInView->setPolygon( polygon );
}
}
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -177,6 +211,7 @@ void RimPolygonFilter::defineUiOrdering( QString uiConfigName, caf::PdmUiOrderin
group->add( &m_editPolygonButton, { .newRow = false } );
group->add( &m_filterMode );
group->add( &m_enableFiltering );
group->add( &m_closePolygon );

auto group1 = uiOrdering.addNewGroup( "Polygon Selection" );
group1->add( &m_polyFilterMode );
Expand Down Expand Up @@ -707,6 +742,17 @@ bool RimPolygonFilter::isPolygonClosed() const
return false;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonFilter::setIsPolygonClosed( const bool& isClosed )
{
if ( m_cellFilterPolygon() )
{
m_cellFilterPolygon->setIsClosed( isClosed );
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class RimPolygon;
class RigGridBase;
class RigFemPartGrid;
class RigEclipseCaseData;
class RimPolylineTarget;

namespace cvf
{
Expand Down Expand Up @@ -101,6 +102,7 @@ class RimPolygonFilter : public RimCellFilter
void initializeCellList();

bool isPolygonClosed() const;
void setIsPolygonClosed( const bool& isClosed );

void setPolygonAndConnectSignals( RimPolygon* polygon );
void onObjectChanged( const caf::SignalEmitter* emitter );
Expand All @@ -118,4 +120,7 @@ class RimPolygonFilter : public RimCellFilter
std::vector<std::vector<size_t>> m_cells;

RimCellFilterIntervalTool m_intervalTool;

caf::PdmChildArrayField<RimPolylineTarget*> m_targets;
caf::PdmProxyValueField<bool> m_closePolygon;
};
9 changes: 9 additions & 0 deletions ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ std::vector<cvf::Vec3d> RimPolygon::pointsInDomainCoords() const
return m_pointsInDomainCoords();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygon::setIsClosed( bool isClosed )
{
m_appearance->setIsClosed( isClosed );
objectChanged.send();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class RimPolygon : public RimNamedObject, public RimPolylinesDataInterface

void setPointsInDomainCoords( const std::vector<cvf::Vec3d>& points );
std::vector<cvf::Vec3d> pointsInDomainCoords() const;
bool isClosed() const;

void setIsClosed( bool isClosed );
bool isClosed() const;

cvf::ref<RigPolyLinesData> polyLinesData() const override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ void RimPolygonAppearance::applyAppearanceSettings( RigPolyLinesData* polyLinesD
polyLinesData->setVisibility( m_showLines, m_showSpheres );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonAppearance::setIsClosed( bool isClosed )
{
m_isClosed = isClosed;
objectChanged.send();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class RimPolygonAppearance : public caf::PdmObject

void applyAppearanceSettings( RigPolyLinesData* polyLinesData );

void setIsClosed( bool isClosed );
bool isClosed() const;

public:
Expand Down
38 changes: 25 additions & 13 deletions ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,11 @@
//--------------------------------------------------------------------------------------------------
void RimPolygonTools::selectPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject )
{
if ( auto gridView = sourceObject->firstAncestorOfType<RimGridView>() )
auto polygonInView = findPolygonInView( polygon, sourceObject );
if ( polygonInView )
{
auto polyCollection = gridView->polygonInViewCollection();

for ( auto polygonInView : polyCollection->polygonsInView() )
{
if ( polygonInView && polygonInView->polygon() == polygon )
{
polygonInView->enablePicking( true );
Riu3DMainWindowTools::selectAsCurrentItem( polygonInView );

return;
}
}
polygonInView->enablePicking( true );
Riu3DMainWindowTools::selectAsCurrentItem( polygonInView );
}
}

Expand All @@ -63,3 +54,24 @@ RimPolygon* RimPolygonTools::createNewPolygon()

return newPolygon;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPolygonInView* RimPolygonTools::findPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject )
{
if ( auto gridView = sourceObject->firstAncestorOfType<RimGridView>() )
{
auto polyCollection = gridView->polygonInViewCollection();

for ( auto polygonInView : polyCollection->polygonsInView() )
{
if ( polygonInView && polygonInView->polygon() == polygon )
{
return polygonInView;
}
}
}

return nullptr;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

class RimPolygon;
class RimPolygonInView;

namespace caf
{
Expand All @@ -28,6 +29,7 @@ class PdmObject;
class RimPolygonTools
{
public:
static void selectPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject );
static RimPolygon* createNewPolygon();
static void selectPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject );
static RimPolygon* createNewPolygon();
static RimPolygonInView* findPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject );
};

0 comments on commit ee8743f

Please sign in to comment.