From e82a58a12ed62ce9a88b4a48c926c836ab9b4d48 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Wed, 12 Jul 2023 22:25:15 +0100 Subject: [PATCH] Changed: Allow filling/unfilling individual zones with no selection The draft fill and single zone unfill would only work if something was selected first, this allows them to call the selection operation to request what is under the cursor. Also properly gate the operation to not cause crashes/issues when the selection contains non-zone items. --- pcbnew/pcb_edit_frame.cpp | 2 -- pcbnew/tools/pcb_actions.cpp | 12 +++++---- pcbnew/tools/zone_filler_tool.cpp | 45 +++++++++++++++++++++++++------ 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 48b987feea..b7167332b1 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -921,8 +921,6 @@ void PCB_EDIT_FRAME::setupUIConditions() mgr->SetConditions( PCB_ACTIONS::drawZoneCutout, ENABLE( singleZoneCond ) ); mgr->SetConditions( PCB_ACTIONS::drawSimilarZone, ENABLE( singleZoneCond ) ); mgr->SetConditions( PCB_ACTIONS::zoneMerge, ENABLE( zoneMergeCond ) ); - mgr->SetConditions( PCB_ACTIONS::zoneFill, ENABLE( SELECTION_CONDITIONS::MoreThan( 0 ) ) ); - mgr->SetConditions( PCB_ACTIONS::zoneUnfill, ENABLE( SELECTION_CONDITIONS::MoreThan( 0 ) ) ); mgr->SetConditions( PCB_ACTIONS::toggleHV45Mode, CHECK( cond.Get45degMode() ) ); diff --git a/pcbnew/tools/pcb_actions.cpp b/pcbnew/tools/pcb_actions.cpp index e87f1d0a37..72910b8163 100644 --- a/pcbnew/tools/pcb_actions.cpp +++ b/pcbnew/tools/pcb_actions.cpp @@ -1635,11 +1635,13 @@ TOOL_ACTION PCB_ACTIONS::filterSelection( "pcbnew.InteractiveSelection.FilterSel // ZONE_FILLER_TOOL // -TOOL_ACTION PCB_ACTIONS::zoneFill( "pcbnew.ZoneFiller.zoneFill", - AS_GLOBAL, 0, "", - _( "Draft Fill Selected Zone(s)" ), - _( "Update copper fill of selected zone(s) without regard to other interacting zones" ), - BITMAPS::fill_zone ); +TOOL_ACTION PCB_ACTIONS::zoneFill( TOOL_ACTION_ARGS() + .Name( "pcbnew.ZoneFiller.zoneFill" ) + .Scope( AS_GLOBAL ) + .MenuText( _( "Draft Fill Selected Zone(s)" ) ) + .Tooltip( _( "Update copper fill of selected zone(s) without regard to other interacting zones" ) ) + .Icon( BITMAPS::fill_zone ) + .Parameter( nullptr ) ); TOOL_ACTION PCB_ACTIONS::zoneFillAll( "pcbnew.ZoneFiller.zoneFillAll", AS_GLOBAL, diff --git a/pcbnew/tools/zone_filler_tool.cpp b/pcbnew/tools/zone_filler_tool.cpp index 1a0637f01a..c8b1d5a1b6 100644 --- a/pcbnew/tools/zone_filler_tool.cpp +++ b/pcbnew/tools/zone_filler_tool.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include "pcb_actions.h" #include "zone_filler_tool.h" #include "zone_filler.h" @@ -309,8 +310,6 @@ int ZONE_FILLER_TOOL::ZoneFill( const TOOL_EVENT& aEvent ) return -1; } - m_fillInProgress = true; - std::vector toFill; if( ZONE* passedZone = aEvent.Parameter() ) @@ -319,13 +318,27 @@ int ZONE_FILLER_TOOL::ZoneFill( const TOOL_EVENT& aEvent ) } else { - for( EDA_ITEM* item : selection() ) + const PCB_SELECTION& sel = m_toolMgr->GetTool()->RequestSelection( + []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool ) + { + } ); + + for( EDA_ITEM* item : sel ) { if( ZONE* zone = dynamic_cast( item ) ) toFill.push_back( zone ); } } + // Bail out of the filler if there is nothing to fill + if( toFill.empty() ) + { + wxBell(); + return -1; + } + + m_fillInProgress = true; + BOARD_COMMIT commit( this ); std::unique_ptr reporter; @@ -362,14 +375,30 @@ int ZONE_FILLER_TOOL::ZoneFillAll( const TOOL_EVENT& aEvent ) int ZONE_FILLER_TOOL::ZoneUnfill( const TOOL_EVENT& aEvent ) { + const PCB_SELECTION& sel = m_toolMgr->GetTool()->RequestSelection( + []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool ) + { + } ); + + std::vector toUnfill; + + for( EDA_ITEM* item : sel ) + { + if( ZONE* zone = dynamic_cast( item ) ) + toUnfill.push_back( zone ); + } + + // Bail out if there are no zones + if( toUnfill.empty() ) + { + wxBell(); + return -1; + } + BOARD_COMMIT commit( this ); - for( EDA_ITEM* item : selection() ) + for( ZONE* zone : toUnfill ) { - assert( item->Type() == PCB_ZONE_T ); - - ZONE* zone = static_cast( item ); - commit.Modify( zone ); zone->UnFill();