diff --git a/ApplicationLibCode/Commands/CellFilterCommands/RicNewPolygonFilterFeature.cpp b/ApplicationLibCode/Commands/CellFilterCommands/RicNewPolygonFilterFeature.cpp index 274bda4898..7df414c23b 100644 --- a/ApplicationLibCode/Commands/CellFilterCommands/RicNewPolygonFilterFeature.cpp +++ b/ApplicationLibCode/Commands/CellFilterCommands/RicNewPolygonFilterFeature.cpp @@ -37,6 +37,14 @@ CAF_CMD_SOURCE_INIT( RicNewPolygonFilterFeature, "RicNewPolygonFilterFeature" ); +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicNewPolygonFilterFeature::RicNewPolygonFilterFeature() + : RicBasicPolygonFeature( true /*multiselect*/ ) +{ +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -50,7 +58,6 @@ void RicNewPolygonFilterFeature::onActionTriggered( bool isChecked ) } auto cellFilterCollection = caf::SelectionManager::instance()->selectedItemOfType(); - if ( !cellFilterCollection ) { RimGridView* activeView = RiaApplication::instance()->activeMainOrComparisonGridView(); @@ -59,31 +66,40 @@ void RicNewPolygonFilterFeature::onActionTriggered( bool isChecked ) cellFilterCollection = activeView->cellFilterCollection(); } } - if ( !cellFilterCollection ) return; - if ( !polygonDataSource ) - { - auto selectedPolygon = caf::SelectionManager::instance()->selectedItemOfType(); - if ( !selectedPolygon ) - { - if ( auto polygonInView = caf::SelectionManager::instance()->selectedItemOfType() ) - { - selectedPolygon = polygonInView->polygon(); - } - } + auto sourceCase = cellFilterCollection->firstAncestorOrThisOfTypeAsserted()->ownerCase(); + if ( !sourceCase ) return; - polygonDataSource = selectedPolygon; + std::vector polygons; + + if ( polygonDataSource ) + { + polygons.push_back( polygonDataSource ); + } + else + { + polygons = selectedPolygons(); } - auto sourceCase = cellFilterCollection->firstAncestorOrThisOfTypeAsserted()->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 ); + } } //-------------------------------------------------------------------------------------------------- @@ -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; +} diff --git a/ApplicationLibCode/Commands/CellFilterCommands/RicNewPolygonFilterFeature.h b/ApplicationLibCode/Commands/CellFilterCommands/RicNewPolygonFilterFeature.h index 570408e305..1f6726f345 100644 --- a/ApplicationLibCode/Commands/CellFilterCommands/RicNewPolygonFilterFeature.h +++ b/ApplicationLibCode/Commands/CellFilterCommands/RicNewPolygonFilterFeature.h @@ -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; }; diff --git a/ApplicationLibCode/Commands/CrossSectionCommands/RicNewPolygonIntersectionFeature.cpp b/ApplicationLibCode/Commands/CrossSectionCommands/RicNewPolygonIntersectionFeature.cpp index 3ee2f4e7a3..cb4e70c1d5 100644 --- a/ApplicationLibCode/Commands/CrossSectionCommands/RicNewPolygonIntersectionFeature.cpp +++ b/ApplicationLibCode/Commands/CrossSectionCommands/RicNewPolygonIntersectionFeature.cpp @@ -27,12 +27,22 @@ #include "Polygons/RimPolygon.h" #include "Polygons/RimPolygonInView.h" +#include "Riu3DMainWindowTools.h" + #include "cafSelectionManager.h" #include CAF_CMD_SOURCE_INIT( RicNewPolygonIntersectionFeature, "RicNewPolygonIntersectionFeature" ); +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicNewPolygonIntersectionFeature::RicNewPolygonIntersectionFeature() + : RicBasicPolygonFeature( true /*multiselect*/ ) +{ +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -44,18 +54,21 @@ void RicNewPolygonIntersectionFeature::onActionTriggered( bool isChecked ) auto collection = activeView->intersectionCollection(); if ( !collection ) return; - auto polygon = caf::SelectionManager::instance()->selectedItemOfType(); - if ( !polygon ) + auto polygons = selectedPolygons(); + + RimExtrudedCurveIntersection* lastItem = nullptr; + + for ( auto polygon : polygons ) { - if ( auto polygonInView = caf::SelectionManager::instance()->selectedItemOfType() ) - { - 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 ); + } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/Commands/CrossSectionCommands/RicNewPolygonIntersectionFeature.h b/ApplicationLibCode/Commands/CrossSectionCommands/RicNewPolygonIntersectionFeature.h index f06741ab06..efdb291c0f 100644 --- a/ApplicationLibCode/Commands/CrossSectionCommands/RicNewPolygonIntersectionFeature.h +++ b/ApplicationLibCode/Commands/CrossSectionCommands/RicNewPolygonIntersectionFeature.h @@ -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; diff --git a/ApplicationLibCode/Commands/PolygonCommands/CMakeLists_files.cmake b/ApplicationLibCode/Commands/PolygonCommands/CMakeLists_files.cmake index c4afbccf2d..f9f047dd19 100644 --- a/ApplicationLibCode/Commands/PolygonCommands/CMakeLists_files.cmake +++ b/ApplicationLibCode/Commands/PolygonCommands/CMakeLists_files.cmake @@ -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 @@ -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}) diff --git a/ApplicationLibCode/Commands/PolygonCommands/RicBasicPolygonFeature.cpp b/ApplicationLibCode/Commands/PolygonCommands/RicBasicPolygonFeature.cpp new file mode 100644 index 0000000000..7041ab04eb --- /dev/null +++ b/ApplicationLibCode/Commands/PolygonCommands/RicBasicPolygonFeature.cpp @@ -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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicBasicPolygonFeature.h" + +#include "Polygons/RimPolygon.h" +#include "Polygons/RimPolygonInView.h" + +#include "cafSelectionManager.h" +#include "cafSelectionManagerTools.h" + +#include + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +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 RicBasicPolygonFeature::selectedPolygons() const +{ + std::set uniquePolygons; + + auto polygons = caf::selectedObjectsByType(); + auto polygonivs = caf::selectedObjectsByType(); + for ( auto piv : polygonivs ) + { + polygons.push_back( piv->polygon() ); + } + + // make sure we avoid duplicates + for ( auto p : polygons ) + { + uniquePolygons.insert( p ); + } + + std::vector returnPolygons; + for ( auto p : uniquePolygons ) + { + returnPolygons.push_back( p ); + } + + return returnPolygons; +} diff --git a/ApplicationLibCode/Commands/PolygonCommands/RicBasicPolygonFeature.h b/ApplicationLibCode/Commands/PolygonCommands/RicBasicPolygonFeature.h new file mode 100644 index 0000000000..a8f62e1fb9 --- /dev/null +++ b/ApplicationLibCode/Commands/PolygonCommands/RicBasicPolygonFeature.h @@ -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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" + +#include + +class RimPolygon; + +//================================================================================================== +/// +//================================================================================================== +class RicBasicPolygonFeature : public caf::CmdFeature +{ +public: + RicBasicPolygonFeature( bool multiSelectSupported ); + +protected: + std::vector selectedPolygons() const; + bool isCommandEnabled() const override; + +private: + bool m_multiSelectSupported; +}; diff --git a/ApplicationLibCode/Commands/PolygonCommands/RicDuplicatePolygonFeature.cpp b/ApplicationLibCode/Commands/PolygonCommands/RicDuplicatePolygonFeature.cpp index 7c0101dd7e..8da3c923f7 100644 --- a/ApplicationLibCode/Commands/PolygonCommands/RicDuplicatePolygonFeature.cpp +++ b/ApplicationLibCode/Commands/PolygonCommands/RicDuplicatePolygonFeature.cpp @@ -31,26 +31,29 @@ #include "Riu3DMainWindowTools.h" #include "cafSelectionManager.h" +#include "cafSelectionManagerTools.h" + #include CAF_CMD_SOURCE_INIT( RicDuplicatePolygonFeature, "RicDuplicatePolygonFeature" ); +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicDuplicatePolygonFeature::RicDuplicatePolygonFeature() + : RicBasicPolygonFeature( false /*multiselect*/ ) +{ +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicDuplicatePolygonFeature::onActionTriggered( bool isChecked ) { - auto sourcePolygon = caf::SelectionManager::instance()->selectedItemOfType(); - if ( !sourcePolygon ) - { - auto sourcePolygonInView = caf::SelectionManager::instance()->selectedItemOfType(); - 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(); diff --git a/ApplicationLibCode/Commands/PolygonCommands/RicDuplicatePolygonFeature.h b/ApplicationLibCode/Commands/PolygonCommands/RicDuplicatePolygonFeature.h index a54a5975fa..67c7e5672b 100644 --- a/ApplicationLibCode/Commands/PolygonCommands/RicDuplicatePolygonFeature.h +++ b/ApplicationLibCode/Commands/PolygonCommands/RicDuplicatePolygonFeature.h @@ -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; diff --git a/ApplicationLibCode/Commands/PolygonCommands/RicExportPolygonCsvFeature.cpp b/ApplicationLibCode/Commands/PolygonCommands/RicExportPolygonCsvFeature.cpp index 64e05b7942..2825762480 100644 --- a/ApplicationLibCode/Commands/PolygonCommands/RicExportPolygonCsvFeature.cpp +++ b/ApplicationLibCode/Commands/PolygonCommands/RicExportPolygonCsvFeature.cpp @@ -27,29 +27,28 @@ #include "RiuFileDialogTools.h" -#include "cafSelectionManager.h" - #include #include CAF_CMD_SOURCE_INIT( RicExportPolygonCsvFeature, "RicExportPolygonCsvFeature" ); +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicExportPolygonCsvFeature::RicExportPolygonCsvFeature() + : RicBasicPolygonFeature( false /*multiselect*/ ) +{ +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicExportPolygonCsvFeature::onActionTriggered( bool isChecked ) { - auto sourcePolygon = caf::SelectionManager::instance()->selectedItemOfType(); - if ( !sourcePolygon ) - { - auto sourcePolygonInView = caf::SelectionManager::instance()->selectedItemOfType(); - if ( sourcePolygonInView ) - { - sourcePolygon = sourcePolygonInView->polygon(); - } - } + auto selPolygons = selectedPolygons(); + if ( selPolygons.empty() ) return; - if ( !sourcePolygon ) return; + auto sourcePolygon = selPolygons[0]; auto app = RiaGuiApplication::instance(); auto fallbackPath = app->lastUsedDialogDirectory( "BINARY_GRID" ); diff --git a/ApplicationLibCode/Commands/PolygonCommands/RicExportPolygonCsvFeature.h b/ApplicationLibCode/Commands/PolygonCommands/RicExportPolygonCsvFeature.h index 844b87248a..4c419081d2 100644 --- a/ApplicationLibCode/Commands/PolygonCommands/RicExportPolygonCsvFeature.h +++ b/ApplicationLibCode/Commands/PolygonCommands/RicExportPolygonCsvFeature.h @@ -18,15 +18,18 @@ #pragma once -#include "cafCmdFeature.h" +#include "RicBasicPolygonFeature.h" //================================================================================================== /// //================================================================================================== -class RicExportPolygonCsvFeature : public caf::CmdFeature +class RicExportPolygonCsvFeature : public RicBasicPolygonFeature { CAF_CMD_HEADER_INIT; +public: + RicExportPolygonCsvFeature(); + protected: void onActionTriggered( bool isChecked ) override; void setupActionLook( QAction* actionToSetup ) override; diff --git a/ApplicationLibCode/Commands/PolygonCommands/RicExportPolygonPolFeature.cpp b/ApplicationLibCode/Commands/PolygonCommands/RicExportPolygonPolFeature.cpp index cfdf1839f4..8ee80d7fe0 100644 --- a/ApplicationLibCode/Commands/PolygonCommands/RicExportPolygonPolFeature.cpp +++ b/ApplicationLibCode/Commands/PolygonCommands/RicExportPolygonPolFeature.cpp @@ -37,33 +37,32 @@ CAF_CMD_SOURCE_INIT( RicExportPolygonPolFeature, "RicExportPolygonPolFeature" ); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicExportPolygonPolFeature::onActionTriggered( bool isChecked ) +RicExportPolygonPolFeature::RicExportPolygonPolFeature() + : RicBasicPolygonFeature( true /*multiselect*/ ) { - auto sourcePolygon = caf::SelectionManager::instance()->selectedItemOfType(); - if ( !sourcePolygon ) - { - auto sourcePolygonInView = caf::SelectionManager::instance()->selectedItemOfType(); - if ( sourcePolygonInView ) - { - sourcePolygon = sourcePolygonInView->polygon(); - } - } +} - if ( !sourcePolygon ) return; +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicExportPolygonPolFeature::onActionTriggered( bool isChecked ) +{ + auto selPolygons = selectedPolygons(); + if ( selPolygons.empty() ) return; auto app = RiaGuiApplication::instance(); auto fallbackPath = app->lastUsedDialogDirectory( "BINARY_GRID" ); auto polygonPath = app->lastUsedDialogDirectoryWithFallback( RimPolygonTools::polygonCacheName(), fallbackPath ); - auto polygonFileName = polygonPath + "/" + sourcePolygon->name() + ".pol"; + auto polygonFileName = polygonPath + "/" + selPolygons[0]->name() + ".pol"; auto fileName = RiuFileDialogTools::getSaveFileName( nullptr, "Select File for Polygon Export to POL", polygonFileName, "POL Files (*.pol);;All files(*.*)" ); - if ( !RimPolygonTools::exportPolygonPol( sourcePolygon, fileName ) ) + if ( !RimPolygonTools::exportPolygonPol( selPolygons, fileName ) ) { - RiaLogging::error( "Failed to export polygon to " + fileName ); + RiaLogging::error( "Failed to export polygon(s) to " + fileName ); } else { diff --git a/ApplicationLibCode/Commands/PolygonCommands/RicExportPolygonPolFeature.h b/ApplicationLibCode/Commands/PolygonCommands/RicExportPolygonPolFeature.h index 66f3a7babb..5d943c22f5 100644 --- a/ApplicationLibCode/Commands/PolygonCommands/RicExportPolygonPolFeature.h +++ b/ApplicationLibCode/Commands/PolygonCommands/RicExportPolygonPolFeature.h @@ -18,15 +18,18 @@ #pragma once -#include "cafCmdFeature.h" +#include "RicBasicPolygonFeature.h" //================================================================================================== /// //================================================================================================== -class RicExportPolygonPolFeature : public caf::CmdFeature +class RicExportPolygonPolFeature : public RicBasicPolygonFeature { CAF_CMD_HEADER_INIT; +public: + RicExportPolygonPolFeature(); + protected: void onActionTriggered( bool isChecked ) override; void setupActionLook( QAction* actionToSetup ) override; diff --git a/ApplicationLibCode/Commands/PolygonCommands/RicReloadPolygonFileFeature.cpp b/ApplicationLibCode/Commands/PolygonCommands/RicReloadPolygonFileFeature.cpp index b3bb1ff89c..83a8d71f91 100644 --- a/ApplicationLibCode/Commands/PolygonCommands/RicReloadPolygonFileFeature.cpp +++ b/ApplicationLibCode/Commands/PolygonCommands/RicReloadPolygonFileFeature.cpp @@ -21,6 +21,7 @@ #include "Polygons/RimPolygonFile.h" #include "cafSelectionManager.h" +#include "cafSelectionManagerTools.h" #include @@ -31,13 +32,13 @@ CAF_CMD_SOURCE_INIT( RicReloadPolygonFileFeature, "RicReloadPolygonFileFeature" //-------------------------------------------------------------------------------------------------- void RicReloadPolygonFileFeature::onActionTriggered( bool isChecked ) { - auto polygonFile = caf::SelectionManager::instance()->selectedItemOfType(); - if ( polygonFile ) - { - polygonFile->loadData(); - polygonFile->objectChanged.send(); + auto polygonFiles = caf::selectedObjectsByType(); - polygonFile->updateConnectedEditors(); + for ( auto p : polygonFiles ) + { + p->loadData(); + p->objectChanged.send(); + p->updateConnectedEditors(); } } diff --git a/ApplicationLibCode/Commands/PolygonCommands/RicSimplifyPolygonFeature.cpp b/ApplicationLibCode/Commands/PolygonCommands/RicSimplifyPolygonFeature.cpp index d8695176fc..786afdd797 100644 --- a/ApplicationLibCode/Commands/PolygonCommands/RicSimplifyPolygonFeature.cpp +++ b/ApplicationLibCode/Commands/PolygonCommands/RicSimplifyPolygonFeature.cpp @@ -33,19 +33,18 @@ CAF_CMD_SOURCE_INIT( RicSimplifyPolygonFeature, "RicSimplifyPolygonFeature" ); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicSimplifyPolygonFeature::onActionTriggered( bool isChecked ) +RicSimplifyPolygonFeature::RicSimplifyPolygonFeature() + : RicBasicPolygonFeature( true /*multiselect*/ ) { - auto sourcePolygon = caf::SelectionManager::instance()->selectedItemOfType(); - if ( !sourcePolygon ) - { - auto sourcePolygonInView = caf::SelectionManager::instance()->selectedItemOfType(); - if ( sourcePolygonInView ) - { - sourcePolygon = sourcePolygonInView->polygon(); - } - } +} - if ( !sourcePolygon ) return; +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSimplifyPolygonFeature::onActionTriggered( bool isChecked ) +{ + auto selPolygons = selectedPolygons(); + if ( selPolygons.empty() ) return; const double defaultEpsilon = 10.0; @@ -53,7 +52,9 @@ void RicSimplifyPolygonFeature::onActionTriggered( bool isChecked ) auto epsilon = QInputDialog::getDouble( nullptr, "Simplify Polygon Threshold", "Threshold:", defaultEpsilon, 1.0, 1000.0, 1, &ok, Qt::WindowFlags(), 1 ); - if ( ok ) + if ( !ok ) return; + + for ( auto sourcePolygon : selPolygons ) { auto coords = sourcePolygon->pointsInDomainCoords(); RigCellGeometryTools::simplifyPolygon( &coords, epsilon ); diff --git a/ApplicationLibCode/Commands/PolygonCommands/RicSimplifyPolygonFeature.h b/ApplicationLibCode/Commands/PolygonCommands/RicSimplifyPolygonFeature.h index 1b74d5876c..61aedf45c9 100644 --- a/ApplicationLibCode/Commands/PolygonCommands/RicSimplifyPolygonFeature.h +++ b/ApplicationLibCode/Commands/PolygonCommands/RicSimplifyPolygonFeature.h @@ -18,15 +18,18 @@ #pragma once -#include "cafCmdFeature.h" +#include "RicBasicPolygonFeature.h" //================================================================================================== /// //================================================================================================== -class RicSimplifyPolygonFeature : public caf::CmdFeature +class RicSimplifyPolygonFeature : public RicBasicPolygonFeature { CAF_CMD_HEADER_INIT; +public: + RicSimplifyPolygonFeature(); + protected: void onActionTriggered( bool isChecked ) override; void setupActionLook( QAction* actionToSetup ) override; diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonFile.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonFile.cpp index 105af7ea7d..5ef49eb097 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonFile.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonFile.cpp @@ -37,7 +37,7 @@ CAF_PDM_SOURCE_INIT( RimPolygonFile, "RimPolygonFileFile" ); RimPolygonFile::RimPolygonFile() : objectChanged( this ) { - CAF_PDM_InitObject( "PolygonFile", ":/PolylinesFromFile16x16.png" ); + CAF_PDM_InitObject( "PolygonFile", ":/Folder.png" ); CAF_PDM_InitFieldNoDefault( &m_fileName, "StimPlanFileName", "File Name" ); CAF_PDM_InitFieldNoDefault( &m_polygons, "Polygons", "Polygons" ); diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.cpp index 11d2d49425..22a4822d2c 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.cpp @@ -103,9 +103,9 @@ bool RimPolygonTools::exportPolygonCsv( const RimPolygon* polygon, const QString //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RimPolygonTools::exportPolygonPol( const RimPolygon* polygon, const QString& filePath ) +bool RimPolygonTools::exportPolygonPol( const std::vector polygons, const QString& filePath ) { - if ( !polygon ) return false; + if ( polygons.empty() ) return false; QFile file( filePath ); if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) ) return false; @@ -122,20 +122,23 @@ bool RimPolygonTools::exportPolygonPol( const RimPolygon* polygon, const QString header.emplace_back( " ", RifTextDataTableDoubleFormatting( RIF_FLOAT, precision ) ); formatter.header( header ); - for ( const auto& point : polygon->pointsInDomainCoords() ) + for ( auto polygon : polygons ) { - formatter.add( point.x() ); - formatter.add( point.y() ); - formatter.add( -point.z() ); + for ( const auto& point : polygon->pointsInDomainCoords() ) + { + formatter.add( point.x() ); + formatter.add( point.y() ); + formatter.add( -point.z() ); + formatter.rowCompleted(); + } + + const double endOfPolygon = 999.0; + formatter.add( endOfPolygon ); + formatter.add( endOfPolygon ); + formatter.add( endOfPolygon ); formatter.rowCompleted(); } - const double endOfPolygon = 999.0; - formatter.add( endOfPolygon ); - formatter.add( endOfPolygon ); - formatter.add( endOfPolygon ); - formatter.rowCompleted(); - formatter.tableCompleted(); file.close(); diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.h b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.h index 29fb32b401..309f3dcc22 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.h +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.h @@ -23,6 +23,8 @@ class RimPolygonInView; class QString; +#include + namespace caf { class PdmObject; @@ -34,7 +36,7 @@ class RimPolygonTools static void activate3dEditOfPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject ); static void selectPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject ); static bool exportPolygonCsv( const RimPolygon* polygon, const QString& filePath ); - static bool exportPolygonPol( const RimPolygon* polygon, const QString& filePath ); + static bool exportPolygonPol( const std::vector polygons, const QString& filePath ); static QString polygonCacheName();