KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_kicad_sexpr.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <algorithm>
21#include <chrono>
22#include <filesystem>
23#include <fstream>
24#include <iterator>
25#include <memory>
26#include <sstream>
27#include <string>
28#include <thread>
29
30#include <qa_utils/file_utils.h>
34
37#include <progress_reporter.h>
38#include <richio.h>
39
40#include <board.h>
44#include <footprint.h>
45#include <netinfo.h>
46#include <pad.h>
47#include <pcb_group.h>
48#include <pcb_shape.h>
49#include <pcb_track.h>
50#include <zone.h>
51
52
53#define CHECK_ENUM_CLASS_EQUAL( L, R ) \
54 BOOST_CHECK_EQUAL( static_cast<int>( L ), static_cast<int>( R ) )
55
56
63
64
68BOOST_FIXTURE_TEST_SUITE( KiCadSexprIO, KICAD_SEXPR_FIXTURE )
69
70
71
74BOOST_AUTO_TEST_CASE( Issue19775_ZoneLayerWildcards )
75{
76 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "plugins/kicad_sexpr/Issue19775_ZoneLayers/";
77
78 BOOST_TEST_CONTEXT( "Zone layers with wildcards" )
79 {
80 std::unique_ptr<BOARD> testBoard = kicadPlugin.LoadBoard( dataPath + "LayerWildcard.kicad_pcb" );
81
82 // One zone in the file
83 BOOST_CHECK( testBoard->Zones().size() == 1 );
84
85 ZONE* z = testBoard->Zones()[0];
86
87 // On both front and back layers, with zone fill on both
91 }
92
93 BOOST_TEST_CONTEXT( "Round trip layers" )
94 {
95 auto tmpBoard = std::filesystem::temp_directory_path() / "Issue19775_RoundTrip.kicad_pcb";
96
97 // Load and save the board from above to test how we write the zones into it
98 {
99 std::unique_ptr<BOARD> testBoard = kicadPlugin.LoadBoard( dataPath + "LayerEnumerate.kicad_pcb" );
100 kicadPlugin.SaveBoard( tmpBoard.string(), *testBoard );
101 }
102
103 // Read the new board
104 std::unique_ptr<BOARD> testBoard = kicadPlugin.LoadBoard( tmpBoard.string() );
105
106 // One zone in the file
107 BOOST_CHECK( testBoard->Zones().size() == 1 );
108
109 ZONE* z = testBoard->Zones()[0];
110
111 // On both front and back layers, with zone fill on both
115 BOOST_CHECK( z->LayerProperties().contains( F_Cu ) );
116 }
117}
118
119
127BOOST_AUTO_TEST_CASE( Issue23125_EmptyZoneDiscarded )
128{
129 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
130 + "plugins/kicad_sexpr/Issue23125_EmptyZone/";
131
132 std::unique_ptr<BOARD> testBoard = kicadPlugin.LoadBoard( dataPath + "EmptyZone.kicad_pcb" );
133
134 // The file contains 3 zones: 1 valid (with polygon) and 2 empty (no polygon).
135 // The 2 empty zones should have been discarded during loading.
136 BOOST_CHECK_EQUAL( testBoard->Zones().size(), 1 );
137
138 // The surviving zone should have a valid position
139 ZONE* z = testBoard->Zones()[0];
140 BOOST_CHECK_NO_THROW( z->GetPosition() );
141 BOOST_CHECK( z->GetNumCorners() > 0 );
142}
143
144
150BOOST_AUTO_TEST_CASE( CoincidentDrawingsSurviveSave )
151{
152 // The writer sorts drawings into a std::set, so a cmp_drawings that reports equality for
153 // two coincident shapes silently drops one of them
154 BOARD board;
155
156 for( int ii = 0; ii < 2; ++ii )
157 {
158 PCB_SHAPE* line = new PCB_SHAPE( &board, SHAPE_T::SEGMENT );
159
160 line->SetLayer( F_SilkS );
161 line->SetStart( VECTOR2I( 0, 0 ) );
162 line->SetEnd( VECTOR2I( pcbIUScale.mmToIU( 5.0 ), 0 ) );
163 line->SetWidth( pcbIUScale.mmToIU( 0.1 ) );
164
165 board.Add( line, ADD_MODE::APPEND );
166 }
167
168 BOOST_REQUIRE_EQUAL( board.Drawings().size(), 2u );
169
170 const wxString path =
171 ( std::filesystem::temp_directory_path() / "qa_coincident_drawings.kicad_pcb" ).string();
172
173 kicadPlugin.SaveBoard( path, board );
174
175 std::unique_ptr<BOARD> reloaded = kicadPlugin.LoadBoard( path );
176
177 BOOST_REQUIRE( reloaded != nullptr );
178 BOOST_CHECK_EQUAL( reloaded->Drawings().size(), 2u );
179
180 std::filesystem::remove( path.ToStdString() );
181}
182
183
184BOOST_AUTO_TEST_CASE( ScientificNotationLoading )
185{
186 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
187 + "plugins/kicad_sexpr/";
188
189 std::unique_ptr<BOARD> testBoard = kicadPlugin.LoadBoard( dataPath + "ScientificNotation.kicad_pcb" );
190
191 // The file contains 1 arc with scientific notation in its coordinates
192 BOOST_CHECK_EQUAL( testBoard->Drawings().size(), 1 );
193
194 PCB_SHAPE* arc = dynamic_cast<PCB_SHAPE*>( testBoard->Drawings().front() );
195
196 // The arc's midpoint should be located at (4.17, -4.5e-05) in file units
197 BOOST_REQUIRE( arc );
198 BOOST_TEST( arc->GetArcMid().x == 4170000 );
199 BOOST_TEST( arc->GetArcMid().y == -45 );
200}
201
202
209BOOST_AUTO_TEST_CASE( Issue23625_CorruptedStackupCapped )
210{
211 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
212 + "plugins/kicad_sexpr/Issue23625_CorruptedStackup/";
213
214 std::unique_ptr<BOARD> testBoard;
215
216 BOOST_CHECK_NO_THROW( testBoard = kicadPlugin.LoadBoard( dataPath + "corrupted_stackup.kicad_pcb" ) );
217
218 const BOARD_STACKUP& stackup =
219 testBoard->GetDesignSettings().GetStackupDescriptor();
220
221 // The test file has 200 dielectric layers (plus copper, silk, mask), well
222 // beyond the parser's 128-item cap. After loading, the count must be
223 // clamped and the board must still be usable.
224 BOOST_CHECK_LE( stackup.GetCount(), 128 );
225 BOOST_CHECK_GT( stackup.GetCount(), 0 );
226}
227
228
236BOOST_AUTO_TEST_CASE( Issue24133_DuplicatedStackupNotInflated )
237{
238 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
239 + "plugins/kicad_sexpr/Issue24133_DuplicatedStackup/";
240
241 std::unique_ptr<BOARD> testBoard;
242
243 BOOST_CHECK_NO_THROW( testBoard = kicadPlugin.LoadBoard( dataPath + "duplicated_stackup.kicad_pcb" ) );
244
245 const BOARD_STACKUP& stackup = testBoard->GetDesignSettings().GetStackupDescriptor();
246
247 // The file repeats the 9-item layer sequence three times. Only the first copy must be kept.
248 BOOST_CHECK_EQUAL( stackup.GetCount(), 9 );
249
250 // A single copy is a standard 1.6 mm two-layer board. Without dedup the three copies would
251 // sum to 4.8 mm.
253}
254
255
262BOOST_AUTO_TEST_CASE( Issue23752_AppendBoardPreservesStackupAndGrowsToSixCopperLayers )
263{
264 std::string dataPath = KI_TEST::GetPcbnewTestDataDir();
265
266 // four layer board
267 std::string destinationPath = dataPath + "issue3812.kicad_pcb";
268 // six layer board
269 std::string sourcePath = dataPath + "issue18142.kicad_pcb";
270 std::map<std::string, UTF8> props;
271
272 // basically, make sure that we start with a four layer board, append a six layer
273 // board like this is a design block apply-layout with six layers, and make
274 // sure we end up with a six layer board and a six layer stackup and not a
275 // ten layer board
276 //
277 // we also need to test the stackup properties are preserved, because the increase
278 // in copper layers should cause a stackup growth from from four to six layers,
279 // but not replace the stackup with the source board's stackup, which has different properties (e.g. finish type)
281
282 auto countCopperLayers = []( const BOARD_STACKUP& aStackup )
283 {
284 int copperLayerCount = 0;
285
286 for( BOARD_STACKUP_ITEM* item : aStackup.GetList() )
287 {
288 if( item->GetType() == BS_ITEM_TYPE_COPPER )
289 ++copperLayerCount;
290 }
291
292 return copperLayerCount;
293 };
294
295 auto findFirstDielectric = []( const BOARD_STACKUP& aStackup ) -> const BOARD_STACKUP_ITEM*
296 {
297 for( BOARD_STACKUP_ITEM* item : aStackup.GetList() )
298 {
299 if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC )
300 return item;
301 }
302
303 return nullptr;
304 };
305
306 std::unique_ptr<BOARD> testBoard = kicadPlugin.LoadBoard( destinationPath );
307
308 const BOARD_STACKUP& initialStackup = testBoard->GetDesignSettings().GetStackupDescriptor();
309 const BOARD_STACKUP_ITEM* initialFirstDielectric = findFirstDielectric( initialStackup );
310 const int initialCopperLayerCount = testBoard->GetCopperLayerCount();
311 const LSET initialEnabledLayers = testBoard->GetEnabledLayers();
312 const wxString initialFinishType = initialStackup.m_FinishType;
313
314 BOOST_REQUIRE_EQUAL( initialCopperLayerCount, 4 );
315 BOOST_REQUIRE_EQUAL( countCopperLayers( initialStackup ), 4 );
316 BOOST_REQUIRE( initialFirstDielectric );
317 BOOST_REQUIRE_EQUAL( initialFinishType, wxS( "ENIG" ) );
318 const wxString initialFirstDielectricMaterial = initialFirstDielectric->GetMaterial();
319 const int initialFirstDielectricThickness = initialFirstDielectric->GetThickness();
320
321 kicadPlugin.LoadAndAppendBoard( sourcePath, *testBoard, &props );
322
323 const int appendedCopperLayerCount = testBoard->GetCopperLayerCount();
324
325 if( appendedCopperLayerCount > initialCopperLayerCount )
326 testBoard->SetCopperLayerCount( appendedCopperLayerCount );
327
328 LSET enabledLayers = testBoard->GetEnabledLayers();
329 enabledLayers |= initialEnabledLayers;
330 testBoard->SetEnabledLayers( enabledLayers );
331 testBoard->GetDesignSettings().GetStackupDescriptor().SynchronizeWithBoard( &testBoard->GetDesignSettings() );
332
333 const BOARD_STACKUP& finalStackup = testBoard->GetDesignSettings().GetStackupDescriptor();
334 const BOARD_STACKUP_ITEM* finalFirstDielectric = findFirstDielectric( finalStackup );
335
336 BOOST_CHECK_EQUAL( testBoard->GetCopperLayerCount(), 6 );
337 BOOST_CHECK_EQUAL( countCopperLayers( finalStackup ), 6 );
338 BOOST_REQUIRE( finalFirstDielectric );
339 BOOST_CHECK_EQUAL( finalStackup.m_FinishType, initialFinishType );
340 BOOST_CHECK_EQUAL( finalFirstDielectric->GetMaterial(), initialFirstDielectricMaterial );
341 BOOST_CHECK_EQUAL( finalFirstDielectric->GetThickness(), initialFirstDielectricThickness );
342}
343
344
352BOOST_AUTO_TEST_CASE( Issue24642_AppendBoardPreservesDestinationLayerNames )
353{
354 std::string dataPath = KI_TEST::GetPcbnewTestDataDir();
355
356 // four layer board with custom copper layer names
357 std::string destinationPath = dataPath + "issue3812.kicad_pcb";
358 // six layer board using the standard copper layer names
359 std::string sourcePath = dataPath + "issue18142.kicad_pcb";
360
361 std::map<std::string, UTF8> props;
363
364 std::unique_ptr<BOARD> testBoard = kicadPlugin.LoadBoard( destinationPath );
365
366 BOOST_REQUIRE_EQUAL( testBoard->GetLayerName( F_Cu ), wxS( "Top_layer" ) );
367 BOOST_REQUIRE_EQUAL( testBoard->GetLayerName( In1_Cu ), wxS( "GND_layer" ) );
368 BOOST_REQUIRE_EQUAL( testBoard->GetLayerName( In2_Cu ), wxS( "VDD_layer" ) );
369 BOOST_REQUIRE_EQUAL( testBoard->GetLayerName( B_Cu ), wxS( "Bottom_layer" ) );
370
371 kicadPlugin.LoadAndAppendBoard( sourcePath, *testBoard, &props );
372
373 // The destination layer names must survive the append
374 BOOST_CHECK_EQUAL( testBoard->GetLayerName( F_Cu ), wxS( "Top_layer" ) );
375 BOOST_CHECK_EQUAL( testBoard->GetLayerName( In1_Cu ), wxS( "GND_layer" ) );
376 BOOST_CHECK_EQUAL( testBoard->GetLayerName( In2_Cu ), wxS( "VDD_layer" ) );
377 BOOST_CHECK_EQUAL( testBoard->GetLayerName( B_Cu ), wxS( "Bottom_layer" ) );
378
379 // The two extra copper layers from the source board are still added
380 BOOST_CHECK( testBoard->IsLayerEnabled( In3_Cu ) );
381 BOOST_CHECK( testBoard->IsLayerEnabled( In4_Cu ) );
382 BOOST_CHECK_EQUAL( testBoard->GetCopperLayerCount(), 6 );
383}
384
385
392BOOST_AUTO_TEST_CASE( Issue24642_AppendBoardRemapsLayersViaHandler )
393{
394 std::string dataPath = KI_TEST::GetPcbnewTestDataDir();
395 // four layer board with custom copper names and tracks on In2.Cu
396 std::string sourcePath = dataPath + "issue3812.kicad_pcb";
397
398 std::map<std::string, UTF8> props;
400
401 auto countTracksOn = []( BOARD* aBoard, PCB_LAYER_ID aLayer )
402 {
403 int n = 0;
404
405 for( PCB_TRACK* track : aBoard->Tracks() )
406 {
407 if( track->GetLayer() == aLayer )
408 n++;
409 }
410
411 return n;
412 };
413
414 // Source copper user names as the handler sees them
415 const wxString fName = wxS( "Top_layer" );
416 const wxString in1Name = wxS( "GND_layer" );
417 const wxString in2Name = wxS( "VDD_layer" );
418 const wxString bName = wxS( "Bottom_layer" );
419
420 // Identity mapping: appended layers stay where they are
421 std::vector<wxString> seenNames;
422
423 kicadPlugin.RegisterCallback(
424 [&]( const std::vector<INPUT_LAYER_DESC>& aDescs ) -> std::map<wxString, PCB_LAYER_ID>
425 {
426 for( const INPUT_LAYER_DESC& desc : aDescs )
427 seenNames.push_back( desc.Name );
428
429 return { { fName, F_Cu }, { in1Name, In1_Cu }, { in2Name, In2_Cu }, { bName, B_Cu } };
430 } );
431
432 std::unique_ptr<BOARD> identityBoard = std::make_unique<BOARD>();
433
434 kicadPlugin.LoadAndAppendBoard( sourcePath, *identityBoard, &props );
435
436 // The dialog must see the source board's own layer names, not the canonical defaults
437 BOOST_CHECK( std::find( seenNames.begin(), seenNames.end(), in1Name ) != seenNames.end() );
438 BOOST_CHECK( std::find( seenNames.begin(), seenNames.end(), in2Name ) != seenNames.end() );
439
440 const int idIn1 = countTracksOn( identityBoard.get(), In1_Cu );
441 const int idIn2 = countTracksOn( identityBoard.get(), In2_Cu );
442
443 BOOST_REQUIRE_GT( idIn2, 0 ); // the source has tracks on In2.Cu
444
445 // Swap mapping: appended In1 <-> In2
446 kicadPlugin.RegisterCallback(
447 [&]( const std::vector<INPUT_LAYER_DESC>& ) -> std::map<wxString, PCB_LAYER_ID>
448 {
449 return { { fName, F_Cu }, { in1Name, In2_Cu }, { in2Name, In1_Cu }, { bName, B_Cu } };
450 } );
451
452 std::unique_ptr<BOARD> swapBoard = std::make_unique<BOARD>();
453
454 kicadPlugin.LoadAndAppendBoard( sourcePath, *swapBoard, &props );
455
456 const int swIn1 = countTracksOn( swapBoard.get(), In1_Cu );
457 const int swIn2 = countTracksOn( swapBoard.get(), In2_Cu );
458
459 // The inner-copper track counts must have swapped
460 BOOST_CHECK_EQUAL( swIn1, idIn2 );
461 BOOST_CHECK_EQUAL( swIn2, idIn1 );
462}
463
464
470BOOST_AUTO_TEST_CASE( Issue24642_AppendBoardPromptsOnlyOnNameMismatch )
471{
472 std::string dataPath = KI_TEST::GetPcbnewTestDataDir();
473 std::string standardNames = dataPath + "issue18142.kicad_pcb"; // six layer, default names
474 std::string customNames = dataPath + "issue3812.kicad_pcb"; // four layer, custom copper names
475
476 std::map<std::string, UTF8> props;
478
479 bool handlerCalled = false;
480
481 kicadPlugin.RegisterCallback(
482 [&]( const std::vector<INPUT_LAYER_DESC>& aDescs ) -> std::map<wxString, PCB_LAYER_ID>
483 {
484 handlerCalled = true;
485
486 std::map<wxString, PCB_LAYER_ID> remap;
487
488 for( const INPUT_LAYER_DESC& desc : aDescs )
489 remap[desc.Name] = desc.AutoMapLayer;
490
491 return remap;
492 } );
493
494 // Appending onto a board with identical layer names must not prompt
495 {
496 std::unique_ptr<BOARD> matchBoard = kicadPlugin.LoadBoard( standardNames );
497 handlerCalled = false;
498 kicadPlugin.LoadAndAppendBoard( standardNames, *matchBoard, &props );
499 BOOST_CHECK( !handlerCalled );
500 }
501
502 // Appending a board with differently-named layers must prompt
503 {
504 std::unique_ptr<BOARD> mismatchBoard = kicadPlugin.LoadBoard( standardNames );
505 handlerCalled = false;
506 kicadPlugin.LoadAndAppendBoard( customNames, *mismatchBoard, &props );
507 BOOST_CHECK( handlerCalled );
508 }
509}
510
511
529BOOST_AUTO_TEST_CASE( FootprintSave_OmitsNetsOnAllBoardConnectedItems )
530{
531 KI_TEST::SCOPED_TEMP_DIR tmpLib( wxS( "qa_fp_save_netinfo" ) );
532
533 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
534
535 NETINFO_ITEM* net = new NETINFO_ITEM( board.get(), wxT( "TestNet" ), 1 );
536 board->Add( net );
537
538 FOOTPRINT* fp = new FOOTPRINT( board.get() );
539 board->Add( fp );
540 fp->SetFPID( LIB_ID( wxT( "scratch" ), wxT( "test_fp_save_netinfo" ) ) );
541
542 PAD* pad = new PAD( fp );
543 pad->SetPadstackMode( PADSTACK::MODE::NORMAL );
545 pad->SetSize( PADSTACK::ALL_LAYERS,
546 VECTOR2I( pcbIUScale.mmToIU( 1 ), pcbIUScale.mmToIU( 1 ) ) );
547 pad->SetNet( net );
548 fp->Add( pad );
549
550 PCB_SHAPE* shape = new PCB_SHAPE( fp, SHAPE_T::SEGMENT );
551 shape->SetLayer( F_Cu );
552 shape->SetStart( VECTOR2I( 0, 0 ) );
553 shape->SetEnd( VECTOR2I( pcbIUScale.mmToIU( 5 ), 0 ) );
554 shape->SetNet( net );
555 fp->Add( shape );
556
557 ZONE* zone = new ZONE( fp );
558 zone->SetLayer( F_Cu );
559 zone->SetNet( net );
560 fp->Add( zone );
561
562 BOOST_REQUIRE_EQUAL( pad->GetNet(), net );
563 BOOST_REQUIRE_EQUAL( shape->GetNet(), net );
564 BOOST_REQUIRE_EQUAL( zone->GetNet(), net );
565
566 // Save into the scratch library via the public library-save API. Must not throw.
567 BOOST_REQUIRE_NO_THROW( kicadPlugin.FootprintSave( tmpLib.Path().string(), fp ) );
568
569 auto savedFile = tmpLib.Path() / "test_fp_save_netinfo.kicad_mod";
570 BOOST_REQUIRE( std::filesystem::exists( savedFile ) );
571
572 std::ifstream in( savedFile );
573 BOOST_REQUIRE_MESSAGE( in.is_open(),
574 "Failed to open serialized footprint: " << savedFile.string() );
575
576 std::stringstream ss;
577 ss << in.rdbuf();
578 BOOST_REQUIRE( !in.bad() );
579
580 // Windows refuses to unlink a file that still has an open handle, so release it before the
581 // scoped directory teardown.
582 in.close();
583
584 const std::string contents = ss.str();
585 BOOST_REQUIRE( !contents.empty() );
586
587 BOOST_CHECK_MESSAGE( contents.find( "(net " ) == std::string::npos,
588 "Saved footprint library file must not contain (net ...) tokens:\n"
589 << contents );
590
591 // Verify the second defense directly on the save-path's transient state: clone the
592 // footprint, detach it from its parent board exactly as FootprintSave does, invoke
593 // ClearAllNets(), and assert every BOARD_CONNECTED_ITEM descendant is orphaned. This
594 // catches a regression where FootprintSave stops calling ClearAllNets() even if the
595 // serializer guards keep the file contents looking correct.
596 std::unique_ptr<FOOTPRINT> detached( static_cast<FOOTPRINT*>( fp->Clone() ) );
597 detached->SetParent( nullptr );
598 detached->SetParentGroup( nullptr );
599 detached->ClearAllNets();
600
601 BOARD_CONNECTED_ITEM* detachedPad = nullptr;
602 BOARD_CONNECTED_ITEM* detachedShape = nullptr;
603 BOARD_CONNECTED_ITEM* detachedZone = nullptr;
604
605 detached->RunOnChildren(
606 [&]( BOARD_ITEM* aItem )
607 {
608 switch( aItem->Type() )
609 {
610 case PCB_PAD_T: detachedPad = static_cast<BOARD_CONNECTED_ITEM*>( aItem ); break;
611 case PCB_SHAPE_T: detachedShape = static_cast<BOARD_CONNECTED_ITEM*>( aItem ); break;
612 case PCB_ZONE_T: detachedZone = static_cast<BOARD_CONNECTED_ITEM*>( aItem ); break;
613 default: break;
614 }
615 },
617
618 BOOST_REQUIRE( detachedPad );
619 BOOST_REQUIRE( detachedShape );
620 BOOST_REQUIRE( detachedZone );
624}
625
626
635BOOST_AUTO_TEST_CASE( CopperThievingZone_RoundTrip )
636{
637 std::unique_ptr<BOARD> writeBoard = std::make_unique<BOARD>();
638
639 ZONE* zone = new ZONE( writeBoard.get() );
640 zone->SetLayer( F_Cu );
641 zone->AppendCorner( VECTOR2I( 0, 0 ), -1 );
642 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 10 ), 0 ), -1 );
643 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 10 ), pcbIUScale.mmToIU( 10 ) ), -1 );
644 zone->AppendCorner( VECTOR2I( 0, pcbIUScale.mmToIU( 10 ) ), -1 );
646
647 THIEVING_SETTINGS thieving;
649 thieving.element_size = pcbIUScale.mmToIU( 0.42 );
650 thieving.gap = pcbIUScale.mmToIU( 1.27 );
651 thieving.line_width = pcbIUScale.mmToIU( 0.35 );
652 thieving.stagger = true;
653 thieving.orientation.SetAngle( EDA_ANGLE( 30.0, DEGREES_T ) );
654 zone->SetThievingSettings( thieving );
655
656 writeBoard->Add( zone );
657
658 std::filesystem::path tmpPath = std::filesystem::temp_directory_path()
659 / "copper_thieving_roundtrip.kicad_pcb";
660
661 PCB_IO_KICAD_SEXPR writer;
662 writer.SaveBoard( tmpPath.string(), *writeBoard );
663
664 PCB_IO_KICAD_SEXPR reader;
665 std::unique_ptr<BOARD> readBoard = reader.LoadBoard( tmpPath.string() );
666
667 BOOST_REQUIRE_EQUAL( readBoard->Zones().size(), 1u );
668
669 ZONE* loaded = readBoard->Zones()[0];
670
672 BOOST_CHECK( loaded->IsCopperThieving() );
673 BOOST_CHECK_EQUAL( loaded->GetNetCode(), 0 );
674
675 const THIEVING_SETTINGS& loadedSettings = loaded->GetThievingSettings();
676 BOOST_CHECK( loadedSettings.pattern == THIEVING_PATTERN::HATCH );
677 BOOST_CHECK_EQUAL( loadedSettings.element_size, thieving.element_size );
678 BOOST_CHECK_EQUAL( loadedSettings.gap, thieving.gap );
679 BOOST_CHECK_EQUAL( loadedSettings.line_width, thieving.line_width );
680 BOOST_CHECK_EQUAL( loadedSettings.stagger, true );
681 BOOST_CHECK( loadedSettings.orientation.GetAngle() == EDA_ANGLE( 30.0, DEGREES_T ) );
682
683 std::filesystem::remove( tmpPath );
684}
685
686
691BOOST_AUTO_TEST_CASE( CopperThievingZone_AllPatternsRoundTrip )
692{
693 const std::array<THIEVING_PATTERN, 3> patterns = {
697 };
698
699 for( THIEVING_PATTERN pattern : patterns )
700 {
701 BOOST_TEST_CONTEXT( "pattern enum value " << static_cast<int>( pattern ) )
702 {
703 std::unique_ptr<BOARD> writeBoard = std::make_unique<BOARD>();
704
705 ZONE* zone = new ZONE( writeBoard.get() );
706 zone->SetLayer( F_Cu );
707 zone->AppendCorner( VECTOR2I( 0, 0 ), -1 );
708 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 5 ), 0 ), -1 );
709 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 5 ), pcbIUScale.mmToIU( 5 ) ), -1 );
710 zone->AppendCorner( VECTOR2I( 0, pcbIUScale.mmToIU( 5 ) ), -1 );
712
713 THIEVING_SETTINGS thieving = zone->GetThievingSettings();
714 thieving.pattern = pattern;
715 zone->SetThievingSettings( thieving );
716
717 writeBoard->Add( zone );
718
719 std::filesystem::path tmpPath = std::filesystem::temp_directory_path()
720 / "copper_thieving_pattern.kicad_pcb";
721 PCB_IO_KICAD_SEXPR writer;
722 writer.SaveBoard( tmpPath.string(), *writeBoard );
723
724 PCB_IO_KICAD_SEXPR reader;
725 std::unique_ptr<BOARD> readBoard = reader.LoadBoard( tmpPath.string() );
726
727 BOOST_REQUIRE_EQUAL( readBoard->Zones().size(), 1u );
728 BOOST_CHECK( readBoard->Zones()[0]->GetThievingSettings().pattern == pattern );
729
730 std::filesystem::remove( tmpPath );
731 }
732 }
733}
734
735
742BOOST_AUTO_TEST_CASE( CopperThievingZone_RejectedInOldFileVersion )
743{
744 std::filesystem::path tmpPath = std::filesystem::temp_directory_path()
745 / "copper_thieving_old_version.kicad_pcb";
746 std::ofstream out( tmpPath );
747 // 20260512 is the Net Chains release; thieving needs >= 20260513. Using the
748 // immediately-prior version exercises the boundary check.
749 out << "(kicad_pcb (version 20260512) (generator \"test\") (generator_version \"test\")"
750 << " (general (thickness 1.6)) (paper \"A4\")"
751 << " (layers (0 \"F.Cu\" signal) (31 \"B.Cu\" signal))"
752 << " (zone (net 0) (net_name \"\") (layer \"F.Cu\") (uuid \"00000000-0000-0000-0000-000000000001\")"
753 << " (hatch edge 0.5)"
754 << " (connect_pads (clearance 0))"
755 << " (min_thickness 0.25) (filled_areas_thickness no)"
756 << " (fill yes (mode thieving) (thermal_gap 0.5) (thermal_bridge_width 0.5)"
757 << " (island_removal_mode 0))"
758 << " (polygon (pts (xy 0 0) (xy 5 0) (xy 5 5) (xy 0 5))))"
759 << ")";
760 out.close();
761
762 PCB_IO_KICAD_SEXPR reader;
763 BOOST_REQUIRE_THROW( reader.LoadBoard( tmpPath.string() ), IO_ERROR );
764
765 std::filesystem::remove( tmpPath );
766}
767
768
769BOOST_AUTO_TEST_CASE( MalformedDimensionTextThrowsCleanly )
770{
771 KI_TEST::SCOPED_TEMP_DIR tempDir( "kicad_qa_malformed_dimension_text" );
772 std::filesystem::path tmpPath = tempDir.Path() / "malformed_dimension_text.kicad_pcb";
773 std::ofstream out( tmpPath );
774 out << "(kicad_pcb (version 20240108) (generator \"test\")"
775 << " (general (thickness 1.6)) (paper \"A4\")"
776 << " (layers (0 \"F.Cu\" signal) (31 \"B.Cu\" signal) (36 \"B.SilkS\" user \"b.silkscreen\"))"
777 << " (dimension (type aligned) (layer \"B.SilkS\")"
778 << " (gr_text \"1 mm\" (at broken))))";
779 out.close();
780
781 PCB_IO_KICAD_SEXPR reader;
782
783 BOOST_CHECK_THROW( reader.LoadBoard( tmpPath.string() ), IO_ERROR );
784}
785
786
793BOOST_AUTO_TEST_CASE( CopperThievingZone_RejectsMalformedGeometry )
794{
795 std::filesystem::path tmpPath = std::filesystem::temp_directory_path()
796 / "copper_thieving_malformed.kicad_pcb";
797 std::ofstream out( tmpPath );
798 out << "(kicad_pcb (version 20260513) (generator \"test\") (generator_version \"test\")"
799 << " (general (thickness 1.6)) (paper \"A4\")"
800 << " (layers (0 \"F.Cu\" signal) (31 \"B.Cu\" signal))"
801 << " (zone (net 0) (net_name \"\") (layer \"F.Cu\") (uuid \"00000000-0000-0000-0000-000000000002\")"
802 << " (hatch edge 0.5)"
803 << " (connect_pads (clearance 0))"
804 << " (min_thickness 0.25) (filled_areas_thickness no)"
805 << " (fill yes (mode thieving)"
806 << " (thermal_gap 0.5) (thermal_bridge_width 0.5)"
807 << " (island_removal_mode 0)"
808 << " (thieving (type dots) (size -1) (gap 0)"
809 << " (width -5) (stagger no) (orientation 0)))"
810 << " (polygon (pts (xy 0 0) (xy 5 0) (xy 5 5) (xy 0 5))))"
811 << ")";
812 out.close();
813
814 PCB_IO_KICAD_SEXPR reader;
815 std::unique_ptr<BOARD> readBoard = reader.LoadBoard( tmpPath.string() );
816
817 BOOST_REQUIRE_EQUAL( readBoard->Zones().size(), 1u );
818
819 const THIEVING_SETTINGS& loaded = readBoard->Zones()[0]->GetThievingSettings();
820 BOOST_CHECK_GT( loaded.element_size, 0 );
821 BOOST_CHECK_GT( loaded.gap, 0 );
822 BOOST_CHECK_GT( loaded.line_width, 0 );
823
824 std::filesystem::remove( tmpPath );
825}
826
827
835BOOST_AUTO_TEST_CASE( Issue24955_AppendDoesNotInheritSessionZoneDefaults )
836{
837 KI_TEST::SCOPED_TEMP_DIR tempDir( "kicad_qa_zone_defaults_append" );
838 std::filesystem::path tmpPath = tempDir.Path() / "thermal_zone_block.kicad_pcb";
839 std::ofstream out( tmpPath );
840
841 // Two zones, first with every omitted-when-default token left out (thermal, polygon
842 // fill, no smoothing, unlocked), second with the explicit tokens
843 out << "(kicad_pcb (version 20260513) (generator \"test\") (generator_version \"test\")"
844 << " (general (thickness 1.6)) (paper \"A4\")"
845 << " (layers (0 \"F.Cu\" signal) (31 \"B.Cu\" signal))"
846 << " (zone (net 0) (net_name \"\") (layer \"F.Cu\") (uuid \"00000000-0000-0000-0000-000000000001\")"
847 << " (hatch edge 0.5)"
848 << " (connect_pads (clearance 0.5))"
849 << " (min_thickness 0.25) (filled_areas_thickness no)"
850 << " (fill yes (thermal_gap 0.5) (thermal_bridge_width 0.5) (island_removal_mode 0))"
851 << " (polygon (pts (xy 0 0) (xy 5 0) (xy 5 5) (xy 0 5))))"
852 << " (zone (net 0) (net_name \"\") (layer \"F.Cu\") (uuid \"00000000-0000-0000-0000-000000000002\")"
853 << " (locked yes)"
854 << " (hatch edge 0.5)"
855 << " (connect_pads yes (clearance 0.5))"
856 << " (min_thickness 0.25) (filled_areas_thickness no)"
857 << " (fill yes (thermal_gap 0.5) (thermal_bridge_width 0.5) (island_removal_mode 0)"
858 << " (smoothing fillet) (radius 1))"
859 << " (polygon (pts (xy 10 0) (xy 15 0) (xy 15 5) (xy 10 5))))"
860 << ")";
861 out.close();
862
863 // A destination board whose session zone defaults differ from the format defaults
864 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
865
866 ZONE_SETTINGS settings = board->GetDesignSettings().GetDefaultZoneSettings();
870 settings.SetCornerRadius( pcbIUScale.mmToIU( 1 ) );
871 settings.m_HatchSmoothingLevel = 2;
872 settings.m_Locked = true;
873 board->GetDesignSettings().SetDefaultZoneSettings( settings );
874
875 kicadPlugin.LoadAndAppendBoard( tmpPath.string(), *board );
876
877 BOOST_REQUIRE_EQUAL( board->Zones().size(), 2u );
878
879 // The all-defaults zone must not pick up the board's session defaults
880 ZONE* omitted = board->Zones()[0];
884 BOOST_CHECK_EQUAL( omitted->GetCornerRadius(), 0 );
886 BOOST_CHECK( !omitted->IsLocked() );
887
888 // Explicit tokens still win
889 ZONE* explicitZone = board->Zones()[1];
892 BOOST_CHECK_EQUAL( explicitZone->GetCornerRadius(), pcbIUScale.mmToIU( 1 ) );
893 BOOST_CHECK( explicitZone->IsLocked() );
894}
895
896
901BOOST_AUTO_TEST_CASE( Issue24911_CancelledAppendLeavesBoardUntouched )
902{
903 // Requests cancellation once the parse reaches the given line, then stalls long
904 // enough to open the parser 250ms cancel checkpoint window
905 class CANCEL_AT_LINE_READER : public STRING_LINE_READER
906 {
907 public:
908 CANCEL_AT_LINE_READER( const std::string& aText, unsigned aCancelLine, bool* aCancelFlag ) :
909 STRING_LINE_READER( aText, wxT( "cancel-test" ) ),
910 m_cancelLine( aCancelLine ),
911 m_cancelFlag( aCancelFlag )
912 {
913 }
914
915 char* ReadLine() override
916 {
917 if( !*m_cancelFlag && LineNumber() >= m_cancelLine )
918 {
919 *m_cancelFlag = true;
920 std::this_thread::sleep_for( std::chrono::milliseconds( 300 ) );
921 }
922
924 }
925
926 private:
927 unsigned m_cancelLine;
928 bool* m_cancelFlag;
929 };
930
931 class CANCELLING_REPORTER : public PROGRESS_REPORTER
932 {
933 public:
934 CANCELLING_REPORTER( bool* aCancelFlag ) :
935 m_cancelFlag( aCancelFlag )
936 {
937 }
938
939 void SetNumPhases( int ) override {}
940 void AddPhases( int ) override {}
941 void BeginPhase( int ) override {}
942 void AdvancePhase() override {}
943 void AdvancePhase( const wxString& ) override {}
944 void Report( const wxString& ) override {}
945 void SetCurrentProgress( double ) override {}
946 void SetMaxProgress( int ) override {}
947 void AdvanceProgress() override {}
948 void SetTitle( const wxString& ) override {}
949 bool IsCancelled() const override { return *m_cancelFlag; }
950 bool KeepRefreshing( bool ) override { return !*m_cancelFlag; }
951
952 private:
953 bool* m_cancelFlag;
954 };
955
956 // Source board with one net and enough tracks that the cancel lands mid-parse
957 std::unique_ptr<BOARD> source = std::make_unique<BOARD>();
958
959 NETINFO_ITEM* net = new NETINFO_ITEM( source.get(), wxT( "GHOST_NET" ), 1 );
960 source->Add( net );
961
962 for( int i = 0; i < 400; i++ )
963 {
964 PCB_TRACK* track = new PCB_TRACK( source.get() );
965 track->SetStart( VECTOR2I( i * 10000, 0 ) );
966 track->SetEnd( VECTOR2I( i * 10000, 10000 ) );
967 track->SetWidth( 200000 );
968 track->SetLayer( F_Cu );
969 track->SetNet( net );
970 source->Add( track );
971 }
972
974 kicadPlugin.FormatBoardToFormatter( &fmt, source.get() );
975
976 // The formatter emits a single line, the parser can only be interrupted between lines
977 std::string text = fmt.GetString();
979
980 unsigned lineCount = std::count( text.begin(), text.end(), '\n' );
981
982 // Destination board with one pre-existing track
983 std::unique_ptr<BOARD> dest = std::make_unique<BOARD>();
984
985 PCB_TRACK* existing = new PCB_TRACK( dest.get() );
986 existing->SetStart( VECTOR2I( 0, 0 ) );
987 existing->SetEnd( VECTOR2I( 5000, 0 ) );
988 existing->SetWidth( 200000 );
989 existing->SetLayer( F_Cu );
990 dest->Add( existing );
991
992 size_t tracksBefore = dest->Tracks().size();
993 unsigned netsBefore = dest->GetNetInfo().GetNetCount();
994
995 bool cancelRequested = false;
996
997 CANCEL_AT_LINE_READER reader( text, lineCount / 2, &cancelRequested );
998 CANCELLING_REPORTER reporter( &cancelRequested );
999
1000 BOOST_CHECK_THROW( kicadPlugin.DoLoad( reader, *dest, false, nullptr, &reporter, lineCount ), IO_ERROR );
1001 BOOST_CHECK( cancelRequested );
1002
1003 BOOST_CHECK_EQUAL( dest->Tracks().size(), tracksBefore );
1004 BOOST_CHECK_EQUAL( dest->GetNetInfo().GetNetCount(), netsBefore );
1005}
1006
1007
1008// Enumerating a footprint library that is not on disk must fail every time. The failed
1009// load leaves a cache bound to the missing path carrying a zero timestamp, which is also
1010// what a missing directory reports, so the cache looks current and the next enumerate
1011// answers with an empty library instead of the error.
1012BOOST_AUTO_TEST_CASE( MissingLibraryThrowsOnEveryEnumerate )
1013{
1014 std::filesystem::path libPath = std::filesystem::temp_directory_path() / "kicad_qa_no_such_library.pretty";
1015
1016 BOOST_REQUIRE( !std::filesystem::exists( libPath ) );
1017
1018 wxArrayString names;
1019
1020 BOOST_CHECK_THROW( kicadPlugin.FootprintEnumerate( names, libPath.string(), false ), IO_ERROR );
1021
1022 BOOST_CHECK_THROW( kicadPlugin.FootprintEnumerate( names, libPath.string(), false ), IO_ERROR );
1023}
1024
1025
1026// A library load must finish a footprint the way Parse() does, or the next save drops its groups
1027BOOST_AUTO_TEST_CASE( LibraryFootprintKeepsGroupsAndLoadsUnlocked )
1028{
1029 KI_TEST::SCOPED_TEMP_DIR temp( wxS( "fp_finish" ) );
1030
1031 std::filesystem::path libPath = temp.Path() / "finish.pretty";
1032 std::filesystem::create_directories( libPath );
1033
1034 std::filesystem::path source = std::filesystem::path( KI_TEST::GetTestDataRootDir() ) / "libraries"
1035 / "Resistor_SMD.pretty" / "R_0402_1005Metric.kicad_mod";
1036
1037 wxString name;
1038 std::unique_ptr<FOOTPRINT> footprint = kicadPlugin.ImportFootprint( wxString( source.string() ), name );
1039
1040 footprint->SetFPID( LIB_ID( wxEmptyString, wxS( "grouped" ) ) );
1041 footprint->SetLocked( true );
1042
1043 PCB_GROUP* group = new PCB_GROUP( footprint.get() );
1044 group->AddItem( footprint->Pads().front() );
1045 footprint->Add( group );
1046
1047 kicadPlugin.FootprintSave( libPath.string(), footprint.get() );
1048
1049 std::unique_ptr<FOOTPRINT> loaded =
1050 kicadPlugin.ImportFootprint( wxString( ( libPath / "grouped.kicad_mod" ).string() ), name );
1051
1052 BOOST_CHECK( !loaded->IsLocked() );
1053 BOOST_REQUIRE_EQUAL( loaded->Groups().size(), 1u );
1054 BOOST_CHECK_EQUAL( loaded->Groups().front()->GetBoardItems().size(), 1u );
1055}
1056
1057
1058// A parse warning leaves the footprint usable, so it must not stop the rest of the library loading
1059// fails on revert, since the warning then makes the whole library fail
1060BOOST_AUTO_TEST_CASE( ParseWarningDoesNotFailTheLibrary )
1061{
1062 KI_TEST::SCOPED_TEMP_DIR temp( wxS( "fp_warning" ) );
1063
1064 std::filesystem::path libPath = temp.Path() / "warning.pretty";
1065 std::filesystem::create_directories( libPath );
1066
1067 std::filesystem::path source =
1068 std::filesystem::path( KI_TEST::GetTestDataRootDir() ) / "libraries" / "Resistor_SMD.pretty";
1069
1070 for( const char* name : { "R_0402_1005Metric", "R_0603_1608Metric" } )
1071 std::filesystem::copy_file( source / ( std::string( name ) + ".kicad_mod" ),
1072 libPath / ( std::string( name ) + ".kicad_mod" ) );
1073
1074 // A zero size pad parses with a warning
1075 std::filesystem::path zeroPad = libPath / "R_0402_1005Metric.kicad_mod";
1076 std::ifstream in( zeroPad );
1077 std::string text( ( std::istreambuf_iterator<char>( in ) ), std::istreambuf_iterator<char>() );
1078 in.close();
1079
1080 size_t at = text.find( "(size 0.54 0.64)" );
1081 BOOST_REQUIRE( at != std::string::npos );
1082 text.replace( at, std::string( "(size 0.54 0.64)" ).size(), "(size 0 0)" );
1083 std::ofstream( zeroPad ) << text;
1084
1085 wxArrayString names;
1086
1087 BOOST_CHECK_NO_THROW( kicadPlugin.FootprintEnumerate( names, libPath.string(), false ) );
1088 BOOST_CHECK_EQUAL( names.size(), 2u );
1089 BOOST_CHECK( names.Index( wxS( "R_0402_1005Metric" ) ) != wxNOT_FOUND );
1090
1091 // A file that does not parse still fails the library, as it always has
1092 std::ofstream( libPath / "broken.kicad_mod" ) << "(footprint";
1093
1094 kicadPlugin.ClearCachedFootprints( libPath.string() );
1095 names.clear();
1096
1097 BOOST_CHECK_THROW( kicadPlugin.FootprintEnumerate( names, libPath.string(), false ), IO_ERROR );
1098}
1099
1100
1101BOOST_AUTO_TEST_CASE( LegacyModuleFileImports )
1102{
1103 const std::string fpPath = KI_TEST::GetPcbnewTestDataDir() + "legacy_module/Crystal_SMD_HC49-US.kicad_mod";
1104 PCB_IO_KICAD_SEXPR kicadPlugin;
1105 wxString name;
1106
1107 BOOST_CHECK( kicadPlugin.ImportFootprint( fpPath, name ) != nullptr );
1108}
1109
1110
const char * name
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
General utilities for PCB file IO for QA programs.
@ BS_ITEM_TYPE_COPPER
@ BS_ITEM_TYPE_DIELECTRIC
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
NETINFO_ITEM * GetNet() const
Return NETINFO_ITEM object for a given item.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
bool IsLocked() const override
Manage one layer needed to make a physical board.
int GetThickness(int aDielectricSubLayer=0) const
wxString GetMaterial(int aDielectricSubLayer=0) const
Manage layers needed to make a physical board.
int GetCount() const
int BuildBoardThicknessFromStackup() const
wxString m_FinishType
The name of external copper finish.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1548
const TRACKS & Tracks() const
Definition board.h:463
const DRAWINGS & Drawings() const
Definition board.h:467
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ANGLE GetAngle() const
Definition eda_angle.h:557
void SetAngle(const EDA_ANGLE &aAngle)
Definition eda_angle.h:559
VECTOR2I GetArcMid() const
void SetFPID(const LIB_ID &aFPID)
Definition footprint.h:418
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Adds an item to the container.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
const std::filesystem::path & Path() const
Get the path to the temporary directory as a std::filesystem::path.
Definition file_utils.h:61
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
Definition richio.h:119
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition lset.h:63
Handle the data for a net.
Definition netinfo.h:50
static NETINFO_ITEM * OrphanedItem()
NETINFO_ITEM meaning that there was no net assigned for an item, as there was no board storing net li...
Definition netinfo.h:289
@ NORMAL
Shape is the same on all layers.
Definition padstack.h:175
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:184
Definition pad.h:61
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
A PCB_IO derivation for saving and loading Pcbnew s-expression formatted files.
std::unique_ptr< FOOTPRINT > ImportFootprint(const wxString &aFootprintPath, wxString &aFootprintNameOut, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a single footprint from aFootprintPath and put its name in aFootprintNameOut.
void SaveBoard(const wxString &aFileName, BOARD &aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aBoard to a storage file in a format that this PCB_IO implementation knows about or it can be u...
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
void SetWidth(int aWidth) override
void SetEnd(const VECTOR2I &aEnd) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetStart(const VECTOR2I &aStart) override
void SetEnd(const VECTOR2I &aEnd)
Definition pcb_track.h:96
void SetStart(const VECTOR2I &aStart)
Definition pcb_track.h:99
virtual void SetWidth(int aWidth)
Definition pcb_track.h:93
A progress reporter interface for use in multi-threaded environments.
virtual bool IsCancelled() const =0
virtual void AddPhases(int aNumPhases)=0
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void SetNumPhases(int aNumPhases)=0
Set the number of phases.
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
virtual void BeginPhase(int aPhase)=0
Initialize the aPhase virtual zone of the dialog progress bar.
virtual void AdvancePhase()=0
Use the next available virtual zone of the dialog progress bar.
virtual void SetTitle(const wxString &aTitle)=0
Change the title displayed on the window caption.
virtual void AdvanceProgress()=0
Increment the progress bar length (inside the current virtual zone).
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).
virtual void SetMaxProgress(int aMaxProgress)=0
Fix the value that gives the 100 percent progress bar length (inside the current virtual zone).
int TotalVertices() const
Return total number of vertices stored in the set.
Implement an OUTPUTFORMATTER to a memory buffer.
Definition richio.h:430
const std::string & GetString()
Definition richio.h:453
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition richio.h:225
STRING_LINE_READER(const std::string &aString, const wxString &aSource)
Construct a string line reader.
Definition richio.cpp:236
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
Definition richio.cpp:259
Handle zones parameters.
void SetCornerSmoothingType(CORNER_SMOOTHING aType)
void SetPadConnection(ZONE_CONNECTION aPadConnection)
void SetCornerRadius(int aRadius)
ZONE_FILL_MODE m_FillMode
Handle a list of polygons defining a copper zone.
Definition zone.h:70
const THIEVING_SETTINGS & GetThievingSettings() const
Definition zone.h:351
bool AppendCorner(const VECTOR2I &aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
Definition zone.cpp:1519
ZONE_LAYER_PROPERTIES & LayerProperties(PCB_LAYER_ID aLayer)
Definition zone.h:146
std::shared_ptr< SHAPE_POLY_SET > GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition zone.h:701
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition zone.cpp:677
bool IsCopperThieving() const
Definition zone.h:349
ZONE_SETTINGS::CORNER_SMOOTHING GetCornerSmoothingType() const
Definition zone.h:773
void SetFillMode(ZONE_FILL_MODE aFillMode)
Definition zone.cpp:683
ZONE_CONNECTION GetPadConnection() const
Definition zone.h:312
void SetThievingSettings(const THIEVING_SETTINGS &aSettings)
Definition zone.h:352
VECTOR2I GetPosition() const override
Definition zone.cpp:601
void SetNet(NETINFO_ITEM *aNetInfo) override
Override that drops aNetInfo when this zone is in copper-thieving fill mode.
Definition zone.cpp:668
ZONE_FILL_MODE GetFillMode() const
Definition zone.h:238
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition zone.h:133
int GetHatchSmoothingLevel() const
Definition zone.h:334
unsigned int GetCornerRadius() const
Definition zone.h:777
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition zone.h:619
@ DEGREES_T
Definition eda_angle.h:30
@ RECURSE
Definition eda_item.h:51
@ SEGMENT
Definition eda_shape.h:57
std::string source
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ B_Cu
Definition layer_ids.h:61
@ In2_Cu
Definition layer_ids.h:63
@ F_SilkS
Definition layer_ids.h:96
@ In4_Cu
Definition layer_ids.h:65
@ In1_Cu
Definition layer_ids.h:62
@ In3_Cu
Definition layer_ids.h:64
@ F_Cu
Definition layer_ids.h:60
void Prettify(std::string &aSource, FORMAT_MODE aMode)
Pretty-prints s-expression text according to KiCad format rules.
std::string GetTestDataRootDir()
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
constexpr char APPEND_PRESERVE_DESTINATION_STACKUP[]
Definition pcb_io.h:46
Class to handle a set of BOARD_ITEMs.
Describes an imported layer and how it could be mapped to KiCad Layers.
PCB_IO_KICAD_SEXPR kicadPlugin
Parameters that drive copper-thieving fill generation.
THIEVING_PATTERN pattern
EDA_ORIENTATION orientation
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)
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST(netlist.find("R_G1 ARM_OUT1 DIE_B R='0.001 / ((SW_STATE)") !=std::string::npos)
std::string path
IbisParser parser & reporter
#define CHECK_ENUM_CLASS_EQUAL(L, R)
BOOST_AUTO_TEST_CASE(Issue19775_ZoneLayerWildcards)
Declares the struct as the Boost test fixture.
BOOST_TEST_CONTEXT("Test Clearance")
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:100
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
THIEVING_PATTERN
Shape stamped onto the grid for a copper-thieving fill.
@ THERMAL
Use thermal relief for pads.
Definition zones.h:46
@ FULL
pads are covered by copper
Definition zones.h:47