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

Constructor & Destructor Documentation

◆ CN_ANCHOR() [1/2]

CN_ANCHOR::CN_ANCHOR ( )
inline

Definition at line 62 of file connectivity_items.h.

63  {
64  m_item = nullptr;
65  }
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 67 of file connectivity_items.h.

68  {
69  m_pos = aPos;
70  m_item = aItem;
71  assert( m_item );
72  }
VECTOR2I m_pos
Position of the anchor.
CN_ITEM * m_item
Pad or track/arc/via owning 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 392 of file connectivity_items.cpp.

393 {
394  if( !m_cluster )
395  return 0;
396 
397  int connected_count = 0;
398 
399  for( CN_ITEM* item : m_item->ConnectedItems() )
400  {
401  if( item->Parent()->Type() == PCB_ZONE_T )
402  {
403  ZONE* zone = static_cast<ZONE*>( item->Parent() );
404 
405  if( zone->HitTestFilledArea( ToLAYER_ID( item->Layer() ), (wxPoint) Pos() ) )
406  connected_count++;
407  }
408  else if( item->Parent()->HitTest( (wxPoint) Pos() ) )
409  {
410  connected_count++;
411  }
412  }
413 
414  return connected_count;
415 }
const CONNECTED_ITEMS & ConnectedItems() const
std::shared_ptr< CN_CLUSTER > m_cluster
Cluster to which the anchor belongs.
bool HitTestFilledArea(PCB_LAYER_ID aLayer, const wxPoint &aRefPos, int aAccuracy=0) const
Test if the given wxPoint is within the bounds of a filled area of this zone.
Definition: zone.cpp:504
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
class ZONE, a copper pour area
Definition: typeinfo.h:105
CN_ITEM * m_item
Pad or track/arc/via owning the anchor.
CN_ITEM represents a BOARD_CONNETED_ITEM in the connectivity system (ie: a pad, track/arc/via,...
const VECTOR2I & Pos() const
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:914

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

References EuclideanNorm(), m_pos, and Pos().

◆ GetCluster()

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

Definition at line 127 of file connectivity_items.h.

128  {
129  return m_cluster;
130  }
std::shared_ptr< CN_CLUSTER > m_cluster
Cluster to which the anchor belongs.

References m_cluster.

◆ GetNoLine()

const bool& CN_ANCHOR::GetNoLine ( ) const
inline

Definition at line 117 of file connectivity_items.h.

118  {
119  return m_noline;
120  }
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 99 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 347 of file connectivity_items.cpp.

348 {
349  int accuracy = 0;
350 
351  if( !m_cluster )
352  return true;
353 
354  // the minimal number of items connected to item_ref
355  // at this anchor point to decide the anchor is *not* dangling
356  size_t minimal_count = 1;
357  size_t connected_count = m_item->ConnectedItems().size();
358 
359  // a via can be removed if connected to only one other item.
360  if( Parent()->Type() == PCB_VIA_T )
361  return connected_count < 2;
362 
363  if( m_item->AnchorCount() == 1 )
364  return connected_count < minimal_count;
365 
366  if( Parent()->Type() == PCB_TRACE_T || Parent()->Type() == PCB_ARC_T )
367  accuracy = KiROUND( static_cast<const PCB_TRACK*>( Parent() )->GetWidth() / 2 );
368 
369  // Items with multiple anchors have usually items connected to each anchor.
370  // We want only the item count of this anchor point
371  connected_count = 0;
372 
373  for( CN_ITEM* item : m_item->ConnectedItems() )
374  {
375  if( item->Parent()->Type() == PCB_ZONE_T )
376  {
377  ZONE* zone = static_cast<ZONE*>( item->Parent() );
378 
379  if( zone->HitTestFilledArea( ToLAYER_ID( item->Layer() ), (wxPoint) Pos(), accuracy ) )
380  connected_count++;
381  }
382  else if( item->Parent()->HitTest( (wxPoint) Pos(), accuracy ) )
383  {
384  connected_count++;
385  }
386  }
387 
388  return connected_count < minimal_count;
389 }
const CONNECTED_ITEMS & ConnectedItems() const
std::shared_ptr< CN_CLUSTER > m_cluster
Cluster to which the anchor belongs.
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
bool HitTestFilledArea(PCB_LAYER_ID aLayer, const wxPoint &aRefPos, int aAccuracy=0) const
Test if the given wxPoint is within the bounds of a filled area of this zone.
Definition: zone.cpp:504
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
virtual int AnchorCount() const
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
class ZONE, a copper pour area
Definition: typeinfo.h:105
CN_ITEM * m_item
Pad or track/arc/via owning the anchor.
CN_ITEM represents a BOARD_CONNETED_ITEM in the connectivity system (ie: a pad, track/arc/via,...
BOARD_CONNECTED_ITEM * Parent() const
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:73
const VECTOR2I & Pos() const
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:914
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

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(), ToLAYER_ID(), and EDA_ITEM::Type().

◆ Item()

CN_ITEM* CN_ANCHOR::Item ( ) const
inline

Definition at line 76 of file connectivity_items.h.

77  {
78  return m_item;
79  }
CN_ITEM * m_item
Pad or track/arc/via owning the anchor.

References m_item.

◆ Move()

void CN_ANCHOR::Move ( const VECTOR2I aPos)
inline

Definition at line 88 of file connectivity_items.h.

89  {
90  m_pos += aPos;
91  }
VECTOR2I m_pos
Position of the anchor.

References m_pos.

◆ Parent()

BOARD_CONNECTED_ITEM * CN_ANCHOR::Parent ( ) const

Definition at line 331 of file connectivity_items.cpp.

332 {
333  assert( m_item->Valid() );
334  return m_item->Parent();
335 }
BOARD_CONNECTED_ITEM * Parent() const
CN_ITEM * m_item
Pad or track/arc/via owning the anchor.
bool Valid() const

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

Referenced by IsDangling().

◆ Pos()

const VECTOR2I& CN_ANCHOR::Pos ( ) const
inline

Definition at line 83 of file connectivity_items.h.

84  {
85  return m_pos;
86  }
VECTOR2I m_pos
Position of the anchor.

References m_pos.

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

◆ SetCluster()

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

Definition at line 122 of file connectivity_items.h.

123  {
124  m_cluster = aCluster;
125  }
std::shared_ptr< CN_CLUSTER > m_cluster
Cluster to which the anchor belongs.

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

References m_tag.

◆ Valid()

bool CN_ANCHOR::Valid ( ) const

Definition at line 338 of file connectivity_items.cpp.

339 {
340  if( !m_item )
341  return false;
342 
343  return m_item->Valid();
344 }
CN_ITEM * m_item
Pad or track/arc/via owning the anchor.
bool Valid() const

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 155 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 151 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 153 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 150 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 152 of file connectivity_items.h.

Referenced by GetTag(), and SetTag().

◆ TAG_UNCONNECTED

const int CN_ANCHOR::TAG_UNCONNECTED = -1
static

Definition at line 147 of file connectivity_items.h.


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