Fold down select/expand connection/copper to a single action.

Fixes: lp:1832902
* https://bugs.launchpad.net/kicad/+bug/1832902
This commit is contained in:
Jeff Young 2019-11-22 19:29:07 +00:00
parent 523de87b45
commit 13df645af9
5 changed files with 31 additions and 106 deletions

View File

@ -839,7 +839,7 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
if( isAlt && isHover
&& ( selectionCopy.HasType( PCB_TRACE_T ) || selectionCopy.HasType( PCB_VIA_T ) ) )
{
m_toolMgr->RunAction( PCB_ACTIONS::expandSelectedConnection, true );
m_toolMgr->RunAction( PCB_ACTIONS::selectConnection, true );
}
if( selectionCopy.Empty() )

View File

@ -1015,22 +1015,10 @@ TOOL_ACTION PCB_ACTIONS::selectionMenu( "pcbnew.InteractiveSelection.SelectionMe
TOOL_ACTION PCB_ACTIONS::selectConnection( "pcbnew.InteractiveSelection.SelectConnection",
AS_GLOBAL,
'U', LEGACY_HK_NAME( "Select Single Track" ),
_( "Select Single Track" ),
_( "Selects all track segments & vias between two junctions." ),
_( "Select/Expand Connection" ),
_( "Selects a connection or expands an existing selection to junctions, pads, or entire connections" ),
add_tracks_xpm );
TOOL_ACTION PCB_ACTIONS::selectCopper( "pcbnew.InteractiveSelection.SelectCopper",
AS_GLOBAL,
'I', LEGACY_HK_NAME( "Select Connected Tracks" ),
_( "Select Connected Tracks" ),
_( "Selects all connected tracks & vias." ),
net_highlight_xpm );
TOOL_ACTION PCB_ACTIONS::expandSelectedConnection( "pcbnew.InteractiveSelection.ExpandConnection",
AS_GLOBAL, 0, "",
_( "Expand Selected Connection" ),
_( "Expands the current selection to select a connection between two junctions." ) );
TOOL_ACTION PCB_ACTIONS::selectNet( "pcbnew.InteractiveSelection.SelectNet",
AS_GLOBAL, 0, "",
_( "Select All Tracks in Net" ),

View File

@ -83,15 +83,10 @@ public:
/// Runs a selection menu to select from a list of items
static TOOL_ACTION selectionMenu;
/// Selects a connection between junctions.
/// Selects tracks between junctions or expands an existing selection to pads or the
/// entire connection.
static TOOL_ACTION selectConnection;
/// Expands the current selection to select a connection between two junctions
static TOOL_ACTION expandSelectedConnection;
/// Selects whole copper connection.
static TOOL_ACTION selectCopper;
/// Selects all connections belonging to a single net.
static TOOL_ACTION selectNet;

View File

@ -70,7 +70,6 @@ public:
AppendSeparator();
Add( PCB_ACTIONS::selectConnection );
Add( PCB_ACTIONS::selectCopper );
Add( PCB_ACTIONS::selectNet );
Add( PCB_ACTIONS::selectSameSheet );
}
@ -87,7 +86,6 @@ private:
bool sheetSelEnabled = ( S_C::OnlyType( PCB_MODULE_T ) )( selection );
Enable( getMenuId( PCB_ACTIONS::selectNet ), connItem );
Enable( getMenuId( PCB_ACTIONS::selectCopper ), connItem );
Enable( getMenuId( PCB_ACTIONS::selectConnection ), connItem );
Enable( getMenuId( PCB_ACTIONS::selectSameSheet ), sheetSelEnabled );
}
@ -753,63 +751,6 @@ void SELECTION_TOOL::UnbrightenItem( BOARD_ITEM* aItem )
}
void connectedTrackFilter( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
{
// Narrow the collection down to a single TRACK item for a trivial connection, or
// multiple TRACK items for non-trivial connections.
for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
{
if( !dynamic_cast<TRACK*>( aCollector[i] ) )
aCollector.Remove( i );
}
ROUTER_TOOL::NeighboringSegmentFilter( aPt, aCollector );
}
int SELECTION_TOOL::selectConnection( const TOOL_EVENT& aEvent )
{
if( !m_selection.HasType( PCB_TRACE_T ) && !m_selection.HasType( PCB_VIA_T ) )
selectCursor( true, connectedTrackFilter );
if( !m_selection.HasType( PCB_TRACE_T ) && !m_selection.HasType( PCB_VIA_T ) )
return 0;
return expandConnection( aEvent );
}
int SELECTION_TOOL::expandConnection( const TOOL_EVENT& aEvent )
{
// copy the selection, since we're going to iterate and modify
std::deque<EDA_ITEM*> selectedItems = m_selection.GetItems();
// We use the BUSY flag to mark connections
for( EDA_ITEM* item : selectedItems )
item->SetState( BUSY, false );
for( EDA_ITEM* item : selectedItems )
{
TRACK* trackItem = dynamic_cast<TRACK*>( item );
// Track items marked BUSY have already been visited
if( trackItem && !trackItem->GetState( BUSY ) )
{
if( aEvent.IsAction( &PCB_ACTIONS::selectConnection ) )
selectConnectedTracks( *trackItem, SCH_JUNCTION_T );
else
selectConnectedTracks( *trackItem, PCB_PAD_T );
}
}
// Inform other potentially interested tools
if( m_selection.Size() > 0 )
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
return 0;
}
void connectedItemFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector )
{
// Narrow the collection down to a single BOARD_CONNECTED_ITEM for each represented net.
@ -829,32 +770,39 @@ void connectedItemFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector )
}
int SELECTION_TOOL::selectCopper( const TOOL_EVENT& aEvent )
int SELECTION_TOOL::expandConnection( const TOOL_EVENT& aEvent )
{
bool haveCopper = false;
int initialCount = 0;
for( auto item : m_selection.GetItems() )
{
if( dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
haveCopper = true;;
initialCount++;
}
if( !haveCopper )
if( initialCount == 0 )
selectCursor( true, connectedItemFilter );
// copy the selection, since we're going to iterate and modify
std::deque<EDA_ITEM*> selectedItems = m_selection.GetItems();
// We use the BUSY flag to mark connections
for( EDA_ITEM* item : selectedItems )
item->SetState( BUSY, false );
for( EDA_ITEM* item : selectedItems )
for( KICAD_T stopCondition : { SCH_JUNCTION_T, PCB_PAD_T, EOT } )
{
BOARD_CONNECTED_ITEM* connItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( item );
// copy the selection, since we're going to iterate and modify
std::deque<EDA_ITEM*> selectedItems = m_selection.GetItems();
if( connItem && !connItem->GetState( BUSY ) )
selectConnectedTracks( *connItem, EOT );
// We use the BUSY flag to mark connections
for( EDA_ITEM* item : selectedItems )
item->SetState( BUSY, false );
for( EDA_ITEM* item : selectedItems )
{
TRACK* trackItem = dynamic_cast<TRACK*>( item );
// Track items marked BUSY have already been visited
if( trackItem && !trackItem->GetState( BUSY ) )
selectConnectedTracks( *trackItem, stopCondition );
}
if( m_selection.GetItems().size() > initialCount )
break;
}
// Inform other potentially interested tools
@ -2300,9 +2248,7 @@ void SELECTION_TOOL::setTransitions()
Go( &SELECTION_TOOL::find, ACTIONS::find.MakeEvent() );
Go( &SELECTION_TOOL::filterSelection, PCB_ACTIONS::filterSelection.MakeEvent() );
Go( &SELECTION_TOOL::selectConnection, PCB_ACTIONS::selectConnection.MakeEvent() );
Go( &SELECTION_TOOL::expandConnection, PCB_ACTIONS::expandSelectedConnection.MakeEvent() );
Go( &SELECTION_TOOL::selectCopper, PCB_ACTIONS::selectCopper.MakeEvent() );
Go( &SELECTION_TOOL::expandConnection, PCB_ACTIONS::selectConnection.MakeEvent() );
Go( &SELECTION_TOOL::selectNet, PCB_ACTIONS::selectNet.MakeEvent() );
Go( &SELECTION_TOOL::selectSameSheet, PCB_ACTIONS::selectSameSheet.MakeEvent() );
Go( &SELECTION_TOOL::selectSheetContents, PCB_ACTIONS::selectOnSheetFromEeschema.MakeEvent() );

View File

@ -208,15 +208,11 @@ private:
*/
bool doSelectionMenu( GENERAL_COLLECTOR* aItems, const wxString& aTitle );
///> Selects a trivial connection (between two junctions) of items in selection
int selectConnection( const TOOL_EVENT& aEvent );
///> Expands the current selection to select a connection between two junctions
/**
* Expands the current track selection to the next boundary (junctions, pads, or all)
*/
int expandConnection( const TOOL_EVENT& aEvent );
///> Selects items with a continuous copper connection to items in selection
int selectCopper( const TOOL_EVENT& aEvent );
/**
* Selects all copper connections belonging to the same net(s) as the
* items in the selection