From 44dbe3577bbb8a7ce4856e5779936192b4d33270 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 12 Oct 2020 20:55:36 +0100 Subject: [PATCH] Create proxy items for PNS when needing to query clearances. Fixes https://gitlab.com/kicad/code/kicad/issues/5929 --- pcbnew/router/pns_kicad_iface.cpp | 32 +++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 31cc6c457d..6a94ebdaf8 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -226,11 +226,39 @@ bool PNS_PCBNEW_RULE_RESOLVER::QueryConstraint( PNS::CONSTRAINT_TYPE aType, return false; // should not happen } + // A track being routed may not have a BOARD_ITEM associated yet. + static TRACK dummyTrack( m_board ); + static ARC dummyArc( m_board ); + static VIA dummyVia( m_board ); + const BOARD_ITEM* parentA = aItemA ? aItemA->Parent() : nullptr; const BOARD_ITEM* parentB = aItemB ? aItemB->Parent() : nullptr; + DRC_CONSTRAINT hostConstraint; - DRC_CONSTRAINT hostConstraint = drcEngine->EvalRulesForItems( hostRuleType, parentA, parentB, - (PCB_LAYER_ID) aLayer ); + if( !parentA ) + { + switch( aItemA->Kind() ) + { + case PNS::ITEM::ARC_T: + dummyArc.SetLayer( (PCB_LAYER_ID) aLayer ); + parentA = &dummyArc; + break; + case PNS::ITEM::VIA_T: + dummyVia.SetLayer( (PCB_LAYER_ID) aLayer ); + parentA = &dummyVia; + break; + default: + dummyTrack.SetLayer( (PCB_LAYER_ID) aLayer ); + parentA = &dummyTrack; + break; + } + } + + if( parentA ) + { + hostConstraint = drcEngine->EvalRulesForItems( hostRuleType, parentA, parentB, + (PCB_LAYER_ID) aLayer ); + } if( hostConstraint.IsNull() ) return false;