diff --git a/pcbnew/connectivity/connectivity_items.cpp b/pcbnew/connectivity/connectivity_items.cpp index 6d1cd7c0b5..0cf1512e6c 100644 --- a/pcbnew/connectivity/connectivity_items.cpp +++ b/pcbnew/connectivity/connectivity_items.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 2016-2018 CERN - * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. * * @author Tomasz Wlostowski * @@ -265,12 +265,20 @@ bool CN_ANCHOR::IsDangling() const if( m_item->AnchorCount() == 1 ) return connected_count < minimal_count; - // Only items with multiple anchors might have additional items connected that we - // should ignore for this calculation. + // Items with multiple anchors have usually items connected to each anchor. + // We want only the item count of this anchor point + connected_count = 0; for( auto item : m_item->ConnectedItems() ) { - if( !item->Parent()->HitTest( wxPoint( Pos().x, Pos().y ) ) ) - connected_count--; + if( item->Parent()->Type() == PCB_ZONE_AREA_T ) + { + ZONE_CONTAINER* zone = static_cast( item->Parent() ); + + if( zone->HitTestFilledArea( wxPoint( Pos().x, Pos().y ) ) ) + connected_count++; + } + else if( item->Parent()->HitTest( wxPoint( Pos().x, Pos().y ) ) ) + connected_count++; } return connected_count < minimal_count; diff --git a/pcbnew/tracks_cleaner.cpp b/pcbnew/tracks_cleaner.cpp index 2a0e3afd67..220015a899 100644 --- a/pcbnew/tracks_cleaner.cpp +++ b/pcbnew/tracks_cleaner.cpp @@ -45,7 +45,7 @@ int GLOBAL_EDIT_TOOL::CleanupTracksAndVias( const TOOL_EVENT& aEvent ) { PCB_EDIT_FRAME* editFrame = getEditFrame(); DIALOG_CLEANUP_TRACKS_AND_VIAS dlg( editFrame ); - + dlg.ShowModal(); return 0; } @@ -223,21 +223,6 @@ bool TRACKS_CLEANER::cleanupVias() } -bool TRACKS_CLEANER::testTrackHasPad( const TRACK* aTrack ) const -{ - auto connectivity = m_brd->GetConnectivity(); - - // Mark track if connected to pads - for( auto pad : connectivity->GetConnectedPads( aTrack ) ) - { - if( pad->HitTest( aTrack->GetStart() ) || pad->HitTest( aTrack->GetEnd() ) ) - return true; - } - - return false; -} - - bool TRACKS_CLEANER::testTrackEndpointDangling( TRACK* aTrack ) { auto connectivity = m_brd->GetConnectivity(); @@ -275,19 +260,16 @@ bool TRACKS_CLEANER::deleteDanglingTracks() do // Iterate when at least one track is deleted { item_erased = false; + // Ensure the connectivity is up to date, especially after removind a dangling segment + m_brd->BuildConnectivity(); for( TRACK* track : m_brd->Tracks() ) { bool flag_erase = false; // Start without a good reason to erase it - if( track->Type() != PCB_TRACE_T ) - continue; - - // if a track endpoint is not connected to a pad, test if - // the endpoint is connected to another track or to a zone. - - if( !testTrackHasPad( track ) ) - flag_erase |= testTrackEndpointDangling( track ); + // Tst if a track (or a via) endpoint is not connected to another track or to a zone. + if( testTrackEndpointDangling( track ) ) + flag_erase = true; if( flag_erase ) { @@ -307,11 +289,12 @@ bool TRACKS_CLEANER::deleteDanglingTracks() * now perhaps is not connected and should be deleted */ item_erased = true; modified = true; - break; } + // Fix me: In dry run we should disable the track to erase and retry with this disabled track + // However the connectivity algo does not handle disabled items. } } - } while( item_erased ); + } while( item_erased ); // A segment was erased: test for some new dangling segments return modified; } diff --git a/pcbnew/tracks_cleaner.h b/pcbnew/tracks_cleaner.h index 8f7909c9be..19885cf982 100644 --- a/pcbnew/tracks_cleaner.h +++ b/pcbnew/tracks_cleaner.h @@ -56,13 +56,6 @@ private: */ bool removeBadTrackSegments(); - /** - * Checks whether the track is connected to a pad - * @param aTrack pointer to the track - * @return true if the track has a pad - */ - bool testTrackHasPad( const TRACK* aTrack ) const; - /** * Removes redundant vias like vias at same location * or on pad through