28#include <initializer_list>
59 const std::vector<BOARD_ITEM*>& aLocalItems,
60 bool aSkipRatsnestUpdate ) :
63 Build( aGlobalConnectivity, aLocalItems );
104 std::unique_lock<KISPINLOCK> lock(
m_lock, std::try_to_lock );
111 aReporter->
Report(
_(
"Updating nets..." ) );
155 const std::vector<BOARD_ITEM*>& aLocalItems )
157 std::unique_lock<KISPINLOCK> lock(
m_lock, std::try_to_lock );
163 m_connAlgo->LocalBuild( aGlobalConnectivity, aLocalItems );
184 std::vector<RN_NET*> dirty_nets;
188 std::copy_if(
m_nets.begin() + 1,
m_nets.end(), std::back_inserter( dirty_nets ),
191 return aNet->IsDirty() && aNet->GetNodeCount() > 0;
196 auto results =
tp.submit_loop( 0, dirty_nets.size(),
199 dirty_nets[ii]->UpdateNet();
203 auto results2 =
tp.submit_loop( 0, dirty_nets.size(),
206 dirty_nets[ii]->OptimizeRNEdges();
229 std::unique_lock<KISPINLOCK> lock(
m_lock );
241 if( lastNet >= (
int)
m_nets.size() )
243 unsigned int prevSize =
m_nets.size();
244 m_nets.resize( lastNet + 1 );
246 for(
unsigned int i = prevSize; i <
m_nets.size(); i++ )
251 for(
size_t ii = lastNet; ii <
m_nets.size(); ++ii )
255 const std::vector<std::shared_ptr<CN_CLUSTER>>& clusters =
m_connAlgo->GetClusters();
257 for(
int net = 0; net < lastNet; net++ )
263 for(
const std::shared_ptr<CN_CLUSTER>& c : clusters )
265 int net = c->OriginNet();
268 if( c->IsOrphaned() && c->Size() == 1 )
287 std::vector<BOARD_CONNECTED_ITEM*> citems;
294 citems.push_back(
pad );
299 citems.push_back( citem );
311 for(
const std::shared_ptr<CN_ANCHOR>&
anchor : cnItem->Anchors() )
312 anchor->SetNoLine(
true );
326 bool aConnectivityAlreadyRebuilt )
328 m_connAlgo->FillIsolatedIslandsMap( aMap, aConnectivityAlreadyRebuilt );
340 std::mutex dynamic_ratsnest_mutex;
345 auto update_lambda = [&](
int nc )
364 std::lock_guard<std::mutex> lock( dynamic_ratsnest_mutex );
371 size_t num_nets = std::min(
m_nets.size(), aDynamicData->
m_nets.size() );
373 auto results =
tp.submit_loop( 1, num_nets,
383 for(
const CN_EDGE& edge : edges )
385 const std::shared_ptr<const CN_ANCHOR>& nodeA = edge.GetSourceNode();
386 const std::shared_ptr<const CN_ANCHOR>& nodeB = edge.GetTargetNode();
388 if( !nodeA || nodeA->Dirty() || !nodeB || nodeB->Dirty() )
394 l.
a = nodeA->Parent()->GetPosition() + aInternalOffset;
395 l.
b = nodeB->Parent()->GetPosition() + aInternalOffset;
406 anchor.SetNoLine(
false );
425 const std::initializer_list<KICAD_T>& aTypes )
const
434 if( aTypes.size() == 0 )
449 if( connected->Valid()
450 && connected->StartLayer() <= lyIdx && connected->EndLayer() >= lyIdx
451 && matchType( connected->Parent()->Type() )
454 BOARD_ITEM* connectedItem = connected->Parent();
456 if( connectedItem == aItem )
459 if( parentFootprint && connectedItem
468 const PAD* thisPad =
static_cast<const PAD*
>( aItem );
469 const PAD* otherPad =
static_cast<const PAD*
>( connectedItem );
496 const PAD*
pad =
static_cast<const PAD*
>( aItem );
538 if( !viaHull.SHAPE::Collide( pt ) )
557 unsigned int unconnected = 0;
564 for(
const CN_EDGE& edge : net->GetEdges() )
566 if( edge.IsVisible() || !aVisibleOnly )
582const std::vector<BOARD_CONNECTED_ITEM*>
588 std::vector<BOARD_CONNECTED_ITEM*> rv;
590 auto clusters =
m_connAlgo->SearchClusters( ( aFlags &
IGNORE_NETS ) ? CSM_PROPAGATE : CSM_CONNECTIVITY_CHECK,
594 for(
const std::shared_ptr<CN_CLUSTER>& cl : clusters )
596 if( cl->Contains( aItem ) )
598 for(
const CN_ITEM* item : *cl )
601 rv.push_back( item->Parent() );
610const std::vector<BOARD_CONNECTED_ITEM*>
613 std::vector<BOARD_CONNECTED_ITEM*> items;
616 std::bitset<MAX_STRUCT_TYPE_ID> type_bits;
618 for(
KICAD_T scanType : aTypes )
621 type_bits.set( scanType );
627 if( aItem.
Valid() && ( aItem.
Net() == aNetCode ) && type_bits[aItem.
Parent()->
Type()] )
628 items.push_back( aItem.
Parent() );
631 std::sort( items.begin(), items.end() );
632 items.erase( std::unique( items.begin(), items.end() ), items.end() );
637const std::vector<PCB_TRACK*>
642 std::set<PCB_TRACK*> tracks;
643 std::vector<PCB_TRACK*> rv;
649 if( connected->Valid() &&
651 connected->Parent()->Type() ==
PCB_VIA_T ||
652 connected->Parent()->Type() ==
PCB_ARC_T ) )
654 tracks.insert(
static_cast<PCB_TRACK*
> ( connected->Parent() ) );
659 std::copy( tracks.begin(), tracks.end(), std::back_inserter( rv ) );
670 if( connected->Valid() && connected->Parent()->Type() ==
PCB_PAD_T )
671 pads->insert(
static_cast<PAD*
> ( connected->Parent() ) );
681 std::vector<PAD*> rv;
685 std::copy( pads.begin(), pads.end(), std::back_inserter( rv ) );
691 std::vector<PCB_VIA*>* vias )
697 if( connected->Valid() )
702 pads->push_back(
static_cast<PAD*
>( parent ) );
704 vias->push_back(
static_cast<PCB_VIA*
>( parent ) );
712 std::vector<std::set<const BOARD_ITEM*>>* aIslands )
720 if( !island || !island->
Valid() || island->
GetLayer() != aLayer )
723 std::set<const BOARD_ITEM*>& connected = aIslands->emplace_back();
728 connected.insert( other->Parent() );
741 sum += net->GetNodeCount();
743 else if( aNet < (
int)
m_nets.size() )
745 sum =
m_nets[aNet]->GetNodeCount();
761 PAD* dpad =
static_cast<PAD*
>(
pad->Parent() );
763 if( aNet < 0 || aNet == dpad->GetNetCode() )
777 for(
CN_EDGE& edge : rnNet->GetEdges() )
789 switch( aItem->
Type() )
813 wxFAIL_MSG( wxT(
"track not in connectivity system" ) );
817 CN_ITEM* citem = items.front();
819 if( !citem->
Valid() )
837 ZONE* zone =
dynamic_cast<ZONE*
>( item );
839 bool hitStart =
false;
864 if( hitStart && hitEnd )
874 if( aIgnoreTracksInPads )
892 if( start_count > 0 && end_count > 0 )
897 *aPos = (start_count == 0 ) ? aTrack->
GetStart() : aTrack->
GetEnd();
907 if( connected.empty() )
922 for(
CN_ITEM* item : connected )
928 first_layer = item->Layer();
929 else if( item->Layer() != first_layer )
940 wxFAIL_MSG( wxT(
"CONNECTIVITY_DATA::TestTrackEndpointDangling: unknown track type" ) );
947const std::vector<BOARD_CONNECTED_ITEM*>
949 const std::vector<KICAD_T>& aTypes,
const int& aMaxError )
const
952 std::vector<BOARD_CONNECTED_ITEM*> rv;
959 for(
const std::shared_ptr<CN_ANCHOR>&
anchor : connected->Anchors() )
961 if( (
anchor->Pos() - aAnchor ).SquaredEuclideanNorm() <= maxError_sq )
965 if( connected->Valid() && connected->Parent()->Type() == type )
967 rv.push_back( connected->Parent() );
984 if ( aNet < 0 || aNet >= (
int)
m_nets.size() )
1009 rnNet->RemoveInvalidRefs();
1020const std::vector<CN_EDGE>
1024 std::vector<CN_EDGE> edges;
1025 std::set<BOARD_CONNECTED_ITEM*> item_set;
1035 nets.insert(
pad->GetNetCode() );
1036 item_set.insert(
pad );
1039 else if( item->IsConnected() )
1043 item_set.insert( conn_item );
1048 for(
int netcode : nets )
1057 std::shared_ptr<const CN_ANCHOR> srcNode = edge.GetSourceNode();
1058 std::shared_ptr<const CN_ANCHOR> dstNode = edge.GetTargetNode();
1060 if( !srcNode || srcNode->Dirty() || !dstNode || dstNode->Dirty() )
1066 bool srcFound = ( item_set.find( srcParent ) != item_set.end() );
1067 bool dstFound = ( item_set.find( dstParent ) != item_set.end() );
1069 if ( srcFound && dstFound )
1070 edges.push_back( edge );
1080 std::vector<CN_EDGE> edges;
1088 if( !edge.GetSourceNode() || edge.GetSourceNode()->Dirty() )
1091 if( !edge.GetTargetNode() || edge.GetTargetNode()->Dirty() )
1094 if( edge.GetSourceNode()->Parent() == aPad || edge.GetTargetNode()->Parent() == aPad )
1095 edges.push_back( edge );
1103 bool aSkipInternalConnections )
1106 std::set<const PAD*> pads;
1107 std::vector<CN_EDGE> edges;
1111 nets.insert(
pad->GetNetCode() );
1115 for(
int netcode : nets )
1124 const std::shared_ptr<const CN_ANCHOR>& srcNode = edge.GetSourceNode();
1125 const std::shared_ptr<const CN_ANCHOR>& dstNode = edge.GetTargetNode();
1127 if( !srcNode || srcNode->Dirty() || !dstNode || dstNode->Dirty() )
1130 const PAD* srcParent =
static_cast<const PAD*
>( srcNode->Parent() );
1131 const PAD* dstParent =
static_cast<const PAD*
>( dstNode->Parent() );
1133 bool srcFound = ( pads.find(srcParent) != pads.end() );
1134 bool dstFound = ( pads.find(dstParent) != pads.end() );
1136 if ( srcFound && dstFound && !aSkipInternalConnections )
1137 edges.push_back( edge );
1138 else if ( srcFound || dstFound )
1139 edges.push_back( edge );
1149 if( std::shared_ptr<NET_SETTINGS> netSettings =
m_netSettings.lock() )
1150 return netSettings.get();
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
std::shared_ptr< NET_SETTINGS > m_NetSettings
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Information pertinent to a Pcbnew printed circuit board.
const NETINFO_LIST & GetNetInfo() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
DRC_RTREE * GetCopperZoneRTree(ZONE *aZone) const
Look up a zone's filled-copper R-tree.
void CacheTriangulation(PROGRESS_REPORTER *aReporter=nullptr, const std::vector< ZONE * > &aZones={})
CN_ANCHOR represents a physical location that can be connected: a pad or a track/arc/via endpoint.
const std::list< CN_ITEM * > & GetItems() const
ITEM_MAP_ENTRY & ItemEntry(const BOARD_CONNECTED_ITEM *aItem)
CN_EDGE represents a point-to-point connection, whether realized or unrealized (ie: tracks etc.
CN_ITEM represents a BOARD_CONNECTED_ITEM in the connectivity system (ie: a pad, track/arc/via,...
const std::vector< CN_ITEM * > & ConnectedItems() const
BOARD_CONNECTED_ITEM * Parent() const
Represents a single outline of a zone fill on a particular layer.
PCB_LAYER_ID GetLayer() const
void FillIsolatedIslandsMap(std::map< ZONE *, std::map< PCB_LAYER_ID, ISOLATED_ISLANDS > > &aMap, bool aConnectivityAlreadyRebuilt=false)
Fill the isolate islands list for each layer of each zone.
void RecalculateRatsnest(BOARD_COMMIT *aCommit=nullptr)
Update the ratsnest for the board.
void ClearLocalRatsnest()
Erase the temporary, selection-based ratsnest (i.e.
PROGRESS_REPORTER * m_progressReporter
unsigned int GetPadCount(int aNet=-1) const
void MarkItemNetAsDirty(BOARD_ITEM *aItem)
std::weak_ptr< NET_SETTINGS > m_netSettings
Used to get netclass data when drawing ratsnests.
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItems(const BOARD_CONNECTED_ITEM *aItem, int aFlags=0) const
void PropagateNets(BOARD_COMMIT *aCommit=nullptr)
Propagate the net codes from the source pads to the tracks/vias.
void RunOnUnconnectedEdges(std::function< bool(CN_EDGE &)> aFunc)
std::vector< RN_DYNAMIC_LINE > m_dynamicRatsnest
bool m_skipRatsnestUpdate
Used to suppress ratsnest calculations on dynamic ratsnests.
const std::vector< CN_EDGE > GetRatsnestForPad(const PAD *aPad)
RN_NET * GetRatsnestForNet(int aNet)
Return the ratsnest, expressed as a set of graph edges for a given net.
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItemsAtAnchor(const BOARD_CONNECTED_ITEM *aItem, const VECTOR2I &aAnchor, const std::vector< KICAD_T > &aTypes, const int &aMaxError=0) const
Return a list of items connected to a source item aItem at position aAnchor with an optional maximum ...
void ClearRatsnest()
Erases the connectivity database.
bool Remove(BOARD_ITEM *aItem)
Remove an item from the connectivity data.
void GetConnectedPadsAndVias(const BOARD_CONNECTED_ITEM *aItem, std::vector< PAD * > *pads, std::vector< PCB_VIA * > *vias)
const NET_SETTINGS * GetNetSettings() const
void ComputeLocalRatsnest(const std::vector< BOARD_ITEM * > &aItems, const CONNECTIVITY_DATA *aDynamicData, VECTOR2I aInternalOffset={ 0, 0 })
Calculate the temporary (usually selection-based) ratsnest for the set of aItems.
bool TestTrackEndpointDangling(PCB_TRACK *aTrack, bool aIgnoreTracksInPads, VECTOR2I *aPos=nullptr) const
unsigned int GetNodeCount(int aNet=-1) const
void SetProgressReporter(PROGRESS_REPORTER *aReporter)
void BlockRatsnestItems(const std::vector< BOARD_ITEM * > &aItems)
bool IsConnectedOnLayer(const BOARD_CONNECTED_ITEM *aItem, int aLayer, const std::initializer_list< KICAD_T > &aTypes={}) const
const std::vector< PCB_TRACK * > GetConnectedTracks(const BOARD_CONNECTED_ITEM *aItem) const
const std::vector< CN_EDGE > GetRatsnestForComponent(FOOTPRINT *aComponent, bool aSkipInternalConnections=false)
const std::vector< BOARD_CONNECTED_ITEM * > GetNetItems(int aNetCode, const std::vector< KICAD_T > &aTypes) const
Return the list of items that belong to a certain net.
bool Add(BOARD_ITEM *aItem)
Add an item to the connectivity data.
unsigned int GetUnconnectedCount(bool aVisibleOnly) const
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
bool Build(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Build the connectivity database for the board aBoard.
std::shared_ptr< FROM_TO_CACHE > m_fromToCache
const std::vector< PAD * > GetConnectedPads(const BOARD_CONNECTED_ITEM *aItem) const
std::map< int, wxString > m_netcodeMap
Used to map netcode to net name.
void internalRecalculateRatsnest(BOARD_COMMIT *aCommit=nullptr)
Update the ratsnest for the board without locking the connectivity mutex.
void RefreshNetcodeMap(BOARD *aBoard)
Refresh the map of netcodes to net names.
void HideLocalRatsnest()
Hide the temporary, selection-based ratsnest lines.
const std::vector< CN_EDGE > GetRatsnestForItems(const std::vector< BOARD_ITEM * > &aItems)
void addRatsnestCluster(const std::shared_ptr< CN_CLUSTER > &aCluster)
std::vector< RN_NET * > m_nets
bool Update(BOARD_ITEM *aItem)
Update the connectivity data for an item.
void Move(const VECTOR2I &aDelta)
Move the connectivity list anchors.
int GetNetCount() const
Return the total number of nets in the connectivity database.
void GetZoneIslandConnections(const ZONE *aZone, PCB_LAYER_ID aLayer, std::vector< std::set< const BOARD_ITEM * > > *aIslands)
Return, for each filled island of aZone on aLayer, the items that island touches.
std::shared_ptr< CN_CONNECTIVITY_ALGO > GetConnectivityAlgo() const
Implement an R-tree for fast spatial and layer indexing of connectable items.
int QueryColliding(BOARD_ITEM *aRefItem, PCB_LAYER_ID aRefLayer, PCB_LAYER_ID aTargetLayer, std::function< bool(BOARD_ITEM *)> aFilter=nullptr, std::function< bool(BOARD_ITEM *)> aVisitor=nullptr, int aClearance=0) const
This is a fast test which essentially does bounding-box overlap given a worst-case clearance.
virtual VECTOR2I GetPosition() const
KICAD_T Type() const
Returns the type of object.
EDA_ITEM_FLAGS GetFlags() const
Handle the data for a net.
NET_SETTINGS stores various net-related settings in a project context.
UNCONNECTED_LAYER_MODE UnconnectedLayerMode() const
const PADSTACK & Padstack() const
const VECTOR2I & GetStart() const
VECTOR2I GetPosition() const override
const VECTOR2I & GetEnd() const
virtual int GetWidth() const
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 KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).
Describe ratsnest for a single net.
unsigned int GetNodeCount() const
const std::vector< CN_EDGE > & GetEdges() const
bool NearestBicoloredPair(RN_NET *aOtherNet, VECTOR2I &aPos1, VECTOR2I &aPos2) const
void AddCluster(std::shared_ptr< CN_CLUSTER > aCluster)
VECTOR2I::extended_type ecoord
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const override
Check if point aP lies inside a closed shape.
const std::vector< VECTOR2I > & CPoints() const
Represent a set of closed polygons.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
Handle a list of polygons defining a copper zone.
SHAPE_POLY_SET * GetFill(PCB_LAYER_ID aLayer)
bool ItemsTouchOnLayer(const BOARD_CONNECTED_ITEM *aItemA, const BOARD_CONNECTED_ITEM *aItemB, PCB_LAYER_ID aLayer)
Test whether two items have copper in contact on aLayer.
static int getMinDist(BOARD_CONNECTED_ITEM *aItem, const VECTOR2I &aPoint)
#define IGNORE_NETS
Return a list of items connected to a source item aItem.
size_t CopperLayerToOrdinal(PCB_LAYER_ID aLayer)
Converts KiCad copper layer enum to an ordinal between the front and back layers.
PCB_LAYER_ID
A quick note on layer IDs:
PCB_LAYER_ID ToLAYER_ID(int aLayer)
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
@ REMOVE_EXCEPT_START_AND_END
Class that computes missing connections on a PCB.
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
BS::priority_thread_pool thread_pool
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ 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_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
VECTOR2< int32_t > VECTOR2I