KiCad PCB EDA Suite
CN_ANCHOR Class Reference

#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
 
const unsigned int Dist (const CN_ANCHOR &aSecond)
 
int GetTag () const
 Returns tag, common identifier for connected nodes. More...
 
void SetTag (int aTag)
 Sets tag, common identifier for connected nodes. More...
 
void SetNoLine (bool aEnable)
 Decides whether this node can be a ratsnest line target. More...
 
const bool & GetNoLine () const
 Returns true if this node can be a target for ratsnest lines. More...
 
void SetCluster (std::shared_ptr< CN_CLUSTER > aCluster)
 
const std::shared_ptr< CN_CLUSTER > & GetCluster () const
 
bool IsDangling () const
 has meaning only for tracks and vias. More...
 
int ConnectedItemsCount () const
 has meaning only for tracks and vias. More...
 

Static Public Attributes

static const int TAG_UNCONNECTED = -1
 

Private Attributes

VECTOR2I m_pos
 Position of the anchor. More...
 
CN_ITEMm_item = nullptr
 Item 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

Definition at line 54 of file connectivity_items.h.

Constructor & Destructor Documentation

◆ CN_ANCHOR() [1/2]

CN_ANCHOR::CN_ANCHOR ( )
inline

Definition at line 57 of file connectivity_items.h.

58  {
59  m_item = nullptr;
60  }
CN_ITEM * m_item
Item owning the anchor.

References m_item.

◆ CN_ANCHOR() [2/2]

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

Definition at line 62 of file connectivity_items.h.

63  {
64  m_pos = aPos;
65  m_item = aItem;
66  assert( m_item );
67  }
VECTOR2I m_pos
Position of the anchor.
CN_ITEM * m_item
Item owning the anchor.

References m_item, and m_pos.

Member Function Documentation

◆ ConnectedItemsCount()

int CN_ANCHOR::ConnectedItemsCount ( ) const

has meaning only for tracks and vias.

Returns
the count of items connected to this anchor

Definition at line 375 of file connectivity_items.cpp.

376 {
377  if( !m_cluster )
378  return 0;
379 
380  int connected_count = 0;
381 
382  for( auto item : m_item->ConnectedItems() )
383  {
384  if( item->Parent()->Type() == PCB_ZONE_AREA_T )
385  {
386  ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item->Parent() );
387 
388  if( zone->HitTestFilledArea( static_cast<PCB_LAYER_ID>( item->Layer() ),
389  wxPoint( Pos().x, Pos().y ) ) )
390  connected_count++;
391  }
392  else if( item->Parent()->HitTest( wxPoint( Pos().x, Pos().y ) ) )
393  connected_count++;
394  }
395 
396  return connected_count;
397 }
const CONNECTED_ITEMS & ConnectedItems() const
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
bool HitTestFilledArea(PCB_LAYER_ID aLayer, const wxPoint &aRefPos) const
Function HitTestFilledArea tests if the given wxPoint is within the bounds of a filled area of this z...
Definition: class_zone.cpp:559
std::shared_ptr< CN_CLUSTER > m_cluster
Cluster to which the anchor belongs.
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
CN_ITEM * m_item
Item owning the anchor.
const VECTOR2I & Pos() const

References CN_ITEM::ConnectedItems(), ZONE_CONTAINER::HitTestFilledArea(), m_cluster, m_item, PCB_ZONE_AREA_T, Pos(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ Dist()

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

Definition at line 84 of file connectivity_items.h.

85  {
86  return ( m_pos - aSecond.Pos() ).EuclideanNorm();
87  }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:128
VECTOR2I m_pos
Position of the anchor.
const VECTOR2I & Pos() const

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

◆ GetCluster()

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

Definition at line 118 of file connectivity_items.h.

119  {
120  return m_cluster;
121  }
std::shared_ptr< CN_CLUSTER > m_cluster
Cluster to which the anchor belongs.

References m_cluster.

◆ GetNoLine()

const bool& CN_ANCHOR::GetNoLine ( ) const
inline

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

Definition at line 108 of file connectivity_items.h.

109  {
110  return m_noline;
111  }
bool m_noline
Whether it the node can be a target for ratsnest lines.

References m_noline.

◆ GetTag()

int CN_ANCHOR::GetTag ( ) const
inline

Returns tag, common identifier for connected nodes.

Definition at line 90 of file connectivity_items.h.

91  {
92  return m_tag;
93  }
int m_tag
Tag for quick connection resolution.

References m_tag.

◆ IsDangling()

bool CN_ANCHOR::IsDangling ( ) const

has meaning only for tracks and vias.

Returns
true if this anchor is dangling The anchor point is dangling if the parent is a track and this anchor point is not connected to another item ( track, vas 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

Definition at line 337 of file connectivity_items.cpp.

338 {
339  if( !m_cluster )
340  return true;
341 
342  // the minimal number of items connected to item_ref
343  // at this anchor point to decide the anchor is *not* dangling
344  size_t minimal_count = 1;
345  size_t connected_count = m_item->ConnectedItems().size();
346 
347  // a via can be removed if connected to only one other item.
348  if( Parent()->Type() == PCB_VIA_T )
349  return connected_count < 2;
350 
351  if( m_item->AnchorCount() == 1 )
352  return connected_count < minimal_count;
353 
354  // Items with multiple anchors have usually items connected to each anchor.
355  // We want only the item count of this anchor point
356  connected_count = 0;
357  for( auto item : m_item->ConnectedItems() )
358  {
359  if( item->Parent()->Type() == PCB_ZONE_AREA_T )
360  {
361  ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item->Parent() );
362 
363  if( zone->HitTestFilledArea( static_cast<PCB_LAYER_ID>( item->Layer() ),
364  static_cast<wxPoint>( Pos() ) ) )
365  connected_count++;
366  }
367  else if( item->Parent()->HitTest( (wxPoint) Pos() ) )
368  connected_count++;
369  }
370 
371  return connected_count < minimal_count;
372 }
const CONNECTED_ITEMS & ConnectedItems() const
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
bool HitTestFilledArea(PCB_LAYER_ID aLayer, const wxPoint &aRefPos) const
Function HitTestFilledArea tests if the given wxPoint is within the bounds of a filled area of this z...
Definition: class_zone.cpp:559
std::shared_ptr< CN_CLUSTER > m_cluster
Cluster to which the anchor belongs.
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
virtual int AnchorCount() const
CN_ITEM * m_item
Item owning the anchor.
BOARD_CONNECTED_ITEM * Parent() const
const VECTOR2I & Pos() const
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97

References CN_ITEM::AnchorCount(), CN_ITEM::ConnectedItems(), ZONE_CONTAINER::HitTestFilledArea(), m_cluster, m_item, Parent(), PCB_VIA_T, PCB_ZONE_AREA_T, and Pos().

◆ Item()

CN_ITEM* CN_ANCHOR::Item ( ) const
inline

Definition at line 72 of file connectivity_items.h.

73  {
74  return m_item;
75  }
CN_ITEM * m_item
Item owning the anchor.

References m_item.

◆ Parent()

BOARD_CONNECTED_ITEM * CN_ANCHOR::Parent ( ) const

Definition at line 321 of file connectivity_items.cpp.

322 {
323  assert( m_item->Valid() );
324  return m_item->Parent();
325 }
BOARD_CONNECTED_ITEM * Parent() const
CN_ITEM * m_item
Item 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 79 of file connectivity_items.h.

80  {
81  return m_pos;
82  }
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 113 of file connectivity_items.h.

114  {
115  m_cluster = aCluster;
116  }
std::shared_ptr< CN_CLUSTER > m_cluster
Cluster to which the anchor belongs.

References m_cluster.

◆ SetNoLine()

void CN_ANCHOR::SetNoLine ( bool  aEnable)
inline

Decides whether this node can be a ratsnest line target.

Definition at line 102 of file connectivity_items.h.

103  {
104  m_noline = aEnable;
105  }
bool m_noline
Whether it the node can be a target for ratsnest lines.

References m_noline.

Referenced by CONNECTIVITY_DATA::ClearDynamicRatsnest().

◆ SetTag()

void CN_ANCHOR::SetTag ( int  aTag)
inline

Sets tag, common identifier for connected nodes.

Definition at line 96 of file connectivity_items.h.

97  {
98  m_tag = aTag;
99  }
int m_tag
Tag for quick connection resolution.

References m_tag.

◆ Valid()

bool CN_ANCHOR::Valid ( ) const

Definition at line 328 of file connectivity_items.cpp.

329 {
330  if( !m_item )
331  return false;
332 
333  return m_item->Valid();
334 }
CN_ITEM * m_item
Item 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 156 of file connectivity_items.h.

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

◆ m_item

CN_ITEM* CN_ANCHOR::m_item = nullptr
private

Item owning the anchor.

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

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

◆ m_tag

int CN_ANCHOR::m_tag = -1
private

Tag for quick connection resolution.

Definition at line 150 of file connectivity_items.h.

Referenced by GetTag(), and SetTag().

◆ TAG_UNCONNECTED

const int CN_ANCHOR::TAG_UNCONNECTED = -1
static

Definition at line 140 of file connectivity_items.h.


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