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 255 of file connectivity_algo.h.

Constructor & Destructor Documentation

CN_VISITOR::CN_VISITOR ( CN_ITEM aItem)
inline

Definition at line 259 of file connectivity_algo.h.

259  :
260  m_item( aItem )
261  {}
CN_ITEM * m_item
the item we are looking for connections to

Member Function Documentation

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

Definition at line 599 of file connectivity_algo.cpp.

References CN_ITEM::CanChangeNet(), CN_ITEM::Connect(), CN_ITEM::GetAnchor(), CN_ITEM::Net(), CN_ITEM::Parent(), PCB_TRACE_T, and EDA_ITEM::Type().

600 {
601  auto zoneItem = static_cast<CN_ZONE*> ( aZone );
602 
603  if( zoneItem->Net() != aItem->Net() && !aItem->CanChangeNet() )
604  return;
605 
606  if( zoneItem->ContainsPoint( aItem->GetAnchor( 0 ) ) ||
607  ( aItem->Parent()->Type() == PCB_TRACE_T &&
608  zoneItem->ContainsPoint( aItem->GetAnchor( 1 ) ) ) )
609  {
610  zoneItem->Connect( aItem );
611  aItem->Connect( zoneItem );
612  }
613 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
int Net() const
virtual const VECTOR2I GetAnchor(int n) const
BOARD_CONNECTED_ITEM * Parent() const
void Connect(CN_ITEM *b)
bool CanChangeNet() const
void CN_VISITOR::checkZoneZoneConnection ( CN_ZONE aZoneA,
CN_ZONE aZoneB 
)
protected

Definition at line 615 of file connectivity_algo.cpp.

References CN_ITEM::Connect(), CN_ZONE::ContainsPoint(), SHAPE_POLY_SET::COutline(), ZONE_CONTAINER::GetFilledPolysList(), i, CN_ITEM::Net(), CN_ITEM::Parent(), PCB_ZONE_AREA_T, and CN_ZONE::SubpolyIndex().

616 {
617  const auto refParent = static_cast<const ZONE_CONTAINER*>( aZoneA->Parent() );
618  const auto testedParent = static_cast<const ZONE_CONTAINER*>( aZoneB->Parent() );
619 
620  if( testedParent->Type () != PCB_ZONE_AREA_T )
621  return;
622 
623  if( aZoneB == aZoneA || refParent == testedParent )
624  return;
625 
626  if( aZoneB->Net() != aZoneA->Net() )
627  return; // we only test zones belonging to the same net
628 
629  const auto& outline = refParent->GetFilledPolysList().COutline( aZoneA->SubpolyIndex() );
630 
631  for( int i = 0; i < outline.PointCount(); i++ )
632  {
633  if( aZoneB->ContainsPoint( outline.CPoint( i ) ) )
634  {
635  aZoneA->Connect( aZoneB );
636  aZoneB->Connect( aZoneA );
637  return;
638  }
639  }
640 
641  const auto& outline2 = testedParent->GetFilledPolysList().COutline( aZoneB->SubpolyIndex() );
642 
643  for( int i = 0; i < outline2.PointCount(); i++ )
644  {
645  if( aZoneA->ContainsPoint( outline2.CPoint( i ) ) )
646  {
647  aZoneA->Connect( aZoneB );
648  aZoneB->Connect( aZoneA );
649  return;
650  }
651  }
652 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
bool ContainsPoint(const VECTOR2I p) const
int SubpolyIndex() const
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
int Net() const
const SHAPE_POLY_SET & GetFilledPolysList() const
Function GetFilledPolysList returns a reference to the list of filled polygons.
Definition: class_zone.h:555
BOARD_CONNECTED_ITEM * Parent() const
size_t i
Definition: json11.cpp:597
void Connect(CN_ITEM *b)
bool CN_VISITOR::operator() ( CN_ITEM aCandidate)

Definition at line 655 of file connectivity_algo.cpp.

References CN_ITEM::Connect(), CN_ITEM::Dirty(), CN_ITEM::GetAnchor(), CN_ITEM::Parent(), PCB_TRACE_T, PCB_ZONE_AREA_T, CN_ITEM::Valid(), VECTOR2< T >::x, and VECTOR2< T >::y.

656 {
657  const auto parentA = aCandidate->Parent();
658  const auto parentB = m_item->Parent();
659 
660  if( !aCandidate->Valid() || !m_item->Valid() )
661  return true;
662 
663  if( parentA == parentB )
664  return true;
665 
666  if( !( parentA->GetLayerSet() & parentB->GetLayerSet() ).any() )
667  return true;
668 
669  // If both m_item and aCandidate are marked dirty, they will both be searched
670  // Since we are reciprocal in our connection, we arbitrarily pick one of the connections
671  // to conduct the expensive search
672  if( aCandidate->Dirty() && aCandidate < m_item )
673  return true;
674 
675  // We should handle zone-zone connection separately
676  if ( parentA->Type() == PCB_ZONE_AREA_T && parentB->Type() == PCB_ZONE_AREA_T )
677  {
678  checkZoneZoneConnection( static_cast<CN_ZONE*>( m_item ),
679  static_cast<CN_ZONE*>( aCandidate ) );
680  return true;
681  }
682 
683  if( parentA->Type() == PCB_ZONE_AREA_T )
684  {
685  checkZoneItemConnection( static_cast<CN_ZONE*>( aCandidate ), m_item );
686  return true;
687  }
688 
689  if( parentB->Type() == PCB_ZONE_AREA_T )
690  {
691  checkZoneItemConnection( static_cast<CN_ZONE*>( m_item ), aCandidate );
692  return true;
693  }
694 
695  // Items do not necessarily have reciprocity as we only check for anchors
696  // therefore, we check HitTest both directions A->B & B->A
697  // TODO: Check for collision geometry on extended features
698  wxPoint ptA1( aCandidate->GetAnchor( 0 ).x, aCandidate->GetAnchor( 0 ).y );
699  wxPoint ptA2( aCandidate->GetAnchor( 1 ).x, aCandidate->GetAnchor( 1 ).y );
700  wxPoint ptB1( m_item->GetAnchor( 0 ).x, m_item->GetAnchor( 0 ).y );
701  wxPoint ptB2( m_item->GetAnchor( 1 ).x, m_item->GetAnchor( 1 ).y );
702  if( parentA->HitTest( ptB1 ) || parentB->HitTest( ptA1 ) ||
703  ( parentA->Type() == PCB_TRACE_T && parentB->HitTest( ptA2 ) ) ||
704  ( parentB->Type() == PCB_TRACE_T && parentA->HitTest( ptB2 ) ) )
705  {
706  m_item->Connect( aCandidate );
707  aCandidate->Connect( m_item );
708  }
709 
710  return true;
711 };
void checkZoneItemConnection(CN_ZONE *aZone, CN_ITEM *aItem)
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
bool Valid() const
virtual const VECTOR2I GetAnchor(int n) const
BOARD_CONNECTED_ITEM * Parent() 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 Dirty() const

Member Data Documentation

CN_ITEM* CN_VISITOR::m_item
protected

the item we are looking for connections to

Definition at line 272 of file connectivity_algo.h.


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