KiCad PCB EDA Suite
CN_ITEM Class Reference

#include <connectivity_items.h>

Inheritance diagram for CN_ITEM:
INTRUSIVE_LIST< CN_ITEM > CN_ZONE

Public Types

using CONNECTED_ITEMS = std::set< CN_ITEM * >
 

Public Member Functions

void Dump ()
 
 CN_ITEM (BOARD_CONNECTED_ITEM *aParent, bool aCanChangeNet, int aAnchorCount=2)
 
virtual ~CN_ITEM ()
 
void AddAnchor (const VECTOR2I &aPos)
 
CN_ANCHORSAnchors ()
 
void SetValid (bool aValid)
 
bool Valid () const
 
void SetDirty (bool aDirty)
 
bool Dirty () const
 
void SetLayers (const LAYER_RANGE &aLayers)
 Function SetLayers() More...
 
void SetLayer (int aLayer)
 Function SetLayer() More...
 
const LAYER_RANGELayers () const
 Function Layers() More...
 
virtual int Layer () const
 Function Layer() More...
 
const BOX2IBBox ()
 
BOARD_CONNECTED_ITEMParent () const
 
const CONNECTED_ITEMSConnectedItems () const
 
void ClearConnections ()
 
void SetVisited (bool aVisited)
 
bool Visited () const
 
bool CanChangeNet () const
 
void Connect (CN_ITEM *b)
 
void RemoveInvalidRefs ()
 
virtual int AnchorCount () const
 
virtual const VECTOR2I GetAnchor (int n) const
 
int Net () const
 
void ListClear ()
 
CN_ITEMListRemove ()
 
int ListSize () const
 
void ListInsert (CN_ITEM *item)
 
CN_ITEMListNext () const
 
CN_ITEMListPrev () const
 

Protected Attributes

bool m_dirty
 

dirty flag, used to identify recently added item not yet scanned into the connectivity search

More...
 
LAYER_RANGE m_layers
 

layer range over which the item exists

More...
 
BOX2I m_bbox
 

bounding box for the item

More...
 

Private Attributes

BOARD_CONNECTED_ITEMm_parent
 
CONNECTED_ITEMS m_connected
 

list of items physically connected (touching)

More...
 
CN_ANCHORS m_anchors
 
bool m_visited
 

visited flag for the BFS scan

More...
 
bool m_canChangeNet
 

can the net propagator modify the netcode?

More...
 
bool m_valid
 

valid flag, used to identify garbage items (we use lazy removal)

More...
 
std::mutex m_listLock
 

mutex protecting this item's connected_items set to allow parallel connection threads

More...
 

Detailed Description

Definition at line 159 of file connectivity_items.h.

Member Typedef Documentation

◆ CONNECTED_ITEMS

using CN_ITEM::CONNECTED_ITEMS = std::set<CN_ITEM*>

Definition at line 162 of file connectivity_items.h.

Constructor & Destructor Documentation

◆ CN_ITEM()

CN_ITEM::CN_ITEM ( BOARD_CONNECTED_ITEM aParent,
bool  aCanChangeNet,
int  aAnchorCount = 2 
)
inline

Definition at line 197 of file connectivity_items.h.

198  {
199  m_parent = aParent;
200  m_canChangeNet = aCanChangeNet;
201  m_visited = false;
202  m_valid = true;
203  m_dirty = true;
204  m_anchors.reserve( 2 );
206  }
BOARD_CONNECTED_ITEM * m_parent
bool m_valid
valid flag, used to identify garbage items (we use lazy removal)
LAYER_RANGE m_layers
layer range over which the item exists
bool m_visited
visited flag for the BFS scan
bool m_dirty
dirty flag, used to identify recently added item not yet scanned into the connectivity search
bool m_canChangeNet
can the net propagator modify the netcode?
Class LAYER_RANGE.
Definition: pns_layerset.h:32
CN_ANCHORS m_anchors

References m_anchors, m_canChangeNet, m_dirty, m_layers, m_parent, m_valid, m_visited, and PCB_LAYER_ID_COUNT.

◆ ~CN_ITEM()

virtual CN_ITEM::~CN_ITEM ( )
inlinevirtual

Definition at line 208 of file connectivity_items.h.

208 {};

Member Function Documentation

◆ AddAnchor()

void CN_ITEM::AddAnchor ( const VECTOR2I aPos)
inline

Definition at line 210 of file connectivity_items.h.

211  {
212  m_anchors.emplace_back( std::make_unique<CN_ANCHOR>( aPos, this ) );
213  }
CN_ANCHORS m_anchors

References m_anchors.

Referenced by CN_LIST::Add().

◆ AnchorCount()

int CN_ITEM::AnchorCount ( ) const
virtual

Reimplemented in CN_ZONE.

Definition at line 29 of file connectivity_items.cpp.

30 {
31  if( !m_valid )
32  return 0;
33 
34  switch( m_parent->Type() )
35  {
36  case PCB_PAD_T:
37  return 5; // center, north, south, east and west
38  case PCB_TRACE_T:
39  return 2; // stard and end
40  default:
41  return 1;
42  }
43 }
BOARD_CONNECTED_ITEM * m_parent
bool m_valid
valid flag, used to identify garbage items (we use lazy removal)
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

References m_parent, m_valid, PCB_PAD_T, PCB_TRACE_T, and EDA_ITEM::Type().

Referenced by CN_VISITOR::checkZoneItemConnection(), CN_ANCHOR::IsDangling(), and CN_VISITOR::operator()().

◆ Anchors()

CN_ANCHORS& CN_ITEM::Anchors ( )
inline

Definition at line 215 of file connectivity_items.h.

216  {
217  return m_anchors;
218  }
CN_ANCHORS m_anchors

References m_anchors.

Referenced by CN_CONNECTIVITY_ALGO::ForEachAnchor().

◆ BBox()

const BOX2I& CN_ITEM::BBox ( )
inline

Definition at line 280 of file connectivity_items.h.

281  {
282  if( m_dirty && m_valid )
283  {
285  m_bbox = BOX2I( box.GetPosition(), box.GetSize() );
286  }
287  return m_bbox;
288  }
BOX2< VECTOR2I > BOX2I
Definition: box2.h:520
BOARD_CONNECTED_ITEM * m_parent
bool m_valid
valid flag, used to identify garbage items (we use lazy removal)
const wxPoint GetPosition() const
Definition: eda_rect.h:115
bool m_dirty
dirty flag, used to identify recently added item not yet scanned into the connectivity search
BOX2I m_bbox
bounding box for the item
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
const wxSize GetSize() const
Definition: eda_rect.h:103

References EDA_ITEM::GetBoundingBox(), EDA_RECT::GetPosition(), EDA_RECT::GetSize(), m_bbox, m_dirty, m_parent, and m_valid.

Referenced by CN_LIST::FindNearby().

◆ CanChangeNet()

bool CN_ITEM::CanChangeNet ( ) const
inline

Definition at line 315 of file connectivity_items.h.

316  {
317  return m_canChangeNet;
318  }
bool m_canChangeNet
can the net propagator modify the netcode?

References m_canChangeNet.

Referenced by CN_VISITOR::checkZoneItemConnection().

◆ ClearConnections()

void CN_ITEM::ClearConnections ( )
inline

Definition at line 300 of file connectivity_items.h.

301  {
302  m_connected.clear();
303  }
CONNECTED_ITEMS m_connected
list of items physically connected (touching)

References m_connected.

◆ Connect()

void CN_ITEM::Connect ( CN_ITEM b)
inline

Definition at line 320 of file connectivity_items.h.

321  {
322  std::lock_guard<std::mutex> lock( m_listLock );
323  m_connected.insert( b );
324  }
std::mutex m_listLock
mutex protecting this item's connected_items set to allow parallel connection threads
CONNECTED_ITEMS m_connected
list of items physically connected (touching)

References m_connected, and m_listLock.

Referenced by CN_VISITOR::checkZoneItemConnection(), CN_VISITOR::checkZoneZoneConnection(), and CN_VISITOR::operator()().

◆ ConnectedItems()

const CONNECTED_ITEMS& CN_ITEM::ConnectedItems ( ) const
inline

Definition at line 295 of file connectivity_items.h.

296  {
297  return m_connected;
298  }
CONNECTED_ITEMS m_connected
list of items physically connected (touching)

References m_connected.

Referenced by CN_ANCHOR::ConnectedItemsCount(), CN_ANCHOR::IsDangling(), and CN_CONNECTIVITY_ALGO::SearchClusters().

◆ Dirty()

bool CN_ITEM::Dirty ( ) const
inline

Definition at line 235 of file connectivity_items.h.

236  {
237  return m_dirty;
238  }
bool m_dirty
dirty flag, used to identify recently added item not yet scanned into the connectivity search

References m_dirty.

Referenced by CN_VISITOR::operator()().

◆ Dump()

void CN_ITEM::Dump ( )

Definition at line 138 of file connectivity_items.cpp.

139 {
140  printf(" valid: %d, connected: \n", !!Valid());
141 
142  for( auto i : m_connected )
143  {
144  TRACK* t = static_cast<TRACK*>( i->Parent() );
145  printf( " - %p %d\n", t, t->Type() );
146  }
147 }
size_t i
Definition: json11.cpp:597
CONNECTED_ITEMS m_connected
list of items physically connected (touching)
bool Valid() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

References i, m_connected, EDA_ITEM::Type(), and Valid().

Referenced by CN_CONNECTIVITY_ALGO::SearchClusters().

◆ GetAnchor()

const VECTOR2I CN_ITEM::GetAnchor ( int  n) const
virtual

Reimplemented in CN_ZONE.

Definition at line 46 of file connectivity_items.cpp.

47 {
48  VECTOR2I pt0;
49 
50  if( !m_valid )
51  return pt0;
52 
53  switch( m_parent->Type() )
54  {
55  case PCB_PAD_T:
56  {
57  D_PAD* pad = (D_PAD*) m_parent;
58 
59  if( n == 0 )
60  return VECTOR2I( pad->GetPosition() );
61 
62  // ShapePos() is the geometric center (not anchor) for the pad
63  pt0 = pad->ShapePos();
64  VECTOR2I pt1 = pt0;
65 
66  switch( n )
67  {
68  case 1: pt1.y = m_bbox.GetTop(); break; // North
69  case 2: pt1.y = m_bbox.GetBottom(); break; // South
70  case 3: pt1.x = m_bbox.GetLeft(); break; // East
71  case 4: pt1.x = m_bbox.GetRight(); break; // West
72  default: break; // Wicked witch
73  }
74 
75  switch( pad->GetShape() )
76  {
77  case PAD_SHAPE_RECT:
78  case PAD_SHAPE_OVAL:
81  return pt1;
82 
83  case PAD_SHAPE_CIRCLE:
84  // Thermal spokes on circular pads form an 'X' instead of a '+'
85  RotatePoint( pt1, pad->ShapePos(), 450 );
86  return pt1;
87 
89  case PAD_SHAPE_CUSTOM:
90  {
91  SHAPE_POLY_SET padPolySet;
92  pad->BuildPadShapePolygon( padPolySet, wxSize( 0, 0 ), ARC_LOW_DEF );
93  const SHAPE_LINE_CHAIN& padOutline = padPolySet.COutline( 0 );
94  SHAPE_LINE_CHAIN::INTERSECTIONS intersections;
95 
96  padOutline.Intersect( SEG( pt0, pt1 ), intersections );
97 
98  if( intersections.empty() )
99  {
100  // There should always be at least some copper outside the hole
101  assert( false );
102  return pt0;
103  }
104 
105  return intersections[ intersections.size() - 1 ].p;
106  }
107  }
108 
109  break;
110  }
111  case PCB_TRACE_T:
112  if( n == 0 )
113  return static_cast<const TRACK*>( m_parent )->GetStart();
114  else
115  return static_cast<const TRACK*>( m_parent )->GetEnd();
116 
117  case PCB_VIA_T:
118  return static_cast<const VIA*>( m_parent )->GetStart();
119 
120  default:
121  assert( false );
122  break;
123  }
124 
125  return pt0;
126 }
int Intersect(const SEG &aSeg, INTERSECTIONS &aIp) const
Function Intersect()
std::vector< INTERSECTION > INTERSECTIONS
BOARD_CONNECTED_ITEM * m_parent
coord_type GetTop() const
Definition: box2.h:202
bool m_valid
valid flag, used to identify garbage items (we use lazy removal)
void BuildPadShapePolygon(SHAPE_POLY_SET &aCornerBuffer, wxSize aInflateValue, int aError=ARC_HIGH_DEF) const
Function BuildPadShapePolygon Build the Corner list of the polygonal shape, depending on shape,...
coord_type GetRight() const
Definition: box2.h:197
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:206
coord_type GetBottom() const
Definition: box2.h:198
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
Class SHAPE_POLY_SET.
BOX2I m_bbox
bounding box for the item
Definition: seg.h:36
Class SHAPE_LINE_CHAIN.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
wxPoint ShapePos() const
Definition: class_pad.cpp:570
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:221
coord_type GetLeft() const
Definition: box2.h:201
const wxPoint GetPosition() const override
Definition: class_pad.h:225
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

References D_PAD::BuildPadShapePolygon(), SHAPE_POLY_SET::COutline(), BOX2< Vec >::GetBottom(), BOX2< Vec >::GetLeft(), D_PAD::GetPosition(), BOX2< Vec >::GetRight(), D_PAD::GetShape(), BOX2< Vec >::GetTop(), SHAPE_LINE_CHAIN::Intersect(), m_bbox, m_parent, m_valid, PAD_SHAPE_CHAMFERED_RECT, PAD_SHAPE_CIRCLE, PAD_SHAPE_CUSTOM, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, PAD_SHAPE_ROUNDRECT, PAD_SHAPE_TRAPEZOID, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, RotatePoint(), D_PAD::ShapePos(), EDA_ITEM::Type(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by CN_VISITOR::checkZoneItemConnection(), and CN_VISITOR::operator()().

◆ Layer()

virtual int CN_ITEM::Layer ( ) const
inlinevirtual

Function Layer()

Returns the item's layer, for single-layered items only.

Definition at line 275 of file connectivity_items.h.

276  {
277  return Layers().Start();
278  }
int Start() const
Definition: pns_layerset.h:83
const LAYER_RANGE & Layers() const
Function Layers()

References Layers(), and LAYER_RANGE::Start().

◆ Layers()

const LAYER_RANGE& CN_ITEM::Layers ( ) const
inline

Function Layers()

Returns the contiguous set of layers spanned by the item.

Definition at line 265 of file connectivity_items.h.

266  {
267  return m_layers;
268  }
LAYER_RANGE m_layers
layer range over which the item exists

References m_layers.

Referenced by CN_LIST::FindNearby(), and Layer().

◆ ListClear()

void INTRUSIVE_LIST< CN_ITEM >::ListClear ( )
inlineinherited

Definition at line 38 of file intrusive_list.h.

39  {
40  m_prev = nullptr;
41  m_next = nullptr;
42  m_root = (T*) this;
43  m_count = 1;
44  }

◆ ListInsert()

void INTRUSIVE_LIST< CN_ITEM >::ListInsert ( CN_ITEM item)
inlineinherited

Definition at line 74 of file intrusive_list.h.

75  {
76  if( !m_root )
77  m_root = item;
78 
79  if( m_next )
80  m_next->m_prev = item;
81 
82  item->m_prev = (T*) this;
83  item->m_next = m_next;
84  item->m_root = m_root;
85  m_root->m_count++;
86 
87  m_next = item;
88  }

◆ ListNext()

CN_ITEM * INTRUSIVE_LIST< CN_ITEM >::ListNext ( ) const
inlineinherited

Definition at line 90 of file intrusive_list.h.

90 { return m_next; };

◆ ListPrev()

CN_ITEM * INTRUSIVE_LIST< CN_ITEM >::ListPrev ( ) const
inlineinherited

Definition at line 91 of file intrusive_list.h.

91 { return m_prev; };

◆ ListRemove()

CN_ITEM * INTRUSIVE_LIST< CN_ITEM >::ListRemove ( )
inlineinherited

Definition at line 46 of file intrusive_list.h.

47  {
48  if( m_prev )
49  m_prev->m_next = m_next;
50 
51  if( m_next )
52  m_next->m_prev = m_prev;
53 
54  m_root->m_count--;
55 
56  T* rv = nullptr;
57 
58  if( m_prev )
59  rv = m_prev;
60  else if( m_next )
61  rv = m_next;
62 
63  m_root = nullptr;
64  m_prev = nullptr;
65  m_next = nullptr;
66  return rv;
67  }

◆ ListSize()

int INTRUSIVE_LIST< CN_ITEM >::ListSize ( ) const
inlineinherited

Definition at line 69 of file intrusive_list.h.

70  {
71  return m_root ? m_root->m_count : 0;
72  }

◆ Net()

int CN_ITEM::Net ( ) const

Definition at line 129 of file connectivity_items.cpp.

130 {
131  if( !m_parent || !m_valid )
132  return -1;
133 
134  return m_parent->GetNetCode();
135 }
int GetNetCode() const
Function GetNetCode.
BOARD_CONNECTED_ITEM * m_parent
bool m_valid
valid flag, used to identify garbage items (we use lazy removal)

References BOARD_CONNECTED_ITEM::GetNetCode(), m_parent, and m_valid.

Referenced by CN_CLUSTER::Add(), CN_VISITOR::checkZoneItemConnection(), CN_VISITOR::checkZoneZoneConnection(), CONNECTIVITY_DATA::GetNetItems(), and CN_CONNECTIVITY_ALGO::SearchClusters().

◆ Parent()

◆ RemoveInvalidRefs()

void CN_ITEM::RemoveInvalidRefs ( )

Definition at line 174 of file connectivity_items.cpp.

175 {
176  for( auto it = m_connected.begin(); it != m_connected.end(); )
177  {
178  if( !(*it)->Valid() )
179  it = m_connected.erase( it );
180  else
181  ++it;
182  }
183 }
CONNECTED_ITEMS m_connected
list of items physically connected (touching)

References m_connected.

◆ SetDirty()

void CN_ITEM::SetDirty ( bool  aDirty)
inline

Definition at line 230 of file connectivity_items.h.

231  {
232  m_dirty = aDirty;
233  }
bool m_dirty
dirty flag, used to identify recently added item not yet scanned into the connectivity search

References m_dirty.

◆ SetLayer()

void CN_ITEM::SetLayer ( int  aLayer)
inline

Function SetLayer()

Sets the layers spanned by the item to a single layer aLayer.

Definition at line 255 of file connectivity_items.h.

256  {
257  m_layers = LAYER_RANGE( aLayer, aLayer );
258  }
LAYER_RANGE m_layers
layer range over which the item exists
Class LAYER_RANGE.
Definition: pns_layerset.h:32

References m_layers.

Referenced by CN_LIST::Add().

◆ SetLayers()

void CN_ITEM::SetLayers ( const LAYER_RANGE aLayers)
inline

Function SetLayers()

Sets the layers spanned by the item to aLayers.

Definition at line 245 of file connectivity_items.h.

246  {
247  m_layers = aLayers;
248  }
LAYER_RANGE m_layers
layer range over which the item exists

References m_layers.

◆ SetValid()

void CN_ITEM::SetValid ( bool  aValid)
inline

Definition at line 220 of file connectivity_items.h.

221  {
222  m_valid = aValid;
223  }
bool m_valid
valid flag, used to identify garbage items (we use lazy removal)

References m_valid.

◆ SetVisited()

void CN_ITEM::SetVisited ( bool  aVisited)
inline

Definition at line 305 of file connectivity_items.h.

306  {
307  m_visited = aVisited;
308  }
bool m_visited
visited flag for the BFS scan

References m_visited.

Referenced by CN_CONNECTIVITY_ALGO::SearchClusters().

◆ Valid()

bool CN_ITEM::Valid ( ) const
inline

Definition at line 225 of file connectivity_items.h.

226  {
227  return m_valid;
228  }
bool m_valid
valid flag, used to identify garbage items (we use lazy removal)

References m_valid.

Referenced by CN_ZONE::AnchorCount(), Dump(), CN_ZONE::GetAnchor(), CONNECTIVITY_DATA::GetNetItems(), CN_VISITOR::operator()(), CN_CLUSTER::OriginNetName(), CN_ANCHOR::Parent(), and CN_ANCHOR::Valid().

◆ Visited()

bool CN_ITEM::Visited ( ) const
inline

Definition at line 310 of file connectivity_items.h.

311  {
312  return m_visited;
313  }
bool m_visited
visited flag for the BFS scan

References m_visited.

Member Data Documentation

◆ m_anchors

CN_ANCHORS CN_ITEM::m_anchors
private

Definition at line 170 of file connectivity_items.h.

Referenced by AddAnchor(), Anchors(), and CN_ITEM().

◆ m_bbox

BOX2I CN_ITEM::m_bbox
protected

bounding box for the item

Definition at line 192 of file connectivity_items.h.

Referenced by BBox(), CN_ZONE::BBox(), and GetAnchor().

◆ m_canChangeNet

bool CN_ITEM::m_canChangeNet
private

can the net propagator modify the netcode?

Definition at line 176 of file connectivity_items.h.

Referenced by CanChangeNet(), and CN_ITEM().

◆ m_connected

CONNECTED_ITEMS CN_ITEM::m_connected
private

list of items physically connected (touching)

Definition at line 168 of file connectivity_items.h.

Referenced by ClearConnections(), Connect(), ConnectedItems(), Dump(), and RemoveInvalidRefs().

◆ m_dirty

bool CN_ITEM::m_dirty
protected

dirty flag, used to identify recently added item not yet scanned into the connectivity search

Definition at line 186 of file connectivity_items.h.

Referenced by BBox(), CN_ZONE::BBox(), CN_ITEM(), Dirty(), and SetDirty().

◆ m_layers

LAYER_RANGE CN_ITEM::m_layers
protected

layer range over which the item exists

Definition at line 189 of file connectivity_items.h.

Referenced by CN_ITEM(), Layers(), SetLayer(), and SetLayers().

◆ m_listLock

std::mutex CN_ITEM::m_listLock
private

mutex protecting this item's connected_items set to allow parallel connection threads

Definition at line 182 of file connectivity_items.h.

Referenced by Connect().

◆ m_parent

BOARD_CONNECTED_ITEM* CN_ITEM::m_parent
private

Definition at line 165 of file connectivity_items.h.

Referenced by AnchorCount(), BBox(), CN_ITEM(), GetAnchor(), Net(), and Parent().

◆ m_valid

bool CN_ITEM::m_valid
private

valid flag, used to identify garbage items (we use lazy removal)

Definition at line 179 of file connectivity_items.h.

Referenced by AnchorCount(), BBox(), CN_ITEM(), GetAnchor(), Net(), SetValid(), and Valid().

◆ m_visited

bool CN_ITEM::m_visited
private

visited flag for the BFS scan

Definition at line 173 of file connectivity_items.h.

Referenced by CN_ITEM(), SetVisited(), and Visited().


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