7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-03-30 06:36:55 +00:00

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.)
This commit is contained in:
Jeff Young 2025-02-26 10:59:03 +00:00
parent 888cbf8e7a
commit 20f40c1030
9 changed files with 26 additions and 67 deletions

View File

@ -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++;

View File

@ -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 );

View File

@ -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 );
/**

View File

@ -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 )
{

View File

@ -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()

View File

@ -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 )

View File

@ -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 );
}

View File

@ -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 )

View File

@ -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 );
}