From 00edc85f4f08698e6630c4841cbd90d020113e31 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 2 Dec 2020 21:16:48 +0000 Subject: [PATCH] Allow layer switching when routing from pad. Additionally, don't process layer events from both main loop and transitions -- it makes for a mess. Fixes https://gitlab.com/kicad/code/kicad/issues/4832 --- pcbnew/router/pns_line_placer.cpp | 3 +- pcbnew/router/pns_router.cpp | 14 ++--- pcbnew/router/pns_router.h | 2 +- pcbnew/router/router_tool.cpp | 93 ++++++++++++++++++------------- pcbnew/router/router_tool.h | 2 + 5 files changed, 63 insertions(+), 51 deletions(-) diff --git a/pcbnew/router/pns_line_placer.cpp b/pcbnew/router/pns_line_placer.cpp index 8775ec15c0..f5f936d460 100644 --- a/pcbnew/router/pns_line_placer.cpp +++ b/pcbnew/router/pns_line_placer.cpp @@ -942,7 +942,8 @@ bool LINE_PLACER::SetLayer( int aLayer ) return false; } else if( !m_startItem - || ( m_startItem->OfKind( ITEM::VIA_T ) && m_startItem->Layers().Overlaps( aLayer ) ) ) + || ( m_startItem->OfKind( ITEM::VIA_T ) && m_startItem->Layers().Overlaps( aLayer ) ) + || ( m_startItem->OfKind( ITEM::SOLID_T ) && m_startItem->Layers().Overlaps( aLayer ) ) ) { m_currentLayer = aLayer; m_head.Line().Clear(); diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index c0195c5800..d223b6ec73 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -479,16 +479,12 @@ void ROUTER::FlipPosture() } -void ROUTER::SwitchLayer( int aLayer ) +bool ROUTER::SwitchLayer( int aLayer ) { - switch( m_state ) - { - case ROUTE_TRACK: - m_placer->SetLayer( aLayer ); - break; - default: - break; - } + if( m_state == ROUTE_TRACK ) + return m_placer->SetLayer( aLayer ); + + return false; } diff --git a/pcbnew/router/pns_router.h b/pcbnew/router/pns_router.h index 637241c10a..fc92f2a326 100644 --- a/pcbnew/router/pns_router.h +++ b/pcbnew/router/pns_router.h @@ -159,7 +159,7 @@ public: void FlipPosture(); - void SwitchLayer( int layer ); + bool SwitchLayer( int layer ); void ToggleViaPlacement(); void SetOrthoMode( bool aEnable ); diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index f29bdbe4b5..ddeee11316 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -648,7 +648,19 @@ static PCB_LAYER_ID getTargetLayerFromEvent( const TOOL_EVENT& aEvent ) } +int ROUTER_TOOL::onLayerCommand( const TOOL_EVENT& aEvent ) +{ + return handleLayerSwitch( aEvent, false ); +} + + int ROUTER_TOOL::onViaCommand( const TOOL_EVENT& aEvent ) +{ + return handleLayerSwitch( aEvent, true ); +} + + +int ROUTER_TOOL::handleLayerSwitch( const TOOL_EVENT& aEvent, bool aForceVia ) { if( !IsToolActive() ) return 0; @@ -701,6 +713,13 @@ int ROUTER_TOOL::onViaCommand( const TOOL_EVENT& aEvent ) } } + if( !aForceVia && m_router && m_router->SwitchLayer( targetLayer ) ) + { + updateEndItem( aEvent ); + m_router->Move( m_endSnapPoint, m_endItem ); // refresh + return 0; + } + BOARD_DESIGN_SETTINGS& bds = board()->GetDesignSettings(); const int layerCount = bds.GetCopperLayerCount(); @@ -1045,12 +1064,6 @@ void ROUTER_TOOL::performRouting() updateEndItem( *evt ); m_router->Move( m_endSnapPoint, m_endItem ); // refresh } - else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) ) - { - m_router->SwitchLayer( frame()->GetActiveLayer() ); - updateEndItem( *evt ); - m_router->Move( m_endSnapPoint, m_endItem ); // refresh - } else if( evt->IsAction( &ACT_EndTrack ) || evt->IsDblClick( BUT_LEFT ) ) { // Stop current routing: @@ -1739,40 +1752,40 @@ void ROUTER_TOOL::setTransitions() Go( &ROUTER_TOOL::onViaCommand, ACT_SelLayerAndPlaceThroughVia.MakeEvent() ); Go( &ROUTER_TOOL::onViaCommand, ACT_SelLayerAndPlaceBlindVia.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerTop.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner1.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner2.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner3.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner4.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner5.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner6.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner7.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner8.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner9.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner10.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner11.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner12.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner13.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner14.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner15.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner16.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner17.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner18.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner19.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner20.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner21.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner22.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner23.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner24.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner25.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner26.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner27.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner28.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner29.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerInner30.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerBottom.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerNext.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, PCB_ACTIONS::layerPrev.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerTop.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner1.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner2.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner3.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner4.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner5.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner6.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner7.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner8.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner9.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner10.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner11.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner12.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner13.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner14.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner15.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner16.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner17.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner18.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner19.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner20.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner21.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner22.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner23.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner24.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner25.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner26.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner27.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner28.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner29.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerInner30.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerBottom.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerNext.MakeEvent() ); + Go( &ROUTER_TOOL::onLayerCommand, PCB_ACTIONS::layerPrev.MakeEvent() ); Go( &ROUTER_TOOL::CustomTrackWidthDialog, ACT_CustomTrackWidth.MakeEvent() ); Go( &ROUTER_TOOL::onTrackViaSizeChanged, PCB_ACTIONS::trackViaSizeChanged.MakeEvent() ); diff --git a/pcbnew/router/router_tool.h b/pcbnew/router/router_tool.h index 196bfca4cc..b2236bbb76 100644 --- a/pcbnew/router/router_tool.h +++ b/pcbnew/router/router_tool.h @@ -60,10 +60,12 @@ private: void breakTrack(); void handleCommonEvents( const TOOL_EVENT& evt ); + int handleLayerSwitch( const TOOL_EVENT& aEvent, bool aForceVia ); int getStartLayer( const PNS::ITEM* aItem ); void switchLayerOnViaPlacement(); + int onLayerCommand( const TOOL_EVENT& aEvent ); int onViaCommand( const TOOL_EVENT& aEvent ); int onTrackViaSizeChanged( const TOOL_EVENT& aEvent );