KiCad PCB EDA Suite
CN_VISITOR Class Reference

Struct CN_VISTOR. More...

#include <connectivity_algo.h>

Public Member Functions

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

Protected Member Functions

void checkZoneItemConnection (CN_ZONE *aZone, CN_ITEM *aItem)
 
void checkZoneZoneConnection (CN_ZONE *aZoneA, CN_ZONE *aZoneB)
 

Protected Attributes

CN_ITEMm_item
 

the item we are looking for connections to

More...
 

Detailed Description

Struct CN_VISTOR.

Definition at line 290 of file connectivity_algo.h.

Constructor & Destructor Documentation

◆ CN_VISITOR()

CN_VISITOR::CN_VISITOR ( CN_ITEM aItem)
inline

Definition at line 294 of file connectivity_algo.h.

294  :
295  m_item( aItem )
296  {}
CN_ITEM * m_item
the item we are looking for connections to

Member Function Documentation

◆ checkZoneItemConnection()

void CN_VISITOR::checkZoneItemConnection ( CN_ZONE aZone,
CN_ITEM aItem 
)
protected

Definition at line 618 of file connectivity_algo.cpp.

619 {
620  if( aZone->Net() != aItem->Net() && !aItem->CanChangeNet() )
621  return;
622 
623  if( !aZone->BBox().Intersects( aItem->BBox() ) )
624  return;
625 
626  auto zoneItem = static_cast<CN_ZONE*> ( aZone );
627 
628  for( int i = 0; i < aItem->AnchorCount(); ++i )
629  {
630  if( zoneItem->ContainsPoint( aItem->GetAnchor( i ) ) )
631  {
632  zoneItem->Connect( aItem );
633  aItem->Connect( zoneItem );
634  return;
635  }
636  }
637 }
const BOX2I & BBox()
int Net() const
virtual int AnchorCount() const
bool Intersects(const BOX2< Vec > &aRect) const
Function Intersects.
Definition: box2.h:235
virtual const VECTOR2I GetAnchor(int n) const
bool CanChangeNet() const
void Connect(CN_ITEM *b)
const BOX2I & BBox()

References CN_ITEM::AnchorCount(), CN_ITEM::BBox(), CN_ZONE::BBox(), CN_ITEM::CanChangeNet(), CN_ITEM::Connect(), CN_ITEM::GetAnchor(), BOX2< Vec >::Intersects(), and CN_ITEM::Net().

Referenced by operator()().

◆ checkZoneZoneConnection()

void CN_VISITOR::checkZoneZoneConnection ( CN_ZONE aZoneA,
CN_ZONE aZoneB 
)
protected

Definition at line 639 of file connectivity_algo.cpp.

640 {
641  const auto refParent = static_cast<const ZONE_CONTAINER*>( aZoneA->Parent() );
642  const auto testedParent = static_cast<const ZONE_CONTAINER*>( aZoneB->Parent() );
643 
644  if( testedParent->Type () != PCB_ZONE_AREA_T )
645  return;
646 
647  if( aZoneB == aZoneA || refParent == testedParent )
648  return;
649 
650  if( aZoneA->Layer() != aZoneB->Layer() )
651  return;
652 
653  if( aZoneB->Net() != aZoneA->Net() )
654  return; // we only test zones belonging to the same net
655 
656  PCB_LAYER_ID layer = static_cast<PCB_LAYER_ID>( aZoneA->Layer() );
657 
658  const auto& outline = refParent->GetFilledPolysList( layer ).COutline( aZoneA->SubpolyIndex() );
659 
660  for( int i = 0; i < outline.PointCount(); i++ )
661  {
662  if( aZoneB->ContainsPoint( outline.CPoint( i ) ) )
663  {
664  aZoneA->Connect( aZoneB );
665  aZoneB->Connect( aZoneA );
666  return;
667  }
668  }
669 
670  const auto& outline2 =
671  testedParent->GetFilledPolysList( layer ).COutline( aZoneB->SubpolyIndex() );
672 
673  for( int i = 0; i < outline2.PointCount(); i++ )
674  {
675  if( aZoneA->ContainsPoint( outline2.CPoint( i ) ) )
676  {
677  aZoneA->Connect( aZoneB );
678  aZoneB->Connect( aZoneA );
679  return;
680  }
681  }
682 }
int SubpolyIndex() const
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
BOARD_CONNECTED_ITEM * Parent() const
int Net() const
PCB_LAYER_ID
A quick note on layer IDs:
bool ContainsPoint(const VECTOR2I p) const
virtual int Layer() const
Function Layer()
void Connect(CN_ITEM *b)

References CN_ITEM::Connect(), CN_ZONE::ContainsPoint(), CN_ITEM::Layer(), CN_ITEM::Net(), CN_ITEM::Parent(), PCB_ZONE_AREA_T, and CN_ZONE::SubpolyIndex().

Referenced by operator()().

◆ operator()()

bool CN_VISITOR::operator() ( CN_ITEM aCandidate)

Definition at line 685 of file connectivity_algo.cpp.

686 {
687  const auto parentA = aCandidate->Parent();
688  const auto parentB = m_item->Parent();
689 
690  if( !aCandidate->Valid() || !m_item->Valid() )
691  return true;
692 
693  if( parentA == parentB )
694  return true;
695 
696  if( !( parentA->GetLayerSet() & parentB->GetLayerSet() ).any() )
697  return true;
698 
699  // If both m_item and aCandidate are marked dirty, they will both be searched
700  // Since we are reciprocal in our connection, we arbitrarily pick one of the connections
701  // to conduct the expensive search
702  if( aCandidate->Dirty() && aCandidate < m_item )
703  return true;
704 
705  // We should handle zone-zone connection separately
706  if ( parentA->Type() == PCB_ZONE_AREA_T && parentB->Type() == PCB_ZONE_AREA_T )
707  {
708  checkZoneZoneConnection( static_cast<CN_ZONE*>( m_item ),
709  static_cast<CN_ZONE*>( aCandidate ) );
710  return true;
711  }
712 
713  if( parentA->Type() == PCB_ZONE_AREA_T )
714  {
715  checkZoneItemConnection( static_cast<CN_ZONE*>( aCandidate ), m_item );
716  return true;
717  }
718 
719  if( parentB->Type() == PCB_ZONE_AREA_T )
720  {
721  checkZoneItemConnection( static_cast<CN_ZONE*>( m_item ), aCandidate );
722  return true;
723  }
724 
725  // Items do not necessarily have reciprocity as we only check for anchors
726  // therefore, we check HitTest both directions A->B & B->A
727  for( int i = 0; i < aCandidate->AnchorCount(); ++i )
728  {
729  if( parentB->HitTest( wxPoint( aCandidate->GetAnchor( i ) ) ) )
730  {
731  m_item->Connect( aCandidate );
732  aCandidate->Connect( m_item );
733  return true;
734  }
735  }
736 
737  for( int i = 0; i < m_item->AnchorCount(); ++i )
738  {
739  if( parentA->HitTest( wxPoint( m_item->GetAnchor( i ) ) ) )
740  {
741  m_item->Connect( aCandidate );
742  aCandidate->Connect( m_item );
743  return true;
744  }
745  }
746 
747  return true;
748 };
void checkZoneItemConnection(CN_ZONE *aZone, CN_ITEM *aItem)
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
bool Dirty() const
BOARD_CONNECTED_ITEM * Parent() const
virtual int AnchorCount() const
virtual const VECTOR2I GetAnchor(int n) const
void checkZoneZoneConnection(CN_ZONE *aZoneA, CN_ZONE *aZoneB)
void Connect(CN_ITEM *b)
CN_ITEM * m_item
the item we are looking for connections to
bool Valid() const

References CN_ITEM::AnchorCount(), checkZoneItemConnection(), checkZoneZoneConnection(), CN_ITEM::Connect(), CN_ITEM::Dirty(), CN_ITEM::GetAnchor(), m_item, CN_ITEM::Parent(), PCB_ZONE_AREA_T, 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 307 of file connectivity_algo.h.

Referenced by operator()().


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