From 4a25db599ef612de1864ea50017a39ccb1795b97 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Wed, 16 Sep 2020 19:09:12 -0400 Subject: [PATCH] ADDED: Deselect net action You can now deselect nets and netclasses (i.e. remove them from the active selection) via the context menus in the appearance panel --- pcbnew/pcb_edit_frame.cpp | 2 ++ pcbnew/tools/pcb_actions.cpp | 6 ++++++ pcbnew/tools/pcb_actions.h | 3 +++ pcbnew/tools/selection_tool.cpp | 14 +++++++++----- pcbnew/tools/selection_tool.h | 4 +++- pcbnew/widgets/appearance_controls.cpp | 20 ++++++++++++++++++-- pcbnew/widgets/appearance_controls.h | 1 + 7 files changed, 42 insertions(+), 8 deletions(-) diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 1c02bf7bae..b4c5594fa5 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -670,6 +670,8 @@ void PCB_EDIT_FRAME::setupUIConditions() mgr->SetConditions( PCB_ACTIONS::selectNet, ENABLE( SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ) ); + mgr->SetConditions( PCB_ACTIONS::deselectNet, + ENABLE( SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ) ); mgr->SetConditions( PCB_ACTIONS::selectConnection, ENABLE( SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ) ); mgr->SetConditions( PCB_ACTIONS::selectSameSheet, diff --git a/pcbnew/tools/pcb_actions.cpp b/pcbnew/tools/pcb_actions.cpp index 7bd8e253a8..b0d33b03b5 100644 --- a/pcbnew/tools/pcb_actions.cpp +++ b/pcbnew/tools/pcb_actions.cpp @@ -1156,6 +1156,12 @@ TOOL_ACTION PCB_ACTIONS::selectNet( "pcbnew.InteractiveSelection.SelectNet", _( "Selects all tracks & vias belonging to the same net." ), mode_track_xpm ); +TOOL_ACTION PCB_ACTIONS::deselectNet( "pcbnew.InteractiveSelection.DeselectNet", + AS_GLOBAL, 0, "", + _( "Deselect All Tracks in Net" ), + _( "Deselects all tracks & vias belonging to the same net." ), + mode_track_xpm ); + TOOL_ACTION PCB_ACTIONS::selectOnSheetFromEeschema( "pcbnew.InteractiveSelection.SelectOnSheet", AS_GLOBAL, 0, "", _( "Sheet" ), diff --git a/pcbnew/tools/pcb_actions.h b/pcbnew/tools/pcb_actions.h index 7ac852e5e1..d0eeaeeb86 100644 --- a/pcbnew/tools/pcb_actions.h +++ b/pcbnew/tools/pcb_actions.h @@ -79,6 +79,9 @@ public: /// Selects all connections belonging to a single net. static TOOL_ACTION selectNet; + /// Removes all connections belonging to a single net from the active selection + static TOOL_ACTION deselectNet; + /// Selects all components on sheet from Eeschema crossprobing. static TOOL_ACTION selectOnSheetFromEeschema; diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index afda41c64e..3c4de99eb1 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -73,6 +73,7 @@ public: Add( PCB_ACTIONS::selectConnection ); Add( PCB_ACTIONS::selectNet ); + Add( PCB_ACTIONS::deselectNet ); Add( PCB_ACTIONS::selectSameSheet ); } @@ -1066,25 +1067,27 @@ void SELECTION_TOOL::selectConnectedTracks( BOARD_CONNECTED_ITEM& aStartItem, } -void SELECTION_TOOL::selectAllItemsOnNet( int aNetCode ) +void SELECTION_TOOL::selectAllItemsOnNet( int aNetCode, bool aSelect ) { constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT }; auto connectivity = board()->GetConnectivity(); for( BOARD_CONNECTED_ITEM* item : connectivity->GetNetItems( aNetCode, types ) ) if( itemPassesFilter( item ) ) - select( item ); + aSelect ? select( item ) : unselect( item ); } int SELECTION_TOOL::selectNet( const TOOL_EVENT& aEvent ) { - // If we've been passed an argument, just select that netcode + bool select = aEvent.IsAction( &PCB_ACTIONS::selectNet ); + + // If we've been passed an argument, just select that netcode1 int netcode = aEvent.Parameter(); if( netcode > 0 ) { - selectAllItemsOnNet( netcode ); + selectAllItemsOnNet( netcode, select ); return 0; } @@ -1099,7 +1102,7 @@ int SELECTION_TOOL::selectNet( const TOOL_EVENT& aEvent ) BOARD_CONNECTED_ITEM* connItem = dynamic_cast( i ); if( connItem ) - selectAllItemsOnNet( connItem->GetNetCode() ); + selectAllItemsOnNet( connItem->GetNetCode(), select ); } // Inform other potentially interested tools @@ -2600,6 +2603,7 @@ void SELECTION_TOOL::setTransitions() Go( &SELECTION_TOOL::filterSelection, PCB_ACTIONS::filterSelection.MakeEvent() ); Go( &SELECTION_TOOL::expandConnection, PCB_ACTIONS::selectConnection.MakeEvent() ); Go( &SELECTION_TOOL::selectNet, PCB_ACTIONS::selectNet.MakeEvent() ); + Go( &SELECTION_TOOL::selectNet, PCB_ACTIONS::deselectNet.MakeEvent() ); Go( &SELECTION_TOOL::selectSameSheet, PCB_ACTIONS::selectSameSheet.MakeEvent() ); Go( &SELECTION_TOOL::selectSheetContents, PCB_ACTIONS::selectOnSheetFromEeschema.MakeEvent() ); Go( &SELECTION_TOOL::updateSelection, EVENTS::SelectedItemsModified ); diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index d84d1ed25f..7bca8d1a87 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -278,8 +278,10 @@ private: /** * Selects all items with the given net code + * @param aNetCode is the target net to select + * @param aSelect is true to add the items to the selection, false to remove them (deselect) */ - void selectAllItemsOnNet( int aNetCode ); + void selectAllItemsOnNet( int aNetCode, bool aSelect = true ); /** * Selects all items with the given sheet timestamp/UUID name diff --git a/pcbnew/widgets/appearance_controls.cpp b/pcbnew/widgets/appearance_controls.cpp index 763f556822..b6c7d2db4e 100644 --- a/pcbnew/widgets/appearance_controls.cpp +++ b/pcbnew/widgets/appearance_controls.cpp @@ -812,6 +812,9 @@ void APPEARANCE_CONTROLS::OnNetGridRightClick( wxGridEvent& event ) menu.Append( new wxMenuItem( &menu, ID_SELECT_NET, wxString::Format( _( "Select tracks and vias in %s" ), netName ), wxEmptyString, wxITEM_NORMAL ) ); + menu.Append( new wxMenuItem( &menu, ID_DESELECT_NET, + wxString::Format( _( "Deselect tracks and vias in %s" ), netName ), + wxEmptyString, wxITEM_NORMAL ) ); menu.AppendSeparator(); @@ -1947,6 +1950,10 @@ void APPEARANCE_CONTROLS::rebuildNets() wxString::Format( _( "Select tracks and vias in %s" ), name ), wxEmptyString, wxITEM_NORMAL ) ); + menu.Append( new wxMenuItem( &menu, ID_DESELECT_NET, + wxString::Format( _( "Deselect tracks and vias in %s" ), + name ), + wxEmptyString, wxITEM_NORMAL ) ); menu.AppendSeparator(); @@ -2277,6 +2284,13 @@ void APPEARANCE_CONTROLS::onNetContextMenu( wxCommandEvent& aEvent ) break; } + case ID_DESELECT_NET: + { + m_frame->GetToolManager()->RunAction( PCB_ACTIONS::deselectNet, true, net.code ); + m_frame->GetCanvas()->Refresh(); + break; + } + case ID_SHOW_ALL_NETS: m_netsTable->ShowAllNets(); break; @@ -2504,9 +2518,12 @@ void APPEARANCE_CONTROLS::onNetclassContextMenu( wxCommandEvent& aEvent ) } case ID_SELECT_NET: + case ID_DESELECT_NET: { if( netclass ) { + TOOL_ACTION& action = aEvent.GetId() == ID_SELECT_NET ? PCB_ACTIONS::selectNet : + PCB_ACTIONS::deselectNet; runOnNetsOfClass( netclass, [&]( NETINFO_ITEM* aItem ) { @@ -2514,8 +2531,7 @@ void APPEARANCE_CONTROLS::onNetclassContextMenu( wxCommandEvent& aEvent ) return; int code = aItem->GetNet(); - m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectNet, true, - code ); + m_frame->GetToolManager()->RunAction( action, true, code ); } ); } break; diff --git a/pcbnew/widgets/appearance_controls.h b/pcbnew/widgets/appearance_controls.h index c8805e2f35..c4a33df0d6 100644 --- a/pcbnew/widgets/appearance_controls.h +++ b/pcbnew/widgets/appearance_controls.h @@ -366,6 +366,7 @@ private: ID_HIDE_OTHER_NETS, ID_HIGHLIGHT_NET, ID_SELECT_NET, + ID_DESELECT_NET, ID_SHOW_ALL_COPPER_LAYERS, ID_HIDE_ALL_COPPER_LAYERS, ID_HIDE_ALL_BUT_ACTIVE,