50 switch( aItem->
Type() )
118 return !it->second.GetItems().empty();
121 switch( aItem->
Type() )
134 if( alreadyAdded(
pad ) )
151 if( alreadyAdded( aItem ) )
159 if( alreadyAdded( aItem ) )
166 if( alreadyAdded( aItem ) )
173 if( alreadyAdded( aItem ) )
180 if( alreadyAdded( aItem ) )
191 ZONE* zone =
static_cast<ZONE*
>( aItem );
193 if( alreadyAdded( aItem ) )
225 item->RemoveInvalidRefs();
232 PROF_TIMER garbage_collection(
"garbage-collection" );
234 std::vector<CN_ITEM*> garbage;
235 garbage.reserve( 1024 );
248 garbage_collection.
Show();
253 std::vector<CN_ITEM*> dirtyItems;
257 return aItem->Dirty();
271 std::vector<std::future<size_t>> returns( dirtyItems.size() );
274 [&dirtyItems](
size_t aItem,
CN_LIST* aItemList,
277 if( aReporter && aReporter->IsCancelled() )
281 aItemList->FindNearby( dirtyItems[aItem], visitor );
284 aReporter->AdvanceProgress();
289 for(
size_t ii = 0; ii < dirtyItems.size(); ++ii )
292 for(
const std::future<size_t>& ret : returns )
295 std::future_status status = ret.wait_for( std::chrono::milliseconds( 250 ) );
297 while( status != std::future_status::ready )
302 status = ret.wait_for( std::chrono::milliseconds( 250 ) );
320 static const std::vector<KICAD_T> withoutZones = {
PCB_TRACE_T,
326 static const std::vector<KICAD_T> withZones = {
PCB_TRACE_T,
340 int aSingleNet,
CN_ITEM* rootItem )
344 std::deque<CN_ITEM*> Q;
345 std::set<CN_ITEM*> item_set;
352 auto addToSearchList =
353 [&item_set, withinAnyNet, aSingleNet, &aTypes, rootItem ](
CN_ITEM *aItem )
355 if( withinAnyNet && aItem->Net() <= 0 )
358 if( !aItem->Valid() )
361 if( aSingleNet >=0 && aItem->Net() != aSingleNet )
368 if( aItem->Parent()->Type() == type )
375 if( !found && aItem != rootItem )
378 aItem->SetVisited(
false );
380 item_set.insert( aItem );
388 while( !item_set.empty() )
390 std::shared_ptr<CN_CLUSTER> cluster = std::make_shared<CN_CLUSTER>();
392 auto it = item_set.begin();
394 while( it != item_set.end() && (*it)->Visited() )
395 it = item_set.erase( item_set.begin() );
397 if( it == item_set.end() )
411 cluster->Add( current );
415 if( withinAnyNet && n->Net() != root->
Net() )
418 if( !n->Visited() && n->Valid() )
426 clusters.push_back( cluster );
432 std::sort( clusters.begin(), clusters.end(),
433 [](
const std::shared_ptr<CN_CLUSTER>& a,
const std::shared_ptr<CN_CLUSTER>& b )
435 return a->OriginNet() < b->OriginNet();
446 std::vector<CN_ZONE_LAYER*> zitems;
450 if( zone->IsOnCopperLayer() )
463 for(
int j = 0; j < zone->GetFilledPolysList( layer )->OutlineCount(); j++ )
471 int progressDelta = 50;
474 size += zitems.size();
475 size += zitems.size();
476 size += aBoard->
Tracks().size();
480 size += footprint->Pads().size();
484 progressDelta = std::max( progressDelta, (
int) size / 4 );
489 if( aReporter && ( progress % progressDelta ) == 0 )
499 std::vector<std::future<size_t>> returns( zitems.size() );
507 aZoneLayer->BuildRTree();
515 for(
size_t ii = 0; ii < zitems.size(); ++ii )
516 returns[ii] =
tp.submit( cache_zones, zitems[ii] );
518 for(
const std::future<size_t>& ret : returns )
520 std::future_status status = ret.wait_for( std::chrono::milliseconds( 250 ) );
522 while( status != std::future_status::ready )
527 status = ret.wait_for( std::chrono::milliseconds( 250 ) );
534 int ii = zitems.size();
539 m_itemMap[ zitem->Parent() ].Link( zitem );
551 for(
PAD*
pad : footprint->Pads() )
562 if( shape->IsOnCopperLayer() )
578 const std::vector<BOARD_ITEM*>& aLocalItems )
585 switch( item->Type() )
605 for(
const std::shared_ptr<CN_CLUSTER>& cluster :
m_connClusters )
607 if( cluster->IsConflicting() )
611 wxLogTrace( wxT(
"CN" ), wxT(
"Conflicting pads in cluster %p; skipping propagation" ),
614 else if( cluster->HasValidNet() )
620 for(
CN_ITEM* item : *cluster )
622 if( item->Valid() && item->CanChangeNet()
623 && item->Parent()->GetNetCode() != cluster->OriginNet() )
629 aCommit->
Modify( item->Parent() );
631 item->Parent()->SetNetCode( cluster->OriginNet() );
638 wxLogTrace( wxT(
"CN" ), wxT(
"Cluster %p: net: %d %s" ),
640 cluster->OriginNet(),
641 (
const char*) cluster->OriginNetName().c_str() );
645 wxLogTrace( wxT(
"CN" ), wxT(
"Cluster %p: no changeable items to propagate to" ),
651 wxLogTrace( wxT(
"CN" ), wxT(
"Cluster %p: connected to unused net" ),
666 std::map<
ZONE*, std::map<PCB_LAYER_ID, ISOLATED_ISLANDS>>& aMap,
667 bool aConnectivityAlreadyRebuilt )
669 int progressDelta = 50;
672 progressDelta = std::max( progressDelta, (
int) aMap.size() / 4 );
674 if( !aConnectivityAlreadyRebuilt )
676 for(
const auto& [ zone, islands ] : aMap )
695 for(
auto& [ zone, zoneIslands ] : aMap )
697 for(
auto& [ layer, layerIslands ] : zoneIslands )
699 if( zone->GetFilledPolysList( layer )->IsEmpty() )
702 for(
const std::shared_ptr<CN_CLUSTER>& cluster :
m_connClusters )
704 for(
CN_ITEM* item : *cluster )
706 if( item->Parent() == zone && item->GetBoardLayer() == layer )
710 if( cluster->IsOrphaned() )
711 layerIslands.m_IsolatedOutlines.push_back( z->
SubpolyIndex() );
713 layerIslands.m_SingleConnectionOutlines.push_back( z->
SubpolyIndex() );
743 for(
int i = lastNet; i < aNet + 1; i++ )
771 if(
pad->ConditionallyFlashed( layer )
781 if(
via->ConditionallyFlashed( layer )
813 const ZONE* zoneA =
static_cast<const ZONE*
>( aZoneLayerA->
Parent() );
814 const ZONE* zoneB =
static_cast<const ZONE*
>( aZoneLayerB->
Parent() );
821 if( aZoneLayerB->
GetLayer() != layer )
830 for(
int i = 0; i < outline.
PointCount(); i++ )
837 aZoneLayerA->
Connect( aZoneLayerB );
838 aZoneLayerB->
Connect( aZoneLayerA );
846 for(
int i = 0; i < outline2.
PointCount(); i++ )
853 aZoneLayerA->
Connect( aZoneLayerB );
854 aZoneLayerB->
Connect( aZoneLayerA );
869 if( parentA == parentB )
904 for(
size_t ii = 0; ii < commonLayers.size(); ++ii )
906 if( commonLayers.test( ii ) )
909 FLASHING flashingA = FLASHING::NEVER_FLASHED;
910 FLASHING flashingB = FLASHING::NEVER_FLASHED;
914 if( !
static_cast<const PAD*
>( parentA )->ConditionallyFlashed( layer ) )
915 flashingA = FLASHING::ALWAYS_FLASHED;
919 if( !
static_cast<const PCB_VIA*
>( parentA )->ConditionallyFlashed( layer ) )
920 flashingA = FLASHING::ALWAYS_FLASHED;
925 if( !
static_cast<const PAD*
>( parentB )->ConditionallyFlashed( layer ) )
926 flashingB = FLASHING::ALWAYS_FLASHED;
930 if( !
static_cast<const PCB_VIA*
>( parentB )->ConditionallyFlashed( layer ) )
931 flashingB = FLASHING::ALWAYS_FLASHED;
@ ZLO_FORCE_NO_ZONE_CONNECTION
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
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.
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
virtual bool IsOnCopperLayer() const
Information pertinent to a Pcbnew printed circuit board.
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
const ZONES & Zones() const
const FOOTPRINTS & Footprints() const
const TRACKS & Tracks() const
const DRAWINGS & Drawings() const
constexpr bool Contains(const Vec &aPoint) const
constexpr bool Intersects(const BOX2< Vec > &aRect) const
void FillIsolatedIslandsMap(std::map< ZONE *, std::map< PCB_LAYER_ID, ISOLATED_ISLANDS > > &aMap, bool aConnectivityAlreadyRebuilt)
Fill in the isolated islands map with copper islands that are not connected to a net.
bool Remove(BOARD_ITEM *aItem)
CONNECTIVITY_DATA * m_parentConnectivityData
void add(Container &c, BItem brditem)
PROGRESS_REPORTER * m_progressReporter
std::vector< std::shared_ptr< CN_CLUSTER > > m_connClusters
void LocalBuild(std::shared_ptr< CONNECTIVITY_DATA > aGlobalConnectivity, const std::vector< BOARD_ITEM * > &aLocalItems)
void propagateConnections(BOARD_COMMIT *aCommit=nullptr)
const CLUSTERS & GetClusters()
void MarkNetAsDirty(int aNet)
void markItemNetAsDirty(const BOARD_ITEM *aItem)
std::vector< std::shared_ptr< CN_CLUSTER > > m_ratsnestClusters
void PropagateNets(BOARD_COMMIT *aCommit=nullptr)
Propagate nets from pads to other items in clusters.
std::shared_ptr< CONNECTIVITY_DATA > m_globalConnectivityData
const CLUSTERS SearchClusters(CLUSTER_SEARCH_MODE aMode, const std::vector< KICAD_T > &aTypes, int aSingleNet, CN_ITEM *rootItem=nullptr)
std::vector< bool > m_dirtyNets
std::vector< std::shared_ptr< CN_CLUSTER > > CLUSTERS
std::unordered_map< const BOARD_ITEM *, ITEM_MAP_ENTRY > m_itemMap
void SetProgressReporter(PROGRESS_REPORTER *aReporter)
void Build(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
bool Add(BOARD_ITEM *aItem)
CN_ITEM represents a BOARD_CONNETED_ITEM in the connectivity system (ie: a pad, track/arc/via,...
virtual int AnchorCount() const
const std::vector< CN_ITEM * > & ConnectedItems() const
virtual const VECTOR2I GetAnchor(int n) const
bool CanChangeNet() const
void SetVisited(bool aVisited)
BOARD_CONNECTED_ITEM * Parent() const
std::vector< CN_ITEM * >::iterator begin()
void SetDirty(bool aDirty=true)
std::vector< CN_ITEM * >::iterator end()
void SetHasInvalid(bool aInvalid=true)
void RemoveInvalidItems(std::vector< CN_ITEM * > &aGarbage)
void checkZoneItemConnection(CN_ZONE_LAYER *aZoneLayer, CN_ITEM *aItem)
CN_ITEM * m_item
The item we are looking for connections to.
void checkZoneZoneConnection(CN_ZONE_LAYER *aZoneLayerA, CN_ZONE_LAYER *aZoneLayerB)
bool operator()(CN_ITEM *aCandidate)
bool HasSingleConnection()
PCB_LAYER_ID GetLayer() const
bool Collide(SHAPE *aRefShape) const
bool ContainsPoint(const VECTOR2I &p) const
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
KICAD_T Type() const
Returns the type of object.
LSET is a set of PCB_LAYER_IDs.
void RunOnLayers(const std::function< void(PCB_LAYER_ID)> &aFunction) const
Execute a function on each layer of the LSET.
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Handle the data for a net.
A small class to help profiling.
void Show(std::ostream &aStream=std::cerr)
Print the elapsed time (in a suitable unit) to a stream.
A progress reporter interface for use in multi-threaded environments.
virtual bool IsCancelled() const =0
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void AdvanceProgress()=0
Increment the progress bar length (inside the current virtual zone).
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).
virtual void SetMaxProgress(int aMaxProgress)=0
Fix the value that gives the 100 percent progress bar length (inside the current virtual zone).
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Handle a list of polygons defining a copper zone.
const std::shared_ptr< SHAPE_POLY_SET > & GetFilledPolysList(PCB_LAYER_ID aLayer) const
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
a few functions useful in geometry calculations.
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
PCB_LAYER_ID
A quick note on layer IDs:
BS::thread_pool thread_pool
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_ZONE_T
class ZONE, a copper pour area
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
@ PCB_PAD_T
class PAD, a pad in a footprint
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)