KiCad PCB EDA Suite
CN_CONNECTIVITY_ALGO Class Reference

#include <connectivity_algo.h>

Classes

class  ITEM_MAP_ENTRY
 

Public Types

enum  CLUSTER_SEARCH_MODE { CSM_PROPAGATE, CSM_CONNECTIVITY_CHECK, CSM_RATSNEST }
 
using CLUSTERS = std::vector< CN_CLUSTER_PTR >
 

Public Member Functions

 CN_CONNECTIVITY_ALGO ()
 
 ~CN_CONNECTIVITY_ALGO ()
 
bool ItemExists (const BOARD_CONNECTED_ITEM *aItem)
 
ITEM_MAP_ENTRYItemEntry (const BOARD_CONNECTED_ITEM *aItem)
 
bool IsNetDirty (int aNet) const
 
void ClearDirtyFlags ()
 
void GetDirtyClusters (CLUSTERS &aClusters)
 
int NetCount () const
 
void Build (BOARD *aBoard)
 
void Build (const std::vector< BOARD_ITEM * > &aItems)
 
void Clear ()
 
bool Remove (BOARD_ITEM *aItem)
 
bool Add (BOARD_ITEM *aItem)
 
const CLUSTERS SearchClusters (CLUSTER_SEARCH_MODE aMode, const KICAD_T aTypes[], int aSingleNet)
 
const CLUSTERS SearchClusters (CLUSTER_SEARCH_MODE aMode)
 
void PropagateNets ()
 
void FindIsolatedCopperIslands (ZONE_CONTAINER *aZone, std::vector< int > &aIslands)
 
void FindIsolatedCopperIslands (std::vector< CN_ZONE_ISOLATED_ISLAND_LIST > &aZones)
 Finds the copper islands that are not connected to a net. More...
 
bool CheckConnectivity (std::vector< CN_DISJOINT_NET_ENTRY > &aReport)
 
const CLUSTERSGetClusters ()
 
int GetUnconnectedCount ()
 
CN_LISTItemList ()
 
void ForEachAnchor (const std::function< void(CN_ANCHOR &)> &aFunc)
 
void ForEachItem (const std::function< void(CN_ITEM &)> &aFunc)
 
void MarkNetAsDirty (int aNet)
 
void SetProgressReporter (PROGRESS_REPORTER *aReporter)
 

Private Member Functions

void searchConnections ()
 
void update ()
 
void propagateConnections ()
 
template<class Container , class BItem >
void add (Container &c, BItem brditem)
 
void markItemNetAsDirty (const BOARD_ITEM *aItem)
 

Private Attributes

CN_LIST m_itemList
 
std::unordered_map< const BOARD_CONNECTED_ITEM *, ITEM_MAP_ENTRYm_itemMap
 
CLUSTERS m_connClusters
 
CLUSTERS m_ratsnestClusters
 
std::vector< bool > m_dirtyNets
 
PROGRESS_REPORTERm_progressReporter = nullptr
 

Detailed Description

Definition at line 102 of file connectivity_algo.h.

Member Typedef Documentation

◆ CLUSTERS

Definition at line 112 of file connectivity_algo.h.

Member Enumeration Documentation

◆ CLUSTER_SEARCH_MODE

Constructor & Destructor Documentation

◆ CN_CONNECTIVITY_ALGO()

CN_CONNECTIVITY_ALGO::CN_CONNECTIVITY_ALGO ( )
inline

Definition at line 172 of file connectivity_algo.h.

172 {}

◆ ~CN_CONNECTIVITY_ALGO()

CN_CONNECTIVITY_ALGO::~CN_CONNECTIVITY_ALGO ( )
inline

Definition at line 173 of file connectivity_algo.h.

173 { Clear(); }

References Clear().

Member Function Documentation

◆ add()

template<class Container , class BItem >
void CN_CONNECTIVITY_ALGO::add ( Container &  c,
BItem  brditem 
)
inlineprivate

Definition at line 161 of file connectivity_algo.h.

162  {
163  auto item = c.Add( brditem );
164 
165  m_itemMap[ brditem ] = ITEM_MAP_ENTRY( item );
166  }
std::unordered_map< const BOARD_CONNECTED_ITEM *, ITEM_MAP_ENTRY > m_itemMap

References m_itemMap.

Referenced by Add().

◆ Add()

bool CN_CONNECTIVITY_ALGO::Add ( BOARD_ITEM aItem)

Definition at line 112 of file connectivity_algo.cpp.

113 {
114  if( !IsCopperLayer( aItem->GetLayer() ) )
115  return false;
116 
117  markItemNetAsDirty ( aItem );
118 
119  switch( aItem->Type() )
120  {
121  case PCB_NETINFO_T:
122  {
123  MarkNetAsDirty( static_cast<NETINFO_ITEM*>( aItem )->GetNet() );
124  break;
125  }
126  case PCB_MODULE_T:
127  for( auto pad : static_cast<MODULE*>( aItem ) -> Pads() )
128  {
129  if( m_itemMap.find( pad ) != m_itemMap.end() )
130  return false;
131 
132  add( m_itemList, pad );
133  }
134 
135  break;
136 
137  case PCB_PAD_T:
138  if( m_itemMap.find ( static_cast<D_PAD*>( aItem ) ) != m_itemMap.end() )
139  return false;
140 
141  add( m_itemList, static_cast<D_PAD*>( aItem ) );
142 
143  break;
144 
145  case PCB_TRACE_T:
146  {
147  if( m_itemMap.find( static_cast<TRACK*>( aItem ) ) != m_itemMap.end() )
148  return false;
149 
150  add( m_itemList, static_cast<TRACK*>( aItem ) );
151 
152  break;
153  }
154 
155  case PCB_VIA_T:
156  if( m_itemMap.find( static_cast<VIA*>( aItem ) ) != m_itemMap.end() )
157  return false;
158 
159  add( m_itemList, static_cast<VIA*>( aItem ) );
160 
161  break;
162 
163  case PCB_ZONE_AREA_T:
164  {
165  auto zone = static_cast<ZONE_CONTAINER*>( aItem );
166 
167  if( m_itemMap.find( static_cast<ZONE_CONTAINER*>( aItem ) ) != m_itemMap.end() )
168  return false;
169 
170  m_itemMap[zone] = ITEM_MAP_ENTRY();
171 
172  for( auto zitem : m_itemList.Add( zone ) )
173  m_itemMap[zone].Link(zitem);
174 
175  break;
176  }
177 
178  default:
179  return false;
180  }
181 
182  return true;
183 }
CN_ITEM * Add(D_PAD *pad)
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:100
void MarkNetAsDirty(int aNet)
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
void add(Container &c, BItem brditem)
std::unordered_map< const BOARD_CONNECTED_ITEM *, ITEM_MAP_ENTRY > m_itemMap
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
class MODULE, a footprint
Definition: typeinfo.h:89
void markItemNetAsDirty(const BOARD_ITEM *aItem)
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:102
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204

References add(), CN_LIST::Add(), BOARD_ITEM::GetLayer(), IsCopperLayer(), m_itemList, m_itemMap, markItemNetAsDirty(), MarkNetAsDirty(), PCB_MODULE_T, PCB_NETINFO_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_T, and EDA_ITEM::Type().

Referenced by Build(), and FindIsolatedCopperIslands().

◆ Build() [1/2]

void CN_CONNECTIVITY_ALGO::Build ( BOARD aBoard)

Definition at line 395 of file connectivity_algo.cpp.

396 {
397  for( int i = 0; i<aBoard->GetAreaCount(); i++ )
398  {
399  auto zone = aBoard->GetArea( i );
400  Add( zone );
401  }
402 
403  for( auto tv : aBoard->Tracks() )
404  Add( tv );
405 
406  for( auto mod : aBoard->Modules() )
407  {
408  for( auto pad : mod->Pads() )
409  Add( pad );
410  }
411 
412  /*wxLogTrace( "CN", "zones : %lu, pads : %lu vias : %lu tracks : %lu\n",
413  m_zoneList.Size(), m_padList.Size(),
414  m_viaList.Size(), m_trackList.Size() );*/
415 }
bool Add(BOARD_ITEM *aItem)
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:981
DLIST_ITERATOR_WRAPPER< MODULE > Modules()
Definition: class_board.h:252
size_t i
Definition: json11.cpp:597
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
Definition: class_board.h:251
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:952
#define mod(a, n)
Definition: greymap.cpp:24

References Add(), BOARD::GetArea(), BOARD::GetAreaCount(), i, mod, BOARD::Modules(), and BOARD::Tracks().

◆ Build() [2/2]

void CN_CONNECTIVITY_ALGO::Build ( const std::vector< BOARD_ITEM * > &  aItems)

Definition at line 418 of file connectivity_algo.cpp.

419 {
420  for( auto item : aItems )
421  {
422  switch( item->Type() )
423  {
424  case PCB_TRACE_T:
425  case PCB_VIA_T:
426  case PCB_PAD_T:
427  Add( item );
428  break;
429 
430  case PCB_MODULE_T:
431  {
432  for( auto pad : static_cast<MODULE*>( item )->Pads() )
433  {
434  Add( pad );
435  }
436 
437  break;
438  }
439 
440  default:
441  break;
442  }
443  }
444 }
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
bool Add(BOARD_ITEM *aItem)
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
class MODULE, a footprint
Definition: typeinfo.h:89
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96

References Add(), PCB_MODULE_T, PCB_PAD_T, PCB_TRACE_T, and PCB_VIA_T.

◆ CheckConnectivity()

bool CN_CONNECTIVITY_ALGO::CheckConnectivity ( std::vector< CN_DISJOINT_NET_ENTRY > &  aReport)

◆ Clear()

void CN_CONNECTIVITY_ALGO::Clear ( )

Definition at line 709 of file connectivity_algo.cpp.

710 {
711  m_ratsnestClusters.clear();
712  m_connClusters.clear();
713  m_itemMap.clear();
714  m_itemList.Clear();
715 
716 }
std::unordered_map< const BOARD_CONNECTED_ITEM *, ITEM_MAP_ENTRY > m_itemMap

References CN_LIST::Clear(), m_connClusters, m_itemList, m_itemMap, and m_ratsnestClusters.

Referenced by ~CN_CONNECTIVITY_ALGO().

◆ ClearDirtyFlags()

void CN_CONNECTIVITY_ALGO::ClearDirtyFlags ( )
inline

Definition at line 193 of file connectivity_algo.h.

194  {
195  for( auto i = m_dirtyNets.begin(); i != m_dirtyNets.end(); ++i )
196  *i = false;
197  }
std::vector< bool > m_dirtyNets
size_t i
Definition: json11.cpp:597

References i, and m_dirtyNets.

◆ FindIsolatedCopperIslands() [1/2]

void CN_CONNECTIVITY_ALGO::FindIsolatedCopperIslands ( ZONE_CONTAINER aZone,
std::vector< int > &  aIslands 
)

Definition at line 501 of file connectivity_algo.cpp.

502 {
503  if( aZone->GetFilledPolysList().IsEmpty() )
504  return;
505 
506  aIslands.clear();
507 
508  Remove( aZone );
509  Add( aZone );
510 
512 
513  for( const auto& cluster : m_connClusters )
514  {
515  if( cluster->Contains( aZone ) && cluster->IsOrphaned() )
516  {
517  for( auto z : *cluster )
518  {
519  if( z->Parent() == aZone )
520  {
521  aIslands.push_back( static_cast<CN_ZONE*>(z)->SubpolyIndex() );
522  }
523  }
524  }
525  }
526 
527  wxLogTrace( "CN", "Found %u isolated islands\n", (unsigned)aIslands.size() );
528 }
bool Remove(BOARD_ITEM *aItem)
bool IsEmpty() const
Returns true if the set is empty (no polygons at all)
bool Add(BOARD_ITEM *aItem)
const CLUSTERS SearchClusters(CLUSTER_SEARCH_MODE aMode, const KICAD_T aTypes[], int aSingleNet)
const SHAPE_POLY_SET & GetFilledPolysList() const
Function GetFilledPolysList returns a reference to the list of filled polygons.
Definition: class_zone.h:580

References Add(), CSM_CONNECTIVITY_CHECK, ZONE_CONTAINER::GetFilledPolysList(), SHAPE_POLY_SET::IsEmpty(), m_connClusters, Remove(), and SearchClusters().

◆ FindIsolatedCopperIslands() [2/2]

void CN_CONNECTIVITY_ALGO::FindIsolatedCopperIslands ( std::vector< CN_ZONE_ISOLATED_ISLAND_LIST > &  aZones)

Finds the copper islands that are not connected to a net.

These are added to the m_islands vector. N.B. This must be called after aZones has been refreshed.

Parameters
aZones The set of zones to search for islands

Definition at line 530 of file connectivity_algo.cpp.

531 {
532  for ( auto& z : aZones )
533  Remove( z.m_zone );
534 
535  for ( auto& z : aZones )
536  {
537  if( !z.m_zone->GetFilledPolysList().IsEmpty() )
538  Add( z.m_zone );
539  }
540 
542 
543  for ( auto& zone : aZones )
544  {
545  if( zone.m_zone->GetFilledPolysList().IsEmpty() )
546  continue;
547 
548  for( const auto& cluster : m_connClusters )
549  {
550  if( cluster->Contains( zone.m_zone ) && cluster->IsOrphaned() )
551  {
552  for( auto z : *cluster )
553  {
554  if( z->Parent() == zone.m_zone )
555  {
556  zone.m_islands.push_back( static_cast<CN_ZONE*>(z)->SubpolyIndex() );
557  }
558  }
559  }
560  }
561  }
562 }
bool Remove(BOARD_ITEM *aItem)
bool Add(BOARD_ITEM *aItem)
const CLUSTERS SearchClusters(CLUSTER_SEARCH_MODE aMode, const KICAD_T aTypes[], int aSingleNet)

References Add(), CSM_CONNECTIVITY_CHECK, m_connClusters, Remove(), and SearchClusters().

◆ ForEachAnchor()

void CN_CONNECTIVITY_ALGO::ForEachAnchor ( const std::function< void(CN_ANCHOR &)> &  aFunc)

Definition at line 726 of file connectivity_algo.cpp.

727 {
728  ForEachItem( [aFunc] ( CN_ITEM& item ) {
729  for( const auto& anchor : item.Anchors() )
730  aFunc( *anchor );
731  }
732  );
733 }
CN_ANCHORS & Anchors()
void ForEachItem(const std::function< void(CN_ITEM &)> &aFunc)

References CN_ITEM::Anchors(), and ForEachItem().

◆ ForEachItem()

void CN_CONNECTIVITY_ALGO::ForEachItem ( const std::function< void(CN_ITEM &)> &  aFunc)

Definition at line 719 of file connectivity_algo.cpp.

720 {
721  for( auto item : m_itemList )
722  aFunc( *item );
723 }

References m_itemList.

Referenced by ForEachAnchor().

◆ GetClusters()

const CN_CONNECTIVITY_ALGO::CLUSTERS & CN_CONNECTIVITY_ALGO::GetClusters ( )

Definition at line 565 of file connectivity_algo.cpp.

566 {
568  return m_ratsnestClusters;
569 }
const CLUSTERS SearchClusters(CLUSTER_SEARCH_MODE aMode, const KICAD_T aTypes[], int aSingleNet)

References CSM_RATSNEST, m_ratsnestClusters, and SearchClusters().

◆ GetDirtyClusters()

void CN_CONNECTIVITY_ALGO::GetDirtyClusters ( CLUSTERS aClusters)
inline

Definition at line 199 of file connectivity_algo.h.

200  {
201  for( auto cl : m_ratsnestClusters )
202  {
203  int net = cl->OriginNet();
204 
205  if( net >= 0 && m_dirtyNets[net] )
206  aClusters.push_back( cl );
207  }
208  }
std::vector< bool > m_dirtyNets

References m_dirtyNets, and m_ratsnestClusters.

◆ GetUnconnectedCount()

int CN_CONNECTIVITY_ALGO::GetUnconnectedCount ( )

◆ IsNetDirty()

bool CN_CONNECTIVITY_ALGO::IsNetDirty ( int  aNet) const
inline

Definition at line 185 of file connectivity_algo.h.

186  {
187  if( aNet < 0 )
188  return false;
189 
190  return m_dirtyNets[ aNet ];
191  }
std::vector< bool > m_dirtyNets

References m_dirtyNets.

◆ ItemEntry()

ITEM_MAP_ENTRY& CN_CONNECTIVITY_ALGO::ItemEntry ( const BOARD_CONNECTED_ITEM aItem)
inline

Definition at line 180 of file connectivity_algo.h.

181  {
182  return m_itemMap[ aItem ];
183  }
std::unordered_map< const BOARD_CONNECTED_ITEM *, ITEM_MAP_ENTRY > m_itemMap

References m_itemMap.

◆ ItemExists()

bool CN_CONNECTIVITY_ALGO::ItemExists ( const BOARD_CONNECTED_ITEM aItem)
inline

Definition at line 175 of file connectivity_algo.h.

176  {
177  return m_itemMap.find( aItem ) != m_itemMap.end();
178  }
std::unordered_map< const BOARD_CONNECTED_ITEM *, ITEM_MAP_ENTRY > m_itemMap

References m_itemMap.

◆ ItemList()

CN_LIST& CN_CONNECTIVITY_ALGO::ItemList ( )
inline

Definition at line 242 of file connectivity_algo.h.

242 { return m_itemList; }

References m_itemList.

◆ markItemNetAsDirty()

void CN_CONNECTIVITY_ALGO::markItemNetAsDirty ( const BOARD_ITEM aItem)
private

Definition at line 92 of file connectivity_algo.cpp.

93 {
94  if( aItem->IsConnected() )
95  {
96  auto citem = static_cast<const BOARD_CONNECTED_ITEM*>( aItem );
97  MarkNetAsDirty( citem->GetNetCode() );
98  }
99  else
100  {
101  if( aItem->Type() == PCB_MODULE_T )
102  {
103  auto mod = static_cast <const MODULE*>( aItem );
104 
105  for( D_PAD* pad = mod->PadsList(); pad; pad = pad->Next() )
106  MarkNetAsDirty( pad->GetNetCode() );
107  }
108  }
109 }
void MarkNetAsDirty(int aNet)
class MODULE, a footprint
Definition: typeinfo.h:89
virtual bool IsConnected() const
Function IsConnected() Returns information if the object is derived from BOARD_CONNECTED_ITEM.
#define mod(a, n)
Definition: greymap.cpp:24
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204

References BOARD_ITEM::IsConnected(), MarkNetAsDirty(), mod, PCB_MODULE_T, and EDA_ITEM::Type().

Referenced by Add(), and Remove().

◆ MarkNetAsDirty()

void CN_CONNECTIVITY_ALGO::MarkNetAsDirty ( int  aNet)

Definition at line 572 of file connectivity_algo.cpp.

573 {
574  if( aNet < 0 )
575  return;
576 
577  if( (int) m_dirtyNets.size() <= aNet )
578  {
579  int lastNet = m_dirtyNets.size() - 1;
580 
581  if( lastNet < 0 )
582  lastNet = 0;
583 
584  m_dirtyNets.resize( aNet + 1 );
585 
586  for( int i = lastNet; i < aNet + 1; i++ )
587  m_dirtyNets[i] = true;
588  }
589 
590  m_dirtyNets[aNet] = true;
591 }
std::vector< bool > m_dirtyNets
size_t i
Definition: json11.cpp:597

References i, and m_dirtyNets.

Referenced by Add(), markItemNetAsDirty(), and propagateConnections().

◆ NetCount()

int CN_CONNECTIVITY_ALGO::NetCount ( ) const
inline

Definition at line 210 of file connectivity_algo.h.

211  {
212  return m_dirtyNets.size();
213  }
std::vector< bool > m_dirtyNets

References m_dirtyNets.

◆ propagateConnections()

void CN_CONNECTIVITY_ALGO::propagateConnections ( )
private

Definition at line 447 of file connectivity_algo.cpp.

448 {
449  for( const auto& cluster : m_connClusters )
450  {
451  if( cluster->IsConflicting() )
452  {
453  wxLogTrace( "CN", "Conflicting nets in cluster %p\n", cluster.get() );
454  }
455  else if( cluster->IsOrphaned() )
456  {
457  wxLogTrace( "CN", "Skipping orphaned cluster %p [net: %s]\n", cluster.get(),
458  (const char*) cluster->OriginNetName().c_str() );
459  }
460  else if( cluster->HasValidNet() )
461  {
462  // normal cluster: just propagate from the pads
463  int n_changed = 0;
464 
465  for( auto item : *cluster )
466  {
467  if( item->CanChangeNet() )
468  {
469  if( item->Valid() && item->Parent()->GetNetCode() != cluster->OriginNet() )
470  {
471  MarkNetAsDirty( item->Parent()->GetNetCode() );
472  MarkNetAsDirty( cluster->OriginNet() );
473 
474  item->Parent()->SetNetCode( cluster->OriginNet() );
475  n_changed++;
476  }
477  }
478  }
479 
480  if( n_changed )
481  wxLogTrace( "CN", "Cluster %p : net : %d %s\n", cluster.get(),
482  cluster->OriginNet(), (const char*) cluster->OriginNetName().c_str() );
483  else
484  wxLogTrace( "CN", "Cluster %p : nothing to propagate\n", cluster.get() );
485  }
486  else
487  {
488  wxLogTrace( "CN", "Cluster %p : connected to unused net\n", cluster.get() );
489  }
490  }
491 }
void MarkNetAsDirty(int aNet)

References m_connClusters, and MarkNetAsDirty().

Referenced by PropagateNets().

◆ PropagateNets()

void CN_CONNECTIVITY_ALGO::PropagateNets ( )

Definition at line 494 of file connectivity_algo.cpp.

495 {
498 }
const CLUSTERS SearchClusters(CLUSTER_SEARCH_MODE aMode, const KICAD_T aTypes[], int aSingleNet)

References CSM_PROPAGATE, m_connClusters, propagateConnections(), and SearchClusters().

◆ Remove()

bool CN_CONNECTIVITY_ALGO::Remove ( BOARD_ITEM aItem)

Definition at line 39 of file connectivity_algo.cpp.

40 {
41  markItemNetAsDirty( aItem );
42 
43  switch( aItem->Type() )
44  {
45  case PCB_MODULE_T:
46  for( auto pad : static_cast<MODULE*>( aItem ) -> Pads() )
47  {
48  m_itemMap[ static_cast<BOARD_CONNECTED_ITEM*>( pad ) ].MarkItemsAsInvalid();
49  m_itemMap.erase( static_cast<BOARD_CONNECTED_ITEM*>( pad ) );
50  }
51 
52  m_itemList.SetDirty( true );
53  break;
54 
55  case PCB_PAD_T:
56  m_itemMap[ static_cast<BOARD_CONNECTED_ITEM*>( aItem ) ].MarkItemsAsInvalid();
57  m_itemMap.erase( static_cast<BOARD_CONNECTED_ITEM*>( aItem ) );
58  m_itemList.SetDirty( true );
59  break;
60 
61  case PCB_TRACE_T:
62  m_itemMap[ static_cast<BOARD_CONNECTED_ITEM*>( aItem ) ].MarkItemsAsInvalid();
63  m_itemMap.erase( static_cast<BOARD_CONNECTED_ITEM*>( aItem ) );
64  m_itemList.SetDirty( true );
65  break;
66 
67  case PCB_VIA_T:
68  m_itemMap[ static_cast<BOARD_CONNECTED_ITEM*>( aItem ) ].MarkItemsAsInvalid();
69  m_itemMap.erase( static_cast<BOARD_CONNECTED_ITEM*>( aItem ) );
70  m_itemList.SetDirty( true );
71  break;
72 
73  case PCB_ZONE_AREA_T:
74  {
75  m_itemMap[ static_cast<BOARD_CONNECTED_ITEM*>( aItem ) ].MarkItemsAsInvalid();
76  m_itemMap.erase ( static_cast<BOARD_CONNECTED_ITEM*>( aItem ) );
77  m_itemList.SetDirty( true );
78  break;
79  }
80 
81  default:
82  return false;
83  }
84 
85  // Once we delete an item, it may connect between lists, so mark both as potentially invalid
86  m_itemList.SetHasInvalid( true );
87 
88  return true;
89 }
void SetHasInvalid(bool aInvalid=true)
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:100
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
std::unordered_map< const BOARD_CONNECTED_ITEM *, ITEM_MAP_ENTRY > m_itemMap
void SetDirty(bool aDirty=true)
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
class MODULE, a footprint
Definition: typeinfo.h:89
void markItemNetAsDirty(const BOARD_ITEM *aItem)
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204

References m_itemList, m_itemMap, markItemNetAsDirty(), PCB_MODULE_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_T, CN_LIST::SetDirty(), CN_LIST::SetHasInvalid(), and EDA_ITEM::Type().

Referenced by FindIsolatedCopperIslands().

◆ SearchClusters() [1/2]

const CN_CONNECTIVITY_ALGO::CLUSTERS CN_CONNECTIVITY_ALGO::SearchClusters ( CLUSTER_SEARCH_MODE  aMode,
const KICAD_T  aTypes[],
int  aSingleNet 
)

Definition at line 292 of file connectivity_algo.cpp.

294 {
295  bool withinAnyNet = ( aMode != CSM_PROPAGATE );
296 
297  std::deque<CN_ITEM*> Q;
298  CN_ITEM* head = nullptr;
299  CLUSTERS clusters;
300 
301  if( m_itemList.IsDirty() )
303 
304  auto addToSearchList = [&head, withinAnyNet, aSingleNet, aTypes] ( CN_ITEM *aItem )
305  {
306  if( withinAnyNet && aItem->Net() <= 0 )
307  return;
308 
309  if( !aItem->Valid() )
310  return;
311 
312  if( aSingleNet >=0 && aItem->Net() != aSingleNet )
313  return;
314 
315  bool found = false;
316 
317  for( int i = 0; aTypes[i] != EOT; i++ )
318  {
319  if( aItem->Parent()->Type() == aTypes[i] )
320  {
321  found = true;
322  break;
323  }
324  }
325 
326  if( !found )
327  return;
328 
329  aItem->ListClear();
330  aItem->SetVisited( false );
331 
332  if( !head )
333  head = aItem;
334  else
335  head->ListInsert( aItem );
336  };
337 
338  std::for_each( m_itemList.begin(), m_itemList.end(), addToSearchList );
339 
340  while( head )
341  {
342  CN_CLUSTER_PTR cluster ( new CN_CLUSTER() );
343 
344  Q.clear();
345  CN_ITEM* root = head;
346  root->SetVisited ( true );
347 
348  head = root->ListRemove();
349 
350  Q.push_back( root );
351 
352  while( Q.size() )
353  {
354  CN_ITEM* current = Q.front();
355 
356  Q.pop_front();
357  cluster->Add( current );
358 
359  for( auto n : current->ConnectedItems() )
360  {
361  if( withinAnyNet && n->Net() != root->Net() )
362  continue;
363 
364  if( !n->Visited() && n->Valid() )
365  {
366  n->SetVisited( true );
367  Q.push_back( n );
368  head = n->ListRemove();
369  }
370  }
371  }
372 
373  clusters.push_back( cluster );
374  }
375 
376 
377  std::sort( clusters.begin(), clusters.end(), []( CN_CLUSTER_PTR a, CN_CLUSTER_PTR b ) {
378  return a->OriginNet() < b->OriginNet();
379  } );
380 
381 #ifdef CONNECTIVITY_DEBUG
382  printf("Active clusters: %d\n", clusters.size() );
383 
384  for( auto cl : clusters )
385  {
386  printf( "Net %d\n", cl->OriginNet() );
387  cl->Dump();
388  }
389 #endif
390 
391  return clusters;
392 }
const CONNECTED_ITEMS & ConnectedItems() const
void ListInsert(T *item)
void SetVisited(bool aVisited)
bool IsDirty() const
int Net() const
search types array terminator (End Of Types)
Definition: typeinfo.h:82
size_t i
Definition: json11.cpp:597
std::shared_ptr< CN_CLUSTER > CN_CLUSTER_PTR
std::vector< CN_CLUSTER_PTR > CLUSTERS

References CN_LIST::begin(), CN_ITEM::ConnectedItems(), CSM_PROPAGATE, CN_ITEM::Dump(), CN_LIST::end(), EOT, i, CN_LIST::IsDirty(), INTRUSIVE_LIST< T >::ListInsert(), INTRUSIVE_LIST< T >::ListRemove(), m_itemList, CN_ITEM::Net(), searchConnections(), and CN_ITEM::SetVisited().

Referenced by FindIsolatedCopperIslands(), GetClusters(), PropagateNets(), and SearchClusters().

◆ SearchClusters() [2/2]

const CN_CONNECTIVITY_ALGO::CLUSTERS CN_CONNECTIVITY_ALGO::SearchClusters ( CLUSTER_SEARCH_MODE  aMode)

Definition at line 280 of file connectivity_algo.cpp.

281 {
283  constexpr KICAD_T no_zones[] = { PCB_TRACE_T, PCB_PAD_T, PCB_VIA_T, PCB_MODULE_T, EOT };
284 
285  if( aMode == CSM_PROPAGATE )
286  return SearchClusters( aMode, no_zones, -1 );
287  else
288  return SearchClusters( aMode, types, -1 );
289 }
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:100
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
const CLUSTERS SearchClusters(CLUSTER_SEARCH_MODE aMode, const KICAD_T aTypes[], int aSingleNet)
class MODULE, a footprint
Definition: typeinfo.h:89
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96

References CSM_PROPAGATE, EOT, PCB_MODULE_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_T, and SearchClusters().

◆ searchConnections()

void CN_CONNECTIVITY_ALGO::searchConnections ( )
private

Definition at line 186 of file connectivity_algo.cpp.

187 {
188 #ifdef CONNECTIVITY_DEBUG
189  printf("Search start\n");
190 #endif
191 
192 #ifdef PROFILE
193  PROF_COUNTER garbage_collection( "garbage-collection" );
194 #endif
195  std::vector<CN_ITEM*> garbage;
196  garbage.reserve( 1024 );
197 
198  m_itemList.RemoveInvalidItems( garbage );
199 
200  for( auto item : garbage )
201  delete item;
202 
203 #ifdef PROFILE
204  garbage_collection.Show();
205  PROF_COUNTER search_basic( "search-basic" );
206 #endif
207 
208  std::vector<CN_ITEM*> dirtyItems;
209  std::copy_if( m_itemList.begin(), m_itemList.end(), std::back_inserter( dirtyItems ),
210  [] ( CN_ITEM* aItem ) { return aItem->Dirty(); } );
211 
212  if( m_progressReporter )
213  {
214  m_progressReporter->SetMaxProgress( dirtyItems.size() );
216  }
217 
218  if( m_itemList.IsDirty() )
219  {
220  size_t parallelThreadCount = std::min<size_t>( std::thread::hardware_concurrency(),
221  ( dirtyItems.size() + 7 ) / 8 );
222 
223  std::atomic<size_t> nextItem( 0 );
224  std::vector<std::future<size_t>> returns( parallelThreadCount );
225 
226  auto conn_lambda = [&nextItem, &dirtyItems]
227  ( CN_LIST* aItemList, PROGRESS_REPORTER* aReporter) -> size_t
228  {
229  for( size_t i = nextItem++; i < dirtyItems.size(); i = nextItem++ )
230  {
231  CN_VISITOR visitor( dirtyItems[i] );
232  aItemList->FindNearby( dirtyItems[i], visitor );
233 
234  if( aReporter )
235  aReporter->AdvanceProgress();
236  }
237 
238  return 1;
239  };
240 
241  if( parallelThreadCount <= 1 )
242  conn_lambda( &m_itemList, m_progressReporter );
243  else
244  {
245  for( size_t ii = 0; ii < parallelThreadCount; ++ii )
246  returns[ii] = std::async( std::launch::async, conn_lambda,
248 
249  for( size_t ii = 0; ii < parallelThreadCount; ++ii )
250  {
251  // Here we balance returns with a 100ms timeout to allow UI updating
252  std::future_status status;
253  do
254  {
255  if( m_progressReporter )
257 
258  status = returns[ii].wait_for( std::chrono::milliseconds( 100 ) );
259  } while( status != std::future_status::ready );
260  }
261  }
262 
263  if( m_progressReporter )
265  }
266 
267 #ifdef PROFILE
268  search_basic.Show();
269 #endif
270 
272 
273 #ifdef CONNECTIVITY_DEBUG
274  printf("Search end\n");
275 #endif
276 
277 }
void RemoveInvalidItems(std::vector< CN_ITEM * > &aGarbage)
A progress reporter for use in multi-threaded environments.
void ClearDirtyFlags()
bool IsDirty() const
The class PROF_COUNTER is a small class to help profiling.
Definition: profile.h:45
Struct CN_VISTOR.
size_t i
Definition: json11.cpp:597
bool KeepRefreshing(bool aWait=false)
Update the UI dialog.
void SetMaxProgress(int aMaxProgress)
Fix the value thar gives the 100 precent progress bar length (inside the current virtual zone)
PROGRESS_REPORTER * m_progressReporter

References CN_LIST::begin(), CN_LIST::ClearDirtyFlags(), CN_LIST::end(), i, CN_LIST::IsDirty(), PROGRESS_REPORTER::KeepRefreshing(), m_itemList, m_progressReporter, CN_LIST::RemoveInvalidItems(), PROGRESS_REPORTER::SetMaxProgress(), and PROF_COUNTER::Show().

Referenced by SearchClusters().

◆ SetProgressReporter()

void CN_CONNECTIVITY_ALGO::SetProgressReporter ( PROGRESS_REPORTER aReporter)

Definition at line 736 of file connectivity_algo.cpp.

737 {
738  m_progressReporter = aReporter;
739 }
PROGRESS_REPORTER * m_progressReporter

References m_progressReporter.

◆ update()

void CN_CONNECTIVITY_ALGO::update ( )
private

Member Data Documentation

◆ m_connClusters

CLUSTERS CN_CONNECTIVITY_ALGO::m_connClusters
private

◆ m_dirtyNets

std::vector<bool> CN_CONNECTIVITY_ALGO::m_dirtyNets
private

◆ m_itemList

CN_LIST CN_CONNECTIVITY_ALGO::m_itemList
private

◆ m_itemMap

std::unordered_map<const BOARD_CONNECTED_ITEM*, ITEM_MAP_ENTRY> CN_CONNECTIVITY_ALGO::m_itemMap
private

Definition at line 148 of file connectivity_algo.h.

Referenced by add(), Add(), Clear(), ItemEntry(), ItemExists(), and Remove().

◆ m_progressReporter

PROGRESS_REPORTER* CN_CONNECTIVITY_ALGO::m_progressReporter = nullptr
private

Definition at line 153 of file connectivity_algo.h.

Referenced by searchConnections(), and SetProgressReporter().

◆ m_ratsnestClusters

CLUSTERS CN_CONNECTIVITY_ALGO::m_ratsnestClusters
private

Definition at line 151 of file connectivity_algo.h.

Referenced by Clear(), GetClusters(), and GetDirtyClusters().


The documentation for this class was generated from the following files: