From fdeff24182c905d9f2c3fc994e52d50bd5e66d87 Mon Sep 17 00:00:00 2001 From: John Beard Date: Thu, 12 Jul 2018 18:07:06 +0100 Subject: [PATCH] Pcbnew: Add selection by netclass Add a new action to the SELECTION_TOOL to select all items on the nets contained in the netclass(es) of the selection. --- pcbnew/tools/pcb_actions.h | 3 ++ pcbnew/tools/selection_tool.cpp | 54 +++++++++++++++++++++++++++++++++ pcbnew/tools/selection_tool.h | 11 +++++++ 3 files changed, 68 insertions(+) diff --git a/pcbnew/tools/pcb_actions.h b/pcbnew/tools/pcb_actions.h index cdd8f1569..1504bfd8b 100644 --- a/pcbnew/tools/pcb_actions.h +++ b/pcbnew/tools/pcb_actions.h @@ -76,6 +76,9 @@ public: /// Selects all connections belonging to a single net. static TOOL_ACTION selectNet; + /// Selects all connections belonging to a single netclass + static TOOL_ACTION selectNetclass; + /// 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 348d2b83c..b38e39ea6 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -109,6 +109,10 @@ TOOL_ACTION PCB_ACTIONS::selectNet( "pcbnew.InteractiveSelection.SelectNet", AS_GLOBAL, 0, _( "Whole Net" ), _( "Selects all tracks & vias belonging to the same net." ), mode_track_xpm ); +TOOL_ACTION PCB_ACTIONS::selectNetclass( "pcbnew.InteractiveSelection.SelectNetclass", + AS_GLOBAL, 0, + _( "Netclass" ), _( "Selects all tracks & vias belonging to the same netclass." ) ); + TOOL_ACTION PCB_ACTIONS::selectOnSheetFromEeschema( "pcbnew.InteractiveSelection.SelectOnSheet", AS_GLOBAL, 0, _( "Sheet" ), _( "Selects all modules and tracks in the schematic sheet" ), select_same_sheet_xpm ); @@ -148,6 +152,7 @@ public: Add( PCB_ACTIONS::selectConnection ); Add( PCB_ACTIONS::selectCopper ); Add( PCB_ACTIONS::selectNet ); + Add( PCB_ACTIONS::selectNetclass ); Add( PCB_ACTIONS::selectSameSheet ); } @@ -163,6 +168,7 @@ private: bool sheetSelEnabled = ( S_C::OnlyType( PCB_MODULE_T ) )( selection ); Enable( getMenuId( PCB_ACTIONS::selectNet ), connItem ); + Enable( getMenuId( PCB_ACTIONS::selectNetclass ), connItem ); Enable( getMenuId( PCB_ACTIONS::selectCopper ), connItem ); Enable( getMenuId( PCB_ACTIONS::selectConnection ), connItem ); Enable( getMenuId( PCB_ACTIONS::selectSameSheet ), sheetSelEnabled ); @@ -689,6 +695,7 @@ void SELECTION_TOOL::setTransitions() Go( &SELECTION_TOOL::expandSelectedConnection, PCB_ACTIONS::expandSelectedConnection.MakeEvent() ); Go( &SELECTION_TOOL::selectCopper, PCB_ACTIONS::selectCopper.MakeEvent() ); Go( &SELECTION_TOOL::selectNet, PCB_ACTIONS::selectNet.MakeEvent() ); + Go( &SELECTION_TOOL::selectNetclass, PCB_ACTIONS::selectNetclass.MakeEvent() ); Go( &SELECTION_TOOL::selectSameSheet, PCB_ACTIONS::selectSameSheet.MakeEvent() ); Go( &SELECTION_TOOL::selectOnSheetFromEeschema, PCB_ACTIONS::selectOnSheetFromEeschema.MakeEvent() ); Go( &SELECTION_TOOL::updateSelection, PCB_ACTIONS::selectionModified.MakeEvent() ); @@ -1008,6 +1015,53 @@ int SELECTION_TOOL::selectNet( const TOOL_EVENT& aEvent ) } +void SELECTION_TOOL::selectAllItemsInNetclass( NETCLASSPTR aNetclass ) +{ + for( const auto& netName : *aNetclass ) + { + const auto netInfo = board()->FindNet( netName ); + selectAllItemsOnNet( netInfo->GetNet() ); + } +} + + +int SELECTION_TOOL::selectNetclass( const TOOL_EVENT& aEvent ) +{ + if( !selectCursor() ) + return 0; + + // copy the selection, since we're going to iterate and modify + auto selection = m_selection.GetItems(); + + std::set netClasses; + + // collect all the selected netclasses + for( auto i : m_selection.GetItems() ) + { + auto item = static_cast( i ); + + // only connected items get a net code + if( item->IsConnected() ) + { + const auto& connItem = static_cast( *item ); + + netClasses.insert( connItem.GetNetClass() ); + } + } + + for( const auto& nc : netClasses ) + { + selectAllItemsInNetclass( nc ); + } + + // Inform other potentially interested tools + if( m_selection.Size() > 0 ) + m_toolMgr->ProcessEvent( SelectedEvent ); + + return 0; +} + + void SELECTION_TOOL::selectAllItemsOnSheet( wxString& aSheetpath ) { auto modules = board()->m_Modules.GetFirst(); diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 54eab3004..81b56d2a2 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -194,6 +194,12 @@ private: */ int selectNet( const TOOL_EVENT& aEvent ); + /** + * Selects all copper connects belonging to the netclass(es) of the + * selection + */ + int selectNetclass( const TOOL_EVENT& aEvent ); + /** * Selects all items connected by copper tracks to the given TRACK */ @@ -209,6 +215,11 @@ private: */ void selectAllItemsOnNet( int aNetCode ); + /** + * Selects all items with the given netclass + */ + void selectAllItemsInNetclass( NETCLASSPTR aNetclass ); + /** * Selects all items with the given sheet timestamp name * (the sheet path) -- 2.17.1