32#include <initializer_list>
48 m_skipRatsnestUpdate( false )
57 const std::vector<BOARD_ITEM*>& aLocalItems,
58 bool aSkipRatsnestUpdate ) :
59 m_skipRatsnestUpdate( aSkipRatsnestUpdate )
61 Build( aGlobalConnectivity, aLocalItems );
102 std::unique_lock<KISPINLOCK> lock(
m_lock, std::try_to_lock );
109 aReporter->
Report(
_(
"Updating nets..." ) );
154 const std::vector<BOARD_ITEM*>& aLocalItems )
156 std::unique_lock<KISPINLOCK> lock(
m_lock, std::try_to_lock );
162 m_connAlgo->LocalBuild( aGlobalConnectivity, aLocalItems );
183 std::vector<RN_NET*> dirty_nets;
187 std::copy_if(
m_nets.begin() + 1,
m_nets.end(), std::back_inserter( dirty_nets ),
190 return aNet->IsDirty() && aNet->GetNodeCount() > 0;
195 tp.push_loop( dirty_nets.size(),
196 [&](
const int a,
const int b )
198 for( int ii = a; ii < b; ++ii )
199 dirty_nets[ii]->UpdateNet();
203 tp.push_loop( dirty_nets.size(),
204 [&](
const int a,
const int b )
206 for( int ii = a; ii < b; ++ii )
207 dirty_nets[ii]->OptimizeRNEdges();
230 std::unique_lock<KISPINLOCK> lock(
m_lock );
242 if( lastNet >= (
int)
m_nets.size() )
244 unsigned int prevSize =
m_nets.size();
245 m_nets.resize( lastNet + 1 );
247 for(
unsigned int i = prevSize; i <
m_nets.size(); i++ )
252 for(
size_t ii = lastNet; ii <
m_nets.size(); ++ii )
256 const std::vector<std::shared_ptr<CN_CLUSTER>>& clusters =
m_connAlgo->GetClusters();
258 for(
int net = 0; net < lastNet; net++ )
266 for(
const std::shared_ptr<CN_CLUSTER>& c : clusters )
268 int net = c->OriginNet();
271 if( c->IsOrphaned() && c->Size() == 1 )
290 std::vector<BOARD_CONNECTED_ITEM*> citems;
297 citems.push_back(
pad );
302 citems.push_back( citem );
314 for(
const std::shared_ptr<CN_ANCHOR>&
anchor : cnItem->Anchors() )
315 anchor->SetNoLine(
true );
329 bool aConnectivityAlreadyRebuilt )
331 m_connAlgo->FillIsolatedIslandsMap( aMap, aConnectivityAlreadyRebuilt );
343 std::mutex dynamic_ratsnest_mutex;
348 auto update_lambda = [&](
int nc )
368 std::lock_guard<std::mutex> lock( dynamic_ratsnest_mutex );
375 size_t num_nets = std::min(
m_nets.size(), aDynamicData->
m_nets.size() );
377 tp.push_loop( 1, num_nets,
378 [&](
const int a,
const int b)
380 for(
int ii = a; ii < b; ++ii )
388 for(
const CN_EDGE& edge : edges )
390 const std::shared_ptr<const CN_ANCHOR>& nodeA = edge.GetSourceNode();
391 const std::shared_ptr<const CN_ANCHOR>& nodeB = edge.GetTargetNode();
393 if( !nodeA || nodeA->Dirty() || !nodeB || nodeB->Dirty() )
399 l.
a = nodeA->Parent()->GetPosition() + aInternalOffset;
400 l.
b = nodeB->Parent()->GetPosition() + aInternalOffset;
411 anchor.SetNoLine(
false );
430 const std::initializer_list<KICAD_T>& aTypes )
const
437 if( aTypes.size() == 0 )
454 lyIdx = std::numeric_limits<int>::max();
456 if( connected->Valid()
457 && connected->StartLayer() <= lyIdx && connected->EndLayer() >= lyIdx
458 && matchType( connected->Parent()->Type() )
463 const PAD*
pad =
static_cast<const PAD*
>( aItem );
505 if( !viaHull.SHAPE::Collide( pt ) )
524 unsigned int unconnected = 0;
531 for(
const CN_EDGE& edge : net->GetEdges() )
533 if( edge.IsVisible() || !aVisibleOnly )
549const std::vector<BOARD_CONNECTED_ITEM*>
551 const std::vector<KICAD_T>& aTypes,
552 bool aIgnoreNetcodes )
const
554 std::vector<BOARD_CONNECTED_ITEM*> rv;
557 if( aIgnoreNetcodes )
562 const auto clusters =
m_connAlgo->SearchClusters( searchMode, aTypes,
565 for(
const std::shared_ptr<CN_CLUSTER>& cl : clusters )
567 if( cl->Contains( aItem ) )
569 for(
const CN_ITEM* item : *cl )
572 rv.push_back( item->Parent() );
581const std::vector<BOARD_CONNECTED_ITEM*>
584 std::vector<BOARD_CONNECTED_ITEM*> items;
587 std::bitset<MAX_STRUCT_TYPE_ID> type_bits;
589 for(
KICAD_T scanType : aTypes )
592 type_bits.set( scanType );
598 if( aItem.
Valid() && ( aItem.
Net() == aNetCode ) && type_bits[aItem.
Parent()->
Type()] )
599 items.push_back( aItem.
Parent() );
602 std::sort( items.begin(), items.end() );
603 items.erase( std::unique( items.begin(), items.end() ), items.end() );
608const std::vector<PCB_TRACK*>
613 std::set<PCB_TRACK*> tracks;
614 std::vector<PCB_TRACK*> rv;
620 if( connected->Valid() &&
622 connected->Parent()->Type() ==
PCB_VIA_T ||
623 connected->Parent()->Type() ==
PCB_ARC_T ) )
625 tracks.insert(
static_cast<PCB_TRACK*
> ( connected->Parent() ) );
630 std::copy( tracks.begin(), tracks.end(), std::back_inserter( rv ) );
636 std::set<PAD*>* pads )
const
642 if( connected->Valid() && connected->Parent()->Type() ==
PCB_PAD_T )
643 pads->insert(
static_cast<PAD*
> ( connected->Parent() ) );
653 std::vector<PAD*> rv;
657 std::copy( pads.begin(), pads.end(), std::back_inserter( rv ) );
663 std::vector<PAD*>* pads,
664 std::vector<PCB_VIA*>* vias )
670 if( connected->Valid() )
675 pads->push_back(
static_cast<PAD*
>( parent ) );
677 vias->push_back(
static_cast<PCB_VIA*
>( parent ) );
691 sum += net->GetNodeCount();
693 else if( aNet < (
int)
m_nets.size() )
695 sum =
m_nets[aNet]->GetNodeCount();
711 PAD* dpad =
static_cast<PAD*
>(
pad->Parent() );
713 if( aNet < 0 || aNet == dpad->GetNetCode() )
727 for(
CN_EDGE& edge : rnNet->GetEdges() )
739 switch( aItem->
Type() )
764 wxFAIL_MSG( wxT(
"track not in connectivity system" ) );
768 CN_ITEM* citem = items.front();
770 if( !citem->
Valid() )
788 ZONE* zone =
dynamic_cast<ZONE*
>( item );
790 bool hitStart =
false;
811 hitStart = shape->Collide( aTrack->
GetStart(), accuracy );
812 hitEnd = shape->Collide( aTrack->
GetEnd(), accuracy );
815 if( hitStart && hitEnd )
825 if( aIgnoreTracksInPads )
843 if( start_count > 0 && end_count > 0 )
848 *aPos = (start_count == 0 ) ? aTrack->
GetStart() : aTrack->
GetEnd();
858 if( connected.empty() )
869 for(
CN_ITEM* item : connected )
875 first_layer = item->Layer();
876 else if( item->Layer() != first_layer )
887 wxFAIL_MSG( wxT(
"CONNECTIVITY_DATA::TestTrackEndpointDangling: unknown track type" ) );
894const std::vector<BOARD_CONNECTED_ITEM*>
897 const std::vector<KICAD_T>& aTypes,
898 const int& aMaxError )
const
901 std::vector<BOARD_CONNECTED_ITEM*> rv;
908 for(
const std::shared_ptr<CN_ANCHOR>&
anchor : connected->Anchors() )
910 if( (
anchor->Pos() - aAnchor ).SquaredEuclideanNorm() <= maxError_sq )
914 if( connected->Valid() && connected->Parent()->Type() == type )
916 rv.push_back( connected->Parent() );
933 if ( aNet < 0 || aNet >= (
int)
m_nets.size() )
958 rnNet->RemoveInvalidRefs();
969const std::vector<CN_EDGE>
973 std::vector<CN_EDGE> edges;
974 std::set<BOARD_CONNECTED_ITEM*> item_set;
984 nets.insert(
pad->GetNetCode() );
985 item_set.insert(
pad );
988 else if( item->IsConnected() )
992 item_set.insert( conn_item );
997 for(
int netcode : nets )
1006 std::shared_ptr<const CN_ANCHOR> srcNode = edge.GetSourceNode();
1007 std::shared_ptr<const CN_ANCHOR> dstNode = edge.GetTargetNode();
1009 if( !srcNode || srcNode->Dirty() || !dstNode || dstNode->Dirty() )
1015 bool srcFound = ( item_set.find( srcParent ) != item_set.end() );
1016 bool dstFound = ( item_set.find( dstParent ) != item_set.end() );
1018 if ( srcFound && dstFound )
1019 edges.push_back( edge );
1029 std::vector<CN_EDGE> edges;
1037 if( !edge.GetSourceNode() || edge.GetSourceNode()->Dirty() )
1040 if( !edge.GetTargetNode() || edge.GetTargetNode()->Dirty() )
1043 if( edge.GetSourceNode()->Parent() == aPad || edge.GetTargetNode()->Parent() == aPad )
1044 edges.push_back( edge );
1052 bool aSkipInternalConnections )
1055 std::set<const PAD*> pads;
1056 std::vector<CN_EDGE> edges;
1060 nets.insert(
pad->GetNetCode() );
1064 for(
int netcode : nets )
1073 const std::shared_ptr<const CN_ANCHOR>& srcNode = edge.GetSourceNode();
1074 const std::shared_ptr<const CN_ANCHOR>& dstNode = edge.GetTargetNode();
1076 if( !srcNode || srcNode->Dirty() || !dstNode || dstNode->Dirty() )
1079 const PAD* srcParent =
static_cast<const PAD*
>( srcNode->Parent() );
1080 const PAD* dstParent =
static_cast<const PAD*
>( dstNode->Parent() );
1082 bool srcFound = ( pads.find(srcParent) != pads.end() );
1083 bool dstFound = ( pads.find(dstParent) != pads.end() );
1085 if ( srcFound && dstFound && !aSkipInternalConnections )
1086 edges.push_back( edge );
1087 else if ( srcFound || dstFound )
1088 edges.push_back( edge );
1098 if( std::shared_ptr<NET_SETTINGS> netSettings =
m_netSettings.lock() )
1099 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,...
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 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 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.
Information pertinent to a Pcbnew printed circuit board.
const NETINFO_LIST & GetNetInfo() const
std::unordered_map< ZONE *, std::unique_ptr< DRC_RTREE > > m_CopperZoneRTreeCache
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
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
CN_EDGE represents a point-to-point connection, whether realized or unrealized (ie: tracks etc.
CN_ITEM represents a BOARD_CONNETED_ITEM in the connectivity system (ie: a pad, track/arc/via,...
const std::vector< CN_ITEM * > & ConnectedItems() const
BOARD_CONNECTED_ITEM * Parent() 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)
Function RecalculateRatsnest() Updates the ratsnest for the board.
void ClearLocalRatsnest()
Function ClearLocalRatsnest() Erases 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.
void PropagateNets(BOARD_COMMIT *aCommit=nullptr)
Propagates 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)
Function GetRatsnestForNet() Returns 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
Function GetConnectedItemsAtAnchor() Returns a list of items connected to a source item aItem at posi...
void ClearRatsnest()
Function Clear() Erases the connectivity database.
bool Remove(BOARD_ITEM *aItem)
Function Remove() Removes 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 })
Function ComputeLocalRatsnest() Calculates the temporary (usually selection-based) ratsnest for the s...
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
Function GetNetItems() Returns the list of items that belong to a certain net.
bool Add(BOARD_ITEM *aItem)
Function Add() Adds an item to the connectivity data.
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
bool Build(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Function Build() Builds the connectivity database for the board aBoard.
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItems(const BOARD_CONNECTED_ITEM *aItem, const std::vector< KICAD_T > &aTypes, bool aIgnoreNetcodes=false) const
Function GetConnectedItems() Returns a list of items connected to a source item aItem.
std::shared_ptr< FROM_TO_CACHE > m_fromToCache
const std::vector< PAD * > GetConnectedPads(const BOARD_CONNECTED_ITEM *aItem) const
unsigned int GetUnconnectedCount(bool aVisibileOnly) const
std::map< int, wxString > m_netcodeMap
Used to map netcode to net name.
void internalRecalculateRatsnest(BOARD_COMMIT *aCommit=nullptr)
Updates the ratsnest for the board without locking the connectivity mutex.
void RefreshNetcodeMap(BOARD *aBoard)
Refresh the map of netcodes to net names.
void HideLocalRatsnest()
Hides 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)
Function Update() Updates the connectivity data for an item.
void Move(const VECTOR2I &aDelta)
Moves the connectivity list anchors.
int GetNetCount() const
Function GetNetCount() Returns the total number of nets in the connectivity database.
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.
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.
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const override
Check if point aP lies inside a closed shape.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
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)
static int getMinDist(BOARD_CONNECTED_ITEM *aItem, const VECTOR2I &aPoint)
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.
Class that computes missing connections on a PCB.
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_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)