Add ability to quickly move through nets

After highlighting a net (`), press Tab to quikcly move to the next item
on the net and Shift-Tab to move to the previous

Fixes https://gitlab.com/kicad/code/kicad/-/issues/10911

(cherry picked from commit 1e9cf4e3d79c9cb78dfef232790246276725810e)
This commit is contained in:
Seth Hillbrand 2025-03-03 14:01:12 -08:00
parent d29d5e77fe
commit 6a8e1b1135
6 changed files with 153 additions and 1 deletions

View File

@ -382,6 +382,82 @@ void SCH_EDIT_FRAME::RefreshNetNavigator( const NET_NAVIGATOR_ITEM_DATA* aSelect
}
const SCH_ITEM* SCH_EDIT_FRAME::SelectNextPrevNetNavigatorItem( bool aNext )
{
wxCHECK( m_netNavigator, nullptr );
wxTreeItemId id = m_netNavigator->GetSelection();
if( !id.IsOk() )
return nullptr;
wxTreeItemId nextId;
wxTreeItemId netNode = m_netNavigator->GetRootItem();
std::vector<wxTreeItemId> netItems;
std::list<wxTreeItemId> itemList;
itemList.push_back( netNode );
while( !itemList.empty() )
{
wxTreeItemId current = itemList.front();
itemList.pop_front();
wxTreeItemIdValue cookie;
wxTreeItemId child = m_netNavigator->GetFirstChild( current, cookie );
while( child.IsOk() )
{
if( m_netNavigator->ItemHasChildren( child ) )
itemList.push_back( child );
else
netItems.push_back( child );
child = m_netNavigator->GetNextSibling( child );
}
}
// Locate current item and move forward or backward with wrap
auto it = std::find( netItems.begin(), netItems.end(), id );
if( it != netItems.end() )
{
if( aNext )
{
++it;
if( it == netItems.end() )
it = netItems.begin();
}
else
{
if( it == netItems.begin() )
it = netItems.end();
--it;
}
nextId = *it;
}
if( nextId.IsOk() )
{
if( !m_netNavigator->IsVisible( nextId ) )
{
m_netNavigator->CollapseAll();
m_netNavigator->EnsureVisible( nextId );
}
m_netNavigator->SelectItem( nextId );
NET_NAVIGATOR_ITEM_DATA* data = static_cast<NET_NAVIGATOR_ITEM_DATA*>(
m_netNavigator->GetItemData( nextId ) );
if( data && data->GetItem() )
return data->GetItem();
}
return nullptr;
}
void SCH_EDIT_FRAME::SelectNetNavigatorItem( const NET_NAVIGATOR_ITEM_DATA* aSelection )
{
wxCHECK( m_netNavigator && !m_netNavigator->IsFrozen(), /* void */ );

View File

@ -959,6 +959,8 @@ public:
void SelectNetNavigatorItem( const NET_NAVIGATOR_ITEM_DATA* aSelection = nullptr );
const SCH_ITEM* SelectNextPrevNetNavigatorItem( bool aNext );
void ToggleNetNavigator();
PLUGIN_ACTION_SCOPE PluginActionScope() const override

View File

@ -1069,6 +1069,20 @@ TOOL_ACTION SCH_ACTIONS::remapSymbols( TOOL_ACTION_ARGS()
.Tooltip( _( "Remap library symbol references in legacy schematics to the symbol library table" ) )
.Icon( BITMAPS::rescue ) );
TOOL_ACTION SCH_ACTIONS::nextNetItem( TOOL_ACTION_ARGS()
.Name( "eeschema.EditorControl.nextNetItem" )
.Scope( AS_GLOBAL )
.DefaultHotkey( WXK_TAB )
.FriendlyName( _( "Next Net Item" ) )
.Tooltip( _( "Select next item on the current net" ) ) );
TOOL_ACTION SCH_ACTIONS::previousNetItem( TOOL_ACTION_ARGS()
.Name( "eeschema.EditorControl.previousNetItem" )
.Scope( AS_GLOBAL )
.DefaultHotkey( MD_SHIFT + static_cast<int>( WXK_TAB ) )
.FriendlyName( _( "Previous Net Item" ) )
.Tooltip( _( "Select previous item on the current net" ) ) );
TOOL_ACTION SCH_ACTIONS::drawSheetOnClipboard( TOOL_ACTION_ARGS()
.Name( "eeschema.EditorControl.drawSheetOnClipboard" )
.Scope( AS_GLOBAL )

View File

@ -175,6 +175,9 @@ public:
static TOOL_ACTION rescueSymbols;
static TOOL_ACTION remapSymbols;
static TOOL_ACTION nextNetItem;
static TOOL_ACTION previousNetItem;
// Suite operations
static TOOL_ACTION editWithLibEdit;
static TOOL_ACTION editLibSymbolWithLibEdit;

View File

@ -597,7 +597,11 @@ int SCH_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
SCH_COLLECTOR collector;
if( CollectHits( collector, evt->DragOrigin(), { SCH_TABLECELL_T } ) )
if( m_selection.GetSize() == 1 && dynamic_cast<SCH_TABLE*>( m_selection.GetItem( 0 ) ) )
{
m_toolMgr->RunAction( SCH_ACTIONS::move );
}
else if( CollectHits( collector, evt->DragOrigin(), { SCH_TABLECELL_T } ) )
{
selectTableCells( static_cast<SCH_TABLE*>( collector[0]->GetParent() ) );
}
@ -2827,6 +2831,50 @@ bool SCH_SELECTION_TOOL::selectionContains( const VECTOR2I& aPoint ) const
}
int SCH_SELECTION_TOOL::SelectNext( const TOOL_EVENT& aEvent )
{
SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
if( !editFrame || !editFrame->GetNetNavigator() || m_selection.Size() == 0 )
return 0;
if( !m_selection.Front()->IsSelected() )
return 0;
const SCH_ITEM* item = editFrame->SelectNextPrevNetNavigatorItem( true );
if( item )
{
select( const_cast<SCH_ITEM*>( item ) );
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
}
return 0;
}
int SCH_SELECTION_TOOL::SelectPrevious( const TOOL_EVENT& aEvent )
{
SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
if( !editFrame || !editFrame->GetNetNavigator() || m_selection.Size() == 0 )
return 0;
if( !m_selection.Front()->IsBrightened() )
return 0;
const SCH_ITEM* item = editFrame->SelectNextPrevNetNavigatorItem( false );
if( item )
{
select( const_cast<SCH_ITEM*>( item ) );
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
}
return 0;
}
void SCH_SELECTION_TOOL::setTransitions()
{
Go( &SCH_SELECTION_TOOL::UpdateMenu, ACTIONS::updateMenu.MakeEvent() );
@ -2849,5 +2897,8 @@ void SCH_SELECTION_TOOL::setTransitions()
Go( &SCH_SELECTION_TOOL::SelectAll, SCH_ACTIONS::selectAll.MakeEvent() );
Go( &SCH_SELECTION_TOOL::UnselectAll, SCH_ACTIONS::unselectAll.MakeEvent() );
Go( &SCH_SELECTION_TOOL::SelectNext, SCH_ACTIONS::nextNetItem.MakeEvent() );
Go( &SCH_SELECTION_TOOL::SelectPrevious, SCH_ACTIONS::previousNetItem.MakeEvent() );
Go( &SCH_SELECTION_TOOL::disambiguateCursor, EVENTS::DisambiguatePoint );
}

View File

@ -152,6 +152,12 @@ public:
///< Unselect all visible items in sheet
int UnselectAll( const TOOL_EVENT& aEvent );
///< Select next net item
int SelectNext( const TOOL_EVENT& aEvent );
///< Select previous net item
int SelectPrevious( const TOOL_EVENT& aEvent );
void ClearSelection( bool aQuietMode = false );
/**