From 7b2f2452833abb8cc15b844771d094870ab97a3d Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 26 Nov 2018 22:04:14 -0700 Subject: [PATCH] pcbnew: Tracks cleanup use connectivity database Rather than duplicating the connectivity calculations in determining whether a track is dangling, we utilize the current database to find the number of connected items for an anchor item when feasible. Multiple anchors such as tracks still need additional logic. Fixes: lp:1805479 * https://bugs.launchpad.net/kicad/+bug/1805479 --- pcbnew/connectivity/connectivity_items.cpp | 49 ++++++---------------- pcbnew/connectivity/connectivity_items.h | 5 ++- 2 files changed, 16 insertions(+), 38 deletions(-) diff --git a/pcbnew/connectivity/connectivity_items.cpp b/pcbnew/connectivity/connectivity_items.cpp index 803d19d5da..a39d2adfd6 100644 --- a/pcbnew/connectivity/connectivity_items.cpp +++ b/pcbnew/connectivity/connectivity_items.cpp @@ -253,50 +253,27 @@ bool CN_ANCHOR::IsDangling() const if( !m_cluster ) return true; - // Calculate the item count connected to this anchor. - // m_cluster groups all items connected, but they are not necessary connected - // at this coordinate point (they are only candidates) - BOARD_CONNECTED_ITEM* item_ref = Parent(); - LSET layers = item_ref->GetLayerSet() & LSET::AllCuMask(); - - // the number of items connected to item_ref at ths anchor point - int connected_items_count = 0; - // the minimal number of items connected to item_ref // at this anchor point to decide the anchor is *not* dangling - int minimal_count = 1; + size_t minimal_count = 1; + size_t connected_count = m_item->ConnectedItems().size(); // a via can be removed if connected to only one other item. - // the minimal_count is therefore 2 - if( item_ref->Type() == PCB_VIA_T ) - minimal_count = 2; + if( Parent()->Type() == PCB_VIA_T ) + return connected_count < 2; - for( CN_ITEM* item : *m_cluster ) + 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. + for( auto item : m_item->ConnectedItems() ) { - if( !item->Valid() ) - continue; - - BOARD_CONNECTED_ITEM* brd_item = item->Parent(); - - if( brd_item == item_ref ) - continue; - - // count only items on the same layer at this coordinate (especially for zones) - if( !( brd_item->GetLayerSet() & layers ).any() ) - continue; - - if( brd_item->Type() == PCB_ZONE_AREA_T ) - { - ZONE_CONTAINER* zone = static_cast( brd_item ); - - if( zone->HitTestInsideZone( wxPoint( Pos() ) ) ) - connected_items_count++; - } - else if( brd_item->HitTest( wxPoint( Pos() ) ) ) - connected_items_count++; + if( !item->Parent()->HitTest( wxPoint( Pos().x, Pos().y ) ) ) + connected_count--; } - return connected_items_count < minimal_count; + return connected_count < minimal_count; } diff --git a/pcbnew/connectivity/connectivity_items.h b/pcbnew/connectivity/connectivity_items.h index 40a705a621..b8d63db301 100644 --- a/pcbnew/connectivity/connectivity_items.h +++ b/pcbnew/connectivity/connectivity_items.h @@ -152,11 +152,12 @@ typedef std::vector CN_ANCHORS; // basic connectivity item class CN_ITEM : public INTRUSIVE_LIST { +public: + using CONNECTED_ITEMS = std::set; + private: BOARD_CONNECTED_ITEM* m_parent; - using CONNECTED_ITEMS = std::set; - ///> list of items physically connected (touching) CONNECTED_ITEMS m_connected;