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)
 
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
 
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
 
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...
 
const std::vector< VECTOR2INearestUnconnectedTargets (const BOARD_CONNECTED_ITEM *aRef, const VECTOR2I &aPos, int aMaxCount=-1)
 
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_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
 
std::mutex m_lock
 

Detailed Description

Definition at line 80 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 52 of file connectivity_data.cpp.

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

References Clear().

◆ CONNECTIVITY_DATA() [2/2]

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

Definition at line 45 of file connectivity_data.cpp.

46 {
47  Build( aItems );
48  m_progressReporter = nullptr;
49 }
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 58 of file connectivity_data.cpp.

59 {
60  m_connAlgo->Add( aItem );
61  return true;
62 }
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 142 of file connectivity_data.cpp.

143 {
144  auto rnNet = m_nets[ aCluster->OriginNet() ];
145 
146  rnNet->AddCluster( aCluster );
147 }
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 194 of file connectivity_data.cpp.

195 {
196  std::vector<BOARD_CONNECTED_ITEM*> citems;
197 
198  for( auto item : aItems )
199  {
200  if( item->Type() == PCB_MODULE_T )
201  {
202  for( auto pad : static_cast<MODULE*>(item)->Pads() )
203  citems.push_back( pad );
204  }
205  else
206  {
207  citems.push_back( static_cast<BOARD_CONNECTED_ITEM*>(item) );
208  }
209  }
210 
211  for( const auto& item : citems )
212  {
213  if ( m_connAlgo->ItemExists( item ) )
214  {
215  auto& entry = m_connAlgo->ItemEntry( item );
216 
217  for( const auto& cnItem : entry.GetItems() )
218  {
219  for( auto anchor : cnItem->Anchors() )
220  anchor->SetNoLine( true );
221  }
222  }
223  }
224 }
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 80 of file connectivity_data.cpp.

81 {
82  m_connAlgo.reset( new CN_CONNECTIVITY_ALGO );
83  m_connAlgo->Build( aBoard );
85 }
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 88 of file connectivity_data.cpp.

89 {
90  m_connAlgo.reset( new CN_CONNECTIVITY_ALGO );
91  m_connAlgo->Build( aItems );
92 
94 }
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 414 of file connectivity_data.cpp.

415 {
417 
418  for( auto net : m_nets )
419  {
420  if( net )
421  {
422  for( const auto& edge : net->GetEdges() )
423  {
425  ent.net = edge.GetSourceNode()->Parent()->GetNetCode();
426  ent.a = edge.GetSourceNode()->Parent();
427  ent.b = edge.GetTargetNode()->Parent();
428  ent.anchorA = edge.GetSourceNode()->Pos();
429  ent.anchorB = edge.GetTargetNode()->Pos();
430  aReport.push_back( ent );
431  }
432  }
433  }
434 
435  return aReport.empty();
436 }
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 346 of file connectivity_data.cpp.

347 {
348  for( auto net : m_nets )
349  delete net;
350 
351  m_nets.clear();
352 }
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 306 of file connectivity_data.cpp.

307 {
308  m_connAlgo->ForEachAnchor( [] ( CN_ANCHOR& anchor ) { anchor.SetNoLine( false ); } );
310 }
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 245 of file connectivity_data.cpp.

246 {
247  m_dynamicRatsnest.clear();
248 
249  if( std::none_of( aItems.begin(), aItems.end(), []( const BOARD_ITEM* aItem )
250  { return( aItem->Type() == PCB_TRACE_T || aItem->Type() == PCB_PAD_T ||
251  aItem->Type() == PCB_ARC_T || aItem->Type() == PCB_ZONE_AREA_T ||
252  aItem->Type() == PCB_MODULE_T || aItem->Type() == PCB_VIA_T ); } ) )
253  {
254  return ;
255  }
256 
257  CONNECTIVITY_DATA connData( aItems );
258  BlockRatsnestItems( aItems );
259 
260  for( unsigned int nc = 1; nc < connData.m_nets.size(); nc++ )
261  {
262  auto dynNet = connData.m_nets[nc];
263 
264  if( dynNet->GetNodeCount() != 0 )
265  {
266  auto ourNet = m_nets[nc];
267  CN_ANCHOR_PTR nodeA, nodeB;
268 
269  if( ourNet->NearestBicoloredPair( *dynNet, nodeA, nodeB ) )
270  {
271  RN_DYNAMIC_LINE l;
272  l.a = nodeA->Pos();
273  l.b = nodeB->Pos();
274  l.netCode = nc;
275 
276  m_dynamicRatsnest.push_back( l );
277  }
278  }
279  }
280 
281  for( auto net : connData.m_nets )
282  {
283  if( !net )
284  continue;
285 
286  const auto& edges = net->GetUnconnected();
287 
288  if( edges.empty() )
289  continue;
290 
291  for( const auto& edge : edges )
292  {
293  const auto& nodeA = edge.GetSourceNode();
294  const auto& nodeB = edge.GetTargetNode();
295  RN_DYNAMIC_LINE l;
296 
297  l.a = nodeA->Pos();
298  l.b = nodeB->Pos();
299  l.netCode = 0;
300  m_dynamicRatsnest.push_back( l );
301  }
302  }
303 }
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

References RN_DYNAMIC_LINE::a, RN_DYNAMIC_LINE::b, BlockRatsnestItems(), 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 233 of file connectivity_data.cpp.

235 {
236  m_connAlgo->FindIsolatedCopperIslands( aZone, aIslands );
237 }
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 239 of file connectivity_data.cpp.

240 {
241  m_connAlgo->FindIsolatedCopperIslands( aZones );
242 }
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 607 of file connectivity_data.cpp.

609 {
610  auto& entry = m_connAlgo->ItemEntry( aItem );
611  std::vector<BOARD_CONNECTED_ITEM* > rv;
612 
613  for( auto cnItem : entry.GetItems() )
614  {
615  for( auto anchor : cnItem->Anchors() )
616  {
617  if( anchor->Pos() == aAnchor )
618  {
619  for( int i = 0; aTypes[i] > 0; i++ )
620  {
621  if( cnItem->Valid() && cnItem->Parent()->Type() == aTypes[i] )
622  {
623  rv.push_back( cnItem->Parent() );
624  break;
625  }
626  }
627  }
628  }
629  }
630 
631  return rv;
632 }
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 355 of file connectivity_data.cpp.

359 {
360  std::vector<BOARD_CONNECTED_ITEM*> rv;
361  const auto clusters = m_connAlgo->SearchClusters(
362  aIgnoreNetcodes ?
365  aIgnoreNetcodes ? -1 : aItem->GetNetCode() );
366 
367  for( auto cl : clusters )
368  {
369  if( cl->Contains( aItem ) )
370  {
371  for( const auto item : *cl )
372  {
373  if( item->Valid() )
374  rv.push_back( item->Parent() );
375  }
376  }
377  }
378 
379  return rv;
380 }
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 478 of file connectivity_data.cpp.

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

◆ GetConnectedPads() [2/2]

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

Definition at line 464 of file connectivity_data.cpp.

466 {
467  for( auto citem : m_connAlgo->ItemEntry( aItem ).GetItems() )
468  {
469  for( auto connected : citem->ConnectedItems() )
470  {
471  if( connected->Valid() && connected->Parent()->Type() == PCB_PAD_T )
472  pads->insert( static_cast<D_PAD*> ( connected->Parent() ) );
473  }
474  }
475 }
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 439 of file connectivity_data.cpp.

441 {
442  auto& entry = m_connAlgo->ItemEntry( aItem );
443 
444  std::set<TRACK*> tracks;
445  std::vector<TRACK*> rv;
446 
447  for( auto citem : entry.GetItems() )
448  {
449  for( auto connected : citem->ConnectedItems() )
450  {
451  if( connected->Valid() &&
452  ( connected->Parent()->Type() == PCB_TRACE_T ||
453  connected->Parent()->Type() == PCB_VIA_T ||
454  connected->Parent()->Type() == PCB_ARC_T ) )
455  tracks.insert( static_cast<TRACK*> ( connected->Parent() ) );
456  }
457  }
458 
459  std::copy( tracks.begin(), tracks.end(), std::back_inserter( rv ) );
460  return rv;
461 }
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 234 of file connectivity_data.h.

235  {
236  return m_connAlgo;
237  }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo

References m_connAlgo.

◆ GetDynamicRatsnest()

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

Definition at line 205 of file connectivity_data.h.

206  {
207  return m_dynamicRatsnest;
208  }
std::vector< RN_DYNAMIC_LINE > m_dynamicRatsnest

References m_dynamicRatsnest.

◆ GetLock()

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

Definition at line 239 of file connectivity_data.h.

240  {
241  return m_lock;
242  }

References m_lock.

◆ GetNetCount()

int CONNECTIVITY_DATA::GetNetCount ( ) const

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

Definition at line 227 of file connectivity_data.cpp.

228 {
229  return m_connAlgo->NetCount();
230 }
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 383 of file connectivity_data.cpp.

385 {
386  std::set<BOARD_CONNECTED_ITEM*> items;
387  std::vector<BOARD_CONNECTED_ITEM*> rv;
388 
389  m_connAlgo->ForEachItem( [&items, aNetCode, &aTypes] ( CN_ITEM& aItem )
390  {
391  if( aItem.Valid() && ( aItem.Net() == aNetCode ) )
392  {
393  KICAD_T itemType = aItem.Parent()->Type();
394 
395  for( int i = 0; aTypes[i] > 0; ++i )
396  {
397  wxASSERT( aTypes[i] < MAX_STRUCT_TYPE_ID );
398 
399  if( itemType == aTypes[i] )
400  {
401  items.insert( aItem.Parent() );
402  break;
403  }
404  }
405  }
406  } );
407 
408  std::copy( items.begin(), items.end(), std::back_inserter( rv ) );
409 
410  return rv;
411 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
BOARD_CONNECTED_ITEM * Parent() const
int Net() const
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
bool Valid() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212

References 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 491 of file connectivity_data.cpp.

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

References m_nets.

◆ GetPadCount()

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

Definition at line 509 of file connectivity_data.cpp.

510 {
511  int n = 0;
512 
513  for( auto pad : m_connAlgo->ItemList() )
514  {
515  if( !pad->Valid() || pad->Parent()->Type() != PCB_PAD_T)
516  continue;
517 
518  auto dpad = static_cast<D_PAD*>( pad->Parent() );
519 
520  if( aNet < 0 || aNet == dpad->GetNetCode() )
521  {
522  n++;
523  }
524  }
525 
526  return n;
527 }
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 669 of file connectivity_data.cpp.

670 {
671  std::set<int> nets;
672  std::set<const D_PAD*> pads;
673  std::vector<CN_EDGE> edges;
674 
675  for( auto pad : aComponent->Pads() )
676  {
677  nets.insert( pad->GetNetCode() );
678  pads.insert( pad );
679  }
680 
681  for( const auto& netcode : nets )
682  {
683  const auto& net = GetRatsnestForNet( netcode );
684 
685  for( const auto& edge : net->GetEdges() )
686  {
687  auto srcNode = edge.GetSourceNode();
688  auto dstNode = edge.GetTargetNode();
689 
690  auto srcParent = static_cast<const D_PAD*>( srcNode->Parent() );
691  auto dstParent = static_cast<const D_PAD*>( dstNode->Parent() );
692 
693  bool srcFound = ( pads.find(srcParent) != pads.end() );
694  bool dstFound = ( pads.find(dstParent) != pads.end() );
695 
696  if ( srcFound && dstFound && !aSkipInternalConnections )
697  {
698  edges.push_back( edge );
699  }
700  else if ( srcFound || dstFound )
701  {
702  edges.push_back( edge );
703  }
704  }
705  }
706 
707  return edges;
708 }
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().

◆ 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 635 of file connectivity_data.cpp.

636 {
637  if ( aNet < 0 || aNet >= (int) m_nets.size() )
638  {
639  return nullptr;
640  }
641 
642  return m_nets[ aNet ];
643 }
std::vector< RN_NET * > m_nets

References m_nets.

Referenced by GetRatsnestForComponent().

◆ GetUnconnectedCount()

unsigned int CONNECTIVITY_DATA::GetUnconnectedCount ( ) const

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

Definition at line 325 of file connectivity_data.cpp.

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

References m_nets.

◆ GetUnconnectedEdges()

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

Definition at line 592 of file connectivity_data.cpp.

593 {
594  for( auto rnNet : m_nets )
595  {
596  if( rnNet )
597  {
598  for( const auto& edge : rnNet->GetEdges() )
599  {
600  aEdges.push_back( edge );
601  }
602  }
603  }
604 }
std::vector< RN_NET * > m_nets

References m_nets.

◆ HideDynamicRatsnest()

void CONNECTIVITY_DATA::HideDynamicRatsnest ( )

Hides the temporary dynamic ratsnest lines.

Definition at line 313 of file connectivity_data.cpp.

314 {
315  m_dynamicRatsnest.clear();
316 }
std::vector< RN_DYNAMIC_LINE > m_dynamicRatsnest

References m_dynamicRatsnest.

Referenced by ClearDynamicRatsnest().

◆ MarkItemNetAsDirty()

void CONNECTIVITY_DATA::MarkItemNetAsDirty ( BOARD_ITEM aItem)

Definition at line 646 of file connectivity_data.cpp.

647 {
648  if (aItem->Type() == PCB_MODULE_T)
649  {
650  for ( auto pad : static_cast<MODULE*>( aItem )->Pads() )
651  {
652  m_connAlgo->MarkNetAsDirty( pad->GetNetCode() );
653  }
654  }
655  if (aItem->IsConnected() )
656  {
657  m_connAlgo->MarkNetAsDirty( static_cast<BOARD_CONNECTED_ITEM*>( aItem )->GetNetCode() );
658  }
659 }
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:212

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

◆ NearestUnconnectedTargets()

const std::vector< VECTOR2I > CONNECTIVITY_DATA::NearestUnconnectedTargets ( const BOARD_CONNECTED_ITEM aRef,
const VECTOR2I aPos,
int  aMaxCount = -1 
)

Definition at line 530 of file connectivity_data.cpp.

534 {
535  CN_CLUSTER_PTR refCluster;
536  int refNet = -1;
537 
538  if( aRef )
539  refNet = aRef->GetNetCode();
540 
541  if( aNet >= 0 )
542  refNet = aNet;
543 
544  if( aRef )
545  {
546  for( auto cl : m_connAlgo->GetClusters() )
547  {
548  if( cl->Contains( aRef ) )
549  {
550  refCluster = cl;
551  break;
552  }
553  }
554  }
555 
556  std::set <VECTOR2I> anchors;
557 
558  for( auto cl : m_connAlgo->GetClusters() )
559  {
560  if( cl != refCluster )
561  {
562  for( auto item : *cl )
563  {
564  if( item->Valid() && item->Parent()->GetNetCode() == refNet
565  && item->Parent()->Type() != PCB_ZONE_AREA_T )
566  {
567  for( auto anchor : item->Anchors() )
568  {
569  anchors.insert( anchor->Pos() );
570  }
571  }
572  }
573  }
574  }
575 
576 
577  std::vector<VECTOR2I> rv;
578 
579  std::copy( anchors.begin(), anchors.end(), std::back_inserter( rv ) );
580  std::sort( rv.begin(), rv.end(), [aPos] ( const VECTOR2I& a, const VECTOR2I& b )
581  {
582  auto da = (a - aPos).EuclideanNorm();
583  auto db = (b - aPos).EuclideanNorm();
584 
585  return da < db;
586  } );
587 
588  return rv;
589 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:128
int GetNetCode() const
Function GetNetCode.
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
std::shared_ptr< CN_CLUSTER > CN_CLUSTER_PTR

References EuclideanNorm(), BOARD_CONNECTED_ITEM::GetNetCode(), m_connAlgo, and PCB_ZONE_AREA_T.

◆ PropagateNets()

void CONNECTIVITY_DATA::PropagateNets ( )

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

Definition at line 319 of file connectivity_data.cpp.

320 {
321  m_connAlgo->PropagateNets();
322 }
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 150 of file connectivity_data.cpp.

151 {
152  m_connAlgo->PropagateNets( aCommit );
153 
154  int lastNet = m_connAlgo->NetCount();
155 
156  if( lastNet >= (int) m_nets.size() )
157  {
158  unsigned int prevSize = m_nets.size();
159  m_nets.resize( lastNet + 1 );
160 
161  for( unsigned int i = prevSize; i < m_nets.size(); i++ )
162  m_nets[i] = new RN_NET;
163  }
164 
165  auto clusters = m_connAlgo->GetClusters();
166 
167  int dirtyNets = 0;
168 
169  for( int net = 0; net < lastNet; net++ )
170  {
171  if( m_connAlgo->IsNetDirty( net ) )
172  {
173  m_nets[net]->Clear();
174  dirtyNets++;
175  }
176  }
177 
178  for( const auto& c : clusters )
179  {
180  int net = c->OriginNet();
181 
182  if( m_connAlgo->IsNetDirty( net ) )
183  {
184  addRatsnestCluster( c );
185  }
186  }
187 
188  m_connAlgo->ClearDirtyFlags();
189 
190  updateRatsnest();
191 }
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:59
void addRatsnestCluster(const std::shared_ptr< CN_CLUSTER > &aCluster)

References addRatsnestCluster(), m_connAlgo, m_nets, 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 65 of file connectivity_data.cpp.

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

References m_connAlgo.

◆ SetProgressReporter()

void CONNECTIVITY_DATA::SetProgressReporter ( PROGRESS_REPORTER aReporter)

Definition at line 662 of file connectivity_data.cpp.

663 {
664  m_progressReporter = aReporter;
665  m_connAlgo->SetProgressReporter( m_progressReporter );
666 }
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
PROGRESS_REPORTER * m_progressReporter

References m_connAlgo, and m_progressReporter.

◆ 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 72 of file connectivity_data.cpp.

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

References m_connAlgo.

Referenced by updateRatsnest().

◆ updateRatsnest()

void CONNECTIVITY_DATA::updateRatsnest ( )
private

Definition at line 97 of file connectivity_data.cpp.

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

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 263 of file connectivity_data.h.

Referenced by GetLock().

◆ m_nets

◆ m_progressReporter

PROGRESS_REPORTER* CONNECTIVITY_DATA::m_progressReporter
private

Definition at line 261 of file connectivity_data.h.

Referenced by CONNECTIVITY_DATA(), and SetProgressReporter().


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