49 : m_skipRatsnest( aSkipRatsnest )
94 m_netclassMap[ net->GetNetCode() ] = net->GetNetClass()->GetName();
113 anchor.
Move( aDelta );
123 std::vector<RN_NET*> dirty_nets;
127 std::copy_if(
m_nets.begin() + 1,
m_nets.end(), std::back_inserter( dirty_nets ),
128 [] (
RN_NET* aNet ) {
return aNet->IsDirty() && aNet->GetNodeCount() > 0; } );
131 size_t parallelThreadCount = std::min<size_t>( std::thread::hardware_concurrency(),
132 ( dirty_nets.size() + 7 ) / 8 );
134 std::atomic<size_t> nextNet( 0 );
135 std::vector<std::future<size_t>> returns( parallelThreadCount );
137 auto update_lambda = [&nextNet, &dirty_nets]() ->
size_t 139 for(
size_t i = nextNet++; i < dirty_nets.size(); i = nextNet++ )
145 if( parallelThreadCount == 1 )
149 for(
size_t ii = 0; ii < parallelThreadCount; ++ii )
150 returns[ii] = std::async( std::launch::async, update_lambda );
153 for(
size_t ii = 0; ii < parallelThreadCount; ++ii )
165 auto rnNet =
m_nets[ aCluster->OriginNet() ];
167 rnNet->AddCluster( aCluster );
177 if( lastNet >= (
int)
m_nets.size() )
179 unsigned int prevSize =
m_nets.size();
180 m_nets.resize( lastNet + 1 );
182 for(
unsigned int i = prevSize; i <
m_nets.size(); i++ )
190 for(
int net = 0; net < lastNet; net++ )
199 for(
const auto& c : clusters )
201 int net = c->OriginNet();
204 if( c->IsOrphaned() && c->Size() == 1 )
206 if( dynamic_cast<CN_ZONE_LAYER*>( *c->begin() ) )
225 std::vector<BOARD_CONNECTED_ITEM*> citems;
227 for(
auto item : aItems )
231 for(
PAD* pad : static_cast<FOOTPRINT*>(item)->Pads() )
232 citems.push_back( pad );
236 if(
auto citem = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
237 citems.push_back( citem );
241 for(
const auto& item : citems )
247 for(
const auto& cnItem : entry.GetItems() )
249 for(
auto anchor : cnItem->Anchors() )
250 anchor->SetNoLine(
true );
267 m_connAlgo->FindIsolatedCopperIslands( aZone, aIslands );
273 m_connAlgo->FindIsolatedCopperIslands( aZones );
287 for(
unsigned int nc = 1; nc < aDynamicData->
m_nets.size(); nc++ )
289 auto dynNet = aDynamicData->
m_nets[nc];
291 if( dynNet->GetNodeCount() != 0 )
296 if( ourNet->NearestBicoloredPair( *dynNet, nodeA, nodeB ) )
311 for(
const auto& edge : edges )
313 const auto& nodeA = edge.GetSourceNode();
314 const auto& nodeB = edge.GetTargetNode();
318 l.
a = nodeA->Parent()->GetPosition();
319 l.
b = nodeB->Parent()->GetPosition();
348 std::vector<KICAD_T> aTypes )
const 352 auto matchType = [&](
KICAD_T aItemType )
357 return std::count( aTypes.begin(), aTypes.end(), aItemType ) > 0;
364 if( connected->Valid()
365 && connected->Layers().Overlaps( aLayer )
367 && matchType( connected->Parent()->Type() ) )
380 unsigned int unconnected = 0;
387 const auto& edges = net->GetUnconnected();
392 unconnected += edges.size();
411 bool aIgnoreNetcodes )
const 413 std::vector<BOARD_CONNECTED_ITEM*> rv;
414 const auto clusters =
m_connAlgo->SearchClusters(
420 for(
auto cl : clusters )
422 if( cl->Contains( aItem ) )
424 for(
const auto item : *cl )
427 rv.push_back( item->Parent() );
439 std::vector<BOARD_CONNECTED_ITEM*> items;
442 std::bitset<MAX_STRUCT_TYPE_ID> type_bits;
444 for(
unsigned int i = 0; aTypes[i] !=
EOT; ++i )
447 type_bits.set( aTypes[i] );
451 if( aItem.
Valid() && ( aItem.
Net() == aNetCode ) && type_bits[aItem.
Parent()->
Type()] )
452 items.push_back( aItem.
Parent() );
455 std::sort( items.begin(), items.end() );
456 items.erase( std::unique( items.begin(), items.end() ), items.end() );
469 for(
const auto& edge : net->GetEdges() )
472 ent.
net = edge.GetSourceNode()->Parent()->GetNetCode();
473 ent.
a = edge.GetSourceNode()->Parent();
474 ent.
b = edge.GetTargetNode()->Parent();
475 ent.
anchorA = edge.GetSourceNode()->Pos();
476 ent.
anchorB = edge.GetTargetNode()->Pos();
477 aReport.push_back( ent );
482 return aReport.empty();
491 std::set<TRACK*> tracks;
492 std::vector<TRACK*> rv;
494 for(
auto citem : entry.GetItems() )
496 for(
auto connected : citem->ConnectedItems() )
498 if( connected->Valid() &&
500 connected->Parent()->Type() ==
PCB_VIA_T ||
501 connected->Parent()->Type() ==
PCB_ARC_T ) )
502 tracks.insert( static_cast<TRACK*> ( connected->Parent() ) );
506 std::copy( tracks.begin(), tracks.end(), std::back_inserter( rv ) );
512 std::set<PAD*>* pads )
const 518 if( connected->Valid() && connected->Parent()->Type() ==
PCB_PAD_T )
519 pads->insert( static_cast<PAD*> ( connected->Parent() ) );
529 std::vector<PAD*> rv;
533 std::copy( pads.begin(), pads.end(), std::back_inserter( rv ) );
545 sum += net->GetNodeCount();
547 else if( aNet < (
int)
m_nets.size() )
549 sum =
m_nets[aNet]->GetNodeCount();
562 if( !pad->Valid() || pad->Parent()->Type() !=
PCB_PAD_T)
565 PAD* dpad = static_cast<PAD*>( pad->Parent() );
567 if( aNet < 0 || aNet == dpad->GetNetCode() )
581 for(
const CN_EDGE& edge : rnNet->GetEdges() )
582 aEdges.push_back( edge );
595 wxFAIL_MSG(
"track not in connectivity system" );
599 CN_ITEM* citem = items.front();
601 if( !citem->
Valid() )
604 for(
const std::shared_ptr<CN_ANCHOR>& anchor : citem->
Anchors() )
606 if( anchor->IsDangling() )
609 *aPos = static_cast<wxPoint>( anchor->Pos() );
621 if( connected.empty() )
630 int first_layer = connected.front()->Layer();
632 for(
auto& item : connected )
634 if( item->Layer() != first_layer )
652 std::vector<BOARD_CONNECTED_ITEM* > rv;
654 for(
auto cnItem : entry.GetItems() )
656 for(
auto connected : cnItem->ConnectedItems() )
658 for(
auto anchor : connected->Anchors() )
660 if( anchor->Pos() == aAnchor )
662 for(
int i = 0; aTypes[i] > 0; i++ )
664 if( connected->Valid() && connected->Parent()->Type() == aTypes[i] )
666 rv.push_back( connected->Parent() );
683 if ( aNet < 0 || aNet >= (
int)
m_nets.size() )
696 for(
PAD* pad : static_cast<FOOTPRINT*>( aItem )->Pads() )
697 m_connAlgo->MarkNetAsDirty( pad->GetNetCode() );
701 m_connAlgo->MarkNetAsDirty( static_cast<BOARD_CONNECTED_ITEM*>( aItem )->GetNetCode() );
716 std::vector<CN_EDGE> edges;
717 std::set<BOARD_CONNECTED_ITEM*> item_set;
719 for(
auto item : aItems )
723 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
725 for(
PAD* pad : footprint->
Pads() )
727 nets.insert( pad->GetNetCode() );
728 item_set.insert( pad );
731 else if(
auto conn_item = dyn_cast<BOARD_CONNECTED_ITEM*>( item ) )
733 item_set.insert( conn_item );
734 nets.insert( conn_item->GetNetCode() );
738 for(
const auto& netcode : nets )
742 for(
const auto& edge : net->GetEdges() )
744 auto srcNode = edge.GetSourceNode();
745 auto dstNode = edge.GetTargetNode();
747 auto srcParent = srcNode->Parent();
748 auto dstParent = dstNode->Parent();
750 bool srcFound = ( item_set.find(srcParent) != item_set.end() );
751 bool dstFound = ( item_set.find(dstParent) != item_set.end() );
753 if ( srcFound && dstFound )
754 edges.push_back( edge );
765 std::set<const PAD*> pads;
766 std::vector<CN_EDGE> edges;
768 for(
auto pad : aComponent->
Pads() )
770 nets.insert( pad->GetNetCode() );
774 for(
const auto& netcode : nets )
778 for(
const auto& edge : net->GetEdges() )
780 auto srcNode = edge.GetSourceNode();
781 auto dstNode = edge.GetTargetNode();
783 const PAD* srcParent = static_cast<const PAD*>( srcNode->Parent() );
784 const PAD* dstParent = static_cast<const PAD*>( dstNode->Parent() );
786 bool srcFound = ( pads.find(srcParent) != pads.end() );
787 bool dstFound = ( pads.find(dstParent) != pads.end() );
789 if ( srcFound && dstFound && !aSkipInternalConnections )
791 edges.push_back( edge );
793 else if ( srcFound || dstFound )
795 edges.push_back( edge );
std::vector< CN_ITEM * > CONNECTED_ITEMS
const CONNECTED_ITEMS & ConnectedItems() const
const std::vector< TRACK * > GetConnectedTracks(const BOARD_CONNECTED_ITEM *aItem) const
void Clear()
Function Clear() Erases the connectivity database.
const std::vector< CN_EDGE > GetRatsnestForComponent(FOOTPRINT *aComponent, bool aSkipInternalConnections=false)
bool IsConnectedOnLayer(const BOARD_CONNECTED_ITEM *aItem, int aLayer, std::vector< KICAD_T > aTypes={}) const
unsigned int GetNodeCount(int aNet=-1) const
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItemsAtAnchor(const BOARD_CONNECTED_ITEM *aItem, const VECTOR2I &aAnchor, const KICAD_T aTypes[]) const
Function GetConnectedItemsAtAnchor() Returns a list of items connected to a source item aItem at posi...
bool TestTrackEndpointDangling(TRACK *aTrack, wxPoint *aPos=nullptr)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
A progress reporter for use in multi-threaded environments.
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
Class that computes missing connections on a PCB.
PROGRESS_REPORTER * m_progressReporter
const std::list< CN_ITEM * > GetItems() const
std::shared_ptr< CN_CONNECTIVITY_ALGO > GetConnectivityAlgo() const
bool Update(BOARD_ITEM *aItem)
Function Update() Updates the connectivity data for an item.
const std::vector< BOARD_CONNECTED_ITEM * > GetNetItems(int aNetCode, const KICAD_T aTypes[]) const
Function GetNetItems() Returns the list of items that belong to a certain net.
void RecalculateRatsnest(BOARD_COMMIT *aCommit=nullptr)
Function RecalculateRatsnest() Updates the ratsnest for the board.
std::shared_ptr< FROM_TO_CACHE > m_fromToCache
class ARC, an arc track segment on a copper layer
const NETINFO_LIST & GetNetInfo() const
class PAD, a pad in a footprint
BOARD_CONNECTED_ITEM * Parent() const
A small class to help profiling.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
std::vector< RN_DYNAMIC_LINE > m_dynamicRatsnest
int Net() const
allow parallel connection threads
search types array terminator (End Of Types)
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
class TRACK, a track segment (segment on a copper layer)
unsigned int GetPadCount(int aNet=-1) const
void Build(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Function Build() Builds the connectivity database for the board aBoard.
static const char Default[]
the name of the default NETCLASS
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItems(const BOARD_CONNECTED_ITEM *aItem, const KICAD_T aTypes[], bool aIgnoreNetcodes=false) const
Function GetConnectedItems() Returns a list of items connected to a source item aItem.
std::map< int, wxString > m_netclassMap
Map of netcode -> netclass the net is a member of; used for ratsnest painting.
unsigned int GetUnconnectedCount() const
Function GetUnconnectedCount() Returns the number of remaining edges in the ratsnest.
void PropagateNets()
Function PropagateNets() Propagates the net codes from the source pads to the tracks/vias.
ZONE handles a list of polygons defining a copper zone.
void ClearDynamicRatsnest()
Function ClearDynamicRatsnest() Erases the temporary dynamic ratsnest (i.e.
void SetProgressReporter(PROGRESS_REPORTER *aReporter)
bool Remove(BOARD_ITEM *aItem)
Function Remove() Removes an item from the connectivity data.
void MarkItemNetAsDirty(BOARD_ITEM *aItem)
std::vector< RN_NET * > m_nets
class FOOTPRINT, a footprint
void GetUnconnectedEdges(std::vector< CN_EDGE > &aEdges) const
bool Add(BOARD_ITEM *aItem)
Function Add() Adds an item to the connectivity data.
void BlockRatsnestItems(const std::vector< BOARD_ITEM * > &aItems)
RN_NET * GetRatsnestForNet(int aNet)
Function GetRatsnestForNet() Returns the ratsnest, expressed as a set of graph edges for a given net.
Handle the data for a net.
bool CheckConnectivity(std::vector< CN_DISJOINT_NET_ENTRY > &aReport)
void ComputeDynamicRatsnest(const std::vector< BOARD_ITEM * > &aItems, const CONNECTIVITY_DATA *aDynamicData)
Function ComputeDynamicRatsnest() Calculates the temporary dynamic ratsnest (i.e.
void FindIsolatedCopperIslands(ZONE *aZone, std::vector< int > &aIslands)
Function FindIsolatedCopperIslands() Searches for copper islands in zone aZone that are not connected...
Information pertinent to a Pcbnew printed circuit board.
std::shared_ptr< CN_ANCHOR > CN_ANCHOR_PTR
void SetNoLine(bool aEnable)
Return true if this node can be a target for ratsnest lines.
wxPoint GetPosition() const override
int GetNetCount() const
Function GetNetCount() Returns the total number of nets in the connectivity database.
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
class VIA, a via (like a track segment on a copper layer)
Describe ratsnest for a single net.
void Show(std::ostream &aStream=std::cerr)
Print the elapsed time (in a suitable unit) to a stream.
const std::vector< PAD * > GetConnectedPads(const BOARD_CONNECTED_ITEM *aItem) const
void Move(const VECTOR2I &aPos)
void HideDynamicRatsnest()
Hides the temporary dynamic ratsnest lines.
void addRatsnestCluster(const std::shared_ptr< CN_CLUSTER > &aCluster)
void Move(const VECTOR2I &aDelta)
Moves the connectivity list anchors.
const std::vector< CN_EDGE > GetRatsnestForItems(const std::vector< BOARD_ITEM * > aItems)
KICAD_T Type() const
Returns the type of object.