KiCad PCB EDA Suite
CN_LIST Class Reference

#include <connectivity_items.h>

Public Types

using ITER = decltype(m_items)::iterator
 
using CONST_ITER = decltype(m_items)::const_iterator
 

Public Member Functions

 CN_LIST ()
 
void Clear ()
 
ITER begin ()
 
ITER end ()
 
CONST_ITER begin () const
 
CONST_ITER end () const
 
CN_ITEMoperator[] (int aIndex)
 
template<class T >
void FindNearby (CN_ITEM *aItem, T aFunc)
 
void SetHasInvalid (bool aInvalid=true)
 
void SetDirty (bool aDirty=true)
 
bool IsDirty () const
 
void RemoveInvalidItems (std::vector< CN_ITEM * > &aGarbage)
 
void ClearDirtyFlags ()
 
int Size () const
 
CN_ITEMAdd (PAD *pad)
 
CN_ITEMAdd (PCB_TRACK *track)
 
CN_ITEMAdd (PCB_ARC *track)
 
CN_ITEMAdd (PCB_VIA *via)
 
CN_ITEMAdd (CN_ZONE_LAYER *zitem)
 
const std::vector< CN_ITEM * > Add (ZONE *zone, PCB_LAYER_ID aLayer)
 

Protected Member Functions

void addItemtoTree (CN_ITEM *item)
 

Protected Attributes

std::vector< CN_ITEM * > m_items
 

Private Attributes

bool m_dirty
 
bool m_hasInvalid
 
CN_RTREE< CN_ITEM * > m_index
 

Detailed Description

Definition at line 398 of file connectivity_items.h.

Member Typedef Documentation

◆ CONST_ITER

using CN_LIST::CONST_ITER = decltype( m_items )::const_iterator

Definition at line 425 of file connectivity_items.h.

◆ ITER

using CN_LIST::ITER = decltype( m_items )::iterator

Definition at line 424 of file connectivity_items.h.

Constructor & Destructor Documentation

◆ CN_LIST()

CN_LIST::CN_LIST ( )
inline

Definition at line 409 of file connectivity_items.h.

410 {
411 m_dirty = false;
412 m_hasInvalid = false;
413 }

References m_dirty, and m_hasInvalid.

Member Function Documentation

◆ Add() [1/6]

CN_ITEM * CN_LIST::Add ( CN_ZONE_LAYER zitem)

Definition at line 224 of file connectivity_items.cpp.

225{
226 m_items.push_back( zitem );
227 addItemtoTree( zitem );
228 SetDirty();
229 return zitem;
230}
void SetDirty(bool aDirty=true)
std::vector< CN_ITEM * > m_items
void addItemtoTree(CN_ITEM *item)

References addItemtoTree(), m_items, and SetDirty().

◆ Add() [2/6]

CN_ITEM * CN_LIST::Add ( PAD pad)

Definition at line 124 of file connectivity_items.cpp.

125 {
126 if( !pad->IsOnCopperLayer() )
127 return nullptr;
128
129 auto item = new CN_ITEM( pad, false, 1 );
130 item->AddAnchor( pad->ShapePos() );
131 item->SetLayers( LAYER_RANGE( F_Cu, B_Cu ) );
132
133 switch( pad->GetAttribute() )
134 {
135 case PAD_ATTRIB::SMD:
136 case PAD_ATTRIB::NPTH:
137 case PAD_ATTRIB::CONN:
138 {
139 LSET lmsk = pad->GetLayerSet();
140
141 for( int i = 0; i <= MAX_CU_LAYERS; i++ )
142 {
143 if( lmsk[i] )
144 {
145 item->SetLayer( i );
146 break;
147 }
148 }
149 break;
150 }
151 default:
152 break;
153 }
154
155 addItemtoTree( item );
156 m_items.push_back( item );
157 SetDirty();
158 return item;
159}
CN_ITEM represents a BOARD_CONNETED_ITEM in the connectivity system (ie: a pad, track/arc/via,...
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:32
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:530
#define MAX_CU_LAYERS
Definition: layer_ids.h:140
@ B_Cu
Definition: layer_ids.h:95
@ F_Cu
Definition: layer_ids.h:64
@ NPTH
like PAD_PTH, but not plated
@ SMD
Smd pad, appears on the solder paste layer (default)
@ CONN
Like smd, does not appear on the solder paste layer (default)

References addItemtoTree(), B_Cu, CONN, F_Cu, m_items, MAX_CU_LAYERS, NPTH, pad, SetDirty(), and SMD.

Referenced by CN_CONNECTIVITY_ALGO::Add(), Add(), and CN_CONNECTIVITY_ALGO::Build().

◆ Add() [3/6]

CN_ITEM * CN_LIST::Add ( PCB_ARC track)

Definition at line 175 of file connectivity_items.cpp.

176{
177 CN_ITEM* item = new CN_ITEM( aArc, true );
178 m_items.push_back( item );
179 item->AddAnchor( aArc->GetStart() );
180 item->AddAnchor( aArc->GetEnd() );
181 item->SetLayer( aArc->GetLayer() );
182 addItemtoTree( item );
183 SetDirty();
184 return item;
185}
std::shared_ptr< CN_ANCHOR > AddAnchor(const VECTOR2I &aPos)
void SetLayer(int aLayer)
Set the layers spanned by the item to a single layer aLayer.

References CN_ITEM::AddAnchor(), addItemtoTree(), PCB_TRACK::GetEnd(), BOARD_ITEM::GetLayer(), PCB_TRACK::GetStart(), m_items, SetDirty(), and CN_ITEM::SetLayer().

◆ Add() [4/6]

CN_ITEM * CN_LIST::Add ( PCB_TRACK track)

Definition at line 162 of file connectivity_items.cpp.

163{
164 CN_ITEM* item = new CN_ITEM( track, true );
165 m_items.push_back( item );
166 item->AddAnchor( track->GetStart() );
167 item->AddAnchor( track->GetEnd() );
168 item->SetLayer( track->GetLayer() );
169 addItemtoTree( item );
170 SetDirty();
171 return item;
172}
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:180
const VECTOR2I & GetStart() const
Definition: pcb_track.h:113
const VECTOR2I & GetEnd() const
Definition: pcb_track.h:110

References CN_ITEM::AddAnchor(), addItemtoTree(), PCB_TRACK::GetEnd(), BOARD_ITEM::GetLayer(), PCB_TRACK::GetStart(), m_items, SetDirty(), and CN_ITEM::SetLayer().

◆ Add() [5/6]

CN_ITEM * CN_LIST::Add ( PCB_VIA via)

Definition at line 188 of file connectivity_items.cpp.

189{
190 CN_ITEM* item = new CN_ITEM( via, !via->GetIsFree(), 1 );
191
192 m_items.push_back( item );
193 item->AddAnchor( via->GetStart() );
194
195 item->SetLayers( LAYER_RANGE( via->TopLayer(), via->BottomLayer() ) );
196 addItemtoTree( item );
197 SetDirty();
198 return item;
199}
void SetLayers(const LAYER_RANGE &aLayers)
Set the layers spanned by the item to aLayers.

References CN_ITEM::AddAnchor(), addItemtoTree(), m_items, SetDirty(), CN_ITEM::SetLayers(), and via.

◆ Add() [6/6]

const std::vector< CN_ITEM * > CN_LIST::Add ( ZONE zone,
PCB_LAYER_ID  aLayer 
)

Definition at line 202 of file connectivity_items.cpp.

203{
204 const std::shared_ptr<SHAPE_POLY_SET>& polys = zone->GetFilledPolysList( aLayer );
205
206 std::vector<CN_ITEM*> rv;
207
208 for( int j = 0; j < polys->OutlineCount(); j++ )
209 {
210 CN_ZONE_LAYER* zitem = new CN_ZONE_LAYER( zone, aLayer, j );
211
212 zitem->BuildRTree();
213
214 for( VECTOR2I pt : zone->GetFilledPolysList( aLayer )->COutline( j ).CPoints() )
215 zitem->AddAnchor( pt );
216
217 rv.push_back( Add( zitem ) );
218 }
219
220 return rv;
221}
CN_ITEM * Add(PAD *pad)
const std::shared_ptr< SHAPE_POLY_SET > & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition: zone.h:602

References Add(), CN_ITEM::AddAnchor(), CN_ZONE_LAYER::BuildRTree(), and ZONE::GetFilledPolysList().

◆ addItemtoTree()

void CN_LIST::addItemtoTree ( CN_ITEM item)
inlineprotected

Definition at line 403 of file connectivity_items.h.

404 {
405 m_index.Insert( item );
406 }
CN_RTREE< CN_ITEM * > m_index
void Insert(T aItem)
Function Insert() Inserts an item into the tree.

References CN_RTREE< T >::Insert(), and m_index.

Referenced by Add().

◆ begin() [1/2]

ITER CN_LIST::begin ( )
inline

Definition at line 427 of file connectivity_items.h.

427{ return m_items.begin(); };

References m_items.

Referenced by CN_CONNECTIVITY_ALGO::SearchClusters(), and CN_CONNECTIVITY_ALGO::searchConnections().

◆ begin() [2/2]

CONST_ITER CN_LIST::begin ( ) const
inline

Definition at line 430 of file connectivity_items.h.

430{ return m_items.begin(); }

References m_items.

◆ Clear()

void CN_LIST::Clear ( )
inline

Definition at line 415 of file connectivity_items.h.

416 {
417 for( CN_ITEM* item : m_items )
418 delete item;
419
420 m_items.clear();
422 }
void RemoveAll()
Function RemoveAll() Removes all items from the RTree.

References m_index, m_items, and CN_RTREE< T >::RemoveAll().

Referenced by CN_CONNECTIVITY_ALGO::Clear().

◆ ClearDirtyFlags()

void CN_LIST::ClearDirtyFlags ( )
inline

Definition at line 448 of file connectivity_items.h.

449 {
450 for( CN_ITEM* item : m_items )
451 item->SetDirty( false );
452
453 SetDirty( false );
454 }

References m_items, and SetDirty().

Referenced by CN_CONNECTIVITY_ALGO::searchConnections().

◆ end() [1/2]

ITER CN_LIST::end ( )
inline

Definition at line 428 of file connectivity_items.h.

428{ return m_items.end(); };

References m_items.

Referenced by CN_CONNECTIVITY_ALGO::SearchClusters(), and CN_CONNECTIVITY_ALGO::searchConnections().

◆ end() [2/2]

CONST_ITER CN_LIST::end ( ) const
inline

Definition at line 431 of file connectivity_items.h.

431{ return m_items.end(); }

References m_items.

◆ FindNearby()

template<class T >
void CN_LIST::FindNearby ( CN_ITEM aItem,
aFunc 
)
inline

Definition at line 436 of file connectivity_items.h.

437 {
438 m_index.Query( aItem->BBox(), aItem->Layers(), aFunc );
439 }
const BOX2I & BBox()
const LAYER_RANGE & Layers() const
Return the contiguous set of layers spanned by the item.
void Query(const BOX2I &aBounds, const LAYER_RANGE &aRange, Visitor &aVisitor) const
Function Query() Executes a function object aVisitor for each item whose bounding box intersects with...

References CN_ITEM::BBox(), CN_ITEM::Layers(), m_index, and CN_RTREE< T >::Query().

◆ IsDirty()

bool CN_LIST::IsDirty ( ) const
inline

Definition at line 444 of file connectivity_items.h.

444{ return m_dirty; }

References m_dirty.

Referenced by CN_CONNECTIVITY_ALGO::SearchClusters(), and CN_CONNECTIVITY_ALGO::searchConnections().

◆ operator[]()

CN_ITEM * CN_LIST::operator[] ( int  aIndex)
inline

Definition at line 433 of file connectivity_items.h.

433{ return m_items[aIndex]; }

References m_items.

◆ RemoveInvalidItems()

void CN_LIST::RemoveInvalidItems ( std::vector< CN_ITEM * > &  aGarbage)

Definition at line 233 of file connectivity_items.cpp.

234{
235 if( !m_hasInvalid )
236 return;
237
238 auto lastItem = std::remove_if( m_items.begin(), m_items.end(),
239 [&aGarbage]( CN_ITEM* item )
240 {
241 if( !item->Valid() )
242 {
243 aGarbage.push_back ( item );
244 return true;
245 }
246
247 return false;
248 } );
249
250 m_items.resize( lastItem - m_items.begin() );
251
252 for( CN_ITEM* item : m_items )
253 item->RemoveInvalidRefs();
254
255 for( CN_ITEM* item : aGarbage )
256 m_index.Remove( item );
257
258 m_hasInvalid = false;
259}
void Remove(T aItem)
Function Remove() Removes an item from the tree.

References m_hasInvalid, and m_items.

Referenced by CN_CONNECTIVITY_ALGO::searchConnections().

◆ SetDirty()

void CN_LIST::SetDirty ( bool  aDirty = true)
inline

Definition at line 443 of file connectivity_items.h.

443{ m_dirty = aDirty; }

References m_dirty.

Referenced by Add(), ClearDirtyFlags(), and CN_CONNECTIVITY_ALGO::Remove().

◆ SetHasInvalid()

void CN_LIST::SetHasInvalid ( bool  aInvalid = true)
inline

Definition at line 441 of file connectivity_items.h.

441{ m_hasInvalid = aInvalid; }

References m_hasInvalid.

Referenced by CN_CONNECTIVITY_ALGO::Remove().

◆ Size()

int CN_LIST::Size ( ) const
inline

Definition at line 456 of file connectivity_items.h.

457 {
458 return m_items.size();
459 }

References m_items.

Member Data Documentation

◆ m_dirty

bool CN_LIST::m_dirty
private

Definition at line 474 of file connectivity_items.h.

Referenced by CN_LIST(), IsDirty(), and SetDirty().

◆ m_hasInvalid

bool CN_LIST::m_hasInvalid
private

Definition at line 475 of file connectivity_items.h.

Referenced by CN_LIST(), RemoveInvalidItems(), and SetHasInvalid().

◆ m_index

CN_RTREE<CN_ITEM*> CN_LIST::m_index
private

Definition at line 476 of file connectivity_items.h.

Referenced by addItemtoTree(), Clear(), and FindNearby().

◆ m_items

std::vector<CN_ITEM*> CN_LIST::m_items
protected

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