KiCad PCB EDA Suite
Loading...
Searching...
No Matches
topo_match.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <cstdio>
21#include <cstdlib>
22#include <cmath>
23#include <string>
24#include <vector>
25#include <algorithm>
26#include <cassert>
27#include <future>
28#include <map>
29#include <set>
30#include <unordered_map>
31#include <unordered_set>
32
33#include <thread_pool.h>
34#include <cctype>
35
36#include <core/profile.h>
37#include <pad.h>
38#include <footprint.h>
39#include <refdes_utils.h>
40#include <board.h>
41#include <wx/string.h>
42#include <wx/log.h>
43
44#include "topo_match.h"
45
46
47static const wxString traceTopoMatch = wxT( "TOPO_MATCH" );
48static const wxString traceTopoMatchDetail = wxT( "TOPO_MATCH_DETAIL" );
49
50
51namespace TMATCH
52{
53
54bool PIN::IsIsomorphic( const PIN& b, TOPOLOGY_MISMATCH_REASON& aReason ) const
55{
56 if( m_conns.size() != b.m_conns.size() )
57 {
58 wxLogTrace( traceTopoMatch,
59 wxT( "[conns mismatch n1 %d n2 %d c-ref %d c-other %d thispin %s-%s "
60 "otherpin %s-%s" ),
62 b.m_netcode,
63 (int) m_conns.size(),
64 (int) b.m_conns.size(),
65 m_parent->m_reference,
66 m_ref,
68 b.m_ref );
69
70 aReason.m_reference = m_parent->GetParent()->GetReferenceAsString();
72 aReason.m_reason = wxString::Format(
73 _( "Pad %s of %s connects to %lu pads, but candidate pad %s of %s connects to %lu." ), m_ref,
74 aReason.m_reference, static_cast<unsigned long>( m_conns.size() ), b.m_ref, aReason.m_candidate,
75 static_cast<unsigned long>( b.m_conns.size() ) );
76
77 for( auto c : m_conns )
78 {
79 wxLogTrace( traceTopoMatch, wxT( "%s-%s " ), c->m_parent->m_reference, c->m_ref );
80 }
81
82 wxLogTrace( traceTopoMatch, wxT( "||" ) );
83
84 for( auto c : b.m_conns )
85 {
86 wxLogTrace( traceTopoMatch, wxT( "%s-%s " ), c->m_parent->m_reference, c->m_ref );
87 }
88
89
90 wxLogTrace( traceTopoMatch, wxT( "] " ) );
91 return false;
92 }
93
94 if( m_conns.empty() )
95 {
96 wxLogTrace( traceTopoMatch, wxT( "[conns empty]" ) );
97 return true;
98 }
99
100 std::vector<bool> matches( m_conns.size() );
101
102 for( size_t i = 0; i < m_conns.size(); i++ )
103 matches[i] = false;
104
105 size_t nref = 0;
106
107 for( auto& cref : m_conns )
108 {
109 for( size_t i = 0; i < m_conns.size(); i++ )
110 {
111 if( b.m_conns[i]->IsTopologicallySimilar( *cref ) )
112 {
113 matches[nref] = true;
114 break;
115 }
116 }
117
118 nref++;
119 }
120
121 for( size_t i = 0; i < m_conns.size(); i++ )
122 {
123 if( !matches[i] )
124 {
125 aReason.m_reference = m_parent->GetParent()->GetReferenceAsString();
127 aReason.m_reason = wxString::Format(
128 _( "Pad %s of %s cannot match candidate pad %s of %s due to differing connectivity." ), m_ref,
129 aReason.m_reference, b.m_ref, aReason.m_candidate );
130
131 return false;
132 }
133 }
134
135 return true;
136}
137
138
139std::unordered_map<int, int> buildBaseNetMapping( const BACKTRACK_STAGE& aMatches )
140{
141 std::unordered_map<int, int> mapping;
142 mapping.reserve( aMatches.GetMatchingComponentPairs().size() * 4 );
143
144 for( const auto& [tgtCmp, refCmp] : aMatches.GetMatchingComponentPairs() )
145 {
146 auto& refPins = refCmp->Pins();
147 auto& tgtPins = tgtCmp->Pins();
148
149 for( size_t i = 0; i < refPins.size() && i < tgtPins.size(); i++ )
150 mapping[refPins[i]->GetNetCode()] = tgtPins[i]->GetNetCode();
151 }
152
153 return mapping;
154}
155
156
157bool checkCandidateNetConsistency( const std::unordered_map<int, int>& aBaseMapping,
158 COMPONENT* aRef, COMPONENT* aTgt,
160 const std::unordered_set<int>& aExternalNets )
161{
162 if( aRef->Pins().size() != aTgt->Pins().size() )
163 {
164 aReason.m_reference = aRef->GetParent()->GetReferenceAsString();
165 aReason.m_candidate = aTgt->GetParent()->GetReferenceAsString();
166 aReason.m_reason =
167 wxString::Format( _( "Component %s expects %lu matching pads but candidate %s provides %lu." ),
168 aReason.m_reference, static_cast<unsigned long>( aRef->Pins().size() ),
169 aReason.m_candidate, static_cast<unsigned long>( aTgt->Pins().size() ) );
170 return false;
171 }
172
173 // Track net mappings introduced by this candidate's pins that aren't yet in the
174 // base mapping. Two pins sharing the same ref net must map to the same target net.
175 std::unordered_map<int, int> candidateAdditions;
176
177 for( size_t i = 0; i < aRef->Pins().size(); i++ )
178 {
179 int refNet = aRef->Pins()[i]->GetNetCode();
180 int tgtNet = aTgt->Pins()[i]->GetNetCode();
181
182 // Pads on external (global/power) nets are shared with the outside world and may be
183 // tied to different global nets in different channels (e.g. an address-select pin tied
184 // to +3V3 in one channel and GND in another). Skip them in the net-consistency check
185 // so such legitimate differences do not cause false topology-mismatch errors.
186 if( aExternalNets.count( refNet ) || aExternalNets.count( tgtNet ) )
187 continue;
188
189 auto baseIt = aBaseMapping.find( refNet );
190
191 if( baseIt != aBaseMapping.end() )
192 {
193 if( baseIt->second != tgtNet )
194 {
195 wxLogTrace( traceTopoMatch, wxT( "nets inconsistent\n" ) );
196
197 aReason.m_reference = aRef->GetParent()->GetReferenceAsString();
198 aReason.m_candidate = aTgt->GetParent()->GetReferenceAsString();
199
200 wxString refNetName;
201 wxString tgtNetName;
202
203 if( const BOARD* board = aRef->GetParent()->GetBoard() )
204 {
205 if( const NETINFO_ITEM* net = board->FindNet( refNet ) )
206 refNetName = net->GetNetname();
207 }
208
209 if( const BOARD* board = aTgt->GetParent()->GetBoard() )
210 {
211 if( const NETINFO_ITEM* net = board->FindNet( tgtNet ) )
212 tgtNetName = net->GetNetname();
213 }
214
215 if( refNetName.IsEmpty() )
216 refNetName = wxString::Format( _( "net %d" ), refNet );
217
218 if( tgtNetName.IsEmpty() )
219 tgtNetName = wxString::Format( _( "net %d" ), tgtNet );
220
221 aReason.m_reason = wxString::Format(
222 _( "Pad %s of %s is on net %s but its match in candidate %s is on net %s." ),
223 aRef->Pins()[i]->GetReference(), aReason.m_reference, refNetName,
224 aReason.m_candidate, tgtNetName );
225
226 return false;
227 }
228
229 continue;
230 }
231
232 auto localIt = candidateAdditions.find( refNet );
233
234 if( localIt != candidateAdditions.end() )
235 {
236 if( localIt->second != tgtNet )
237 {
238 wxLogTrace( traceTopoMatch, wxT( "nets inconsistent (candidate internal)\n" ) );
239
240 aReason.m_reference = aRef->GetParent()->GetReferenceAsString();
241 aReason.m_candidate = aTgt->GetParent()->GetReferenceAsString();
242 aReason.m_reason = wxString::Format(
243 _( "Pad %s of %s has inconsistent net mapping in candidate %s." ),
244 aRef->Pins()[i]->GetReference(), aReason.m_reference,
245 aReason.m_candidate );
246
247 return false;
248 }
249
250 continue;
251 }
252
253 candidateAdditions[refNet] = tgtNet;
254 }
255
256 return true;
257}
258
259
260std::vector<COMPONENT*>
262 const std::vector<COMPONENT*>& aStructuralMatches,
263 const TOPOLOGY_MISMATCH_REASON& aStructuralReason,
264 const BACKTRACK_STAGE& partialMatches,
265 std::vector<TOPOLOGY_MISMATCH_REASON>& aMismatchReasons,
266 const std::atomic<bool>* aCancelled )
267{
268 if( aCancelled && aCancelled->load( std::memory_order_relaxed ) )
269 return {};
270
271 PROF_TIMER timerFmc;
272
273 aMismatchReasons.clear();
274 std::vector<COMPONENT*> matches;
275 int candidatesChecked = 0;
276
277 // Build the net consistency map from locked pairs once for this entire evaluation
278 // pass, rather than rebuilding it from scratch for every candidate.
279 std::unordered_map<int, int> baseNetMapping = buildBaseNetMapping( partialMatches );
280
281 double netCheckMs = 0.0;
282
283 for( COMPONENT* cmpTarget : aStructuralMatches )
284 {
285 if( partialMatches.m_locked.find( cmpTarget ) != partialMatches.m_locked.end() )
286 continue;
287
288 candidatesChecked++;
289
290 wxLogTrace( traceTopoMatch, wxT( "Check '%s'/'%s' " ), aRef->m_reference,
291 cmpTarget->m_reference );
292
293 TOPOLOGY_MISMATCH_REASON localReason;
294 localReason.m_reference = aRef->GetParent()->GetReferenceAsString();
295 localReason.m_candidate = cmpTarget->GetParent()->GetReferenceAsString();
296
297 PROF_TIMER timerNet;
298 bool netResult = checkCandidateNetConsistency( baseNetMapping, aRef, cmpTarget, localReason,
300 timerNet.Stop();
301 netCheckMs += timerNet.msecs();
302
303 if( netResult )
304 {
305 wxLogTrace( traceTopoMatch, wxT( "match!\n" ) );
306 matches.push_back( cmpTarget );
307 }
308 else
309 {
310 wxLogTrace( traceTopoMatch, wxT( "Reject [net topo mismatch]\n" ) );
311 aMismatchReasons.push_back( localReason );
312 }
313 }
314
315 PROF_TIMER timerScore;
316
317 std::unordered_map<COMPONENT*, double> simScores;
318 simScores.reserve( matches.size() );
319
320 for( COMPONENT* match : matches )
321 {
322 int n = 0;
323
324 for( size_t i = 0; i < aRef->m_pins.size(); i++ )
325 {
326 if( aRef->m_pins[i]->GetNetCode() == match->m_pins[i]->GetNetCode() )
327 n++;
328 }
329
330 simScores[match] = static_cast<double>( n ) / static_cast<double>( aRef->m_pins.size() );
331 }
332
333 std::sort( matches.begin(), matches.end(),
334 [&]( COMPONENT* a, COMPONENT* b ) -> bool
335 {
336 double simA = simScores[a];
337 double simB = simScores[b];
338
339 if( simA != simB )
340 return simA > simB;
341
342 return a->GetParent()->GetReferenceAsString()
343 < b->GetParent()->GetReferenceAsString();
344 } );
345
346 timerScore.Stop();
347
348 if( matches.empty() && aMismatchReasons.empty() )
349 {
350 // No net-consistency reasons were recorded above, which means there were no structural
351 // candidates to test in the first place. Surface the structural reason captured during
352 // precomputation so the user sees the actual connectivity difference (e.g. a pad that
353 // connects to a different number of pads because of an external loop between channels)
354 // rather than a generic "no compatible component" message.
355 if( !aStructuralReason.m_reason.IsEmpty() )
356 {
357 aMismatchReasons.push_back( aStructuralReason );
358 }
359 else
360 {
362 reason.m_reference = aRef->GetParent()->GetReferenceAsString();
363 reason.m_reason = _( "No compatible component found in the target area." );
364 aMismatchReasons.push_back( reason );
365 }
366 }
367
368 timerFmc.Stop();
369
370 wxLogTrace( traceTopoMatchDetail,
371 wxT( " findMatch '%s' (%d pins): %s total, checked %d/%d structural, "
372 "netCheck %0.3f ms, score %0.3f ms, %d matches" ),
373 aRef->m_reference, aRef->GetPinCount(), timerFmc.to_string(),
374 candidatesChecked, (int) aStructuralMatches.size(),
375 netCheckMs, timerScore.msecs(),
376 (int) matches.size() );
377
378 return matches;
379}
380
381
382void CONNECTION_GRAPH::breakTie( COMPONENT* aRef, std::vector<COMPONENT*>& aMatches ) const
383{
384 if( aMatches.size() <= 1 )
385 return;
386
387 wxString candidateRefs;
388
389 for( size_t i = 0; i < aMatches.size(); i++ )
390 {
391 if( i > 0 )
392 candidateRefs += wxT( ", " );
393
394 candidateRefs += aMatches[i]->GetParent()->GetReferenceAsString();
395 }
396
397 wxLogTrace( traceTopoMatch, wxT( "Topology tie for %s: %s" ),
398 aRef->GetParent()->GetReferenceAsString(), candidateRefs );
399
400 if( breakTieBySymbolUuid( aRef, aMatches ) )
401 {
402 wxLogTrace( traceTopoMatchDetail, wxT( "Broke tie with symbol UUID match for %s" ),
403 aRef->GetParent()->GetReferenceAsString() );
404 }
405 else if( breakTieByValue( aRef, aMatches ) )
406 {
407 wxLogTrace( traceTopoMatchDetail, wxT( "Broke tie with footprint value match for %s" ),
408 aRef->GetParent()->GetReferenceAsString() );
409 }
410 // TODO: other tie breakers can be added, e.g. based on position or reference designators,
411 // just waiting for actual user test cases
412 else
413 {
414 wxLogTrace( traceTopoMatchDetail, wxT( "No tie breakers worked for %s, leaving match order alone." ),
415 aRef->GetParent()->GetReferenceAsString() );
416 }
417}
418
419
420bool CONNECTION_GRAPH::breakTieByValue( COMPONENT* aRef, std::vector<COMPONENT*>& aMatches ) const
421{
422 FOOTPRINT* refFp = aRef ? aRef->GetParent() : nullptr;
423
424 if( !refFp )
425 return false;
426
427 const wxString refValue = refFp->GetValue();
428
429 if( refValue.IsEmpty() )
430 return false;
431
432 int valueHitCount = 0;
433 int uniqueMatchIdx = -1;
434
435 for( size_t i = 0; i < aMatches.size(); i++ )
436 {
437 if( aMatches[i]->GetParent()->GetValue() == refValue )
438 {
439 if( uniqueMatchIdx < 0 )
440 uniqueMatchIdx = static_cast<int>( i );
441
442 valueHitCount++;
443 }
444 }
445
446 // Only one candidate may share the value for it to disambiguate the tie. Several same-value
447 // candidates (e.g. a bank of identical decoupling caps) tell us nothing.
448 if( valueHitCount == 1 )
449 {
450 std::rotate( aMatches.begin(), aMatches.begin() + uniqueMatchIdx, aMatches.begin() + uniqueMatchIdx + 1 );
451 return true;
452 }
453
454 return false;
455}
456
457
458bool CONNECTION_GRAPH::breakTieBySymbolUuid( COMPONENT* aRef, std::vector<COMPONENT*>& aMatches ) const
459{
460 auto getSymbolInstanceUuid =
461 []( const FOOTPRINT* aFootprint ) -> KIID
462 {
463 if( !aFootprint )
464 return niluuid;
465
466 const KIID_PATH& path = aFootprint->GetPath();
467
468 if( path.empty() )
469 return niluuid;
470
471 const KIID& symbolUuid = path.back();
472
473 return symbolUuid;
474 };
475
476 FOOTPRINT* refFp = aRef ? aRef->GetParent() : nullptr;
477 const KIID refSymbolUuid = getSymbolInstanceUuid( refFp );
478 wxString candidateSymbolUuids;
479 wxString matchingSymbolCandidates;
480 int symbolUuidHitCount = 0;
481 int uniqueMatchIdx = -1;
482
483 if( refSymbolUuid == niluuid )
484 {
485 wxLogTrace( traceTopoMatchDetail, wxT( "Tie symbol UUID unavailable for %s" ),
486 refFp ? refFp->GetReferenceAsString() : wxString( wxT( "<null>" ) ) );
487 return false;
488 }
489
490 // Inspect every tied candidate and collect:
491 // 1) a detailed ref->symbol UUID mapping string for traces, and
492 // 2) the subset of candidates whose symbol-path tail UUID matches the reference.
493 for( size_t i = 0; i < aMatches.size(); i++ )
494 {
495 FOOTPRINT* candidateFp = aMatches[i]->GetParent();
496 const wxString candidateRef = candidateFp->GetReferenceAsString();
497 const KIID candidateSymbolUuid = getSymbolInstanceUuid( candidateFp );
498
499 if( i > 0 )
500 candidateSymbolUuids += wxT( ", " );
501
502 if( candidateSymbolUuid == niluuid )
503 candidateSymbolUuids += candidateRef + wxT( "=<none>" );
504 else
505 candidateSymbolUuids += candidateRef + wxT( "=" ) + candidateSymbolUuid.AsString();
506
507 if( candidateSymbolUuid == refSymbolUuid )
508 {
509 if( uniqueMatchIdx < 0 )
510 uniqueMatchIdx = static_cast<int>( i );
511
512 symbolUuidHitCount++;
513
514 if( !matchingSymbolCandidates.IsEmpty() )
515 matchingSymbolCandidates += wxT( ", " );
516
517 matchingSymbolCandidates += candidateRef;
518 }
519 }
520
521 wxLogTrace( traceTopoMatchDetail, wxT( "Tie reference symbol UUID for %s: %s (hits=%d)" ),
522 refFp->GetReferenceAsString(), refSymbolUuid.AsString(), symbolUuidHitCount );
523
524 wxLogTrace( traceTopoMatchDetail, wxT( "Tie candidate symbol UUIDs: %s" ), candidateSymbolUuids );
525
526 // One match is what we want, we should have one match between the source symbol instance
527 // and the destination only since in theory we are repeating across two instances of the same sheet
528 if( symbolUuidHitCount == 1 )
529 {
530 wxLogTrace( traceTopoMatchDetail, wxT( "Symbol UUID unique match (usable) for %s: %s" ),
531 refFp->GetReferenceAsString(), matchingSymbolCandidates );
532
533 std::rotate( aMatches.begin(), aMatches.begin() + uniqueMatchIdx, aMatches.begin() + uniqueMatchIdx + 1 );
534
535 wxLogTrace( traceTopoMatchDetail, wxT( "Applied symbol UUID tie-break for %s: selected %s" ),
536 refFp->GetReferenceAsString(), aMatches.front()->GetParent()->GetReferenceAsString() );
537
538 return true;
539 }
540 // Copy and pasting footprints can result in multiple matches
541 else if( symbolUuidHitCount > 1 )
542 {
543 wxLogTrace( traceTopoMatchDetail, wxT( "Symbol UUID multiple matches (not usable) for %s: %s" ),
544 refFp->GetReferenceAsString(), matchingSymbolCandidates );
545 return false;
546 }
547 // Probably not sheet instances, break the tie some other way
548 else
549 {
550 wxLogTrace( traceTopoMatchDetail, wxT( "No symbol UUID candidate match (not usable) for %s" ),
551 refFp->GetReferenceAsString() );
552 return false;
553 }
554}
555
556
558{
559 std::sort( m_pins.begin(), m_pins.end(),
560 []( PIN* a, PIN* b )
561 {
562 return a->GetReference() < b->GetReference();
563 } );
564}
565
566
568{
569 std::sort( m_components.begin(), m_components.end(),
570 []( COMPONENT* a, COMPONENT* b )
571 {
572 if( a->GetPinCount() != b->GetPinCount() )
573 return a->GetPinCount() > b->GetPinCount();
574
575 return a->GetParent()->GetReferenceAsString() < b->GetParent()->GetReferenceAsString();
576 } );
577}
578
579
580void CONNECTION_GRAPH::BuildConnectivity( const std::unordered_set<int>& aExternalNets )
581{
582 m_externalNets = aExternalNets;
583
584 std::map<int, std::vector<PIN*>> nets;
585
587
588 for( auto c : m_components )
589 {
590 c->sortPinsByName();
591
592 for( auto p : c->Pins() )
593 {
594 if( p->GetNetCode() > 0 )
595 nets[p->GetNetCode()].push_back( p );
596 }
597 }
598
599 for( auto& [netcode, pins] : nets )
600 {
601 // Skip nets that extend beyond this channel's footprint set. Global power nets
602 // (GND, VCC, etc.) are shared across channels and can create spurious intra-channel
603 // connections that cause false topology mismatches when hierarchical pins are tied
604 // directly to those nets.
605 if( aExternalNets.count( netcode ) )
606 continue;
607
608 wxLogTrace( traceTopoMatch, wxT( "net %d: %d connections\n" ), netcode,
609 (int) pins.size() );
610
611 for( PIN* p : pins )
612 {
613 p->m_conns.reserve( pins.size() - 1 );
614
615 for( PIN* p2 : pins )
616 {
617 if( p != p2 )
618 p->m_conns.push_back( p2 );
619 }
620 }
621 }
622
623/* for( auto c : m_components )
624 for( auto p : c->Pins() )
625 {
626 printf("pin %s: \n", p->m_ref.c_str().AsChar() );
627
628 for( auto c : p->m_conns )
629 printf( "%s ", c->m_ref.c_str().AsChar() );
630 printf("\n");
631 }
632 */
633}
634
635
637 std::vector<TOPOLOGY_MISMATCH_REASON>& aMismatchReasons,
638 const ISOMORPHISM_PARAMS& aParams )
639{
640 std::vector<BACKTRACK_STAGE> stack;
642
643 aMismatchReasons.clear();
644
645 if( aParams.m_totalComponents )
646 aParams.m_totalComponents->store( (int) m_components.size(), std::memory_order_relaxed );
647
648 PROF_TIMER timerTotal;
649 int backtrackCount = 0;
650 double mrvTotalMs = 0.0;
651
652 std::vector<TOPOLOGY_MISMATCH_REASON> localReasons;
653
654 if( m_components.empty()|| aTarget->m_components.empty() )
655 {
657 reason.m_reason = _( "One or both of the areas has no components assigned." );
658 aMismatchReasons.push_back( reason );
659 return false;
660 }
661
662 if( m_components.size() != aTarget->m_components.size() )
663 {
665 reason.m_reason = _( "Component count mismatch" );
666 aMismatchReasons.push_back( reason );
667 return false;
668 }
669
670 // Structural compatibility (MatchesWith) depends only on pin count, footprint ID, and
671 // pin connection topology -- all immutable graph properties. Precompute it once per
672 // source component so the backtracking loop never repeats these comparisons.
673 size_t numRef = m_components.size();
674 std::vector<std::vector<COMPONENT*>> structuralMatches( numRef );
675
676 // When a source component has no structural match at all, keep a representative reason so we
677 // can explain the actual connectivity difference rather than a generic "no compatible
678 // component" message.
679 std::vector<TOPOLOGY_MISMATCH_REASON> structuralReasons( numRef );
680
681 PROF_TIMER timerPrecompute;
682 {
684 std::vector<std::future<void>> futures;
685 futures.reserve( numRef );
686
687 const std::atomic<bool>* cancelled = aParams.m_cancelled;
688
689 for( size_t i = 0; i < numRef; i++ )
690 {
691 futures.emplace_back( tp.submit_task(
692 [this, i, aTarget, &structuralMatches, &structuralReasons, cancelled]()
693 {
694 if( cancelled && cancelled->load( std::memory_order_relaxed ) )
695 return;
696
697 COMPONENT* ref = m_components[i];
698 TOPOLOGY_MISMATCH_REASON reason;
699 TOPOLOGY_MISMATCH_REASON bestReason;
700
701 for( COMPONENT* tgt : aTarget->m_components )
702 {
703 if( ref->MatchesWith( tgt, reason ) )
704 {
705 structuralMatches[i].push_back( tgt );
706 }
707 else if( bestReason.m_reason.IsEmpty() || ref->IsSameKind( *tgt ) )
708 {
709 // Prefer the reason from a same-kind counterpart (same prefix and
710 // footprint) because that is the candidate the user actually expects
711 // to match; a connectivity difference there is the meaningful failure.
712 bestReason = reason;
713 }
714 }
715
716 if( structuralMatches[i].empty() )
717 structuralReasons[i] = bestReason;
718 } ) );
719 }
720
721 for( auto& f : futures )
722 f.wait();
723 }
724 timerPrecompute.Stop();
725
726 wxLogTrace( traceTopoMatchDetail,
727 wxT( "Structural precomputation: %s (%d source x %d target)" ),
728 timerPrecompute.to_string(), (int) numRef,
729 (int) aTarget->m_components.size() );
730
731 if( aParams.m_cancelled && aParams.m_cancelled->load( std::memory_order_relaxed ) )
732 return false;
733
734 top.m_ref = m_components.front();
735 top.m_refIndex = 0;
736
737 stack.push_back( top );
738
739 int nloops = 0;
740
741 while( !stack.empty() )
742 {
743 if( aParams.m_cancelled && aParams.m_cancelled->load( std::memory_order_relaxed ) )
744 return false;
745
746 nloops++;
747 auto& current = stack.back();
748
749 for( auto it = current.m_locked.begin(); it != current.m_locked.end(); it++ )
750 {
751 if (it->second == current.m_ref)
752 {
753 wxLogTrace( traceTopoMatch, wxT( "stk: Remove %s from locked\n" ),
754 current.m_ref->m_reference );
755 current.m_locked.erase( it );
756 break;
757 }
758 }
759
760 if( nloops >= c_ITER_LIMIT )
761 {
762 wxLogTrace( traceTopoMatch, wxT( "stk: Iter cnt exceeded\n" ) );
763
765 reason.m_reason = _( "Iteration count exceeded (timeout)" );
766
767 if( aMismatchReasons.empty() )
768 aMismatchReasons.push_back( reason );
769 else
770 aMismatchReasons.insert( aMismatchReasons.begin(), reason );
771
772 return false;
773 }
774
775 if( current.m_currentMatch < 0 )
776 {
777 PROF_TIMER timerInitMatch;
778
779 localReasons.clear();
780 current.m_matches = aTarget->findMatchingComponents(
781 current.m_ref, structuralMatches[current.m_refIndex],
782 structuralReasons[current.m_refIndex], current, localReasons,
783 aParams.m_cancelled );
784
785 timerInitMatch.Stop();
786
787 wxLogTrace( traceTopoMatchDetail,
788 wxT( "iter %d: initial match for '%s' (%d pins): %s, %d candidates" ),
789 nloops, current.m_ref->m_reference, current.m_ref->GetPinCount(),
790 timerInitMatch.to_string(), (int) current.m_matches.size() );
791
792 if( current.m_matches.empty() && aMismatchReasons.empty() && !localReasons.empty() )
793 aMismatchReasons = localReasons;
794
795 current.m_currentMatch = 0;
796 }
797
798 wxLogTrace( traceTopoMatch, wxT( "stk: Current '%s' stack %d cm %d/%d locked %d/%d\n" ),
799 current.m_ref->m_reference, (int) stack.size(), current.m_currentMatch,
800 (int) current.m_matches.size(), (int) current.m_locked.size(),
801 (int) m_components.size() );
802
803 if( current.m_currentMatch == 0 && current.m_matches.size() > 1 )
804 breakTie( current.m_ref, current.m_matches );
805
806 if ( current.m_matches.empty() )
807 {
808 wxLogTrace( traceTopoMatch, wxT( "stk: No matches at all, going up [level=%d]\n" ),
809 (int) stack.size() );
810 stack.pop_back();
811 backtrackCount++;
812 continue;
813 }
814
815 if( current.m_currentMatch >= 0
816 && static_cast<size_t>( current.m_currentMatch ) >= current.m_matches.size() )
817 {
818 wxLogTrace( traceTopoMatch, wxT( "stk: No more matches, going up [level=%d]\n" ),
819 (int) stack.size() );
820 stack.pop_back();
821 backtrackCount++;
822 continue;
823 }
824
825 auto& match = current.m_matches[current.m_currentMatch];
826
827 wxLogTrace( traceTopoMatch, wxT( "stk: candidate '%s', match list : ( " ),
828 current.m_matches[current.m_currentMatch]->m_reference, current.m_refIndex );
829
830 for( auto m : current.m_matches )
831 wxLogTrace( traceTopoMatch, wxT( "%s " ), m->GetParent()->GetReferenceAsString() );
832
833 wxLogTrace( traceTopoMatch, wxT( "\n" ) );
834
835 current.m_currentMatch++;
836 current.m_locked[match] = current.m_ref;
837
838 if( aParams.m_matchedComponents )
839 {
840 aParams.m_matchedComponents->store( (int) current.m_locked.size(),
841 std::memory_order_relaxed );
842 }
843
844 if( current.m_locked.size() == m_components.size() )
845 {
846 current.m_nloops = nloops;
847
848 aResult.clear();
849 aMismatchReasons.clear();
850
851 for( auto iter : current.m_locked )
852 aResult[ iter.second->GetParent() ] = iter.first->GetParent();
853
854 timerTotal.Stop();
855 wxLogTrace( traceTopoMatch,
856 wxT( "Isomorphism: %s, %d iterations, %d backtracks, "
857 "MRV total %0.1f ms (%d candidates)" ),
858 timerTotal.to_string(), nloops, backtrackCount, mrvTotalMs,
859 (int) m_components.size() );
860
861 return true;
862 }
863
864
865 // MRV heuristic: find the unlocked component with the fewest candidate matches.
866 // Collect unlocked components, then evaluate them in parallel since each
867 // findMatchingComponents call is independent (read-only on graphs and current stage).
868 struct MRV_CANDIDATE
869 {
870 COMPONENT* m_cmp;
871 size_t m_index;
872 std::vector<COMPONENT*> m_matches;
873 std::vector<TOPOLOGY_MISMATCH_REASON> m_reasons;
874 };
875
876 std::vector<MRV_CANDIDATE> mrvCandidates;
877
878 // Build a set of all ref-components already locked so we can skip them in O(1)
879 // instead of scanning m_locked values for each component.
880 std::unordered_set<COMPONENT*> lockedRefs;
881 lockedRefs.reserve( current.m_locked.size() );
882
883 for( const auto& [tgt, ref] : current.m_locked )
884 lockedRefs.insert( ref );
885
886 for( size_t i = 0; i < m_components.size(); i++ )
887 {
888 COMPONENT* cmp = m_components[i];
889
890 if( cmp != current.m_ref && lockedRefs.find( cmp ) == lockedRefs.end() )
891 mrvCandidates.push_back( { cmp, i, {}, {} } );
892 }
893
894 static const size_t MRV_PARALLEL_THRESHOLD = 4;
895
896 PROF_TIMER timerMrv;
897
898 if( mrvCandidates.size() >= MRV_PARALLEL_THRESHOLD )
899 {
901 std::vector<std::future<void>> futures;
902 futures.reserve( mrvCandidates.size() );
903
904 const std::atomic<bool>* cancelled = aParams.m_cancelled;
905
906 for( MRV_CANDIDATE& c : mrvCandidates )
907 {
908 futures.emplace_back( tp.submit_task(
909 [&c, aTarget, &current, &structuralMatches, &structuralReasons, cancelled]()
910 {
911 c.m_matches = aTarget->findMatchingComponents(
912 c.m_cmp, structuralMatches[c.m_index],
913 structuralReasons[c.m_index], current, c.m_reasons,
914 cancelled );
915 } ) );
916 }
917
918 for( auto& f : futures )
919 f.wait();
920 }
921 else
922 {
923 for( MRV_CANDIDATE& c : mrvCandidates )
924 {
925 c.m_matches = aTarget->findMatchingComponents(
926 c.m_cmp, structuralMatches[c.m_index],
927 structuralReasons[c.m_index], current, c.m_reasons,
928 aParams.m_cancelled );
929 }
930 }
931
932 timerMrv.Stop();
933 double mrvMs = timerMrv.msecs();
934 mrvTotalMs += mrvMs;
935
936 wxLogTrace( traceTopoMatchDetail,
937 wxT( "iter %d: MRV scan %0.3f ms, %d unlocked candidates" ),
938 nloops, mrvMs, (int) mrvCandidates.size() );
939
940 if( aParams.m_cancelled && aParams.m_cancelled->load( std::memory_order_relaxed ) )
941 return false;
942
943 int minMatches = std::numeric_limits<int>::max();
944 COMPONENT* altNextRef = nullptr;
945 COMPONENT* bestNextRef = nullptr;
946 int bestRefIndex = 0;
947 int altRefIndex = 0;
948 std::vector<COMPONENT*> bestMatches;
949
950 for( MRV_CANDIDATE& c : mrvCandidates )
951 {
952 int nMatches = static_cast<int>( c.m_matches.size() );
953
954 if( nMatches == 1 )
955 {
956 bestNextRef = c.m_cmp;
957 bestRefIndex = static_cast<int>( c.m_index );
958 bestMatches = std::move( c.m_matches );
959 break;
960 }
961 else if( nMatches == 0 )
962 {
963 altNextRef = c.m_cmp;
964 altRefIndex = static_cast<int>( c.m_index );
965
966 if( aMismatchReasons.empty() && !c.m_reasons.empty() )
967 aMismatchReasons = c.m_reasons;
968 }
969 else if( nMatches < minMatches )
970 {
971 minMatches = nMatches;
972 bestNextRef = c.m_cmp;
973 bestRefIndex = static_cast<int>( c.m_index );
974 bestMatches = std::move( c.m_matches );
975 }
976 }
977
978 BACKTRACK_STAGE next( current );
979
980 if( bestNextRef )
981 {
982 wxLogTrace( traceTopoMatchDetail,
983 wxT( "iter %d: MRV picked '%s' (%d matches, best of %d)" ),
984 nloops, bestNextRef->m_reference,
985 (int) bestMatches.size(), (int) mrvCandidates.size() );
986
987 next.m_ref = bestNextRef;
988 next.m_refIndex = bestRefIndex;
989 next.m_matches = std::move( bestMatches );
990 next.m_currentMatch = 0;
991 }
992 else
993 {
994 wxLogTrace( traceTopoMatchDetail,
995 wxT( "iter %d: MRV dead end, alt='%s'" ),
996 nloops, altNextRef ? altNextRef->m_reference : wxString( "(none)" ) );
997
998 next.m_ref = altNextRef;
999 next.m_refIndex = altRefIndex;
1000 next.m_currentMatch = -1;
1001 }
1002
1003 stack.push_back( next );
1004 };
1005
1006 timerTotal.Stop();
1007 wxLogTrace( traceTopoMatch,
1008 wxT( "Isomorphism: %s, %d iterations, %d backtracks, "
1009 "MRV total %0.1f ms (%d candidates)" ),
1010 timerTotal.to_string(), nloops, backtrackCount, mrvTotalMs,
1011 (int) m_components.size() );
1012
1013 return false;
1014}
1015
1016
1017#if 0
1018int main()
1019{
1020 FILE * f = fopen("connectivity.dump","rb" );
1021 auto cgRef = loadCGraph(f);
1022 auto cgTarget = loadCGraph(f);
1023
1024 cgRef->buildConnectivity();
1025 cgTarget->buildConnectivity();
1026
1027 int attempts = 0;
1028 int max_loops = 0;
1029
1030 for( ;; )
1031 {
1032 cgRef->shuffle();
1033 cgTarget->shuffle();
1034
1035 const BacktrackStage latest = cgRef->matchCGraphs( cgTarget );
1036
1037 if( !latest.locked.size() )
1038 {
1039 printf("MATCH FAIL\n");
1040 break;
1041 }
1042
1043 //printf("loops: %d\n", latest.nloops );
1044 //printf("Locked: %d\n", latest.locked.size() );
1045
1046 //if (matchFound)
1047 //{
1048 // for( auto& iter : latest.locked )
1049 //{
1050 // printf("%-10s : %-10s\n", iter.first->reference.c_str(), iter.second->reference.c_str() );
1051 //}
1052
1053 //}
1054
1055 if( latest.nloops > max_loops )
1056 {
1057 max_loops = latest.nloops;
1058 }
1059
1060 if (attempts % 10000 == 0)
1061 {
1062 printf("attempts: %d maxloops: %d\n", attempts, max_loops );
1063 }
1064
1065 attempts++;
1066
1067 }
1068
1069 fclose(f);
1070
1071 return 0;
1072}
1073
1074#endif
1075
1076
1077COMPONENT::COMPONENT( const wxString& aRef, FOOTPRINT* aParentFp,
1078 std::optional<VECTOR2I> aRaOffset ) :
1079 m_raOffset( aRaOffset ),
1080 m_reference( aRef ),
1081 m_parentFootprint( aParentFp )
1082{
1084}
1085
1086
1087bool COMPONENT::isChannelSuffix( const wxString& aSuffix )
1088{
1089 if( aSuffix.IsEmpty() )
1090 return true;
1091
1092 for( wxUniChar ch : aSuffix )
1093 {
1094 if( std::isalpha( static_cast<int>( ch ) ) )
1095 return false;
1096 }
1097
1098 return true;
1099}
1100
1101
1102bool COMPONENT::prefixesShareCommonBase( const wxString& aPrefixA, const wxString& aPrefixB )
1103{
1104 if( aPrefixA == aPrefixB )
1105 return true;
1106
1107 size_t commonLen = 0;
1108 size_t minLen = std::min( aPrefixA.length(), aPrefixB.length() );
1109
1110 while( commonLen < minLen && aPrefixA[commonLen] == aPrefixB[commonLen] )
1111 commonLen++;
1112
1113 if( commonLen == 0 )
1114 return false;
1115
1116 wxString suffixA = aPrefixA.Mid( commonLen );
1117 wxString suffixB = aPrefixB.Mid( commonLen );
1118
1119 return isChannelSuffix( suffixA ) && isChannelSuffix( suffixB );
1120}
1121
1122
1123bool COMPONENT::IsSameKind( const COMPONENT& b ) const
1124{
1126 return false;
1127
1128 return ( m_parentFootprint->GetFPID() == b.m_parentFootprint->GetFPID() )
1129 || ( m_parentFootprint->GetFPID().empty() && b.m_parentFootprint->GetFPID().empty() );
1130}
1131
1132
1134{
1135 m_pins.push_back( aPin );
1136 aPin->SetParent( this );
1137}
1138
1139
1141{
1142 if( GetPinCount() != b->GetPinCount() )
1143 {
1145 aReason.m_candidate = b->GetParent()->GetReferenceAsString();
1146 aReason.m_reason =
1147 wxString::Format( _( "Component %s has %d pads but candidate %s has %d." ), aReason.m_reference,
1148 GetPinCount(), aReason.m_candidate, b->GetPinCount() );
1149 return false;
1150 }
1151
1152 if( !IsSameKind( *b ) )
1153 {
1155 aReason.m_candidate = b->GetParent()->GetReferenceAsString();
1156
1158 {
1159 aReason.m_reason = wxString::Format(
1160 _( "Reference prefix mismatch: %s uses prefix '%s' but candidate %s uses '%s'." ),
1161 aReason.m_reference, m_prefix, aReason.m_candidate, b->m_prefix );
1162 }
1163 else
1164 {
1165 wxString refFootprint = GetParent()->GetFPIDAsString();
1166 wxString candFootprint = b->GetParent()->GetFPIDAsString();
1167
1168 if( refFootprint.IsEmpty() )
1169 refFootprint = _( "(no library ID)" );
1170
1171 if( candFootprint.IsEmpty() )
1172 candFootprint = _( "(no library ID)" );
1173
1174 aReason.m_reason =
1175 wxString::Format( _( "Library link mismatch: %s expects '%s' but candidate %s is '%s'." ),
1176 aReason.m_reference, refFootprint, aReason.m_candidate, candFootprint );
1177 }
1178
1179 return false;
1180 }
1181
1182 for( int pin = 0; pin < b->GetPinCount(); pin++ )
1183 {
1184 // Call with the reference pin as the subject so the reason's reference/candidate match
1185 // MatchesWith's own orientation (this == reference, b == candidate).
1186 if( !m_pins[pin]->IsIsomorphic( *b->m_pins[pin], aReason ) )
1187 {
1188 if( aReason.m_reason.IsEmpty() )
1189 {
1191 aReason.m_candidate = b->GetParent()->GetReferenceAsString();
1192 aReason.m_reason = wxString::Format( _( "Component pads differ between %s and %s." ),
1193 aReason.m_reference, aReason.m_candidate );
1194 }
1195
1196 return false;
1197 }
1198
1199 }
1200
1201 return true;
1202}
1203
1204
1206{
1207 auto cmp = new COMPONENT( aFp->GetReference(), aFp );
1208
1209 for( auto pad : aFp->Pads() )
1210 {
1211 auto pin = new PIN( );
1212 pin->m_netcode = pad->GetNetCode();
1213 pin->m_ref = pad->GetNumber();
1214 cmp->AddPin( pin );
1215 }
1216
1217 m_components.push_back( cmp );
1218}
1219
1220
1221std::unique_ptr<CONNECTION_GRAPH>
1222CONNECTION_GRAPH::BuildFromFootprintSet( const std::set<FOOTPRINT*>& aFps,
1223 const std::set<FOOTPRINT*>& aOtherChannelFps )
1224{
1225 auto cgraph = std::make_unique<CONNECTION_GRAPH>();
1226 VECTOR2I ref(0, 0);
1227
1228 if( aFps.size() > 0 )
1229 ref = (*aFps.begin())->GetPosition();
1230
1231 for( auto fp : aFps )
1232 cgraph->AddFootprint( fp, fp->GetPosition() - ref );
1233
1234 std::unordered_map<int, int> localNetPadCounts;
1235
1236 for( const FOOTPRINT* fp : aFps )
1237 {
1238 for( const PAD* pad : fp->Pads() )
1239 {
1240 if( pad->GetNetCode() > 0 )
1241 localNetPadCounts[pad->GetNetCode()]++;
1242 }
1243 }
1244
1245 std::unordered_map<int, int> otherChannelNetPadCounts;
1246
1247 for( const FOOTPRINT* fp : aOtherChannelFps )
1248 {
1249 for( const PAD* pad : fp->Pads() )
1250 {
1251 if( pad->GetNetCode() > 0 )
1252 otherChannelNetPadCounts[pad->GetNetCode()]++;
1253 }
1254 }
1255
1256 // Exclude a net from topology comparison only when it forms a real internal connection (two
1257 // or more pads) in BOTH sets. This drops global rails (GND, VCC) while keeping single-pad
1258 // boundary nets, such as an applied design block's daisy-chain output feeding the target
1259 // instance's inputs, whose asymmetric exclusion would otherwise break the isomorphism.
1260 std::unordered_set<int> externalNets;
1261
1262 for( const auto& [netCode, localCount] : localNetPadCounts )
1263 {
1264 auto otherIt = otherChannelNetPadCounts.find( netCode );
1265
1266 if( localCount >= 2 && otherIt != otherChannelNetPadCounts.end() && otherIt->second >= 2 )
1267 externalNets.insert( netCode );
1268 }
1269
1270 cgraph->BuildConnectivity( externalNets );
1271
1272 return cgraph;
1273}
1274
1275
1280
1281
1283{
1284 for( COMPONENT* fp : m_components )
1285 {
1286 delete fp;
1287 }
1288}
1289
1290
1292{
1293 for( PIN* p : m_pins )
1294 {
1295 delete p;
1296 }
1297}
1298
1299
1300}; // namespace TMATCH
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.
Definition board.h:373
COMPONENT(const LIB_ID &aFPID, const wxString &aReference, const wxString &aValue, const KIID_PATH &aPath, const std::vector< KIID > &aKiids)
std::deque< PAD * > & Pads()
Definition footprint.h:375
wxString GetFPIDAsString() const
Definition footprint.h:447
const LIB_ID & GetFPID() const
Definition footprint.h:441
wxString GetReferenceAsString() const
Definition footprint.h:850
const wxString & GetValue() const
Definition footprint.h:863
const wxString & GetReference() const
Definition footprint.h:841
Definition kiid.h:44
wxString AsString() const
Definition kiid.cpp:242
bool empty() const
Definition lib_id.h:189
Handle the data for a net.
Definition netinfo.h:46
Definition pad.h:61
A small class to help profiling.
Definition profile.h:46
void Stop()
Save the time when this function was called, and set the counter stane to stop.
Definition profile.h:86
std::string to_string()
Definition profile.h:153
double msecs(bool aSinceLast=false)
Definition profile.h:147
const std::unordered_map< COMPONENT *, COMPONENT * > & GetMatchingComponentPairs() const
Definition topo_match.h:166
std::unordered_map< COMPONENT *, COMPONENT * > m_locked
Definition topo_match.h:176
static bool prefixesShareCommonBase(const wxString &aPrefixA, const wxString &aPrefixB)
Check if two prefixes share a common starting sequence.
bool IsSameKind(const COMPONENT &b) const
int GetPinCount() const
Definition topo_match.h:68
COMPONENT(const wxString &aRef, FOOTPRINT *aParentFp, std::optional< VECTOR2I > aRaOffset=std::optional< VECTOR2I >())
FOOTPRINT * m_parentFootprint
Definition topo_match.h:99
std::optional< VECTOR2I > m_raOffset
Definition topo_match.h:96
bool MatchesWith(COMPONENT *b, TOPOLOGY_MISMATCH_REASON &aDetail)
wxString m_prefix
Definition topo_match.h:98
void AddPin(PIN *p)
std::vector< PIN * > & Pins()
Definition topo_match.h:70
friend class PIN
Definition topo_match.h:59
wxString m_reference
Definition topo_match.h:97
static bool isChannelSuffix(const wxString &aSuffix)
Check if a suffix looks like a channel identifier.
std::vector< PIN * > m_pins
Definition topo_match.h:100
FOOTPRINT * GetParent() const
Definition topo_match.h:71
std::vector< COMPONENT * > findMatchingComponents(COMPONENT *ref, const std::vector< COMPONENT * > &aStructuralMatches, const TOPOLOGY_MISMATCH_REASON &aStructuralReason, const BACKTRACK_STAGE &partialMatches, std::vector< TOPOLOGY_MISMATCH_REASON > &aFailureDetails, const std::atomic< bool > *aCancelled=nullptr)
bool FindIsomorphism(CONNECTION_GRAPH *target, COMPONENT_MATCHES &result, std::vector< TOPOLOGY_MISMATCH_REASON > &aFailureDetails, const ISOMORPHISM_PARAMS &aParams={})
void BuildConnectivity(const std::unordered_set< int > &aExternalNets={})
bool breakTieByValue(COMPONENT *aRef, std::vector< COMPONENT * > &aMatches) const
Break a tie by footprint value when the symbol UUID can't, e.g.
std::vector< COMPONENT * > m_components
Definition topo_match.h:228
void AddFootprint(FOOTPRINT *aFp, const VECTOR2I &aOffset)
bool breakTieBySymbolUuid(COMPONENT *aRef, std::vector< COMPONENT * > &aMatches) const
The most useful tie breaker is based on symbol/sheet instances, since multiple channels in a design a...
void breakTie(COMPONENT *aRef, std::vector< COMPONENT * > &aMatches) const
Many times components are electrically/topologically identical, e.g.
std::unordered_set< int > m_externalNets
Definition topo_match.h:229
static std::unique_ptr< CONNECTION_GRAPH > BuildFromFootprintSet(const std::set< FOOTPRINT * > &aFps, const std::set< FOOTPRINT * > &aOtherChannelFps={})
std::vector< PIN * > m_conns
Definition topo_match.h:140
void SetParent(COMPONENT *parent)
Definition topo_match.h:111
COMPONENT * m_parent
Definition topo_match.h:139
bool IsIsomorphic(const PIN &b, TOPOLOGY_MISMATCH_REASON &aDetail) const
wxString m_ref
Definition topo_match.h:137
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
KIID niluuid(0)
std::unordered_map< int, int > buildBaseNetMapping(const BACKTRACK_STAGE &aMatches)
std::map< FOOTPRINT *, FOOTPRINT * > COMPONENT_MATCHES
Definition topo_match.h:180
bool checkCandidateNetConsistency(const std::unordered_map< int, int > &aBaseMapping, COMPONENT *aRef, COMPONENT *aTgt, TOPOLOGY_MISMATCH_REASON &aReason, const std::unordered_set< int > &aExternalNets)
wxString GetRefDesPrefix(const wxString &aRefDes)
Get the (non-numeric) prefix from a refdes - e.g.
CITER next(CITER it)
Definition ptree.cpp:120
Collection of utility functions for component reference designators (refdes)
std::atomic< bool > * m_cancelled
Definition topo_match.h:45
std::atomic< int > * m_totalComponents
Definition topo_match.h:47
std::string path
KIBIS top(path, &reporter)
KIBIS_PIN * pin
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
static thread_pool * tp
BS::priority_thread_pool thread_pool
Definition thread_pool.h:27
static const wxString traceTopoMatchDetail
static const wxString traceTopoMatch
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683