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.
This commit is contained in:
Ian McInerney 2023-07-12 22:25:15 +01:00
parent dde017cdc2
commit e82a58a12e
3 changed files with 44 additions and 15 deletions

View File

@ -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() ) );

View File

@ -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<ZONE*>( nullptr ) );
TOOL_ACTION PCB_ACTIONS::zoneFillAll( "pcbnew.ZoneFiller.zoneFillAll",
AS_GLOBAL,

View File

@ -39,6 +39,7 @@
#include <wx/hyperlink.h>
#include <tool/tool_manager.h>
#include <tool/actions.h>
#include <tools/pcb_selection_tool.h>
#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<ZONE*> toFill;
if( ZONE* passedZone = aEvent.Parameter<ZONE*>() )
@ -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<PCB_SELECTION_TOOL>()->RequestSelection(
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
{
} );
for( EDA_ITEM* item : sel )
{
if( ZONE* zone = dynamic_cast<ZONE*>( 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<WX_PROGRESS_REPORTER> 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<PCB_SELECTION_TOOL>()->RequestSelection(
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
{
} );
std::vector<ZONE*> toUnfill;
for( EDA_ITEM* item : sel )
{
if( ZONE* zone = dynamic_cast<ZONE*>( 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<ZONE*>( item );
commit.Modify( zone );
zone->UnFill();