KiCad PCB EDA Suite
CN_ANCHOR Class Reference

CN_ANCHOR represents a physical location that can be connected: a pad or a track/arc/via endpoint. More...

#include <connectivity_items.h>

Public Member Functions

 CN_ANCHOR ()
 
 CN_ANCHOR (const VECTOR2I &aPos, CN_ITEM *aItem)
 
bool Valid () const
 
CN_ITEMItem () const
 
BOARD_CONNECTED_ITEMParent () const
 
const VECTOR2IPos () const
 
void Move (const VECTOR2I &aPos)
 
const unsigned int Dist (const CN_ANCHOR &aSecond)
 Return tag, common identifier for connected nodes. More...
 
int GetTag () const
 Set tag, common identifier for connected nodes. More...
 
void SetTag (int aTag)
 Decide whether this node can be a ratsnest line target. More...
 
void SetNoLine (bool aEnable)
 Return true if this node can be a target for ratsnest lines. More...
 
const bool & GetNoLine () const
 
void SetCluster (std::shared_ptr< CN_CLUSTER > &aCluster)
 
const std::shared_ptr< CN_CLUSTER > & GetCluster () const
 
bool IsDangling () const
 The anchor point is dangling if the parent is a track and this anchor point is not connected to another item ( track, vias pad or zone) or if the parent is a via and this anchor point is connected to only one track and not to another item. More...
 
int ConnectedItemsCount () const
 

Static Public Attributes

static const int TAG_UNCONNECTED = -1
 

Private Attributes

VECTOR2I m_pos
 Position of the anchor. More...
 
CN_ITEMm_item = nullptr
 Pad or track/arc/via owning the anchor. More...
 
int m_tag = -1
 Tag for quick connection resolution. More...
 
bool m_noline = false
 Whether it the node can be a target for ratsnest lines. More...
 
std::shared_ptr< CN_CLUSTERm_cluster
 Cluster to which the anchor belongs. More...
 

Detailed Description

CN_ANCHOR represents a physical location that can be connected: a pad or a track/arc/via endpoint.

Definition at line 58 of file connectivity_items.h.

Constructor & Destructor Documentation

◆ CN_ANCHOR() [1/2]

CN_ANCHOR::CN_ANCHOR ( )
inline

Definition at line 61 of file connectivity_items.h.

62 {
63 m_item = nullptr;
64 }
CN_ITEM * m_item
Pad or track/arc/via owning the anchor.

References m_item.

◆ CN_ANCHOR() [2/2]

CN_ANCHOR::CN_ANCHOR ( const VECTOR2I aPos,
CN_ITEM aItem 
)
inline

Definition at line 66 of file connectivity_items.h.

67 {
68 m_pos = aPos;
69 m_item = aItem;
70 assert( m_item );
71 }
VECTOR2I m_pos
Position of the anchor.

References m_item, and m_pos.

Member Function Documentation

◆ ConnectedItemsCount()

int CN_ANCHOR::ConnectedItemsCount ( ) const
Returns
the count of tracks and vias connected to this anchor.

Definition at line 323 of file connectivity_items.cpp.

324{
325 if( !m_cluster )
326 return 0;
327
328 int connected_count = 0;
329
330 for( CN_ITEM* item : m_item->ConnectedItems() )
331 {
332 if( item->Parent()->Type() == PCB_ZONE_T )
333 {
334 ZONE* zone = static_cast<ZONE*>( item->Parent() );
335
336 if( zone->HitTestFilledArea( ToLAYER_ID( item->Layer() ), Pos() ) )
337 connected_count++;
338 }
339 else if( item->Parent()->HitTest( Pos() ) )
340 {
341 connected_count++;
342 }
343 }
344
345 return connected_count;
346}
std::shared_ptr< CN_CLUSTER > m_cluster
Cluster to which the anchor belongs.
const VECTOR2I & Pos() const
CN_ITEM represents a BOARD_CONNETED_ITEM in the connectivity system (ie: a pad, track/arc/via,...
const std::vector< CN_ITEM * > & ConnectedItems() const
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
bool HitTestFilledArea(PCB_LAYER_ID aLayer, const VECTOR2I &aRefPos, int aAccuracy=0) const
Test if the given VECTOR2I is within the bounds of a filled area of this zone.
Definition: zone.cpp:482
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:932
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition: typeinfo.h:112

References CN_ITEM::ConnectedItems(), ZONE::HitTestFilledArea(), m_cluster, m_item, PCB_ZONE_T, Pos(), and ToLAYER_ID().

◆ Dist()

const unsigned int CN_ANCHOR::Dist ( const CN_ANCHOR aSecond)
inline

Return tag, common identifier for connected nodes.

Definition at line 92 of file connectivity_items.h.

References m_pos, and Pos().

◆ GetCluster()

const std::shared_ptr< CN_CLUSTER > & CN_ANCHOR::GetCluster ( ) const
inline

Definition at line 126 of file connectivity_items.h.

127 {
128 return m_cluster;
129 }

References m_cluster.

◆ GetNoLine()

const bool & CN_ANCHOR::GetNoLine ( ) const
inline

Definition at line 116 of file connectivity_items.h.

117 {
118 return m_noline;
119 }
bool m_noline
Whether it the node can be a target for ratsnest lines.

References m_noline.

◆ GetTag()

int CN_ANCHOR::GetTag ( ) const
inline

Set tag, common identifier for connected nodes.

Definition at line 98 of file connectivity_items.h.

References m_tag.

◆ IsDangling()

bool CN_ANCHOR::IsDangling ( ) const

The anchor point is dangling if the parent is a track and this anchor point is not connected to another item ( track, vias pad or zone) or if the parent is a via and this anchor point is connected to only one track and not to another item.

Returns
true if this anchor is dangling.

Definition at line 278 of file connectivity_items.cpp.

279{
280 int accuracy = 0;
281
282 if( !m_cluster )
283 return true;
284
285 // the minimal number of items connected to item_ref
286 // at this anchor point to decide the anchor is *not* dangling
287 size_t minimal_count = 1;
288 size_t connected_count = m_item->ConnectedItems().size();
289
290 // a via can be removed if connected to only one other item.
291 if( Parent()->Type() == PCB_VIA_T )
292 return connected_count < 2;
293
294 if( m_item->AnchorCount() == 1 )
295 return connected_count < minimal_count;
296
297 if( Parent()->Type() == PCB_TRACE_T || Parent()->Type() == PCB_ARC_T )
298 accuracy = KiROUND( static_cast<const PCB_TRACK*>( Parent() )->GetWidth() / 2 );
299
300 // Items with multiple anchors have usually items connected to each anchor.
301 // We want only the item count of this anchor point
302 connected_count = 0;
303
304 for( CN_ITEM* item : m_item->ConnectedItems() )
305 {
306 if( item->Parent()->Type() == PCB_ZONE_T )
307 {
308 ZONE* zone = static_cast<ZONE*>( item->Parent() );
309
310 if( zone->HitTestFilledArea( ToLAYER_ID( item->Layer() ), Pos(), accuracy ) )
311 connected_count++;
312 }
313 else if( item->Parent()->HitTest( Pos(), accuracy ) )
314 {
315 connected_count++;
316 }
317 }
318
319 return connected_count < minimal_count;
320}
BOARD_CONNECTED_ITEM * Parent() const
virtual int AnchorCount() const
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:102
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:103
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:101
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85

References CN_ITEM::AnchorCount(), CN_ITEM::ConnectedItems(), ZONE::HitTestFilledArea(), KiROUND(), m_cluster, m_item, Parent(), PCB_ARC_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, Pos(), and ToLAYER_ID().

◆ Item()

CN_ITEM * CN_ANCHOR::Item ( ) const
inline

Definition at line 75 of file connectivity_items.h.

76 {
77 return m_item;
78 }

References m_item.

◆ Move()

void CN_ANCHOR::Move ( const VECTOR2I aPos)
inline

Definition at line 87 of file connectivity_items.h.

88 {
89 m_pos += aPos;
90 }

References m_pos.

◆ Parent()

BOARD_CONNECTED_ITEM * CN_ANCHOR::Parent ( ) const

Definition at line 262 of file connectivity_items.cpp.

263{
264 assert( m_item->Valid() );
265 return m_item->Parent();
266}
bool Valid() const
BOARD_CONNECTED_ITEM * Parent() const

References m_item, CN_ITEM::Parent(), and CN_ITEM::Valid().

Referenced by PCB_SELECTION_TOOL::grabUnconnected(), and IsDangling().

◆ Pos()

const VECTOR2I & CN_ANCHOR::Pos ( ) const
inline

Definition at line 82 of file connectivity_items.h.

83 {
84 return m_pos;
85 }

References m_pos.

Referenced by ConnectedItemsCount(), Dist(), and IsDangling().

◆ SetCluster()

void CN_ANCHOR::SetCluster ( std::shared_ptr< CN_CLUSTER > &  aCluster)
inline

Definition at line 121 of file connectivity_items.h.

122 {
123 m_cluster = aCluster;
124 }

References m_cluster.

◆ SetNoLine()

void CN_ANCHOR::SetNoLine ( bool  aEnable)
inline

Return true if this node can be a target for ratsnest lines.

Definition at line 110 of file connectivity_items.h.

References m_noline.

◆ SetTag()

void CN_ANCHOR::SetTag ( int  aTag)
inline

Decide whether this node can be a ratsnest line target.

Definition at line 104 of file connectivity_items.h.

References m_tag.

◆ Valid()

bool CN_ANCHOR::Valid ( ) const

Definition at line 269 of file connectivity_items.cpp.

270{
271 if( !m_item )
272 return false;
273
274 return m_item->Valid();
275}

References m_item, and CN_ITEM::Valid().

Member Data Documentation

◆ m_cluster

std::shared_ptr<CN_CLUSTER> CN_ANCHOR::m_cluster
private

Cluster to which the anchor belongs.

Definition at line 154 of file connectivity_items.h.

Referenced by ConnectedItemsCount(), GetCluster(), IsDangling(), and SetCluster().

◆ m_item

CN_ITEM* CN_ANCHOR::m_item = nullptr
private

Pad or track/arc/via owning the anchor.

Definition at line 150 of file connectivity_items.h.

Referenced by CN_ANCHOR(), ConnectedItemsCount(), IsDangling(), Item(), Parent(), and Valid().

◆ m_noline

bool CN_ANCHOR::m_noline = false
private

Whether it the node can be a target for ratsnest lines.

Definition at line 152 of file connectivity_items.h.

Referenced by GetNoLine(), and SetNoLine().

◆ m_pos

VECTOR2I CN_ANCHOR::m_pos
private

Position of the anchor.

Definition at line 149 of file connectivity_items.h.

Referenced by CN_ANCHOR(), Dist(), Move(), and Pos().

◆ m_tag

int CN_ANCHOR::m_tag = -1
private

Tag for quick connection resolution.

Definition at line 151 of file connectivity_items.h.

Referenced by GetTag(), and SetTag().

◆ TAG_UNCONNECTED

const int CN_ANCHOR::TAG_UNCONNECTED = -1
static

Definition at line 146 of file connectivity_items.h.


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