Get rid of error-prone reverse logic.
Fixes https://gitlab.com/kicad/code/kicad/issues/12049
This commit is contained in:
parent
3389e456b1
commit
012d861aab
|
@ -115,47 +115,52 @@ void DIALOG_GLOBAL_DELETION::onCheckDeleteBoardOutlines( wxCommandEvent& event )
|
||||||
void DIALOG_GLOBAL_DELETION::DoGlobalDeletions()
|
void DIALOG_GLOBAL_DELETION::DoGlobalDeletions()
|
||||||
{
|
{
|
||||||
bool gen_rastnest = false;
|
bool gen_rastnest = false;
|
||||||
|
bool delete_all = m_delAll->GetValue();
|
||||||
|
|
||||||
// Clear selection before removing any items
|
if( !IsOK( GetParent(), delete_all ? _( "Are you sure you want to delete the entire board?" )
|
||||||
m_Parent->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
|
: _( "Are you sure you want to delete the selected items?" ) ) )
|
||||||
|
|
||||||
bool delete_all = false;
|
|
||||||
|
|
||||||
if( m_delAll->GetValue() )
|
|
||||||
{
|
|
||||||
if( !IsOK( GetParent(), _( "Are you sure you want to delete the entire board?" ) ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
delete_all = true;
|
|
||||||
}
|
|
||||||
else if( !IsOK( GetParent(), _( "Are you sure you want to delete the selected items?" ) ) )
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear selection before removing any items
|
||||||
|
m_Parent->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
|
||||||
|
|
||||||
BOARD* board = m_Parent->GetBoard();
|
BOARD* board = m_Parent->GetBoard();
|
||||||
BOARD_COMMIT commit( m_Parent );
|
BOARD_COMMIT commit( m_Parent );
|
||||||
LSET layers_filter = LSET().set();
|
LSET all_layers = LSET().set();
|
||||||
|
LSET layers_filter;
|
||||||
|
|
||||||
if( m_rbLayersOption->GetSelection() != 0 ) // Use current layer only
|
if( m_rbLayersOption->GetSelection() != 0 )
|
||||||
layers_filter = LSET( ToLAYER_ID( m_currentLayer ) );
|
layers_filter.set( m_currentLayer );
|
||||||
|
else
|
||||||
|
layers_filter = all_layers;
|
||||||
|
|
||||||
|
auto processItem =
|
||||||
|
[&]( BOARD_ITEM* item, const LSET& layers_mask )
|
||||||
|
{
|
||||||
|
if( ( item->GetLayerSet() & layers_mask ).any() )
|
||||||
|
commit.Remove( item );
|
||||||
|
};
|
||||||
|
|
||||||
|
auto processConnectedItem =
|
||||||
|
[&]( BOARD_ITEM* item, const LSET& layers_mask )
|
||||||
|
{
|
||||||
|
if( ( item->GetLayerSet() & layers_mask ).any() )
|
||||||
|
{
|
||||||
|
commit.Remove( item );
|
||||||
|
gen_rastnest = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if( delete_all || m_delZones->GetValue() )
|
if( delete_all || m_delZones->GetValue() )
|
||||||
{
|
{
|
||||||
int area_index = 0;
|
for( ZONE* zone : board->Zones() )
|
||||||
ZONE* item = board->GetArea( area_index );
|
|
||||||
|
|
||||||
while( item )
|
|
||||||
{
|
{
|
||||||
// The zone will be deleted if it is ar least on one selected layer.
|
if( delete_all )
|
||||||
if( delete_all || ( layers_filter & item->GetLayerSet() ).any() )
|
processConnectedItem( zone, all_layers );
|
||||||
{
|
else
|
||||||
commit.Remove( item );
|
processConnectedItem( zone, layers_filter );
|
||||||
gen_rastnest = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
area_index++;
|
|
||||||
item = board->GetArea( area_index );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,46 +169,41 @@ void DIALOG_GLOBAL_DELETION::DoGlobalDeletions()
|
||||||
|
|
||||||
if( delete_all || delete_shapes || delete_texts )
|
if( delete_all || delete_shapes || delete_texts )
|
||||||
{
|
{
|
||||||
// Layer mask for texts
|
|
||||||
LSET del_text_layers = layers_filter;
|
|
||||||
|
|
||||||
// Layer mask for drawings
|
// Layer mask for drawings
|
||||||
LSET masque_layer;
|
LSET drawing_layers_filter;
|
||||||
|
|
||||||
if( m_delDrawings->GetValue() )
|
if( m_delDrawings->GetValue() )
|
||||||
masque_layer = LSET::AllNonCuMask().set( Edge_Cuts, false );
|
drawing_layers_filter = LSET::AllNonCuMask().set( Edge_Cuts, false );
|
||||||
|
|
||||||
if( m_delBoardEdges->GetValue() )
|
if( m_delBoardEdges->GetValue() )
|
||||||
masque_layer.set( Edge_Cuts );
|
drawing_layers_filter.set( Edge_Cuts );
|
||||||
|
|
||||||
masque_layer &= layers_filter;
|
drawing_layers_filter &= layers_filter;
|
||||||
|
|
||||||
for( BOARD_ITEM* item : board->Drawings() )
|
for( BOARD_ITEM* item : board->Drawings() )
|
||||||
{
|
{
|
||||||
KICAD_T type = item->Type();
|
if( delete_all )
|
||||||
int layer = item->GetLayer();
|
|
||||||
|
|
||||||
if( !delete_all )
|
|
||||||
{
|
{
|
||||||
if( type == PCB_SHAPE_T )
|
processItem( item, all_layers );
|
||||||
|
}
|
||||||
|
else if( delete_shapes )
|
||||||
|
{
|
||||||
|
if( item->Type() == PCB_SHAPE_T && item->IsLocked() )
|
||||||
{
|
{
|
||||||
if( !delete_shapes || !masque_layer[layer] )
|
if( m_drawingFilterLocked->GetValue() )
|
||||||
continue;
|
processItem( item, drawing_layers_filter );
|
||||||
|
|
||||||
if( item->IsLocked() && !m_drawingFilterLocked->GetValue() )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if( !item->IsLocked() && !m_drawingFilterUnlocked->GetValue() )
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else if( type == PCB_TEXT_T || type == PCB_TEXTBOX_T )
|
else if( item->Type() == PCB_SHAPE_T && !item->IsLocked() )
|
||||||
{
|
{
|
||||||
if( !delete_texts || !del_text_layers[layer] )
|
if( m_drawingFilterUnlocked->GetValue() )
|
||||||
continue;
|
processItem( item, drawing_layers_filter );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if( delete_texts )
|
||||||
commit.Remove( item );
|
{
|
||||||
|
if( item->Type() == PCB_TEXT_T || item->Type() == PCB_TEXTBOX_T )
|
||||||
|
processItem( item, layers_filter );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,20 +211,20 @@ void DIALOG_GLOBAL_DELETION::DoGlobalDeletions()
|
||||||
{
|
{
|
||||||
for( FOOTPRINT* footprint : board->Footprints() )
|
for( FOOTPRINT* footprint : board->Footprints() )
|
||||||
{
|
{
|
||||||
if( !delete_all )
|
if( delete_all )
|
||||||
{
|
{
|
||||||
if( footprint->IsLocked() && !m_footprintFilterLocked->GetValue() )
|
processConnectedItem( footprint, all_layers );
|
||||||
continue;
|
}
|
||||||
|
else if( footprint->IsLocked() )
|
||||||
if( !footprint->IsLocked() && !m_footprintFilterUnlocked->GetValue() )
|
{
|
||||||
continue;
|
if( m_footprintFilterLocked->GetValue() )
|
||||||
|
processConnectedItem( footprint, layers_filter );
|
||||||
if( !layers_filter[footprint->GetLayer()] )
|
}
|
||||||
continue;
|
else
|
||||||
|
{
|
||||||
|
if( m_footprintFilterUnlocked->GetValue() )
|
||||||
|
processConnectedItem( footprint, layers_filter );
|
||||||
}
|
}
|
||||||
|
|
||||||
commit.Remove( footprint );
|
|
||||||
gen_rastnest = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,26 +232,25 @@ void DIALOG_GLOBAL_DELETION::DoGlobalDeletions()
|
||||||
{
|
{
|
||||||
for( PCB_TRACK* track : board->Tracks() )
|
for( PCB_TRACK* track : board->Tracks() )
|
||||||
{
|
{
|
||||||
if( !delete_all )
|
if( delete_all )
|
||||||
{
|
{
|
||||||
if( track->Type() == PCB_TRACE_T )
|
processConnectedItem( track, all_layers );
|
||||||
{
|
}
|
||||||
if( track->IsLocked() && !m_trackFilterLocked->GetValue() )
|
else if( track->Type() == PCB_VIA_T )
|
||||||
continue;
|
{
|
||||||
|
if( m_trackFilterVias->GetValue() )
|
||||||
if( !track->IsLocked() && !m_trackFilterUnlocked->GetValue() )
|
processConnectedItem( track, layers_filter );
|
||||||
continue;
|
}
|
||||||
}
|
else if( track->IsLocked() )
|
||||||
|
{
|
||||||
if( ( track->Type() == PCB_VIA_T ) && !m_trackFilterVias->GetValue() )
|
if( m_trackFilterLocked->GetValue() )
|
||||||
continue;
|
processConnectedItem( track, layers_filter );
|
||||||
|
}
|
||||||
if( ( track->GetLayerSet() & layers_filter ) == 0 )
|
else
|
||||||
continue;
|
{
|
||||||
|
if( m_trackFilterUnlocked->GetValue() )
|
||||||
|
processConnectedItem( track, layers_filter );
|
||||||
}
|
}
|
||||||
|
|
||||||
commit.Remove( track );
|
|
||||||
gen_rastnest = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue