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>& ) -> std::map<wxString, PCB_LAYER_ID>
483 {
484 handlerCalled = true;
485 return {};
486 } );
487
488 // Appending onto a board with identical layer names must not prompt
489 {
490 std::unique_ptr<BOARD> matchBoard = kicadPlugin.LoadBoard( standardNames );
491 handlerCalled = false;
492 kicadPlugin.LoadAndAppendBoard( standardNames, *matchBoard, &props );
493 BOOST_CHECK( !handlerCalled );
494 }
495
496 // Appending a board with differently-named layers must prompt
497 {
498 std::unique_ptr<BOARD> mismatchBoard = kicadPlugin.LoadBoard( standardNames );
499 handlerCalled = false;
500 kicadPlugin.LoadAndAppendBoard( customNames, *mismatchBoard, &props );
501 BOOST_CHECK( handlerCalled );
502 }
503}
504
505
523BOOST_AUTO_TEST_CASE( FootprintSave_OmitsNetsOnAllBoardConnectedItems )
524{
525 KI_TEST::SCOPED_TEMP_DIR tmpLib( wxS( "qa_fp_save_netinfo" ) );
526
527 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
528
529 NETINFO_ITEM* net = new NETINFO_ITEM( board.get(), wxT( "TestNet" ), 1 );
530 board->Add( net );
531
532 FOOTPRINT* fp = new FOOTPRINT( board.get() );
533 board->Add( fp );
534 fp->SetFPID( LIB_ID( wxT( "scratch" ), wxT( "test_fp_save_netinfo" ) ) );
535
536 PAD* pad = new PAD( fp );
537 pad->SetPadstackMode( PADSTACK::MODE::NORMAL );
539 pad->SetSize( PADSTACK::ALL_LAYERS,
540 VECTOR2I( pcbIUScale.mmToIU( 1 ), pcbIUScale.mmToIU( 1 ) ) );
541 pad->SetNet( net );
542 fp->Add( pad );
543
544 PCB_SHAPE* shape = new PCB_SHAPE( fp, SHAPE_T::SEGMENT );
545 shape->SetLayer( F_Cu );
546 shape->SetStart( VECTOR2I( 0, 0 ) );
547 shape->SetEnd( VECTOR2I( pcbIUScale.mmToIU( 5 ), 0 ) );
548 shape->SetNet( net );
549 fp->Add( shape );
550
551 ZONE* zone = new ZONE( fp );
552 zone->SetLayer( F_Cu );
553 zone->SetNet( net );
554 fp->Add( zone );
555
556 BOOST_REQUIRE_EQUAL( pad->GetNet(), net );
557 BOOST_REQUIRE_EQUAL( shape->GetNet(), net );
558 BOOST_REQUIRE_EQUAL( zone->GetNet(), net );
559
560 // Save into the scratch library via the public library-save API. Must not throw.
561 BOOST_REQUIRE_NO_THROW( kicadPlugin.FootprintSave( tmpLib.Path().string(), fp ) );
562
563 auto savedFile = tmpLib.Path() / "test_fp_save_netinfo.kicad_mod";
564 BOOST_REQUIRE( std::filesystem::exists( savedFile ) );
565
566 std::ifstream in( savedFile );
567 BOOST_REQUIRE_MESSAGE( in.is_open(),
568 "Failed to open serialized footprint: " << savedFile.string() );
569
570 std::stringstream ss;
571 ss << in.rdbuf();
572 BOOST_REQUIRE( !in.bad() );
573
574 // Windows refuses to unlink a file that still has an open handle, so release it before the
575 // scoped directory teardown.
576 in.close();
577
578 const std::string contents = ss.str();
579 BOOST_REQUIRE( !contents.empty() );
580
581 BOOST_CHECK_MESSAGE( contents.find( "(net " ) == std::string::npos,
582 "Saved footprint library file must not contain (net ...) tokens:\n"
583 << contents );
584
585 // Verify the second defense directly on the save-path's transient state: clone the
586 // footprint, detach it from its parent board exactly as FootprintSave does, invoke
587 // ClearAllNets(), and assert every BOARD_CONNECTED_ITEM descendant is orphaned. This
588 // catches a regression where FootprintSave stops calling ClearAllNets() even if the
589 // serializer guards keep the file contents looking correct.
590 std::unique_ptr<FOOTPRINT> detached( static_cast<FOOTPRINT*>( fp->Clone() ) );
591 detached->SetParent( nullptr );
592 detached->SetParentGroup( nullptr );
593 detached->ClearAllNets();
594
595 BOARD_CONNECTED_ITEM* detachedPad = nullptr;
596 BOARD_CONNECTED_ITEM* detachedShape = nullptr;
597 BOARD_CONNECTED_ITEM* detachedZone = nullptr;
598
599 detached->RunOnChildren(
600 [&]( BOARD_ITEM* aItem )
601 {
602 switch( aItem->Type() )
603 {
604 case PCB_PAD_T: detachedPad = static_cast<BOARD_CONNECTED_ITEM*>( aItem ); break;
605 case PCB_SHAPE_T: detachedShape = static_cast<BOARD_CONNECTED_ITEM*>( aItem ); break;
606 case PCB_ZONE_T: detachedZone = static_cast<BOARD_CONNECTED_ITEM*>( aItem ); break;
607 default: break;
608 }
609 },
611
612 BOOST_REQUIRE( detachedPad );
613 BOOST_REQUIRE( detachedShape );
614 BOOST_REQUIRE( detachedZone );
618}
619
620
629BOOST_AUTO_TEST_CASE( CopperThievingZone_RoundTrip )
630{
631 std::unique_ptr<BOARD> writeBoard = std::make_unique<BOARD>();
632
633 ZONE* zone = new ZONE( writeBoard.get() );
634 zone->SetLayer( F_Cu );
635 zone->AppendCorner( VECTOR2I( 0, 0 ), -1 );
636 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 10 ), 0 ), -1 );
637 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 10 ), pcbIUScale.mmToIU( 10 ) ), -1 );
638 zone->AppendCorner( VECTOR2I( 0, pcbIUScale.mmToIU( 10 ) ), -1 );
640
641 THIEVING_SETTINGS thieving;
643 thieving.element_size = pcbIUScale.mmToIU( 0.42 );
644 thieving.gap = pcbIUScale.mmToIU( 1.27 );
645 thieving.line_width = pcbIUScale.mmToIU( 0.35 );
646 thieving.stagger = true;
647 thieving.orientation.SetAngle( EDA_ANGLE( 30.0, DEGREES_T ) );
648 zone->SetThievingSettings( thieving );
649
650 writeBoard->Add( zone );
651
652 std::filesystem::path tmpPath = std::filesystem::temp_directory_path()
653 / "copper_thieving_roundtrip.kicad_pcb";
654
655 PCB_IO_KICAD_SEXPR writer;
656 writer.SaveBoard( tmpPath.string(), *writeBoard );
657
658 PCB_IO_KICAD_SEXPR reader;
659 std::unique_ptr<BOARD> readBoard = reader.LoadBoard( tmpPath.string() );
660
661 BOOST_REQUIRE_EQUAL( readBoard->Zones().size(), 1u );
662
663 ZONE* loaded = readBoard->Zones()[0];
664
666 BOOST_CHECK( loaded->IsCopperThieving() );
667 BOOST_CHECK_EQUAL( loaded->GetNetCode(), 0 );
668
669 const THIEVING_SETTINGS& loadedSettings = loaded->GetThievingSettings();
670 BOOST_CHECK( loadedSettings.pattern == THIEVING_PATTERN::HATCH );
671 BOOST_CHECK_EQUAL( loadedSettings.element_size, thieving.element_size );
672 BOOST_CHECK_EQUAL( loadedSettings.gap, thieving.gap );
673 BOOST_CHECK_EQUAL( loadedSettings.line_width, thieving.line_width );
674 BOOST_CHECK_EQUAL( loadedSettings.stagger, true );
675 BOOST_CHECK( loadedSettings.orientation.GetAngle() == EDA_ANGLE( 30.0, DEGREES_T ) );
676
677 std::filesystem::remove( tmpPath );
678}
679
680
685BOOST_AUTO_TEST_CASE( CopperThievingZone_AllPatternsRoundTrip )
686{
687 const std::array<THIEVING_PATTERN, 3> patterns = {
691 };
692
693 for( THIEVING_PATTERN pattern : patterns )
694 {
695 BOOST_TEST_CONTEXT( "pattern enum value " << static_cast<int>( pattern ) )
696 {
697 std::unique_ptr<BOARD> writeBoard = std::make_unique<BOARD>();
698
699 ZONE* zone = new ZONE( writeBoard.get() );
700 zone->SetLayer( F_Cu );
701 zone->AppendCorner( VECTOR2I( 0, 0 ), -1 );
702 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 5 ), 0 ), -1 );
703 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 5 ), pcbIUScale.mmToIU( 5 ) ), -1 );
704 zone->AppendCorner( VECTOR2I( 0, pcbIUScale.mmToIU( 5 ) ), -1 );
706
707 THIEVING_SETTINGS thieving = zone->GetThievingSettings();
708 thieving.pattern = pattern;
709 zone->SetThievingSettings( thieving );
710
711 writeBoard->Add( zone );
712
713 std::filesystem::path tmpPath = std::filesystem::temp_directory_path()
714 / "copper_thieving_pattern.kicad_pcb";
715 PCB_IO_KICAD_SEXPR writer;
716 writer.SaveBoard( tmpPath.string(), *writeBoard );
717
718 PCB_IO_KICAD_SEXPR reader;
719 std::unique_ptr<BOARD> readBoard = reader.LoadBoard( tmpPath.string() );
720
721 BOOST_REQUIRE_EQUAL( readBoard->Zones().size(), 1u );
722 BOOST_CHECK( readBoard->Zones()[0]->GetThievingSettings().pattern == pattern );
723
724 std::filesystem::remove( tmpPath );
725 }
726 }
727}
728
729
736BOOST_AUTO_TEST_CASE( CopperThievingZone_RejectedInOldFileVersion )
737{
738 std::filesystem::path tmpPath = std::filesystem::temp_directory_path()
739 / "copper_thieving_old_version.kicad_pcb";
740 std::ofstream out( tmpPath );
741 // 20260512 is the Net Chains release; thieving needs >= 20260513. Using the
742 // immediately-prior version exercises the boundary check.
743 out << "(kicad_pcb (version 20260512) (generator \"test\") (generator_version \"test\")"
744 << " (general (thickness 1.6)) (paper \"A4\")"
745 << " (layers (0 \"F.Cu\" signal) (31 \"B.Cu\" signal))"
746 << " (zone (net 0) (net_name \"\") (layer \"F.Cu\") (uuid \"00000000-0000-0000-0000-000000000001\")"
747 << " (hatch edge 0.5)"
748 << " (connect_pads (clearance 0))"
749 << " (min_thickness 0.25) (filled_areas_thickness no)"
750 << " (fill yes (mode thieving) (thermal_gap 0.5) (thermal_bridge_width 0.5)"
751 << " (island_removal_mode 0))"
752 << " (polygon (pts (xy 0 0) (xy 5 0) (xy 5 5) (xy 0 5))))"
753 << ")";
754 out.close();
755
756 PCB_IO_KICAD_SEXPR reader;
757 BOOST_REQUIRE_THROW( reader.LoadBoard( tmpPath.string() ), IO_ERROR );
758
759 std::filesystem::remove( tmpPath );
760}
761
762
763BOOST_AUTO_TEST_CASE( MalformedDimensionTextThrowsCleanly )
764{
765 KI_TEST::SCOPED_TEMP_DIR tempDir( "kicad_qa_malformed_dimension_text" );
766 std::filesystem::path tmpPath = tempDir.Path() / "malformed_dimension_text.kicad_pcb";
767 std::ofstream out( tmpPath );
768 out << "(kicad_pcb (version 20240108) (generator \"test\")"
769 << " (general (thickness 1.6)) (paper \"A4\")"
770 << " (layers (0 \"F.Cu\" signal) (31 \"B.Cu\" signal) (36 \"B.SilkS\" user \"b.silkscreen\"))"
771 << " (dimension (type aligned) (layer \"B.SilkS\")"
772 << " (gr_text \"1 mm\" (at broken))))";
773 out.close();
774
775 PCB_IO_KICAD_SEXPR reader;
776
777 BOOST_CHECK_THROW( reader.LoadBoard( tmpPath.string() ), IO_ERROR );
778}
779
780
787BOOST_AUTO_TEST_CASE( CopperThievingZone_RejectsMalformedGeometry )
788{
789 std::filesystem::path tmpPath = std::filesystem::temp_directory_path()
790 / "copper_thieving_malformed.kicad_pcb";
791 std::ofstream out( tmpPath );
792 out << "(kicad_pcb (version 20260513) (generator \"test\") (generator_version \"test\")"
793 << " (general (thickness 1.6)) (paper \"A4\")"
794 << " (layers (0 \"F.Cu\" signal) (31 \"B.Cu\" signal))"
795 << " (zone (net 0) (net_name \"\") (layer \"F.Cu\") (uuid \"00000000-0000-0000-0000-000000000002\")"
796 << " (hatch edge 0.5)"
797 << " (connect_pads (clearance 0))"
798 << " (min_thickness 0.25) (filled_areas_thickness no)"
799 << " (fill yes (mode thieving)"
800 << " (thermal_gap 0.5) (thermal_bridge_width 0.5)"
801 << " (island_removal_mode 0)"
802 << " (thieving (type dots) (size -1) (gap 0)"
803 << " (width -5) (stagger no) (orientation 0)))"
804 << " (polygon (pts (xy 0 0) (xy 5 0) (xy 5 5) (xy 0 5))))"
805 << ")";
806 out.close();
807
808 PCB_IO_KICAD_SEXPR reader;
809 std::unique_ptr<BOARD> readBoard = reader.LoadBoard( tmpPath.string() );
810
811 BOOST_REQUIRE_EQUAL( readBoard->Zones().size(), 1u );
812
813 const THIEVING_SETTINGS& loaded = readBoard->Zones()[0]->GetThievingSettings();
814 BOOST_CHECK_GT( loaded.element_size, 0 );
815 BOOST_CHECK_GT( loaded.gap, 0 );
816 BOOST_CHECK_GT( loaded.line_width, 0 );
817
818 std::filesystem::remove( tmpPath );
819}
820
821
829BOOST_AUTO_TEST_CASE( Issue24955_AppendDoesNotInheritSessionZoneDefaults )
830{
831 KI_TEST::SCOPED_TEMP_DIR tempDir( "kicad_qa_zone_defaults_append" );
832 std::filesystem::path tmpPath = tempDir.Path() / "thermal_zone_block.kicad_pcb";
833 std::ofstream out( tmpPath );
834
835 // Two zones, first with every omitted-when-default token left out (thermal, polygon
836 // fill, no smoothing, unlocked), second with the explicit tokens
837 out << "(kicad_pcb (version 20260513) (generator \"test\") (generator_version \"test\")"
838 << " (general (thickness 1.6)) (paper \"A4\")"
839 << " (layers (0 \"F.Cu\" signal) (31 \"B.Cu\" signal))"
840 << " (zone (net 0) (net_name \"\") (layer \"F.Cu\") (uuid \"00000000-0000-0000-0000-000000000001\")"
841 << " (hatch edge 0.5)"
842 << " (connect_pads (clearance 0.5))"
843 << " (min_thickness 0.25) (filled_areas_thickness no)"
844 << " (fill yes (thermal_gap 0.5) (thermal_bridge_width 0.5) (island_removal_mode 0))"
845 << " (polygon (pts (xy 0 0) (xy 5 0) (xy 5 5) (xy 0 5))))"
846 << " (zone (net 0) (net_name \"\") (layer \"F.Cu\") (uuid \"00000000-0000-0000-0000-000000000002\")"
847 << " (locked yes)"
848 << " (hatch edge 0.5)"
849 << " (connect_pads yes (clearance 0.5))"
850 << " (min_thickness 0.25) (filled_areas_thickness no)"
851 << " (fill yes (thermal_gap 0.5) (thermal_bridge_width 0.5) (island_removal_mode 0)"
852 << " (smoothing fillet) (radius 1))"
853 << " (polygon (pts (xy 10 0) (xy 15 0) (xy 15 5) (xy 10 5))))"
854 << ")";
855 out.close();
856
857 // A destination board whose session zone defaults differ from the format defaults
858 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
859
860 ZONE_SETTINGS settings = board->GetDesignSettings().GetDefaultZoneSettings();
864 settings.SetCornerRadius( pcbIUScale.mmToIU( 1 ) );
865 settings.m_HatchSmoothingLevel = 2;
866 settings.m_Locked = true;
867 board->GetDesignSettings().SetDefaultZoneSettings( settings );
868
869 kicadPlugin.LoadAndAppendBoard( tmpPath.string(), *board );
870
871 BOOST_REQUIRE_EQUAL( board->Zones().size(), 2u );
872
873 // The all-defaults zone must not pick up the board's session defaults
874 ZONE* omitted = board->Zones()[0];
878 BOOST_CHECK_EQUAL( omitted->GetCornerRadius(), 0 );
880 BOOST_CHECK( !omitted->IsLocked() );
881
882 // Explicit tokens still win
883 ZONE* explicitZone = board->Zones()[1];
886 BOOST_CHECK_EQUAL( explicitZone->GetCornerRadius(), pcbIUScale.mmToIU( 1 ) );
887 BOOST_CHECK( explicitZone->IsLocked() );
888}
889
890
895BOOST_AUTO_TEST_CASE( Issue24911_CancelledAppendLeavesBoardUntouched )
896{
897 // Requests cancellation once the parse reaches the given line, then stalls long
898 // enough to open the parser 250ms cancel checkpoint window
899 class CANCEL_AT_LINE_READER : public STRING_LINE_READER
900 {
901 public:
902 CANCEL_AT_LINE_READER( const std::string& aText, unsigned aCancelLine, bool* aCancelFlag ) :
903 STRING_LINE_READER( aText, wxT( "cancel-test" ) ),
904 m_cancelLine( aCancelLine ),
905 m_cancelFlag( aCancelFlag )
906 {
907 }
908
909 char* ReadLine() override
910 {
911 if( !*m_cancelFlag && LineNumber() >= m_cancelLine )
912 {
913 *m_cancelFlag = true;
914 std::this_thread::sleep_for( std::chrono::milliseconds( 300 ) );
915 }
916
918 }
919
920 private:
921 unsigned m_cancelLine;
922 bool* m_cancelFlag;
923 };
924
925 class CANCELLING_REPORTER : public PROGRESS_REPORTER
926 {
927 public:
928 CANCELLING_REPORTER( bool* aCancelFlag ) :
929 m_cancelFlag( aCancelFlag )
930 {
931 }
932
933 void SetNumPhases( int ) override {}
934 void AddPhases( int ) override {}
935 void BeginPhase( int ) override {}
936 void AdvancePhase() override {}
937 void AdvancePhase( const wxString& ) override {}
938 void Report( const wxString& ) override {}
939 void SetCurrentProgress( double ) override {}
940 void SetMaxProgress( int ) override {}
941 void AdvanceProgress() override {}
942 void SetTitle( const wxString& ) override {}
943 bool IsCancelled() const override { return *m_cancelFlag; }
944 bool KeepRefreshing( bool ) override { return !*m_cancelFlag; }
945
946 private:
947 bool* m_cancelFlag;
948 };
949
950 // Source board with one net and enough tracks that the cancel lands mid-parse
951 std::unique_ptr<BOARD> source = std::make_unique<BOARD>();
952
953 NETINFO_ITEM* net = new NETINFO_ITEM( source.get(), wxT( "GHOST_NET" ), 1 );
954 source->Add( net );
955
956 for( int i = 0; i < 400; i++ )
957 {
958 PCB_TRACK* track = new PCB_TRACK( source.get() );
959 track->SetStart( VECTOR2I( i * 10000, 0 ) );
960 track->SetEnd( VECTOR2I( i * 10000, 10000 ) );
961 track->SetWidth( 200000 );
962 track->SetLayer( F_Cu );
963 track->SetNet( net );
964 source->Add( track );
965 }
966
968 kicadPlugin.FormatBoardToFormatter( &fmt, source.get() );
969
970 // The formatter emits a single line, the parser can only be interrupted between lines
971 std::string text = fmt.GetString();
973
974 unsigned lineCount = std::count( text.begin(), text.end(), '\n' );
975
976 // Destination board with one pre-existing track
977 std::unique_ptr<BOARD> dest = std::make_unique<BOARD>();
978
979 PCB_TRACK* existing = new PCB_TRACK( dest.get() );
980 existing->SetStart( VECTOR2I( 0, 0 ) );
981 existing->SetEnd( VECTOR2I( 5000, 0 ) );
982 existing->SetWidth( 200000 );
983 existing->SetLayer( F_Cu );
984 dest->Add( existing );
985
986 size_t tracksBefore = dest->Tracks().size();
987 unsigned netsBefore = dest->GetNetInfo().GetNetCount();
988
989 bool cancelRequested = false;
990
991 CANCEL_AT_LINE_READER reader( text, lineCount / 2, &cancelRequested );
992 CANCELLING_REPORTER reporter( &cancelRequested );
993
994 BOOST_CHECK_THROW( kicadPlugin.DoLoad( reader, *dest, false, nullptr, &reporter, lineCount ), IO_ERROR );
995 BOOST_CHECK( cancelRequested );
996
997 BOOST_CHECK_EQUAL( dest->Tracks().size(), tracksBefore );
998 BOOST_CHECK_EQUAL( dest->GetNetInfo().GetNetCount(), netsBefore );
999}
1000
1001
1002// Enumerating a footprint library that is not on disk must fail every time. The failed
1003// load leaves a cache bound to the missing path carrying a zero timestamp, which is also
1004// what a missing directory reports, so the cache looks current and the next enumerate
1005// answers with an empty library instead of the error.
1006BOOST_AUTO_TEST_CASE( MissingLibraryThrowsOnEveryEnumerate )
1007{
1008 std::filesystem::path libPath = std::filesystem::temp_directory_path() / "kicad_qa_no_such_library.pretty";
1009
1010 BOOST_REQUIRE( !std::filesystem::exists( libPath ) );
1011
1012 wxArrayString names;
1013
1014 BOOST_CHECK_THROW( kicadPlugin.FootprintEnumerate( names, libPath.string(), false ), IO_ERROR );
1015
1016 BOOST_CHECK_THROW( kicadPlugin.FootprintEnumerate( names, libPath.string(), false ), IO_ERROR );
1017}
1018
1019
1020// A library load must finish a footprint the way Parse() does, or the next save drops its groups
1021BOOST_AUTO_TEST_CASE( LibraryFootprintKeepsGroupsAndLoadsUnlocked )
1022{
1023 KI_TEST::SCOPED_TEMP_DIR temp( wxS( "fp_finish" ) );
1024
1025 std::filesystem::path libPath = temp.Path() / "finish.pretty";
1026 std::filesystem::create_directories( libPath );
1027
1028 std::filesystem::path source = std::filesystem::path( KI_TEST::GetTestDataRootDir() ) / "libraries"
1029 / "Resistor_SMD.pretty" / "R_0402_1005Metric.kicad_mod";
1030
1031 wxString name;
1032 std::unique_ptr<FOOTPRINT> footprint = kicadPlugin.ImportFootprint( wxString( source.string() ), name );
1033
1034 footprint->SetFPID( LIB_ID( wxEmptyString, wxS( "grouped" ) ) );
1035 footprint->SetLocked( true );
1036
1037 PCB_GROUP* group = new PCB_GROUP( footprint.get() );
1038 group->AddItem( footprint->Pads().front() );
1039 footprint->Add( group );
1040
1041 kicadPlugin.FootprintSave( libPath.string(), footprint.get() );
1042
1043 std::unique_ptr<FOOTPRINT> loaded =
1044 kicadPlugin.ImportFootprint( wxString( ( libPath / "grouped.kicad_mod" ).string() ), name );
1045
1046 BOOST_CHECK( !loaded->IsLocked() );
1047 BOOST_REQUIRE_EQUAL( loaded->Groups().size(), 1u );
1048 BOOST_CHECK_EQUAL( loaded->Groups().front()->GetBoardItems().size(), 1u );
1049}
1050
1051
1052// A parse warning leaves the footprint usable, so it must not stop the rest of the library loading
1053// fails on revert, since the warning then makes the whole library fail
1054BOOST_AUTO_TEST_CASE( ParseWarningDoesNotFailTheLibrary )
1055{
1056 KI_TEST::SCOPED_TEMP_DIR temp( wxS( "fp_warning" ) );
1057
1058 std::filesystem::path libPath = temp.Path() / "warning.pretty";
1059 std::filesystem::create_directories( libPath );
1060
1061 std::filesystem::path source =
1062 std::filesystem::path( KI_TEST::GetTestDataRootDir() ) / "libraries" / "Resistor_SMD.pretty";
1063
1064 for( const char* name : { "R_0402_1005Metric", "R_0603_1608Metric" } )
1065 std::filesystem::copy_file( source / ( std::string( name ) + ".kicad_mod" ),
1066 libPath / ( std::string( name ) + ".kicad_mod" ) );
1067
1068 // A zero size pad parses with a warning
1069 std::filesystem::path zeroPad = libPath / "R_0402_1005Metric.kicad_mod";
1070 std::ifstream in( zeroPad );
1071 std::string text( ( std::istreambuf_iterator<char>( in ) ), std::istreambuf_iterator<char>() );
1072 in.close();
1073
1074 size_t at = text.find( "(size 0.54 0.64)" );
1075 BOOST_REQUIRE( at != std::string::npos );
1076 text.replace( at, std::string( "(size 0.54 0.64)" ).size(), "(size 0 0)" );
1077 std::ofstream( zeroPad ) << text;
1078
1079 wxArrayString names;
1080
1081 BOOST_CHECK_NO_THROW( kicadPlugin.FootprintEnumerate( names, libPath.string(), false ) );
1082 BOOST_CHECK_EQUAL( names.size(), 2u );
1083 BOOST_CHECK( names.Index( wxS( "R_0402_1005Metric" ) ) != wxNOT_FOUND );
1084
1085 // A file that does not parse still fails the library, as it always has
1086 std::ofstream( libPath / "broken.kicad_mod" ) << "(footprint";
1087
1088 kicadPlugin.ClearCachedFootprints( libPath.string() );
1089 names.clear();
1090
1091 BOOST_CHECK_THROW( kicadPlugin.FootprintEnumerate( names, libPath.string(), false ), IO_ERROR );
1092}
1093
1094
1095BOOST_AUTO_TEST_CASE( LegacyModuleFileImports )
1096{
1097 const std::string fpPath = KI_TEST::GetPcbnewTestDataDir() + "legacy_module/Crystal_SMD_HC49-US.kicad_mod";
1098 PCB_IO_KICAD_SEXPR kicadPlugin;
1099 wxString name;
1100
1101 BOOST_CHECK( kicadPlugin.ImportFootprint( fpPath, name ) != nullptr );
1102}
1103
1104
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