From 20f40c1030405d0be45285196ec1d40902312ad0 Mon Sep 17 00:00:00 2001 From: Jeff Young <jeff@rokeby.ie> Date: Wed, 26 Feb 2025 10:59:03 +0000 Subject: [PATCH] Replace GetConnectedItems() type list with an EXCLUDE_ZONES flag. The type list kept atrophying when various new items were added (arcs, shapes). And god knows what the purpose of putting PCB_FOOTPRINT_T in some of them was. As far as I can tell a CN_ITEMs parent can never be a footprint. (Also moves IGNORE_NETS to a flag so that we don't end up with two booleans and the potential to have them out-of-order.) --- pcbnew/board.cpp | 7 +---- pcbnew/connectivity/connectivity_algo.cpp | 34 +++-------------------- pcbnew/connectivity/connectivity_algo.h | 3 +- pcbnew/connectivity/connectivity_data.cpp | 20 ++++++------- pcbnew/connectivity/connectivity_data.h | 7 +++-- pcbnew/connectivity/from_to_cache.cpp | 4 +-- pcbnew/tools/multichannel_tool.cpp | 8 +++--- pcbnew/tools/pcb_selection_tool.cpp | 2 +- pcbnew/tracks_cleaner.cpp | 8 +----- 9 files changed, 26 insertions(+), 67 deletions(-) diff --git a/pcbnew/board.cpp b/pcbnew/board.cpp index e813ac18cc..85395cad36 100644 --- a/pcbnew/board.cpp +++ b/pcbnew/board.cpp @@ -2392,12 +2392,7 @@ std::tuple<int, double, double> BOARD::GetTrackLength( const PCB_TRACK& aTrack ) BOARD_STACKUP& stackup = GetDesignSettings().GetStackupDescriptor(); bool useHeight = GetDesignSettings().m_UseHeightForLengthCalcs; - static const std::vector<KICAD_T> baseConnectedTypes = { PCB_TRACE_T, - PCB_ARC_T, - PCB_VIA_T, - PCB_PAD_T }; - - for( BOARD_CONNECTED_ITEM* item : connectivity->GetConnectedItems( &aTrack, baseConnectedTypes ) ) + for( BOARD_CONNECTED_ITEM* item : connectivity->GetConnectedItems( &aTrack, EXCLUDE_ZONES ) ) { count++; diff --git a/pcbnew/connectivity/connectivity_algo.cpp b/pcbnew/connectivity/connectivity_algo.cpp index 909b051ca2..dabcba1328 100644 --- a/pcbnew/connectivity/connectivity_algo.cpp +++ b/pcbnew/connectivity/connectivity_algo.cpp @@ -318,27 +318,12 @@ void CN_CONNECTIVITY_ALGO::searchConnections() const CN_CONNECTIVITY_ALGO::CLUSTERS CN_CONNECTIVITY_ALGO::SearchClusters( CLUSTER_SEARCH_MODE aMode ) { - static const std::vector<KICAD_T> withoutZones = { PCB_TRACE_T, - PCB_ARC_T, - PCB_PAD_T, - PCB_VIA_T, - PCB_FOOTPRINT_T, - PCB_SHAPE_T }; - static const std::vector<KICAD_T> withZones = { PCB_TRACE_T, - PCB_ARC_T, - PCB_PAD_T, - PCB_VIA_T, - PCB_ZONE_T, - PCB_FOOTPRINT_T, - PCB_SHAPE_T }; - - return SearchClusters( aMode, aMode == CSM_PROPAGATE ? withoutZones : withZones, -1 ); + return SearchClusters( aMode, ( aMode == CSM_PROPAGATE ), -1 ); } const CN_CONNECTIVITY_ALGO::CLUSTERS -CN_CONNECTIVITY_ALGO::SearchClusters( CLUSTER_SEARCH_MODE aMode, const std::vector<KICAD_T>& aTypes, - int aSingleNet, CN_ITEM* rootItem ) +CN_CONNECTIVITY_ALGO::SearchClusters( CLUSTER_SEARCH_MODE aMode, bool aExcludeZones, int aSingleNet ) { bool withinAnyNet = ( aMode != CSM_PROPAGATE ); @@ -353,7 +338,7 @@ CN_CONNECTIVITY_ALGO::SearchClusters( CLUSTER_SEARCH_MODE aMode, const std::vect std::set<CN_ITEM*> visited; auto addToSearchList = - [&item_set, withinAnyNet, aSingleNet, &aTypes, rootItem]( CN_ITEM *aItem ) + [&item_set, withinAnyNet, aSingleNet, &aExcludeZones]( CN_ITEM *aItem ) { if( withinAnyNet && aItem->Net() <= 0 ) return; @@ -364,18 +349,7 @@ CN_CONNECTIVITY_ALGO::SearchClusters( CLUSTER_SEARCH_MODE aMode, const std::vect if( aSingleNet >=0 && aItem->Net() != aSingleNet ) return; - bool found = false; - - for( KICAD_T type : aTypes ) - { - if( aItem->Parent()->Type() == type ) - { - found = true; - break; - } - } - - if( !found && aItem != rootItem ) + if( aExcludeZones && aItem->Parent()->Type() == PCB_ZONE_T ) return; item_set.insert( aItem ); diff --git a/pcbnew/connectivity/connectivity_algo.h b/pcbnew/connectivity/connectivity_algo.h index 9954f715d7..58bf0ef7d3 100644 --- a/pcbnew/connectivity/connectivity_algo.h +++ b/pcbnew/connectivity/connectivity_algo.h @@ -226,8 +226,7 @@ public: bool Remove( BOARD_ITEM* aItem ); bool Add( BOARD_ITEM* aItem ); - const CLUSTERS SearchClusters( CLUSTER_SEARCH_MODE aMode, const std::vector<KICAD_T>& aTypes, - int aSingleNet, CN_ITEM* rootItem = nullptr ); + const CLUSTERS SearchClusters( CLUSTER_SEARCH_MODE aMode, bool aExcludeZones, int aSingleNet ); const CLUSTERS SearchClusters( CLUSTER_SEARCH_MODE aMode ); /** diff --git a/pcbnew/connectivity/connectivity_data.cpp b/pcbnew/connectivity/connectivity_data.cpp index 7caf68ff60..844e4fda65 100644 --- a/pcbnew/connectivity/connectivity_data.cpp +++ b/pcbnew/connectivity/connectivity_data.cpp @@ -547,20 +547,18 @@ void CONNECTIVITY_DATA::ClearRatsnest() const std::vector<BOARD_CONNECTED_ITEM*> -CONNECTIVITY_DATA::GetConnectedItems( const BOARD_CONNECTED_ITEM *aItem, - const std::vector<KICAD_T>& aTypes, - bool aIgnoreNetcodes ) const +CONNECTIVITY_DATA::GetConnectedItems( const BOARD_CONNECTED_ITEM *aItem, int aFlags ) const { + using CN_CONNECTIVITY_ALGO::CSM_PROPAGATE; + using CN_CONNECTIVITY_ALGO::CSM_CONNECTIVITY_CHECK; + std::vector<BOARD_CONNECTED_ITEM*> rv; - CN_CONNECTIVITY_ALGO::CLUSTER_SEARCH_MODE searchMode; - if( aIgnoreNetcodes ) - searchMode = CN_CONNECTIVITY_ALGO::CSM_PROPAGATE; - else - searchMode = CN_CONNECTIVITY_ALGO::CSM_CONNECTIVITY_CHECK; - - const auto clusters = m_connAlgo->SearchClusters( searchMode, aTypes, - aIgnoreNetcodes ? -1 : aItem->GetNetCode() ); + auto clusters = m_connAlgo->SearchClusters( ( aFlags & IGNORE_NETS ) ? CSM_PROPAGATE + : CSM_CONNECTIVITY_CHECK, + ( aFlags & EXCLUDE_ZONES ), + ( aFlags & IGNORE_NETS ) ? -1 + : aItem->GetNetCode() ); for( const std::shared_ptr<CN_CLUSTER>& cl : clusters ) { diff --git a/pcbnew/connectivity/connectivity_data.h b/pcbnew/connectivity/connectivity_data.h index c4f77de48d..744591a8cc 100644 --- a/pcbnew/connectivity/connectivity_data.h +++ b/pcbnew/connectivity/connectivity_data.h @@ -247,9 +247,10 @@ public: * @param aItem is the reference item to find other connected items. * @param aTypes allows one to filter by item types. */ - const std::vector<BOARD_CONNECTED_ITEM*> - GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem, const std::vector<KICAD_T>& aTypes, - bool aIgnoreNetcodes = false ) const; +#define IGNORE_NETS 0x0001 +#define EXCLUDE_ZONES 0x0002 + const std::vector<BOARD_CONNECTED_ITEM*> GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem, + int aFlags = 0 ) const; /** * Function GetNetItems() diff --git a/pcbnew/connectivity/from_to_cache.cpp b/pcbnew/connectivity/from_to_cache.cpp index efc5e78047..be66d941d6 100644 --- a/pcbnew/connectivity/from_to_cache.cpp +++ b/pcbnew/connectivity/from_to_cache.cpp @@ -144,9 +144,7 @@ int FROM_TO_CACHE::cacheFromToPaths( const wxString& aFrom, const wxString& aTo wxString fromName = path.from->GetParentFootprint()->GetReference() + wxT( "-" ) + path.from->GetNumber(); - auto padCandidates = connectivity->GetConnectedItems( path.from, - { PCB_PAD_T, PCB_ARC_T, PCB_VIA_T, - PCB_TRACE_T } ); + auto padCandidates = connectivity->GetConnectedItems( path.from, EXCLUDE_ZONES ); PAD* toPad = nullptr; for( BOARD_CONNECTED_ITEM* pitem : padCandidates ) diff --git a/pcbnew/tools/multichannel_tool.cpp b/pcbnew/tools/multichannel_tool.cpp index 6f502fb1e7..654a5e73d0 100644 --- a/pcbnew/tools/multichannel_tool.cpp +++ b/pcbnew/tools/multichannel_tool.cpp @@ -576,7 +576,8 @@ wxString MULTICHANNEL_TOOL::stripComponentIndex( const wxString& aRef ) const int MULTICHANNEL_TOOL::findRoutedConnections( std::set<BOARD_ITEM*>& aOutput, std::shared_ptr<CONNECTIVITY_DATA> aConnectivity, - const SHAPE_POLY_SET& aRAPoly, RULE_AREA* aRA, + const SHAPE_POLY_SET& aRAPoly, + RULE_AREA* aRA, FOOTPRINT* aFp, const REPEAT_LAYOUT_OPTIONS& aOpts ) const { @@ -584,10 +585,9 @@ int MULTICHANNEL_TOOL::findRoutedConnections( std::set<BOARD_ITEM*>& for( PAD* pad : aFp->Pads() ) { - const std::vector<BOARD_CONNECTED_ITEM*> connItems = aConnectivity->GetConnectedItems( - pad, { PCB_PAD_T, PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_SHAPE_T }, true ); + auto connectedItems = aConnectivity->GetConnectedItems( pad, EXCLUDE_ZONES | IGNORE_NETS ); - for( BOARD_CONNECTED_ITEM* item : connItems ) + for( BOARD_CONNECTED_ITEM* item : connectedItems ) conns.insert( item ); } diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index fa31cb3d6e..b625813622 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -1509,7 +1509,7 @@ void PCB_SELECTION_TOOL::selectAllConnectedTracks( continue; auto connectedItems = connectivity->GetConnectedItems( startItem, - { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, PCB_SHAPE_T }, true ); + EXCLUDE_ZONES | IGNORE_NETS ); // Build maps of connected items for( BOARD_CONNECTED_ITEM* item : connectedItems ) diff --git a/pcbnew/tracks_cleaner.cpp b/pcbnew/tracks_cleaner.cpp index bb7150a74e..0c7dfcc05b 100644 --- a/pcbnew/tracks_cleaner.cpp +++ b/pcbnew/tracks_cleaner.cpp @@ -624,16 +624,10 @@ void TRACKS_CLEANER::cleanup( bool aDeleteDuplicateVias, bool aDeleteNullSegment const std::vector<BOARD_CONNECTED_ITEM*>& TRACKS_CLEANER::getConnectedItems( PCB_TRACK* aTrack ) { - static const std::vector<KICAD_T> connectedTypes = { PCB_TRACE_T, - PCB_ARC_T, - PCB_VIA_T, - PCB_PAD_T, - PCB_ZONE_T }; - const std::shared_ptr<CONNECTIVITY_DATA>& connectivity = m_brd->GetConnectivity(); if( std::lock_guard lock( m_mutex ); !m_connectedItemsCache.contains( aTrack ) ) - m_connectedItemsCache[aTrack] = connectivity->GetConnectedItems( aTrack, connectedTypes ); + m_connectedItemsCache[aTrack] = connectivity->GetConnectedItems( aTrack ); return m_connectedItemsCache.at( aTrack ); }