diff --git a/pcbnew/board.cpp b/pcbnew/board.cpp index 2311f0f87b..a237496dc4 100644 --- a/pcbnew/board.cpp +++ b/pcbnew/board.cpp @@ -1736,13 +1736,13 @@ std::tuple BOARD::GetTrackLength( const PCB_TRACK& aTrack ) double length = 0.0; double package_length = 0.0; - constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, EOT }; auto connectivity = GetBoard()->GetConnectivity(); BOARD_STACKUP& stackup = GetDesignSettings().GetStackupDescriptor(); bool useHeight = GetDesignSettings().m_UseHeightForLengthCalcs; for( BOARD_CONNECTED_ITEM* item : connectivity->GetConnectedItems( - static_cast( &aTrack ), types ) ) + static_cast( &aTrack ), + { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T } ) ) { count++; diff --git a/pcbnew/connectivity/connectivity_algo.cpp b/pcbnew/connectivity/connectivity_algo.cpp index c8f2c49147..9916cbce35 100644 --- a/pcbnew/connectivity/connectivity_algo.cpp +++ b/pcbnew/connectivity/connectivity_algo.cpp @@ -305,20 +305,17 @@ void CN_CONNECTIVITY_ALGO::searchConnections() const CN_CONNECTIVITY_ALGO::CLUSTERS CN_CONNECTIVITY_ALGO::SearchClusters( CLUSTER_SEARCH_MODE aMode ) { - constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_PAD_T, PCB_VIA_T, PCB_ZONE_T, - PCB_FOOTPRINT_T, EOT }; - constexpr KICAD_T no_zones[] = { PCB_TRACE_T, PCB_ARC_T, PCB_PAD_T, PCB_VIA_T, - PCB_FOOTPRINT_T, EOT }; - if( aMode == CSM_PROPAGATE ) - return SearchClusters( aMode, no_zones, -1 ); + return SearchClusters( aMode, + { PCB_TRACE_T, PCB_ARC_T, PCB_PAD_T, PCB_VIA_T, PCB_FOOTPRINT_T }, -1 ); else - return SearchClusters( aMode, types, -1 ); + return SearchClusters( aMode, + { PCB_TRACE_T, PCB_ARC_T, PCB_PAD_T, PCB_VIA_T, PCB_ZONE_T, PCB_FOOTPRINT_T }, -1 ); } const CN_CONNECTIVITY_ALGO::CLUSTERS -CN_CONNECTIVITY_ALGO::SearchClusters( CLUSTER_SEARCH_MODE aMode, const KICAD_T aTypes[], +CN_CONNECTIVITY_ALGO::SearchClusters( CLUSTER_SEARCH_MODE aMode, const std::initializer_list& aTypes, int aSingleNet, CN_ITEM* rootItem ) { bool withinAnyNet = ( aMode != CSM_PROPAGATE ); @@ -345,9 +342,9 @@ CN_CONNECTIVITY_ALGO::SearchClusters( CLUSTER_SEARCH_MODE aMode, const KICAD_T a bool found = false; - for( int i = 0; aTypes[i] != EOT; i++ ) + for( KICAD_T type : aTypes ) { - if( aItem->Parent()->Type() == aTypes[i] ) + if( aItem->Parent()->Type() == type ) { found = true; break; diff --git a/pcbnew/connectivity/connectivity_algo.h b/pcbnew/connectivity/connectivity_algo.h index 97cf76d939..1e7a540f71 100644 --- a/pcbnew/connectivity/connectivity_algo.h +++ b/pcbnew/connectivity/connectivity_algo.h @@ -201,7 +201,8 @@ public: bool Remove( BOARD_ITEM* aItem ); bool Add( BOARD_ITEM* aItem ); - const CLUSTERS SearchClusters( CLUSTER_SEARCH_MODE aMode, const KICAD_T aTypes[], + const CLUSTERS SearchClusters( CLUSTER_SEARCH_MODE aMode, + const std::initializer_list& aTypes, int aSingleNet, CN_ITEM* rootItem = nullptr ); const CLUSTERS SearchClusters( CLUSTER_SEARCH_MODE aMode ); diff --git a/pcbnew/connectivity/connectivity_data.cpp b/pcbnew/connectivity/connectivity_data.cpp index 411e2c5014..e0469c626f 100644 --- a/pcbnew/connectivity/connectivity_data.cpp +++ b/pcbnew/connectivity/connectivity_data.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -390,7 +391,7 @@ void CONNECTIVITY_DATA::PropagateNets( BOARD_COMMIT* aCommit, PROPAGATE_MODE aMo bool CONNECTIVITY_DATA::IsConnectedOnLayer( const BOARD_CONNECTED_ITEM *aItem, int aLayer, - std::vector aTypes, + const std::initializer_list& aTypes, bool aCheckOptionalFlashing ) const { CN_CONNECTIVITY_ALGO::ITEM_MAP_ENTRY &entry = m_connAlgo->ItemEntry( aItem ); @@ -398,10 +399,10 @@ bool CONNECTIVITY_DATA::IsConnectedOnLayer( const BOARD_CONNECTED_ITEM *aItem, i auto matchType = [&]( KICAD_T aItemType ) { - if( aTypes.empty() ) + if( aTypes.size() == 0 ) return true; - return std::count( aTypes.begin(), aTypes.end(), aItemType ) > 0; + return alg::contains( aTypes, aItemType); }; for( CN_ITEM* citem : entry.GetItems() ) @@ -474,12 +475,9 @@ void CONNECTIVITY_DATA::Clear() const std::vector -CONNECTIVITY_DATA::GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem, const KICAD_T aTypes[], - bool aIgnoreNetcodes ) const +CONNECTIVITY_DATA::GetConnectedItems( const BOARD_CONNECTED_ITEM *aItem, + const std::initializer_list& aTypes, bool aIgnoreNetcodes ) const { - constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_PAD_T, PCB_VIA_T, PCB_ZONE_T, - PCB_FOOTPRINT_T, EOT }; - std::vector rv; CN_CONNECTIVITY_ALGO::CLUSTER_SEARCH_MODE searchMode; @@ -488,7 +486,7 @@ CONNECTIVITY_DATA::GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem, const K else searchMode = CN_CONNECTIVITY_ALGO::CSM_CONNECTIVITY_CHECK; - const auto clusters = m_connAlgo->SearchClusters( searchMode, types, + const auto clusters = m_connAlgo->SearchClusters( searchMode, aTypes, aIgnoreNetcodes ? -1 : aItem->GetNetCode() ); for( const std::shared_ptr& cl : clusters ) diff --git a/pcbnew/connectivity/connectivity_data.h b/pcbnew/connectivity/connectivity_data.h index 96c4af534f..3ef5548c93 100644 --- a/pcbnew/connectivity/connectivity_data.h +++ b/pcbnew/connectivity/connectivity_data.h @@ -201,7 +201,8 @@ public: unsigned int GetUnconnectedCount() const; bool IsConnectedOnLayer( const BOARD_CONNECTED_ITEM* aItem, - int aLayer, std::vector aTypes = {}, + int aLayer, + const std::initializer_list& aTypes = {}, bool aCheckOptionalFlashing = false ) const; unsigned int GetNodeCount( int aNet = -1 ) const; @@ -267,7 +268,7 @@ public: * @param aTypes allows one to filter by item types. */ const std::vector GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem, - const KICAD_T aTypes[], bool aIgnoreNetcodes = false ) const; + const std::initializer_list& aTypes, bool aIgnoreNetcodes = false ) const; /** * Function GetNetItems() diff --git a/pcbnew/connectivity/from_to_cache.cpp b/pcbnew/connectivity/from_to_cache.cpp index 2c17cc2fd8..a31eb396ab 100644 --- a/pcbnew/connectivity/from_to_cache.cpp +++ b/pcbnew/connectivity/from_to_cache.cpp @@ -145,9 +145,8 @@ int FROM_TO_CACHE::cacheFromToPaths( const wxString& aFrom, const wxString& aTo wxString fromName = path.from->GetParent()->GetReference() + wxT( "-" ) + path.from->GetNumber(); - const KICAD_T onlyRouting[] = { PCB_PAD_T, PCB_ARC_T, PCB_VIA_T, PCB_TRACE_T, EOT }; - - auto padCandidates = connectivity->GetConnectedItems( path.from, onlyRouting ); + auto padCandidates = connectivity->GetConnectedItems( path.from, + { PCB_PAD_T, PCB_ARC_T, PCB_VIA_T, PCB_TRACE_T } ); PAD* toPad = nullptr; for( BOARD_CONNECTED_ITEM* pitem : padCandidates ) @@ -280,4 +279,4 @@ FROM_TO_CACHE::FT_PATH* FROM_TO_CACHE::QueryFromToPath( const std::set( item ); - auto connectedItems = connectivity->GetConnectedItems( boardItem, ourTypes, true ); + auto connectedItems = connectivity->GetConnectedItems( boardItem, + { PCB_TRACE_T, PCB_ARC_T, PCB_PAD_T, PCB_VIA_T, PCB_FOOTPRINT_T }, true ); for ( BOARD_CONNECTED_ITEM* citem : connectedItems ) { diff --git a/pcbnew/pad.cpp b/pcbnew/pad.cpp index fd18c99eba..97f178f68e 100644 --- a/pcbnew/pad.cpp +++ b/pcbnew/pad.cpp @@ -232,7 +232,7 @@ bool PAD::FlashLayer( LSET aLayers ) const bool PAD::FlashLayer( int aLayer ) const { - std::vector types + std::initializer_list types { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, PCB_ZONE_T, PCB_FP_ZONE_T }; const BOARD* board = GetBoard(); diff --git a/pcbnew/pcb_track.cpp b/pcbnew/pcb_track.cpp index e6bd394aa5..70ae0eb2a2 100644 --- a/pcbnew/pcb_track.cpp +++ b/pcbnew/pcb_track.cpp @@ -545,8 +545,8 @@ bool PCB_VIA::FlashLayer( int aLayer ) const return true; // Must be static to keep from raising its ugly head in performance profiles - static std::vector connectedTypes = { PCB_TRACE_T, PCB_ARC_T, PCB_PAD_T, - PCB_ZONE_T, PCB_FP_ZONE_T }; + static std::initializer_list connectedTypes = { PCB_TRACE_T, PCB_ARC_T, PCB_PAD_T, + PCB_ZONE_T, PCB_FP_ZONE_T }; return board->GetConnectivity()->IsConnectedOnLayer( this, aLayer, connectedTypes, true ); } diff --git a/pcbnew/tools/board_inspection_tool.cpp b/pcbnew/tools/board_inspection_tool.cpp index feb41bbc59..c36c3fb8d7 100644 --- a/pcbnew/tools/board_inspection_tool.cpp +++ b/pcbnew/tools/board_inspection_tool.cpp @@ -424,9 +424,8 @@ int BOARD_INSPECTION_TOOL::InspectClearance( const TOOL_EVENT& aEvent ) minSpokes ) ); std::shared_ptr connectivity = pad->GetBoard()->GetConnectivity(); - const KICAD_T zones[] = { PCB_ZONE_T, EOT }; - if( !alg::contains( connectivity->GetConnectedItems( pad, zones ), zone ) ) + if( !alg::contains( connectivity->GetConnectedItems( pad, { PCB_ZONE_T } ), zone ) ) r->Report( _( "Items are not connected. No thermal spokes will be generated." ) ); } else if( constraint.m_ZoneConnection == ZONE_CONNECTION::NONE ) diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index 8e8b880c1e..8189064d0d 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -1163,7 +1163,6 @@ int PCB_SELECTION_TOOL::expandConnection( const TOOL_EVENT& aEvent ) void PCB_SELECTION_TOOL::selectAllConnectedTracks( const std::vector& aStartItems, STOP_CONDITION aStopCondition ) { - constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, EOT }; const LSET allCuMask = LSET::AllCuMask(); PROF_TIMER refreshTimer; @@ -1191,8 +1190,8 @@ void PCB_SELECTION_TOOL::selectAllConnectedTracks( if( startItem->HasFlag( SKIP_STRUCT ) ) // Skip already visited items continue; - std::vector connectedItems = - connectivity->GetConnectedItems( startItem, types, true ); + auto connectedItems = connectivity->GetConnectedItems( startItem, + { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T }, true ); // Build maps of connected items for( BOARD_CONNECTED_ITEM* item : connectedItems ) diff --git a/pcbnew/tracks_cleaner.cpp b/pcbnew/tracks_cleaner.cpp index 600ebc901e..85ce8edf58 100644 --- a/pcbnew/tracks_cleaner.cpp +++ b/pcbnew/tracks_cleaner.cpp @@ -461,15 +461,15 @@ void TRACKS_CLEANER::cleanup( bool aDeleteDuplicateVias, bool aDeleteNullSegment bool TRACKS_CLEANER::mergeCollinearSegments( PCB_TRACK* aSeg1, PCB_TRACK* aSeg2 ) { - KICAD_T items[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, PCB_ZONE_T }; - if( aSeg1->IsLocked() || aSeg2->IsLocked() ) return false; std::shared_ptr connectivity = m_brd->GetConnectivity(); - std::vector tracks = connectivity->GetConnectedItems( aSeg1, items ); - std::vector tracks2 = connectivity->GetConnectedItems( aSeg2, items ); + std::vector tracks = connectivity->GetConnectedItems( aSeg1, + { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, PCB_ZONE_T } ); + std::vector tracks2 = connectivity->GetConnectedItems( aSeg2, + { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, PCB_ZONE_T } ); std::move( tracks2.begin(), tracks2.end(), std::back_inserter( tracks ) ); std::sort( tracks.begin(), tracks.end() );