KiCad PCB EDA Suite
CN_VISITOR Class Reference

#include <connectivity_algo.h>

Public Member Functions

 CN_VISITOR (CN_ITEM *aItem)
 
bool operator() (CN_ITEM *aCandidate)
 

Protected Member Functions

void checkZoneItemConnection (CN_ZONE_LAYER *aZoneLayer, CN_ITEM *aItem)
 
void checkZoneZoneConnection (CN_ZONE_LAYER *aZoneLayerA, CN_ZONE_LAYER *aZoneLayerB)
 

Protected Attributes

CN_ITEMm_item
 The item we are looking for connections to. More...
 

Detailed Description

Definition at line 295 of file connectivity_algo.h.

Constructor & Destructor Documentation

◆ CN_VISITOR()

CN_VISITOR::CN_VISITOR ( CN_ITEM aItem)
inline

Definition at line 298 of file connectivity_algo.h.

298  :
299  m_item( aItem )
300  {}
CN_ITEM * m_item
The item we are looking for connections to.

Member Function Documentation

◆ checkZoneItemConnection()

void CN_VISITOR::checkZoneItemConnection ( CN_ZONE_LAYER aZoneLayer,
CN_ITEM aItem 
)
protected

Definition at line 648 of file connectivity_algo.cpp.

649 {
650  if( aZoneLayer->Net() != aItem->Net() && !aItem->CanChangeNet() )
651  return;
652 
653  if( !aZoneLayer->BBox().Intersects( aItem->BBox() ) )
654  return;
655 
656  int accuracy = 0;
657 
658  if( aItem->Parent()->Type() == PCB_VIA_T
659  || aItem->Parent()->Type() == PCB_TRACE_T
660  || aItem->Parent()->Type() == PCB_ARC_T )
661  {
662  accuracy = ( static_cast<PCB_TRACK*>( aItem->Parent() )->GetWidth() + 1 ) / 2;
663  }
664 
665  for( int i = 0; i < aItem->AnchorCount(); ++i )
666  {
667  if( aZoneLayer->ContainsPoint( aItem->GetAnchor( i ), accuracy ) )
668  {
669  aZoneLayer->Connect( aItem );
670  aItem->Connect( aZoneLayer );
671  return;
672  }
673  }
674 }
const BOX2I & BBox()
bool ContainsPoint(const VECTOR2I &p, int aAccuracy=0) const
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
BOARD_CONNECTED_ITEM * Parent() const
int Net() const
allow parallel connection threads
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
virtual int AnchorCount() const
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:217
virtual const VECTOR2I GetAnchor(int n) const
bool CanChangeNet() const
void Connect(CN_ITEM *b)
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
const BOX2I & BBox()
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References CN_ITEM::AnchorCount(), CN_ITEM::BBox(), CN_ZONE_LAYER::BBox(), CN_ITEM::CanChangeNet(), CN_ITEM::Connect(), CN_ZONE_LAYER::ContainsPoint(), CN_ITEM::GetAnchor(), BOX2< Vec >::Intersects(), CN_ITEM::Net(), CN_ITEM::Parent(), PCB_ARC_T, PCB_TRACE_T, PCB_VIA_T, and EDA_ITEM::Type().

Referenced by operator()().

◆ checkZoneZoneConnection()

void CN_VISITOR::checkZoneZoneConnection ( CN_ZONE_LAYER aZoneLayerA,
CN_ZONE_LAYER aZoneLayerB 
)
protected

Definition at line 676 of file connectivity_algo.cpp.

677 {
678  const ZONE* zoneA = static_cast<const ZONE*>( aZoneLayerA->Parent() );
679  const ZONE* zoneB = static_cast<const ZONE*>( aZoneLayerB->Parent() );
680 
681  if( aZoneLayerA->Layer() != aZoneLayerB->Layer() )
682  return;
683 
684  if( aZoneLayerB->Net() != aZoneLayerA->Net() )
685  return; // we only test zones belonging to the same net
686 
687  const BOX2I& boxA = aZoneLayerA->BBox();
688  const BOX2I& boxB = aZoneLayerB->BBox();
689 
690  int radiusA = 0;
691  int radiusB = 0;
692 
693  if( zoneA->GetFilledPolysUseThickness() )
694  radiusA = ( zoneA->GetMinThickness() + 1 ) / 2;
695 
696  if( zoneB->GetFilledPolysUseThickness() )
697  radiusB = ( zoneB->GetMinThickness() + 1 ) / 2;
698 
699  PCB_LAYER_ID layer = static_cast<PCB_LAYER_ID>( aZoneLayerA->Layer() );
700 
701  const SHAPE_LINE_CHAIN& outline =
702  zoneA->GetFilledPolysList( layer ).COutline( aZoneLayerA->SubpolyIndex() );
703 
704  for( int i = 0; i < outline.PointCount(); i++ )
705  {
706  if( !boxB.Contains( outline.CPoint( i ) ) )
707  continue;
708 
709  if( aZoneLayerB->ContainsPoint( outline.CPoint( i ), radiusA ) )
710  {
711  aZoneLayerA->Connect( aZoneLayerB );
712  aZoneLayerB->Connect( aZoneLayerA );
713  return;
714  }
715  }
716 
717  const SHAPE_LINE_CHAIN& outline2 =
718  zoneB->GetFilledPolysList( layer ).COutline( aZoneLayerB->SubpolyIndex() );
719 
720  for( int i = 0; i < outline2.PointCount(); i++ )
721  {
722  if( !boxA.Contains( outline2.CPoint( i ) ) )
723  continue;
724 
725  if( aZoneLayerA->ContainsPoint( outline2.CPoint( i ), radiusB ) )
726  {
727  aZoneLayerA->Connect( aZoneLayerB );
728  aZoneLayerB->Connect( aZoneLayerA );
729  return;
730  }
731  }
732 }
const BOX2I & BBox()
bool ContainsPoint(const VECTOR2I &p, int aAccuracy=0) const
const SHAPE_POLY_SET & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition: zone.h:635
BOARD_CONNECTED_ITEM * Parent() const
int PointCount() const
Return the number of points (vertices) in this line chain.
int Net() const
allow parallel connection threads
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
int GetMinThickness() const
Definition: zone.h:244
bool Contains(const Vec &aPoint) const
Definition: box2.h:134
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
int SubpolyIndex() const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
virtual int Layer() const
Return the item's layer, for single-layered items only.
void Connect(CN_ITEM *b)
bool GetFilledPolysUseThickness() const
Definition: zone.h:689

References CN_ZONE_LAYER::BBox(), CN_ITEM::Connect(), BOX2< Vec >::Contains(), CN_ZONE_LAYER::ContainsPoint(), SHAPE_POLY_SET::COutline(), SHAPE_LINE_CHAIN::CPoint(), ZONE::GetFilledPolysList(), ZONE::GetFilledPolysUseThickness(), ZONE::GetMinThickness(), CN_ITEM::Layer(), CN_ITEM::Net(), CN_ITEM::Parent(), SHAPE_LINE_CHAIN::PointCount(), and CN_ZONE_LAYER::SubpolyIndex().

Referenced by operator()().

◆ operator()()

bool CN_VISITOR::operator() ( CN_ITEM aCandidate)

Definition at line 735 of file connectivity_algo.cpp.

736 {
737  const BOARD_CONNECTED_ITEM* parentA = aCandidate->Parent();
738  const BOARD_CONNECTED_ITEM* parentB = m_item->Parent();
739 
740  if( !aCandidate->Valid() || !m_item->Valid() )
741  return true;
742 
743  if( parentA == parentB )
744  return true;
745 
746  if( !( parentA->GetLayerSet() & parentB->GetLayerSet() ).any() )
747  return true;
748 
749  // If both m_item and aCandidate are marked dirty, they will both be searched
750  // Since we are reciprocal in our connection, we arbitrarily pick one of the connections
751  // to conduct the expensive search
752  if( aCandidate->Dirty() && aCandidate < m_item )
753  return true;
754 
755  // We should handle zone-zone connection separately
756  if ( parentA->Type() == PCB_ZONE_T && parentB->Type() == PCB_ZONE_T )
757  {
758  checkZoneZoneConnection( static_cast<CN_ZONE_LAYER*>( m_item ),
759  static_cast<CN_ZONE_LAYER*>( aCandidate ) );
760  return true;
761  }
762 
763  if( parentA->Type() == PCB_ZONE_T )
764  {
765  checkZoneItemConnection( static_cast<CN_ZONE_LAYER*>( aCandidate ), m_item );
766  return true;
767  }
768 
769  if( parentB->Type() == PCB_ZONE_T )
770  {
771  checkZoneItemConnection( static_cast<CN_ZONE_LAYER*>( m_item ), aCandidate );
772  return true;
773  }
774 
775  int accuracyA = 0;
776  int accuracyB = 0;
777 
778  if( parentA->Type() == PCB_VIA_T
779  || parentA->Type() == PCB_TRACE_T
780  || parentA->Type() == PCB_ARC_T)
781  accuracyA = ( static_cast<const PCB_TRACK*>( parentA )->GetWidth() + 1 ) / 2;
782 
783  if( parentB->Type() == PCB_VIA_T
784  || parentB->Type() == PCB_TRACE_T
785  || parentB->Type() == PCB_ARC_T )
786  accuracyB = ( static_cast<const PCB_TRACK*>( parentB )->GetWidth() + 1 ) / 2;
787 
788  // Items do not necessarily have reciprocity as we only check for anchors
789  // therefore, we check HitTest both directions A->B & B->A
790  for( int i = 0; i < aCandidate->AnchorCount(); ++i )
791  {
792  if( parentB->HitTest( wxPoint( aCandidate->GetAnchor( i ) ), accuracyA ) )
793  {
794  m_item->Connect( aCandidate );
795  aCandidate->Connect( m_item );
796  return true;
797  }
798  }
799 
800  for( int i = 0; i < m_item->AnchorCount(); ++i )
801  {
802  if( parentA->HitTest( wxPoint( m_item->GetAnchor( i ) ), accuracyB ) )
803  {
804  m_item->Connect( aCandidate );
805  aCandidate->Connect( m_item );
806  return true;
807  }
808  }
809 
810  return true;
811 };
void checkZoneItemConnection(CN_ZONE_LAYER *aZoneLayer, CN_ITEM *aItem)
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
bool Dirty() const
BOARD_CONNECTED_ITEM * Parent() const
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
virtual int AnchorCount() const
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const
Test if aPosition is contained within or on the bounding box of an item.
Definition: eda_item.h:224
void checkZoneZoneConnection(CN_ZONE_LAYER *aZoneLayerA, CN_ZONE_LAYER *aZoneLayerB)
class ZONE, a copper pour area
Definition: typeinfo.h:105
virtual const VECTOR2I GetAnchor(int n) const
void Connect(CN_ITEM *b)
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
CN_ITEM * m_item
The item we are looking for connections to.
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:147
bool Valid() const
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References CN_ITEM::AnchorCount(), checkZoneItemConnection(), checkZoneZoneConnection(), CN_ITEM::Connect(), CN_ITEM::Dirty(), CN_ITEM::GetAnchor(), BOARD_ITEM::GetLayerSet(), EDA_ITEM::HitTest(), m_item, CN_ITEM::Parent(), PCB_ARC_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, EDA_ITEM::Type(), and CN_ITEM::Valid().

Member Data Documentation

◆ m_item

CN_ITEM* CN_VISITOR::m_item
protected

The item we are looking for connections to.

Definition at line 310 of file connectivity_algo.h.

Referenced by operator()().


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