32#include <initializer_list>
56 : m_skipRatsnest( aSkipRatsnest )
99 std::unique_lock<KISPINLOCK> lock(
m_lock, std::try_to_lock );
106 aReporter->
Report(
_(
"Updating nets..." ) );
119 net->SetNetClass( netSettings->GetEffectiveNetClass( net->GetNetname() ) );
122 m_netclassMap[ net->GetNetCode() ] = net->GetNetClass()->GetName();
145 std::unique_lock<KISPINLOCK> lock(
m_lock, std::try_to_lock );
172 std::vector<RN_NET*> dirty_nets;
176 std::copy_if(
m_nets.begin() + 1,
m_nets.end(), std::back_inserter( dirty_nets ),
179 return aNet->IsDirty() && aNet->GetNodeCount() > 0;
184 tp.push_loop( dirty_nets.size(),
185 [&](
const int a,
const int b )
187 for( int ii = a; ii < b; ++ii )
188 dirty_nets[ii]->UpdateNet();
192 tp.push_loop( dirty_nets.size(),
193 [&](
const int a,
const int b )
195 for( int ii = a; ii < b; ++ii )
196 dirty_nets[ii]->OptimizeRNEdges();
219 std::unique_lock<KISPINLOCK> lock(
m_lock );
231 if( lastNet >= (
int)
m_nets.size() )
233 unsigned int prevSize =
m_nets.size();
234 m_nets.resize( lastNet + 1 );
236 for(
unsigned int i = prevSize; i <
m_nets.size(); i++ )
241 for(
size_t ii = lastNet; ii <
m_nets.size(); ++ii )
245 const std::vector<std::shared_ptr<CN_CLUSTER>>& clusters =
m_connAlgo->GetClusters();
249 for(
int net = 0; net < lastNet; net++ )
258 for(
const std::shared_ptr<CN_CLUSTER>& c : clusters )
260 int net = c->OriginNet();
263 if( c->IsOrphaned() && c->Size() == 1 )
282 std::vector<BOARD_CONNECTED_ITEM*> citems;
289 citems.push_back(
pad );
294 citems.push_back( citem );
306 for(
const std::shared_ptr<CN_ANCHOR>&
anchor : cnItem->Anchors() )
307 anchor->SetNoLine(
true );
321 bool aConnectivityAlreadyRebuilt )
323 m_connAlgo->FillIsolatedIslandsMap( aMap, aConnectivityAlreadyRebuilt );
335 std::mutex dynamic_ratsnest_mutex;
340 auto update_lambda = [&](
int nc )
360 std::lock_guard<std::mutex> lock( dynamic_ratsnest_mutex );
367 size_t num_nets = std::min(
m_nets.size(), aDynamicData->
m_nets.size() );
369 tp.push_loop( 1, num_nets,
370 [&](
const int a,
const int b)
372 for(
int ii = a; ii < b; ++ii )
380 for(
const CN_EDGE& edge : edges )
382 const std::shared_ptr<const CN_ANCHOR>& nodeA = edge.GetSourceNode();
383 const std::shared_ptr<const CN_ANCHOR>& nodeB = edge.GetTargetNode();
387 l.
a = nodeA->Parent()->GetPosition() + aInternalOffset;
388 l.
b = nodeB->Parent()->GetPosition() + aInternalOffset;
399 anchor.SetNoLine(
false );
418 const std::initializer_list<KICAD_T>& aTypes )
const
425 if( aTypes.size() == 0 )
437 if( connected->Valid()
438 && connected->Layers().Overlaps( aLayer )
439 && matchType( connected->Parent()->Type() )
444 const PAD*
pad =
static_cast<const PAD*
>( aItem );
483 if( !viaHull.SHAPE::Collide( pt ) )
502 unsigned int unconnected = 0;
509 for(
const CN_EDGE& edge : net->GetEdges() )
511 if( edge.IsVisible() || !aVisibleOnly )
527const std::vector<BOARD_CONNECTED_ITEM*>
529 const std::initializer_list<KICAD_T>& aTypes,
530 bool aIgnoreNetcodes )
const
532 std::vector<BOARD_CONNECTED_ITEM*> rv;
535 if( aIgnoreNetcodes )
540 const auto clusters =
m_connAlgo->SearchClusters( searchMode, aTypes,
543 for(
const std::shared_ptr<CN_CLUSTER>& cl : clusters )
545 if( cl->Contains( aItem ) )
547 for(
const CN_ITEM* item : *cl )
550 rv.push_back( item->Parent() );
559const std::vector<BOARD_CONNECTED_ITEM*>
562 std::vector<BOARD_CONNECTED_ITEM*> items;
565 std::bitset<MAX_STRUCT_TYPE_ID> type_bits;
567 for(
KICAD_T scanType : aTypes )
570 type_bits.set( scanType );
576 if( aItem.
Valid() && ( aItem.
Net() == aNetCode ) && type_bits[aItem.
Parent()->
Type()] )
577 items.push_back( aItem.
Parent() );
580 std::sort( items.begin(), items.end() );
581 items.erase( std::unique( items.begin(), items.end() ), items.end() );
586const std::vector<PCB_TRACK*>
591 std::set<PCB_TRACK*> tracks;
592 std::vector<PCB_TRACK*> rv;
598 if( connected->Valid() &&
600 connected->Parent()->Type() ==
PCB_VIA_T ||
601 connected->Parent()->Type() ==
PCB_ARC_T ) )
603 tracks.insert(
static_cast<PCB_TRACK*
> ( connected->Parent() ) );
608 std::copy( tracks.begin(), tracks.end(), std::back_inserter( rv ) );
614 std::set<PAD*>* pads )
const
620 if( connected->Valid() && connected->Parent()->Type() ==
PCB_PAD_T )
621 pads->insert(
static_cast<PAD*
> ( connected->Parent() ) );
631 std::vector<PAD*> rv;
635 std::copy( pads.begin(), pads.end(), std::back_inserter( rv ) );
641 std::vector<PAD*>* pads,
642 std::vector<PCB_VIA*>* vias )
648 if( connected->Valid() )
653 pads->push_back(
static_cast<PAD*
>( parent ) );
655 vias->push_back(
static_cast<PCB_VIA*
>( parent ) );
669 sum += net->GetNodeCount();
671 else if( aNet < (
int)
m_nets.size() )
673 sum =
m_nets[aNet]->GetNodeCount();
689 PAD* dpad =
static_cast<PAD*
>(
pad->Parent() );
691 if( aNet < 0 || aNet == dpad->GetNetCode() )
705 for(
CN_EDGE& edge : rnNet->GetEdges() )
717 switch( aItem->
Type() )
742 wxFAIL_MSG( wxT(
"track not in connectivity system" ) );
746 CN_ITEM* citem = items.front();
748 if( !citem->
Valid() )
766 ZONE* zone =
dynamic_cast<ZONE*
>( item );
768 bool hitStart =
false;
789 hitStart = shape->Collide( aTrack->
GetStart(), accuracy );
790 hitEnd = shape->Collide( aTrack->
GetEnd(), accuracy );
793 if( hitStart && hitEnd )
803 if( aIgnoreTracksInPads )
821 if( start_count > 0 && end_count > 0 )
826 *aPos = (start_count == 0 ) ? aTrack->
GetStart() : aTrack->
GetEnd();
836 if( connected.empty() )
847 for(
CN_ITEM* item : connected )
853 first_layer = item->Layer();
854 else if( item->Layer() != first_layer )
865 wxFAIL_MSG( wxT(
"CONNECTIVITY_DATA::TestTrackEndpointDangling: unknown track type" ) );
872const std::vector<BOARD_CONNECTED_ITEM*>
875 const std::initializer_list<KICAD_T>& aTypes,
876 const int& aMaxError )
const
879 std::vector<BOARD_CONNECTED_ITEM*> rv;
886 for(
const std::shared_ptr<CN_ANCHOR>&
anchor : connected->Anchors() )
888 if( (
anchor->Pos() - aAnchor ).SquaredEuclideanNorm() <= maxError_sq )
892 if( connected->Valid() && connected->Parent()->Type() == type )
894 rv.push_back( connected->Parent() );
911 if ( aNet < 0 || aNet >= (
int)
m_nets.size() )
938const std::vector<CN_EDGE>
942 std::vector<CN_EDGE> edges;
943 std::set<BOARD_CONNECTED_ITEM*> item_set;
953 nets.insert(
pad->GetNetCode() );
954 item_set.insert(
pad );
957 else if( item->IsConnected() )
961 item_set.insert( conn_item );
966 for(
int netcode : nets )
975 std::shared_ptr<const CN_ANCHOR> srcNode = edge.GetSourceNode();
976 std::shared_ptr<const CN_ANCHOR> dstNode = edge.GetTargetNode();
981 bool srcFound = ( item_set.find( srcParent ) != item_set.end() );
982 bool dstFound = ( item_set.find( dstParent ) != item_set.end() );
984 if ( srcFound && dstFound )
985 edges.push_back( edge );
995 std::vector<CN_EDGE> edges;
1003 if( edge.GetSourceNode()->Parent() == aPad || edge.GetTargetNode()->Parent() == aPad )
1004 edges.push_back( edge );
1012 bool aSkipInternalConnections )
1015 std::set<const PAD*> pads;
1016 std::vector<CN_EDGE> edges;
1020 nets.insert(
pad->GetNetCode() );
1024 for(
int netcode : nets )
1033 const std::shared_ptr<const CN_ANCHOR>& srcNode = edge.GetSourceNode();
1034 const std::shared_ptr<const CN_ANCHOR>& dstNode = edge.GetTargetNode();
1036 const PAD* srcParent =
static_cast<const PAD*
>( srcNode->Parent() );
1037 const PAD* dstParent =
static_cast<const PAD*
>( dstNode->Parent() );
1039 bool srcFound = ( pads.find(srcParent) != pads.end() );
1040 bool dstFound = ( pads.find(dstParent) != pads.end() );
1042 if ( srcFound && dstFound && !aSkipInternalConnections )
1043 edges.push_back( edge );
1044 else if ( srcFound || dstFound )
1045 edges.push_back( edge );
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
bool m_skipRatsnest
Used to suppress ratsnest calculations on dynamic ratsnests.
unsigned int GetPadCount(int aNet=-1) const
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItemsAtAnchor(const BOARD_CONNECTED_ITEM *aItem, const VECTOR2I &aAnchor, const std::initializer_list< KICAD_T > &aTypes, const int &aMaxError=0) const
Function GetConnectedItemsAtAnchor() Returns a list of items connected to a source item aItem at posi...
void MarkItemNetAsDirty(BOARD_ITEM *aItem)
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
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.
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)
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
std::map< int, wxString > m_netclassMap
Map of netcode -> netclass the net is a member of; used for ratsnest painting.
const std::vector< CN_EDGE > GetRatsnestForComponent(FOOTPRINT *aComponent, bool aSkipInternalConnections=false)
bool Add(BOARD_ITEM *aItem)
Function Add() Adds an item to the connectivity data.
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItems(const BOARD_CONNECTED_ITEM *aItem, const std::initializer_list< KICAD_T > &aTypes, bool aIgnoreNetcodes=false) const
Function GetConnectedItems() Returns a list of items connected to a source item aItem.
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.
std::shared_ptr< FROM_TO_CACHE > m_fromToCache
const std::vector< PAD * > GetConnectedPads(const BOARD_CONNECTED_ITEM *aItem) const
const std::vector< BOARD_CONNECTED_ITEM * > GetNetItems(int aNetCode, const std::initializer_list< KICAD_T > &aTypes) const
Function GetNetItems() Returns the list of items that belong to a certain net.
unsigned int GetUnconnectedCount(bool aVisibileOnly) const
void internalRecalculateRatsnest(BOARD_COMMIT *aCommit=nullptr)
Updates the ratsnest for the board without locking the connectivity mutex.
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
static const char Default[]
the name of the default NETCLASS
Handle the data for a net.
const VECTOR2I & GetStart() const
VECTOR2I GetPosition() const override
const VECTOR2I & GetEnd() 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
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.
double GetLineLength(const VECTOR2I &aPointA, const VECTOR2I &aPointB)
Return the length of a line segment defined by aPointA and aPointB.
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)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".