KiCad PCB EDA Suite
CN_ITEM Class Reference

#include <connectivity_items.h>

Inheritance diagram for CN_ITEM:
CN_ZONE_LAYER

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)
 Set the layers spanned by the item to aLayers. More...
 
void SetLayer (int aLayer)
 Set the layers spanned by the item to a single layer aLayer. More...
 
const LAYER_RANGELayers () const
 Return the contiguous set of layers spanned by the item. More...
 
virtual int Layer () const
 Return the item's layer, for single-layered items only. 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
 allow parallel connection threads More...
 

Protected Attributes

bool m_dirty
 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_canChangeNet
 can the net propagator modify the netcode? More...
 
bool m_visited
 visited flag for the BFS scan More...
 
bool m_valid
 used to identify garbage items (we use lazy removal) More...
 
std::mutex m_listLock
 mutex protecting this item's connected_items set to More...
 

Detailed Description

Definition at line 168 of file connectivity_items.h.

Member Typedef Documentation

◆ CONNECTED_ITEMS

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

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

176  {
177  m_parent = aParent;
178  m_canChangeNet = aCanChangeNet;
179  m_visited = false;
180  m_valid = true;
181  m_dirty = true;
182  m_anchors.reserve( std::max( 6, aAnchorCount ) );
184  m_connected.reserve( 8 );
185  }
BOARD_CONNECTED_ITEM * m_parent
bool m_valid
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
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)
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:31
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 187 of file connectivity_items.h.

187 {};

Member Function Documentation

◆ AddAnchor()

void CN_ITEM::AddAnchor ( const VECTOR2I aPos)
inline

Definition at line 189 of file connectivity_items.h.

190  {
191  m_anchors.emplace_back( std::make_shared<CN_ANCHOR>( aPos, this ) );
192  }
CN_ANCHORS m_anchors

References m_anchors.

Referenced by CN_LIST::Add().

◆ AnchorCount()

int CN_ITEM::AnchorCount ( ) const
virtual

Reimplemented in CN_ZONE_LAYER.

Definition at line 31 of file connectivity_items.cpp.

32 {
33  if( !m_valid )
34  return 0;
35 
36  switch( m_parent->Type() )
37  {
38  case PCB_PAD_T:
39  return 5; // center, north, south, east and west
40  case PCB_TRACE_T:
41  case PCB_ARC_T:
42  return 2; // start and end
43  default:
44  return 1;
45  }
46 }
BOARD_CONNECTED_ITEM * m_parent
bool m_valid
used to identify garbage items (we use lazy removal)
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
class PAD, a pad in a footprint
Definition: typeinfo.h:89
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:162

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

194 { return m_anchors; }
CN_ANCHORS m_anchors

References m_anchors.

Referenced by CONNECTIVITY_DATA::TestTrackEndpointDangling().

◆ BBox()

const BOX2I& CN_ITEM::BBox ( )
inline

Definition at line 234 of file connectivity_items.h.

235  {
236  if( m_dirty && m_valid )
237  {
239  m_bbox = BOX2I( box.GetPosition(), box.GetSize() );
240  }
241  return m_bbox;
242  }
BOX2< VECTOR2I > BOX2I
Definition: box2.h:522
BOARD_CONNECTED_ITEM * m_parent
bool m_valid
used to identify garbage items (we use lazy removal)
const wxPoint GetPosition() const
Definition: eda_rect.h:107
bool m_dirty
used to identify recently added item not yet scanned into the connectivity search
BOX2I m_bbox
bounding box for the item
Handle the component boundary box.
Definition: eda_rect.h:42
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:89
const wxSize GetSize() const
Definition: eda_rect.h:96

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

255 { return m_canChangeNet; }
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 250 of file connectivity_items.h.

250 { m_connected.clear(); }
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 257 of file connectivity_items.h.

258  {
259  std::lock_guard<std::mutex> lock( m_listLock );
260 
261  auto i = std::lower_bound( m_connected.begin(), m_connected.end(), b );
262 
263  if( i != m_connected.end() && *i == b )
264  return;
265 
266  m_connected.insert( i, b );
267  }
std::mutex m_listLock
mutex protecting this item's connected_items set to
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()

◆ Dirty()

bool CN_ITEM::Dirty ( ) const
inline

Definition at line 200 of file connectivity_items.h.

200 { return m_dirty; }
bool m_dirty
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 153 of file connectivity_items.cpp.

154 {
155  wxLogDebug(" valid: %d, connected: \n", !!Valid());
156 
157  for( auto i : m_connected )
158  {
159  TRACK* t = static_cast<TRACK*>( i->Parent() );
160  wxLogDebug( " - %p %d\n", t, t->Type() );
161  }
162 }
CONNECTED_ITEMS m_connected
list of items physically connected (touching)
Definition: track.h:83
bool Valid() const
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:162

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

◆ GetAnchor()

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

Reimplemented in CN_ZONE_LAYER.

Definition at line 49 of file connectivity_items.cpp.

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

References PAD::GetEffectivePolygon(), PAD::GetOrientation(), PAD::GetPosition(), PAD::GetShape(), 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(), 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

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

Definition at line 229 of file connectivity_items.h.

230  {
231  return Layers().Start();
232  }
int Start() const
Definition: pns_layerset.h:82
const LAYER_RANGE & Layers() const
Return the contiguous set of layers spanned by the item.

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

Referenced by CN_VISITOR::checkZoneZoneConnection().

◆ Layers()

const LAYER_RANGE& CN_ITEM::Layers ( ) const
inline

Return the contiguous set of layers spanned by the item.

Definition at line 221 of file connectivity_items.h.

222  {
223  return m_layers;
224  }
LAYER_RANGE m_layers
layer range over which the item exists

References m_layers.

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

◆ Net()

◆ Parent()

◆ RemoveInvalidRefs()

void CN_ITEM::RemoveInvalidRefs ( )

Definition at line 189 of file connectivity_items.cpp.

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

References m_connected.

◆ SetDirty()

void CN_ITEM::SetDirty ( bool  aDirty)
inline

Definition at line 199 of file connectivity_items.h.

199 { m_dirty = aDirty; }
bool m_dirty
used to identify recently added item not yet scanned into the connectivity search

References m_dirty.

◆ SetLayer()

void CN_ITEM::SetLayer ( int  aLayer)
inline

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

Definition at line 213 of file connectivity_items.h.

214  {
215  m_layers = LAYER_RANGE( aLayer, aLayer );
216  }
LAYER_RANGE m_layers
layer range over which the item exists
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:31

References m_layers.

Referenced by CN_LIST::Add().

◆ SetLayers()

void CN_ITEM::SetLayers ( const LAYER_RANGE aLayers)
inline

Set the layers spanned by the item to aLayers.

Definition at line 205 of file connectivity_items.h.

206  {
207  m_layers = aLayers;
208  }
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 196 of file connectivity_items.h.

196 { m_valid = aValid; }
bool m_valid
used to identify garbage items (we use lazy removal)

References m_valid.

◆ SetVisited()

void CN_ITEM::SetVisited ( bool  aVisited)
inline

Definition at line 252 of file connectivity_items.h.

252 { m_visited = aVisited; }
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 253 of file connectivity_items.h.

253 { return m_visited; }
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 289 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 283 of file connectivity_items.h.

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

◆ m_canChangeNet

bool CN_ITEM::m_canChangeNet
private

can the net propagator modify the netcode?

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

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

◆ m_dirty

bool CN_ITEM::m_dirty
protected

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

Definition at line 280 of file connectivity_items.h.

Referenced by BBox(), CN_ZONE_LAYER::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 282 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

Definition at line 296 of file connectivity_items.h.

Referenced by Connect().

◆ m_parent

BOARD_CONNECTED_ITEM* CN_ITEM::m_parent
private

Definition at line 286 of file connectivity_items.h.

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

◆ m_valid

bool CN_ITEM::m_valid
private

used to identify garbage items (we use lazy removal)

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

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


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