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 670 of file connectivity_algo.cpp.

671 {
672  if( aZoneLayer->Net() != aItem->Net() && !aItem->CanChangeNet() )
673  return;
674 
675  if( !aZoneLayer->BBox().Intersects( aItem->BBox() ) )
676  return;
677 
678  int accuracy = 0;
679 
680  if( aItem->Parent()->Type() == PCB_VIA_T
681  || aItem->Parent()->Type() == PCB_TRACE_T
682  || aItem->Parent()->Type() == PCB_ARC_T )
683  {
684  accuracy = ( static_cast<PCB_TRACK*>( aItem->Parent() )->GetWidth() + 1 ) / 2;
685  }
686 
687  for( int i = 0; i < aItem->AnchorCount(); ++i )
688  {
689  if( aZoneLayer->ContainsPoint( aItem->GetAnchor( i ), accuracy ) )
690  {
691  aZoneLayer->Connect( aItem );
692  aItem->Connect( aZoneLayer );
693  return;
694  }
695  }
696 }
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 698 of file connectivity_algo.cpp.

699 {
700  const ZONE* zoneA = static_cast<const ZONE*>( aZoneLayerA->Parent() );
701  const ZONE* zoneB = static_cast<const ZONE*>( aZoneLayerB->Parent() );
702 
703  if( aZoneLayerA->Layer() != aZoneLayerB->Layer() )
704  return;
705 
706  if( aZoneLayerB->Net() != aZoneLayerA->Net() )
707  return; // we only test zones belonging to the same net
708 
709  const BOX2I& boxA = aZoneLayerA->BBox();
710  const BOX2I& boxB = aZoneLayerB->BBox();
711 
712  int radiusA = 0;
713  int radiusB = 0;
714 
715  if( zoneA->GetFilledPolysUseThickness() )
716  radiusA = ( zoneA->GetMinThickness() + 1 ) / 2;
717 
718  if( zoneB->GetFilledPolysUseThickness() )
719  radiusB = ( zoneB->GetMinThickness() + 1 ) / 2;
720 
721  PCB_LAYER_ID layer = static_cast<PCB_LAYER_ID>( aZoneLayerA->Layer() );
722 
723  const SHAPE_LINE_CHAIN& outline =
724  zoneA->GetFilledPolysList( layer ).COutline( aZoneLayerA->SubpolyIndex() );
725 
726  for( int i = 0; i < outline.PointCount(); i++ )
727  {
728  if( !boxB.Contains( outline.CPoint( i ) ) )
729  continue;
730 
731  if( aZoneLayerB->ContainsPoint( outline.CPoint( i ), radiusA ) )
732  {
733  aZoneLayerA->Connect( aZoneLayerB );
734  aZoneLayerB->Connect( aZoneLayerA );
735  return;
736  }
737  }
738 
739  const SHAPE_LINE_CHAIN& outline2 =
740  zoneB->GetFilledPolysList( layer ).COutline( aZoneLayerB->SubpolyIndex() );
741 
742  for( int i = 0; i < outline2.PointCount(); i++ )
743  {
744  if( !boxA.Contains( outline2.CPoint( i ) ) )
745  continue;
746 
747  if( aZoneLayerA->ContainsPoint( outline2.CPoint( i ), radiusB ) )
748  {
749  aZoneLayerA->Connect( aZoneLayerB );
750  aZoneLayerB->Connect( aZoneLayerA );
751  return;
752  }
753  }
754 }
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:637
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:691

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 757 of file connectivity_algo.cpp.

758 {
759  const BOARD_CONNECTED_ITEM* parentA = aCandidate->Parent();
760  const BOARD_CONNECTED_ITEM* parentB = m_item->Parent();
761 
762  if( !aCandidate->Valid() || !m_item->Valid() )
763  return true;
764 
765  if( parentA == parentB )
766  return true;
767 
768  LSET commonLayers = parentA->GetLayerSet() & parentB->GetLayerSet();
769 
770  if( !commonLayers.any() )
771  return true;
772 
773  // If both m_item and aCandidate are marked dirty, they will both be searched
774  // Since we are reciprocal in our connection, we arbitrarily pick one of the connections
775  // to conduct the expensive search
776  if( aCandidate->Dirty() && aCandidate < m_item )
777  return true;
778 
779  // We should handle zone-zone connection separately
780  if ( parentA->Type() == PCB_ZONE_T && parentB->Type() == PCB_ZONE_T )
781  {
782  checkZoneZoneConnection( static_cast<CN_ZONE_LAYER*>( m_item ),
783  static_cast<CN_ZONE_LAYER*>( aCandidate ) );
784  return true;
785  }
786 
787  if( parentA->Type() == PCB_ZONE_T )
788  {
789  checkZoneItemConnection( static_cast<CN_ZONE_LAYER*>( aCandidate ), m_item );
790  return true;
791  }
792 
793  if( parentB->Type() == PCB_ZONE_T )
794  {
795  checkZoneItemConnection( static_cast<CN_ZONE_LAYER*>( m_item ), aCandidate );
796  return true;
797  }
798 
799  for( PCB_LAYER_ID layer : commonLayers.Seq() )
800  {
801  FLASHING flashingA = FLASHING::NEVER_FLASHED;
802  FLASHING flashingB = FLASHING::NEVER_FLASHED;
803 
804  if( const PAD* pad = dyn_cast<const PAD*>( parentA ) )
805  {
806  if( !pad->GetRemoveUnconnected() || ( ( layer == F_Cu || layer == B_Cu ) && pad->GetKeepTopBottom() ) )
807  flashingA = FLASHING::ALWAYS_FLASHED;
808  }
809  else if( const PCB_VIA* via = dyn_cast<const PCB_VIA*>( parentA ) )
810  {
811  if( !via->GetRemoveUnconnected() || ( ( layer == F_Cu || layer == B_Cu ) && via->GetKeepTopBottom() ) )
812  flashingA = FLASHING::ALWAYS_FLASHED;
813  }
814 
815  if( const PAD* pad = dyn_cast<const PAD*>( parentB ) )
816  {
817  if( !pad->GetRemoveUnconnected() || ( ( layer == F_Cu || layer == B_Cu ) && pad->GetKeepTopBottom() ) )
818  flashingB = FLASHING::ALWAYS_FLASHED;
819  }
820  else if( const PCB_VIA* via = dyn_cast<const PCB_VIA*>( parentB ) )
821  {
822  if( !via->GetRemoveUnconnected() || ( ( layer == F_Cu || layer == B_Cu ) && via->GetKeepTopBottom() ) )
823  flashingB = FLASHING::ALWAYS_FLASHED;
824  }
825 
826  if( parentA->GetEffectiveShape( layer, flashingA )->Collide(
827  parentB->GetEffectiveShape( layer, flashingB ).get() ) )
828  {
829  m_item->Connect( aCandidate );
830  aCandidate->Connect( m_item );
831  return true;
832  }
833  }
834 
835  return true;
836 };
void checkZoneItemConnection(CN_ZONE_LAYER *aZoneLayer, CN_ITEM *aItem)
bool Dirty() const
BOARD_CONNECTED_ITEM * Parent() const
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: board_item.cpp:181
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:516
void checkZoneZoneConnection(CN_ZONE_LAYER *aZoneLayerA, CN_ZONE_LAYER *aZoneLayerB)
class ZONE, a copper pour area
Definition: typeinfo.h:105
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:153
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
Definition: layer_ids.h:71
void Connect(CN_ITEM *b)
Definition: pad.h:57
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:148
bool Valid() const
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References ALWAYS_FLASHED, B_Cu, checkZoneItemConnection(), checkZoneZoneConnection(), CN_ITEM::Connect(), CN_ITEM::Dirty(), F_Cu, BOARD_ITEM::GetEffectiveShape(), BOARD_ITEM::GetLayerSet(), m_item, NEVER_FLASHED, pad, CN_ITEM::Parent(), PCB_ZONE_T, LSET::Seq(), EDA_ITEM::Type(), CN_ITEM::Valid(), and via.

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: