Remove the open array in favor of std containers
The containers allow iteration, size knowledge and lower bug surface
This commit is contained in:
parent
2d1fa48a73
commit
b5c2f0d39a
|
@ -1736,13 +1736,13 @@ std::tuple<int, double, double> 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<const BOARD_CONNECTED_ITEM*>( &aTrack ), types ) )
|
||||
static_cast<const BOARD_CONNECTED_ITEM*>( &aTrack ),
|
||||
{ PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T } ) )
|
||||
{
|
||||
count++;
|
||||
|
||||
|
|
|
@ -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<KICAD_T>& 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;
|
||||
|
|
|
@ -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<KICAD_T>& aTypes,
|
||||
int aSingleNet, CN_ITEM* rootItem = nullptr );
|
||||
const CLUSTERS SearchClusters( CLUSTER_SEARCH_MODE aMode );
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <thread>
|
||||
#include <algorithm>
|
||||
#include <future>
|
||||
#include <initializer_list>
|
||||
|
||||
#include <connectivity/connectivity_data.h>
|
||||
#include <connectivity/connectivity_algo.h>
|
||||
|
@ -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<KICAD_T> aTypes,
|
||||
const std::initializer_list<KICAD_T>& 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<BOARD_CONNECTED_ITEM*>
|
||||
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<KICAD_T>& 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<BOARD_CONNECTED_ITEM*> 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<CN_CLUSTER>& cl : clusters )
|
||||
|
|
|
@ -201,7 +201,8 @@ public:
|
|||
unsigned int GetUnconnectedCount() const;
|
||||
|
||||
bool IsConnectedOnLayer( const BOARD_CONNECTED_ITEM* aItem,
|
||||
int aLayer, std::vector<KICAD_T> aTypes = {},
|
||||
int aLayer,
|
||||
const std::initializer_list<KICAD_T>& 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<BOARD_CONNECTED_ITEM*> GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem,
|
||||
const KICAD_T aTypes[], bool aIgnoreNetcodes = false ) const;
|
||||
const std::initializer_list<KICAD_T>& aTypes, bool aIgnoreNetcodes = false ) const;
|
||||
|
||||
/**
|
||||
* Function GetNetItems()
|
||||
|
|
|
@ -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<BOARD_CON
|
|||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -672,9 +672,9 @@ bool DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow()
|
|||
|
||||
for( EDA_ITEM* item : m_items )
|
||||
{
|
||||
const KICAD_T ourTypes[] = { PCB_TRACE_T, PCB_ARC_T, PCB_PAD_T, PCB_VIA_T, PCB_FOOTPRINT_T, EOT };
|
||||
BOARD_CONNECTED_ITEM* boardItem = static_cast<BOARD_CONNECTED_ITEM*>( 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 )
|
||||
{
|
||||
|
|
|
@ -232,7 +232,7 @@ bool PAD::FlashLayer( LSET aLayers ) const
|
|||
|
||||
bool PAD::FlashLayer( int aLayer ) const
|
||||
{
|
||||
std::vector<KICAD_T> types
|
||||
std::initializer_list<KICAD_T> types
|
||||
{ PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, PCB_ZONE_T, PCB_FP_ZONE_T };
|
||||
|
||||
const BOARD* board = GetBoard();
|
||||
|
|
|
@ -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<KICAD_T> connectedTypes = { PCB_TRACE_T, PCB_ARC_T, PCB_PAD_T,
|
||||
PCB_ZONE_T, PCB_FP_ZONE_T };
|
||||
static std::initializer_list<KICAD_T> 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 );
|
||||
}
|
||||
|
|
|
@ -424,9 +424,8 @@ int BOARD_INSPECTION_TOOL::InspectClearance( const TOOL_EVENT& aEvent )
|
|||
minSpokes ) );
|
||||
|
||||
std::shared_ptr<CONNECTIVITY_DATA> 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 )
|
||||
|
|
|
@ -1163,7 +1163,6 @@ int PCB_SELECTION_TOOL::expandConnection( const TOOL_EVENT& aEvent )
|
|||
void PCB_SELECTION_TOOL::selectAllConnectedTracks(
|
||||
const std::vector<BOARD_CONNECTED_ITEM*>& 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<BOARD_CONNECTED_ITEM*> 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 )
|
||||
|
|
|
@ -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_DATA> connectivity = m_brd->GetConnectivity();
|
||||
|
||||
std::vector<BOARD_CONNECTED_ITEM*> tracks = connectivity->GetConnectedItems( aSeg1, items );
|
||||
std::vector<BOARD_CONNECTED_ITEM*> tracks2 = connectivity->GetConnectedItems( aSeg2, items );
|
||||
std::vector<BOARD_CONNECTED_ITEM*> tracks = connectivity->GetConnectedItems( aSeg1,
|
||||
{ PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, PCB_ZONE_T } );
|
||||
std::vector<BOARD_CONNECTED_ITEM*> 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() );
|
||||
|
|
Loading…
Reference in New Issue