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
 
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, 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. 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
 Tag for quick connection resolution. More...
 
int m_tag = -1
 Whether it the node can be a target for ratsnest lines. More...
 
bool m_noline = false
 Cluster to which the anchor belongs. More...
 
std::shared_ptr< CN_CLUSTERm_cluster
 

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
Tag for quick connection resolution.

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
Tag for quick connection resolution.

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 388 of file connectivity_items.cpp.

389 {
390  if( !m_cluster )
391  return 0;
392 
393  int connected_count = 0;
394 
395  for( CN_ITEM* item : m_item->ConnectedItems() )
396  {
397  if( item->Parent()->Type() == PCB_ZONE_T )
398  {
399  ZONE* zone = static_cast<ZONE*>( item->Parent() );
400 
401  if( zone->HitTestFilledArea( static_cast<PCB_LAYER_ID>( item->Layer() ),
402  (wxPoint) Pos() ) )
403  connected_count++;
404  }
405  else if( item->Parent()->HitTest( (wxPoint) Pos() ) )
406  connected_count++;
407  }
408 
409  return connected_count;
410 }
const CONNECTED_ITEMS & ConnectedItems() const
std::shared_ptr< CN_CLUSTER > m_cluster
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:57
class ZONE, a copper pour area
Definition: typeinfo.h:105
CN_ITEM * m_item
Tag for quick connection resolution.
const VECTOR2I & Pos() const

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

◆ Dist()

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

Return tag, common identifier for connected nodes.

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

124  {
125  return m_cluster;
126  }
std::shared_ptr< CN_CLUSTER > m_cluster

References m_cluster.

◆ GetNoLine()

const bool& CN_ANCHOR::GetNoLine ( ) const
inline

Definition at line 113 of file connectivity_items.h.

114  {
115  return m_noline;
116  }
bool m_noline
Cluster to which the anchor belongs.

References m_noline.

◆ GetTag()

int CN_ANCHOR::GetTag ( ) const
inline

Set tag, common identifier for connected nodes.

Definition at line 95 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, 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.

Returns
true if this anchor is dangling.

Definition at line 345 of file connectivity_items.cpp.

346 {
347  int accuracy = 0;
348 
349  if( !m_cluster )
350  return true;
351 
352  // the minimal number of items connected to item_ref
353  // at this anchor point to decide the anchor is *not* dangling
354  size_t minimal_count = 1;
355  size_t connected_count = m_item->ConnectedItems().size();
356 
357  // a via can be removed if connected to only one other item.
358  if( Parent()->Type() == PCB_VIA_T )
359  return connected_count < 2;
360 
361  if( m_item->AnchorCount() == 1 )
362  return connected_count < minimal_count;
363 
364  if( Parent()->Type() == PCB_TRACE_T || Parent()->Type() == PCB_ARC_T )
365  accuracy = ( static_cast<const TRACK*>( Parent() )->GetWidth() + 1 )/ 2;
366 
367  // Items with multiple anchors have usually items connected to each anchor.
368  // We want only the item count of this anchor point
369  connected_count = 0;
370  for( auto item : m_item->ConnectedItems() )
371  {
372  if( item->Parent()->Type() == PCB_ZONE_T )
373  {
374  ZONE* zone = static_cast<ZONE*>( item->Parent() );
375 
376  if( zone->HitTestFilledArea( static_cast<PCB_LAYER_ID>( item->Layer() ),
377  wxPoint( Pos() ), accuracy ) )
378  connected_count++;
379  }
380  else if( item->Parent()->HitTest( wxPoint( Pos() ), accuracy ) )
381  connected_count++;
382  }
383 
384  return connected_count < minimal_count;
385 }
const CONNECTED_ITEMS & ConnectedItems() const
std::shared_ptr< CN_CLUSTER > m_cluster
class 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 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:57
class ZONE, a copper pour area
Definition: typeinfo.h:105
CN_ITEM * m_item
Tag for quick connection resolution.
BOARD_CONNECTED_ITEM * Parent() const
const VECTOR2I & Pos() const
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163

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

◆ 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
Tag for quick connection resolution.

References m_item.

◆ Move()

void CN_ANCHOR::Move ( const VECTOR2I aPos)
inline

Definition at line 84 of file connectivity_items.h.

85  {
86  m_pos += aPos;
87  }
VECTOR2I m_pos
< Position of the anchor.

References m_pos.

◆ Parent()

BOARD_CONNECTED_ITEM * CN_ANCHOR::Parent ( ) const

Definition at line 329 of file connectivity_items.cpp.

330 {
331  assert( m_item->Valid() );
332  return m_item->Parent();
333 }
BOARD_CONNECTED_ITEM * Parent() const
CN_ITEM * m_item
Tag for quick connection resolution.
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 118 of file connectivity_items.h.

119  {
120  m_cluster = aCluster;
121  }
std::shared_ptr< CN_CLUSTER > m_cluster

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

References m_tag.

◆ Valid()

bool CN_ANCHOR::Valid ( ) const

Definition at line 336 of file connectivity_items.cpp.

337 {
338  if( !m_item )
339  return false;
340 
341  return m_item->Valid();
342 }
CN_ITEM * m_item
Tag for quick connection resolution.
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

Definition at line 159 of file connectivity_items.h.

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

◆ m_item

CN_ITEM* CN_ANCHOR::m_item = nullptr
private

Tag for quick connection resolution.

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

Cluster to which the anchor belongs.

Definition at line 156 of file connectivity_items.h.

Referenced by GetNoLine(), and SetNoLine().

◆ m_pos

VECTOR2I CN_ANCHOR::m_pos
private

< Position of the anchor.

Item owning the anchor.

Definition at line 147 of file connectivity_items.h.

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

◆ m_tag

int CN_ANCHOR::m_tag = -1
private

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

Definition at line 153 of file connectivity_items.h.

Referenced by GetTag(), and SetTag().

◆ TAG_UNCONNECTED

const int CN_ANCHOR::TAG_UNCONNECTED = -1
static

Definition at line 143 of file connectivity_items.h.


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