From d155870275034c488349b85febb138e42d958f62 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 21 Dec 2023 12:58:37 +0000 Subject: [PATCH] Sometimes use grid (instead of clearance) for slop radius. This is particularly important both when very large grids are in use, and when the router hasn't been initialized with a net yet (ie: in hover mode) and the board clearance is set to 0. https://forum.kicad.info/t/new-track-start-position-problem-on-kicad-7-0-10-rc1/47006 --- pcbnew/generators/pcb_tuning_pattern.cpp | 6 ++++-- pcbnew/router/pns_router.cpp | 26 ++++-------------------- pcbnew/router/pns_router.h | 2 +- pcbnew/router/pns_tool_base.cpp | 5 +++-- 4 files changed, 12 insertions(+), 27 deletions(-) diff --git a/pcbnew/generators/pcb_tuning_pattern.cpp b/pcbnew/generators/pcb_tuning_pattern.cpp index 4d9ae648b8..46d576049a 100644 --- a/pcbnew/generators/pcb_tuning_pattern.cpp +++ b/pcbnew/generators/pcb_tuning_pattern.cpp @@ -734,6 +734,8 @@ void PCB_TUNING_PATTERN::EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_ static PNS::LINKED_ITEM* pickSegment( PNS::ROUTER* aRouter, const VECTOR2I& aWhere, int aLayer, VECTOR2I& aPointOut ) { + int maxSlopRadius = aRouter->Sizes().Clearance() + aRouter->Sizes().TrackWidth() / 2; + static const int candidateCount = 2; PNS::LINKED_ITEM* prioritized[candidateCount]; SEG::ecoord dist[candidateCount]; @@ -757,9 +759,9 @@ static PNS::LINKED_ITEM* pickSegment( PNS::ROUTER* aRouter, const VECTOR2I& aWhe return false; }; - for( bool useClearance : { false, true } ) + for( int slopRadius : { 0, maxSlopRadius } ) { - PNS::ITEM_SET candidates = aRouter->QueryHoverItems( aWhere, useClearance ); + PNS::ITEM_SET candidates = aRouter->QueryHoverItems( aWhere, slopRadius ); for( PNS::ITEM* item : candidates.Items() ) { diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index 9a8828adef..8c0a6796e4 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -120,32 +120,14 @@ bool ROUTER::RoutingInProgress() const } -const ITEM_SET ROUTER::QueryHoverItems( const VECTOR2I& aP, bool aUseClearance ) +const ITEM_SET ROUTER::QueryHoverItems( const VECTOR2I& aP, int aSlopRadius ) { - NODE* node = nullptr; - int clearance = 0; - - if( m_state == IDLE || m_placer == nullptr ) - { - node = m_world.get(); - clearance = 0; - } - else if( m_mode == PNS_MODE_ROUTE_SINGLE ) - { - node = m_placer->CurrentNode(); - clearance = m_sizes.Clearance() + m_sizes.TrackWidth() / 2; - } - else if( m_mode == PNS_MODE_ROUTE_DIFF_PAIR ) - { - node = m_placer->CurrentNode(); - clearance = m_sizes.Clearance() + m_sizes.DiffPairWidth() / 2; - } - + NODE* node = m_placer ? m_placer->CurrentNode() : m_world.get(); PNS::ITEM_SET ret; wxCHECK( node, ret ); - if( aUseClearance ) + if( aSlopRadius > 0 ) { NODE::OBSTACLES obs; SEGMENT test( SEG( aP, aP ), nullptr ); @@ -155,7 +137,7 @@ const ITEM_SET ROUTER::QueryHoverItems( const VECTOR2I& aP, bool aUseClearance ) test.SetLayers( LAYER_RANGE::All() ); opts.m_differentNetsOnly = false; - opts.m_overrideClearance = clearance; + opts.m_overrideClearance = aSlopRadius; node->QueryColliding( &test, obs, opts ); diff --git a/pcbnew/router/pns_router.h b/pcbnew/router/pns_router.h index 9f3e23dac3..0b8679a352 100644 --- a/pcbnew/router/pns_router.h +++ b/pcbnew/router/pns_router.h @@ -181,7 +181,7 @@ public: bool IsPlacingVia() const; - const ITEM_SET QueryHoverItems( const VECTOR2I& aP, bool aUseClearance = false ); + const ITEM_SET QueryHoverItems( const VECTOR2I& aP, int aSlopRadius = 0 ); bool StartDragging( const VECTOR2I& aP, ITEM* aItem, int aDragMode = DM_ANY ); bool StartDragging( const VECTOR2I& aP, ITEM_SET aItems, int aDragMode = DM_COMPONENT ); diff --git a/pcbnew/router/pns_tool_base.cpp b/pcbnew/router/pns_tool_base.cpp index 2051ade04d..a200e7ca3a 100644 --- a/pcbnew/router/pns_tool_base.cpp +++ b/pcbnew/router/pns_tool_base.cpp @@ -100,6 +100,7 @@ ITEM* TOOL_BASE::pickSingleItem( const VECTOR2I& aWhere, NET_HANDLE aNet, int aL bool aIgnorePads, const std::vector aAvoidItems ) { int tl = aLayer > 0 ? aLayer : getView()->GetTopLayer(); + int maxSlopRadius = std::max( m_gridHelper->GetGrid().x, m_gridHelper->GetGrid().y ); static const int candidateCount = 5; ITEM* prioritized[candidateCount]; @@ -123,9 +124,9 @@ ITEM* TOOL_BASE::pickSingleItem( const VECTOR2I& aWhere, NET_HANDLE aNet, int aL return false; }; - for( bool useClearance : { false, true } ) + for( int slopRadius : { 0, maxSlopRadius } ) { - ITEM_SET candidates = m_router->QueryHoverItems( aWhere, useClearance ); + ITEM_SET candidates = m_router->QueryHoverItems( aWhere, slopRadius ); for( ITEM* item : candidates.Items() ) {