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) const
 
ITEM_MAP_ENTRYItemEntry (const BOARD_CONNECTED_ITEM *aItem)
 
bool IsNetDirty (int aNet) const
 
void ClearDirtyFlags ()
 
void GetDirtyClusters (CLUSTERS &aClusters) const
 
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 (BOARD_COMMIT *aCommit=nullptr)
 Propagates nets from pads to other items in clusters. More...
 
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...
 
const CLUSTERSGetClusters ()
 
const CN_LISTItemList () const
 
template<typename Func >
void ForEachAnchor (Func &&aFunc) const
 
template<typename Func >
void ForEachItem (Func &&aFunc) const
 
void MarkNetAsDirty (int aNet)
 
void SetProgressReporter (PROGRESS_REPORTER *aReporter)
 

Private Member Functions

void searchConnections ()
 
void update ()
 
void propagateConnections (BOARD_COMMIT *aCommit=nullptr)
 
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_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 173 of file connectivity_algo.h.

173 {}

◆ ~CN_CONNECTIVITY_ALGO()

CN_CONNECTIVITY_ALGO::~CN_CONNECTIVITY_ALGO ( )
inline

Definition at line 174 of file connectivity_algo.h.

174 { 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 162 of file connectivity_algo.h.

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

References m_itemMap.

Referenced by Add().

◆ Add()

bool CN_CONNECTIVITY_ALGO::Add ( BOARD_ITEM aItem)

Definition at line 114 of file connectivity_algo.cpp.

115 {
116  if( !aItem->IsOnCopperLayer() )
117  return false;
118 
119  markItemNetAsDirty ( aItem );
120 
121  switch( aItem->Type() )
122  {
123  case PCB_NETINFO_T:
124  {
125  MarkNetAsDirty( static_cast<NETINFO_ITEM*>( aItem )->GetNet() );
126  break;
127  }
128  case PCB_MODULE_T:
129  for( auto pad : static_cast<MODULE*>( aItem ) -> Pads() )
130  {
131  if( m_itemMap.find( pad ) != m_itemMap.end() )
132  return false;
133 
134  add( m_itemList, pad );
135  }
136 
137  break;
138 
139  case PCB_PAD_T:
140  if( m_itemMap.find ( aItem ) != m_itemMap.end() )
141  return false;
142 
143  add( m_itemList, static_cast<D_PAD*>( aItem ) );
144 
145  break;
146 
147  case PCB_TRACE_T:
148  {
149  if( m_itemMap.find( aItem ) != m_itemMap.end() )
150  return false;
151 
152  add( m_itemList, static_cast<TRACK*>( aItem ) );
153 
154  break;
155  }
156 
157  case PCB_ARC_T:
158  {
159  if( m_itemMap.find( aItem ) != m_itemMap.end() )
160  return false;
161 
162  add( m_itemList, static_cast<ARC*>( aItem ) );
163 
164  break;
165  }
166 
167  case PCB_VIA_T:
168  if( m_itemMap.find( aItem ) != m_itemMap.end() )
169  return false;
170 
171  add( m_itemList, static_cast<VIA*>( aItem ) );
172 
173  break;
174 
175  case PCB_ZONE_AREA_T:
176  {
177  auto zone = static_cast<ZONE_CONTAINER*>( aItem );
178 
179  if( m_itemMap.find( aItem ) != m_itemMap.end() )
180  return false;
181 
182  m_itemMap[zone] = ITEM_MAP_ENTRY();
183 
184  for( auto zitem : m_itemList.Add( zone ) )
185  m_itemMap[zone].Link(zitem);
186 
187  break;
188  }
189 
190  default:
191  return false;
192  }
193 
194  return true;
195 }
CN_ITEM * Add(D_PAD *pad)
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
void MarkNetAsDirty(int aNet)
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
void add(Container &c, BItem brditem)
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
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:104
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
virtual bool IsOnCopperLayer() const
std::unordered_map< const BOARD_ITEM *, ITEM_MAP_ENTRY > m_itemMap
KICAD_T Type() const
Function Type()
Definition: base_struct.h:197

References add(), CN_LIST::Add(), BOARD_ITEM::IsOnCopperLayer(), m_itemList, m_itemMap, markItemNetAsDirty(), MarkNetAsDirty(), PCB_ARC_T, 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 409 of file connectivity_algo.cpp.

410 {
411  for( int i = 0; i<aBoard->GetAreaCount(); i++ )
412  {
413  auto zone = aBoard->GetArea( i );
414  Add( zone );
415  }
416 
417  for( auto tv : aBoard->Tracks() )
418  Add( tv );
419 
420  for( auto mod : aBoard->Modules() )
421  {
422  for( auto pad : mod->Pads() )
423  Add( pad );
424  }
425 
426  /*wxLogTrace( "CN", "zones : %lu, pads : %lu vias : %lu tracks : %lu\n",
427  m_zoneList.Size(), m_padList.Size(),
428  m_viaList.Size(), m_trackList.Size() );*/
429 }
bool Add(BOARD_ITEM *aItem)
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:927
MODULES & Modules()
Definition: class_board.h:256
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:892
TRACKS & Tracks()
Definition: class_board.h:247

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

◆ Build() [2/2]

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

Definition at line 432 of file connectivity_algo.cpp.

433 {
434  for( auto item : aItems )
435  {
436  switch( item->Type() )
437  {
438  case PCB_TRACE_T:
439  case PCB_ARC_T:
440  case PCB_VIA_T:
441  case PCB_PAD_T:
442  Add( item );
443  break;
444 
445  case PCB_MODULE_T:
446  {
447  for( auto pad : static_cast<MODULE*>( item )->Pads() )
448  {
449  Add( pad );
450  }
451 
452  break;
453  }
454 
455  default:
456  break;
457  }
458  }
459 }
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
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:96
class MODULE, a footprint
Definition: typeinfo.h:89
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97

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

◆ Clear()

void CN_CONNECTIVITY_ALGO::Clear ( )

Definition at line 741 of file connectivity_algo.cpp.

742 {
743  m_ratsnestClusters.clear();
744  m_connClusters.clear();
745  m_itemMap.clear();
746  m_itemList.Clear();
747 
748 }
std::unordered_map< const BOARD_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 194 of file connectivity_algo.h.

195  {
196  for( auto i = m_dirtyNets.begin(); i != m_dirtyNets.end(); ++i )
197  *i = false;
198  }
std::vector< bool > m_dirtyNets

References m_dirtyNets.

◆ FindIsolatedCopperIslands() [1/2]

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

Definition at line 521 of file connectivity_algo.cpp.

522 {
523  if( aZone->GetFilledPolysList().IsEmpty() )
524  return;
525 
526  aIslands.clear();
527 
528  Remove( aZone );
529  Add( aZone );
530 
532 
533  for( const auto& cluster : m_connClusters )
534  {
535  if( cluster->Contains( aZone ) && cluster->IsOrphaned() )
536  {
537  for( auto z : *cluster )
538  {
539  if( z->Parent() == aZone )
540  {
541  aIslands.push_back( static_cast<CN_ZONE*>(z)->SubpolyIndex() );
542  }
543  }
544  }
545  }
546 
547  wxLogTrace( "CN", "Found %u isolated islands\n", (unsigned)aIslands.size() );
548 }
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:568

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 550 of file connectivity_algo.cpp.

551 {
552  for ( auto& z : aZones )
553  Remove( z.m_zone );
554 
555  for ( auto& z : aZones )
556  {
557  if( !z.m_zone->GetFilledPolysList().IsEmpty() )
558  Add( z.m_zone );
559  }
560 
562 
563  for ( auto& zone : aZones )
564  {
565  if( zone.m_zone->GetFilledPolysList().IsEmpty() )
566  continue;
567 
568  for( const auto& cluster : m_connClusters )
569  {
570  if( cluster->Contains( zone.m_zone ) && cluster->IsOrphaned() )
571  {
572  for( auto z : *cluster )
573  {
574  if( z->Parent() == zone.m_zone )
575  {
576  zone.m_islands.push_back( static_cast<CN_ZONE*>(z)->SubpolyIndex() );
577  }
578  }
579  }
580  }
581  }
582 }
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()

template<typename Func >
void CN_CONNECTIVITY_ALGO::ForEachAnchor ( Func &&  aFunc) const
inline

Definition at line 251 of file connectivity_algo.h.

252  {
253  for( auto&& item : m_itemList )
254  {
255  for( auto&& anchor : item->Anchors() )
256  aFunc( *anchor );
257  }
258  }

References m_itemList.

◆ ForEachItem()

template<typename Func >
void CN_CONNECTIVITY_ALGO::ForEachItem ( Func &&  aFunc) const
inline

Definition at line 261 of file connectivity_algo.h.

262  {
263  for( auto&& item : m_itemList )
264  aFunc( *item );
265  }

References m_itemList.

◆ GetClusters()

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

Definition at line 585 of file connectivity_algo.cpp.

586 {
588  return m_ratsnestClusters;
589 }
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) const
inline

Definition at line 200 of file connectivity_algo.h.

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

References m_dirtyNets, and m_ratsnestClusters.

◆ IsNetDirty()

bool CN_CONNECTIVITY_ALGO::IsNetDirty ( int  aNet) const
inline

Definition at line 186 of file connectivity_algo.h.

187  {
188  if( aNet < 0 )
189  return false;
190 
191  return m_dirtyNets[ aNet ];
192  }
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 181 of file connectivity_algo.h.

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

References m_itemMap.

◆ ItemExists()

bool CN_CONNECTIVITY_ALGO::ItemExists ( const BOARD_CONNECTED_ITEM aItem) const
inline

Definition at line 176 of file connectivity_algo.h.

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

References m_itemMap.

◆ ItemList()

const CN_LIST& CN_CONNECTIVITY_ALGO::ItemList ( ) const
inline

Definition at line 245 of file connectivity_algo.h.

246  {
247  return m_itemList;
248  }

References m_itemList.

◆ markItemNetAsDirty()

void CN_CONNECTIVITY_ALGO::markItemNetAsDirty ( const BOARD_ITEM aItem)
private

Definition at line 94 of file connectivity_algo.cpp.

95 {
96  if( aItem->IsConnected() )
97  {
98  auto citem = static_cast<const BOARD_CONNECTED_ITEM*>( aItem );
99  MarkNetAsDirty( citem->GetNetCode() );
100  }
101  else
102  {
103  if( aItem->Type() == PCB_MODULE_T )
104  {
105  auto mod = static_cast <const MODULE*>( aItem );
106 
107  for( auto pad : mod->Pads() )
108  MarkNetAsDirty( pad->GetNetCode() );
109  }
110  }
111 }
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.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:197

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

Referenced by Add(), and Remove().

◆ MarkNetAsDirty()

void CN_CONNECTIVITY_ALGO::MarkNetAsDirty ( int  aNet)

Definition at line 592 of file connectivity_algo.cpp.

593 {
594  if( aNet < 0 )
595  return;
596 
597  if( (int) m_dirtyNets.size() <= aNet )
598  {
599  int lastNet = m_dirtyNets.size() - 1;
600 
601  if( lastNet < 0 )
602  lastNet = 0;
603 
604  m_dirtyNets.resize( aNet + 1 );
605 
606  for( int i = lastNet; i < aNet + 1; i++ )
607  m_dirtyNets[i] = true;
608  }
609 
610  m_dirtyNets[aNet] = true;
611 }
std::vector< bool > m_dirtyNets

References m_dirtyNets.

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

◆ NetCount()

int CN_CONNECTIVITY_ALGO::NetCount ( ) const
inline

Definition at line 211 of file connectivity_algo.h.

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

References m_dirtyNets.

◆ propagateConnections()

void CN_CONNECTIVITY_ALGO::propagateConnections ( BOARD_COMMIT aCommit = nullptr)
private

Definition at line 462 of file connectivity_algo.cpp.

463 {
464  for( const auto& cluster : m_connClusters )
465  {
466  if( cluster->IsConflicting() )
467  {
468  wxLogTrace( "CN", "Conflicting nets in cluster %p\n", cluster.get() );
469  }
470  else if( cluster->IsOrphaned() )
471  {
472  wxLogTrace( "CN", "Skipping orphaned cluster %p [net: %s]\n", cluster.get(),
473  (const char*) cluster->OriginNetName().c_str() );
474  }
475  else if( cluster->HasValidNet() )
476  {
477  // normal cluster: just propagate from the pads
478  int n_changed = 0;
479 
480  for( auto item : *cluster )
481  {
482  if( item->CanChangeNet() )
483  {
484  if( item->Valid() && item->Parent()->GetNetCode() != cluster->OriginNet() )
485  {
486  MarkNetAsDirty( item->Parent()->GetNetCode() );
487  MarkNetAsDirty( cluster->OriginNet() );
488 
489  if( aCommit )
490  aCommit->Modify( item->Parent() );
491 
492  item->Parent()->SetNetCode( cluster->OriginNet() );
493  n_changed++;
494  }
495  }
496  }
497 
498  if( n_changed )
499  {
500  wxLogTrace( "CN", "Cluster %p : net : %d %s\n", cluster.get(),
501  cluster->OriginNet(), (const char*) cluster->OriginNetName().c_str() );
502  }
503  else
504  wxLogTrace( "CN", "Cluster %p : nothing to propagate\n", cluster.get() );
505  }
506  else
507  {
508  wxLogTrace( "CN", "Cluster %p : connected to unused net\n", cluster.get() );
509  }
510  }
511 }
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
void MarkNetAsDirty(int aNet)

References m_connClusters, MarkNetAsDirty(), and COMMIT::Modify().

Referenced by PropagateNets().

◆ PropagateNets()

void CN_CONNECTIVITY_ALGO::PropagateNets ( BOARD_COMMIT aCommit = nullptr)

Propagates nets from pads to other items in clusters.

Parameters
aCommitis used to store undo information for items modified by the call

Definition at line 514 of file connectivity_algo.cpp.

515 {
517  propagateConnections( aCommit );
518 }
void propagateConnections(BOARD_COMMIT *aCommit=nullptr)
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 40 of file connectivity_algo.cpp.

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

References m_itemList, m_itemMap, markItemNetAsDirty(), PCB_ARC_T, 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 306 of file connectivity_algo.cpp.

308 {
309  bool withinAnyNet = ( aMode != CSM_PROPAGATE );
310 
311  std::deque<CN_ITEM*> Q;
312  CN_ITEM* head = nullptr;
313  CLUSTERS clusters;
314 
315  if( m_itemList.IsDirty() )
317 
318  auto addToSearchList = [&head, withinAnyNet, aSingleNet, aTypes] ( CN_ITEM *aItem )
319  {
320  if( withinAnyNet && aItem->Net() <= 0 )
321  return;
322 
323  if( !aItem->Valid() )
324  return;
325 
326  if( aSingleNet >=0 && aItem->Net() != aSingleNet )
327  return;
328 
329  bool found = false;
330 
331  for( int i = 0; aTypes[i] != EOT; i++ )
332  {
333  if( aItem->Parent()->Type() == aTypes[i] )
334  {
335  found = true;
336  break;
337  }
338  }
339 
340  if( !found )
341  return;
342 
343  aItem->ListClear();
344  aItem->SetVisited( false );
345 
346  if( !head )
347  head = aItem;
348  else
349  head->ListInsert( aItem );
350  };
351 
352  std::for_each( m_itemList.begin(), m_itemList.end(), addToSearchList );
353 
354  while( head )
355  {
356  CN_CLUSTER_PTR cluster ( new CN_CLUSTER() );
357 
358  Q.clear();
359  CN_ITEM* root = head;
360  root->SetVisited ( true );
361 
362  head = root->ListRemove();
363 
364  Q.push_back( root );
365 
366  while( Q.size() )
367  {
368  CN_ITEM* current = Q.front();
369 
370  Q.pop_front();
371  cluster->Add( current );
372 
373  for( auto n : current->ConnectedItems() )
374  {
375  if( withinAnyNet && n->Net() != root->Net() )
376  continue;
377 
378  if( !n->Visited() && n->Valid() )
379  {
380  n->SetVisited( true );
381  Q.push_back( n );
382  head = n->ListRemove();
383  }
384  }
385  }
386 
387  clusters.push_back( cluster );
388  }
389 
390 
391  std::sort( clusters.begin(), clusters.end(), []( CN_CLUSTER_PTR a, CN_CLUSTER_PTR b ) {
392  return a->OriginNet() < b->OriginNet();
393  } );
394 
395 #ifdef CONNECTIVITY_DEBUG
396  printf("Active clusters: %d\n", clusters.size() );
397 
398  for( auto cl : clusters )
399  {
400  printf( "Net %d\n", cl->OriginNet() );
401  cl->Dump();
402  }
403 #endif
404 
405  return clusters;
406 }
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
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, 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 292 of file connectivity_algo.cpp.

293 {
294  constexpr KICAD_T types[] =
296  constexpr KICAD_T no_zones[] =
298 
299  if( aMode == CSM_PROPAGATE )
300  return SearchClusters( aMode, no_zones, -1 );
301  else
302  return SearchClusters( aMode, types, -1 );
303 }
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
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:96
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:97

References CSM_PROPAGATE, EOT, PCB_ARC_T, 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 198 of file connectivity_algo.cpp.

199 {
200 #ifdef CONNECTIVITY_DEBUG
201  printf("Search start\n");
202 #endif
203 
204 #ifdef PROFILE
205  PROF_COUNTER garbage_collection( "garbage-collection" );
206 #endif
207  std::vector<CN_ITEM*> garbage;
208  garbage.reserve( 1024 );
209 
210  m_itemList.RemoveInvalidItems( garbage );
211 
212  for( auto item : garbage )
213  delete item;
214 
215 #ifdef PROFILE
216  garbage_collection.Show();
217  PROF_COUNTER search_basic( "search-basic" );
218 #endif
219 
220  std::vector<CN_ITEM*> dirtyItems;
221  std::copy_if( m_itemList.begin(), m_itemList.end(), std::back_inserter( dirtyItems ),
222  [] ( CN_ITEM* aItem ) { return aItem->Dirty(); } );
223 
224  if( m_progressReporter )
225  {
226  m_progressReporter->SetMaxProgress( dirtyItems.size() );
228  }
229 
230  if( m_itemList.IsDirty() )
231  {
232  size_t parallelThreadCount = std::min<size_t>( std::thread::hardware_concurrency(),
233  ( dirtyItems.size() + 7 ) / 8 );
234 
235  std::atomic<size_t> nextItem( 0 );
236  std::vector<std::future<size_t>> returns( parallelThreadCount );
237 
238  auto conn_lambda = [&nextItem, &dirtyItems]
239  ( CN_LIST* aItemList, PROGRESS_REPORTER* aReporter) -> size_t
240  {
241  for( size_t i = nextItem++; i < dirtyItems.size(); i = nextItem++ )
242  {
243  CN_VISITOR visitor( dirtyItems[i] );
244  aItemList->FindNearby( dirtyItems[i], visitor );
245 
246  if( aReporter )
247  aReporter->AdvanceProgress();
248  }
249 
250  return 1;
251  };
252 
253  if( parallelThreadCount <= 1 )
254  conn_lambda( &m_itemList, m_progressReporter );
255  else
256  {
257  for( size_t ii = 0; ii < parallelThreadCount; ++ii )
258  returns[ii] = std::async( std::launch::async, conn_lambda,
260 
261  for( size_t ii = 0; ii < parallelThreadCount; ++ii )
262  {
263  // Here we balance returns with a 100ms timeout to allow UI updating
264  std::future_status status;
265  do
266  {
267  if( m_progressReporter )
269 
270  status = returns[ii].wait_for( std::chrono::milliseconds( 100 ) );
271  } while( status != std::future_status::ready );
272  }
273  }
274 
275  if( m_progressReporter )
277  }
278 
279 #ifdef PROFILE
280  search_basic.Show();
281 #endif
282 
284 
285 #ifdef CONNECTIVITY_DEBUG
286  printf("Search end\n");
287 #endif
288 
289 }
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:44
Struct CN_VISTOR.
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(), 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 750 of file connectivity_algo.cpp.

751 {
752  m_progressReporter = aReporter;
753 }
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_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: