From f6d1baa50a32688480f19c364c89ffa33af44419 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 17 Jun 2023 22:56:57 +0100 Subject: [PATCH] Refine track dangling test. Turns out Clean Up Tracks and Vias wants a different answer from DRC. (cherry picked from commit fb40c202a1a516924b808fea08d0af5a91ac9eda) --- pcbnew/connectivity/connectivity_data.cpp | 14 ++++++++++---- pcbnew/connectivity/connectivity_data.h | 3 ++- pcbnew/drc/drc_test_provider_connectivity.cpp | 4 ++-- pcbnew/tracks_cleaner.cpp | 4 ++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/pcbnew/connectivity/connectivity_data.cpp b/pcbnew/connectivity/connectivity_data.cpp index 3e3d59158f..1ff6088067 100644 --- a/pcbnew/connectivity/connectivity_data.cpp +++ b/pcbnew/connectivity/connectivity_data.cpp @@ -710,7 +710,8 @@ static int getMinDist( BOARD_CONNECTED_ITEM* aItem, const VECTOR2I& aPoint ) } -bool CONNECTIVITY_DATA::TestTrackEndpointDangling( PCB_TRACK* aTrack, VECTOR2I* aPos ) const +bool CONNECTIVITY_DATA::TestTrackEndpointDangling( PCB_TRACK* aTrack, bool aIgnoreTracksInPads, + VECTOR2I* aPos ) const { const std::list& items = GetConnectivityAlgo()->ItemEntry( aTrack ).GetItems(); @@ -770,12 +771,17 @@ bool CONNECTIVITY_DATA::TestTrackEndpointDangling( PCB_TRACK* aTrack, VECTOR2I* if( hitStart && hitEnd ) { - if( zone || item->Type() == PCB_PAD_T || item->Type() == PCB_VIA_T ) + if( zone ) { - // Both start and end in a zone or under a pad: track may be redundant, but - // it's not dangling + // Both start and end in a zone: track may be redundant, but it's not dangling return false; } + else if( item->Type() == PCB_PAD_T || item->Type() == PCB_VIA_T ) + { + // Both start and end are under a pad: see what the caller wants us to do + if( aIgnoreTracksInPads ) + return false; + } if( getMinDist( item, aTrack->GetStart() ) < getMinDist( item, aTrack->GetEnd() ) ) start_count++; diff --git a/pcbnew/connectivity/connectivity_data.h b/pcbnew/connectivity/connectivity_data.h index 1ad5797620..3ca4975258 100644 --- a/pcbnew/connectivity/connectivity_data.h +++ b/pcbnew/connectivity/connectivity_data.h @@ -210,7 +210,8 @@ public: void RunOnUnconnectedEdges( std::function aFunc ); - bool TestTrackEndpointDangling( PCB_TRACK* aTrack, VECTOR2I* aPos = nullptr ) const; + bool TestTrackEndpointDangling( PCB_TRACK* aTrack, bool aIgnoreTracksInPads, + VECTOR2I* aPos = nullptr ) const; /** * Function ClearLocalRatsnest() diff --git a/pcbnew/drc/drc_test_provider_connectivity.cpp b/pcbnew/drc/drc_test_provider_connectivity.cpp index 111f512478..afd46c5dc8 100644 --- a/pcbnew/drc/drc_test_provider_connectivity.cpp +++ b/pcbnew/drc/drc_test_provider_connectivity.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2004-2022 KiCad Developers. + * Copyright (C) 2004-2023 KiCad Developers. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -100,7 +100,7 @@ bool DRC_TEST_PROVIDER_CONNECTIVITY::Run() int code = track->Type() == PCB_VIA_T ? DRCE_DANGLING_VIA : DRCE_DANGLING_TRACK; VECTOR2I pos; - if( connectivity->TestTrackEndpointDangling( track, &pos ) ) + if( connectivity->TestTrackEndpointDangling( track, true, &pos ) ) { std::shared_ptr drcItem = DRC_ITEM::Create( code ); drcItem->SetItems( track ); diff --git a/pcbnew/tracks_cleaner.cpp b/pcbnew/tracks_cleaner.cpp index 93f8218562..b69a6925a7 100644 --- a/pcbnew/tracks_cleaner.cpp +++ b/pcbnew/tracks_cleaner.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2004-2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -273,7 +273,7 @@ bool TRACKS_CLEANER::deleteDanglingTracks( bool aTrack, bool aVia ) continue; // Test if a track (or a via) endpoint is not connected to another track or zone. - if( m_brd->GetConnectivity()->TestTrackEndpointDangling( track ) ) + if( m_brd->GetConnectivity()->TestTrackEndpointDangling( track, false ) ) { std::shared_ptr item;