KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_allegro_import.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
24
25#include "allegro_test_utils.h"
29
31
32#include <board.h>
34#include <footprint.h>
35#include <pad.h>
36#include <pcb_shape.h>
37#include <pcb_text.h>
38#include <pcb_track.h>
39#include <zone.h>
41#include <netinfo.h>
42#include <netclass.h>
45#include <reporter.h>
46
47#include <algorithm>
48#include <cstdlib>
49#include <filesystem>
50#include <functional>
51#include <fstream>
52#include <map>
53#include <set>
54
55using namespace KI_TEST;
56
57
59{
61
62 std::unique_ptr<BOARD> LoadAllegroBoard( const std::string& aFileName )
63 {
64 std::string dataPath = KI_TEST::AllegroBoardFile( aFileName );
65
66 return m_allegroPlugin.LoadBoard( dataPath );
67 }
68
70};
71
72
73BOOST_FIXTURE_TEST_SUITE( AllegroImport, ALLEGRO_IMPORT_FIXTURE )
74
75
76
79BOOST_AUTO_TEST_CASE( FootprintRefDes )
80{
81 std::unique_ptr<BOARD> board = LoadAllegroBoard( "TRS80_POWER/TRS80_POWER.brd" );
82
83 BOOST_REQUIRE( board != nullptr );
84
85 int emptyRefDesCount = 0;
86 int validRefDesCount = 0;
87
88 for( FOOTPRINT* fp : board->Footprints() )
89 {
90 wxString refdes = fp->GetReference();
91
92 if( refdes.IsEmpty() )
93 emptyRefDesCount++;
94 else
95 validRefDesCount++;
96 }
97
98 BOOST_TEST_MESSAGE( "Valid RefDes: " << validRefDesCount << ", Empty: " << emptyRefDesCount );
99
100 // Most footprints should have valid reference designators
101 BOOST_CHECK_GT( validRefDesCount, emptyRefDesCount );
102}
103
104
108BOOST_AUTO_TEST_CASE( UnreferencedFootprintsAreBoardOnly )
109{
110 std::unique_ptr<BOARD> board = LoadAllegroBoard( "TRS80_POWER/TRS80_POWER.brd" );
111
112 BOOST_REQUIRE( board != nullptr );
113
114 int unreferenced = 0;
115
116 for( FOOTPRINT* fp : board->Footprints() )
117 {
118 if( !fp->GetReference().IsEmpty() )
119 continue;
120
121 unreferenced++;
122 BOOST_CHECK( fp->GetAttributes() & FP_BOARD_ONLY );
123 }
124
125 BOOST_CHECK_GT( unreferenced, 0 );
126}
127
128
132BOOST_AUTO_TEST_CASE( FootprintLibItemNames )
133{
134 std::unique_ptr<BOARD> board = LoadAllegroBoard( "TRS80_POWER/TRS80_POWER.brd" );
135
136 BOOST_REQUIRE( board != nullptr );
137
138 int unnamed = 0;
139
140 for( FOOTPRINT* fp : board->Footprints() )
141 {
142 BOOST_TEST_MESSAGE( fp->GetReference() << " -> " << fp->GetFPID().GetLibItemName().wx_str() );
143
144 if( !fp->GetReference().IsEmpty() && fp->GetFPID().GetLibItemName().empty() )
145 unnamed++;
146
147 BOOST_CHECK( fp->GetFPID().GetLibNickname().empty() );
148 }
149
150 BOOST_CHECK_EQUAL( unnamed, 0 );
151}
152
153
157BOOST_AUTO_TEST_CASE( UnplatedHolesHaveSize )
158{
159 std::unique_ptr<BOARD> board = LoadAllegroBoard( "EVK_BaseBoard/EVK_BaseBoard.brd" );
160
161 BOOST_REQUIRE( board != nullptr );
162
163 int zeroSized = 0;
164
165 for( FOOTPRINT* fp : board->Footprints() )
166 {
167 for( PAD* pad : fp->Pads() )
168 {
169 pad->Padstack().ForEachUniqueLayer(
170 [&]( PCB_LAYER_ID layer )
171 {
172 if( pad->GetSize( layer ).x <= 0 || pad->GetSize( layer ).y <= 0 )
173 zeroSized++;
174 } );
175 }
176 }
177
178 BOOST_CHECK_EQUAL( zeroSized, 0 );
179}
180
181
185BOOST_AUTO_TEST_CASE( NearStraightArcsSurviveReorientation )
186{
187 const char* corpusEnv = std::getenv( "KICAD_ORCAD_CORPUS" );
188
189 if( !corpusEnv || !*corpusEnv )
190 return;
191
192 std::filesystem::path brd;
193
194 for( const std::filesystem::directory_entry& entry : std::filesystem::recursive_directory_iterator( corpusEnv ) )
195 {
196 if( entry.is_regular_file() && entry.path().filename() == "EDA-02862-V1-0.brd" )
197 brd = entry.path();
198 }
199
200 if( brd.empty() )
201 return;
202
203 std::unique_ptr<BOARD> board = m_allegroPlugin.LoadBoard( brd.string() );
204
205 BOOST_REQUIRE( board != nullptr );
206
207 for( FOOTPRINT* fp : board->Footprints() )
208 {
209 std::unique_ptr<FOOTPRINT> copy( static_cast<FOOTPRINT*>( fp->Clone() ) );
210 copy->SetOrientation( ANGLE_0 );
211 }
212}
213
214
218BOOST_AUTO_TEST_CASE( Release161Loads )
219{
220 const char* corpusEnv = std::getenv( "KICAD_ORCAD_CORPUS" );
221
222 if( !corpusEnv || !*corpusEnv )
223 return;
224
225 std::filesystem::path brd;
226
227 for( const std::filesystem::directory_entry& entry : std::filesystem::recursive_directory_iterator( corpusEnv ) )
228 {
229 if( entry.is_regular_file() && entry.path().filename() == "EDA-02152-V1-0.brd" )
230 brd = entry.path();
231 }
232
233 if( brd.empty() )
234 return;
235
236 std::unique_ptr<BOARD> board = m_allegroPlugin.LoadBoard( brd.string() );
237
238 BOOST_REQUIRE( board != nullptr );
239 BOOST_CHECK_EQUAL( board->Footprints().size(), 61u );
240}
241
242
246BOOST_AUTO_TEST_CASE( PlaneLayerLinesAreNotCopper )
247{
248 std::unique_ptr<BOARD> board = LoadAllegroBoard( "EVK_BaseBoard/EVK_BaseBoard.brd" );
249
250 BOOST_REQUIRE( board != nullptr );
251
252 int copperLines = 0;
253
254 for( BOARD_ITEM* item : board->Drawings() )
255 {
256 if( item->Type() == PCB_SHAPE_T && IsInnerCopperLayer( item->GetLayer() ) )
257 copperLines++;
258 }
259
260 BOOST_CHECK_EQUAL( copperLines, 0 );
261}
262
263
268BOOST_AUTO_TEST_CASE( PlaneLayerLinesAreNotCopperBefore165 )
269{
270 const char* corpusEnv = std::getenv( "KICAD_ORCAD_CORPUS" );
271
272 if( !corpusEnv || !*corpusEnv )
273 return;
274
275 std::filesystem::path brd;
276
277 for( const std::filesystem::directory_entry& entry : std::filesystem::recursive_directory_iterator( corpusEnv ) )
278 {
279 if( entry.is_regular_file() && entry.path().filename() == "EDA-02152-V1-0.brd" )
280 brd = entry.path();
281 }
282
283 if( brd.empty() )
284 return;
285
286 std::unique_ptr<BOARD> board = m_allegroPlugin.LoadBoard( brd.string() );
287
288 BOOST_REQUIRE( board != nullptr );
289
290 int copperLines = 0;
291
292 for( BOARD_ITEM* item : board->Drawings() )
293 {
294 if( item->Type() == PCB_SHAPE_T && IsInnerCopperLayer( item->GetLayer() )
295 && static_cast<PCB_SHAPE*>( item )->GetShape() == SHAPE_T::SEGMENT )
296 {
297 copperLines++;
298 }
299 }
300
301 BOOST_CHECK_EQUAL( copperLines, 0 );
302}
303
304
308BOOST_AUTO_TEST_CASE( OverlappingPadsAreNetTie )
309{
310 const char* corpusEnv = std::getenv( "KICAD_ORCAD_CORPUS" );
311
312 if( !corpusEnv || !*corpusEnv )
313 return;
314
315 std::filesystem::path brd;
316
317 for( const std::filesystem::directory_entry& entry : std::filesystem::recursive_directory_iterator( corpusEnv ) )
318 {
319 if( entry.is_regular_file() && entry.path().filename() == "USB-PD w QC3_0.brd" )
320 brd = entry.path();
321 }
322
323 if( brd.empty() )
324 return;
325
326 std::unique_ptr<BOARD> board = m_allegroPlugin.LoadBoard( brd.string() );
327
328 BOOST_REQUIRE( board != nullptr );
329
330 FOOTPRINT* tie = board->FindFootprintByReference( wxS( "NT1" ) );
331
332 BOOST_REQUIRE( tie != nullptr );
333 BOOST_REQUIRE_EQUAL( tie->GetNetTiePadGroups().size(), 1 );
334 BOOST_CHECK_EQUAL( tie->GetNetTiePadGroups()[0], wxS( "1,2" ) );
335}
336
337
341BOOST_AUTO_TEST_CASE( V164PadstackMaskAndPaste )
342{
343 const char* corpusEnv = std::getenv( "KICAD_ORCAD_CORPUS" );
344
345 if( !corpusEnv || !*corpusEnv )
346 return;
347
348 // EDA-02016 has 8 NOPM_* SMD padstacks, 4 of them also NOSM_*. EDA-03470 has 4 NOPM_* and 6 fiducials
349 // without paste, and its 7 bottom-start pads keep their opening in the bottom mask slot.
350 const std::map<std::string, std::pair<int, int>> expected = { { "EDA-02016-V8-0.brd", { 43, 4 } },
351 { "EDA-03470-V1-0.brd", { 138, 0 } } };
352
353 std::map<std::string, std::filesystem::path> boards;
354
355 for( const std::filesystem::directory_entry& entry : std::filesystem::recursive_directory_iterator( corpusEnv ) )
356 {
357 if( entry.is_regular_file() && expected.count( entry.path().filename().string() ) )
358 boards[entry.path().filename().string()] = entry.path();
359 }
360
361 for( const auto& [name, brd] : boards )
362 {
364 {
365 std::unique_ptr<BOARD> board = m_allegroPlugin.LoadBoard( brd.string() );
366
367 BOOST_REQUIRE( board != nullptr );
368
369 int pasted = 0;
370 int unmasked = 0;
371
372 for( FOOTPRINT* fp : board->Footprints() )
373 {
374 for( PAD* pad : fp->Pads() )
375 {
376 if( pad->GetAttribute() != PAD_ATTRIB::SMD )
377 continue;
378
379 const LSET layers = pad->GetLayerSet();
380
381 if( layers.Contains( F_Paste ) || layers.Contains( B_Paste ) )
382 pasted++;
383
384 if( !layers.Contains( F_Mask ) && !layers.Contains( B_Mask ) )
385 unmasked++;
386 }
387 }
388
389 BOOST_CHECK_EQUAL( pasted, expected.at( name ).first );
390 BOOST_CHECK_EQUAL( unmasked, expected.at( name ).second );
391 }
392 }
393}
394
395
399BOOST_AUTO_TEST_CASE( EdgeConnectorBottomFingers )
400{
401 const char* corpusEnv = std::getenv( "KICAD_ORCAD_CORPUS" );
402
403 if( !corpusEnv || !*corpusEnv )
404 return;
405
406 std::filesystem::path brd;
407
408 for( const std::filesystem::directory_entry& entry : std::filesystem::recursive_directory_iterator( corpusEnv ) )
409 {
410 if( entry.is_regular_file() && entry.path().filename() == "600-20192-01_CYW920822M2P4XXI040_REV1.0.brd" )
411 brd = entry.path();
412 }
413
414 if( brd.empty() )
415 return;
416
417 std::unique_ptr<BOARD> board = m_allegroPlugin.LoadBoard( brd.string() );
418
419 BOOST_REQUIRE( board != nullptr );
420
421 FOOTPRINT* edge = board->FindFootprintByReference( wxS( "J1" ) );
422
423 BOOST_REQUIRE( edge != nullptr );
424
425 const PAD* top = edge->FindPadByNumber( wxS( "39" ) );
426 const PAD* bottom = edge->FindPadByNumber( wxS( "40" ) );
427
428 BOOST_REQUIRE( top && bottom );
429 BOOST_CHECK( top->IsOnLayer( F_Cu ) && !top->IsOnLayer( B_Cu ) );
430 BOOST_CHECK( bottom->IsOnLayer( B_Cu ) && !bottom->IsOnLayer( F_Cu ) );
431 BOOST_CHECK( bottom->IsOnLayer( B_Mask ) && !bottom->IsOnLayer( F_Mask ) );
432}
433
434
438BOOST_AUTO_TEST_CASE( AntiEtchLinesAreNotCopper )
439{
440 const char* corpusEnv = std::getenv( "KICAD_ORCAD_CORPUS" );
441
442 if( !corpusEnv || !*corpusEnv )
443 return;
444
445 std::filesystem::path brd;
446
447 for( const std::filesystem::directory_entry& entry : std::filesystem::recursive_directory_iterator( corpusEnv ) )
448 {
449 if( entry.is_regular_file() && entry.path().filename() == "EDA-02067-V1-0.brd" )
450 brd = entry.path();
451 }
452
453 if( brd.empty() )
454 return;
455
456 std::unique_ptr<BOARD> board = m_allegroPlugin.LoadBoard( brd.string() );
457
458 BOOST_REQUIRE( board != nullptr );
459
460 int copperLines = 0;
461
462 for( BOARD_ITEM* item : board->Drawings() )
463 {
464 if( item->Type() == PCB_SHAPE_T && IsInnerCopperLayer( item->GetLayer() )
465 && static_cast<PCB_SHAPE*>( item )->GetShape() == SHAPE_T::SEGMENT )
466 {
467 copperLines++;
468 }
469 }
470
471 BOOST_CHECK_EQUAL( copperLines, 0 );
472}
473
474
478BOOST_AUTO_TEST_CASE( PlaneCopperIsAZone )
479{
480 const char* corpusEnv = std::getenv( "KICAD_ORCAD_CORPUS" );
481
482 if( !corpusEnv || !*corpusEnv )
483 return;
484
485 std::filesystem::path brd;
486
487 for( const std::filesystem::directory_entry& entry : std::filesystem::recursive_directory_iterator( corpusEnv ) )
488 {
489 if( entry.is_regular_file() && entry.path().filename() == "EDA-02153-V1-0.brd" )
490 brd = entry.path();
491 }
492
493 if( brd.empty() )
494 return;
495
496 std::unique_ptr<BOARD> board = m_allegroPlugin.LoadBoard( brd.string() );
497
498 BOOST_REQUIRE( board != nullptr );
499
500 int planePolygons = 0;
501 int planeZones = 0;
502
503 for( BOARD_ITEM* item : board->Drawings() )
504 {
505 if( item->Type() == PCB_SHAPE_T && IsInnerCopperLayer( item->GetLayer() )
506 && static_cast<PCB_SHAPE*>( item )->GetShape() == SHAPE_T::POLY )
507 {
508 planePolygons++;
509 }
510 }
511
512 for( ZONE* zone : board->Zones() )
513 {
514 if( !zone->GetIsRuleArea() && IsInnerCopperLayer( zone->GetFirstLayer() ) && zone->GetNetCode() > 0 )
515 {
516 planeZones++;
517
518 // The board's rules set the clearance, and thin fill is not dropped
519 BOOST_CHECK( zone->GetLocalClearance().has_value() );
520 BOOST_CHECK_EQUAL( zone->GetLocalClearance().value_or( -1 ), 0 );
521 BOOST_CHECK_EQUAL( zone->GetMinThickness(), 0 );
522 }
523 }
524
525 BOOST_CHECK_EQUAL( planePolygons, 0 );
526 BOOST_CHECK_GT( planeZones, 0 );
527
528 KI_TEST::FillZones( board.get() );
529
530 int filledPlanes = 0;
531 int coveredVias = 0;
532
533 for( ZONE* zone : board->Zones() )
534 {
535 PCB_LAYER_ID layer = zone->GetFirstLayer();
536
537 if( !zone->GetIsRuleArea() && IsInnerCopperLayer( layer ) && zone->HasFilledPolysForLayer( layer )
538 && !zone->GetFilledPolysList( layer )->IsEmpty() )
539 {
540 filledPlanes++;
541 }
542 }
543
544 for( PCB_TRACK* track : board->Tracks() )
545 {
546 if( track->Type() != PCB_VIA_T )
547 continue;
548
549 for( ZONE* zone : board->Zones() )
550 {
551 PCB_LAYER_ID layer = zone->GetFirstLayer();
552
553 if( zone->GetIsRuleArea() || zone->GetNetCode() == track->GetNetCode() || !IsInnerCopperLayer( layer )
554 || !track->IsOnLayer( layer ) || !zone->HasFilledPolysForLayer( layer ) )
555 {
556 continue;
557 }
558
559 if( zone->GetFilledPolysList( layer )->Collide( track->GetEffectiveShape( layer ).get() ) )
560 coveredVias++;
561 }
562 }
563
564 BOOST_CHECK_GT( filledPlanes, 0 );
565 BOOST_CHECK_EQUAL( coveredVias, 0 );
566}
567
568
572BOOST_AUTO_TEST_CASE( PlaneFillRespectsVoids )
573{
574 std::unique_ptr<BOARD> board = LoadAllegroBoard( "EVK_BaseBoard/EVK_BaseBoard.brd" );
575
576 BOOST_REQUIRE( board != nullptr );
577
578 std::vector<ZONE*> voids;
579
580 for( ZONE* zone : board->Zones() )
581 {
582 if( zone->GetIsRuleArea() && zone->GetZoneName() == wxS( "Plane void" ) )
583 voids.push_back( zone );
584 }
585
586 BOOST_REQUIRE( !voids.empty() );
587
588 // A zone is saved with only its first polygon, so each void area holds exactly one
589 for( ZONE* area : voids )
590 BOOST_CHECK_EQUAL( area->Outline()->OutlineCount(), 1 );
591
592 KI_TEST::FillZones( board.get() );
593
594 double overlap = 0;
595
596 for( ZONE* area : voids )
597 {
598 PCB_LAYER_ID layer = area->GetFirstLayer();
599
600 for( ZONE* zone : board->Zones() )
601 {
602 if( zone->GetIsRuleArea() || !zone->IsOnLayer( layer ) || !zone->HasFilledPolysForLayer( layer ) )
603 continue;
604
605 SHAPE_POLY_SET common( *zone->GetFilledPolysList( layer ) );
606 common.BooleanIntersection( *area->Outline() );
607 overlap += common.Area();
608 }
609 }
610
611 // slivers from rounding are fine, a closed void is not
612 BOOST_CHECK_LT( overlap, 1e10 );
613}
614
615
619BOOST_AUTO_TEST_CASE( CustomPadsAreOnePolygon )
620{
621 for( const char* name : { "EVK_BaseBoard/EVK_BaseBoard.brd", "EVK_SOM/EVK_SOM.brd",
622 "BeagleBone-AI/BeagleBone-AI.brd", "CutiePi_V2_3_v166/CutiePi_V2_3.brd",
623 "mainBoard/mainBoard.brd", "ABX00162_UNOQ/20250806_UNOQ.brd" } )
624 {
625 std::unique_ptr<BOARD> board = LoadAllegroBoard( name );
626
627 BOOST_REQUIRE( board );
628
629 int multi = 0;
630
631 for( FOOTPRINT* fp : board->Footprints() )
632 {
633 for( PAD* pad : fp->Pads() )
634 {
635 for( PCB_LAYER_ID layer : pad->Padstack().UniqueLayers() )
636 {
637 if( pad->GetShape( layer ) != PAD_SHAPE::CUSTOM )
638 continue;
639
640 if( pad->GetEffectivePolygon( layer )->OutlineCount() != 1 )
641 multi++;
642 }
643 }
644 }
645
646 BOOST_TEST_CONTEXT( name ) { BOOST_CHECK_EQUAL( multi, 0 ); }
647 }
648}
649
650
655{
656 std::unique_ptr<BOARD> board = LoadAllegroBoard( "TRS80_POWER/TRS80_POWER.brd" );
657
658 BOOST_REQUIRE( board != nullptr );
659
660 int validPadCount = 0;
661 int zeroPadCount = 0;
662 int hugePadCount = 0;
663
664 for( FOOTPRINT* fp : board->Footprints() )
665 {
666 for( PAD* pad : fp->Pads() )
667 {
668 VECTOR2I size = pad->GetSize( F_Cu );
669
670 if( size.x == 0 || size.y == 0 )
671 {
672 zeroPadCount++;
673 BOOST_TEST_MESSAGE( "Zero-size pad in " << fp->GetReference() << " pad "
674 << pad->GetNumber() );
675 }
676 else if( size.x > 50000000 || size.y > 50000000 ) // > 50mm is suspicious
677 {
678 hugePadCount++;
679 BOOST_TEST_MESSAGE( "Huge pad in " << fp->GetReference() << " pad " << pad->GetNumber()
680 << ": " << size.x / 1000000.0 << "mm x "
681 << size.y / 1000000.0 << "mm" );
682 }
683 else
684 {
685 validPadCount++;
686 }
687 }
688 }
689
690 BOOST_TEST_MESSAGE( "Valid pads: " << validPadCount << ", Zero: " << zeroPadCount
691 << ", Huge: " << hugePadCount );
692
693 // No pads should be zero-size (this catches hardcoded fallbacks)
694 BOOST_CHECK_EQUAL( zeroPadCount, 0 );
695}
696
697
702{
703 std::unique_ptr<BOARD> board = LoadAllegroBoard( "TRS80_POWER/TRS80_POWER.brd" );
704
705 BOOST_REQUIRE( board != nullptr );
706
707 int validViaCount = 0;
708 int suspiciousViaCount = 0;
709
710 // Count vias with the hardcoded size (1000000 = 1mm exactly)
711 const int HARDCODED_SIZE = 1000000;
712
713 for( PCB_TRACK* track : board->Tracks() )
714 {
715 if( track->Type() == PCB_VIA_T )
716 {
717 PCB_VIA* via = static_cast<PCB_VIA*>( track );
718 int width = via->GetWidth( F_Cu );
719
720 if( width == HARDCODED_SIZE )
721 {
722 suspiciousViaCount++;
723 }
724 else if( width > 0 && width < 10000000 ) // 0 < size < 10mm is reasonable
725 {
726 validViaCount++;
727 }
728 }
729 }
730
731 BOOST_TEST_MESSAGE( "Valid vias: " << validViaCount << ", Hardcoded-size vias: " << suspiciousViaCount );
732
733 // This test will fail until via size is properly extracted from padstack
734 if( suspiciousViaCount > 0 )
735 {
736 BOOST_WARN_MESSAGE( false, "Found " << suspiciousViaCount << " vias with hardcoded 1mm size" );
737 }
738}
739
740
745{
746 std::unique_ptr<BOARD> board = LoadAllegroBoard( "TRS80_POWER/TRS80_POWER.brd" );
747
748 BOOST_REQUIRE( board != nullptr );
749
750 int validTrackCount = 0;
751 int zeroTrackCount = 0;
752
753 for( PCB_TRACK* track : board->Tracks() )
754 {
755 if( track->Type() == PCB_TRACE_T )
756 {
757 int width = track->GetWidth();
758
759 if( width == 0 )
760 zeroTrackCount++;
761 else if( width > 0 && width < 10000000 ) // 0 < width < 10mm
762 validTrackCount++;
763 }
764 }
765
766 BOOST_TEST_MESSAGE( "Valid tracks: " << validTrackCount << ", Zero-width: " << zeroTrackCount );
767
768 BOOST_CHECK_EQUAL( zeroTrackCount, 0 );
769}
770
771
776{
777 std::unique_ptr<BOARD> board = LoadAllegroBoard( "TRS80_POWER/TRS80_POWER.brd" );
778
779 BOOST_REQUIRE( board != nullptr );
780
781 int numberedPads = 0;
782 int unnumberedPads = 0;
783
784 for( FOOTPRINT* fp : board->Footprints() )
785 {
786 for( PAD* pad : fp->Pads() )
787 {
788 if( pad->GetNumber().IsEmpty() )
789 unnumberedPads++;
790 else
791 numberedPads++;
792 }
793 }
794
795 BOOST_TEST_MESSAGE( "Numbered pads: " << numberedPads << ", Unnumbered: " << unnumberedPads );
796
797 // All pads should have numbers for proper netlist generation
798 // This test will fail until pad numbers are properly set
799 if( unnumberedPads > 0 )
800 {
801 BOOST_WARN_MESSAGE( false, "Found " << unnumberedPads << " pads without numbers" );
802 }
803}
804
805
806static unsigned CountOutlineElements( const BOARD& board )
807{
808 unsigned count = 0;
809 for( const BOARD_ITEM* item : board.Drawings() )
810 {
811 if( item->Type() == PCB_SHAPE_T && item->GetLayer() == Edge_Cuts )
812 {
813 count++;
814 }
815 }
816 return count;
817}
818
819
820static void AssertOutlineValid( const BOARD& aBoard )
821{
822 // Verify outline forms a closed contour by checking that all segments connect
823 std::vector<SEG> outlineSegs;
824
825 for( BOARD_ITEM* item : aBoard.Drawings() )
826 {
827 if( item->Type() == PCB_SHAPE_T && item->GetLayer() == Edge_Cuts )
828 {
829 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
830 switch( shape->GetShape() )
831 {
832 case SHAPE_T::SEGMENT:
833 case SHAPE_T::ARC:
834 case SHAPE_T::BEZIER:
835 {
836 outlineSegs.push_back( SEG( shape->GetStart(), shape->GetEnd() ) );
837 break;
838 }
840 {
841 // Rectangles are stored as a single item but represent 4 segments
842 VECTOR2I start = shape->GetStart();
843 VECTOR2I end = shape->GetEnd();
844
845 for( const auto& seg : KIGEOM::BoxToSegs( BOX2I( start, end ) ) )
846 {
847 outlineSegs.push_back( seg );
848 }
849 break;
850 }
851 case SHAPE_T::POLY:
852 {
853 std::vector<VECTOR2I> polyPoints = shape->GetPolyPoints();
854
855 for( size_t i = 0; i < polyPoints.size() - 1; i++ )
856 {
857 VECTOR2I start = polyPoints[i];
858 VECTOR2I end = polyPoints[( i + 1 ) % polyPoints.size()];
859 outlineSegs.emplace_back( start, end );
860 }
861 break;
862 }
863 case SHAPE_T::CIRCLE:
864 // Not really sure what we can do here? Zero-length seg?
865 outlineSegs.push_back( SEG( shape->GetStart(), shape->GetStart() ) );
866 break;
867 default:
868 BOOST_WARN_MESSAGE(
869 false, "Unexpected shape type in board outline: " << static_cast<int>( shape->GetShape() ) );
870 }
871 }
872 }
873
874 if( !outlineSegs.empty() )
875 {
876 // For a valid closed outline, the sum of all segment lengths should equal the perimeter
877 // and each endpoint should connect to another endpoint
878 int connectedCount = 0;
879
880 for( const SEG& seg : outlineSegs )
881 {
882 for( const SEG& other : outlineSegs )
883 {
884 if( &other == &seg )
885 continue;
886
887 // Check if this shape's start connects to another shape's start or end
888 if( seg.A == other.A || seg.A == other.B )
889 connectedCount++;
890
891 // Check if this shape's end connects to another shape's start or end
892 if( seg.B == other.A || seg.B == other.B )
893 connectedCount++;
894 }
895 }
896
897 // Each segment should connect at both ends for a closed outline
898 // For 4 segments, we expect 8 connections (2 per segment)
899 BOOST_TEST_MESSAGE( "Connected endpoints: " << connectedCount );
900 BOOST_CHECK_GE( connectedCount, outlineSegs.size() * 2 );
901 }
902}
903
904
908BOOST_AUTO_TEST_CASE( BoardOutline )
909{
910 std::unique_ptr<BOARD> board = LoadAllegroBoard( "TRS80_POWER/TRS80_POWER.brd" );
911
912 BOOST_REQUIRE( board != nullptr );
913
914 // Count shapes on Edge_Cuts layer
915 int outlineSegmentCount = CountOutlineElements( *board );
916
917 BOOST_TEST_MESSAGE( "Board outline elements: " << outlineSegmentCount );
918
919 // Board should have an outline - TRS80_POWER.brd has a rectangular outline (4 segments)
920 BOOST_CHECK_GE( outlineSegmentCount, 1 );
921
922 AssertOutlineValid( *board );
923}
924
925
929BOOST_AUTO_TEST_CASE( PadsInsideOutline )
930{
931 std::unique_ptr<BOARD> board = LoadAllegroBoard( "TRS80_POWER/TRS80_POWER.brd" );
932
933 BOOST_REQUIRE( board != nullptr );
934
935 // Get board bounding box from outline
936 BOX2I boardBbox;
937 bool hasBbox = false;
938
939 for( BOARD_ITEM* item : board->Drawings() )
940 {
941 if( item->Type() == PCB_SHAPE_T && item->GetLayer() == Edge_Cuts )
942 {
943 if( !hasBbox )
944 {
945 boardBbox = item->GetBoundingBox();
946 hasBbox = true;
947 }
948 else
949 {
950 boardBbox.Merge( item->GetBoundingBox() );
951 }
952 }
953 }
954
955 BOOST_REQUIRE_MESSAGE( hasBbox, "Board should have an outline" );
956
957 int padsInside = 0;
958 int padsOutside = 0;
959
960 // Inflate bbox slightly to account for edge cases
961 BOX2I testBbox = boardBbox;
962 testBbox.Inflate( 1000 ); // 1mm tolerance
963
964 for( FOOTPRINT* fp : board->Footprints() )
965 {
966 for( PAD* pad : fp->Pads() )
967 {
968 VECTOR2I padCenter = pad->GetPosition();
969
970 if( testBbox.Contains( padCenter ) )
971 {
972 padsInside++;
973 }
974 else
975 {
976 padsOutside++;
977 BOOST_TEST_MESSAGE( "Pad outside outline: " << fp->GetReference() << " pad "
978 << pad->GetNumber() << " at ("
979 << padCenter.x / 1000000.0 << ", "
980 << padCenter.y / 1000000.0 << ") mm" );
981 }
982 }
983 }
984
985 BOOST_TEST_MESSAGE( "Pads inside outline: " << padsInside << ", outside: " << padsOutside );
986
987 // Most pads should be inside the board outline
988 // Some boards may have off-board test points or fiducials
989 if( padsOutside > 0 )
990 {
991 BOOST_WARN_MESSAGE( false, "Found " << padsOutside << " pads outside board outline" );
992 }
993
994 // At minimum, most pads should be inside
995 BOOST_CHECK_GT( padsInside, padsOutside );
996}
997
998
1003BOOST_AUTO_TEST_CASE( PreV16FileRejection )
1004{
1005 BOOST_CHECK_EXCEPTION(
1006 LoadAllegroBoard( "v13_header/v13_header.brd" ), IO_ERROR,
1007 []( const IO_ERROR& e )
1008 {
1009 wxString msg = e.What();
1010
1011 return msg.Contains( wxS( "predates Allegro 16.0" ) )
1012 && msg.Contains( wxS( "Allegro PCB Design" ) );
1013 } );
1014}
1015
1016
1022BOOST_AUTO_TEST_CASE( RectsZoneVsCopperPolygon )
1023{
1024 std::unique_ptr<BOARD> board = LoadAllegroBoard( "rects/rects.brd" );
1025 BOOST_REQUIRE( board );
1026
1027 // Should have exactly one zone (the left rectangle as a zone fill)
1028 BOOST_CHECK_EQUAL( board->Zones().size(), 1 );
1029
1030 ZONE* zone = board->Zones().front();
1031 BOOST_CHECK( zone->GetNetCode() > 0 );
1033 BOOST_CHECK( zone->IsFilled() );
1034
1035 // Should have exactly one standalone copper polygon (the right rectangle)
1036 int copperPolyCount = 0;
1037 int copperPolyWithNet = 0;
1038
1039 for( BOARD_ITEM* item : board->Drawings() )
1040 {
1041 if( item->Type() == PCB_SHAPE_T )
1042 {
1043 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
1044
1045 if( IsCopperLayer( shape->GetLayer() ) && shape->GetShape() == SHAPE_T::POLY )
1046 {
1047 copperPolyCount++;
1048
1049 if( shape->GetNetCode() > 0 )
1050 copperPolyWithNet++;
1051 }
1052 }
1053 }
1054
1055 BOOST_CHECK_EQUAL( copperPolyCount, 1 );
1056 BOOST_CHECK_EQUAL( copperPolyWithNet, 1 );
1057}
1058
1059
1064{
1065 std::unique_ptr<BOARD> board = LoadAllegroBoard( "copper_text/copper_text.brd" );
1066 BOOST_REQUIRE( board );
1067
1068 int copperTextCount = 0;
1069 bool foundTestingText = false;
1070
1071 for( BOARD_ITEM* item : board->Drawings() )
1072 {
1073 if( item->Type() == PCB_TEXT_T )
1074 {
1075 PCB_TEXT* text = static_cast<PCB_TEXT*>( item );
1076
1077 if( IsCopperLayer( text->GetLayer() ) )
1078 {
1079 copperTextCount++;
1080
1081 if( text->GetText() == wxS( "TESTING" ) )
1082 {
1083 foundTestingText = true;
1084 BOOST_CHECK_EQUAL( text->GetLayer(), F_Cu );
1085 }
1086 }
1087 }
1088 }
1089
1090 BOOST_CHECK_MESSAGE( foundTestingText, "Board should contain 'TESTING' text on F.Cu" );
1091 BOOST_CHECK_EQUAL( copperTextCount, 1 );
1092}
1093
1094
1095BOOST_AUTO_TEST_CASE( CoincidentGraphicsAreDropped )
1096{
1097 // Allegro stacks graphics that land on top of each other, on some designs a third of all
1098 // items. They draw the same picture, so the importer keeps only the first of each
1099 std::unique_ptr<BOARD> board = LoadAllegroBoard( "TRS80_POWER/TRS80_POWER.brd" );
1100
1101 const auto netOf = []( const BOARD_ITEM* aItem )
1102 {
1103 const BOARD_CONNECTED_ITEM* connected = dynamic_cast<const BOARD_CONNECTED_ITEM*>( aItem );
1104 return connected ? connected->GetNetCode() : NETINFO_LIST::UNCONNECTED;
1105 };
1106
1107 const auto coincident = [&]( const BOARD_ITEM* aFirst, const BOARD_ITEM* aSecond )
1108 {
1109 if( aFirst->Type() != aSecond->Type() || aFirst->GetLayer() != aSecond->GetLayer()
1110 || netOf( aFirst ) != netOf( aSecond ) )
1111 {
1112 return false;
1113 }
1114
1115 if( aFirst->Type() == PCB_SHAPE_T )
1116 {
1117 return static_cast<const PCB_SHAPE*>( aFirst )->Compare(
1118 static_cast<const PCB_SHAPE*>( aSecond ) ) == 0;
1119 }
1120
1121 if( aFirst->Type() == PCB_TEXT_T )
1122 {
1123 return static_cast<const PCB_TEXT*>( aFirst )->Compare(
1124 static_cast<const PCB_TEXT*>( aSecond ) ) == 0;
1125 }
1126
1127 return false;
1128 };
1129
1130 const auto countCoincident = [&]( const DRAWINGS& aItems )
1131 {
1132 int count = 0;
1133
1134 for( size_t ii = 0; ii < aItems.size(); ++ii )
1135 {
1136 for( size_t jj = ii + 1; jj < aItems.size(); ++jj )
1137 {
1138 if( coincident( aItems[ii], aItems[jj] ) )
1139 count++;
1140 }
1141 }
1142
1143 return count;
1144 };
1145
1146 BOOST_REQUIRE( !board->Drawings().empty() );
1147 BOOST_CHECK_EQUAL( countCoincident( board->Drawings() ), 0 );
1148
1149 BOOST_REQUIRE( !board->Footprints().empty() );
1150
1151 for( FOOTPRINT* footprint : board->Footprints() )
1152 BOOST_CHECK_EQUAL( countCoincident( footprint->GraphicalItems() ), 0 );
1153}
1154
1155
1156BOOST_AUTO_TEST_CASE( ImportIsRepeatable )
1157{
1158 // Item ids are derived from the Allegro block keys, so importing a design twice has to
1159 // produce the same ids. Random ids reshuffle the whole saved file on every import, because
1160 // the s-expr writer orders items by uuid
1161 const auto collectIds = []( const BOARD& aBoard )
1162 {
1163 std::vector<wxString> ids;
1164
1165 std::function<void( const BOARD_ITEM* )> walk =
1166 [&]( const BOARD_ITEM* aItem )
1167 {
1168 ids.push_back( aItem->m_Uuid.AsString() );
1169
1170 // Group members are collected where they live on the board
1171 if( aItem->Type() == PCB_GROUP_T )
1172 return;
1173
1174 aItem->RunOnChildren(
1175 [&]( BOARD_ITEM* aChild )
1176 {
1177 walk( aChild );
1178 },
1180 };
1181
1182 for( const BOARD_ITEM* item : const_cast<BOARD&>( aBoard ).GetItemSet() )
1183 walk( item );
1184
1185 std::sort( ids.begin(), ids.end() );
1186 return ids;
1187 };
1188
1189 std::unique_ptr<BOARD> first = LoadAllegroBoard( "ProiectBoard/ProiectBoard.brd" );
1190 std::unique_ptr<BOARD> second = LoadAllegroBoard( "ProiectBoard/ProiectBoard.brd" );
1191
1192 const std::vector<wxString> firstIds = collectIds( *first );
1193 const std::vector<wxString> secondIds = collectIds( *second );
1194
1195 BOOST_REQUIRE( !firstIds.empty() );
1196 BOOST_CHECK_EQUAL( firstIds.size(), secondIds.size() );
1197 BOOST_CHECK( firstIds == secondIds );
1198
1199 BOOST_CHECK( std::adjacent_find( firstIds.begin(), firstIds.end() ) == firstIds.end() );
1200}
1201
1202
1203// The 3D model assignment lives on the Allegro package definition, so every placed instance
1204// of a package that names one carries it
1205BOOST_AUTO_TEST_CASE( Footprint3DModels )
1206{
1207 std::unique_ptr<BOARD> board = LoadAllegroBoard( "led_youtube/led_youtube.brd" );
1208 BOOST_REQUIRE( board );
1209
1210 std::map<wxString, FP_3DMODEL> models;
1211
1212 for( FOOTPRINT* fp : board->Footprints() )
1213 {
1214 BOOST_REQUIRE_EQUAL( fp->Models().size(), 1u );
1215 models.emplace( fp->Models().front().m_Filename, fp->Models().front() );
1216 }
1217
1218 BOOST_REQUIRE_EQUAL( models.size(), 3u );
1219 BOOST_CHECK_EQUAL( models.count( wxS( "led3d.stp" ) ), 1u );
1220 BOOST_CHECK_EQUAL( models.count( wxS( "AC0805FR-07360RL.STEP" ) ), 1u );
1221 BOOST_REQUIRE_EQUAL( models.count( wxS( "22272021.stp" ) ), 1u );
1222
1223 // Placement of the connector package is "MM,0.020000,-1.270000,1.580007,90.000,-0.000,90.000"
1224 const FP_3DMODEL& conn = models.at( wxS( "22272021.stp" ) );
1225
1226 BOOST_CHECK_CLOSE( conn.m_Offset.x, 0.02, 1e-6 );
1227 BOOST_CHECK_CLOSE( conn.m_Offset.y, -1.27, 1e-6 );
1228 BOOST_CHECK_CLOSE( conn.m_Offset.z, 1.580007, 1e-6 );
1229 BOOST_CHECK_CLOSE( conn.m_Rotation.x, -90.0, 1e-6 );
1230 BOOST_CHECK_SMALL( conn.m_Rotation.y, 1e-9 );
1231 BOOST_CHECK_CLOSE( conn.m_Rotation.z, -90.0, 1e-6 );
1232}
1233
1234
1239BOOST_AUTO_TEST_CASE( ConstraintSetsAreAssigned )
1240{
1241 std::unique_ptr<BOARD> board = LoadAllegroBoard( "issue25654/MIPI_Camera_Sub.brd" );
1242
1243 BOOST_REQUIRE( board != nullptr );
1244
1245 std::shared_ptr<NET_SETTINGS> netSettings = board->GetDesignSettings().m_NetSettings;
1246
1247 BOOST_REQUIRE( netSettings->HasNetclass( wxS( "DP_CSI_A_CLK" ) ) );
1248 BOOST_CHECK_EQUAL( netSettings->GetNetclasses().at( wxS( "DP_CSI_A_CLK" ) )->GetClearance(), 177800 );
1249
1250 for( NETINFO_ITEM* net : board->GetNetInfo() )
1251 {
1252 if( net->GetNetCode() > 0 )
1253 BOOST_CHECK_NE( net->GetNetClass()->GetName(), NETCLASS::Default );
1254 }
1255}
1256
1257
1259
1260
1261
1265{
1266 std::string filename;
1267 bool expected_to_load; // Set false for known-broken boards
1268};
1269
1270
1275{
1277
1283 BOARD* GetCachedBoard( const std::string& aFilePath )
1284 {
1286 }
1287
1291 static std::vector<std::string> GetAllBoardFiles()
1292 {
1293 std::vector<std::string> boards;
1294 std::string dataPath = KI_TEST::AllegroBoardDataDir( "" );
1295
1296 // For each board dir, look for .brd files and add them to the list of test cases
1297 try
1298 {
1299 for( const auto& boardDir : std::filesystem::directory_iterator( dataPath ) )
1300 {
1301 if( !boardDir.is_directory() )
1302 continue;
1303
1304 for( const auto& entry : std::filesystem::directory_iterator( boardDir ) )
1305 {
1306 if( entry.is_regular_file() && entry.path().extension() == ".brd" && entry.file_size() > 0 )
1307 {
1308 std::string name = entry.path().filename().string();
1309
1310 // v13_header.brd is intentionally pre-v16 and tested separately
1311 if( name != "v13_header.brd" )
1312 {
1313 boards.push_back( boardDir.path().string() + "/" + name );
1314 }
1315 }
1316 }
1317 }
1318 }
1319 catch( const std::filesystem::filesystem_error& e )
1320 {
1321 BOOST_TEST_MESSAGE( "Failed to enumerate board files: " << e.what() );
1322 }
1323
1324 std::sort( boards.begin(), boards.end() );
1325 return boards;
1326 }
1327
1329};
1330
1331BOOST_FIXTURE_TEST_SUITE( AllegroComprehensive, ALLEGRO_COMPREHENSIVE_FIXTURE )
1332
1333
1334
1339BOOST_AUTO_TEST_CASE( BeagleBone_OutermostZoneNets )
1340{
1341 std::string dataPath = KI_TEST::AllegroBoardFile( "BeagleBone_Black_RevC/BeagleBone_Black_RevC.brd" );
1342
1343 BOARD* board = GetCachedBoard( dataPath );
1344 BOOST_REQUIRE( board );
1345
1346 const std::vector<wxString> expectedLayers = { wxS( "TOP" ), wxS( "LYR2_GND" ),
1347 wxS( "LYR5_PWR" ), wxS( "BOTTOM" ) };
1348
1349 for( const wxString& layerName : expectedLayers )
1350 {
1351 BOOST_TEST_CONTEXT( "Outermost zone on " << layerName )
1352 {
1353 PCB_LAYER_ID layerId = board->GetLayerID( layerName );
1354
1356 "Layer " << layerName << " should exist" );
1357
1358 const ZONE* largest = nullptr;
1359 double largestArea = 0;
1360
1361 for( const ZONE* zone : board->Zones() )
1362 {
1363 if( zone->GetIsRuleArea() )
1364 continue;
1365
1366 if( zone->GetNetCode() == 0 )
1367 continue;
1368
1369 if( !zone->GetLayerSet().Contains( layerId ) )
1370 continue;
1371
1372 BOX2I bbox = zone->GetBoundingBox();
1373 double area = static_cast<double>( bbox.GetWidth() )
1374 * static_cast<double>( bbox.GetHeight() );
1375
1376 if( area > largestArea )
1377 {
1378 largestArea = area;
1379 largest = zone;
1380 }
1381 }
1382
1383 BOOST_REQUIRE_MESSAGE( largest != nullptr,
1384 "Should find a netted copper zone on " << layerName );
1385 BOOST_CHECK_EQUAL( largest->GetNetname(), wxString( wxS( "GND_EARTH" ) ) );
1386 }
1387 }
1388}
1389
1390
1394BOOST_AUTO_TEST_CASE( PadSizesPositive )
1395{
1396 std::vector<std::string> boards = GetAllBoardFiles();
1397
1398 for( const std::string& boardPath : boards )
1399 {
1400 std::string boardName = std::filesystem::path( boardPath ).filename().string();
1401 BOARD* board = GetCachedBoard( boardPath );
1402
1403 if( !board )
1404 continue;
1405
1406 BOOST_TEST_CONTEXT( "Testing board: " << boardName )
1407 {
1408 int negativePadCount = 0;
1409
1410 for( FOOTPRINT* fp : board->Footprints() )
1411 {
1412 for( PAD* pad : fp->Pads() )
1413 {
1414 VECTOR2I size = pad->GetSize( F_Cu );
1415
1416 if( size.x < 0 || size.y < 0 )
1417 {
1418 negativePadCount++;
1419 BOOST_TEST_MESSAGE( boardName << ": Negative pad size in " << fp->GetReference()
1420 << " pad " << pad->GetNumber() << ": " << size.x << " x "
1421 << size.y );
1422 }
1423 }
1424 }
1425
1426 BOOST_CHECK_EQUAL( negativePadCount, 0 );
1427 }
1428 }
1429}
1430
1431
1436BOOST_AUTO_TEST_CASE( ViaDrillNotLargerThanSize )
1437{
1438 std::vector<std::string> boards = GetAllBoardFiles();
1439
1440 for( const std::string& boardPath : boards )
1441 {
1442 std::string boardName = std::filesystem::path( boardPath ).filename().string();
1443 BOARD* board = GetCachedBoard( boardPath );
1444
1445 if( !board )
1446 continue;
1447
1448 BOOST_TEST_CONTEXT( "Testing board: " << boardName )
1449 {
1450 int invalidViaCount = 0;
1451
1452 for( PCB_TRACK* track : board->Tracks() )
1453 {
1454 if( track->Type() == PCB_VIA_T )
1455 {
1456 PCB_VIA* via = static_cast<PCB_VIA*>( track );
1457 int drill = via->GetDrill();
1458 int width = via->GetWidth( F_Cu );
1459
1460 if( drill > width )
1461 {
1462 invalidViaCount++;
1463 BOOST_TEST_MESSAGE( boardName << ": Via at ("
1464 << via->GetPosition().x / 1000000.0 << ", "
1465 << via->GetPosition().y / 1000000.0
1466 << ") has drill " << drill / 1000000.0
1467 << "mm > width " << width / 1000000.0 << "mm" );
1468 }
1469 }
1470 }
1471
1472 BOOST_CHECK_EQUAL( invalidViaCount, 0 );
1473 }
1474 }
1475}
1476
1477
1482BOOST_AUTO_TEST_CASE( SmdPadDetection )
1483{
1484 std::vector<std::string> boards = GetAllBoardFiles();
1485
1486 for( const std::string& boardPath : boards )
1487 {
1488 std::string boardName = std::filesystem::path( boardPath ).filename().string();
1489 BOARD* board = GetCachedBoard( boardPath );
1490
1491 if( !board )
1492 continue;
1493
1494 BOOST_TEST_CONTEXT( "Testing board: " << boardName )
1495 {
1496 int misclassifiedSmdCount = 0;
1497 int correctSmdCount = 0;
1498 int correctThCount = 0;
1499
1500 for( FOOTPRINT* fp : board->Footprints() )
1501 {
1502 for( PAD* pad : fp->Pads() )
1503 {
1504 bool hasDrill = pad->GetDrillSize().x > 0 && pad->GetDrillSize().y > 0;
1505 PAD_ATTRIB attr = pad->GetAttribute();
1506
1507 if( !hasDrill && attr == PAD_ATTRIB::PTH )
1508 {
1509 misclassifiedSmdCount++;
1510 BOOST_TEST_MESSAGE( boardName << ": Pad " << fp->GetReference()
1511 << "." << pad->GetNumber()
1512 << " has no drill but is marked as PTH (should be SMD)" );
1513 }
1514 else if( !hasDrill && attr == PAD_ATTRIB::SMD )
1515 {
1516 correctSmdCount++;
1517 }
1518 else if( hasDrill && ( attr == PAD_ATTRIB::PTH || attr == PAD_ATTRIB::NPTH ) )
1519 {
1520 correctThCount++;
1521 }
1522 }
1523 }
1524
1525 BOOST_TEST_MESSAGE( boardName << ": Correct SMD=" << correctSmdCount
1526 << ", Correct TH=" << correctThCount
1527 << ", Misclassified=" << misclassifiedSmdCount );
1528
1529 BOOST_CHECK_EQUAL( misclassifiedSmdCount, 0 );
1530 }
1531 }
1532}
1533
1534
1539BOOST_AUTO_TEST_CASE( QuadPackagePadRotation )
1540{
1541 std::vector<std::string> boards = GetAllBoardFiles();
1542
1543 for( const std::string& boardPath : boards )
1544 {
1545 std::string boardName = std::filesystem::path( boardPath ).filename().string();
1546 BOARD* board = GetCachedBoard( boardPath );
1547
1548 if( !board )
1549 continue;
1550
1551 BOOST_TEST_CONTEXT( "Testing board: " << boardName )
1552 {
1553 int quadPackageCount = 0;
1554 int packagesWithRotatedPads = 0;
1555 int packagesWithUnrotatedPads = 0;
1556
1557 for( FOOTPRINT* fp : board->Footprints() )
1558 {
1559 wxString refdes = fp->GetReference().Upper();
1560
1561 // Look for ICs (typically U* prefix) that might be quad packages
1562 if( !refdes.StartsWith( "U" ) )
1563 continue;
1564
1565 // Must have at least 16 pads to be a quad package
1566 if( fp->Pads().size() < 16 )
1567 continue;
1568
1569 // Find bounding box of all pad centers to estimate package shape
1570 BOX2I padBounds;
1571 bool first = true;
1572
1573 for( PAD* pad : fp->Pads() )
1574 {
1575 VECTOR2I pos = pad->GetPosition();
1576
1577 if( first )
1578 {
1579 padBounds = BOX2I( pos, VECTOR2I( 0, 0 ) );
1580 first = false;
1581 }
1582 else
1583 {
1584 padBounds.Merge( pos );
1585 }
1586 }
1587
1588 // Must be roughly square to be a quad package
1589 int width = padBounds.GetWidth();
1590 int height = padBounds.GetHeight();
1591
1592 if( width == 0 || height == 0 )
1593 continue;
1594
1595 double aspectRatio = static_cast<double>( std::max( width, height ) ) /
1596 static_cast<double>( std::min( width, height ) );
1597
1598 if( aspectRatio > 2.0 )
1599 continue;
1600
1601 quadPackageCount++;
1602
1603 // Check if pads have varying orientations
1604 std::set<int> uniqueAngles;
1605
1606 for( PAD* pad : fp->Pads() )
1607 {
1608 EDA_ANGLE angle = pad->GetOrientation();
1609 angle.Normalize();
1610 int degrees = static_cast<int>( angle.AsDegrees() + 0.5 ) % 360;
1611 uniqueAngles.insert( degrees );
1612 }
1613
1614 // A properly imported quad package should have at least 2 different pad orientations
1615 // (for 2-sided packages) or 4 (for 4-sided packages like QFP)
1616 if( uniqueAngles.size() >= 2 )
1617 {
1618 packagesWithRotatedPads++;
1619 BOOST_TEST_MESSAGE( boardName << ": " << fp->GetReference()
1620 << " has " << uniqueAngles.size() << " unique pad orientations" );
1621 }
1622 else
1623 {
1624 packagesWithUnrotatedPads++;
1625 BOOST_TEST_MESSAGE( boardName << ": " << fp->GetReference()
1626 << " has only " << uniqueAngles.size()
1627 << " unique pad orientation (may be missing rotation)" );
1628 }
1629 }
1630
1631 if( quadPackageCount > 0 )
1632 {
1633 BOOST_TEST_MESSAGE( boardName << ": Found " << quadPackageCount
1634 << " potential quad packages, "
1635 << packagesWithRotatedPads << " with rotated pads, "
1636 << packagesWithUnrotatedPads << " without" );
1637
1638 // At least some packages should have rotated pads to confirm rotation parsing works.
1639 // Many packages may legitimately have all pads at the same orientation (BGAs, single-row).
1640 if( packagesWithRotatedPads == 0 && quadPackageCount > 0 )
1641 {
1642 BOOST_WARN_MESSAGE( false, boardName << " has no packages with rotated pads" );
1643 }
1644 }
1645 }
1646 }
1647}
1648
1649
1655BOOST_AUTO_TEST_CASE( FootprintLayerPlacement )
1656{
1657 std::string dataPath = KI_TEST::AllegroBoardFile( "BeagleBone_Black_RevC/BeagleBone_Black_RevC.brd" );
1658
1659 BOARD* board = GetCachedBoard( dataPath );
1660 BOOST_REQUIRE_MESSAGE( board != nullptr, "BeagleBone_Black_RevC.brd should load successfully" );
1661
1662 // Look for C78 which should be on the bottom layer
1663 FOOTPRINT* c78 = nullptr;
1664
1665 for( FOOTPRINT* fp : board->Footprints() )
1666 {
1667 if( fp->GetReference() == "C78" )
1668 {
1669 c78 = fp;
1670 break;
1671 }
1672 }
1673
1674 BOOST_REQUIRE_MESSAGE( c78 != nullptr, "Footprint C78 should exist in BeagleBone Black" );
1675
1676 PCB_LAYER_ID fpLayer = c78->GetLayer();
1677
1678 BOOST_TEST_MESSAGE( "C78 layer: " << board->GetLayerName( fpLayer ) << " (ID: " << fpLayer << ")" );
1679 BOOST_TEST_MESSAGE( "C78 is flipped: " << ( c78->IsFlipped() ? "yes" : "no" ) );
1680
1681 BOOST_CHECK_MESSAGE( fpLayer == B_Cu, "C78 should be on the bottom copper layer (B_Cu), got "
1682 << board->GetLayerName( fpLayer ) );
1683 BOOST_CHECK_MESSAGE( c78->IsFlipped(), "C78 should be flipped (IsFlipped() == true)" );
1684
1685 // Count footprints on top vs bottom to ensure we're parsing layer correctly
1686 int topCount = 0;
1687 int bottomCount = 0;
1688
1689 for( FOOTPRINT* fp : board->Footprints() )
1690 {
1691 if( fp->GetLayer() == F_Cu )
1692 topCount++;
1693 else if( fp->GetLayer() == B_Cu )
1694 bottomCount++;
1695 }
1696
1697 BOOST_TEST_MESSAGE( "Footprints on top: " << topCount << ", on bottom: " << bottomCount );
1698
1699 // BeagleBone should have components on both sides
1700 BOOST_CHECK_GT( topCount, 0 );
1701 BOOST_CHECK_GT( bottomCount, 0 );
1702}
1703
1704
1709BOOST_AUTO_TEST_CASE( ArcConnectivity )
1710{
1711 std::vector<std::string> boards = GetAllBoardFiles();
1712
1713 for( const std::string& boardPath : boards )
1714 {
1715 std::string boardName = std::filesystem::path( boardPath ).filename().string();
1716 BOARD* board = GetCachedBoard( boardPath );
1717
1718 if( !board )
1719 continue;
1720
1721 BOOST_TEST_CONTEXT( "Testing board: " << boardName )
1722 {
1723 int arcCount = 0;
1724 int disconnectedArcs = 0;
1725
1726 // Build a map of track endpoints per net for quick lookup
1727 std::map<int, std::vector<VECTOR2I>> netEndpoints;
1728
1729 for( PCB_TRACK* track : board->Tracks() )
1730 {
1731 int netCode = track->GetNetCode();
1732
1733 if( track->Type() == PCB_TRACE_T )
1734 {
1735 netEndpoints[netCode].push_back( track->GetStart() );
1736 netEndpoints[netCode].push_back( track->GetEnd() );
1737 }
1738 else if( track->Type() == PCB_VIA_T )
1739 {
1740 netEndpoints[netCode].push_back( track->GetPosition() );
1741 }
1742 }
1743
1744 // Also include pad positions
1745 for( FOOTPRINT* fp : board->Footprints() )
1746 {
1747 for( PAD* pad : fp->Pads() )
1748 {
1749 int netCode = pad->GetNetCode();
1750
1751 if( netCode > 0 )
1752 netEndpoints[netCode].push_back( pad->GetPosition() );
1753 }
1754 }
1755
1756 // Now check each arc
1757 for( PCB_TRACK* track : board->Tracks() )
1758 {
1759 if( track->Type() != PCB_ARC_T )
1760 continue;
1761
1762 arcCount++;
1763 PCB_ARC* arc = static_cast<PCB_ARC*>( track );
1764 int netCode = arc->GetNetCode();
1765
1766 VECTOR2I arcStart = arc->GetStart();
1767 VECTOR2I arcEnd = arc->GetEnd();
1768
1769 // Check if arc endpoints connect to something
1770 bool startConnected = false;
1771 bool endConnected = false;
1772 const int tolerance = 1000; // 1um tolerance
1773
1774 for( const VECTOR2I& pt : netEndpoints[netCode] )
1775 {
1776 if( ( pt - arcStart ).EuclideanNorm() < tolerance )
1777 startConnected = true;
1778
1779 if( ( pt - arcEnd ).EuclideanNorm() < tolerance )
1780 endConnected = true;
1781 }
1782
1783 // Arc should connect to at least one other track/pad at each end
1784 // (unless it's an isolated arc, which is unusual but possible)
1785 if( !startConnected && !endConnected && netEndpoints[netCode].size() > 2 )
1786 {
1787 disconnectedArcs++;
1788 BOOST_TEST_MESSAGE( boardName << ": Arc at ("
1789 << arcStart.x / 1000000.0 << ", "
1790 << arcStart.y / 1000000.0 << ") to ("
1791 << arcEnd.x / 1000000.0 << ", "
1792 << arcEnd.y / 1000000.0
1793 << ") appears disconnected from net " << netCode );
1794 }
1795 }
1796
1797 if( arcCount > 0 )
1798 {
1799 BOOST_TEST_MESSAGE( boardName << ": Found " << arcCount << " arcs, "
1800 << disconnectedArcs << " disconnected" );
1801 }
1802
1803 // Allow some disconnected arcs as they may be legitimate isolated features
1804 // but flag if more than 20% are disconnected
1805 if( arcCount > 5 )
1806 {
1807 BOOST_CHECK_LE( disconnectedArcs, arcCount / 5 );
1808 }
1809 }
1810 }
1811}
1812
1813
1830{
1831 wxString layer;
1832 int recordId = 0;
1833 wxString netName;
1834 double minX = 1e18, minY = 1e18, maxX = -1e18, maxY = -1e18;
1836
1837 void AddPoint( double aX, double aY )
1838 {
1839 minX = std::min( minX, aX );
1840 minY = std::min( minY, aY );
1841 maxX = std::max( maxX, aX );
1842 maxY = std::max( maxY, aY );
1843 segmentCount++;
1844 }
1845};
1846
1847
1849{
1850 std::set<wxString> netNames;
1851 std::set<wxString> refDes;
1852 std::map<wxString, wxString> refDesToSymName;
1853 std::map<wxString, std::set<wxString>> netToRefDes;
1854
1855 std::vector<ALG_ZONE_POLYGON> zonePolygons;
1856
1857 static std::vector<wxString> SplitAlgLine( const wxString& aLine )
1858 {
1859 std::vector<wxString> fields;
1860 wxString current;
1861
1862 for( size_t i = 0; i < aLine.size(); ++i )
1863 {
1864 if( aLine[i] == '!' )
1865 {
1866 fields.push_back( current );
1867 current.clear();
1868 }
1869 else
1870 {
1871 current += aLine[i];
1872 }
1873 }
1874
1875 if( !current.empty() )
1876 fields.push_back( current );
1877
1878 return fields;
1879 }
1880
1885 static int ParseRecordId( const wxString& aTag )
1886 {
1887 long val = -1;
1888 wxString tag = aTag.BeforeFirst( ' ' );
1889 tag.ToLong( &val );
1890 return static_cast<int>( val );
1891 }
1892
1893 static const ALG_REFERENCE_DATA& GetCached( const std::string& aPath )
1894 {
1895 static std::map<std::string, ALG_REFERENCE_DATA> cache;
1896
1897 auto it = cache.find( aPath );
1898
1899 if( it == cache.end() )
1900 it = cache.emplace( aPath, ParseAlgFile( aPath ) ).first;
1901
1902 return it->second;
1903 }
1904
1905 static ALG_REFERENCE_DATA ParseAlgFile( const std::string& aPath )
1906 {
1907 ALG_REFERENCE_DATA data;
1908 std::ifstream file( aPath );
1909
1910 if( !file.is_open() )
1911 return data;
1912
1913 enum class SECTION
1914 {
1915 UNKNOWN,
1916 NET_NODES,
1917 SYM_PLACEMENT,
1918 GRAPHICS,
1919 };
1920
1921 SECTION currentSection = SECTION::UNKNOWN;
1922 std::string line;
1923
1924 // Accumulate zone segments grouped by (layer, recordId)
1925 std::map<std::pair<wxString, int>, ALG_ZONE_POLYGON> zoneMap;
1926
1927 while( std::getline( file, line ) )
1928 {
1929 if( line.empty() || line[0] == 'J' )
1930 continue;
1931
1932 if( line[0] == 'A' )
1933 {
1934 if( line.find( "NET_NAME_SORT!NODE_SORT!NET_NAME!REFDES!" ) != std::string::npos )
1935 currentSection = SECTION::NET_NODES;
1936 else if( line.find( "SYM_TYPE!SYM_NAME!REFDES!SYM_MIRROR!" ) != std::string::npos )
1937 currentSection = SECTION::SYM_PLACEMENT;
1938 else if( line.find( "CLASS!SUBCLASS!RECORD_TAG!GRAPHIC_DATA_NAME!" ) != std::string::npos )
1939 currentSection = SECTION::GRAPHICS;
1940 else
1941 currentSection = SECTION::UNKNOWN;
1942
1943 continue;
1944 }
1945
1946 if( line[0] != 'S' )
1947 continue;
1948
1949 auto fields = SplitAlgLine( wxString::FromUTF8( line ) );
1950
1951 switch( currentSection )
1952 {
1953 case SECTION::NET_NODES:
1954 {
1955 // S!sort!nodeSort!NET_NAME!REFDES!PIN!PIN_NAME!SUBCLASS!
1956 if( fields.size() >= 5 )
1957 {
1958 wxString netName = fields[3];
1959 wxString refdes = fields[4];
1960
1961 if( !netName.empty() )
1962 {
1963 data.netNames.insert( netName );
1964
1965 if( !refdes.empty() )
1966 data.netToRefDes[netName].insert( refdes );
1967 }
1968 }
1969
1970 break;
1971 }
1972 case SECTION::SYM_PLACEMENT:
1973 {
1974 // S!SYM_TYPE!SYM_NAME!REFDES!MIRROR!ROTATE!X!Y!CX!CY!LIB_PATH!
1975 if( fields.size() >= 4 )
1976 {
1977 wxString symType = fields[1];
1978 wxString symName = fields[2];
1979 wxString refdes = fields[3];
1980
1981 if( symType == wxT( "PACKAGE" ) && !refdes.empty() )
1982 {
1983 data.refDes.insert( refdes );
1984 data.refDesToSymName[refdes] = symName;
1985 }
1986 }
1987
1988 break;
1989 }
1990 case SECTION::GRAPHICS:
1991 {
1992 // Field layout (0-indexed after splitting on '!'):
1993 // 0=S, 1=CLASS, 2=SUBCLASS, 3=RECORD_TAG, 4=GRAPHIC_DATA_NAME,
1994 // 5=GRAPHIC_DATA_NUMBER, 6..15=GRAPHIC_DATA_1..10,
1995 // 16=PIN_NUMBER, ..., 23=NET_NAME
1996 if( fields.size() < 16 || fields[1] != wxT( "BOUNDARY" ) )
1997 break;
1998
1999 wxString closureType = fields[15];
2000
2001 if( closureType != wxT( "SHAPE" ) )
2002 break;
2003
2004 wxString layer = fields[2];
2005 int recordId = ParseRecordId( fields[3] );
2006
2007 if( recordId < 0 )
2008 break;
2009
2010 wxString netName;
2011
2012 if( fields.size() > 23 )
2013 netName = fields[23];
2014
2015 auto key = std::make_pair( layer, recordId );
2016 auto& zone = zoneMap[key];
2017 zone.layer = layer;
2018 zone.recordId = recordId;
2019
2020 if( !netName.empty() )
2021 zone.netName = netName;
2022
2023 double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
2024
2025 if( fields.size() > 9 )
2026 {
2027 fields[6].ToDouble( &x1 );
2028 fields[7].ToDouble( &y1 );
2029 fields[8].ToDouble( &x2 );
2030 fields[9].ToDouble( &y2 );
2031 zone.AddPoint( x1, y1 );
2032 zone.AddPoint( x2, y2 );
2033 }
2034
2035 break;
2036 }
2037 default:
2038 break;
2039 }
2040 }
2041
2042 for( auto& [key, zone] : zoneMap )
2043 data.zonePolygons.push_back( std::move( zone ) );
2044
2045 return data;
2046 }
2047};
2048
2049
2051{
2052 std::string brdFile;
2053 std::string algFile;
2054};
2055
2056
2061static std::vector<BRD_ALG_PAIR> getBoardsWithAlg()
2062{
2063 std::string dataPath = KI_TEST::AllegroBoardDataDir( "" );
2064 std::vector<BRD_ALG_PAIR> boardsWithAlg;
2065
2066 for( const auto& boardDir : std::filesystem::directory_iterator( dataPath ) )
2067 {
2068 if( !boardDir.is_directory() )
2069 continue;
2070
2071 std::filesystem::path boardPath;
2072 std::filesystem::path algPath;
2073
2074 for( const auto& entry : std::filesystem::directory_iterator( boardDir ) )
2075 {
2076 if( !entry.is_regular_file() )
2077 continue;
2078
2079 if( entry.path().extension() == ".brd" )
2080 boardPath = entry.path();
2081 else if( entry.path().extension() == ".alg" )
2082 algPath = entry.path();
2083
2084 if( !boardPath.empty() && !algPath.empty() )
2085 {
2086 boardsWithAlg.push_back( { boardPath.string(), algPath.string() } );
2087 break;
2088 }
2089 }
2090 }
2091
2092 return boardsWithAlg;
2093}
2094
2095
2099BOOST_AUTO_TEST_CASE( AlgReferenceNetNames )
2100{
2101 std::vector<BRD_ALG_PAIR> boardsWithAlg = getBoardsWithAlg();
2102
2103 BOOST_REQUIRE_GT( boardsWithAlg.size(), 0u );
2104
2105 for( const auto& [brdFile, algFile] : boardsWithAlg )
2106 {
2107 BOOST_TEST_MESSAGE( "Validating net names: " << brdFile );
2108
2109 const ALG_REFERENCE_DATA& algData = ALG_REFERENCE_DATA::GetCached( algFile );
2110 BOOST_REQUIRE_GT( algData.netNames.size(), 0u );
2111
2112 BOARD* board = GetCachedBoard( brdFile );
2113 BOOST_REQUIRE( board );
2114
2115 std::set<wxString> boardNets;
2116
2117 for( const NETINFO_ITEM* net : board->GetNetInfo() )
2118 {
2119 if( net->GetNetCode() > 0 )
2120 boardNets.insert( net->GetNetname() );
2121 }
2122
2123 int missingNets = 0;
2124
2125 for( const wxString& algNet : algData.netNames )
2126 {
2127 if( boardNets.find( algNet ) == boardNets.end() )
2128 {
2129 missingNets++;
2130
2131 if( missingNets <= 10 )
2132 BOOST_TEST_MESSAGE( " Missing net: " << algNet );
2133 }
2134 }
2135
2136 BOOST_TEST_MESSAGE( brdFile << ": .alg has " << algData.netNames.size() << " nets, board has "
2137 << boardNets.size() << ", missing " << missingNets );
2138
2139 BOOST_CHECK_EQUAL( missingNets, 0 );
2140 }
2141}
2142
2143
2147BOOST_AUTO_TEST_CASE( AlgReferenceComponentPlacement )
2148{
2149 std::vector<BRD_ALG_PAIR> boardsWithAlg = getBoardsWithAlg();
2150
2151 BOOST_REQUIRE_GT( boardsWithAlg.size(), 0u );
2152
2153 for( const auto& [brdFile, algFile] : boardsWithAlg )
2154 {
2155 BOOST_TEST_MESSAGE( "Validating components: " << brdFile );
2156
2157 const ALG_REFERENCE_DATA& algData = ALG_REFERENCE_DATA::GetCached( algFile );
2158 BOOST_REQUIRE_GT( algData.refDes.size(), 0u );
2159
2160 BOARD* board = GetCachedBoard( brdFile );
2161 BOOST_REQUIRE( board );
2162
2163 std::set<wxString> boardRefDes;
2164
2165 for( const FOOTPRINT* fp : board->Footprints() )
2166 boardRefDes.insert( fp->GetReference() );
2167
2168 int missingRefDes = 0;
2169 int extraRefDes = 0;
2170
2171 for( const wxString& algRef : algData.refDes )
2172 {
2173 if( boardRefDes.find( algRef ) == boardRefDes.end() )
2174 {
2175 missingRefDes++;
2176
2177 if( missingRefDes <= 10 )
2178 BOOST_TEST_MESSAGE( " Missing refdes: " << algRef );
2179 }
2180 }
2181
2182 for( const wxString& boardRef : boardRefDes )
2183 {
2184 if( algData.refDes.find( boardRef ) == algData.refDes.end() )
2185 {
2186 extraRefDes++;
2187
2188 if( extraRefDes <= 10 )
2189 BOOST_TEST_MESSAGE( " Extra refdes in board: " << boardRef );
2190 }
2191 }
2192
2193 BOOST_TEST_MESSAGE( brdFile << ": .alg has " << algData.refDes.size()
2194 << " components, board has " << boardRefDes.size()
2195 << ", missing " << missingRefDes
2196 << ", extra " << extraRefDes );
2197
2198 BOOST_CHECK_EQUAL( missingRefDes, 0 );
2199 }
2200}
2201
2202
2206BOOST_AUTO_TEST_CASE( AllTracksPositiveWidth )
2207{
2208 std::vector<std::string> boards = GetAllBoardFiles();
2209
2210 for( const std::string& boardPath : boards )
2211 {
2212 std::string boardName = std::filesystem::path( boardPath ).filename().string();
2213 BOARD* board = GetCachedBoard( boardPath );
2214
2215 if( !board )
2216 continue;
2217
2218 BOOST_TEST_CONTEXT( "Testing board: " << boardName )
2219 {
2220 int zeroWidthCount = 0;
2221 int totalCount = 0;
2222
2223 for( PCB_TRACK* track : board->Tracks() )
2224 {
2225 if( track->Type() == PCB_TRACE_T || track->Type() == PCB_ARC_T )
2226 {
2227 totalCount++;
2228
2229 if( track->GetWidth() <= 0 )
2230 {
2231 zeroWidthCount++;
2232
2233 if( zeroWidthCount <= 5 )
2234 {
2235 BOOST_TEST_MESSAGE( boardName << ": Zero-width track at ("
2236 << track->GetStart().x / 1000000.0 << ", "
2237 << track->GetStart().y / 1000000.0 << ")" );
2238 }
2239 }
2240 }
2241 }
2242
2243 BOOST_CHECK_EQUAL( zeroWidthCount, 0 );
2244 }
2245 }
2246}
2247
2248
2256{
2257 enum class SEGMENT_TYPE
2258 {
2262 };
2263
2265 {
2267 double x1, y1, x2, y2;
2270 };
2271
2274 std::vector<OUTLINE_SEGMENT> designOutlineSegments;
2275 std::vector<OUTLINE_SEGMENT> outlineSegments;
2276
2277 double minX = std::numeric_limits<double>::max();
2278 double minY = std::numeric_limits<double>::max();
2279 double maxX = std::numeric_limits<double>::lowest();
2280 double maxY = std::numeric_limits<double>::lowest();
2281
2282 void updateBounds( double aX, double aY )
2283 {
2284 minX = std::min( minX, aX );
2285 minY = std::min( minY, aY );
2286 maxX = std::max( maxX, aX );
2287 maxY = std::max( maxY, aY );
2288 }
2289
2290 static const ALG_OUTLINE_DATA& GetCached( const std::string& aPath )
2291 {
2292 static std::map<std::string, ALG_OUTLINE_DATA> cache;
2293
2294 auto it = cache.find( aPath );
2295
2296 if( it == cache.end() )
2297 it = cache.emplace( aPath, ParseAlgOutlines( aPath ) ).first;
2298
2299 return it->second;
2300 }
2301
2302 static ALG_OUTLINE_DATA ParseAlgOutlines( const std::string& aPath )
2303 {
2304 ALG_OUTLINE_DATA data;
2305 std::ifstream file( aPath );
2306
2307 if( !file.is_open() )
2308 return data;
2309
2310 std::string line;
2311
2312 while( std::getline( file, line ) )
2313 {
2314 if( line.empty() || line[0] != 'S' )
2315 continue;
2316
2317 auto fields = ALG_REFERENCE_DATA::SplitAlgLine( wxString::FromUTF8( line ) );
2318
2319 if( fields.size() < 10 )
2320 continue;
2321
2322 bool isDesignOutline = ( fields[1] == wxT( "BOARD GEOMETRY" )
2323 && fields[2] == wxT( "DESIGN_OUTLINE" ) );
2324
2325 bool isOutline = ( fields[1] == wxT( "BOARD GEOMETRY" )
2326 && fields[2] == wxT( "OUTLINE" ) );
2327
2328 if( !isDesignOutline && !isOutline )
2329 continue;
2330
2331 wxString shapeType = fields[4];
2332 OUTLINE_SEGMENT seg = {};
2333
2334 if( shapeType == wxT( "LINE" ) && fields.size() >= 10 )
2335 {
2337 fields[6].ToCDouble( &seg.x1 );
2338 fields[7].ToCDouble( &seg.y1 );
2339 fields[8].ToCDouble( &seg.x2 );
2340 fields[9].ToCDouble( &seg.y2 );
2341
2342 data.updateBounds( seg.x1, seg.y1 );
2343 data.updateBounds( seg.x2, seg.y2 );
2344 }
2345 else if( shapeType == wxT( "ARC" ) && fields.size() >= 15 )
2346 {
2347 seg.type = SEGMENT_TYPE::ARC;
2348 fields[6].ToCDouble( &seg.x1 );
2349 fields[7].ToCDouble( &seg.y1 );
2350 fields[8].ToCDouble( &seg.x2 );
2351 fields[9].ToCDouble( &seg.y2 );
2352 fields[10].ToCDouble( &seg.centerX );
2353 fields[11].ToCDouble( &seg.centerY );
2354 fields[12].ToCDouble( &seg.radius );
2355 seg.clockwise = ( fields[14] == wxT( "CLOCKWISE" ) );
2356
2357 data.updateBounds( seg.x1, seg.y1 );
2358 data.updateBounds( seg.x2, seg.y2 );
2359 }
2360 else if( shapeType == wxT( "RECTANGLE" ) && fields.size() >= 10 )
2361 {
2363 fields[6].ToCDouble( &seg.x1 );
2364 fields[7].ToCDouble( &seg.y1 );
2365 fields[8].ToCDouble( &seg.x2 );
2366 fields[9].ToCDouble( &seg.y2 );
2367
2368 data.updateBounds( seg.x1, seg.y1 );
2369 data.updateBounds( seg.x2, seg.y2 );
2370 }
2371 else
2372 {
2373 continue;
2374 }
2375
2376 if( isDesignOutline )
2377 {
2378 data.designOutlineCount++;
2379 data.designOutlineSegments.push_back( seg );
2380 }
2381 else
2382 {
2383 data.outlineCount++;
2384 data.outlineSegments.push_back( seg );
2385 }
2386 }
2387
2388 return data;
2389 }
2390
2396 {
2397 int count = 0;
2398
2399 for( const auto& seg : designOutlineSegments )
2400 {
2401 if( seg.type == SEGMENT_TYPE::RECTANGLE )
2402 count += 4;
2403 else
2404 count += 1;
2405 }
2406
2407 return count;
2408 }
2409};
2410
2411
2416BOOST_AUTO_TEST_CASE( OutlineSegmentCount )
2417{
2418 std::vector<BRD_ALG_PAIR> testBoards = getBoardsWithAlg();
2419
2420 BOOST_REQUIRE_GT( testBoards.size(), 0u );
2421
2422 for( const auto& [brdFile, algFile] : testBoards )
2423 {
2424 BOOST_TEST_CONTEXT( "Board: " << brdFile )
2425 {
2426 const ALG_OUTLINE_DATA& algOutlines = ALG_OUTLINE_DATA::GetCached( algFile );
2427
2428 if( algOutlines.designOutlineCount == 0 && algOutlines.outlineCount == 0 )
2429 {
2430 BOOST_TEST_MESSAGE( " No outline records in .alg, skipping" );
2431 continue;
2432 }
2433
2434 BOARD* board = GetCachedBoard( brdFile );
2435 BOOST_REQUIRE( board );
2436
2437 int edgeCutsCount = 0;
2438
2439 for( BOARD_ITEM* item : board->Drawings() )
2440 {
2441 if( item->Type() == PCB_SHAPE_T && item->GetLayer() == Edge_Cuts )
2442 edgeCutsCount++;
2443 }
2444
2445 int expectedCount = algOutlines.expectedEdgeCutsSegments();
2446
2447 BOOST_TEST_MESSAGE( " .alg DESIGN_OUTLINE records: " << algOutlines.designOutlineCount
2448 << " -> expected Edge_Cuts segments: " << expectedCount );
2449 BOOST_TEST_MESSAGE( " .alg OUTLINE records: " << algOutlines.outlineCount );
2450 BOOST_TEST_MESSAGE( " Binary import Edge_Cuts segments: " << edgeCutsCount );
2451
2452 BOOST_CHECK_EQUAL( edgeCutsCount, expectedCount );
2453 }
2454 }
2455}
2456
2457
2462BOOST_AUTO_TEST_CASE( OutlineBoundingBox )
2463{
2464 std::vector<BRD_ALG_PAIR> testBoards = getBoardsWithAlg();
2465
2466 BOOST_REQUIRE_GT( testBoards.size(), 0u );
2467
2468 // 1 mil = 25400 nm
2469 const double milToNm = 25400.0;
2470
2471 // Allow 2 mil tolerance for coordinate rounding across formats
2472 const int toleranceNm = static_cast<int>( 2.0 * milToNm );
2473
2474 for( const auto& [brdFile, algFile] : testBoards )
2475 {
2476 BOOST_TEST_CONTEXT( "Board: " << brdFile )
2477 {
2478 const ALG_OUTLINE_DATA& algOutlines = ALG_OUTLINE_DATA::GetCached( algFile );
2479
2480 if( algOutlines.designOutlineCount == 0 )
2481 {
2482 BOOST_TEST_MESSAGE( " No DESIGN_OUTLINE records in .alg, skipping" );
2483 continue;
2484 }
2485
2486 BOARD* board = GetCachedBoard( brdFile );
2487 BOOST_REQUIRE( board );
2488
2489 BOX2I boardBbox;
2490 bool hasBbox = false;
2491
2492 for( BOARD_ITEM* item : board->Drawings() )
2493 {
2494 if( item->Type() == PCB_SHAPE_T && item->GetLayer() == Edge_Cuts )
2495 {
2496 if( !hasBbox )
2497 {
2498 boardBbox = item->GetBoundingBox();
2499 hasBbox = true;
2500 }
2501 else
2502 {
2503 boardBbox.Merge( item->GetBoundingBox() );
2504 }
2505 }
2506 }
2507
2508 BOOST_REQUIRE_MESSAGE( hasBbox, "Board should have Edge_Cuts outline" );
2509
2510 // Convert .alg bounding box from mils to nm
2511 int algMinXnm = static_cast<int>( algOutlines.minX * milToNm );
2512 int algMinYnm = static_cast<int>( algOutlines.minY * milToNm );
2513 int algMaxXnm = static_cast<int>( algOutlines.maxX * milToNm );
2514 int algMaxYnm = static_cast<int>( algOutlines.maxY * milToNm );
2515 int algWidthNm = algMaxXnm - algMinXnm;
2516 int algHeightNm = algMaxYnm - algMinYnm;
2517
2518 int boardWidth = boardBbox.GetWidth();
2519 int boardHeight = boardBbox.GetHeight();
2520
2521 BOOST_TEST_MESSAGE( " .alg extent (mils): "
2522 << algOutlines.minX << "," << algOutlines.minY << " to "
2523 << algOutlines.maxX << "," << algOutlines.maxY
2524 << " = " << ( algOutlines.maxX - algOutlines.minX ) << " x "
2525 << ( algOutlines.maxY - algOutlines.minY ) );
2526 BOOST_TEST_MESSAGE( " Board bbox (nm): "
2527 << boardBbox.GetLeft() << "," << boardBbox.GetTop() << " to "
2528 << boardBbox.GetRight() << "," << boardBbox.GetBottom()
2529 << " = " << boardWidth << " x " << boardHeight );
2530 BOOST_TEST_MESSAGE( " .alg (nm): " << algWidthNm << " x " << algHeightNm );
2531
2532 // KiCad bounding boxes include line width so allow 3% tolerance
2533 BOOST_CHECK_CLOSE( static_cast<double>( boardWidth ),
2534 static_cast<double>( algWidthNm ), 3.0 );
2535 BOOST_CHECK_CLOSE( static_cast<double>( boardHeight ),
2536 static_cast<double>( algHeightNm ), 3.0 );
2537 }
2538 }
2539}
2540
2541
2549BOOST_AUTO_TEST_CASE( OutlineEndpoints )
2550{
2551 std::vector<BRD_ALG_PAIR> testBoards = getBoardsWithAlg();
2552
2553 BOOST_REQUIRE_GT( testBoards.size(), 0u );
2554
2555 const double milToNm = 25400.0;
2556 const int toleranceNm = static_cast<int>( 2.0 * milToNm );
2557
2558 for( const auto& [brdFile, algFile] : testBoards )
2559 {
2560 BOOST_TEST_CONTEXT( "Board: " << brdFile )
2561 {
2562 const ALG_OUTLINE_DATA& algOutlines = ALG_OUTLINE_DATA::GetCached( algFile );
2563
2564 if( algOutlines.designOutlineCount == 0 )
2565 continue;
2566
2567 // Only validate endpoint-by-endpoint for pure-LINE outlines
2568 bool allLines = true;
2569
2570 for( const auto& seg : algOutlines.designOutlineSegments )
2571 {
2574 {
2575 allLines = false;
2576 break;
2577 }
2578 }
2579
2580 if( !allLines )
2581 {
2582 BOOST_TEST_MESSAGE( " Outline has arcs, skipping endpoint-level validation" );
2583 continue;
2584 }
2585
2586 BOARD* board = GetCachedBoard( brdFile );
2587 BOOST_REQUIRE( board );
2588
2589 // Collect all Edge_Cuts segment endpoints
2590 struct ENDPOINT_PAIR
2591 {
2592 VECTOR2I start;
2593 VECTOR2I end;
2594 };
2595
2596 std::vector<ENDPOINT_PAIR> boardSegments;
2597
2598 for( BOARD_ITEM* item : board->Drawings() )
2599 {
2600 if( item->Type() != PCB_SHAPE_T || item->GetLayer() != Edge_Cuts )
2601 continue;
2602
2603 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
2604
2605 if( shape->GetShape() == SHAPE_T::SEGMENT )
2606 boardSegments.push_back( { shape->GetStart(), shape->GetEnd() } );
2607 }
2608
2609 // Build expected segments from .alg, expanding RECTANGLEs into 4 segments
2610 std::vector<ENDPOINT_PAIR> algSegments;
2611
2612 for( const auto& seg : algOutlines.designOutlineSegments )
2613 {
2614 if( seg.type == ALG_OUTLINE_DATA::SEGMENT_TYPE::LINE )
2615 {
2616 VECTOR2I start( static_cast<int>( seg.x1 * milToNm ),
2617 static_cast<int>( seg.y1 * milToNm ) );
2618 VECTOR2I end( static_cast<int>( seg.x2 * milToNm ),
2619 static_cast<int>( seg.y2 * milToNm ) );
2620 algSegments.push_back( { start, end } );
2621 }
2622 else if( seg.type == ALG_OUTLINE_DATA::SEGMENT_TYPE::RECTANGLE )
2623 {
2624 int x1 = static_cast<int>( seg.x1 * milToNm );
2625 int y1 = static_cast<int>( seg.y1 * milToNm );
2626 int x2 = static_cast<int>( seg.x2 * milToNm );
2627 int y2 = static_cast<int>( seg.y2 * milToNm );
2628
2629 algSegments.push_back( { { x1, y1 }, { x2, y1 } } );
2630 algSegments.push_back( { { x2, y1 }, { x2, y2 } } );
2631 algSegments.push_back( { { x2, y2 }, { x1, y2 } } );
2632 algSegments.push_back( { { x1, y2 }, { x1, y1 } } );
2633 }
2634 }
2635
2636 BOOST_CHECK_EQUAL( boardSegments.size(), algSegments.size() );
2637
2638 if( boardSegments.size() != algSegments.size() )
2639 continue;
2640
2641 // Match each .alg segment to a board segment by finding closest start/end pair.
2642 // Allegro and KiCad may have opposite Y axis, so we compare using absolute
2643 // coordinate deltas.
2644 int matchedCount = 0;
2645
2646 std::vector<bool> used( boardSegments.size(), false );
2647
2648 for( size_t ai = 0; ai < algSegments.size(); ++ai )
2649 {
2650 const auto& algSeg = algSegments[ai];
2651 int bestIdx = -1;
2652 int64_t bestDist = std::numeric_limits<int64_t>::max();
2653
2654 for( size_t bi = 0; bi < boardSegments.size(); ++bi )
2655 {
2656 if( used[bi] )
2657 continue;
2658
2659 const auto& bSeg = boardSegments[bi];
2660
2661 // Try both orientations (start-start or start-end swap)
2662 auto dist = [&]( const VECTOR2I& aAlgPt, const VECTOR2I& aBoardPt ) -> int64_t
2663 {
2664 int64_t dx = std::abs( static_cast<int64_t>( aAlgPt.x )
2665 - static_cast<int64_t>( aBoardPt.x ) );
2666 int64_t dy = std::abs( static_cast<int64_t>( aAlgPt.y )
2667 - static_cast<int64_t>( aBoardPt.y ) );
2668 return dx + dy;
2669 };
2670
2671 int64_t d1 = dist( algSeg.start, bSeg.start ) + dist( algSeg.end, bSeg.end );
2672 int64_t d2 = dist( algSeg.start, bSeg.end ) + dist( algSeg.end, bSeg.start );
2673 int64_t d = std::min( d1, d2 );
2674
2675 if( d < bestDist )
2676 {
2677 bestDist = d;
2678 bestIdx = static_cast<int>( bi );
2679 }
2680 }
2681
2682 if( bestIdx >= 0 && bestDist < 2LL * toleranceNm )
2683 {
2684 used[bestIdx] = true;
2685 matchedCount++;
2686 }
2687 else
2688 {
2689 BOOST_TEST_MESSAGE( " Unmatched .alg segment " << ai << ": ("
2690 << algSeg.start.x / 1000000.0 << ", "
2691 << algSeg.start.y / 1000000.0 << ") -> ("
2692 << algSeg.end.x / 1000000.0 << ", "
2693 << algSeg.end.y / 1000000.0 << ") mm"
2694 << " bestDist=" << bestDist );
2695 }
2696 }
2697
2698 BOOST_TEST_MESSAGE( " Matched " << matchedCount << " / " << algSegments.size()
2699 << " outline segments" );
2700
2701 BOOST_CHECK_EQUAL( matchedCount, static_cast<int>( algSegments.size() ) );
2702 }
2703 }
2704}
2705
2706
2711BOOST_AUTO_TEST_CASE( PadDrillConsistency )
2712{
2713 std::vector<std::string> boards = GetAllBoardFiles();
2714
2715 for( const std::string& boardPath : boards )
2716 {
2717 std::string boardName = std::filesystem::path( boardPath ).filename().string();
2718 BOARD* board = GetCachedBoard( boardPath );
2719
2720 if( !board )
2721 continue;
2722
2723 BOOST_TEST_CONTEXT( "Testing board: " << boardName )
2724 {
2725 int pthNoDrill = 0;
2726 int smdWithDrill = 0;
2727
2728 for( FOOTPRINT* fp : board->Footprints() )
2729 {
2730 for( PAD* pad : fp->Pads() )
2731 {
2732 PAD_ATTRIB attr = pad->GetAttribute();
2733 bool hasDrill = pad->GetDrillSize().x > 0;
2734
2735 if( attr == PAD_ATTRIB::PTH && !hasDrill )
2736 {
2737 pthNoDrill++;
2738
2739 if( pthNoDrill <= 5 )
2740 {
2741 BOOST_TEST_MESSAGE( boardName << ": PTH pad without drill: "
2742 << fp->GetReference() << "."
2743 << pad->GetNumber() );
2744 }
2745 }
2746
2747 if( attr == PAD_ATTRIB::SMD && hasDrill )
2748 {
2749 smdWithDrill++;
2750
2751 if( smdWithDrill <= 5 )
2752 {
2753 BOOST_TEST_MESSAGE( boardName << ": SMD pad with drill: "
2754 << fp->GetReference() << "."
2755 << pad->GetNumber() );
2756 }
2757 }
2758 }
2759 }
2760
2761 BOOST_CHECK_EQUAL( pthNoDrill, 0 );
2762 BOOST_CHECK_EQUAL( smdWithDrill, 0 );
2763 }
2764 }
2765}
2766
2767
2771BOOST_AUTO_TEST_CASE( ZoneCountMatchesAlg )
2772{
2773 std::vector<BRD_ALG_PAIR> boardsWithAlg = getBoardsWithAlg();
2774
2775 BOOST_REQUIRE_GT( boardsWithAlg.size(), 0u );
2776
2777 for( const auto& [brdFile, algFile] : boardsWithAlg )
2778 {
2779 BOOST_TEST_CONTEXT( "Zone count: " << brdFile )
2780 {
2781 const ALG_REFERENCE_DATA& algData = ALG_REFERENCE_DATA::GetCached( algFile );
2782
2783 BOARD* board = GetCachedBoard( brdFile );
2784 BOOST_REQUIRE( board );
2785
2786 size_t boardCopperZoneLayers = 0;
2787
2788 for( const ZONE* zone : board->Zones() )
2789 {
2790 if( !zone->GetIsRuleArea() )
2791 boardCopperZoneLayers += ( zone->GetLayerSet() & LSET::AllCuMask() ).count();
2792 }
2793
2794 size_t algZoneCount = algData.zonePolygons.size();
2795
2796 BOOST_TEST_MESSAGE( brdFile << ": .alg has " << algZoneCount
2797 << " zone polygons, board has " << boardCopperZoneLayers
2798 << " copper zone-layers" );
2799
2800 BOOST_CHECK_EQUAL( static_cast<size_t>( boardCopperZoneLayers ), algZoneCount );
2801 }
2802 }
2803}
2804
2805
2809BOOST_AUTO_TEST_CASE( ZoneLayerDistribution )
2810{
2811 std::vector<BRD_ALG_PAIR> boardsWithAlg = getBoardsWithAlg();
2812
2813 BOOST_REQUIRE_GT( boardsWithAlg.size(), 0u );
2814
2815 for( const auto& [brdFile, algFile] : boardsWithAlg )
2816 {
2817 BOOST_TEST_CONTEXT( "Zone layers: " << brdFile )
2818 {
2819 const ALG_REFERENCE_DATA& algData = ALG_REFERENCE_DATA::GetCached( algFile );
2820
2821 BOARD* board = GetCachedBoard( brdFile );
2822 BOOST_REQUIRE( board );
2823
2824 std::map<wxString, int> algLayerCounts;
2825
2826 for( const ALG_ZONE_POLYGON& zone : algData.zonePolygons )
2827 algLayerCounts[zone.layer]++;
2828
2829 std::map<wxString, int> boardLayerCounts;
2830
2831 for( const ZONE* zone : board->Zones() )
2832 {
2833 if( zone->GetIsRuleArea() )
2834 continue;
2835
2836 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
2837 {
2838 if( IsCopperLayer( layer ) )
2839 boardLayerCounts[board->GetLayerName( layer )]++;
2840 }
2841 }
2842
2843 BOOST_TEST_MESSAGE( brdFile << " layer distribution:" );
2844
2845 for( const auto& [layer, count] : algLayerCounts )
2846 {
2847 auto it = boardLayerCounts.find( layer );
2848 int boardCount = ( it != boardLayerCounts.end() ) ? it->second : 0;
2849
2850 BOOST_TEST_MESSAGE( " " << layer << ": .alg=" << count << " board=" << boardCount );
2851 BOOST_CHECK_EQUAL( boardCount, count );
2852 }
2853 }
2854 }
2855}
2856
2857
2862BOOST_AUTO_TEST_CASE( ZoneBoundingBoxes )
2863{
2864 std::vector<BRD_ALG_PAIR> boardsWithAlg = getBoardsWithAlg();
2865
2866 BOOST_REQUIRE_GT( boardsWithAlg.size(), 0u );
2867
2868 for( const auto& [brdFile, algFile] : boardsWithAlg )
2869 {
2870 BOOST_TEST_CONTEXT( "Zone bboxes: " << brdFile )
2871 {
2872 const ALG_REFERENCE_DATA& algData = ALG_REFERENCE_DATA::GetCached( algFile );
2873
2874 BOARD* board = GetCachedBoard( brdFile );
2875 BOOST_REQUIRE( board );
2876
2877 // Collect sorted areas per layer from .alg and board, then compare distributions
2878 const double milsToNm = 25400.0;
2879
2880 std::map<wxString, std::vector<double>> algAreas;
2881
2882 for( const ALG_ZONE_POLYGON& zone : algData.zonePolygons )
2883 {
2884 double w = ( zone.maxX - zone.minX ) * milsToNm;
2885 double h = ( zone.maxY - zone.minY ) * milsToNm;
2886 algAreas[zone.layer].push_back( w * h );
2887 }
2888
2889 std::map<wxString, std::vector<double>> boardAreas;
2890
2891 for( const ZONE* zone : board->Zones() )
2892 {
2893 if( zone->GetIsRuleArea() )
2894 continue;
2895
2896 BOX2I bbox = zone->GetBoundingBox();
2897 double area = static_cast<double>( bbox.GetWidth() )
2898 * static_cast<double>( bbox.GetHeight() );
2899
2900 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
2901 {
2902 if( IsCopperLayer( layer ) )
2903 boardAreas[board->GetLayerName( layer )].push_back( area );
2904 }
2905 }
2906
2907 int matched = 0;
2908 int mismatched = 0;
2909
2910 for( auto& [layer, algList] : algAreas )
2911 {
2912 std::sort( algList.begin(), algList.end() );
2913 auto it = boardAreas.find( layer );
2914
2915 if( it == boardAreas.end() || it->second.size() != algList.size() )
2916 continue;
2917
2918 std::sort( it->second.begin(), it->second.end() );
2919
2920 for( size_t i = 0; i < algList.size(); ++i )
2921 {
2922 double ref = std::max( algList[i], 1.0 );
2923 double err = std::abs( it->second[i] - algList[i] ) / ref;
2924
2925 if( err < 0.10 )
2926 {
2927 matched++;
2928 }
2929 else
2930 {
2931 mismatched++;
2932
2933 if( mismatched <= 5 )
2934 {
2935 BOOST_TEST_MESSAGE( " " << layer << " index " << i
2936 << ": alg area " << algList[i] / ( milsToNm * milsToNm )
2937 << " sq mils vs board area "
2938 << it->second[i] / ( milsToNm * milsToNm )
2939 << " sq mils" );
2940 }
2941 }
2942 }
2943 }
2944
2945 BOOST_TEST_MESSAGE( brdFile << ": " << matched << " zone areas matched, "
2946 << mismatched << " mismatched" );
2947
2948 int total = matched + mismatched;
2949
2950 if( total > 0 )
2951 {
2952 BOOST_CHECK_GT( matched, total * 8 / 10 );
2953 }
2954 }
2955 }
2956}
2957
2958
2965BOOST_AUTO_TEST_CASE( PadContainedInFabOutline )
2966{
2967 std::string dataPath = KI_TEST::AllegroBoardFile( "BeagleBone_Black_RevC/BeagleBone_Black_RevC.brd" );
2968
2969 BOARD* board = GetCachedBoard( dataPath );
2970 BOOST_REQUIRE( board );
2971
2972 // Footprints known to have pads and fab outlines that enclose them.
2973 // P6 and P10 are excluded: they are bottom-side connectors whose assembly outlines
2974 // only cover the housing, not the full pin field.
2975 const std::set<wxString> targetRefs = { wxS( "J1" ), wxS( "P5" ), wxS( "U5" ),
2976 wxS( "U13" ), wxS( "C78" ) };
2977
2978 int testedCount = 0;
2979 int failedCount = 0;
2980
2981 for( FOOTPRINT* fp : board->Footprints() )
2982 {
2983 if( targetRefs.find( fp->GetReference() ) == targetRefs.end() )
2984 continue;
2985
2986 PCB_LAYER_ID fabLayer = fp->IsFlipped() ? B_Fab : F_Fab;
2987
2988 BOX2I fabBbox;
2989 bool hasFab = false;
2990
2991 for( BOARD_ITEM* item : fp->GraphicalItems() )
2992 {
2993 if( item->GetLayer() == fabLayer )
2994 {
2995 if( !hasFab )
2996 {
2997 fabBbox = item->GetBoundingBox();
2998 hasFab = true;
2999 }
3000 else
3001 {
3002 fabBbox.Merge( item->GetBoundingBox() );
3003 }
3004 }
3005 }
3006
3007 if( !hasFab || fp->Pads().empty() )
3008 continue;
3009
3010 // Allow generous tolerance: pad centers can extend slightly beyond the fab outline
3011 // (e.g. edge-mount connectors, thermal pads). 3mm handles most cases.
3012 BOX2I testBbox = fabBbox;
3013 testBbox.Inflate( 3000000 );
3014
3015 BOOST_TEST_CONTEXT( "Footprint " << fp->GetReference() )
3016 {
3017 testedCount++;
3018
3019 for( PAD* pad : fp->Pads() )
3020 {
3021 VECTOR2I padCenter = pad->GetPosition();
3022
3023 if( !testBbox.Contains( padCenter ) )
3024 {
3025 failedCount++;
3026 BOOST_TEST_MESSAGE( fp->GetReference() << " pad " << pad->GetNumber()
3027 << " at (" << padCenter.x / 1e6 << ", "
3028 << padCenter.y / 1e6 << ") mm is outside F.Fab bbox" );
3029 }
3030 }
3031 }
3032 }
3033
3034 BOOST_TEST_MESSAGE( "Tested " << testedCount << " footprints for pad containment" );
3035 BOOST_CHECK_GE( testedCount, 4 );
3036 BOOST_CHECK_EQUAL( failedCount, 0 );
3037}
3038
3039
3045BOOST_AUTO_TEST_CASE( PadOrientationP6P10 )
3046{
3047 std::string dataPath = KI_TEST::AllegroBoardFile( "BeagleBone_Black_RevC/BeagleBone_Black_RevC.brd" );
3048
3049 BOARD* board = GetCachedBoard( dataPath );
3050 BOOST_REQUIRE( board );
3051
3052 for( FOOTPRINT* fp : board->Footprints() )
3053 {
3054 wxString ref = fp->GetReference();
3055
3056 if( ref != wxS( "P6" ) && ref != wxS( "P10" ) )
3057 continue;
3058
3059 BOOST_TEST_CONTEXT( "Footprint " << ref )
3060 {
3061 for( PAD* pad : fp->Pads() )
3062 {
3063 long padNum = 0;
3064
3065 if( !pad->GetNumber().ToLong( &padNum ) )
3066 continue;
3067
3068 // Pads 1-19 on P6/P10 are rectangular SMD pads that should be wider than tall
3069 if( padNum < 1 || padNum > 19 )
3070 continue;
3071
3072 // GetBoundingBox accounts for rotation, giving visual dimensions
3073 BOX2I bbox = pad->GetBoundingBox();
3074 auto bboxW = bbox.GetWidth();
3075 auto bboxH = bbox.GetHeight();
3076
3077 // Skip square/circular pads where orientation doesn't affect shape
3078 if( bboxW == bboxH )
3079 continue;
3080
3081 BOOST_TEST_CONTEXT( "Pad " << pad->GetNumber() )
3082 {
3083 BOOST_CHECK_MESSAGE( bboxW > bboxH,
3084 ref << " pad " << pad->GetNumber()
3085 << " should be visually wider than tall: "
3086 << bboxW / 1e6 << " x " << bboxH / 1e6 << " mm" );
3087 }
3088 }
3089 }
3090 }
3091}
3092
3093
3102{
3103 std::string dataPath = KI_TEST::AllegroBoardFile( "BeagleBone_Black_RevC/BeagleBone_Black_RevC.brd" );
3104
3105 BOARD* board = GetCachedBoard( dataPath );
3106 BOOST_REQUIRE( board );
3107
3108 int oblongCount = 0;
3109
3110 for( FOOTPRINT* fp : board->Footprints() )
3111 {
3112 for( PAD* pad : fp->Pads() )
3113 {
3114 VECTOR2I drillSize = pad->GetDrillSize();
3115
3116 if( drillSize.x <= 0 || drillSize.y <= 0 )
3117 continue;
3118
3119 if( drillSize.x == drillSize.y )
3120 continue;
3121
3122 oblongCount++;
3123
3124 BOOST_TEST_CONTEXT( fp->GetReference() << " pad " << pad->GetNumber() )
3125 {
3126 BOOST_CHECK( pad->GetDrillShape() == PAD_DRILL_SHAPE::OBLONG );
3127
3128 BOOST_TEST_MESSAGE( fp->GetReference() << " pad " << pad->GetNumber()
3129 << " slot: " << drillSize.x / 1e6 << " x "
3130 << drillSize.y / 1e6 << " mm"
3131 << " attr=" << static_cast<int>( pad->GetAttribute() ) );
3132 }
3133 }
3134 }
3135
3136 BOOST_TEST_MESSAGE( "Found " << oblongCount << " oblong drill holes" );
3137 BOOST_CHECK_EQUAL( oblongCount, 7 );
3138}
3139
3140
3146BOOST_AUTO_TEST_CASE( FootprintOrientation )
3147{
3148 std::string dataPath = KI_TEST::AllegroBoardFile( "BeagleBone_Black_RevC/BeagleBone_Black_RevC.brd" );
3149
3150 BOARD* board = GetCachedBoard( dataPath );
3151
3152 BOOST_REQUIRE( board );
3153
3154 FOOTPRINT* j1 = nullptr;
3155
3156 for( FOOTPRINT* fp : board->Footprints() )
3157 {
3158 if( fp->GetReference() == wxT( "J1" ) )
3159 {
3160 j1 = fp;
3161 break;
3162 }
3163 }
3164
3165 BOOST_REQUIRE_MESSAGE( j1 != nullptr, "Footprint J1 must exist in BeagleBone_Black_RevC" );
3166
3168 BOOST_TEST_MESSAGE( "J1 orientation: " << orientation.AsDegrees() << " degrees" );
3169 BOOST_CHECK_CLOSE( orientation.AsDegrees(), 90.0, 0.1 );
3170}
3171
3172
3177BOOST_AUTO_TEST_CASE( UIImportPath_NullBoard )
3178{
3179 std::string dataPath = KI_TEST::AllegroBoardFile( "ProiectBoard/ProiectBoard.brd" );
3180
3181 PCB_IO_ALLEGRO plugin;
3183 plugin.SetReporter( &reporter );
3184
3185 std::unique_ptr<BOARD> board;
3186
3187 try
3188 {
3189 board = plugin.LoadBoard( dataPath );
3190 }
3191 catch( const IO_ERROR& e )
3192 {
3193 BOOST_TEST_MESSAGE( "IO_ERROR: " << e.What() );
3194 }
3195 catch( const std::exception& e )
3196 {
3197 BOOST_TEST_MESSAGE( "Exception: " << e.what() );
3198 }
3199
3200 reporter.PrintAllMessages( "UIImportPath_NullBoard" );
3201
3202 BOOST_REQUIRE_MESSAGE( board != nullptr, "LoadBoard must return a valid board" );
3203
3204 BOOST_CHECK_GT( board->GetNetCount(), 0 );
3205 BOOST_CHECK_GT( board->Footprints().size(), 0 );
3206 BOOST_CHECK_GT( board->Tracks().size(), 0 );
3207 BOOST_CHECK_EQUAL( reporter.GetErrorCount(), 0 );
3208
3209 PrintBoardStats( board.get(), "ProiectBoard (UI path)" );
3210}
3211
3212
3221BOOST_AUTO_TEST_CASE( SmdPadLayerConsistency )
3222{
3223 std::vector<std::string> boards = GetAllBoardFiles();
3224
3225 for( const std::string& boardPath : boards )
3226 {
3227 std::string boardName = std::filesystem::path( boardPath ).filename().string();
3228 BOARD* board = GetCachedBoard( boardPath );
3229
3230 if( !board )
3231 continue;
3232
3233 BOOST_TEST_CONTEXT( "Testing board: " << boardName )
3234 {
3235 int inconsistentCount = 0;
3236
3237 for( FOOTPRINT* fp : board->Footprints() )
3238 {
3239 const bool onBottom = fp->IsFlipped();
3240
3241 for( PAD* pad : fp->Pads() )
3242 {
3243 if( pad->GetAttribute() != PAD_ATTRIB::SMD )
3244 continue;
3245
3246 LSET layers = pad->GetLayerSet();
3247 bool hasTopCopper = layers.Contains( F_Cu );
3248 bool hasBotCopper = layers.Contains( B_Cu );
3249
3250 if( onBottom && hasTopCopper && !hasBotCopper )
3251 {
3252 inconsistentCount++;
3253 BOOST_TEST_MESSAGE( boardName << ": " << fp->GetReference() << " pad "
3254 << pad->GetNumber() << " is on bottom footprint but SMD "
3255 << "pad has F.Cu without B.Cu" );
3256 }
3257 else if( !onBottom && hasBotCopper && !hasTopCopper )
3258 {
3259 inconsistentCount++;
3260 BOOST_TEST_MESSAGE( boardName << ": " << fp->GetReference() << " pad "
3261 << pad->GetNumber() << " is on top footprint but SMD "
3262 << "pad has B.Cu without F.Cu" );
3263 }
3264 }
3265 }
3266
3267 BOOST_CHECK_EQUAL( inconsistentCount, 0 );
3268 }
3269 }
3270}
3271
3272
3281BOOST_AUTO_TEST_CASE( SmdFootprintTechLayers )
3282{
3283 // Note that this test is NOT true for all boards - some boards have SMD FPs with
3284 // back-layer items.
3285 std::vector<std::string> boards = {
3286 KI_TEST::AllegroBoardFile( "EVK_BaseBoard/EVK_BaseBoard.brd" ),
3287 };
3288
3289 for( const std::string& boardPath : boards )
3290 {
3291 std::string boardName = std::filesystem::path( boardPath ).filename().string();
3292 BOARD* board = GetCachedBoard( boardPath );
3293
3294 BOOST_REQUIRE( board );
3295
3296 BOOST_TEST_CONTEXT( "Testing board: " << boardName )
3297 {
3298 int inconsistentCount = 0;
3299 int checkedFootprints = 0;
3300
3301 for( FOOTPRINT* fp : board->Footprints() )
3302 {
3303 // Only check SMD-only footprints (no through-hole pads)
3304 bool hasSmd = false;
3305 bool hasTH = false;
3306
3307 for( PAD* pad : fp->Pads() )
3308 {
3309 if( pad->GetAttribute() == PAD_ATTRIB::SMD )
3310 hasSmd = true;
3311 else if( pad->GetAttribute() == PAD_ATTRIB::PTH )
3312 hasTH = true;
3313 }
3314
3315 if( !hasSmd || hasTH )
3316 continue;
3317
3318 checkedFootprints++;
3319
3320 const bool onBottom = fp->IsFlipped();
3321
3322 for( BOARD_ITEM* item : fp->GraphicalItems() )
3323 {
3324 PCB_LAYER_ID layer = item->GetLayer();
3325
3326 if( !IsFrontLayer( layer ) && !IsBackLayer( layer ) )
3327 continue;
3328
3329 bool wrongSide = false;
3330
3331 if( onBottom && IsFrontLayer( layer ) )
3332 wrongSide = true;
3333 else if( !onBottom && IsBackLayer( layer ) )
3334 wrongSide = true;
3335
3336 if( wrongSide )
3337 {
3338 inconsistentCount++;
3340 boardName << ": " << fp->GetReference() << " is "
3341 << ( onBottom ? "bottom" : "top" ) << "-side SMD but has "
3342 << item->GetClass() << " on "
3343 << board->GetLayerName( layer ) );
3344 }
3345 }
3346 }
3347
3348 BOOST_TEST_MESSAGE( "Checked " << checkedFootprints
3349 << " SMD-only footprints for tech layer consistency" );
3350 BOOST_CHECK_EQUAL( inconsistentCount, 0 );
3351 }
3352 }
3353}
3354
3355
3362BOOST_AUTO_TEST_CASE( BeagleBone_DrillSlotOrientation )
3363{
3364 std::string dataPath = KI_TEST::AllegroBoardFile( "BeagleBone_Black_RevC/BeagleBone_Black_RevC.brd" );
3365
3366 BOARD* board = GetCachedBoard( dataPath );
3367 BOOST_REQUIRE( board );
3368
3369 struct SLOT_CHECK
3370 {
3371 wxString fpRef;
3372 wxString padNum;
3373 };
3374
3375 // These pads have vertical oblong copper shapes and should have taller-than-wide drill slots
3376 std::vector<SLOT_CHECK> checks = {
3377 { wxS( "P6" ), wxS( "20" ) },
3378 { wxS( "P6" ), wxS( "21" ) },
3379 { wxS( "P3" ), wxS( "6" ) },
3380 { wxS( "P1" ), wxS( "1" ) },
3381 { wxS( "P1" ), wxS( "2" ) },
3382 { wxS( "P1" ), wxS( "3" ) },
3383 };
3384
3385 for( const auto& check : checks )
3386 {
3387 BOOST_TEST_CONTEXT( check.fpRef << " pad " << check.padNum )
3388 {
3389 FOOTPRINT* fp = nullptr;
3390
3391 for( FOOTPRINT* candidate : board->Footprints() )
3392 {
3393 if( candidate->GetReference() == check.fpRef )
3394 {
3395 fp = candidate;
3396 break;
3397 }
3398 }
3399
3400 BOOST_REQUIRE_MESSAGE( fp != nullptr, "Footprint " << check.fpRef << " should exist" );
3401
3402 PAD* pad = nullptr;
3403
3404 for( PAD* candidate : fp->Pads() )
3405 {
3406 if( candidate->GetNumber() == check.padNum )
3407 {
3408 pad = candidate;
3409 break;
3410 }
3411 }
3412
3413 BOOST_REQUIRE_MESSAGE( pad != nullptr,
3414 "Pad " << check.padNum << " should exist on " << check.fpRef );
3415
3416 VECTOR2I padSize = pad->GetSize( F_Cu );
3417 VECTOR2I drillSize = pad->GetDrillSize();
3418
3419 BOOST_TEST_MESSAGE( check.fpRef << " pad " << check.padNum
3420 << ": pad=" << padSize.x << "x" << padSize.y
3421 << " drill=" << drillSize.x << "x" << drillSize.y );
3422
3423 // If the pad is oblong, the drill should match the pad's aspect ratio
3424 if( drillSize.x != drillSize.y )
3425 {
3426 bool padIsTaller = ( padSize.y > padSize.x );
3427 bool drillIsTaller = ( drillSize.y > drillSize.x );
3428
3429 BOOST_CHECK_MESSAGE( padIsTaller == drillIsTaller,
3430 "Drill slot should match pad orientation" );
3431 }
3432 }
3433 }
3434}
3435
3436
3441BOOST_AUTO_TEST_CASE( BeagleBone_ZoneFills )
3442{
3443 std::string dataPath = KI_TEST::AllegroBoardFile( "BeagleBone_Black_RevC/BeagleBone_Black_RevC.brd" );
3444
3445 BOARD* board = GetCachedBoard( dataPath );
3446 BOOST_REQUIRE( board );
3447
3448 int filledZoneCount = 0;
3449 int totalCopperZones = 0;
3450
3451 for( const ZONE* zone : board->Zones() )
3452 {
3453 if( zone->GetIsRuleArea() || zone->GetNetCode() == 0 )
3454 continue;
3455
3456 totalCopperZones++;
3457
3458 if( zone->IsFilled() )
3459 {
3460 filledZoneCount++;
3461
3462 BOOST_TEST_MESSAGE( "Filled zone: net=" << zone->GetNetname()
3463 << " layers=" << zone->GetLayerSet().count() );
3464 }
3465 }
3466
3467 BOOST_TEST_MESSAGE( "Total copper zones: " << totalCopperZones
3468 << ", filled: " << filledZoneCount );
3469
3470 BOOST_CHECK_GT( totalCopperZones, 0 );
3471 BOOST_CHECK_GT( filledZoneCount, 0 );
3472}
3473
3474
3479BOOST_AUTO_TEST_CASE( BeagleBone_Teardrops )
3480{
3481 std::string dataPath = KI_TEST::AllegroBoardFile( "BeagleBone_Black_RevC/BeagleBone_Black_RevC.brd" );
3482
3483 BOARD* board = GetCachedBoard( dataPath );
3484 BOOST_REQUIRE( board );
3485
3486 int teardropZones = 0;
3487
3488 for( const ZONE* zone : board->Zones() )
3489 {
3490 if( zone->IsTeardropArea() )
3491 teardropZones++;
3492 }
3493
3494 BOOST_CHECK_GT( teardropZones, 1000 );
3495 BOOST_TEST_MESSAGE( "Teardrop zones: " << teardropZones );
3496
3497 // Pads and vias anchoring teardrops must have teardrops enabled
3498 int padsWithTeardrops = 0;
3499 int totalPads = 0;
3500
3501 for( const FOOTPRINT* fp : board->Footprints() )
3502 {
3503 for( const PAD* pad : fp->Pads() )
3504 {
3505 totalPads++;
3506
3507 if( pad->GetTeardropsEnabled() )
3508 padsWithTeardrops++;
3509 }
3510 }
3511
3512 BOOST_CHECK_GT( padsWithTeardrops, 0 );
3513 BOOST_TEST_MESSAGE( "Pads with teardrops enabled: " << padsWithTeardrops << " / " << totalPads );
3514
3515 int viasWithTeardrops = 0;
3516 int totalVias = 0;
3517
3518 for( const PCB_TRACK* track : board->Tracks() )
3519 {
3520 if( track->Type() != PCB_VIA_T )
3521 continue;
3522
3523 totalVias++;
3524
3525 if( static_cast<const PCB_VIA*>( track )->GetTeardropsEnabled() )
3526 viasWithTeardrops++;
3527 }
3528
3529 BOOST_CHECK_GT( viasWithTeardrops, 0 );
3530 BOOST_TEST_MESSAGE( "Vias with teardrops enabled: " << viasWithTeardrops << " / " << totalVias );
3531}
3532
3533
3534BOOST_AUTO_TEST_CASE( BeagleBone_TeardropFillsHaveNoArcs )
3535{
3536 std::string dataPath = KI_TEST::AllegroBoardFile( "BeagleBone_Black_RevC/BeagleBone_Black_RevC.brd" );
3537
3538 BOARD* board = GetCachedBoard( dataPath );
3539 BOOST_REQUIRE( board );
3540
3541 int arcFills = 0;
3542
3543 for( const ZONE* zone : board->Zones() )
3544 {
3545 if( !zone->IsTeardropArea() )
3546 continue;
3547
3548 for( PCB_LAYER_ID layer : zone->GetLayerSet() )
3549 {
3550 if( !zone->HasFilledPolysForLayer( layer ) )
3551 continue;
3552
3553 const std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
3554
3555 for( int i = 0; i < fill->OutlineCount(); ++i )
3556 {
3557 if( fill->COutline( i ).ArcCount() > 0 )
3558 ++arcFills;
3559 }
3560 }
3561 }
3562
3563 BOOST_CHECK_EQUAL( arcFills, 0 );
3564}
3565
3566
3571BOOST_AUTO_TEST_CASE( PreV172_NoTeardrops )
3572{
3573 std::string dataPath = KI_TEST::AllegroBoardFile( "ProiectBoard/ProiectBoard.brd" );
3574
3575 BOARD* board = GetCachedBoard( dataPath );
3576 BOOST_REQUIRE( board );
3577
3578 int teardropZones = 0;
3579
3580 for( const ZONE* zone : board->Zones() )
3581 {
3582 if( zone->IsTeardropArea() )
3583 teardropZones++;
3584 }
3585
3586 BOOST_CHECK_EQUAL( teardropZones, 0 );
3587
3588 int padsWithTeardrops = 0;
3589
3590 for( const FOOTPRINT* fp : board->Footprints() )
3591 {
3592 for( const PAD* pad : fp->Pads() )
3593 {
3594 if( pad->GetTeardropsEnabled() )
3595 padsWithTeardrops++;
3596 }
3597 }
3598
3599 BOOST_CHECK_EQUAL( padsWithTeardrops, 0 );
3600}
3601
3602
3608BOOST_AUTO_TEST_CASE( LegacyNetclassFlags )
3609{
3610 std::string dataPath = KI_TEST::AllegroBoardFile( "TRS80_POWER/TRS80_POWER.brd" );
3611
3612 PCB_IO_ALLEGRO plugin;
3614 plugin.SetReporter( &reporter );
3615
3616 std::unique_ptr<BOARD> board = plugin.LoadBoard( dataPath );
3617
3618 BOOST_REQUIRE( board );
3619
3620 BOOST_CHECK_MESSAGE( board->m_LegacyNetclassesLoaded,
3621 "m_LegacyNetclassesLoaded must be true after Allegro import" );
3622 BOOST_CHECK_MESSAGE( board->m_LegacyDesignSettingsLoaded,
3623 "m_LegacyDesignSettingsLoaded must be true after Allegro import" );
3624}
3625
3626
3631BOOST_AUTO_TEST_CASE( NetclassesCreatedForAllBoards )
3632{
3633 std::vector<std::string> boards = GetAllBoardFiles();
3634
3635 for( const std::string& boardPath : boards )
3636 {
3637 std::string boardName = std::filesystem::path( boardPath ).filename().string();
3638 BOARD* board = GetCachedBoard( boardPath );
3639
3640 if( !board )
3641 continue;
3642
3643 BOOST_TEST_CONTEXT( "Testing board: " << boardName )
3644 {
3645 std::shared_ptr<NET_SETTINGS> netSettings = board->GetDesignSettings().m_NetSettings;
3646 const auto& netclasses = netSettings->GetNetclasses();
3647
3648 BOOST_TEST_MESSAGE( boardName << ": " << netclasses.size() << " netclasses" );
3649
3650 for( const auto& [name, nc] : netclasses )
3651 {
3652 BOOST_TEST_MESSAGE( " " << name << ": track="
3653 << nc->GetTrackWidth() << " clearance="
3654 << nc->GetClearance() );
3655
3656 // Constraint set netclasses should have positive track width.
3657 // Skip generated netclasses (DP_, MG_, W*mil) which may not set track width.
3658 if( !name.StartsWith( wxS( "DP_" ) )
3659 && !name.StartsWith( wxS( "MG_" ) )
3660 && !name.StartsWith( wxS( "W" ) ) )
3661 {
3662 BOOST_CHECK_MESSAGE( nc->HasTrackWidth(),
3663 name << " should have a track width" );
3664 BOOST_CHECK_MESSAGE( nc->GetTrackWidth() > 0,
3665 name << " track width should be positive" );
3666 }
3667 }
3668 }
3669 }
3670}
3671
3672
const char * name
General utilities for PCB file IO for QA programs.
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
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...
Definition board_item.h:99
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
const NETINFO_LIST & GetNetInfo() const
Definition board.h:1241
const ZONES & Zones() const
Definition board.h:469
PCB_LAYER_ID GetLayerID(const wxString &aLayerName) const
Return the ID of a layer.
Definition board.cpp:940
const FOOTPRINTS & Footprints() const
Definition board.h:465
const TRACKS & Tracks() const
Definition board.h:463
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition board.cpp:960
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
const DRAWINGS & Drawings() const
Definition board.h:467
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:556
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:597
constexpr size_type GetHeight() const
Definition box2.h:218
constexpr coord_type GetLeft() const
Definition box2.h:231
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:171
constexpr coord_type GetRight() const
Definition box2.h:220
constexpr coord_type GetTop() const
Definition box2.h:232
constexpr coord_type GetBottom() const
Definition box2.h:225
EDA_ANGLE Normalize()
Definition eda_angle.h:228
double AsDegrees() const
Definition eda_angle.h:115
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
std::vector< VECTOR2I > GetPolyPoints() const
Duplicate the polygon outlines into a flat list of VECTOR2I points.
SHAPE_T GetShape() const
Definition eda_shape.h:178
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:334
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:284
EDA_ANGLE GetOrientation() const
Definition footprint.h:382
std::deque< PAD * > & Pads()
Definition footprint.h:355
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition footprint.h:393
bool IsFlipped() const
Definition footprint.h:620
const std::vector< wxString > & GetNetTiePadGroups() const
Definition footprint.h:567
PAD * FindPadByNumber(const wxString &aPadNumber, PAD *aSearchAfterMe=nullptr) const
Return a PAD with a matching number.
VECTOR3D m_Offset
3D model offset (mm)
Definition footprint.h:134
VECTOR3D m_Rotation
3D model rotation (degrees)
Definition footprint.h:133
virtual void SetReporter(REPORTER *aReporter)
Set an optional reporter for warnings/errors.
Definition io_base.h:89
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
virtual const char * what() const override
std::exception interface, returned as UTF-8
static ALLEGRO_CACHED_LOADER & GetInstance()
Get the singleton instance of the Allegro board cache loader.
BOARD * GetCachedBoard(const std::string &aFilePath)
Get a cached board for the given file path, or load it if not already cached, without forcing a reloa...
Custom REPORTER that captures all messages for later analysis in the unit test framework.
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition lset.h:63
static const char Default[]
the name of the default NETCLASS
Definition netclass.h:46
Handle the data for a net.
Definition netinfo.h:50
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition netinfo.h:281
Definition pad.h:61
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
Definition pad.h:950
std::unique_ptr< BOARD > LoadBoard(const wxString &aFileName, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr)
Load information from some input file format that this PCB_IO implementation knows about into new BOA...
Definition pcb_io.cpp:72
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition pcb_shape.h:70
const VECTOR2I & GetStart() const
Definition pcb_track.h:100
const VECTOR2I & GetEnd() const
Definition pcb_track.h:97
Definition seg.h:38
Represent a set of closed polygons.
double Area()
Return the area of this poly set.
void BooleanIntersection(const SHAPE_POLY_SET &b)
Perform boolean polyset intersection.
Handle a list of polygons defining a copper zone.
Definition zone.h:70
bool IsFilled() const
Definition zone.h:306
PCB_LAYER_ID GetFirstLayer() const
Definition zone.cpp:632
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
@ NO_RECURSE
Definition eda_item.h:52
@ SEGMENT
Definition eda_shape.h:57
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:58
@ FP_BOARD_ONLY
Definition footprint.h:90
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
Definition layer_ids.h:847
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
Definition layer_ids.h:870
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:744
bool IsInnerCopperLayer(int aLayerId)
Test whether a layer is an inner (In1_Cu to In30_Cu) copper layer.
Definition layer_ids.h:766
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ Edge_Cuts
Definition layer_ids.h:108
@ F_Paste
Definition layer_ids.h:100
@ B_Mask
Definition layer_ids.h:94
@ B_Cu
Definition layer_ids.h:61
@ F_Mask
Definition layer_ids.h:93
@ B_Paste
Definition layer_ids.h:101
@ F_Fab
Definition layer_ids.h:115
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ F_Cu
Definition layer_ids.h:60
@ B_Fab
Definition layer_ids.h:114
std::array< SEG, 4 > BoxToSegs(const BOX2I &aBox)
Decompose a BOX2 into four segments.
Test utilities for timestamps.
std::string AllegroBoardDataDir(const std::string &aBoardName)
void PrintBoardStats(const BOARD *aBoard, const std::string &aBoardName)
Print detailed board statistics for debugging using test-framework logging.
void FillZones(BOARD *m_board)
std::string AllegroBoardFile(const std::string &aFileName)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
PAD_ATTRIB
The set of pad shapes, used with PAD::{Set,Get}Attribute().
Definition padstack.h:98
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:104
@ SMD
Smd pad, appears on the solder paste layer (default)
Definition padstack.h:100
@ PTH
Plated through hole pad.
Definition padstack.h:99
std::deque< BOARD_ITEM * > DRAWINGS
Utility functions for working with shapes.
Parse board outline geometry from a .alg ASCII reference file.
void updateBounds(double aX, double aY)
static ALG_OUTLINE_DATA ParseAlgOutlines(const std::string &aPath)
std::vector< OUTLINE_SEGMENT > designOutlineSegments
static const ALG_OUTLINE_DATA & GetCached(const std::string &aPath)
std::vector< OUTLINE_SEGMENT > outlineSegments
int expectedEdgeCutsSegments() const
Expected number of Edge_Cuts segments when translating to KiCad.
std::set< wxString > netNames
static ALG_REFERENCE_DATA ParseAlgFile(const std::string &aPath)
std::map< wxString, wxString > refDesToSymName
std::set< wxString > refDes
static std::vector< wxString > SplitAlgLine(const wxString &aLine)
std::vector< ALG_ZONE_POLYGON > zonePolygons
static int ParseRecordId(const wxString &aTag)
Extract the integer record ID from a RECORD_TAG field like "36 1 0".
static const ALG_REFERENCE_DATA & GetCached(const std::string &aPath)
std::map< wxString, std::set< wxString > > netToRefDes
Parse a FabMaster .alg file and extract reference data for cross-validation.
void AddPoint(double aX, double aY)
Data for parameterized all-boards test.
Fixture for comprehensive board import tests with error capturing.
BOARD * GetCachedBoard(const std::string &aFilePath)
Get a cached board, loading it on first access.
static std::vector< std::string > GetAllBoardFiles()
Get list of all .brd files in the Allegro test data directory.
std::unique_ptr< BOARD > LoadAllegroBoard(const std::string &aFileName)
BOOST_AUTO_TEST_CASE(FootprintRefDes)
Test that footprints have valid reference designators.
static void AssertOutlineValid(const BOARD &aBoard)
static std::vector< BRD_ALG_PAIR > getBoardsWithAlg()
Get a list of all board files in the test data that have a corresponding .alg reference file.
static unsigned CountOutlineElements(const BOARD &board)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE_MESSAGE(dc.CacheTableInfo(table, { "part_id", "val" }), dc.GetLastError())
BOOST_REQUIRE(res.columns()==1)
static EDA_ORIENTATION orientation(double d)
BOOST_AUTO_TEST_SUITE_END()
IbisParser parser & reporter
KIBIS top(path, &reporter)
VECTOR3I expected(15, 30, 45)
VECTOR2I end
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:103
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:84
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:90
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:88
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708