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

392 {
393  if( !m_cluster )
394  return 0;
395 
396  int connected_count = 0;
397 
398  for( CN_ITEM* item : m_item->ConnectedItems() )
399  {
400  if( item->Parent()->Type() == PCB_ZONE_T )
401  {
402  ZONE* zone = static_cast<ZONE*>( item->Parent() );
403 
404  if( zone->HitTestFilledArea( static_cast<PCB_LAYER_ID>( item->Layer() ),
405  (wxPoint) Pos() ) )
406  connected_count++;
407  }
408  else if( item->Parent()->HitTest( (wxPoint) Pos() ) )
409  connected_count++;
410  }
411 
412  return connected_count;
413 }
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:506
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 88 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 122 of file connectivity_items.h.

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

References m_cluster.

◆ GetNoLine()

const bool& CN_ANCHOR::GetNoLine ( ) const
inline

Definition at line 112 of file connectivity_items.h.

113  {
114  return m_noline;
115  }
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 94 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 348 of file connectivity_items.cpp.

349 {
350  int accuracy = 0;
351 
352  if( !m_cluster )
353  return true;
354 
355  // the minimal number of items connected to item_ref
356  // at this anchor point to decide the anchor is *not* dangling
357  size_t minimal_count = 1;
358  size_t connected_count = m_item->ConnectedItems().size();
359 
360  // a via can be removed if connected to only one other item.
361  if( Parent()->Type() == PCB_VIA_T )
362  return connected_count < 2;
363 
364  if( m_item->AnchorCount() == 1 )
365  return connected_count < minimal_count;
366 
367  if( Parent()->Type() == PCB_TRACE_T || Parent()->Type() == PCB_ARC_T )
368  accuracy = ( static_cast<const PCB_TRACK*>( Parent() )->GetWidth() + 1 ) / 2;
369 
370  // Items with multiple anchors have usually items connected to each anchor.
371  // We want only the item count of this anchor point
372  connected_count = 0;
373  for( auto 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( static_cast<PCB_LAYER_ID>( item->Layer() ),
380  wxPoint( Pos() ), accuracy ) )
381  connected_count++;
382  }
383  else if( item->Parent()->HitTest( wxPoint( Pos() ), accuracy ) )
384  connected_count++;
385  }
386 
387  return connected_count < minimal_count;
388 }
const CONNECTED_ITEMS & ConnectedItems() const
std::shared_ptr< CN_CLUSTER > m_cluster
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:506
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: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 PCB_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:113

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

72  {
73  return m_item;
74  }
CN_ITEM * m_item
Tag for quick connection resolution.

References m_item.

◆ Move()

void CN_ANCHOR::Move ( const VECTOR2I aPos)
inline

Definition at line 83 of file connectivity_items.h.

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

References m_pos.

◆ Parent()

BOARD_CONNECTED_ITEM * CN_ANCHOR::Parent ( ) const

Definition at line 332 of file connectivity_items.cpp.

333 {
334  assert( m_item->Valid() );
335  return m_item->Parent();
336 }
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 78 of file connectivity_items.h.

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

118  {
119  m_cluster = aCluster;
120  }
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 106 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 100 of file connectivity_items.h.

References m_tag.

◆ Valid()

bool CN_ANCHOR::Valid ( ) const

Definition at line 339 of file connectivity_items.cpp.

340 {
341  if( !m_item )
342  return false;
343 
344  return m_item->Valid();
345 }
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 158 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 149 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 155 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 146 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 152 of file connectivity_items.h.

Referenced by GetTag(), and SetTag().

◆ TAG_UNCONNECTED

const int CN_ANCHOR::TAG_UNCONNECTED = -1
static

Definition at line 142 of file connectivity_items.h.


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