KiCad PCB EDA Suite
CN_ITEM Class Reference

#include <connectivity_items.h>

Inheritance diagram for CN_ITEM:
CN_ZONE

Public Types

using CONNECTED_ITEMS = std::vector< 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
 

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 165 of file connectivity_items.h.

Member Typedef Documentation

◆ CONNECTED_ITEMS

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

Definition at line 168 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 203 of file connectivity_items.h.

204  {
205  m_parent = aParent;
206  m_canChangeNet = aCanChangeNet;
207  m_visited = false;
208  m_valid = true;
209  m_dirty = true;
210  m_anchors.reserve( std::max( 6, aAnchorCount ) );
212  m_connected.reserve( 8 );
213  }
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?
CONNECTED_ITEMS m_connected
list of items physically connected (touching)
LAYER_RANGE.
Definition: pns_layerset.h:32
CN_ANCHORS m_anchors

References m_anchors, m_canChangeNet, m_connected, 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 215 of file connectivity_items.h.

215 {};

Member Function Documentation

◆ AddAnchor()

void CN_ITEM::AddAnchor ( const VECTOR2I aPos)
inline

Definition at line 217 of file connectivity_items.h.

218  {
219  m_anchors.emplace_back( std::make_shared<CN_ANCHOR>( aPos, this ) );
220  }
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  case PCB_ARC_T:
40  return 2; // start and end
41  default:
42  return 1;
43  }
44 }
BOARD_CONNECTED_ITEM * m_parent
bool m_valid
valid flag, used to identify garbage items (we use lazy removal)
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
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References m_parent, m_valid, PCB_ARC_T, 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 222 of file connectivity_items.h.

223  {
224  return m_anchors;
225  }
CN_ANCHORS m_anchors

References m_anchors.

Referenced by CONNECTIVITY_DATA::TestTrackEndpointDangling().

◆ BBox()

const BOX2I& CN_ITEM::BBox ( )
inline

Definition at line 287 of file connectivity_items.h.

288  {
289  if( m_dirty && m_valid )
290  {
292  m_bbox = BOX2I( box.GetPosition(), box.GetSize() );
293  }
294  return m_bbox;
295  }
BOX2< VECTOR2I > BOX2I
Definition: box2.h:522
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
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.
Definition: base_struct.cpp:97
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_VISITOR::checkZoneItemConnection(), and CN_LIST::FindNearby().

◆ CanChangeNet()

bool CN_ITEM::CanChangeNet ( ) const
inline

Definition at line 322 of file connectivity_items.h.

323  {
324  return m_canChangeNet;
325  }
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 307 of file connectivity_items.h.

308  {
309  m_connected.clear();
310  }
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 327 of file connectivity_items.h.

328  {
329  std::lock_guard<std::mutex> lock( m_listLock );
330 
331  auto i = std::lower_bound( m_connected.begin(), m_connected.end(), b );
332 
333  if( i != m_connected.end() && *i == b )
334  return;
335 
336  m_connected.insert( i, b );
337  }
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 302 of file connectivity_items.h.

303  {
304  return m_connected;
305  }
CONNECTED_ITEMS m_connected
list of items physically connected (touching)

References m_connected.

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

◆ Dirty()

bool CN_ITEM::Dirty ( ) const
inline

Definition at line 242 of file connectivity_items.h.

243  {
244  return m_dirty;
245  }
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 151 of file connectivity_items.cpp.

152 {
153  printf(" valid: %d, connected: \n", !!Valid());
154 
155  for( auto i : m_connected )
156  {
157  TRACK* t = static_cast<TRACK*>( i->Parent() );
158  printf( " - %p %d\n", t, t->Type() );
159  }
160 }
CONNECTED_ITEMS m_connected
list of items physically connected (touching)
bool Valid() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

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

◆ GetAnchor()

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

Reimplemented in CN_ZONE.

Definition at line 47 of file connectivity_items.cpp.

48 {
49  VECTOR2I pt0;
50 
51  if( !m_valid )
52  return pt0;
53 
54  switch( m_parent->Type() )
55  {
56  case PCB_PAD_T:
57  {
58  D_PAD* pad = (D_PAD*) m_parent;
59 
60  if( n == 0 )
61  return VECTOR2I( pad->GetPosition() );
62 
63  // ShapePos() is the geometric center (not anchor) for the pad
64  pt0 = pad->ShapePos();
65  VECTOR2I pt1 = pt0;
66 
67  switch( pad->GetShape() )
68  {
70  // Because the trap delta is applied as +1/2 at one end and -1/2 at the other,
71  // the midpoint is actually unchanged. Therefore all the cardinal points are
72  // the same as for a rectangle.
74 
75  case PAD_SHAPE_RECT:
76  case PAD_SHAPE_CIRCLE:
77  case PAD_SHAPE_OVAL:
80  switch( n )
81  {
82  case 1: pt1.y -= pad->GetSize().y / 2; break; // North
83  case 2: pt1.y += pad->GetSize().y / 2; break; // South
84  case 3: pt1.x -= pad->GetSize().x / 2; break; // East
85  case 4: pt1.x += pad->GetSize().x / 2; break; // West
86  default: break; // Wicked witch
87  }
88 
89  if( pad->GetOrientation() )
90  RotatePoint( pt1, pad->ShapePos(), pad->GetOrientation() );
91 
92  // Thermal spokes on circular pads form an 'X' instead of a '+'
93  if( pad->GetShape() == PAD_SHAPE_CIRCLE )
94  RotatePoint( pt1, pad->ShapePos(), 450 );
95 
96  return pt1;
97 
98  case PAD_SHAPE_CUSTOM:
99  {
100  switch( n )
101  {
102  case 1: pt1.y = INT_MIN / 2; break; // North
103  case 2: pt1.y = INT_MAX / 2; break; // South
104  case 3: pt1.x = INT_MIN / 2; break; // East
105  case 4: pt1.x = INT_MAX / 2; break; // West
106  default: break; // Wicked witch
107  }
108 
109  if( pad->GetOrientation() )
110  RotatePoint( pt1, pad->ShapePos(), pad->GetOrientation() );
111 
112  const std::shared_ptr<SHAPE_POLY_SET>& padPolySet = pad->GetEffectivePolygon();
113  const SHAPE_LINE_CHAIN& padOutline = padPolySet->COutline( 0 );
114  SHAPE_LINE_CHAIN::INTERSECTIONS intersections;
115 
116  padOutline.Intersect( SEG( pt0, pt1 ), intersections );
117 
118  if( intersections.empty() )
119  {
120  // There should always be at least some copper outside the hole and/or
121  // shapePos center
122  assert( false );
123  return pt0;
124  }
125 
126  return intersections[ intersections.size() - 1 ].p;
127  }
128  }
129 
130  break;
131  }
132  case PCB_TRACE_T:
133  case PCB_ARC_T:
134  if( n == 0 )
135  return static_cast<const TRACK*>( m_parent )->GetStart();
136  else
137  return static_cast<const TRACK*>( m_parent )->GetEnd();
138 
139  case PCB_VIA_T:
140  return static_cast<const VIA*>( m_parent )->GetStart();
141 
142  default:
143  assert( false );
144  break;
145  }
146 
147  return pt0;
148 }
int Intersect(const SEG &aSeg, INTERSECTIONS &aIp) const
Function Intersect()
#define KI_FALLTHROUGH
std::vector< INTERSECTION > INTERSECTIONS
BOARD_CONNECTED_ITEM * m_parent
wxPoint GetPosition() const override
Definition: class_pad.h:165
bool m_valid
valid flag, used to identify garbage items (we use lazy removal)
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 RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
const std::shared_ptr< SHAPE_POLY_SET > & GetEffectivePolygon() const
Definition: class_pad.cpp:216
Definition: seg.h:39
SHAPE_LINE_CHAIN.
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees,...
Definition: class_pad.h:325
wxPoint ShapePos() const
Definition: class_pad.cpp:563
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
PAD_SHAPE_T GetShape() const
Definition: class_pad.h:157
const wxSize & GetSize() const
Definition: class_pad.h:224
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References D_PAD::GetEffectivePolygon(), D_PAD::GetOrientation(), D_PAD::GetPosition(), D_PAD::GetShape(), D_PAD::GetSize(), SHAPE_LINE_CHAIN::Intersect(), KI_FALLTHROUGH, 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_ARC_T, 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 282 of file connectivity_items.h.

283  {
284  return Layers().Start();
285  }
int Start() const
Definition: pns_layerset.h:83
const LAYER_RANGE & Layers() const
Function Layers()

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

Referenced by CN_VISITOR::checkZoneZoneConnection().

◆ Layers()

const LAYER_RANGE& CN_ITEM::Layers ( ) const
inline

Function Layers()

Returns the contiguous set of layers spanned by the item.

Definition at line 272 of file connectivity_items.h.

273  {
274  return m_layers;
275  }
LAYER_RANGE m_layers
layer range over which the item exists

References m_layers.

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

◆ Net()

int CN_ITEM::Net ( ) const
inline

Definition at line 344 of file connectivity_items.h.

345  {
346  return ( !m_parent || !m_valid ) ? -1 : m_parent->GetNetCode();
347  }
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(), NETCODE_CMP_LESS::operator()(), and CN_CONNECTIVITY_ALGO::SearchClusters().

◆ Parent()

◆ RemoveInvalidRefs()

void CN_ITEM::RemoveInvalidRefs ( )

Definition at line 187 of file connectivity_items.cpp.

188 {
189  for( auto it = m_connected.begin(); it != m_connected.end(); )
190  {
191  if( !(*it)->Valid() )
192  it = m_connected.erase( it );
193  else
194  ++it;
195  }
196 }
CONNECTED_ITEMS m_connected
list of items physically connected (touching)

References m_connected.

◆ SetDirty()

void CN_ITEM::SetDirty ( bool  aDirty)
inline

Definition at line 237 of file connectivity_items.h.

238  {
239  m_dirty = aDirty;
240  }
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 262 of file connectivity_items.h.

263  {
264  m_layers = LAYER_RANGE( aLayer, aLayer );
265  }
LAYER_RANGE m_layers
layer range over which the item exists
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 252 of file connectivity_items.h.

253  {
254  m_layers = aLayers;
255  }
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 227 of file connectivity_items.h.

228  {
229  m_valid = aValid;
230  }
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 312 of file connectivity_items.h.

313  {
314  m_visited = aVisited;
315  }
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

◆ Visited()

bool CN_ITEM::Visited ( ) const
inline

Definition at line 317 of file connectivity_items.h.

318  {
319  return m_visited;
320  }
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 176 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 198 of file connectivity_items.h.

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

◆ m_canChangeNet

bool CN_ITEM::m_canChangeNet
private

can the net propagator modify the netcode?

Definition at line 182 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 174 of file connectivity_items.h.

Referenced by ClearConnections(), CN_ITEM(), 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 192 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 195 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 188 of file connectivity_items.h.

Referenced by Connect().

◆ m_parent

BOARD_CONNECTED_ITEM* CN_ITEM::m_parent
private

Definition at line 171 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 185 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 179 of file connectivity_items.h.

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


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