32#include <initializer_list> 
   58                                      const std::vector<BOARD_ITEM*>& aLocalItems,
 
   59                                      bool aSkipRatsnestUpdate ) :
 
   62    Build( aGlobalConnectivity, aLocalItems );
 
 
  103    std::unique_lock<KISPINLOCK> lock( 
m_lock, std::try_to_lock );
 
  110        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    auto results = 
tp.submit_loop( 0, dirty_nets.size(),
 
  198                                dirty_nets[ii]->UpdateNet();
 
  202    auto results2 = 
tp.submit_loop( 0, dirty_nets.size(),
 
  205                                dirty_nets[ii]->OptimizeRNEdges();
 
 
  228    std::unique_lock<KISPINLOCK> lock( 
m_lock );
 
 
  240    if( lastNet >= (
int) 
m_nets.size() )
 
  242        unsigned int prevSize = 
m_nets.size();
 
  243        m_nets.resize( lastNet + 1 );
 
  245        for( 
unsigned int i = prevSize; i < 
m_nets.size(); i++ )
 
  250        for( 
size_t ii = lastNet; ii < 
m_nets.size(); ++ii )
 
  254    const std::vector<std::shared_ptr<CN_CLUSTER>>& clusters = 
m_connAlgo->GetClusters();
 
  256    for( 
int net = 0; net < lastNet; net++ )
 
  262    for( 
const std::shared_ptr<CN_CLUSTER>& c : clusters )
 
  264        int net = c->OriginNet();
 
  267        if( c->IsOrphaned() && c->Size() == 1 )
 
 
  286    std::vector<BOARD_CONNECTED_ITEM*> citems;
 
  293                citems.push_back( 
pad );
 
  298                citems.push_back( citem );
 
  310                for( 
const std::shared_ptr<CN_ANCHOR>& 
anchor : cnItem->Anchors() )
 
  311                    anchor->SetNoLine( 
true );
 
 
  325                                                bool aConnectivityAlreadyRebuilt )
 
  327    m_connAlgo->FillIsolatedIslandsMap( aMap, aConnectivityAlreadyRebuilt );
 
 
  339    std::mutex dynamic_ratsnest_mutex;
 
  344    auto update_lambda = [&]( 
int nc )
 
  363                std::lock_guard<std::mutex> lock( dynamic_ratsnest_mutex );
 
  370    size_t num_nets = std::min( 
m_nets.size(), aDynamicData->
m_nets.size() );
 
  372    auto results = 
tp.submit_loop( 1, num_nets,
 
  382    for( 
const CN_EDGE& edge : edges )
 
  384        const std::shared_ptr<const CN_ANCHOR>& nodeA = edge.GetSourceNode();
 
  385        const std::shared_ptr<const CN_ANCHOR>& nodeB = edge.GetTargetNode();
 
  387        if( !nodeA || nodeA->Dirty() || !nodeB || nodeB->Dirty() )
 
  393        l.
a = nodeA->Parent()->GetPosition() + aInternalOffset;
 
  394        l.
b = nodeB->Parent()->GetPosition() + aInternalOffset;
 
 
  405                                   anchor.SetNoLine( 
false );
 
 
  424                                            const std::initializer_list<KICAD_T>& aTypes )
 const 
  433                if( aTypes.size() == 0 )
 
  450                lyIdx = std::numeric_limits<int>::max();
 
  452            if( connected->Valid()
 
  453                    && connected->StartLayer() <= lyIdx && connected->EndLayer() >= lyIdx
 
  454                    && matchType( connected->Parent()->Type() )
 
  457                BOARD_ITEM* connectedItem = connected->Parent();
 
  459                if( connectedItem == aItem )
 
  462                if( parentFootprint && connectedItem
 
  471                    const PAD* thisPad = 
static_cast<const PAD*
>( aItem );
 
  472                    const PAD* otherPad = 
static_cast<const PAD*
>( connectedItem );
 
  489                    const PAD*    
pad = 
static_cast<const PAD*
>( aItem );
 
  531                            if( !viaHull.SHAPE::Collide( pt ) )
 
 
  550    unsigned int unconnected = 0;
 
  557        for( 
const CN_EDGE& edge : net->GetEdges() )
 
  559            if( edge.IsVisible() || !aVisibleOnly )
 
 
  575const std::vector<BOARD_CONNECTED_ITEM*>
 
  581    std::vector<BOARD_CONNECTED_ITEM*> rv;
 
  583    auto clusters = 
m_connAlgo->SearchClusters( ( aFlags & 
IGNORE_NETS ) ? CSM_PROPAGATE : CSM_CONNECTIVITY_CHECK,
 
  587    for( 
const std::shared_ptr<CN_CLUSTER>& cl : clusters )
 
  589        if( cl->Contains( aItem ) )
 
  591            for( 
const CN_ITEM* item : *cl )
 
  594                    rv.push_back( item->Parent() );
 
 
  603const std::vector<BOARD_CONNECTED_ITEM*>
 
  606    std::vector<BOARD_CONNECTED_ITEM*> items;
 
  609    std::bitset<MAX_STRUCT_TYPE_ID> type_bits;
 
  611    for( 
KICAD_T scanType : aTypes )
 
  614        type_bits.set( scanType );
 
  620                if( aItem.
Valid() && ( aItem.
Net() == aNetCode ) && type_bits[aItem.
Parent()->
Type()] )
 
  621                    items.push_back( aItem.
Parent() );
 
  624    std::sort( items.begin(), items.end() );
 
  625    items.erase( std::unique( items.begin(), items.end() ), items.end() );
 
 
  630const std::vector<PCB_TRACK*>
 
  635    std::set<PCB_TRACK*> tracks;
 
  636    std::vector<PCB_TRACK*> rv;
 
  642            if( connected->Valid() &&
 
  644                            connected->Parent()->Type() == 
PCB_VIA_T ||
 
  645                            connected->Parent()->Type() == 
PCB_ARC_T ) )
 
  647                tracks.insert( 
static_cast<PCB_TRACK*
> ( connected->Parent() ) );
 
  652    std::copy( tracks.begin(), tracks.end(), std::back_inserter( rv ) );
 
 
  663            if( connected->Valid() && connected->Parent()->Type() == 
PCB_PAD_T )
 
  664                pads->insert( 
static_cast<PAD*
> ( connected->Parent() ) );
 
 
  674    std::vector<PAD*> rv;
 
  678    std::copy( pads.begin(), pads.end(), std::back_inserter( rv ) );
 
 
  684                                                 std::vector<PCB_VIA*>* vias )
 
  690            if( connected->Valid() )
 
  695                    pads->push_back( 
static_cast<PAD*
>( parent ) );
 
  697                    vias->push_back( 
static_cast<PCB_VIA*
>( parent ) );
 
 
  711            sum += net->GetNodeCount();
 
  713    else if( aNet < (
int) 
m_nets.size() )
 
  715        sum = 
m_nets[aNet]->GetNodeCount();
 
 
  731        PAD* dpad = 
static_cast<PAD*
>( 
pad->Parent() );
 
  733        if( aNet < 0 || aNet == dpad->GetNetCode() )
 
 
  747            for( 
CN_EDGE& edge : rnNet->GetEdges() )
 
 
  759    switch( aItem->
Type() )
 
 
  783        wxFAIL_MSG( wxT( 
"track not in connectivity system" ) );
 
  787    CN_ITEM* citem = items.front();
 
  789    if( !citem->
Valid() )
 
  807            ZONE*                 zone = 
dynamic_cast<ZONE*
>( item );
 
  809            bool                  hitStart = 
false;
 
  834            if( hitStart && hitEnd )
 
  844                    if( aIgnoreTracksInPads )
 
  862            if( start_count > 0 && end_count > 0 )
 
  867            *aPos = (start_count == 0 ) ? aTrack->
GetStart() : aTrack->
GetEnd();
 
  877        if( connected.empty() )
 
  892        for( 
CN_ITEM* item : connected )
 
  898                first_layer = item->Layer();
 
  899            else if( item->Layer() != first_layer )
 
  910        wxFAIL_MSG( wxT( 
"CONNECTIVITY_DATA::TestTrackEndpointDangling: unknown track type" ) );
 
 
  917const std::vector<BOARD_CONNECTED_ITEM*>
 
  919                                              const std::vector<KICAD_T>& aTypes, 
const int& aMaxError )
 const 
  922    std::vector<BOARD_CONNECTED_ITEM*>    rv;
 
  929            for( 
const std::shared_ptr<CN_ANCHOR>& 
anchor : connected->Anchors() )
 
  931                if( ( 
anchor->Pos() - aAnchor ).SquaredEuclideanNorm() <= maxError_sq )
 
  935                        if( connected->Valid() && connected->Parent()->Type() == type )
 
  937                            rv.push_back( connected->Parent() );
 
 
  954    if ( aNet < 0 || aNet >= (
int) 
m_nets.size() )
 
 
  979        rnNet->RemoveInvalidRefs();
 
 
  990const std::vector<CN_EDGE>
 
  994    std::vector<CN_EDGE>            edges;
 
  995    std::set<BOARD_CONNECTED_ITEM*> item_set;
 
 1005                nets.insert( 
pad->GetNetCode() );
 
 1006                item_set.insert( 
pad );
 
 1009        else if( item->IsConnected() )
 
 1013            item_set.insert( conn_item );
 
 1018    for( 
int netcode : nets )
 
 1027            std::shared_ptr<const CN_ANCHOR> srcNode = edge.GetSourceNode();
 
 1028            std::shared_ptr<const CN_ANCHOR> dstNode = edge.GetTargetNode();
 
 1030            if( !srcNode || srcNode->Dirty() || !dstNode || dstNode->Dirty() )
 
 1036            bool srcFound = ( item_set.find( srcParent ) != item_set.end() );
 
 1037            bool dstFound = ( item_set.find( dstParent ) != item_set.end() );
 
 1039            if ( srcFound && dstFound )
 
 1040                edges.push_back( edge );
 
 
 1050    std::vector<CN_EDGE> edges;
 
 1058        if( !edge.GetSourceNode() || edge.GetSourceNode()->Dirty() )
 
 1061        if( !edge.GetTargetNode() || edge.GetTargetNode()->Dirty() )
 
 1064        if( edge.GetSourceNode()->Parent() == aPad || edge.GetTargetNode()->Parent() == aPad )
 
 1065            edges.push_back( edge );
 
 
 1073                                                                       bool aSkipInternalConnections )
 
 1076    std::set<const PAD*> pads;
 
 1077    std::vector<CN_EDGE> edges;
 
 1081        nets.insert( 
pad->GetNetCode() );
 
 1085    for( 
int netcode : nets )
 
 1094            const std::shared_ptr<const CN_ANCHOR>& srcNode = edge.GetSourceNode();
 
 1095            const std::shared_ptr<const CN_ANCHOR>& dstNode = edge.GetTargetNode();
 
 1097            if( !srcNode || srcNode->Dirty() || !dstNode || dstNode->Dirty() )
 
 1100            const PAD* srcParent = 
static_cast<const PAD*
>( srcNode->Parent() );
 
 1101            const PAD* dstParent = 
static_cast<const PAD*
>( dstNode->Parent() );
 
 1103            bool srcFound = ( pads.find(srcParent) != pads.end() );
 
 1104            bool dstFound = ( pads.find(dstParent) != pads.end() );
 
 1106            if ( srcFound && dstFound && !aSkipInternalConnections )
 
 1107                edges.push_back( edge );
 
 1108            else if ( srcFound || dstFound )
 
 1109                edges.push_back( edge );
 
 
 1119    if( std::shared_ptr<NET_SETTINGS> netSettings = 
m_netSettings.lock() )
 
 1120        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.
 
FOOTPRINT * GetParentFootprint() const
 
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
 
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_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.
 
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItems(const BOARD_CONNECTED_ITEM *aItem, int aFlags=0) const
 
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.
 
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.
 
UNCONNECTED_LAYER_MODE UnconnectedLayerMode() const
 
UNCONNECTED_LAYER_MODE
! Whether or not to remove the copper shape for unconnected layers
 
@ REMOVE_EXCEPT_START_AND_END
 
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.
 
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)
 
#define IGNORE_NETS
Function GetConnectedItems() Returns a list of items connected to a source item aItem.
 
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.
 
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
 
BS::thread_pool< 0 > 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