KiCad PCB EDA Suite
Loading...
Searching...
No Matches
connectivity_algo.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 (C) 2016-2018 CERN
5 * Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27
28#include <algorithm>
29#include <future>
30#include <mutex>
31
33#include <progress_reporter.h>
35#include <board_commit.h>
36#include <core/thread_pool.h>
37#include <pcb_shape.h>
38
39#include <wx/log.h>
40
41#ifdef PROFILE
42#include <core/profile.h>
43#endif
44
45
47{
48 markItemNetAsDirty( aItem );
49
50 switch( aItem->Type() )
51 {
52 case PCB_FOOTPRINT_T:
53 for( PAD* pad : static_cast<FOOTPRINT*>( aItem )->Pads() )
54 {
55 m_itemMap[pad].MarkItemsAsInvalid();
56 m_itemMap.erase( pad );
57 }
58
59 m_itemList.SetDirty( true );
60 break;
61
62 case PCB_PAD_T:
63 case PCB_TRACE_T:
64 case PCB_ARC_T:
65 case PCB_VIA_T:
66 case PCB_ZONE_T:
67 case PCB_SHAPE_T:
68 m_itemMap[aItem].MarkItemsAsInvalid();
69 m_itemMap.erase ( aItem );
70 m_itemList.SetDirty( true );
71 break;
72
73 default:
74 return false;
75 }
76
77 // Once we delete an item, it may connect between lists, so mark both as potentially invalid
79
80 return true;
81}
82
83
85{
86 if( aItem->IsConnected() )
87 {
88 const BOARD_CONNECTED_ITEM* citem = static_cast<const BOARD_CONNECTED_ITEM*>( aItem );
89 MarkNetAsDirty( citem->GetNetCode() );
90 }
91 else
92 {
93 if( aItem->Type() == PCB_FOOTPRINT_T )
94 {
95 const FOOTPRINT* footprint = static_cast<const FOOTPRINT*>( aItem );
96
97 for( PAD* pad : footprint->Pads() )
98 MarkNetAsDirty( pad->GetNetCode() );
99 }
100 }
101}
102
103
105{
106 if( !aItem->IsOnCopperLayer() )
107 return false;
108
109 auto alreadyAdded =
110 [this]( BOARD_ITEM* item )
111 {
112 auto it = m_itemMap.find( item );
113
114 if( it == m_itemMap.end() )
115 return false;
116
117 // Don't be fooled by an empty ITEM_MAP_ENTRY auto-created by operator[].
118 return !it->second.GetItems().empty();
119 };
120
121 switch( aItem->Type() )
122 {
123 case PCB_NETINFO_T:
124 MarkNetAsDirty( static_cast<NETINFO_ITEM*>( aItem )->GetNetCode() );
125 break;
126
127 case PCB_FOOTPRINT_T:
128 {
129 if( static_cast<FOOTPRINT*>( aItem )->GetAttributes() & FP_JUST_ADDED )
130 return false;
131
132 for( PAD* pad : static_cast<FOOTPRINT*>( aItem )->Pads() )
133 {
134 if( alreadyAdded( pad ) )
135 return false;
136
137 add( m_itemList, pad );
138 }
139
140 break;
141 }
142
143 case PCB_PAD_T:
144 {
145 if( FOOTPRINT* fp = aItem->GetParentFootprint() )
146 {
147 if( fp->GetAttributes() & FP_JUST_ADDED )
148 return false;
149 }
150
151 if( alreadyAdded( aItem ) )
152 return false;
153
154 add( m_itemList, static_cast<PAD*>( aItem ) );
155 break;
156 }
157
158 case PCB_TRACE_T:
159 if( alreadyAdded( aItem ) )
160 return false;
161
162 add( m_itemList, static_cast<PCB_TRACK*>( aItem ) );
163 break;
164
165 case PCB_ARC_T:
166 if( alreadyAdded( aItem ) )
167 return false;
168
169 add( m_itemList, static_cast<PCB_ARC*>( aItem ) );
170 break;
171
172 case PCB_VIA_T:
173 if( alreadyAdded( aItem ) )
174 return false;
175
176 add( m_itemList, static_cast<PCB_VIA*>( aItem ) );
177 break;
178
179 case PCB_SHAPE_T:
180 if( alreadyAdded( aItem ) )
181 return false;
182
183 if( !IsCopperLayer( aItem->GetLayer() ) )
184 return false;
185
186 add( m_itemList, static_cast<PCB_SHAPE*>( aItem ) );
187 break;
188
189 case PCB_ZONE_T:
190 {
191 ZONE* zone = static_cast<ZONE*>( aItem );
192
193 if( alreadyAdded( aItem ) )
194 return false;
195
196 m_itemMap[zone] = ITEM_MAP_ENTRY();
197
198 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
199 {
200 for( CN_ITEM* zitem : m_itemList.Add( zone, layer ) )
201 m_itemMap[zone].Link( zitem );
202 }
203 }
204 break;
205
206 default:
207 return false;
208 }
209
210 markItemNetAsDirty( aItem );
211
212 return true;
213}
214
215
217{
218#ifdef PROFILE
219 PROF_TIMER garbage_collection( "garbage-collection" );
220#endif
221 std::vector<CN_ITEM*> garbage;
222 garbage.reserve( 1024 );
223
225
226 for( CN_ITEM* item : garbage )
227 delete item;
228
229#ifdef PROFILE
230 garbage_collection.Show();
231 PROF_TIMER search_basic( "search-basic" );
232#endif
233
235 std::vector<CN_ITEM*> dirtyItems;
236 std::copy_if( m_itemList.begin(), m_itemList.end(), std::back_inserter( dirtyItems ),
237 [] ( CN_ITEM* aItem )
238 {
239 return aItem->Dirty();
240 } );
241
243 {
244 m_progressReporter->SetMaxProgress( dirtyItems.size() );
245
247 return;
248 }
249
250 if( m_itemList.IsDirty() )
251 {
252
253 std::vector<std::future<size_t>> returns( dirtyItems.size() );
254
255 auto conn_lambda =
256 [&dirtyItems]( size_t aItem, CN_LIST* aItemList,
257 PROGRESS_REPORTER* aReporter) -> size_t
258 {
259 if( aReporter && aReporter->IsCancelled() )
260 return 0;
261
262 CN_VISITOR visitor( dirtyItems[aItem] );
263 aItemList->FindNearby( dirtyItems[aItem], visitor );
264
265 if( aReporter )
266 aReporter->AdvanceProgress();
267
268 return 1;
269 };
270
271 for( size_t ii = 0; ii < dirtyItems.size(); ++ii )
272 returns[ii] = tp.submit( conn_lambda, ii, &m_itemList, m_progressReporter );
273
274 for( const std::future<size_t>& ret : returns )
275 {
276 // Here we balance returns with a 250ms timeout to allow UI updating
277 std::future_status status = ret.wait_for( std::chrono::milliseconds( 250 ) );
278
279 while( status != std::future_status::ready )
280 {
283
284 status = ret.wait_for( std::chrono::milliseconds( 250 ) );
285 }
286 }
287
290 }
291
292#ifdef PROFILE
293 search_basic.Show();
294#endif
295
297}
298
299
301{
302 if( aMode == CSM_PROPAGATE )
303 {
304 return SearchClusters( aMode,
306 PCB_SHAPE_T },
307 -1 );
308 }
309 else
310 {
311 return SearchClusters( aMode,
314 -1 );
315 }
316}
317
318
321 const std::initializer_list<KICAD_T>& aTypes,
322 int aSingleNet, CN_ITEM* rootItem )
323{
324 bool withinAnyNet = ( aMode != CSM_PROPAGATE );
325
326 std::deque<CN_ITEM*> Q;
327 std::set<CN_ITEM*> item_set;
328
329 CLUSTERS clusters;
330
331 if( m_itemList.IsDirty() )
333
334 auto addToSearchList =
335 [&item_set, withinAnyNet, aSingleNet, &aTypes, rootItem ]( CN_ITEM *aItem )
336 {
337 if( withinAnyNet && aItem->Net() <= 0 )
338 return;
339
340 if( !aItem->Valid() )
341 return;
342
343 if( aSingleNet >=0 && aItem->Net() != aSingleNet )
344 return;
345
346 bool found = false;
347
348 for( KICAD_T type : aTypes )
349 {
350 if( aItem->Parent()->Type() == type )
351 {
352 found = true;
353 break;
354 }
355 }
356
357 if( !found && aItem != rootItem )
358 return;
359
360 aItem->SetVisited( false );
361
362 item_set.insert( aItem );
363 };
364
365 std::for_each( m_itemList.begin(), m_itemList.end(), addToSearchList );
366
368 return CLUSTERS();
369
370 while( !item_set.empty() )
371 {
372 std::shared_ptr<CN_CLUSTER> cluster = std::make_shared<CN_CLUSTER>();
373 CN_ITEM* root;
374 auto it = item_set.begin();
375
376 while( it != item_set.end() && (*it)->Visited() )
377 it = item_set.erase( item_set.begin() );
378
379 if( it == item_set.end() )
380 break;
381
382 root = *it;
383 root->SetVisited( true );
384
385 Q.clear();
386 Q.push_back( root );
387
388 while( Q.size() )
389 {
390 CN_ITEM* current = Q.front();
391
392 Q.pop_front();
393 cluster->Add( current );
394
395 for( CN_ITEM* n : current->ConnectedItems() )
396 {
397 if( withinAnyNet && n->Net() != root->Net() )
398 continue;
399
400 if( !n->Visited() && n->Valid() )
401 {
402 n->SetVisited( true );
403 Q.push_back( n );
404 }
405 }
406 }
407
408 clusters.push_back( cluster );
409 }
410
412 return CLUSTERS();
413
414 std::sort( clusters.begin(), clusters.end(),
415 []( const std::shared_ptr<CN_CLUSTER>& a, const std::shared_ptr<CN_CLUSTER>& b )
416 {
417 return a->OriginNet() < b->OriginNet();
418 } );
419
420 return clusters;
421}
422
423
425{
426 // Generate CN_ZONE_LAYERs for each island on each layer of each zone
427 //
428 std::vector<CN_ZONE_LAYER*> zitems;
429
430 for( ZONE* zone : aBoard->Zones() )
431 {
432 if( zone->IsOnCopperLayer() )
433 {
434 m_itemMap[zone] = ITEM_MAP_ENTRY();
435 markItemNetAsDirty( zone );
436
437 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
438 {
439 if( IsCopperLayer( layer ) )
440 {
441 for( int j = 0; j < zone->GetFilledPolysList( layer )->OutlineCount(); j++ )
442 zitems.push_back( new CN_ZONE_LAYER( zone, layer, j ) );
443 }
444 }
445 }
446 }
447
448 // Setup progress metrics
449 //
450 int progressDelta = 50;
451 double size = 0.0;
452
453 size += zitems.size(); // Once for building RTrees
454 size += zitems.size(); // Once for adding to connectivity
455 size += aBoard->Tracks().size();
456 size += aBoard->Drawings().size();
457
458 for( FOOTPRINT* footprint : aBoard->Footprints() )
459 size += footprint->Pads().size();
460
461 size *= 1.5; // Our caller gets the other third of the progress bar
462
463 progressDelta = std::max( progressDelta, (int) size / 4 );
464
465 auto report =
466 [&]( int progress )
467 {
468 if( aReporter && ( progress % progressDelta ) == 0 )
469 {
470 aReporter->SetCurrentProgress( progress / size );
471 aReporter->KeepRefreshing( false );
472 }
473 };
474
475 // Generate RTrees for CN_ZONE_LAYER items (in parallel)
476 //
478 std::vector<std::future<size_t>> returns( zitems.size() );
479
480 auto cache_zones =
481 [aReporter]( CN_ZONE_LAYER* aZoneLayer ) -> size_t
482 {
483 if( aReporter && aReporter->IsCancelled() )
484 return 0;
485
486 aZoneLayer->BuildRTree();
487
488 if( aReporter )
489 aReporter->AdvanceProgress();
490
491 return 1;
492 };
493
494 for( size_t ii = 0; ii < zitems.size(); ++ii )
495 returns[ii] = tp.submit( cache_zones, zitems[ii] );
496
497 for( const std::future<size_t>& ret : returns )
498 {
499 std::future_status status = ret.wait_for( std::chrono::milliseconds( 250 ) );
500
501 while( status != std::future_status::ready )
502 {
503 if( aReporter )
504 aReporter->KeepRefreshing();
505
506 status = ret.wait_for( std::chrono::milliseconds( 250 ) );
507 }
508
509 }
510
511 // Add CN_ZONE_LAYERS, tracks, and pads to connectivity
512 //
513 int ii = zitems.size();
514
515 for( CN_ZONE_LAYER* zitem : zitems )
516 {
517 m_itemList.Add( zitem );
518 m_itemMap[ zitem->Parent() ].Link( zitem );
519 report( ++ii );
520 }
521
522 for( PCB_TRACK* tv : aBoard->Tracks() )
523 {
524 Add( tv );
525 report( ++ii );
526 }
527
528 for( FOOTPRINT* footprint : aBoard->Footprints() )
529 {
530 for( PAD* pad : footprint->Pads() )
531 {
532 Add( pad );
533 report( ++ii );
534 }
535 }
536
537 for( BOARD_ITEM* drawing : aBoard->Drawings() )
538 {
539 if( PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( drawing ) )
540 {
541 if( shape->IsOnCopperLayer() )
542 Add( shape );
543 }
544
545 report( ++ii );
546 }
547
548 if( aReporter )
549 {
550 aReporter->SetCurrentProgress( (double) ii / (double) size );
551 aReporter->KeepRefreshing( false );
552 }
553}
554
555
556void CN_CONNECTIVITY_ALGO::LocalBuild( const std::vector<BOARD_ITEM*>& aItems )
557{
558 for( BOARD_ITEM* item : aItems )
559 {
560 switch( item->Type() )
561 {
562 case PCB_TRACE_T:
563 case PCB_ARC_T:
564 case PCB_VIA_T:
565 case PCB_PAD_T:
566 case PCB_FOOTPRINT_T:
567 case PCB_SHAPE_T:
568 Add( item );
569 break;
570
571 default:
572 break;
573 }
574 }
575}
576
577
579{
580 for( const std::shared_ptr<CN_CLUSTER>& cluster : m_connClusters )
581 {
582 if( cluster->IsConflicting() )
583 {
584 // Conflicting pads in cluster: we don't know the user's intent so best to do
585 // nothing.
586 wxLogTrace( wxT( "CN" ), wxT( "Conflicting pads in cluster %p; skipping propagation" ),
587 cluster.get() );
588 }
589 else if( cluster->HasValidNet() )
590 {
591 // Propagate from the origin (will be a pad if there are any, or another item if
592 // there are no pads).
593 int n_changed = 0;
594
595 for( CN_ITEM* item : *cluster )
596 {
597 if( item->Valid() && item->CanChangeNet()
598 && item->Parent()->GetNetCode() != cluster->OriginNet() )
599 {
600 MarkNetAsDirty( item->Parent()->GetNetCode() );
601 MarkNetAsDirty( cluster->OriginNet() );
602
603 if( aCommit )
604 aCommit->Modify( item->Parent() );
605
606 item->Parent()->SetNetCode( cluster->OriginNet() );
607 n_changed++;
608 }
609 }
610
611 if( n_changed )
612 {
613 wxLogTrace( wxT( "CN" ), wxT( "Cluster %p: net: %d %s" ),
614 cluster.get(),
615 cluster->OriginNet(),
616 (const char*) cluster->OriginNetName().c_str() );
617 }
618 else
619 {
620 wxLogTrace( wxT( "CN" ), wxT( "Cluster %p: no changeable items to propagate to" ),
621 cluster.get() );
622 }
623 }
624 else
625 {
626 wxLogTrace( wxT( "CN" ), wxT( "Cluster %p: connected to unused net" ),
627 cluster.get() );
628 }
629 }
630}
631
632
634{
636 propagateConnections( aCommit );
637}
638
639
641 std::map<ZONE*, std::map<PCB_LAYER_ID, ISOLATED_ISLANDS>>& aMap,
642 bool aConnectivityAlreadyRebuilt )
643{
644 int progressDelta = 50;
645 int ii = 0;
646
647 progressDelta = std::max( progressDelta, (int) aMap.size() / 4 );
648
649 if( !aConnectivityAlreadyRebuilt )
650 {
651 for( const auto& [ zone, islands ] : aMap )
652 {
653 Remove( zone );
654 Add( zone );
655 ii++;
656
657 if( m_progressReporter && ( ii % progressDelta ) == 0 )
658 {
659 m_progressReporter->SetCurrentProgress( (double) ii / (double) aMap.size() );
661 }
662
664 return;
665 }
666 }
667
669
670 for( auto& [ zone, zoneIslands ] : aMap )
671 {
672 for( auto& [ layer, layerIslands ] : zoneIslands )
673 {
674 if( zone->GetFilledPolysList( layer )->IsEmpty() )
675 continue;
676
677 for( const std::shared_ptr<CN_CLUSTER>& cluster : m_connClusters )
678 {
679 for( CN_ITEM* item : *cluster )
680 {
681 if( item->Parent() == zone && item->Layer() == layer )
682 {
683 CN_ZONE_LAYER* z = static_cast<CN_ZONE_LAYER*>( item );
684
685 if( cluster->IsOrphaned() )
686 layerIslands.m_IsolatedOutlines.push_back( z->SubpolyIndex() );
687 else if( z->HasSingleConnection() )
688 layerIslands.m_SingleConnectionOutlines.push_back( z->SubpolyIndex() );
689 }
690 }
691 }
692 }
693 }
694}
695
696
698{
700 return m_ratsnestClusters;
701}
702
703
705{
706 if( aNet < 0 )
707 return;
708
709 if( (int) m_dirtyNets.size() <= aNet )
710 {
711 int lastNet = m_dirtyNets.size() - 1;
712
713 if( lastNet < 0 )
714 lastNet = 0;
715
716 m_dirtyNets.resize( aNet + 1 );
717
718 for( int i = lastNet; i < aNet + 1; i++ )
719 m_dirtyNets[i] = true;
720 }
721
722 m_dirtyNets[aNet] = true;
723}
724
725
727{
728 PCB_LAYER_ID layer = aZoneLayer->GetLayer();
729 BOARD_CONNECTED_ITEM* item = aItem->Parent();
730
731 if( !item->IsOnLayer( layer ) )
732 return;
733
734 auto connect =
735 [&]()
736 {
737 aZoneLayer->Connect( aItem );
738 aItem->Connect( aZoneLayer );
739 };
740
741 // Try quick checks first...
742 if( item->Type() == PCB_PAD_T )
743 {
744 PAD* pad = static_cast<PAD*>( item );
745
746 if( pad->ConditionallyFlashed( layer )
747 && pad->GetZoneLayerOverride( layer ) == ZLO_FORCE_NO_ZONE_CONNECTION )
748 {
749 return;
750 }
751 }
752 else if( item->Type() == PCB_VIA_T )
753 {
754 PCB_VIA* via = static_cast<PCB_VIA*>( item );
755
756 if( via->ConditionallyFlashed( layer )
757 && via->GetZoneLayerOverride( layer ) == ZLO_FORCE_NO_ZONE_CONNECTION )
758 {
759 return;
760 }
761 }
762
763 for( int i = 0; i < aItem->AnchorCount(); ++i )
764 {
765 if( aZoneLayer->ContainsPoint( aItem->GetAnchor( i ) ) )
766 {
767 connect();
768 return;
769 }
770 }
771
772 if( item->Type() == PCB_VIA_T || item->Type() == PCB_PAD_T )
773 {
774 // As long as the pad/via crosses the zone layer, check for the full effective shape
775 // We check for the overlapping layers above
776 if( aZoneLayer->Collide( item->GetEffectiveShape( layer, FLASHING::ALWAYS_FLASHED ).get() ) )
777 connect();
778
779 return;
780 }
781
782 if( aZoneLayer->Collide( item->GetEffectiveShape( layer ).get() ) )
783 connect();
784}
785
787{
788 const ZONE* zoneA = static_cast<const ZONE*>( aZoneLayerA->Parent() );
789 const ZONE* zoneB = static_cast<const ZONE*>( aZoneLayerB->Parent() );
790
791 const BOX2I& boxA = aZoneLayerA->BBox();
792 const BOX2I& boxB = aZoneLayerB->BBox();
793
794 PCB_LAYER_ID layer = aZoneLayerA->GetLayer();
795
796 if( aZoneLayerB->GetLayer() != layer )
797 return;
798
799 if( !boxA.Intersects( boxB ) )
800 return;
801
802 const SHAPE_LINE_CHAIN& outline =
803 zoneA->GetFilledPolysList( layer )->COutline( aZoneLayerA->SubpolyIndex() );
804
805 for( int i = 0; i < outline.PointCount(); i++ )
806 {
807 if( !boxB.Contains( outline.CPoint( i ) ) )
808 continue;
809
810 if( aZoneLayerB->ContainsPoint( outline.CPoint( i ) ) )
811 {
812 aZoneLayerA->Connect( aZoneLayerB );
813 aZoneLayerB->Connect( aZoneLayerA );
814 return;
815 }
816 }
817
818 const SHAPE_LINE_CHAIN& outline2 =
819 zoneB->GetFilledPolysList( layer )->COutline( aZoneLayerB->SubpolyIndex() );
820
821 for( int i = 0; i < outline2.PointCount(); i++ )
822 {
823 if( !boxA.Contains( outline2.CPoint( i ) ) )
824 continue;
825
826 if( aZoneLayerA->ContainsPoint( outline2.CPoint( i ) ) )
827 {
828 aZoneLayerA->Connect( aZoneLayerB );
829 aZoneLayerB->Connect( aZoneLayerA );
830 return;
831 }
832 }
833}
834
835
837{
838 const BOARD_CONNECTED_ITEM* parentA = aCandidate->Parent();
839 const BOARD_CONNECTED_ITEM* parentB = m_item->Parent();
840
841 if( !aCandidate->Valid() || !m_item->Valid() )
842 return true;
843
844 if( parentA == parentB )
845 return true;
846
847 // Don't connect items in different nets that can't be changed
848 if( !aCandidate->CanChangeNet() && !m_item->CanChangeNet() && aCandidate->Net() != m_item->Net() )
849 return true;
850
851 // If both m_item and aCandidate are marked dirty, they will both be searched
852 // Since we are reciprocal in our connection, we arbitrarily pick one of the connections
853 // to conduct the expensive search
854 if( aCandidate->Dirty() && aCandidate < m_item )
855 return true;
856
857 // We should handle zone-zone connection separately
858 if ( parentA->Type() == PCB_ZONE_T && parentB->Type() == PCB_ZONE_T )
859 {
861 static_cast<CN_ZONE_LAYER*>( aCandidate ) );
862 return true;
863 }
864
865 if( parentA->Type() == PCB_ZONE_T )
866 {
867 checkZoneItemConnection( static_cast<CN_ZONE_LAYER*>( aCandidate ), m_item );
868 return true;
869 }
870
871 if( parentB->Type() == PCB_ZONE_T )
872 {
873 checkZoneItemConnection( static_cast<CN_ZONE_LAYER*>( m_item ), aCandidate );
874 return true;
875 }
876
877 LSET commonLayers = parentA->GetLayerSet() & parentB->GetLayerSet();
878
879 for( PCB_LAYER_ID layer : commonLayers.Seq() )
880 {
881 FLASHING flashingA = FLASHING::NEVER_FLASHED;
882 FLASHING flashingB = FLASHING::NEVER_FLASHED;
883
884 if( parentA->Type() == PCB_PAD_T )
885 {
886 if( !static_cast<const PAD*>( parentA )->ConditionallyFlashed( layer ) )
887 flashingA = FLASHING::ALWAYS_FLASHED;
888 }
889 else if( parentA->Type() == PCB_VIA_T )
890 {
891 if( !static_cast<const PCB_VIA*>( parentA )->ConditionallyFlashed( layer ) )
892 flashingA = FLASHING::ALWAYS_FLASHED;
893 }
894
895 if( parentB->Type() == PCB_PAD_T )
896 {
897 if( !static_cast<const PAD*>( parentB )->ConditionallyFlashed( layer ) )
898 flashingB = FLASHING::ALWAYS_FLASHED;
899 }
900 else if( parentB->Type() == PCB_VIA_T )
901 {
902 if( !static_cast<const PCB_VIA*>( parentB )->ConditionallyFlashed( layer ) )
903 flashingB = FLASHING::ALWAYS_FLASHED;
904 }
905
906 if( parentA->GetEffectiveShape( layer, flashingA )->Collide(
907 parentB->GetEffectiveShape( layer, flashingB ).get() ) )
908 {
909 m_item->Connect( aCandidate );
910 aCandidate->Connect( m_item );
911 return true;
912 }
913 }
914
915 return true;
916};
917
918
920{
921 m_ratsnestClusters.clear();
922 m_connClusters.clear();
923 m_itemMap.clear();
925
926}
927
929{
930 m_progressReporter = aReporter;
931}
@ ZLO_FORCE_NO_ZONE_CONNECTION
Definition: board_item.h:67
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:204
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:134
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:269
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.
Definition: board_item.cpp:227
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:247
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:209
virtual bool IsOnCopperLayer() const
Definition: board_item.h:142
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:271
ZONES & Zones()
Definition: board.h:319
FOOTPRINTS & Footprints()
Definition: board.h:313
TRACKS & Tracks()
Definition: board.h:310
DRAWINGS & Drawings()
Definition: board.h:316
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:270
bool Contains(const Vec &aPoint) const
Definition: box2.h:142
void FillIsolatedIslandsMap(std::map< ZONE *, std::map< PCB_LAYER_ID, ISOLATED_ISLANDS > > &aMap, bool aConnectivityAlreadyRebuilt)
Fill in the isolated islands map with copper islands that are not connected to a net.
bool Remove(BOARD_ITEM *aItem)
void add(Container &c, BItem brditem)
PROGRESS_REPORTER * m_progressReporter
std::vector< std::shared_ptr< CN_CLUSTER > > m_connClusters
void propagateConnections(BOARD_COMMIT *aCommit=nullptr)
const CLUSTERS & GetClusters()
const CLUSTERS SearchClusters(CLUSTER_SEARCH_MODE aMode, const std::initializer_list< KICAD_T > &aTypes, int aSingleNet, CN_ITEM *rootItem=nullptr)
void Build(BOARD *aZoneLayer, PROGRESS_REPORTER *aReporter=nullptr)
void MarkNetAsDirty(int aNet)
void markItemNetAsDirty(const BOARD_ITEM *aItem)
std::vector< std::shared_ptr< CN_CLUSTER > > m_ratsnestClusters
void PropagateNets(BOARD_COMMIT *aCommit=nullptr)
Propagate nets from pads to other items in clusters.
std::vector< bool > m_dirtyNets
std::vector< std::shared_ptr< CN_CLUSTER > > CLUSTERS
void LocalBuild(const std::vector< BOARD_ITEM * > &aItems)
std::unordered_map< const BOARD_ITEM *, ITEM_MAP_ENTRY > m_itemMap
void SetProgressReporter(PROGRESS_REPORTER *aReporter)
bool Add(BOARD_ITEM *aItem)
CN_ITEM represents a BOARD_CONNETED_ITEM in the connectivity system (ie: a pad, track/arc/via,...
void Connect(CN_ITEM *b)
const BOX2I & BBox()
virtual int AnchorCount() const
const std::vector< CN_ITEM * > & ConnectedItems() const
int Net() const
bool Valid() const
virtual const VECTOR2I GetAnchor(int n) const
bool CanChangeNet() const
void SetVisited(bool aVisited)
bool Dirty() const
BOARD_CONNECTED_ITEM * Parent() const
CN_ITEM * Add(PAD *pad)
std::vector< CN_ITEM * >::iterator begin()
void SetDirty(bool aDirty=true)
bool IsDirty() const
std::vector< CN_ITEM * >::iterator end()
void ClearDirtyFlags()
void SetHasInvalid(bool aInvalid=true)
void RemoveInvalidItems(std::vector< CN_ITEM * > &aGarbage)
void checkZoneItemConnection(CN_ZONE_LAYER *aZoneLayer, CN_ITEM *aItem)
CN_ITEM * m_item
The item we are looking for connections to.
void checkZoneZoneConnection(CN_ZONE_LAYER *aZoneLayerA, CN_ZONE_LAYER *aZoneLayerB)
bool operator()(CN_ITEM *aCandidate)
PCB_LAYER_ID GetLayer() const
bool Collide(SHAPE *aRefShape) const
int SubpolyIndex() const
bool ContainsPoint(const VECTOR2I &p) const
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Definition: commit.h:103
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
PADS & Pads()
Definition: footprint.h:188
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:552
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
Handle the data for a net.
Definition: netinfo.h:67
Definition: pad.h:58
A small class to help profiling.
Definition: profile.h:47
void Show(std::ostream &aStream=std::cerr)
Print the elapsed time (in a suitable unit) to a stream.
Definition: profile.h:103
A progress reporter interface for use in multi-threaded environments.
virtual bool IsCancelled() const =0
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void AdvanceProgress()=0
Increment the progress bar length (inside the current virtual zone).
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).
virtual void SetMaxProgress(int aMaxProgress)=0
Fix the value that gives the 100 percent progress bar length (inside the current virtual zone).
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
const std::shared_ptr< SHAPE_POLY_SET > & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition: zone.h:615
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:129
@ FP_JUST_ADDED
Definition: footprint.h:77
a few functions useful in geometry calculations.
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:148
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:847
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
static thread_pool * tp
Definition: thread_pool.cpp:30
BS::thread_pool thread_pool
Definition: thread_pool.h:30
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
Definition: thread_pool.cpp:32
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:94
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition: typeinfo.h:104
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:95
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:106
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:93