Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polygon command updates #11952

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@

CAF_CMD_SOURCE_INIT( RicNewPolygonFilterFeature, "RicNewPolygonFilterFeature" );

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicNewPolygonFilterFeature::RicNewPolygonFilterFeature()
: RicBasicPolygonFeature( true /*multiselect*/ )
{
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand All @@ -50,7 +58,6 @@ void RicNewPolygonFilterFeature::onActionTriggered( bool isChecked )
}

auto cellFilterCollection = caf::SelectionManager::instance()->selectedItemOfType<RimCellFilterCollection>();

if ( !cellFilterCollection )
{
RimGridView* activeView = RiaApplication::instance()->activeMainOrComparisonGridView();
Expand All @@ -59,31 +66,40 @@ void RicNewPolygonFilterFeature::onActionTriggered( bool isChecked )
cellFilterCollection = activeView->cellFilterCollection();
}
}

if ( !cellFilterCollection ) return;

if ( !polygonDataSource )
{
auto selectedPolygon = caf::SelectionManager::instance()->selectedItemOfType<RimPolygon>();
if ( !selectedPolygon )
{
if ( auto polygonInView = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonInView>() )
{
selectedPolygon = polygonInView->polygon();
}
}
auto sourceCase = cellFilterCollection->firstAncestorOrThisOfTypeAsserted<Rim3dView>()->ownerCase();
if ( !sourceCase ) return;

polygonDataSource = selectedPolygon;
std::vector<RimPolygon*> polygons;

if ( polygonDataSource )
{
polygons.push_back( polygonDataSource );
}
else
{
polygons = selectedPolygons();
}

auto sourceCase = cellFilterCollection->firstAncestorOrThisOfTypeAsserted<Rim3dView>()->ownerCase();
if ( sourceCase )
RimPolygonFilter* lastItem = nullptr;

if ( polygons.empty() )
{
if ( auto lastCreatedOrUpdated = cellFilterCollection->addNewPolygonFilter( sourceCase, polygonDataSource ) )
lastItem = cellFilterCollection->addNewPolygonFilter( sourceCase, nullptr );
}
else
{
for ( auto polygon : polygons )
{
Riu3DMainWindowTools::selectAsCurrentItem( lastCreatedOrUpdated );
lastItem = cellFilterCollection->addNewPolygonFilter( sourceCase, polygon );
}
}

if ( lastItem )
{
Riu3DMainWindowTools::selectAsCurrentItem( lastItem );
}
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -94,3 +110,11 @@ void RicNewPolygonFilterFeature::setupActionLook( QAction* actionToSetup )
actionToSetup->setIcon( QIcon( ":/CellFilter_Polygon.png" ) );
actionToSetup->setText( "User Defined Polygon Filter" );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicNewPolygonFilterFeature::isCommandEnabled() const
{
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@

#pragma once

#include "cafCmdFeature.h"
#include "PolygonCommands/RicBasicPolygonFeature.h"

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

public:
RicNewPolygonFilterFeature();

protected:
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
bool isCommandEnabled() const override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,22 @@
#include "Polygons/RimPolygon.h"
#include "Polygons/RimPolygonInView.h"

#include "Riu3DMainWindowTools.h"

#include "cafSelectionManager.h"

#include <QAction>

CAF_CMD_SOURCE_INIT( RicNewPolygonIntersectionFeature, "RicNewPolygonIntersectionFeature" );

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicNewPolygonIntersectionFeature::RicNewPolygonIntersectionFeature()
: RicBasicPolygonFeature( true /*multiselect*/ )
{
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand All @@ -44,18 +54,21 @@ void RicNewPolygonIntersectionFeature::onActionTriggered( bool isChecked )
auto collection = activeView->intersectionCollection();
if ( !collection ) return;

auto polygon = caf::SelectionManager::instance()->selectedItemOfType<RimPolygon>();
if ( !polygon )
auto polygons = selectedPolygons();

RimExtrudedCurveIntersection* lastItem = nullptr;

for ( auto polygon : polygons )
{
if ( auto polygonInView = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonInView>() )
{
polygon = polygonInView->polygon();
}
auto intersection = new RimExtrudedCurveIntersection();
intersection->configureForProjectPolyLine( polygon );
collection->appendIntersectionAndUpdate( intersection );
}

auto intersection = new RimExtrudedCurveIntersection();
intersection->configureForProjectPolyLine( polygon );
collection->appendIntersectionAndUpdate( intersection );
if ( lastItem != nullptr )
{
Riu3DMainWindowTools::selectAsCurrentItem( lastItem );
}
}

//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@

#pragma once

#include "cafCmdFeature.h"
#include "PolygonCommands/RicBasicPolygonFeature.h"

//==================================================================================================
///
//==================================================================================================
class RicNewPolygonIntersectionFeature : public caf::CmdFeature
class RicNewPolygonIntersectionFeature : public RicBasicPolygonFeature
{
CAF_CMD_HEADER_INIT;

public:
RicNewPolygonIntersectionFeature();

protected:
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonCsvFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonPolFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicSimplifyPolygonFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicBasicPolygonFeature.h
)

set(SOURCE_GROUP_SOURCE_FILES
Expand All @@ -16,6 +17,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonCsvFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonPolFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSimplifyPolygonFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicBasicPolygonFeature.cpp
)

list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////

#include "RicBasicPolygonFeature.h"

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

#include "cafSelectionManager.h"
#include "cafSelectionManagerTools.h"

#include <set>

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicBasicPolygonFeature::RicBasicPolygonFeature( bool multiSelectSupported )
: m_multiSelectSupported( multiSelectSupported )
{
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicBasicPolygonFeature::isCommandEnabled() const
{
auto polygons = selectedPolygons();

return m_multiSelectSupported ? polygons.size() > 0 : polygons.size() == 1;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimPolygon*> RicBasicPolygonFeature::selectedPolygons() const
{
std::set<RimPolygon*> uniquePolygons;

auto polygons = caf::selectedObjectsByType<RimPolygon*>();
auto polygonivs = caf::selectedObjectsByType<RimPolygonInView*>();
for ( auto piv : polygonivs )
{
polygons.push_back( piv->polygon() );
}

// make sure we avoid duplicates
for ( auto p : polygons )
{
uniquePolygons.insert( p );
}

std::vector<RimPolygon*> returnPolygons;
for ( auto p : uniquePolygons )
{
returnPolygons.push_back( p );
}

return returnPolygons;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "cafCmdFeature.h"

#include <vector>

class RimPolygon;

//==================================================================================================
///
//==================================================================================================
class RicBasicPolygonFeature : public caf::CmdFeature
{
public:
RicBasicPolygonFeature( bool multiSelectSupported );

protected:
std::vector<RimPolygon*> selectedPolygons() const;
bool isCommandEnabled() const override;

private:
bool m_multiSelectSupported;
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,29 @@
#include "Riu3DMainWindowTools.h"

#include "cafSelectionManager.h"
#include "cafSelectionManagerTools.h"

#include <QAction>

CAF_CMD_SOURCE_INIT( RicDuplicatePolygonFeature, "RicDuplicatePolygonFeature" );

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicDuplicatePolygonFeature::RicDuplicatePolygonFeature()
: RicBasicPolygonFeature( false /*multiselect*/ )
{
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicDuplicatePolygonFeature::onActionTriggered( bool isChecked )
{
auto sourcePolygon = caf::SelectionManager::instance()->selectedItemOfType<RimPolygon>();
if ( !sourcePolygon )
{
auto sourcePolygonInView = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonInView>();
if ( sourcePolygonInView )
{
sourcePolygon = sourcePolygonInView->polygon();
}
}

if ( !sourcePolygon ) return;
auto selPolygons = selectedPolygons();
if ( selPolygons.empty() ) return;

auto sourcePolygon = selPolygons[0];

auto proj = RimProject::current();
auto polygonCollection = proj->activeOilField()->polygonCollection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@

#pragma once

#include "cafCmdFeature.h"
#include "RicBasicPolygonFeature.h"

//==================================================================================================
///
//==================================================================================================
class RicDuplicatePolygonFeature : public caf::CmdFeature
class RicDuplicatePolygonFeature : public RicBasicPolygonFeature
{
CAF_CMD_HEADER_INIT;

public:
RicDuplicatePolygonFeature();

protected:
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
Expand Down
Loading
Loading