From d3bf20e80bafa3bbfdcafc1458672f553a6aa627 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 2 Apr 2021 17:19:44 +0200 Subject: [PATCH] Pcbnew, place free via: take netcode from the pad, if the via is inside a pad. Fixes #8089 https://gitlab.com/kicad/code/kicad/issues/8089 --- pcbnew/tools/drawing_tool.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index bfba485063..9099b19105 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -2304,6 +2304,24 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent ) return false; } + PAD* findPad( VIA* aVia ) + { + const wxPoint position = aVia->GetPosition(); + const LSET lset = aVia->GetLayerSet(); + + for( FOOTPRINT* fp : m_board->Footprints() ) + { + for(PAD* pad : fp->Pads() ) + { + if( pad->HitTest( position ) && ( pad->GetLayerSet() & lset ).any() ) + if( pad->GetNetCode() > 0 ) + return pad; + } + } + + return nullptr; + } + int findStitchedZoneNet( VIA* aVia ) { const wxPoint position = aVia->GetPosition(); @@ -2370,9 +2388,12 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent ) VIA* via = static_cast( aItem ); wxPoint viaPos = via->GetPosition(); TRACK* track = findTrack( via ); + PAD * pad = findPad( via ); if( track ) via->SetNetCode( track->GetNetCode() ); + else if( pad ) + via->SetNetCode( pad->GetNetCode() ); if( !m_allowDRCViolations && checkDRCViolation( via ) ) { @@ -2400,7 +2421,7 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent ) aCommit.Add( newTrack ); } } - else + else if( !pad ) { via->SetNetCode( findStitchedZoneNet( via ) ); via->SetIsFree();