From 6ffb72159a21b5ebd4c4ae071d0afe2ecd7063c0 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 8 Jan 2021 09:38:51 -0800 Subject: [PATCH] Remove vias if they only connect to single layer A via takes up zone space on additional layers, so if we are not connecting to those layers, then we should remove it. Fixes https://gitlab.com/kicad/code/kicad/issues/7004 --- pcbnew/connectivity/connectivity_data.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pcbnew/connectivity/connectivity_data.cpp b/pcbnew/connectivity/connectivity_data.cpp index d09aa208b9..9624f25af9 100644 --- a/pcbnew/connectivity/connectivity_data.cpp +++ b/pcbnew/connectivity/connectivity_data.cpp @@ -612,6 +612,27 @@ bool CONNECTIVITY_DATA::TestTrackEndpointDangling( TRACK* aTrack, wxPoint* aPos } } + // Test if a via is only connected on one layer + if( aTrack->Type() == PCB_VIA_T ) + { + const CN_ITEM::CONNECTED_ITEMS& connected = citem->ConnectedItems(); + + // This is a bit redundant but better safe than sorry here + if( connected.empty() ) + return true; + + // Here, we check if the via is connected only to items on a single layer + int first_layer = connected.front()->Layer(); + + for( auto& item : connected ) + { + if( item->Layer() != first_layer ) + return false; + } + + return true; + } + return false; }