KiCad PCB EDA Suite
CONNECTIVITY_DATA Class Reference

#include <connectivity_data.h>

Public Member Functions

 CONNECTIVITY_DATA ()
 
 ~CONNECTIVITY_DATA ()
 
 CONNECTIVITY_DATA (const std::vector< BOARD_ITEM * > &aItems, bool aSkipItems=false)
 
void Build (BOARD *aBoard)
 Function Build() Builds the connectivity database for the board aBoard. More...
 
void Build (const std::vector< BOARD_ITEM * > &aItems)
 Function Build() Builds the connectivity database for a set of items aItems. More...
 
bool Add (BOARD_ITEM *aItem)
 Function Add() Adds an item to the connectivity data. More...
 
bool Remove (BOARD_ITEM *aItem)
 Function Remove() Removes an item from the connectivity data. More...
 
bool Update (BOARD_ITEM *aItem)
 Function Update() Updates the connectivity data for an item. More...
 
void Clear ()
 Function Clear() Erases the connectivity database. More...
 
int GetNetCount () const
 Function GetNetCount() Returns the total number of nets in the connectivity database. More...
 
RN_NETGetRatsnestForNet (int aNet)
 Function GetRatsnestForNet() Returns the ratsnest, expressed as a set of graph edges for a given net. More...
 
void PropagateNets ()
 Function PropagateNets() Propagates the net codes from the source pads to the tracks/vias. More...
 
bool CheckConnectivity (std::vector< CN_DISJOINT_NET_ENTRY > &aReport)
 
void FindIsolatedCopperIslands (ZONE_CONTAINER *aZone, std::vector< int > &aIslands)
 Function FindIsolatedCopperIslands() Searches for copper islands in zone aZone that are not connected to any pad. More...
 
void FindIsolatedCopperIslands (std::vector< CN_ZONE_ISOLATED_ISLAND_LIST > &aZones)
 
void RecalculateRatsnest (BOARD_COMMIT *aCommit=nullptr)
 Function RecalculateRatsnest() Updates the ratsnest for the board. More...
 
unsigned int GetUnconnectedCount () const
 Function GetUnconnectedCount() Returns the number of remaining edges in the ratsnest. More...
 
unsigned int GetNodeCount (int aNet=-1) const
 
unsigned int GetPadCount (int aNet=-1) const
 
const std::vector< TRACK * > GetConnectedTracks (const BOARD_CONNECTED_ITEM *aItem) const
 
const std::vector< D_PAD * > GetConnectedPads (const BOARD_CONNECTED_ITEM *aItem) const
 
void GetConnectedPads (const BOARD_CONNECTED_ITEM *aItem, std::set< D_PAD * > *pads) const
 
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItems (const BOARD_CONNECTED_ITEM *aItem, const VECTOR2I &aAnchor, KICAD_T aTypes[])
 
void GetUnconnectedEdges (std::vector< CN_EDGE > &aEdges) const
 
bool TestTrackEndpointDangling (TRACK *aTrack, wxPoint *aPos=nullptr)
 
void ClearDynamicRatsnest ()
 Function ClearDynamicRatsnest() Erases the temporary dynamic ratsnest (i.e. More...
 
void HideDynamicRatsnest ()
 Hides the temporary dynamic ratsnest lines. More...
 
void ComputeDynamicRatsnest (const std::vector< BOARD_ITEM * > &aItems)
 Function ComputeDynamicRatsnest() Calculates the temporary dynamic ratsnest (i.e. More...
 
const std::vector< RN_DYNAMIC_LINE > & GetDynamicRatsnest () const
 
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItems (const BOARD_CONNECTED_ITEM *aItem, const KICAD_T aTypes[], bool aIgnoreNetcodes=false) const
 Function GetConnectedItems() Returns a list of items connected to a source item aItem. More...
 
const std::vector< BOARD_CONNECTED_ITEM * > GetNetItems (int aNetCode, const KICAD_T aTypes[]) const
 Function GetNetItems() Returns the list of items that belong to a certain net. More...
 
void BlockRatsnestItems (const std::vector< BOARD_ITEM * > &aItems)
 
std::shared_ptr< CN_CONNECTIVITY_ALGOGetConnectivityAlgo () const
 
std::mutex & GetLock ()
 
void MarkItemNetAsDirty (BOARD_ITEM *aItem)
 
void SetProgressReporter (PROGRESS_REPORTER *aReporter)
 
const std::vector< CN_EDGEGetRatsnestForItems (const std::vector< BOARD_ITEM * > aItems)
 
const std::vector< CN_EDGEGetRatsnestForComponent (MODULE *aComponent, bool aSkipInternalConnections=false)
 

Private Member Functions

void updateRatsnest ()
 
void addRatsnestCluster (const std::shared_ptr< CN_CLUSTER > &aCluster)
 

Private Attributes

std::shared_ptr< CN_CONNECTIVITY_ALGOm_connAlgo
 
std::vector< RN_DYNAMIC_LINEm_dynamicRatsnest
 
std::vector< RN_NET * > m_nets
 
PROGRESS_REPORTERm_progressReporter
 
bool m_skipRatsnest = false
 
std::mutex m_lock
 

Detailed Description

Definition at line 84 of file connectivity_data.h.

Constructor & Destructor Documentation

◆ CONNECTIVITY_DATA() [1/2]

CONNECTIVITY_DATA::CONNECTIVITY_DATA ( )

Definition at line 38 of file connectivity_data.cpp.

39 {
40  m_connAlgo.reset( new CN_CONNECTIVITY_ALGO );
41  m_progressReporter = nullptr;
42 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
PROGRESS_REPORTER * m_progressReporter

References m_connAlgo, and m_progressReporter.

◆ ~CONNECTIVITY_DATA()

CONNECTIVITY_DATA::~CONNECTIVITY_DATA ( )

Definition at line 53 of file connectivity_data.cpp.

54 {
55  Clear();
56 }
void Clear()
Function Clear() Erases the connectivity database.

References Clear().

◆ CONNECTIVITY_DATA() [2/2]

CONNECTIVITY_DATA::CONNECTIVITY_DATA ( const std::vector< BOARD_ITEM * > &  aItems,
bool  aSkipItems = false 
)

Definition at line 45 of file connectivity_data.cpp.

46  : m_skipRatsnest( aSkipRatsnest )
47 {
48  Build( aItems );
49  m_progressReporter = nullptr;
50 }
PROGRESS_REPORTER * m_progressReporter
void Build(BOARD *aBoard)
Function Build() Builds the connectivity database for the board aBoard.

References Build(), and m_progressReporter.

Member Function Documentation

◆ Add()

bool CONNECTIVITY_DATA::Add ( BOARD_ITEM aItem)

Function Add() Adds an item to the connectivity data.

Parameters
aItemis an item to be added.
Returns
True if operation succeeded.

Definition at line 59 of file connectivity_data.cpp.

60 {
61  m_connAlgo->Add( aItem );
62  return true;
63 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo

References m_connAlgo.

◆ addRatsnestCluster()

void CONNECTIVITY_DATA::addRatsnestCluster ( const std::shared_ptr< CN_CLUSTER > &  aCluster)
private

Definition at line 143 of file connectivity_data.cpp.

144 {
145  auto rnNet = m_nets[ aCluster->OriginNet() ];
146 
147  rnNet->AddCluster( aCluster );
148 }
std::vector< RN_NET * > m_nets

References m_nets.

Referenced by RecalculateRatsnest().

◆ BlockRatsnestItems()

void CONNECTIVITY_DATA::BlockRatsnestItems ( const std::vector< BOARD_ITEM * > &  aItems)

Definition at line 203 of file connectivity_data.cpp.

204 {
205  std::vector<BOARD_CONNECTED_ITEM*> citems;
206 
207  for( auto item : aItems )
208  {
209  if( item->Type() == PCB_MODULE_T )
210  {
211  for( auto pad : static_cast<MODULE*>(item)->Pads() )
212  citems.push_back( pad );
213  }
214  else
215  {
216  if( auto citem = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
217  citems.push_back( citem );
218  }
219  }
220 
221  for( const auto& item : citems )
222  {
223  if ( m_connAlgo->ItemExists( item ) )
224  {
225  auto& entry = m_connAlgo->ItemEntry( item );
226 
227  for( const auto& cnItem : entry.GetItems() )
228  {
229  for( auto anchor : cnItem->Anchors() )
230  anchor->SetNoLine( true );
231  }
232  }
233  }
234 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
class MODULE, a footprint
Definition: typeinfo.h:89

References m_connAlgo, and PCB_MODULE_T.

Referenced by ComputeDynamicRatsnest().

◆ Build() [1/2]

void CONNECTIVITY_DATA::Build ( BOARD aBoard)

Function Build() Builds the connectivity database for the board aBoard.

Definition at line 81 of file connectivity_data.cpp.

82 {
83  m_connAlgo.reset( new CN_CONNECTIVITY_ALGO );
84  m_connAlgo->Build( aBoard );
86 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
void RecalculateRatsnest(BOARD_COMMIT *aCommit=nullptr)
Function RecalculateRatsnest() Updates the ratsnest for the board.

References m_connAlgo, and RecalculateRatsnest().

Referenced by CONNECTIVITY_DATA().

◆ Build() [2/2]

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

Function Build() Builds the connectivity database for a set of items aItems.

Definition at line 89 of file connectivity_data.cpp.

90 {
91  m_connAlgo.reset( new CN_CONNECTIVITY_ALGO );
92  m_connAlgo->Build( aItems );
93 
95 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
void RecalculateRatsnest(BOARD_COMMIT *aCommit=nullptr)
Function RecalculateRatsnest() Updates the ratsnest for the board.

References m_connAlgo, and RecalculateRatsnest().

◆ CheckConnectivity()

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

Definition at line 413 of file connectivity_data.cpp.

414 {
416 
417  for( auto net : m_nets )
418  {
419  if( net )
420  {
421  for( const auto& edge : net->GetEdges() )
422  {
424  ent.net = edge.GetSourceNode()->Parent()->GetNetCode();
425  ent.a = edge.GetSourceNode()->Parent();
426  ent.b = edge.GetTargetNode()->Parent();
427  ent.anchorA = edge.GetSourceNode()->Pos();
428  ent.anchorB = edge.GetTargetNode()->Pos();
429  aReport.push_back( ent );
430  }
431  }
432  }
433 
434  return aReport.empty();
435 }
void RecalculateRatsnest(BOARD_COMMIT *aCommit=nullptr)
Function RecalculateRatsnest() Updates the ratsnest for the board.
BOARD_CONNECTED_ITEM * b
VECTOR2I anchorB
VECTOR2I anchorA
std::vector< RN_NET * > m_nets
BOARD_CONNECTED_ITEM * a
int net

References CN_DISJOINT_NET_ENTRY::a, CN_DISJOINT_NET_ENTRY::anchorA, CN_DISJOINT_NET_ENTRY::anchorB, CN_DISJOINT_NET_ENTRY::b, m_nets, CN_DISJOINT_NET_ENTRY::net, and RecalculateRatsnest().

◆ Clear()

void CONNECTIVITY_DATA::Clear ( )

Function Clear() Erases the connectivity database.

Definition at line 351 of file connectivity_data.cpp.

352 {
353  for( auto net : m_nets )
354  delete net;
355 
356  m_nets.clear();
357 }
std::vector< RN_NET * > m_nets

References m_nets.

Referenced by ~CONNECTIVITY_DATA().

◆ ClearDynamicRatsnest()

void CONNECTIVITY_DATA::ClearDynamicRatsnest ( )

Function ClearDynamicRatsnest() Erases the temporary dynamic ratsnest (i.e.

the ratsnest lines that pcbnew displays when moving an item/set of items)

Definition at line 311 of file connectivity_data.cpp.

312 {
313  m_connAlgo->ForEachAnchor( [] ( CN_ANCHOR& anchor ) { anchor.SetNoLine( false ); } );
315 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
void SetNoLine(bool aEnable)
Decides whether this node can be a ratsnest line target.
void HideDynamicRatsnest()
Hides the temporary dynamic ratsnest lines.

References HideDynamicRatsnest(), m_connAlgo, and CN_ANCHOR::SetNoLine().

◆ ComputeDynamicRatsnest()

void CONNECTIVITY_DATA::ComputeDynamicRatsnest ( const std::vector< BOARD_ITEM * > &  aItems)

Function ComputeDynamicRatsnest() Calculates the temporary dynamic ratsnest (i.e.

the ratsnest lines that) for the set of items aItems.

Definition at line 258 of file connectivity_data.cpp.

259 {
260  m_dynamicRatsnest.clear();
261 
262  if( std::none_of( aItems.begin(), aItems.end(), []( const BOARD_ITEM* aItem )
263  { return( aItem->Type() == PCB_TRACE_T || aItem->Type() == PCB_PAD_T ||
264  aItem->Type() == PCB_ARC_T || aItem->Type() == PCB_ZONE_AREA_T ||
265  aItem->Type() == PCB_MODULE_T || aItem->Type() == PCB_VIA_T ); } ) )
266  {
267  return ;
268  }
269 
270  CONNECTIVITY_DATA connData( aItems, true );
271  BlockRatsnestItems( aItems );
272 
273  for( unsigned int nc = 1; nc < connData.m_nets.size(); nc++ )
274  {
275  auto dynNet = connData.m_nets[nc];
276 
277  if( dynNet->GetNodeCount() != 0 )
278  {
279  auto ourNet = m_nets[nc];
280  CN_ANCHOR_PTR nodeA, nodeB;
281 
282  if( ourNet->NearestBicoloredPair( *dynNet, nodeA, nodeB ) )
283  {
284  RN_DYNAMIC_LINE l;
285  l.a = nodeA->Pos();
286  l.b = nodeB->Pos();
287  l.netCode = nc;
288 
289  m_dynamicRatsnest.push_back( l );
290  }
291  }
292  }
293 
294  const auto& edges = GetRatsnestForItems( aItems );
295 
296  for( const auto& edge : edges )
297  {
298  const auto& nodeA = edge.GetSourceNode();
299  const auto& nodeB = edge.GetTargetNode();
300  RN_DYNAMIC_LINE l;
301 
302  // Use the parents' positions
303  l.a = nodeA->Parent()->GetPosition();
304  l.b = nodeB->Parent()->GetPosition();
305  l.netCode = 0;
306  m_dynamicRatsnest.push_back( l );
307  }
308 }
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
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
std::vector< RN_DYNAMIC_LINE > m_dynamicRatsnest
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
class MODULE, a footprint
Definition: typeinfo.h:89
std::vector< RN_NET * > m_nets
void BlockRatsnestItems(const std::vector< BOARD_ITEM * > &aItems)
std::shared_ptr< CN_ANCHOR > CN_ANCHOR_PTR
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
const std::vector< CN_EDGE > GetRatsnestForItems(const std::vector< BOARD_ITEM * > aItems)

References RN_DYNAMIC_LINE::a, RN_DYNAMIC_LINE::b, BlockRatsnestItems(), GetRatsnestForItems(), m_dynamicRatsnest, m_nets, RN_DYNAMIC_LINE::netCode, PCB_ARC_T, PCB_MODULE_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, and PCB_ZONE_AREA_T.

◆ FindIsolatedCopperIslands() [1/2]

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

Function FindIsolatedCopperIslands() Searches for copper islands in zone aZone that are not connected to any pad.

Parameters
aZonezone to test
aIslandslist of islands that have no connections (outline indices in the polygon set)

Definition at line 243 of file connectivity_data.cpp.

245 {
246  // TODO(JE) ZONES
247 #if 0
248  m_connAlgo->FindIsolatedCopperIslands( aZone, aIslands );
249 #endif
250 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo

References m_connAlgo.

◆ FindIsolatedCopperIslands() [2/2]

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

Definition at line 252 of file connectivity_data.cpp.

253 {
254  m_connAlgo->FindIsolatedCopperIslands( aZones );
255 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo

References m_connAlgo.

◆ GetConnectedItems() [1/2]

const std::vector< BOARD_CONNECTED_ITEM * > CONNECTIVITY_DATA::GetConnectedItems ( const BOARD_CONNECTED_ITEM aItem,
const VECTOR2I aAnchor,
KICAD_T  aTypes[] 
)

Definition at line 575 of file connectivity_data.cpp.

577 {
578  auto& entry = m_connAlgo->ItemEntry( aItem );
579  std::vector<BOARD_CONNECTED_ITEM* > rv;
580 
581  for( auto cnItem : entry.GetItems() )
582  {
583  for( auto anchor : cnItem->Anchors() )
584  {
585  if( anchor->Pos() == aAnchor )
586  {
587  for( int i = 0; aTypes[i] > 0; i++ )
588  {
589  if( cnItem->Valid() && cnItem->Parent()->Type() == aTypes[i] )
590  {
591  rv.push_back( cnItem->Parent() );
592  break;
593  }
594  }
595  }
596  }
597  }
598 
599  return rv;
600 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo

References m_connAlgo.

◆ GetConnectedItems() [2/2]

const std::vector< BOARD_CONNECTED_ITEM * > CONNECTIVITY_DATA::GetConnectedItems ( const BOARD_CONNECTED_ITEM aItem,
const KICAD_T  aTypes[],
bool  aIgnoreNetcodes = false 
) const

Function GetConnectedItems() Returns a list of items connected to a source item aItem.

Parameters
aItemis the reference item to find other connected items.
aTypesallows one to filter by item types.

Definition at line 360 of file connectivity_data.cpp.

364 {
365  std::vector<BOARD_CONNECTED_ITEM*> rv;
366  const auto clusters = m_connAlgo->SearchClusters(
367  aIgnoreNetcodes ?
370  aIgnoreNetcodes ? -1 : aItem->GetNetCode() );
371 
372  for( auto cl : clusters )
373  {
374  if( cl->Contains( aItem ) )
375  {
376  for( const auto item : *cl )
377  {
378  if( item->Valid() )
379  rv.push_back( item->Parent() );
380  }
381  }
382  }
383 
384  return rv;
385 }
int GetNetCode() const
Function GetNetCode.
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo

References CN_CONNECTIVITY_ALGO::CSM_CONNECTIVITY_CHECK, CN_CONNECTIVITY_ALGO::CSM_PROPAGATE, BOARD_CONNECTED_ITEM::GetNetCode(), and m_connAlgo.

◆ GetConnectedPads() [1/2]

const std::vector< D_PAD * > CONNECTIVITY_DATA::GetConnectedPads ( const BOARD_CONNECTED_ITEM aItem) const

Definition at line 477 of file connectivity_data.cpp.

479 {
480  std::set<D_PAD*> pads;
481  std::vector<D_PAD*> rv;
482 
483  GetConnectedPads( aItem, &pads );
484 
485  std::copy( pads.begin(), pads.end(), std::back_inserter( rv ) );
486  return rv;
487 }
const std::vector< D_PAD * > GetConnectedPads(const BOARD_CONNECTED_ITEM *aItem) const

◆ GetConnectedPads() [2/2]

void CONNECTIVITY_DATA::GetConnectedPads ( const BOARD_CONNECTED_ITEM aItem,
std::set< D_PAD * > *  pads 
) const

Definition at line 463 of file connectivity_data.cpp.

465 {
466  for( auto citem : m_connAlgo->ItemEntry( aItem ).GetItems() )
467  {
468  for( auto connected : citem->ConnectedItems() )
469  {
470  if( connected->Valid() && connected->Parent()->Type() == PCB_PAD_T )
471  pads->insert( static_cast<D_PAD*> ( connected->Parent() ) );
472  }
473  }
474 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90

References m_connAlgo, and PCB_PAD_T.

◆ GetConnectedTracks()

const std::vector< TRACK * > CONNECTIVITY_DATA::GetConnectedTracks ( const BOARD_CONNECTED_ITEM aItem) const

Definition at line 438 of file connectivity_data.cpp.

440 {
441  auto& entry = m_connAlgo->ItemEntry( aItem );
442 
443  std::set<TRACK*> tracks;
444  std::vector<TRACK*> rv;
445 
446  for( auto citem : entry.GetItems() )
447  {
448  for( auto connected : citem->ConnectedItems() )
449  {
450  if( connected->Valid() &&
451  ( connected->Parent()->Type() == PCB_TRACE_T ||
452  connected->Parent()->Type() == PCB_VIA_T ||
453  connected->Parent()->Type() == PCB_ARC_T ) )
454  tracks.insert( static_cast<TRACK*> ( connected->Parent() ) );
455  }
456  }
457 
458  std::copy( tracks.begin(), tracks.end(), std::back_inserter( rv ) );
459  return rv;
460 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97

References m_connAlgo, PCB_ARC_T, PCB_TRACE_T, and PCB_VIA_T.

◆ GetConnectivityAlgo()

std::shared_ptr<CN_CONNECTIVITY_ALGO> CONNECTIVITY_DATA::GetConnectivityAlgo ( ) const
inline

Definition at line 236 of file connectivity_data.h.

237  {
238  return m_connAlgo;
239  }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo

References m_connAlgo.

Referenced by TestTrackEndpointDangling().

◆ GetDynamicRatsnest()

const std::vector<RN_DYNAMIC_LINE>& CONNECTIVITY_DATA::GetDynamicRatsnest ( ) const
inline

Definition at line 211 of file connectivity_data.h.

212  {
213  return m_dynamicRatsnest;
214  }
std::vector< RN_DYNAMIC_LINE > m_dynamicRatsnest

References m_dynamicRatsnest.

◆ GetLock()

std::mutex& CONNECTIVITY_DATA::GetLock ( )
inline

Definition at line 241 of file connectivity_data.h.

242  {
243  return m_lock;
244  }

References m_lock.

◆ GetNetCount()

int CONNECTIVITY_DATA::GetNetCount ( ) const

Function GetNetCount() Returns the total number of nets in the connectivity database.

Definition at line 237 of file connectivity_data.cpp.

238 {
239  return m_connAlgo->NetCount();
240 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo

References m_connAlgo.

◆ GetNetItems()

const std::vector< BOARD_CONNECTED_ITEM * > CONNECTIVITY_DATA::GetNetItems ( int  aNetCode,
const KICAD_T  aTypes[] 
) const

Function GetNetItems() Returns the list of items that belong to a certain net.

Parameters
aNetCodeis the net code.
aTypesallows one to filter by item types.

Definition at line 388 of file connectivity_data.cpp.

390 {
391  std::vector<BOARD_CONNECTED_ITEM*> items;
392  items.reserve( 32 );
393 
394  std::bitset<MAX_STRUCT_TYPE_ID> type_bits;
395 
396  for( unsigned int i = 0; aTypes[i] != EOT; ++i )
397  {
398  wxASSERT( aTypes[i] < MAX_STRUCT_TYPE_ID );
399  type_bits.set( aTypes[i] );
400  }
401 
402  m_connAlgo->ForEachItem( [&]( CN_ITEM& aItem ) {
403  if( aItem.Valid() && ( aItem.Net() == aNetCode ) && type_bits[aItem.Parent()->Type()] )
404  items.push_back( aItem.Parent() );
405  } );
406 
407  std::sort( items.begin(), items.end() );
408  items.erase( std::unique( items.begin(), items.end() ), items.end() );
409  return items;
410 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
BOARD_CONNECTED_ITEM * Parent() const
int Net() const
search types array terminator (End Of Types)
Definition: typeinfo.h:82
bool Valid() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References EOT, m_connAlgo, MAX_STRUCT_TYPE_ID, CN_ITEM::Net(), CN_ITEM::Parent(), EDA_ITEM::Type(), and CN_ITEM::Valid().

◆ GetNodeCount()

unsigned int CONNECTIVITY_DATA::GetNodeCount ( int  aNet = -1) const

Definition at line 490 of file connectivity_data.cpp.

491 {
492  int sum = 0;
493 
494  if( aNet < 0 ) // Node count for all nets
495  {
496  for( const auto& net : m_nets )
497  sum += net->GetNodeCount();
498  }
499  else if( aNet < (int) m_nets.size() )
500  {
501  sum = m_nets[aNet]->GetNodeCount();
502  }
503 
504  return sum;
505 }
std::vector< RN_NET * > m_nets

References m_nets.

◆ GetPadCount()

unsigned int CONNECTIVITY_DATA::GetPadCount ( int  aNet = -1) const

Definition at line 508 of file connectivity_data.cpp.

509 {
510  int n = 0;
511 
512  for( auto&& pad : m_connAlgo->ItemList() )
513  {
514  if( !pad->Valid() || pad->Parent()->Type() != PCB_PAD_T)
515  continue;
516 
517  auto dpad = static_cast<D_PAD*>( pad->Parent() );
518 
519  if( aNet < 0 || aNet == dpad->GetNetCode() )
520  {
521  n++;
522  }
523  }
524 
525  return n;
526 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90

References m_connAlgo, and PCB_PAD_T.

◆ GetRatsnestForComponent()

const std::vector< CN_EDGE > CONNECTIVITY_DATA::GetRatsnestForComponent ( MODULE aComponent,
bool  aSkipInternalConnections = false 
)

Definition at line 691 of file connectivity_data.cpp.

692 {
693  std::set<int> nets;
694  std::set<const D_PAD*> pads;
695  std::vector<CN_EDGE> edges;
696 
697  for( auto pad : aComponent->Pads() )
698  {
699  nets.insert( pad->GetNetCode() );
700  pads.insert( pad );
701  }
702 
703  for( const auto& netcode : nets )
704  {
705  const auto& net = GetRatsnestForNet( netcode );
706 
707  for( const auto& edge : net->GetEdges() )
708  {
709  auto srcNode = edge.GetSourceNode();
710  auto dstNode = edge.GetTargetNode();
711 
712  auto srcParent = static_cast<const D_PAD*>( srcNode->Parent() );
713  auto dstParent = static_cast<const D_PAD*>( dstNode->Parent() );
714 
715  bool srcFound = ( pads.find(srcParent) != pads.end() );
716  bool dstFound = ( pads.find(dstParent) != pads.end() );
717 
718  if ( srcFound && dstFound && !aSkipInternalConnections )
719  {
720  edges.push_back( edge );
721  }
722  else if ( srcFound || dstFound )
723  {
724  edges.push_back( edge );
725  }
726  }
727  }
728 
729  return edges;
730 }
PADS & Pads()
Definition: class_module.h:173
RN_NET * GetRatsnestForNet(int aNet)
Function GetRatsnestForNet() Returns the ratsnest, expressed as a set of graph edges for a given net.

References GetRatsnestForNet(), and MODULE::Pads().

◆ GetRatsnestForItems()

const std::vector< CN_EDGE > CONNECTIVITY_DATA::GetRatsnestForItems ( const std::vector< BOARD_ITEM * >  aItems)

Definition at line 637 of file connectivity_data.cpp.

638 {
639  std::set<int> nets;
640  std::vector<CN_EDGE> edges;
641  std::set<BOARD_CONNECTED_ITEM*> item_set;
642 
643  for( auto item : aItems )
644  {
645  auto conn_item = dyn_cast<BOARD_CONNECTED_ITEM*>( item );
646 
647  if( !conn_item )
648  continue;
649 
650  if( item->Type() == PCB_MODULE_T )
651  {
652  auto component = static_cast<MODULE*>( item );
653 
654  for( auto pad : component->Pads() )
655  {
656  nets.insert( pad->GetNetCode() );
657  item_set.insert( pad );
658  }
659  }
660  else
661  {
662  item_set.insert( conn_item );
663  nets.insert( conn_item->GetNetCode() );
664  }
665  }
666 
667  for( const auto& netcode : nets )
668  {
669  const auto& net = GetRatsnestForNet( netcode );
670 
671  for( const auto& edge : net->GetEdges() )
672  {
673  auto srcNode = edge.GetSourceNode();
674  auto dstNode = edge.GetTargetNode();
675 
676  auto srcParent = srcNode->Parent();
677  auto dstParent = dstNode->Parent();
678 
679  bool srcFound = ( item_set.find(srcParent) != item_set.end() );
680  bool dstFound = ( item_set.find(dstParent) != item_set.end() );
681 
682  if ( srcFound && dstFound )
683  edges.push_back( edge );
684  }
685  }
686 
687  return edges;
688 }
class MODULE, a footprint
Definition: typeinfo.h:89
RN_NET * GetRatsnestForNet(int aNet)
Function GetRatsnestForNet() Returns the ratsnest, expressed as a set of graph edges for a given net.

References GetRatsnestForNet(), and PCB_MODULE_T.

Referenced by ComputeDynamicRatsnest().

◆ GetRatsnestForNet()

RN_NET * CONNECTIVITY_DATA::GetRatsnestForNet ( int  aNet)

Function GetRatsnestForNet() Returns the ratsnest, expressed as a set of graph edges for a given net.

Definition at line 603 of file connectivity_data.cpp.

604 {
605  if ( aNet < 0 || aNet >= (int) m_nets.size() )
606  {
607  return nullptr;
608  }
609 
610  return m_nets[ aNet ];
611 }
std::vector< RN_NET * > m_nets

References m_nets.

Referenced by GetRatsnestForComponent(), and GetRatsnestForItems().

◆ GetUnconnectedCount()

unsigned int CONNECTIVITY_DATA::GetUnconnectedCount ( ) const

Function GetUnconnectedCount() Returns the number of remaining edges in the ratsnest.

Definition at line 330 of file connectivity_data.cpp.

331 {
332  unsigned int unconnected = 0;
333 
334  for( auto net : m_nets )
335  {
336  if( !net )
337  continue;
338 
339  const auto& edges = net->GetUnconnected();
340 
341  if( edges.empty() )
342  continue;
343 
344  unconnected += edges.size();
345  }
346 
347  return unconnected;
348 }
std::vector< RN_NET * > m_nets

References m_nets.

◆ GetUnconnectedEdges()

void CONNECTIVITY_DATA::GetUnconnectedEdges ( std::vector< CN_EDGE > &  aEdges) const

Definition at line 529 of file connectivity_data.cpp.

530 {
531  for( auto rnNet : m_nets )
532  {
533  if( rnNet )
534  {
535  for( const auto& edge : rnNet->GetEdges() )
536  {
537  aEdges.push_back( edge );
538  }
539  }
540  }
541 }
std::vector< RN_NET * > m_nets

References m_nets.

◆ HideDynamicRatsnest()

void CONNECTIVITY_DATA::HideDynamicRatsnest ( )

Hides the temporary dynamic ratsnest lines.

Definition at line 318 of file connectivity_data.cpp.

319 {
320  m_dynamicRatsnest.clear();
321 }
std::vector< RN_DYNAMIC_LINE > m_dynamicRatsnest

References m_dynamicRatsnest.

Referenced by ClearDynamicRatsnest().

◆ MarkItemNetAsDirty()

void CONNECTIVITY_DATA::MarkItemNetAsDirty ( BOARD_ITEM aItem)

Definition at line 614 of file connectivity_data.cpp.

615 {
616  if (aItem->Type() == PCB_MODULE_T)
617  {
618  for ( auto pad : static_cast<MODULE*>( aItem )->Pads() )
619  {
620  m_connAlgo->MarkNetAsDirty( pad->GetNetCode() );
621  }
622  }
623  if (aItem->IsConnected() )
624  {
625  m_connAlgo->MarkNetAsDirty( static_cast<BOARD_CONNECTED_ITEM*>( aItem )->GetNetCode() );
626  }
627 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
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:193

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

◆ PropagateNets()

void CONNECTIVITY_DATA::PropagateNets ( )

Function PropagateNets() Propagates the net codes from the source pads to the tracks/vias.

Definition at line 324 of file connectivity_data.cpp.

325 {
326  m_connAlgo->PropagateNets();
327 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo

References m_connAlgo.

◆ RecalculateRatsnest()

void CONNECTIVITY_DATA::RecalculateRatsnest ( BOARD_COMMIT aCommit = nullptr)

Function RecalculateRatsnest() Updates the ratsnest for the board.

Parameters
aCommitis used to save the undo state of items modified by this call

Definition at line 151 of file connectivity_data.cpp.

152 {
153  m_connAlgo->PropagateNets( aCommit );
154 
155  int lastNet = m_connAlgo->NetCount();
156 
157  if( lastNet >= (int) m_nets.size() )
158  {
159  unsigned int prevSize = m_nets.size();
160  m_nets.resize( lastNet + 1 );
161 
162  for( unsigned int i = prevSize; i < m_nets.size(); i++ )
163  m_nets[i] = new RN_NET;
164  }
165 
166  auto clusters = m_connAlgo->GetClusters();
167 
168  int dirtyNets = 0;
169 
170  for( int net = 0; net < lastNet; net++ )
171  {
172  if( m_connAlgo->IsNetDirty( net ) )
173  {
174  m_nets[net]->Clear();
175  dirtyNets++;
176  }
177  }
178 
179  for( const auto& c : clusters )
180  {
181  int net = c->OriginNet();
182 
183  // Don't add intentionally-kept zone islands to the ratsnest
184  if( c->IsOrphaned() && c->Size() == 1 )
185  {
186  if( dynamic_cast<CN_ZONE*>( *c->begin() ) )
187  continue;
188  }
189 
190  if( m_connAlgo->IsNetDirty( net ) )
191  {
192  addRatsnestCluster( c );
193  }
194  }
195 
196  m_connAlgo->ClearDirtyFlags();
197 
198  if( !m_skipRatsnest )
199  updateRatsnest();
200 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
std::vector< RN_NET * > m_nets
RN_NET Describes ratsnest for a single net.
Definition: ratsnest_data.h:61
void addRatsnestCluster(const std::shared_ptr< CN_CLUSTER > &aCluster)

References addRatsnestCluster(), m_connAlgo, m_nets, m_skipRatsnest, and updateRatsnest().

Referenced by Build(), and CheckConnectivity().

◆ Remove()

bool CONNECTIVITY_DATA::Remove ( BOARD_ITEM aItem)

Function Remove() Removes an item from the connectivity data.

Parameters
aItemis an item to be updated.
Returns
True if operation succeeded.

Definition at line 66 of file connectivity_data.cpp.

67 {
68  m_connAlgo->Remove( aItem );
69  return true;
70 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo

References m_connAlgo.

◆ SetProgressReporter()

void CONNECTIVITY_DATA::SetProgressReporter ( PROGRESS_REPORTER aReporter)

Definition at line 630 of file connectivity_data.cpp.

631 {
632  m_progressReporter = aReporter;
633  m_connAlgo->SetProgressReporter( m_progressReporter );
634 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
PROGRESS_REPORTER * m_progressReporter

References m_connAlgo, and m_progressReporter.

◆ TestTrackEndpointDangling()

bool CONNECTIVITY_DATA::TestTrackEndpointDangling ( TRACK aTrack,
wxPoint aPos = nullptr 
)

Definition at line 544 of file connectivity_data.cpp.

545 {
546  auto items = GetConnectivityAlgo()->ItemEntry( aTrack ).GetItems();
547 
548  // Not in the connectivity system. This is a bug!
549  if( items.empty() )
550  {
551  wxFAIL_MSG( "track not in connectivity system" );
552  return false;
553  }
554 
555  CN_ITEM* citem = items.front();
556 
557  if( !citem->Valid() )
558  return false;
559 
560  for( const std::shared_ptr<CN_ANCHOR>& anchor : citem->Anchors() )
561  {
562  if( anchor->IsDangling() )
563  {
564  if( aPos )
565  *aPos = static_cast<wxPoint>( anchor->Pos() );
566 
567  return true;
568  }
569  }
570 
571  return false;
572 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > GetConnectivityAlgo() const
CN_ANCHORS & Anchors()
bool Valid() const

References CN_ITEM::Anchors(), GetConnectivityAlgo(), and CN_ITEM::Valid().

◆ Update()

bool CONNECTIVITY_DATA::Update ( BOARD_ITEM aItem)

Function Update() Updates the connectivity data for an item.

Parameters
aItemis an item to be updated.
Returns
True if operation succeeded.

Definition at line 73 of file connectivity_data.cpp.

74 {
75  m_connAlgo->Remove( aItem );
76  m_connAlgo->Add( aItem );
77  return true;
78 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo

References m_connAlgo.

Referenced by updateRatsnest().

◆ updateRatsnest()

void CONNECTIVITY_DATA::updateRatsnest ( )
private

Definition at line 98 of file connectivity_data.cpp.

99 {
100  #ifdef PROFILE
101  PROF_COUNTER rnUpdate( "update-ratsnest" );
102  #endif
103  std::vector<RN_NET*> dirty_nets;
104 
105  // Start with net 1 as net 0 is reserved for not-connected
106  // Nets without nodes are also ignored
107  std::copy_if( m_nets.begin() + 1, m_nets.end(), std::back_inserter( dirty_nets ),
108  [] ( RN_NET* aNet ) { return aNet->IsDirty() && aNet->GetNodeCount() > 0; } );
109 
110  // We don't want to spin up a new thread for fewer than 8 nets (overhead costs)
111  size_t parallelThreadCount = std::min<size_t>( std::thread::hardware_concurrency(),
112  ( dirty_nets.size() + 7 ) / 8 );
113 
114  std::atomic<size_t> nextNet( 0 );
115  std::vector<std::future<size_t>> returns( parallelThreadCount );
116 
117  auto update_lambda = [&nextNet, &dirty_nets]() -> size_t
118  {
119  for( size_t i = nextNet++; i < dirty_nets.size(); i = nextNet++ )
120  dirty_nets[i]->Update();
121 
122  return 1;
123  };
124 
125  if( parallelThreadCount == 1 )
126  update_lambda();
127  else
128  {
129  for( size_t ii = 0; ii < parallelThreadCount; ++ii )
130  returns[ii] = std::async( std::launch::async, update_lambda );
131 
132  // Finalize the ratsnest threads
133  for( size_t ii = 0; ii < parallelThreadCount; ++ii )
134  returns[ii].wait();
135  }
136 
137  #ifdef PROFILE
138  rnUpdate.Show();
139  #endif /* PROFILE */
140 }
bool Update(BOARD_ITEM *aItem)
Function Update() Updates the connectivity data for an item.
The class PROF_COUNTER is a small class to help profiling.
Definition: profile.h:44
std::vector< RN_NET * > m_nets
RN_NET Describes ratsnest for a single net.
Definition: ratsnest_data.h:61

References m_nets, PROF_COUNTER::Show(), and Update().

Referenced by RecalculateRatsnest().

Member Data Documentation

◆ m_connAlgo

◆ m_dynamicRatsnest

std::vector<RN_DYNAMIC_LINE> CONNECTIVITY_DATA::m_dynamicRatsnest
private

◆ m_lock

std::mutex CONNECTIVITY_DATA::m_lock
private

Definition at line 269 of file connectivity_data.h.

Referenced by GetLock().

◆ m_nets

◆ m_progressReporter

PROGRESS_REPORTER* CONNECTIVITY_DATA::m_progressReporter
private

Definition at line 265 of file connectivity_data.h.

Referenced by CONNECTIVITY_DATA(), and SetProgressReporter().

◆ m_skipRatsnest

bool CONNECTIVITY_DATA::m_skipRatsnest = false
private

Definition at line 267 of file connectivity_data.h.

Referenced by RecalculateRatsnest().


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