KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_board_downgrade.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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 <boost/test/unit_test.hpp>
21
22#include <algorithm>
23#include <cmath>
24#include <fstream>
25#include <map>
26#include <memory>
27#include <filesystem>
28#include <set>
29
30#include <wx/image.h>
31#include <wx/imagpng.h>
32#include <wx/mstream.h>
33
34#include <base_units.h>
35#include <board.h>
37#include <footprint.h>
38#include <font/font.h>
39#include <gr_text.h>
40#include <pcb_track.h>
45#include <pad.h>
46#include <padstack.h>
47#include <pcb_barcode.h>
48#include <pcb_group.h>
49#include <pcb_dimension.h>
50#include <pcb_drill_chart.h>
51#include <pcb_drill_map.h>
52#include <pcb_grid_item.h>
53#include <pcb_reference_image.h>
54#include <pcb_shape.h>
55#include <pcb_stackup_table.h>
56#include <pcb_table.h>
57#include <pcb_tablecell.h>
58#include <pcb_textbox.h>
60#include <zone.h>
61#include <zone_settings.h>
62#include <nlohmann/json.hpp>
63#include <netinfo.h>
64#include <project.h>
65#include <ki_exception.h>
66
68#include <downgrade_scan.h>
69#include <downgrade_target.h>
70#include <drc_rules_downgrade.h>
71#include <drc/drc_rule.h>
72#include <drc/drc_rule_parser.h>
80#include <qa_utils/file_utils.h>
81
82
83BOOST_AUTO_TEST_SUITE( BoardDowngrade )
84
85static const DOWNGRADE_TARGET& kicad9 = KI_TEST::RequireDowngradeTarget( wxT( "9.0" ) );
86static const DOWNGRADE_TARGET& kicad10 = KI_TEST::RequireDowngradeTarget( wxT( "10.0" ) );
87
88
89// A board with no post-10.0 features exports to 10.0 with nothing lost.
90BOOST_AUTO_TEST_CASE( EmptyBoardIsClean )
91{
92 BOARD board;
93
95
96 BOOST_CHECK( !report.IsLossy() );
97 BOOST_CHECK( !report.IsBlocked() );
98 BOOST_CHECK( report.Entries().empty() );
99}
100
101
102// The ellipse primitive only exists since 20260508, so 10.0 gets an approximation.
103BOOST_AUTO_TEST_CASE( EllipseIsLoweredForKicad10 )
104{
105 BOARD board;
106 board.Add( new PCB_SHAPE( &board, SHAPE_T::ELLIPSE ) );
107
109
110 BOOST_CHECK( report.IsLossy() );
112}
113
114
115// A target that already has the ellipse primitive keeps it. This proves the version gate.
116BOOST_AUTO_TEST_CASE( EllipseKeptForNewerTarget )
117{
118 BOARD board;
119 board.Add( new PCB_SHAPE( &board, SHAPE_T::ELLIPSE ) );
120
121 DOWNGRADE_TARGET future = { wxT( "future" ), wxT( "future" ), 20260623, 20260629, 20260629 };
122 COMPATIBILITY_REPORT report = ClassifyBoardForDowngrade( &board, future );
123
124 BOOST_CHECK( !report.IsLossy() );
125}
126
127
128BOOST_AUTO_TEST_CASE( EllipseTransformedToPolygon )
129{
130 BOARD board;
131 PCB_SHAPE* ellipse = new PCB_SHAPE( &board, SHAPE_T::ELLIPSE );
132 ellipse->SetStart( VECTOR2I( 0, 0 ) );
133 ellipse->SetEnd( VECTOR2I( pcbIUScale.mmToIU( 5 ), 0 ) );
134 board.Add( ellipse );
135
137
138 BOOST_CHECK( ellipse->GetShape() == SHAPE_T::POLY );
139}
140
141
142// An unfilled ellipse must be lowered to its outline polygon, not to stroke debris.
143BOOST_AUTO_TEST_CASE( UnfilledEllipseKeepsOutline )
144{
145 BOARD board;
146 PCB_SHAPE* ellipse = new PCB_SHAPE( &board, SHAPE_T::ELLIPSE );
147 ellipse->SetEllipseCenter( VECTOR2I( 0, 0 ) );
148 ellipse->SetEllipseMajorRadius( pcbIUScale.mmToIU( 5 ) );
149 ellipse->SetEllipseMinorRadius( pcbIUScale.mmToIU( 3 ) );
150 ellipse->SetFillMode( FILL_T::NO_FILL );
151 ellipse->SetWidth( pcbIUScale.mmToIU( 0.2 ) );
152 board.Add( ellipse );
153
155
156 BOOST_REQUIRE( ellipse->GetShape() == SHAPE_T::POLY );
158 BOOST_CHECK( ellipse->GetFillMode() == FILL_T::NO_FILL );
159
160 double areaMM =
161 std::abs( ellipse->GetPolyShape().Outline( 0 ).Area() ) / ( pcbIUScale.IU_PER_MM * pcbIUScale.IU_PER_MM );
162
163 BOOST_CHECK_CLOSE( areaMM, M_PI * 5.0 * 3.0, 2.0 );
164}
165
166
167// An elliptical arc is an open curve, so it is lowered to a filled polygon of its ink.
168BOOST_AUTO_TEST_CASE( EllipseArcKeepsInk )
169{
170 BOARD board;
171 PCB_SHAPE* arc = new PCB_SHAPE( &board, SHAPE_T::ELLIPSE_ARC );
172 arc->SetEllipseCenter( VECTOR2I( 0, 0 ) );
173 arc->SetEllipseMajorRadius( pcbIUScale.mmToIU( 5 ) );
174 arc->SetEllipseMinorRadius( pcbIUScale.mmToIU( 3 ) );
177 arc->SetWidth( pcbIUScale.mmToIU( 0.3 ) );
178 board.Add( arc );
179
181
183
184 // A quarter arc of a 5 mm by 3 mm ellipse is about 6.4 mm of path at 0.3 mm width.
185 double areaMM = std::abs( arc->GetPolyShape().Area() ) / ( pcbIUScale.IU_PER_MM * pcbIUScale.IU_PER_MM );
186
187 BOOST_CHECK_GT( areaMM, 1.5 );
188 BOOST_CHECK_LT( areaMM, 2.6 );
189}
190
191
192// Text box knockout (20250210) postdates 9.0, so the flag is dropped and reported for 9.0.
193BOOST_AUTO_TEST_CASE( KnockoutTextBoxLoweredForKicad9 )
194{
195 BOARD board;
196 PCB_TEXTBOX* textbox = new PCB_TEXTBOX( &board );
197 textbox->SetIsKnockout( true );
198 board.Add( textbox );
199
202
203 DowngradeBoardInPlace( &board, kicad9 );
204
205 BOOST_CHECK( !textbox->IsKnockout() );
206}
207
208
209// Table cell knockout (20260603) postdates both targets, so the flag is dropped for 10.0.
210BOOST_AUTO_TEST_CASE( TableCellKnockoutLoweredForKicad10 )
211{
212 BOARD board;
213 PCB_TABLE* table = new PCB_TABLE( &board, pcbIUScale.mmToIU( 0.1 ) );
214 table->SetColCount( 1 );
215
216 PCB_TABLECELL* cell = new PCB_TABLECELL( table );
217 cell->SetIsKnockout( true );
218 table->AddCell( cell );
219 board.Add( table );
220
221 // A table inside a footprint carries the same flag and must be counted and lowered too.
222 FOOTPRINT* fp = new FOOTPRINT( &board );
223 PCB_TABLE* fpTable = new PCB_TABLE( fp, pcbIUScale.mmToIU( 0.1 ) );
224 fpTable->SetColCount( 1 );
225
226 PCB_TABLECELL* fpCell = new PCB_TABLECELL( fpTable );
227 fpCell->SetIsKnockout( true );
228 fpTable->AddCell( fpCell );
229 fp->Add( fpTable );
230 board.Add( fp );
231
233
235
236 BOOST_CHECK( !cell->IsKnockout() );
237 BOOST_CHECK( !fpCell->IsKnockout() );
238}
239
240
241// A knockout cell in a library footprint goes through the footprint-scoped rule.
242BOOST_AUTO_TEST_CASE( FootprintTableCellKnockoutLowered )
243{
244 FOOTPRINT* fp = new FOOTPRINT( nullptr );
245 PCB_TABLE* table = new PCB_TABLE( fp, pcbIUScale.mmToIU( 0.1 ) );
246 table->SetColCount( 1 );
247
248 PCB_TABLECELL* cell = new PCB_TABLECELL( table );
249 cell->SetIsKnockout( true );
250 table->AddCell( cell );
251 fp->Add( table );
252
254
255 BOOST_CHECK( !cell->IsKnockout() );
256 delete fp;
257}
258
259
260// Rounded rectangles (20250829) postdate 9.0, so 9.0 gets a polygon that keeps the rounding.
261BOOST_AUTO_TEST_CASE( RoundedRectangleLoweredForKicad9 )
262{
263 BOARD board;
264 PCB_SHAPE* rect = new PCB_SHAPE( &board, SHAPE_T::RECTANGLE );
265 rect->SetStart( VECTOR2I( 0, 0 ) );
266 rect->SetEnd( VECTOR2I( pcbIUScale.mmToIU( 10 ), pcbIUScale.mmToIU( 6 ) ) );
267 rect->SetCornerRadius( pcbIUScale.mmToIU( 1 ) );
268 rect->SetFillMode( FILL_T::NO_FILL );
269 rect->SetWidth( pcbIUScale.mmToIU( 0.2 ) );
270 board.Add( rect );
271
274
275 DowngradeBoardInPlace( &board, kicad9 );
276
277 BOOST_REQUIRE( rect->GetShape() == SHAPE_T::POLY );
278 BOOST_REQUIRE_EQUAL( rect->GetPolyShape().OutlineCount(), 1 );
279
280 // A 10 mm by 6 mm rectangle loses ( 4 - pi ) r^2 to the rounded corners.
281 double areaMM =
282 std::abs( rect->GetPolyShape().Outline( 0 ).Area() ) / ( pcbIUScale.IU_PER_MM * pcbIUScale.IU_PER_MM );
283
284 BOOST_CHECK_CLOSE( areaMM, 60.0 - ( 4.0 - M_PI ), 2.0 );
285}
286
287
288// A custom footprint stackup (20250818) remaps inner layers. 9.0 would expand them and change
289// the connectivity, so the export must block.
290BOOST_AUTO_TEST_CASE( CustomFootprintStackupBlocksKicad9 )
291{
292 BOARD board;
293 FOOTPRINT* fp = new FOOTPRINT( &board );
295 board.Add( fp );
296
299}
300
301
302// Non-component pads (20261031) cannot be represented by older writers for now.
303// (Probably they can be approximated, but needs some thought)
304BOOST_AUTO_TEST_CASE( NonComponentPadBlocksOlderTargets )
305{
306 BOARD board;
307 FOOTPRINT* fp = new FOOTPRINT( &board );
308 board.Add( fp );
309
310 PAD* pad = new PAD( fp );
311 pad->SetAttribute( PAD_ATTRIB::NON_COMPONENT );
312 pad->SetLayerSet( LSET( { F_Cu } ) );
313 fp->Add( pad );
314
317}
318
319
320// Per-zone layer properties (20250302) postdate 9.0, so they are dropped like the board-level
321// zone defaults.
322BOOST_AUTO_TEST_CASE( ZoneLayerPropertiesDroppedForKicad9 )
323{
324 BOARD board;
325 ZONE* zone = new ZONE( &board );
326 zone->LayerProperties()[F_Cu].hatching_offset = VECTOR2I( 100, 100 );
327 board.Add( zone );
328
329 // A zone inside a footprint carries the same properties and must be counted and dropped too.
330 FOOTPRINT* fp = new FOOTPRINT( &board );
331 ZONE* fpZone = new ZONE( fp );
332 fpZone->LayerProperties()[F_Cu].hatching_offset = VECTOR2I( 100, 100 );
333 fp->Add( fpZone );
334 board.Add( fp );
335
337
338 DowngradeBoardInPlace( &board, kicad9 );
339
340 BOOST_CHECK( zone->LayerProperties().empty() );
341 BOOST_CHECK( fpZone->LayerProperties().empty() );
342}
343
344
345BOOST_AUTO_TEST_CASE( BoardZoneDefaultsRoundTripAndDowngrade )
346{
347 SETTINGS_MANAGER settingsManager;
348 BOARD board;
349 board.GetDesignSettings().m_ZoneLayerProperties[F_Cu].hatching_offset = VECTOR2I( 100000, 200000 );
350 board.GetDesignSettings().m_ZoneLayerProperties[B_Cu].hatching_offset = VECTOR2I( 300000, 400000 );
351
352 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_board_zone_defaults" );
353 const std::string src = ( tmp.Path() / "source.kicad_pcb" ).string();
355 io.SaveBoard( src, board );
356 const std::string original = KI_TEST::ReadGoldenText( src );
357 std::unique_ptr<BOARD> current( io.LoadBoard( src, nullptr ) );
358 BOOST_REQUIRE( current );
359 const auto& loadedDefaults = current->GetDesignSettings().m_ZoneLayerProperties;
360 BOOST_REQUIRE_EQUAL( loadedDefaults.size(), 2 );
361 BOOST_CHECK( loadedDefaults.at( F_Cu ).hatching_offset == VECTOR2I( 100000, 200000 ) );
362 BOOST_CHECK( loadedDefaults.at( B_Cu ).hatching_offset == VECTOR2I( 300000, 400000 ) );
363 BOOST_CHECK( current->GetDesignSettings().GetDefaultZoneSettings().m_LayerProperties.empty() );
364
365 for( const auto& target : { kicad9, kicad10 } )
366 {
368 const std::string dest = ( tmp.Path() / ( target.m_id.ToStdString() + ".kicad_pcb" ) ).string();
369 BOOST_REQUIRE( ExportBoardToOlderVersion( src, dest, target, report ) );
370 std::unique_ptr<BOARD> reloaded( io.LoadBoard( dest, nullptr ) );
371 BOOST_REQUIRE( reloaded );
372 const auto& defaults = reloaded->GetDesignSettings().m_ZoneLayerProperties;
373
374 if( target.m_id == wxT( "9.0" ) )
375 {
377 BOOST_CHECK( defaults.empty() );
378 BOOST_CHECK( KI_TEST::ReadGoldenText( dest ).find( "zone_defaults" ) == std::string::npos );
379 }
380 else
381 {
382 BOOST_CHECK( !report.IsLossy() );
383 BOOST_REQUIRE_EQUAL( defaults.size(), 2 );
384 BOOST_CHECK( defaults.at( F_Cu ).hatching_offset == loadedDefaults.at( F_Cu ).hatching_offset );
385 BOOST_CHECK( defaults.at( B_Cu ).hatching_offset == loadedDefaults.at( B_Cu ).hatching_offset );
386 }
387
388 BOOST_CHECK( KI_TEST::ReadGoldenText( src ) == original );
389 }
390}
391
392
393// The old (at) header cannot represent a scaled footprint, so the export must block.
394BOOST_AUTO_TEST_CASE( ScaledFootprintBlocksExport )
395{
396 BOARD board;
397 FOOTPRINT* fp = new FOOTPRINT( &board );
398 fp->SetTransformScale( 2.0, 1.0 );
399 board.Add( fp );
400
402
403 BOOST_CHECK( report.IsBlocked() );
405}
406
407
408// IPC-4761 via protection postdates 9.0, so it is dropped and reported for 9.0.
409BOOST_AUTO_TEST_CASE( ViaProtectionDroppedForKicad9 )
410{
411 BOARD board;
412 PCB_VIA* via = new PCB_VIA( &board );
413 via->Padstack().Drill().is_capped = true;
414 board.Add( via );
415
417
418 DowngradeBoardInPlace( &board, kicad9 );
419
420 BOOST_CHECK( !via->Padstack().Drill().is_capped.has_value() );
421}
422
423
424// Frequency-dependent dielectric models postdate both targets, so they are dropped for 10.0.
438
439
440// Group design block links postdate 9.0, so they are dropped and reported for 9.0.
441BOOST_AUTO_TEST_CASE( GroupDesignBlockLinkDroppedForKicad9 )
442{
443 BOARD board;
444 PCB_GROUP* group = new PCB_GROUP( &board );
445 group->SetDesignBlockLibId( LIB_ID( wxT( "Lib" ), wxT( "Block" ) ) );
446 board.Add( group );
447
449
450 DowngradeBoardInPlace( &board, kicad9 );
451
452 BOOST_CHECK( !group->HasDesignBlockLink() );
453}
454
455
456// Extruded 3D bodies (20260410) have no equivalent in 10.0, so they are dropped.
457BOOST_AUTO_TEST_CASE( ExtrudedBodyDroppedForKicad10 )
458{
459 BOARD board;
460 FOOTPRINT* fp = new FOOTPRINT( &board );
461 fp->EnsureBody();
462 board.Add( fp );
463
465
467
468 BOOST_CHECK( !fp->HasBody() );
469}
470
471
472// A refill in the old version would turn a thieving pattern into solid copper, quietly.
473// That is silent corruption, so the export must block.
474BOOST_AUTO_TEST_CASE( ThievingZoneBlocksKicad10 )
475{
476 BOARD board;
477 ZONE* zone = new ZONE( &board );
479 board.Add( zone );
480
482
484
485 BOOST_CHECK( zone->IsCopperThieving() );
486}
487
488
489// Backdrilling changes copper connectivity between layers, so the export must block for 9.0.
490BOOST_AUTO_TEST_CASE( BackdrillBlocksKicad9 )
491{
492 BOARD board;
493 PCB_VIA* via = new PCB_VIA( &board );
494 via->SetSecondaryDrillSize( VECTOR2I( pcbIUScale.mmToIU( 0.3 ), pcbIUScale.mmToIU( 0.3 ) ) );
495 board.Add( via );
496
499}
500
501
502// The headline fail-closed promise: a blocked board export returns failure and writes nothing.
503// The staging name must not be guessable, because the writer resolves symlinks on purpose.
504BOOST_AUTO_TEST_CASE( BoardExportIgnoresAPredictableStagingSymlink )
505{
506 SETTINGS_MANAGER settingsManager;
507
508 const std::string src = KI_TEST::GetPcbnewTestDataDir() + "via_off_center.kicad_pcb";
509
510 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_staging_symlink", "" );
511 const wxString dest = ( tmp.Path() / "out.kicad_pcb" ).wstring();
512 const wxString victim = ( tmp.Path() / "victim.txt" ).wstring();
513
514 {
515 wxFFile file( victim, wxT( "wb" ) );
516 BOOST_REQUIRE( file.IsOpened() );
517 file.Write( wxT( "untouched" ) );
518 }
519
520 const wxString decoy =
521 dest + wxString::Format( wxT( ".downgrade_tmp.%lu" ), (unsigned long) wxGetProcessId() );
522 std::error_code ec;
523 std::filesystem::create_symlink( victim.ToStdString(), decoy.ToStdString(), ec );
524 BOOST_REQUIRE( !ec );
525
527 BOOST_CHECK( ExportBoardToOlderVersion( src, dest, kicad9, report ) );
528
529 wxString after;
530 {
531 wxFFile file( victim, wxT( "rb" ) );
532 BOOST_REQUIRE( file.IsOpened() && file.ReadAll( &after ) );
533 }
534
535 BOOST_CHECK( after == wxT( "untouched" ) );
536
537 // A normal save in the same directory shares this umask, so the modes must agree.
538 const wxString reference = ( tmp.Path() / "reference.kicad_pcb" ).wstring();
540 std::unique_ptr<BOARD> board( io.LoadBoard( dest, nullptr ) );
541 BOOST_REQUIRE( board );
542 io.SaveBoard( reference, *board );
543
544 BOOST_CHECK( std::filesystem::status( dest.ToStdString() ).permissions()
545 == std::filesystem::status( reference.ToStdString() ).permissions() );
546}
547
548
549BOOST_AUTO_TEST_CASE( BlockedBoardExportWritesNothing )
550{
551 SETTINGS_MANAGER settingsManager;
552
553 BOARD board;
554 ZONE* zone = new ZONE( &board );
555 zone->SetLayer( F_Cu );
556 zone->AppendCorner( VECTOR2I( 0, 0 ), -1 );
557 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 10 ), 0 ), -1 );
558 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 10 ), pcbIUScale.mmToIU( 10 ) ), -1 );
560 board.Add( zone );
561
562 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_blocked_export", "" );
563 const wxString src = ( tmp.Path() / "src.kicad_pcb" ).wstring();
564 const wxString dest = ( tmp.Path() / "out.kicad_pcb" ).wstring();
565
567 io.SaveBoard( src, board );
568
570 BOOST_CHECK( !ExportBoardToOlderVersion( src, dest, kicad10, report ) );
571 BOOST_CHECK( report.IsBlocked() );
572 BOOST_CHECK( !wxFileExists( dest ) );
573}
574
575
576// Pad simulation electrical types (20260521) are dropped for 10.0.
577BOOST_AUTO_TEST_CASE( PadSimTypeDroppedForKicad10 )
578{
579 BOARD board;
580 FOOTPRINT* fp = new FOOTPRINT( &board );
581 PAD* pad = new PAD( fp );
582 pad->SetSimElectricalType( PAD_SIM_ELECTRICAL_TYPE::SOURCE );
583 fp->Add( pad );
584 board.Add( fp );
585
587
589
590 BOOST_CHECK( pad->GetSimElectricalType() == PAD_SIM_ELECTRICAL_TYPE::NONE );
591}
592
593
594// Counterbore / countersink is a post-9.0 feature 9.0 cannot parse, so it is dropped for 9.0.
595BOOST_AUTO_TEST_CASE( PostMachiningDroppedForKicad9 )
596{
597 BOARD board;
598 FOOTPRINT* fp = new FOOTPRINT( &board );
599 PAD* pad = new PAD( fp );
600 pad->Padstack().FrontPostMachining().mode = PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE;
601 fp->Add( pad );
602 board.Add( fp );
603
605
606 DowngradeBoardInPlace( &board, kicad9 );
607
608 BOOST_CHECK( !pad->Padstack().FrontPostMachining().mode.has_value() );
609}
610
611
612// Press-fit is a post-9.0 pad property 9.0 cannot parse, so it is dropped for 9.0.
613BOOST_AUTO_TEST_CASE( PressFitDroppedForKicad9 )
614{
615 BOARD board;
616 FOOTPRINT* fp = new FOOTPRINT( &board );
617 PAD* pad = new PAD( fp );
618 pad->SetProperty( PAD_PROP::PRESSFIT );
619 fp->Add( pad );
620 board.Add( fp );
621
623
624 DowngradeBoardInPlace( &board, kicad9 );
625
626 BOOST_CHECK( pad->GetProperty() == PAD_PROP::NONE );
627}
628
629
630// Skip vias are post-9.0, so they are approximated by the nearest mode 9.0 understands.
631BOOST_AUTO_TEST_CASE( SkipViaLoweredForKicad9 )
632{
633 BOARD board;
634 PCB_VIA* via = new PCB_VIA( &board );
635 via->Padstack().SetUnconnectedLayerMode( UNCONNECTED_LAYER_MODE::START_END_ONLY );
636 board.Add( via );
637
639
640 DowngradeBoardInPlace( &board, kicad9 );
641
642 BOOST_CHECK( via->Padstack().UnconnectedLayerMode() == UNCONNECTED_LAYER_MODE::REMOVE_EXCEPT_START_AND_END );
643}
644
645
646// The v10 writer must not move anything. Every footprint and pad position in the export must match
647// the source exactly. This guards the extracted writer against silent model drift.
648BOOST_AUTO_TEST_CASE( ExportToKicad10PreservesGeometry )
649{
650 SETTINGS_MANAGER settingsManager;
651
652 const std::string src = KI_TEST::GetPcbnewTestDataDir() + "via_off_center.kicad_pcb";
653
654 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_downgrade_geom", "" );
655 const std::string dest = ( tmp.Path() / "out.kicad_pcb" ).string();
656
658 BOOST_REQUIRE( ExportBoardToOlderVersion( src, dest, kicad10, report ) );
659
661 std::unique_ptr<BOARD> source( io.LoadBoard( src, nullptr ) );
662 std::unique_ptr<BOARD> exported( io.LoadBoard( dest, nullptr ) );
663
664 BOOST_REQUIRE( source && exported );
665 BOOST_REQUIRE_EQUAL( source->Footprints().size(), exported->Footprints().size() );
666
667 for( size_t i = 0; i < source->Footprints().size(); i++ )
668 {
669 FOOTPRINT* a = source->Footprints()[i];
670 FOOTPRINT* b = exported->Footprints()[i];
671
673 BOOST_CHECK( a->GetPosition() == b->GetPosition() );
675
676 BOOST_REQUIRE_EQUAL( a->Pads().size(), b->Pads().size() );
677
678 for( size_t p = 0; p < a->Pads().size(); p++ )
679 BOOST_CHECK( a->Pads()[p]->GetPosition() == b->Pads()[p]->GetPosition() );
680 }
681}
682
683
684// Same geometry guard for the v9 writer.
685BOOST_AUTO_TEST_CASE( ExportToKicad9PreservesGeometry )
686{
687 SETTINGS_MANAGER settingsManager;
688
689 const std::string src = KI_TEST::GetPcbnewTestDataDir() + "via_off_center.kicad_pcb";
690
691 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_downgrade_geom9", "" );
692 const std::string dest = ( tmp.Path() / "out.kicad_pcb" ).string();
693
695 BOOST_REQUIRE( ExportBoardToOlderVersion( src, dest, kicad9, report ) );
696
698 std::unique_ptr<BOARD> source( io.LoadBoard( src, nullptr ) );
699 std::unique_ptr<BOARD> exported( io.LoadBoard( dest, nullptr ) );
700
701 BOOST_REQUIRE( source && exported );
702 BOOST_REQUIRE_EQUAL( source->Footprints().size(), exported->Footprints().size() );
703
704 for( size_t i = 0; i < source->Footprints().size(); i++ )
705 {
706 FOOTPRINT* a = source->Footprints()[i];
707 FOOTPRINT* b = exported->Footprints()[i];
708
709 BOOST_CHECK( a->GetPosition() == b->GetPosition() );
710
711 BOOST_REQUIRE_EQUAL( a->Pads().size(), b->Pads().size() );
712
713 for( size_t pd = 0; pd < a->Pads().size(); pd++ )
714 BOOST_CHECK( a->Pads()[pd]->GetPosition() == b->Pads()[pd]->GetPosition() );
715 }
716}
717
718
719// Buried vias postdate 9.0's blind/buried split, so they are written with the old combined type.
720BOOST_AUTO_TEST_CASE( BuriedViaLoweredForKicad9 )
721{
722 BOARD board;
723 PCB_VIA* via = new PCB_VIA( &board );
724 via->SetViaType( VIATYPE::BURIED );
725 board.Add( via );
726
728
729 DowngradeBoardInPlace( &board, kicad9 );
730
731 BOOST_CHECK( via->GetViaType() == VIATYPE::BLIND );
732}
733
734
735// Per-layer zone defaults are a post-9.0 setup block, so they are dropped for 9.0.
736BOOST_AUTO_TEST_CASE( ZoneDefaultsDroppedForKicad9 )
737{
738 BOARD board;
740
742
743 DowngradeBoardInPlace( &board, kicad9 );
744
746}
747
748
749// A barcode is fabricated ink, so it becomes its rendered polygons instead of vanishing.
750BOOST_AUTO_TEST_CASE( BarcodeLoweredToPolygonsForKicad9 )
751{
752 BOARD board;
753 PCB_BARCODE* barcode = new PCB_BARCODE( &board );
754 barcode->SetLayer( F_SilkS );
755 barcode->SetWidth( pcbIUScale.mmToIU( 10 ) );
756 barcode->SetHeight( pcbIUScale.mmToIU( 10 ) );
757 barcode->SetBarcodeText( wxT( "TEST123" ) );
758 board.Add( barcode );
759
762
763 // The net printed area, holes subtracted. A finder ring must not become a solid square.
765 barcode->TransformShapeToPolygon( expected, barcode->GetLayer(), 0, 0, ERROR_INSIDE );
766 expected.Simplify();
767 expected.Fracture();
768 double expectedMM = expected.Area() / ( pcbIUScale.IU_PER_MM * pcbIUScale.IU_PER_MM );
769
770 DowngradeBoardInPlace( &board, kicad9 );
771
772 int polyCount = 0;
773 double areaMM = 0;
774
775 for( BOARD_ITEM* item : board.Drawings() )
776 {
777 BOOST_REQUIRE( item->Type() != PCB_BARCODE_T );
778
779 if( item->Type() == PCB_SHAPE_T )
780 {
781 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
782 BOOST_REQUIRE( shape->GetShape() == SHAPE_T::POLY );
783 BOOST_CHECK( shape->GetLayer() == F_SilkS );
784 polyCount++;
785 areaMM += std::abs( shape->GetPolyShape().Area() ) / ( pcbIUScale.IU_PER_MM * pcbIUScale.IU_PER_MM );
786 }
787 }
788
789 // The printed ink survives: many module polygons with a real total area.
790 BOOST_CHECK_GT( polyCount, 1 );
791 BOOST_CHECK_GT( areaMM, 5.0 );
792 BOOST_CHECK_CLOSE( areaMM, expectedMM, 0.1 );
793}
794
795
796BOOST_AUTO_TEST_CASE( BarcodeProjectVariablesResolvedBeforeExport )
797{
798 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_barcode_project" );
799 wxString projectPath = ( tmp.Path() / "source.kicad_pro" ).string();
800 wxString boardPath = ( tmp.Path() / "source.kicad_pcb" ).string();
801 wxString outputPath = ( tmp.Path() / "output.kicad_pcb" ).string();
802
803 {
804 std::ofstream project( projectPath.ToStdString() );
805 project << R"({"meta":{"version":3},"text_variables":{"SERIAL":"SERIAL123"}})";
806 }
807
808 SETTINGS_MANAGER settings;
809 BOOST_REQUIRE( settings.LoadProject( projectPath, false ) );
810 BOARD board;
811 board.SetProject( settings.GetProject( projectPath ), true );
812 PCB_BARCODE* barcode = new PCB_BARCODE( &board );
813 barcode->SetLayer( F_SilkS );
815 barcode->SetWidth( pcbIUScale.mmToIU( 10 ) );
816 barcode->SetHeight( pcbIUScale.mmToIU( 10 ) );
817 barcode->SetBarcodeText( wxT( "${SERIAL}" ) );
818 barcode->SetShowText( false );
819 board.Add( barcode );
820 BOOST_REQUIRE_EQUAL( barcode->GetShownText( FOR_CANVAS ), wxString( "SERIAL123" ) );
821
824 expected.Simplify();
825 expected.Fracture();
826 double expectedArea = expected.Area();
827
829 io.SaveBoard( boardPath, board );
831 BOOST_REQUIRE( ExportBoardToOlderVersion( boardPath, outputPath, kicad9, report ) );
832 std::unique_ptr<BOARD> result( io.LoadBoard( outputPath, nullptr ) );
834 int polygonCount = 0;
835 double resultArea = 0;
836
837 for( BOARD_ITEM* item : result->Drawings() )
838 {
839 BOOST_REQUIRE( item->Type() != PCB_BARCODE_T );
840
841 if( item->Type() == PCB_SHAPE_T )
842 {
843 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
844 BOOST_REQUIRE( shape->GetShape() == SHAPE_T::POLY );
845 polygonCount++;
846 resultArea += std::abs( shape->GetPolyShape().Area() );
847 }
848 }
849
850 BOOST_CHECK_EQUAL( polygonCount, expected.OutlineCount() );
851 BOOST_CHECK_CLOSE( resultArea, expectedArea, 0.01 );
852}
853
854
855// A barcode inside a footprint takes the same conversion through the footprint path.
856BOOST_AUTO_TEST_CASE( FootprintBarcodeLoweredForKicad9 )
857{
858 BOARD board;
859 FOOTPRINT* fp = new FOOTPRINT( &board );
860 PCB_BARCODE* barcode = new PCB_BARCODE( fp );
861 barcode->SetLayer( F_SilkS );
862 barcode->SetWidth( pcbIUScale.mmToIU( 10 ) );
863 barcode->SetHeight( pcbIUScale.mmToIU( 10 ) );
864 barcode->SetBarcodeText( wxT( "TEST123" ) );
865 fp->Add( barcode );
866 board.Add( fp );
867
869
870 DowngradeBoardInPlace( &board, kicad9 );
871
872 int polyCount = 0;
873
874 for( BOARD_ITEM* item : fp->GraphicalItems() )
875 {
876 BOOST_REQUIRE( item->Type() != PCB_BARCODE_T );
877
878 if( item->Type() == PCB_SHAPE_T && static_cast<PCB_SHAPE*>( item )->GetShape() == SHAPE_T::POLY )
879 polyCount++;
880 }
881
882 BOOST_CHECK_GT( polyCount, 1 );
883}
884
885
886// Exercise the real .kicad_mod write path used to downgrade a footprint library, and confirm the
887// result carries the target stamp and reloads cleanly.
888BOOST_AUTO_TEST_CASE( FootprintFileDowngradeRoundTrips )
889{
890 const std::string src = KI_TEST::GetPcbnewTestDataDir() + "issue24045/QFN-24_L4.0-W4.0-P0.50-BL-EP2.6.kicad_mod";
891
892 PCB_IO_KICAD_SEXPR loader;
893 wxString nameOut;
894 std::unique_ptr<FOOTPRINT> fp( loader.ImportFootprint( src, nameOut ) );
895 BOOST_REQUIRE( fp != nullptr );
896
898
899 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_fp_downgrade", "" );
900 const wxString dest = ( tmp.Path() / "out.kicad_mod" ).wstring();
901
902 SaveFootprintForTarget( fp.get(), dest, kicad9 );
903
904 // The stamp proves the dispatch picked the right writer, not just a parseable one.
905 std::ifstream out( dest.ToStdString() );
906 std::string content( ( std::istreambuf_iterator<char>( out ) ), std::istreambuf_iterator<char>() );
907 BOOST_CHECK( content.find( "(version " + std::to_string( kicad9.m_boardVersion ) + ")" ) != std::string::npos );
908
909 PCB_IO_KICAD_SEXPR reader;
910 wxString reloadName;
911 std::unique_ptr<FOOTPRINT> reloaded( reader.ImportFootprint( dest, reloadName ) );
912 BOOST_CHECK( reloaded != nullptr );
913}
914
915
916// The v10 footprint file path gets the same round-trip check as v9.
917BOOST_AUTO_TEST_CASE( FootprintFileV10RoundTrips )
918{
919 SETTINGS_MANAGER settingsManager;
920
921 const std::string src = KI_TEST::GetPcbnewTestDataDir() + "issue24045/QFN-24_L4.0-W4.0-P0.50-BL-EP2.6.kicad_mod";
922
923 PCB_IO_KICAD_SEXPR loader;
924 wxString nameOut;
925 std::unique_ptr<FOOTPRINT> fp( loader.ImportFootprint( src, nameOut ) );
926 BOOST_REQUIRE( fp != nullptr );
927
929
930 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_fp_downgrade10", "" );
931 const wxString dest = ( tmp.Path() / "out.kicad_mod" ).wstring();
932
933 SaveFootprintForTarget( fp.get(), dest, kicad10 );
934
935 std::ifstream out( dest.ToStdString() );
936 std::string content( ( std::istreambuf_iterator<char>( out ) ), std::istreambuf_iterator<char>() );
937 BOOST_CHECK( content.find( "(version " + std::to_string( kicad10.m_boardVersion ) + ")" ) != std::string::npos );
938
939 PCB_IO_KICAD_SEXPR reader;
940 wxString reloadName;
941 std::unique_ptr<FOOTPRINT> reloaded( reader.ImportFootprint( dest, reloadName ) );
942 BOOST_CHECK( reloaded != nullptr );
943}
944
945
946// A library footprint carries the same features but is downgraded through its own path.
947BOOST_AUTO_TEST_CASE( FootprintPressFitDroppedForKicad9 )
948{
949 BOARD board;
950 FOOTPRINT* fp = new FOOTPRINT( &board );
951 PAD* pad = new PAD( fp );
952 pad->SetProperty( PAD_PROP::PRESSFIT );
953 fp->Add( pad );
954
956
957 BOOST_CHECK( pad->GetProperty() == PAD_PROP::NONE );
958
959 delete fp;
960}
961
962
963// Saving with a target version writes the older stamp, and reloading reads it back.
964BOOST_AUTO_TEST_CASE( SaveWithTargetVersionStampsOlder )
965{
966 SETTINGS_MANAGER settingsManager;
967
968 BOARD board;
969
970 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_downgrade", "" );
971 std::string dest = ( tmp.Path() / "out.kicad_pcb" ).string();
972
973 SaveBoardForTarget( &board, dest, kicad10 );
974
975 PCB_IO_KICAD_SEXPR reader;
976 std::unique_ptr<BOARD> reloaded( reader.LoadBoard( dest, nullptr ) );
977
978 BOOST_REQUIRE( reloaded != nullptr );
979 BOOST_CHECK_EQUAL( reloaded->GetFileFormatVersionAtLoad(), kicad10.m_boardVersion );
980}
981
982
983// The fields deque can hold null slots. The writer must skip them like the current one does.
984BOOST_AUTO_TEST_CASE( NullFieldSlotDoesNotCrashV9Writer )
985{
986 SETTINGS_MANAGER settingsManager;
987
988 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>( nullptr );
989 fp->GetFields().push_back( nullptr );
990
991 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_v9_nullfield", "" );
992 const wxString dest = ( tmp.Path() / "out.kicad_mod" ).wstring();
993
994 SaveFootprintForTarget( fp.get(), dest, kicad9 );
995
996 BOOST_CHECK( std::filesystem::exists( dest.ToStdString() ) );
997}
998
999
1000// The 10.0 release writer skips group members that are no longer on the board, so the v10
1001// snapshot must too. The 9.0 release writer had no such check and its snapshot stays faithful.
1002BOOST_AUTO_TEST_CASE( StaleGroupMemberNotWrittenForV10 )
1003{
1004 SETTINGS_MANAGER settingsManager;
1005
1006 BOARD board;
1007 PCB_SHAPE* onBoard = new PCB_SHAPE( &board, SHAPE_T::SEGMENT );
1008 board.Add( onBoard );
1009
1010 PCB_SHAPE* stale = new PCB_SHAPE( &board, SHAPE_T::SEGMENT );
1011
1012 PCB_GROUP* group = new PCB_GROUP( &board );
1013 group->AddItem( onBoard );
1014 group->AddItem( stale );
1015 board.Add( group );
1016
1017 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_v10_stalegroup", "" );
1018 const std::string dest = ( tmp.Path() / "out.kicad_pcb" ).string();
1019
1020 SaveBoardForTarget( &board, dest, kicad10 );
1021
1022 std::ifstream out( dest );
1023 std::string content( ( std::istreambuf_iterator<char>( out ) ), std::istreambuf_iterator<char>() );
1024
1025 BOOST_CHECK( content.find( onBoard->m_Uuid.AsString().ToStdString() ) != std::string::npos );
1026 BOOST_CHECK( content.find( stale->m_Uuid.AsString().ToStdString() ) == std::string::npos );
1027
1028 group->RemoveAll();
1029 delete stale;
1030}
1031
1032
1033// A via mode the era writer predates must be written as the nearest era mode, not silently
1034// fall through to keep-all.
1035BOOST_AUTO_TEST_CASE( SkipViaModeWrittenForV9 )
1036{
1037 SETTINGS_MANAGER settingsManager;
1038
1039 BOARD board;
1040 PCB_VIA* via = new PCB_VIA( &board );
1041 via->Padstack().SetUnconnectedLayerMode( UNCONNECTED_LAYER_MODE::START_END_ONLY );
1042 board.Add( via );
1043
1044 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_v9_skipvia", "" );
1045 const std::string dest = ( tmp.Path() / "out.kicad_pcb" ).string();
1046
1047 SaveBoardForTarget( &board, dest, kicad9 );
1048
1049 std::ifstream out( dest );
1050 std::string content( ( std::istreambuf_iterator<char>( out ) ), std::istreambuf_iterator<char>() );
1051
1052 BOOST_CHECK( content.find( "(remove_unused_layers yes)" ) != std::string::npos );
1053 BOOST_CHECK( content.find( "(keep_end_layers yes)" ) != std::string::npos );
1054
1055 PCB_IO_KICAD_SEXPR reader;
1056 std::unique_ptr<BOARD> reloaded( reader.LoadBoard( dest, nullptr ) );
1057 BOOST_REQUIRE( reloaded );
1058 BOOST_REQUIRE_EQUAL( reloaded->Tracks().size(), 1 );
1059 BOOST_REQUIRE( reloaded->Tracks().front()->Type() == PCB_VIA_T );
1060 const PCB_VIA* reloadedVia = static_cast<const PCB_VIA*>( reloaded->Tracks().front() );
1061 BOOST_CHECK( reloadedVia->Padstack().UnconnectedLayerMode()
1063}
1064
1065
1066// The target computes the image PPI the old truncating way, so the stored scale must be
1067// migrated back or the image renders at the wrong size there.
1068BOOST_AUTO_TEST_CASE( ImageScaleMigratedForV9 )
1069{
1070 SETTINGS_MANAGER settingsManager;
1071
1072 BOARD board;
1073 PCB_REFERENCE_IMAGE* otherImage = new PCB_REFERENCE_IMAGE( &board );
1074 wxMemoryBuffer buf = KI_TEST::MakePngWithFractionalPixelsPerCm();
1075 BOOST_REQUIRE( otherImage->GetReferenceImage().ReadImageFile( buf ) );
1076 otherImage->GetReferenceImage().SetImageScale( 0.5 );
1077 board.Add( otherImage );
1078
1080 REFERENCE_IMAGE& ref = image->GetReferenceImage();
1081
1082 BOOST_REQUIRE( ref.ReadImageFile( buf ) );
1083 ref.SetImageScale( 2.0 );
1084 board.Add( image );
1085
1086 int ppi = ref.GetImage().GetPPI();
1087 int legacyPPI = ref.GetImage().GetLegacyPPI();
1088 BOOST_REQUIRE( legacyPPI > 0 && ppi != legacyPPI );
1089
1090 double originalScale = ref.GetImageScale();
1091
1092 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_v9_imgscale", "" );
1093 const std::string dest = ( tmp.Path() / "out.kicad_pcb" ).string();
1094
1095 DowngradeBoardInPlace( &board, kicad9 );
1096 SaveBoardForTarget( &board, dest, kicad9 );
1097
1098 std::ifstream out( dest );
1099 std::string content( ( std::istreambuf_iterator<char>( out ) ), std::istreambuf_iterator<char>() );
1100
1101 const double written = KI_TEST::SerializedImageScale( content, image->m_Uuid.AsStdString() );
1102 BOOST_CHECK_CLOSE( written, originalScale * legacyPPI / ppi, 0.1 );
1103 BOOST_CHECK_CLOSE( KI_TEST::SerializedImageScale( content, otherImage->m_Uuid.AsStdString() ),
1104 0.5 * legacyPPI / ppi, 0.1 );
1105}
1106
1107
1108// The target has no way to store an image rotation, so an angled image blocks the export.
1109BOOST_AUTO_TEST_CASE( RotatedReferenceImageBlocks )
1110{
1111 BOARD board;
1113 image->GetReferenceImage().SetOrientation( EDA_ANGLE( 45.0, DEGREES_T ) );
1114 board.Add( image );
1115
1117
1118 BOOST_CHECK( report.IsBlocked() );
1120
1121 // An upright image is still exportable.
1122 image->GetReferenceImage().SetOrientation( ANGLE_0 );
1123 BOOST_CHECK( !ClassifyBoardForDowngrade( &board, kicad10 ).IsBlocked() );
1124}
1125
1126
1127// The target has no way to store an image opacity, so the export proceeds with full opacity.
1128BOOST_AUTO_TEST_CASE( ReferenceImageOpacityIsDropped )
1129{
1130 BOARD board;
1132 image->GetReferenceImage().SetOpacity( 0.4 );
1133 board.Add( image );
1134
1136
1137 BOOST_CHECK( !report.IsBlocked() );
1139
1140 DowngradeBoardInPlace( &board, kicad10 );
1141
1142 BOOST_CHECK_EQUAL( image->GetReferenceImage().GetOpacity(), 1.0 );
1144}
1145
1146
1147// The fail-closed gate: a post-10.0 token surviving in the output is caught, and lookalikes are not.
1148BOOST_AUTO_TEST_CASE( VerifyGateCatchesUnsupportedTokens )
1149{
1150 // An unstripped feature (e.g. an affine transform) must be caught.
1151 BOOST_CHECK( FindUnsupportedBoardToken( wxT( "(footprint (transform (translate 1 2)))" ), kicad10 )
1152 == wxT( "transform" ) );
1153 BOOST_CHECK( FindUnsupportedBoardToken( wxT( "(net_chain \"n\")" ), kicad10 ) == wxT( "net_chain" ) );
1154
1155 // A clean board, and lookalike prefixes, must pass.
1156 BOOST_CHECK( FindUnsupportedBoardToken( wxT( "(kicad_pcb (net 0 \"n\") (gr_line ...))" ), kicad10 ).IsEmpty() );
1157
1158 // Value tokens the node scan cannot see must still be caught for 9.0, but not inside strings.
1159
1160 BOOST_CHECK( FindUnsupportedBoardToken( wxT( "(via buried (at 1 1))" ), kicad9 ) == wxT( "buried" ) );
1161 BOOST_CHECK( FindUnsupportedBoardToken( wxT( "(gr_text \"buried treasure\")" ), kicad9 ).IsEmpty() );
1162}
1163
1164
1165// One unknown keyword makes an old KiCad drop the whole rules file, so the export must
1166// comment out rules the target cannot parse and keep the rest byte-identical.
1167BOOST_AUTO_TEST_CASE( DrcRulesFilterForKicad9 )
1168{
1169 const wxString rules = wxT( "(version 2)\n"
1170 "# keep me\n"
1171 "(rule \"clearance_ok\"\n"
1172 " # chamfer runs at 45deg here\n"
1173 " (constraint clearance (min 0.2mm))\n"
1174 " (condition \"A.NetClass == 'HV'\"))\n"
1175 "(rule \"mask_check\"\n"
1176 " (constraint bridged_mask))\n"
1177 "(rule \"chain_check\"\n"
1178 " (condition \"inNetChain('x')\")\n"
1179 " (constraint clearance (min 0.1mm)))\n"
1180 "(rule \"delay_check\"\n"
1181 " (constraint skew (max 5ps)))\n" );
1182
1184
1185 BOOST_REQUIRE_EQUAL( result.m_dropped.size(), 3 );
1186 BOOST_CHECK_EQUAL( result.m_dropped[0], wxString( "mask_check" ) );
1187 BOOST_CHECK_EQUAL( result.m_dropped[1], wxString( "chain_check" ) );
1188 BOOST_CHECK_EQUAL( result.m_dropped[2], wxString( "delay_check" ) );
1189
1190 BOOST_CHECK( result.m_text.Contains( wxT( "(version 1)" ) ) );
1191 BOOST_CHECK( result.m_text.Contains( wxT( "# keep me" ) ) );
1192 BOOST_CHECK( result.m_text.Contains( wxT( "(rule \"clearance_ok\"" ) ) );
1193 BOOST_CHECK( result.m_text.Contains( wxT( "A.NetClass == 'HV'" ) ) );
1194 BOOST_CHECK( result.m_text.Contains( wxT( "# Not supported by KiCad 9.0:\n"
1195 "# (rule \"mask_check\"\n# (constraint bridged_mask))\n" ) ) );
1196 BOOST_CHECK( result.m_text.Contains( wxT( "# (rule \"chain_check\"\n# (condition \"inNetChain('x')\")\n" ) ) );
1197 BOOST_CHECK( result.m_text.Contains( wxT( "# (rule \"delay_check\"\n# (constraint skew (max 5ps)))\n" ) ) );
1198}
1199
1200
1201// Released targets read line_width as text_thickness, so the kind is renamed instead of dropping the rule
1202BOOST_AUTO_TEST_CASE( LineWidthRuleDowngradesToTextThickness )
1203{
1204 const wxString rules = wxT( "(version 1)\n"
1205 "(rule \"line_width\" (layer F.SilkS) (constraint line_width (min 0.2mm)))\n" );
1206
1207 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
1208 {
1210
1211 BOOST_CHECK( result.m_dropped.empty() );
1212 BOOST_CHECK_EQUAL( result.m_text, wxString( wxT( "(version 1)\n"
1213 "(rule \"line_width\" (layer F.SilkS) "
1214 "(constraint text_thickness (min 0.2mm)))\n" ) ) );
1215 }
1216}
1217
1218
1219static size_t ParsedDrcRuleCount( const wxString& aText, const wxString& aSource )
1220{
1221 DRC_RULES_PARSER parser( aText, aSource );
1223 std::vector<std::shared_ptr<DRC_RULE>> rules;
1224 parser.Parse( rules, &reporter );
1225 BOOST_CHECK_MESSAGE( !reporter.HasMessageOfSeverity( RPT_SEVERITY_ERROR ), reporter.GetMessages() );
1226 return rules.size();
1227}
1228
1229
1230BOOST_AUTO_TEST_CASE( DroppedRulesStayInTheFileAsComments )
1231{
1232 const wxString rules = wxT( "(version 2)\n"
1233 "(rule \"keep\" (constraint clearance (min 0.2mm)))\n"
1234 "# why the chain rule exists\n"
1235 "(rule \"chain\"\n"
1236 " (constraint net_chain_length (max 10mm)))\n"
1237 "(rule \"glued\" (constraint net_chain_length (max 1mm)))"
1238 "(rule \"after\" (constraint clearance (min 0.1mm)))\n" );
1239
1240 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
1241 {
1243 BOOST_REQUIRE( result.m_error.IsEmpty() );
1244 BOOST_REQUIRE_EQUAL( result.m_dropped.size(), 2 );
1245
1246 const wxString marker = wxT( "# Not supported by " ) + target.m_name + wxT( ":\n" );
1247 const wxString expected = wxT( "(version 1)\n"
1248 "(rule \"keep\" (constraint clearance (min 0.2mm)))\n"
1249 "# why the chain rule exists\n" )
1250 + marker
1251 + wxT( "# (rule \"chain\"\n"
1252 "# (constraint net_chain_length (max 10mm)))\n" )
1253 + marker
1254 + wxT( "# (rule \"glued\" (constraint net_chain_length (max 1mm)))\n"
1255 "(rule \"after\" (constraint clearance (min 0.1mm)))\n" );
1257 BOOST_CHECK_EQUAL( ParsedDrcRuleCount( result.m_text, wxT( "downgrade_commented_rules" ) ), 2 );
1258 }
1259}
1260
1261
1262BOOST_AUTO_TEST_CASE( CommentedRuleStartsAndEndsOnItsOwnLine )
1263{
1264 const wxString rules = wxT( "(version 2)"
1265 "(rule \"first\" (constraint net_chain_length (max 1mm)))"
1266 "(rule \"kept\" (constraint clearance (min 0.2mm)))"
1267 "(rule \"last\" (constraint net_chain_length (max 1mm)))" );
1268
1269 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
1270 {
1272 BOOST_REQUIRE( result.m_error.IsEmpty() );
1273
1274 const wxString marker = wxT( "# Not supported by " ) + target.m_name + wxT( ":\n" );
1275 const wxString expected = wxT( "(version 1)\n" ) + marker
1276 + wxT( "# (rule \"first\" (constraint net_chain_length (max 1mm)))\n"
1277 "(rule \"kept\" (constraint clearance (min 0.2mm)))\n" )
1278 + marker + wxT( "# (rule \"last\" (constraint net_chain_length (max 1mm)))\n" );
1280 BOOST_CHECK_EQUAL( ParsedDrcRuleCount( result.m_text, wxT( "downgrade_glued_rules" ) ), 1 );
1281 }
1282}
1283
1284
1285BOOST_AUTO_TEST_CASE( CommentedRuleKeepsItsOwnCommentsAndLineEndings )
1286{
1287 const wxString rules = wxT( "(version 2)\r\n"
1288 " (rule \"messy\"\r\n"
1289 " # ) \" ( unmatched in a comment\r\n"
1290 " (condition \"A.NetName == 'a'\")\r\n"
1291 " (constraint net_chain_length (max 1mm)))\r\n"
1292 "(rule \"kept\" (constraint clearance (min 0.2mm)))\r\n" );
1293
1294 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
1295 {
1297 BOOST_REQUIRE( result.m_error.IsEmpty() );
1298 BOOST_REQUIRE_EQUAL( result.m_dropped.size(), 1 );
1299 BOOST_CHECK( result.m_dropped.front() == wxT( "messy" ) );
1300
1301 const wxString expected = wxT( "(version 1)\r\n # Not supported by " ) + target.m_name
1302 + wxT( ":\r\n"
1303 "# (rule \"messy\"\r\n"
1304 "# # ) \" ( unmatched in a comment\r\n"
1305 "# (condition \"A.NetName == 'a'\")\r\n"
1306 "# (constraint net_chain_length (max 1mm)))\r\n"
1307 "(rule \"kept\" (constraint clearance (min 0.2mm)))\r\n" );
1309 BOOST_CHECK_EQUAL( ParsedDrcRuleCount( result.m_text, wxT( "downgrade_crlf_rules" ) ), 1 );
1310 }
1311}
1312
1313
1314BOOST_AUTO_TEST_CASE( UnknownTopLevelBlockIsCommentedOut )
1315{
1316 const wxString rules = wxT( "(version 2)\n"
1317 "(future_block \"x\" (constraint clearance (min 1mm)))\n"
1318 "(rule \"kept\" (constraint clearance (min 0.2mm)))\n" );
1319
1320 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
1321 {
1323 BOOST_REQUIRE( result.m_error.IsEmpty() );
1324 BOOST_CHECK_EQUAL( result.m_dropped.size(), 1 );
1325 BOOST_CHECK( result.m_text.Contains( wxT( "# (future_block \"x\" (constraint clearance (min 1mm)))\n"
1326 "(rule \"kept\"" ) ) );
1327 BOOST_CHECK_EQUAL( ParsedDrcRuleCount( result.m_text, wxT( "downgrade_unknown_block" ) ), 1 );
1328 }
1329}
1330
1331
1332BOOST_AUTO_TEST_CASE( ExportedRulesFileDowngradesAgainUnchanged )
1333{
1334 const wxString rules = wxT( "(version 2)\n"
1335 "# why the chain rule exists\n"
1336 "(rule \"chain\"\n"
1337 " # ) \" (\n"
1338 " (constraint net_chain_length (max 10mm)))\n"
1339 "(rule \"after\" (constraint clearance (min 0.1mm)))"
1340 "(rule \"last\" (constraint net_chain_length (max 1mm)))\n"
1341 "# trailing note\n" );
1342
1343 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
1344 {
1345 DRC_RULES_FILTER_RESULT first = FilterDrcRulesForTarget( rules, target );
1346 BOOST_REQUIRE( first.m_error.IsEmpty() );
1347 BOOST_REQUIRE_EQUAL( first.m_dropped.size(), 2 );
1348 BOOST_CHECK( first.m_text.EndsWith( wxT( "# (rule \"last\" (constraint net_chain_length (max 1mm)))\n"
1349 "# trailing note\n" ) ) );
1350
1351 DRC_RULES_FILTER_RESULT second = FilterDrcRulesForTarget( first.m_text, target );
1352 BOOST_CHECK( second.m_error.IsEmpty() );
1353 BOOST_CHECK( second.m_dropped.empty() );
1354 BOOST_CHECK_EQUAL( second.m_text, first.m_text );
1355 }
1356}
1357
1358
1359BOOST_AUTO_TEST_CASE( DrcRuleNamesAndExpressionLiteralsDoNotTriggerDrops )
1360{
1361 const wxString rules = wxT( "(version 1)\n"
1362 "(rule \"return_path\" (constraint clearance (min 0.2mm)))\n"
1363 "(rule inNetChain (constraint clearance (min 0.2mm)))\n"
1364 "(rule \"literal\" (condition \"A.NetName == 'hasNetChain() 100 ps .Parent.'\")\n"
1365 " (constraint clearance (min 0.2mm)))\n" );
1366
1367 for( const DOWNGRADE_TARGET* target : { &kicad9, &kicad10 } )
1368 {
1370 BOOST_CHECK( result.m_error.IsEmpty() );
1371 BOOST_CHECK( result.m_dropped.empty() );
1372 BOOST_CHECK_EQUAL( result.m_text.Mid( result.m_text.Find( "(rule" ) ), rules.Mid( rules.Find( "(rule" ) ) );
1373 }
1374}
1375
1376
1377BOOST_AUTO_TEST_CASE( SpacedTimeAndAngleUnitsAreDroppedForKicad9 )
1378{
1379 const wxString rules = wxT( "(version 1)\n"
1380 "(rule \"time\" (constraint length (min \"100 ps\")))\n"
1381 "(rule \"femtoseconds\" (constraint length (max \"2 * 100 fs\")))\n"
1382 "(rule \"angle\" (constraint track_angle (max \"90 deg\")))\n"
1383 "(rule \"ordinary\" (constraint clearance (min \"0.2 mm\")))\n" );
1384
1386 BOOST_CHECK( result9.m_error.IsEmpty() );
1387 BOOST_CHECK_EQUAL( result9.m_dropped.size(), 3 );
1388 BOOST_CHECK( result9.m_text.Contains( "ordinary" ) );
1389
1391 BOOST_CHECK( result10.m_error.IsEmpty() );
1392 BOOST_CHECK( result10.m_dropped.empty() );
1393 BOOST_CHECK_EQUAL( result10.m_text.Mid( result10.m_text.Find( "(rule" ) ), rules.Mid( rules.Find( "(rule" ) ) );
1394}
1395
1396
1397// 10.0 knows the mask constraints and time units. Only post-10.0 syntax drops for it.
1398BOOST_AUTO_TEST_CASE( DrcRulesFilterForKicad10 )
1399{
1400 const wxString rules = wxT( "(version 2)\n"
1401 "(rule \"mask_check\" (constraint bridged_mask))\n"
1402 "(rule \"delay_check\" (constraint skew (max 5ps)))\n"
1403 "(rule \"chain_check\" (constraint net_chain_length (max 10mm)))\n" );
1404
1406
1407 BOOST_REQUIRE_EQUAL( result.m_dropped.size(), 1 );
1408 BOOST_CHECK_EQUAL( result.m_dropped[0], wxString( "chain_check" ) );
1409 BOOST_CHECK( result.m_text.Contains( wxT( "bridged_mask" ) ) );
1410 BOOST_CHECK( result.m_text.Contains( wxT( "5ps" ) ) );
1411}
1412
1413
1414// Comment syntax must never participate in balancing a rule. Parentheses or quotes
1415// in a full-line comment used to truncate or swallow otherwise valid rules.
1416BOOST_AUTO_TEST_CASE( DrcRulesWithCommentsRemainIntact )
1417{
1418 const wxString kept = wxT( "(rule \"clearance # literal\"\n"
1419 " # unmatched: ) (( \" \\\n"
1420 " (condition \"A.NetName == 'SIGNAL#1'\")\n"
1421 " # inNetChain('x')\n"
1422 " (constraint clearance (min 0.2mm))\n"
1423 " # ) \" (\n"
1424 ")\n"
1425 "(rule \"second\" (constraint track_width (min 0.25mm)))" );
1426 const wxString input = wxT( "(version 2)\n" ) + kept
1427 + wxT( "\n(rule \"unsupported\"\n # ) \" (\n"
1428 " (constraint net_chain_length (max 10mm)))\n" );
1429
1430 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
1431 {
1433 BOOST_REQUIRE( result.m_error.IsEmpty() );
1434 BOOST_REQUIRE_EQUAL( result.m_dropped.size(), 1 );
1435 BOOST_CHECK( result.m_dropped.front() == wxT( "unsupported" ) );
1436 BOOST_CHECK( result.m_text.Contains( kept ) );
1437
1438 DRC_RULES_PARSER parser( result.m_text, wxT( "downgrade_inline_comments" ) );
1440 std::vector<std::shared_ptr<DRC_RULE>> rules;
1441 parser.Parse( rules, &reporter );
1442 BOOST_CHECK_MESSAGE( !reporter.HasMessageOfSeverity( RPT_SEVERITY_ERROR ), reporter.GetMessages() );
1443 BOOST_REQUIRE_EQUAL( rules.size(), 2 );
1444 BOOST_CHECK( rules[0]->FindConstraint( CLEARANCE_CONSTRAINT ).has_value() );
1445 BOOST_CHECK( rules[1]->FindConstraint( TRACK_WIDTH_CONSTRAINT ).has_value() );
1446 }
1447}
1448
1449
1450BOOST_AUTO_TEST_CASE( CommentsAboveTheVersionHeaderAreKept )
1451{
1452 const wxString rules = wxT( "# project rules\n"
1453 "(version 2)\n"
1454 "(rule \"a\" (constraint clearance (min 0.2mm)))\n" );
1455
1457 BOOST_REQUIRE( result.m_error.IsEmpty() );
1458 BOOST_CHECK_EQUAL( result.m_text, wxString( "# project rules\n"
1459 "(version 1)\n"
1460 "(rule \"a\" (constraint clearance (min 0.2mm)))\n" ) );
1461 BOOST_CHECK_EQUAL( ParsedDrcRuleCount( result.m_text, wxT( "downgrade_comment_above_header" ) ), 1 );
1462}
1463
1464
1465BOOST_AUTO_TEST_CASE( MissingVersionHeaderIsWrittenOnItsOwnLine )
1466{
1467 const wxString rules = wxT( "# intro\n"
1468 "(rule \"a\" (constraint net_chain_length (max 1mm)))\n" );
1469
1471 BOOST_REQUIRE( result.m_error.IsEmpty() );
1472 BOOST_CHECK_EQUAL( result.m_text, wxString( "(version 1)\n"
1473 "# intro\n"
1474 "# Not supported by KiCad 9.0:\n"
1475 "# (rule \"a\" (constraint net_chain_length (max 1mm)))\n" ) );
1476 BOOST_CHECK_EQUAL( ParsedDrcRuleCount( result.m_text, wxT( "downgrade_missing_header" ) ), 0 );
1477}
1478
1479
1480BOOST_AUTO_TEST_CASE( HeaderGluedToTheFirstRuleStaysGlued )
1481{
1482 const wxString rules = wxT( "(version 2)(rule \"kept\" (constraint clearance (min 0.2mm)))" );
1483
1485 BOOST_REQUIRE( result.m_error.IsEmpty() );
1486 BOOST_CHECK_EQUAL( result.m_text, wxString( "(version 1)(rule \"kept\" (constraint clearance (min 0.2mm)))\n" ) );
1487 BOOST_CHECK_EQUAL( ParsedDrcRuleCount( result.m_text, wxT( "downgrade_glued_header" ) ), 1 );
1488}
1489
1490
1491BOOST_AUTO_TEST_CASE( InlineCommentBetweenRulesFailsClosed )
1492{
1493 const wxString rules = wxT( "(version 1) # note\n(rule \"a\" (constraint clearance (min 0.2mm)))\n" );
1494
1495 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
1496 BOOST_CHECK( !FilterDrcRulesForTarget( rules, target ).m_error.IsEmpty() );
1497}
1498
1499
1500BOOST_AUTO_TEST_CASE( UnitInsideAConditionIsChecked )
1501{
1502 const wxString rules = wxT( "(version 1)(rule \"c\" (condition \"A.Width > 5ps\") "
1503 "(constraint clearance (min 0.2mm)))" );
1504
1505 BOOST_CHECK_EQUAL( FilterDrcRulesForTarget( rules, kicad9 ).m_dropped.size(), 1 );
1506 BOOST_CHECK_EQUAL( FilterDrcRulesForTarget( rules, kicad10 ).m_dropped.size(), 0 );
1507}
1508
1509
1510BOOST_AUTO_TEST_CASE( TextVariableInsideACommentIsIgnored )
1511{
1512 const wxString rules = wxT( "(version 1)\n"
1513 "(rule \"a\"\n"
1514 " # see ${GAP}\n"
1515 " (constraint clearance (min 0.2mm)))\n" );
1516
1517 BOOST_CHECK( FilterDrcRulesForTarget( rules, kicad9 ).m_dropped.empty() );
1518}
1519
1520
1521BOOST_AUTO_TEST_CASE( FunctionNamesAreMatchedWithoutCase )
1522{
1523 const wxString rules = wxT( "(version 1)(rule \"f\" (condition \"A.InsideCourtyard('x')\") "
1524 "(constraint clearance (min 0.2mm)))" );
1525
1526 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
1527 BOOST_CHECK( FilterDrcRulesForTarget( rules, target ).m_dropped.empty() );
1528}
1529
1530
1531BOOST_AUTO_TEST_CASE( ComponentClassSelectorIsDroppedForEveryTarget )
1532{
1533 const wxString rules = wxT( "(version 1)(rule \"hv\" (condition \"A.memberOfFootprint('${Class:HV}')\") "
1534 "(constraint clearance (min 1mm)))" );
1535
1536 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
1537 BOOST_CHECK_EQUAL( FilterDrcRulesForTarget( rules, target ).m_dropped.size(), 1 );
1538}
1539
1540
1541BOOST_AUTO_TEST_CASE( UnquotedExpressionsAreScanned )
1542{
1543 const wxString parent = wxT( "(version 1)(rule \"x\" (condition A.Parent.Reference==B.Reference) "
1544 "(constraint clearance (min 1mm)))" );
1545 const wxString assertion = wxT( "(version 1)(rule \"x\" (constraint assertion A.Parent.Reference==B.Reference))" );
1546 const wxString plain = wxT( "(version 1)(rule \"x\" (condition A.NetClass=='HV') "
1547 "(constraint clearance (min 1mm)))" );
1548
1549 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
1550 {
1551 BOOST_CHECK_EQUAL( FilterDrcRulesForTarget( parent, target ).m_dropped.size(), 1 );
1552 BOOST_CHECK_EQUAL( FilterDrcRulesForTarget( assertion, target ).m_dropped.size(), 1 );
1553 BOOST_CHECK( FilterDrcRulesForTarget( plain, target ).m_dropped.empty() );
1554 }
1555}
1556
1557
1558BOOST_AUTO_TEST_CASE( QuotedConstraintItemsAreChecked )
1559{
1560 const wxString newItem = wxT( "(version 1)(rule \"y\" (constraint disallow \"blind_via\"))" );
1561 const wxString oldItem = wxT( "(version 1)(rule \"y\" (constraint disallow \"via\"))" );
1562 const wxString connection = wxT( "(version 1)(rule \"z\" (constraint zone_connection \"thermal_reliefs\"))" );
1563
1564 BOOST_CHECK_EQUAL( FilterDrcRulesForTarget( newItem, kicad9 ).m_dropped.size(), 1 );
1565 BOOST_CHECK( FilterDrcRulesForTarget( newItem, kicad10 ).m_dropped.empty() );
1566
1567 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
1568 {
1569 BOOST_CHECK( FilterDrcRulesForTarget( oldItem, target ).m_dropped.empty() );
1570 BOOST_CHECK( FilterDrcRulesForTarget( connection, target ).m_dropped.empty() );
1571 }
1572}
1573
1574
1575BOOST_AUTO_TEST_CASE( StringSpanningLinesFailsClosed )
1576{
1577 const wxString rules = wxT( "(version 1)\n(rule \"a\" (condition \"A.NetClass ==\n 'HV'\") "
1578 "(constraint clearance (min 0.2mm)))\n" );
1579
1580 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
1581 BOOST_CHECK( !FilterDrcRulesForTarget( rules, target ).m_error.IsEmpty() );
1582}
1583
1584
1585BOOST_AUTO_TEST_CASE( CommentBetweenParenthesisAndHeadIsKept )
1586{
1587 const wxString rules = wxT( "(version 1)\n"
1588 "(\n"
1589 "# the head comes after this comment\n"
1590 "rule \"a\" (constraint clearance (min 0.2mm)))\n"
1591 "(\n"
1592 "# so does this one\n"
1593 "rule \"b\" (constraint net_chain_length (max 1mm)))\n" );
1594
1596 BOOST_REQUIRE( result.m_error.IsEmpty() );
1597 BOOST_REQUIRE_EQUAL( result.m_dropped.size(), 1 );
1598 BOOST_CHECK_EQUAL( result.m_dropped.front(), wxString( "b" ) );
1599 BOOST_CHECK( result.m_text.Contains( wxT( "\nrule \"a\"" ) ) );
1600 BOOST_CHECK_EQUAL( ParsedDrcRuleCount( result.m_text, wxT( "downgrade_comment_before_head" ) ), 1 );
1601}
1602
1603
1604BOOST_AUTO_TEST_CASE( InvalidDrcCommentAndUnbalancedSyntaxFailClosed )
1605{
1606 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
1607 {
1608 for( const wxString& input : { wxT( "(version 1)\n(rule \"inline\" # )\n (constraint clearance (min 0.2mm)))" ),
1609 wxT( "(version 1)\n(rule \"missing_close\" (constraint clearance (min 0.2mm))" ),
1610 wxT( "(version 1)\n(rule \"missing_quote" ) } )
1611 {
1612 BOOST_CHECK( !FilterDrcRulesForTarget( input, target ).m_error.IsEmpty() );
1613 }
1614 }
1615}
1616
1617
1618BOOST_AUTO_TEST_CASE( DrcRulesMatchIndependentOlderReferences )
1619{
1620 const std::string fixture = KI_TEST::GetPcbnewTestDataDir() + "../downgrade/golden/";
1621 const wxString input = wxString::FromUTF8( KI_TEST::ReadGoldenText( fixture + "current/rules.kicad_dru" ) );
1622
1623 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
1624 {
1626 BOOST_REQUIRE( result.m_error.IsEmpty() );
1627 const std::string release = target.m_id == wxT( "9.0" ) ? "v9" : "v10";
1628 BOOST_CHECK_EQUAL( result.m_text.ToStdString(),
1629 KI_TEST::ReadGoldenText( fixture + release + "/rules.kicad_dru" ) );
1630 BOOST_CHECK_EQUAL( result.m_dropped.size(), release == "v9" ? 2 : 1 );
1631 BOOST_CHECK_EQUAL( ParsedDrcRuleCount( result.m_text, wxT( "downgrade_drc_golden" ) ),
1632 release == "v9" ? 1 : 2 );
1633 }
1634}
1635
1636
1637// Flattening bakes the chosen variant's overrides into the base attributes, so the exported
1638// board matches that variant after the registry is dropped.
1639BOOST_AUTO_TEST_CASE( VariantFlattenedIntoBoard )
1640{
1641 BOARD board;
1642 FOOTPRINT* fp = new FOOTPRINT( &board );
1643 fp->SetDNP( false );
1644
1645 FOOTPRINT_VARIANT* variant = fp->AddVariant( wxT( "V1" ) );
1646 variant->SetDNP( true );
1647 variant->SetFieldValue( wxT( "Value" ), wxT( "10k" ) );
1648 board.Add( fp );
1649
1650 FlattenBoardVariant( &board, wxT( "V1" ) );
1651
1652 BOOST_CHECK( fp->IsDNP() );
1653 BOOST_REQUIRE( fp->GetField( wxT( "Value" ) ) != nullptr );
1654 BOOST_CHECK( fp->GetField( wxT( "Value" ) )->GetText() == wxT( "10k" ) );
1655}
1656
1657
1658// The project file is migrated down: newer settings are removed, nested schema versions are
1659// rewound, and meaningful losses are reported.
1660BOOST_AUTO_TEST_CASE( ProjectFileDowngradeForKicad9 )
1661{
1662 nlohmann::json doc = {
1663 { "meta", { { "filename", "p.kicad_pro" }, { "version", 3 } } },
1664 { "board", { { "layer_presets", { { { "name", "P" }, { "renderLayers", { "tracks", "vias" } } } } } } },
1665 { "net_settings",
1666 { { "meta", { { "version", 5 } } },
1667 { "classes", { { { "name", "Default" }, { "priority", 0 }, { "tuning_profile", "tp" } } } },
1668 { "net_chain_classes", { { { "name", "chainA" } } } } } },
1669 { "tuning_profiles",
1670 { { "meta", { { "version", 1 } } },
1671 { "tuning_profiles_impedance_geometric",
1672 { { { "name", "tp" }, { "frequency", 1e9 }, { "model_solder_mask", false } } } } } },
1673 { "component_class_settings", { { "meta", { { "version", 0 } } } } },
1674 { "schematic",
1675 { { "top_level_sheets", { "aaaa" } },
1676 { "bus_aliases", nlohmann::json::array() },
1677 { "variants", nlohmann::json::array() } } },
1678 };
1679
1680 COMPATIBILITY_REPORT report;
1681 DowngradeProjectFileJson( doc, kicad9, report );
1682
1683 // 9.0 shipped project schema 3 and reads render layers by name, skipping names it does
1684 // not know. So the version and the preset strings must pass through untouched.
1685 BOOST_CHECK_EQUAL( doc["meta"]["version"].get<int>(), 3 );
1686
1687 const nlohmann::json& preset = doc["board"]["layer_presets"][0];
1688 BOOST_REQUIRE( preset["renderLayers"].is_array() );
1689 BOOST_REQUIRE_EQUAL( preset["renderLayers"].size(), 2 );
1690 BOOST_CHECK_EQUAL( preset["renderLayers"][0].get<std::string>(), "tracks" );
1691 BOOST_CHECK_EQUAL( preset["renderLayers"][1].get<std::string>(), "vias" );
1692
1693 BOOST_CHECK_EQUAL( doc["net_settings"]["meta"]["version"].get<int>(), 4 );
1694 BOOST_CHECK( !doc["net_settings"]["classes"][0].contains( "tuning_profile" ) );
1695 BOOST_CHECK( doc["net_settings"]["classes"][0].contains( "name" ) );
1696 BOOST_CHECK( !doc["net_settings"].contains( "net_chain_classes" ) );
1697 BOOST_CHECK( !doc.contains( "tuning_profiles" ) );
1698 BOOST_CHECK( !doc.contains( "component_class_settings" ) );
1699 BOOST_CHECK( !doc["schematic"].contains( "top_level_sheets" ) );
1700 BOOST_CHECK( !doc["schematic"].contains( "bus_aliases" ) );
1701 BOOST_CHECK( !doc["schematic"].contains( "variants" ) );
1702
1703 // The meaningful losses show in the report. Hygiene removals stay silent.
1704 BOOST_CHECK( report.IsLossy() );
1706}
1707
1708
1709BOOST_AUTO_TEST_CASE( EmptyNativeProjectSectionsDoNotRequireConsent )
1710{
1711 const nlohmann::json empty = nlohmann::json::array();
1712 const std::vector<nlohmann::json> tuningDefaults = {
1713 nullptr,
1714 nlohmann::json::object(),
1715 { { "meta", { { "version", 2 } } } },
1716 { { "meta", { { "version", 2 } } }, { "tuning_profiles_impedance_geometric", empty } },
1717 };
1718 const std::vector<nlohmann::json> componentDefaults = {
1719 nullptr,
1720 nlohmann::json::object(),
1721 { { "meta", { { "version", 0 } } } },
1722 { { "assignments", empty }, { "sheet_component_classes", nlohmann::json::object() } },
1723 { { "meta", { { "version", 0 } } },
1724 { "assignments", empty },
1725 { "sheet_component_classes", { { "enabled", false } } } },
1726 };
1727
1728 for( const auto& target : { kicad9, kicad10 } )
1729 {
1730 for( const auto& tuning : tuningDefaults )
1731 {
1732 for( const auto& components : componentDefaults )
1733 {
1734 nlohmann::json doc = {
1735 { "meta", { { "version", 4 } } },
1736 { "board", { { "design_settings", { { "meta", { { "version", 3 } } } } } } },
1737 { "erc", { { "meta", { { "version", 1 } } }, { "erc_exclusions", empty } } },
1738 { "net_settings",
1739 { { "meta", { { "version", 5 } } },
1740 { "classes", { { { "name", "Default" }, { "tuning_profile", "" } } } } } },
1741 { "tuning_profiles", tuning },
1742 { "component_class_settings", components },
1743 };
1744
1745 COMPATIBILITY_REPORT report;
1746 DowngradeProjectFileJson( doc, target, report );
1747
1748 BOOST_CHECK( !report.IsBlocked() );
1749 BOOST_CHECK( !report.IsLossy() );
1751 BOOST_CHECK_EQUAL( doc["meta"]["version"].get<int>(), 3 );
1752 BOOST_CHECK_EQUAL( doc["board"]["design_settings"]["meta"]["version"].get<int>(), 2 );
1753 BOOST_CHECK_EQUAL( doc["erc"]["meta"]["version"].get<int>(), 0 );
1754 BOOST_CHECK_EQUAL( doc.contains( "tuning_profiles" ), target.m_id == wxT( "10.0" ) );
1755 BOOST_CHECK_EQUAL( doc.contains( "component_class_settings" ), target.m_id == wxT( "10.0" ) );
1756
1757 const nlohmann::json once = doc;
1758 COMPATIBILITY_REPORT repeated;
1759 DowngradeProjectFileJson( doc, target, repeated );
1760 BOOST_CHECK( doc == once );
1761 BOOST_CHECK( !repeated.IsLossy() );
1762 }
1763 }
1764 }
1765}
1766
1767
1768BOOST_AUTO_TEST_CASE( SavedProjectTuningAndClassChoicesStillRequireConsent )
1769{
1770 const nlohmann::json empty = nlohmann::json::array();
1771 const nlohmann::json profile = {
1772 { "profile_name", "Default" },
1773 { "frequency", 1e9 },
1774 { "model_solder_mask", false },
1775 { "net_chain_bridge_prop_delay", 0 },
1776 };
1777 const std::vector<nlohmann::json> meaningful = {
1778 { { "tuning_profiles", { { "tuning_profiles_impedance_geometric", { profile } } } } },
1779 { { "net_settings", { { "classes", { { { "tuning_profile", "Saved" } } } } } } },
1780 { { "tuning_profiles", { { "tuning_profiles_impedance_geometric", empty } } },
1781 { "net_settings", { { "classes", { { { "tuning_profile", "Saved" } } } } } } },
1782 { { "tuning_profiles", { { "tuning_profiles_impedance_geometric", { profile } } } },
1783 { "net_settings",
1784 { { "classes", { { { "tuning_profile", "Default" } }, { { "tuning_profile", "Default" } } } } } } },
1785 { { "component_class_settings",
1786 { { "assignments",
1787 { { { "component_class", "Fast" }, { "conditions_operator", "ALL" }, { "conditions", empty } } } },
1788 { "sheet_component_classes", { { "enabled", false } } } } } },
1789 { { "component_class_settings",
1790 { { "assignments", empty }, { "sheet_component_classes", { { "enabled", true } } } } } },
1791 };
1792
1793 for( const auto& source : meaningful )
1794 {
1795 for( const auto& target : { kicad9, kicad10 } )
1796 {
1797 nlohmann::json doc = source;
1798 COMPATIBILITY_REPORT report;
1799 DowngradeProjectFileJson( doc, target, report );
1800 BOOST_CHECK( !report.IsBlocked() );
1801 BOOST_CHECK_EQUAL( report.Count( DOWNGRADE_BUCKET::DROP ), target.m_id == wxT( "9.0" ) ? 1 : 0 );
1802 BOOST_CHECK_EQUAL( report.IsLossy(), target.m_id == wxT( "9.0" ) );
1803
1804 const nlohmann::json once = doc;
1805 COMPATIBILITY_REPORT repeated;
1806 DowngradeProjectFileJson( doc, target, repeated );
1807 BOOST_CHECK( doc == once );
1808 BOOST_CHECK( !repeated.IsLossy() );
1809 }
1810 }
1811}
1812
1813
1814BOOST_AUTO_TEST_CASE( FutureComponentClassSchemaBlocksWithoutMutation )
1815{
1816 const nlohmann::json source = {
1817 { "meta", { { "version", 4 } } },
1818 { "component_class_settings", { { "meta", { { "version", 1 } } } } },
1819 };
1820
1821 for( const auto& target : { kicad9, kicad10 } )
1822 {
1823 nlohmann::json doc = source;
1824 COMPATIBILITY_REPORT report;
1825 DowngradeProjectFileJson( doc, target, report );
1826 BOOST_CHECK( report.IsBlocked() );
1827 BOOST_CHECK( doc == source );
1828 }
1829}
1830
1831
1832// A structurally odd but valid-JSON project file must not throw. Classification swallows
1833// exceptions, so a throw here would surface only mid-export and break fail-closed.
1834BOOST_AUTO_TEST_CASE( WrongShapeProjectFileDoesNotThrow )
1835{
1836 nlohmann::json metaIsString = {
1837 { "meta", "not an object" },
1838 { "net_settings", { { "meta", "also a string" }, { "classes", "not an array" } } },
1839 { "schematic", "a string" },
1840 };
1841
1842 nlohmann::json profilesWrong = {
1843 { "tuning_profiles",
1844 { { "meta", 7 }, { "tuning_profiles_impedance_geometric", { "just", "strings" } } } },
1845 };
1846
1847 COMPATIBILITY_REPORT report;
1848 BOOST_CHECK_NO_THROW( DowngradeProjectFileJson( metaIsString, kicad9, report ) );
1849 BOOST_CHECK_NO_THROW( DowngradeProjectFileJson( profilesWrong, kicad10, report ) );
1850}
1851
1852
1853// An empty net chain class array is removed as hygiene, not reported as a loss.
1854BOOST_AUTO_TEST_CASE( EmptyNetChainClassesSilent )
1855{
1856 nlohmann::json doc = {
1857 { "net_settings", { { "net_chain_classes", nlohmann::json::array() } } },
1858 };
1859
1860 COMPATIBILITY_REPORT report;
1861 DowngradeProjectFileJson( doc, kicad10, report );
1862
1863 BOOST_CHECK( !doc["net_settings"].contains( "net_chain_classes" ) );
1865}
1866
1867
1868BOOST_AUTO_TEST_CASE( NonDefaultTuningModelSettingsAreReportedForKicad10 )
1869{
1870 nlohmann::json doc = {
1871 { "tuning_profiles",
1872 { { "meta", { { "version", 1 } } },
1873 { "tuning_profiles_impedance_geometric",
1874 { { { "profile_name", "5 GHz" }, { "frequency", 5e9 }, { "model_solder_mask", true } },
1875 { { "profile_name", "Default" }, { "frequency", 1e9 }, { "model_solder_mask", false } } } } } }
1876 };
1877
1878 COMPATIBILITY_REPORT report;
1879 DowngradeProjectFileJson( doc, kicad10, report );
1880 BOOST_CHECK( report.IsLossy() );
1882
1883 for( const auto& profile : doc["tuning_profiles"]["tuning_profiles_impedance_geometric"] )
1884 {
1885 BOOST_CHECK( !profile.contains( "frequency" ) );
1886 BOOST_CHECK( !profile.contains( "model_solder_mask" ) );
1887 }
1888
1889 COMPATIBILITY_REPORT secondReport;
1890 DowngradeProjectFileJson( doc, kicad10, secondReport );
1891 BOOST_CHECK( !secondReport.IsLossy() );
1892}
1893
1894
1895BOOST_AUTO_TEST_CASE( ProjectFileDowngradeForKicad10 )
1896{
1897 nlohmann::json doc = {
1898 { "meta", { { "version", 3 } } },
1899 { "net_settings",
1900 { { "meta", { { "version", 5 } } },
1901 { "classes", { { { "name", "Default" }, { "priority", 0 }, { "tuning_profile", "tp" } } } },
1902 { "net_chain_classes", { { { "name", "chainA" } } } } } },
1903 { "tuning_profiles",
1904 { { "meta", { { "version", 1 } } },
1905 { "tuning_profiles_impedance_geometric",
1906 { { { "name", "tp" }, { "frequency", 1e9 }, { "model_solder_mask", false } } } } } },
1907 };
1908
1909 COMPATIBILITY_REPORT report;
1910 DowngradeProjectFileJson( doc, kicad10, report );
1911
1912 // 10.0 knows tuning profiles and reads the per-class reference unguarded, so both stay.
1913 BOOST_CHECK_EQUAL( doc["meta"]["version"].get<int>(), 3 );
1914 BOOST_CHECK_EQUAL( doc["net_settings"]["meta"]["version"].get<int>(), 5 );
1915 BOOST_CHECK( doc["net_settings"]["classes"][0].contains( "tuning_profile" ) );
1916 BOOST_CHECK( !doc["net_settings"].contains( "net_chain_classes" ) );
1917
1918 BOOST_CHECK_EQUAL( doc["tuning_profiles"]["meta"]["version"].get<int>(), 0 );
1919 BOOST_CHECK( !doc["tuning_profiles"]["tuning_profiles_impedance_geometric"][0].contains( "frequency" ) );
1920 BOOST_CHECK( !doc["tuning_profiles"]["tuning_profiles_impedance_geometric"][0].contains( "model_solder_mask" ) );
1921
1923}
1924
1925
1926// A near-closed thick elliptical arc strokes to a ring. The writers save one outline per
1927// shape, so the lowered polygon must carry no holes.
1928BOOST_AUTO_TEST_CASE( EllipseArcRingHasNoHoles )
1929{
1930 BOARD board;
1931 PCB_SHAPE* arc = new PCB_SHAPE( &board, SHAPE_T::ELLIPSE_ARC );
1932 arc->SetEllipseCenter( VECTOR2I( 0, 0 ) );
1933 arc->SetEllipseMajorRadius( pcbIUScale.mmToIU( 5 ) );
1934 arc->SetEllipseMinorRadius( pcbIUScale.mmToIU( 3 ) );
1937 arc->SetWidth( pcbIUScale.mmToIU( 0.3 ) );
1938 board.Add( arc );
1939
1940 DowngradeBoardInPlace( &board, kicad10 );
1941
1943
1944 SHAPE_POLY_SET& poly = arc->GetPolyShape();
1945
1946 for( int ii = 0; ii < poly.OutlineCount(); ++ii )
1947 BOOST_CHECK_EQUAL( poly.HoleCount( ii ), 0 );
1948
1949 // The ring's ink, nowhere near the filled disk's 47 square mm.
1950 double areaMM = std::abs( poly.Area() ) / ( pcbIUScale.IU_PER_MM * pcbIUScale.IU_PER_MM );
1951
1952 BOOST_CHECK_GT( areaMM, 4.0 );
1953 BOOST_CHECK_LT( areaMM, 15.0 );
1954}
1955
1956
1957// The scale compensation must reach images inside footprints on the board.
1958BOOST_AUTO_TEST_CASE( FootprintImageScaleCompensatedOnBoard )
1959{
1960 BOARD board;
1961 FOOTPRINT* fp = new FOOTPRINT( &board );
1963 REFERENCE_IMAGE& ref = image->GetReferenceImage();
1964
1965 wxMemoryBuffer buf = KI_TEST::MakePngWithFractionalPixelsPerCm();
1966 BOOST_REQUIRE( ref.ReadImageFile( buf ) );
1967 ref.SetImageScale( 2.0 );
1968 fp->Add( image );
1969 board.Add( fp );
1970
1971 int ppi = ref.GetImage().GetPPI();
1972 int legacyPPI = ref.GetImage().GetLegacyPPI();
1973 BOOST_REQUIRE( legacyPPI > 0 && ppi != legacyPPI );
1974
1975 DowngradeBoardInPlace( &board, kicad9 );
1976
1977 BOOST_CHECK_CLOSE( ref.GetImageScale(), 2.0 * legacyPPI / ppi, 0.1 );
1978}
1979
1980
1981// A library footprint goes through the footprint-scoped path and gets the same compensation.
1982BOOST_AUTO_TEST_CASE( FootprintImageScaleCompensatedInLibrary )
1983{
1984 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>( nullptr );
1986 REFERENCE_IMAGE& ref = image->GetReferenceImage();
1987
1988 wxMemoryBuffer buf = KI_TEST::MakePngWithFractionalPixelsPerCm();
1989 BOOST_REQUIRE( ref.ReadImageFile( buf ) );
1990 ref.SetImageScale( 2.0 );
1991 fp->Add( image );
1992
1993 int ppi = ref.GetImage().GetPPI();
1994 int legacyPPI = ref.GetImage().GetLegacyPPI();
1995 BOOST_REQUIRE( legacyPPI > 0 && ppi != legacyPPI );
1996
1997 DowngradeFootprintInPlace( fp.get(), kicad9 );
1998
1999 BOOST_CHECK_CLOSE( ref.GetImageScale(), 2.0 * legacyPPI / ppi, 0.1 );
2000}
2001
2002
2003// The duplicate-pad-numbers jumper flag is jumper data too, so 9.0 must drop and report it.
2004BOOST_AUTO_TEST_CASE( DuplicatePadJumperFlagDroppedForKicad9 )
2005{
2006 BOARD board;
2007 FOOTPRINT* fp = new FOOTPRINT( &board );
2009 board.Add( fp );
2010
2012
2013 DowngradeBoardInPlace( &board, kicad9 );
2014
2016}
2017
2018
2019// Downgrading a library file must not clip zone layers to a scratch board's layer set. The
2020// source file is its own oracle: the layer set must survive the round trip unchanged.
2021BOOST_AUTO_TEST_CASE( FootprintFileKeepsZoneLayers )
2022{
2023 SETTINGS_MANAGER settingsManager;
2024
2025 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_fp_zone_layers", "" );
2026 const wxString src = ( tmp.Path() / "src.kicad_mod" ).wstring();
2027 const wxString dest = ( tmp.Path() / "out.kicad_mod" ).wstring();
2028
2029 {
2030 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>( nullptr );
2031 ZONE* zone = new ZONE( fp.get() );
2032
2033 zone->SetLayerSet( LSET::AllCuMask() );
2034 zone->Outline()->NewOutline();
2035 zone->Outline()->Append( 0, 0 );
2036 zone->Outline()->Append( pcbIUScale.mmToIU( 1 ), 0 );
2037 zone->Outline()->Append( pcbIUScale.mmToIU( 1 ), pcbIUScale.mmToIU( 1 ) );
2038 zone->Outline()->Append( 0, pcbIUScale.mmToIU( 1 ) );
2039 fp->Add( zone );
2040
2041 SaveFootprintForTarget( fp.get(), src, kicad10 );
2042 }
2043
2045
2046 PCB_IO_KICAD_SEXPR reader;
2047 wxString nameOut;
2048 std::unique_ptr<FOOTPRINT> srcAgain( reader.ImportFootprint( src, nameOut ) );
2049 std::unique_ptr<FOOTPRINT> converted( reader.ImportFootprint( dest, nameOut ) );
2050
2051 BOOST_REQUIRE( srcAgain && converted );
2052 BOOST_REQUIRE_EQUAL( srcAgain->Zones().size(), 1 );
2053 BOOST_REQUIRE_EQUAL( converted->Zones().size(), 1 );
2054
2055 BOOST_CHECK_EQUAL( converted->Zones()[0]->GetLayerSet().count(), srcAgain->Zones()[0]->GetLayerSet().count() );
2056}
2057
2058
2059// The staged library downgrade converts and verifies every file before any original is
2060// replaced, and a refusal leaves the folder untouched with no temp files behind.
2061BOOST_AUTO_TEST_CASE( LibraryFilesDowngradeFailsClosed )
2062{
2063 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_lib_staged", "" );
2064 const wxString dir = tmp.Path().wstring();
2065
2066 auto writeFile = [&]( const wxString& aName, const wxString& aContent )
2067 {
2068 wxFFile file( dir + wxFileName::GetPathSeparator() + aName, wxT( "wb" ) );
2069 BOOST_REQUIRE( file.IsOpened() );
2070 file.Write( aContent );
2071 };
2072
2073 writeFile( wxT( "a.fake_mod" ), wxT( "old a" ) );
2074 writeFile( wxT( "b.fake_mod" ), wxT( "old b" ) );
2075
2076 auto noForbidden = []( const wxString& )
2077 {
2078 return wxString();
2079 };
2080
2081 auto convertOk = [&]( const wxString& aFile, const wxString& aTmp ) -> DOWNGRADE_FILE_RESULT
2082 {
2083 wxFFile out( aTmp, wxT( "wb" ) );
2084 out.Write( wxT( "(version 123) converted" ) );
2086 };
2087
2088 BOOST_CHECK( DowngradeLibraryFilesInPlace( dir, wxT( "*.fake_mod" ), 123, noForbidden, convertOk ).IsEmpty() );
2089
2090 wxFFile check( dir + wxFileName::GetPathSeparator() + wxT( "a.fake_mod" ), wxT( "rb" ) );
2091 wxString content;
2092 BOOST_REQUIRE( check.IsOpened() && check.ReadAll( &content ) );
2093 BOOST_CHECK( content.Contains( wxT( "converted" ) ) );
2094
2095 // Second pass: the second file refuses, so the first must stay as it is now.
2096 auto convertRefuseB = [&]( const wxString& aFile, const wxString& aTmp ) -> DOWNGRADE_FILE_RESULT
2097 {
2098 if( aFile.Contains( wxT( "b.fake_mod" ) ) )
2100
2101 wxFFile out( aTmp, wxT( "wb" ) );
2102 out.Write( wxT( "(version 123) second pass" ) );
2104 };
2105
2106 wxString bad = DowngradeLibraryFilesInPlace( dir, wxT( "*.fake_mod" ), 123, noForbidden, convertRefuseB );
2107 BOOST_CHECK( bad.Contains( wxT( "b.fake_mod" ) ) );
2108
2109 wxArrayString leftovers;
2110 wxDir::GetAllFiles( dir, &leftovers );
2111 BOOST_CHECK_EQUAL( leftovers.size(), 2 );
2112
2113 wxFFile recheck( dir + wxFileName::GetPathSeparator() + wxT( "a.fake_mod" ), wxT( "rb" ) );
2114 wxString unchanged;
2115 BOOST_REQUIRE( recheck.IsOpened() && recheck.ReadAll( &unchanged ) );
2116 BOOST_CHECK( !unchanged.Contains( wxT( "second pass" ) ) );
2117}
2118
2119
2120// The project export carries design files only. UI state and non-KiCad files stay behind.
2121BOOST_AUTO_TEST_CASE( DesignFileFilter )
2122{
2123 BOOST_CHECK( IsDowngradeDesignFile( wxT( "proj/proj.kicad_pro" ) ) );
2124 BOOST_CHECK( IsDowngradeDesignFile( wxT( "proj/sub/sheet.kicad_sch" ) ) );
2125 BOOST_CHECK( IsDowngradeDesignFile( wxT( "proj/proj.kicad_pcb" ) ) );
2126 BOOST_CHECK( IsDowngradeDesignFile( wxT( "proj/proj.kicad_dru" ) ) );
2127 BOOST_CHECK( IsDowngradeDesignFile( wxT( "proj/frame.kicad_wks" ) ) );
2128 BOOST_CHECK( IsDowngradeDesignFile( wxT( "proj/lib.kicad_sym" ) ) );
2129 BOOST_CHECK( IsDowngradeDesignFile( wxT( "proj/lib.pretty/fp.kicad_mod" ) ) );
2130 BOOST_CHECK( IsDowngradeDesignFile( wxT( "proj/sym-lib-table" ) ) );
2131 BOOST_CHECK( IsDowngradeDesignFile( wxT( "proj/fp-lib-table" ) ) );
2132
2133 BOOST_CHECK( !IsDowngradeDesignFile( wxT( "proj/proj.kicad_prl" ) ) );
2134 BOOST_CHECK( !IsDowngradeDesignFile( wxT( "proj/datasheet.pdf" ) ) );
2135 BOOST_CHECK( !IsDowngradeDesignFile( wxT( "proj/out/proj-F_Cu.gbr" ) ) );
2136 BOOST_CHECK( !IsDowngradeDesignFile( wxT( "proj/proj.kicad_jobset" ) ) );
2137 BOOST_CHECK( !IsDowngradeDesignFile( wxT( "proj/notes.txt" ) ) );
2138}
2139
2140
2141// When this fails a format bump happened. Review the new keywords, update the denylist, then bump
2142// BoardDowngradeCoveredVersion.
2147
2148
2149// When this fails the footprint library format moved. Review what it added inside (footprint ...),
2150// then bump FootprintLibDowngradeCoveredVersion.
2155
2156
2157// Every graphical LOWER rule has an omission path, both on boards and in footprints.
2158BOOST_AUTO_TEST_CASE( DropApproximationsOmitsGraphicsWithoutReplacements )
2159{
2160 for( bool footprintOnly : { false, true } )
2161 {
2162 BOARD board;
2163 FOOTPRINT* fp = new FOOTPRINT( &board );
2164 board.Add( fp );
2165 BOARD_ITEM_CONTAINER* parent = footprintOnly ? static_cast<BOARD_ITEM_CONTAINER*>( fp ) : &board;
2166 PCB_GROUP* group = new PCB_GROUP( parent );
2167 parent->Add( group );
2168
2170 {
2171 PCB_SHAPE* shape = new PCB_SHAPE( parent, type );
2172 if( type == SHAPE_T::RECTANGLE )
2173 {
2174 shape->SetEnd( VECTOR2I( pcbIUScale.mmToIU( 10 ), pcbIUScale.mmToIU( 6 ) ) );
2175 shape->SetCornerRadius( pcbIUScale.mmToIU( 1 ) );
2176 }
2177 parent->Add( shape );
2178 group->AddItem( shape );
2179 }
2180
2181 PCB_BARCODE* barcode = new PCB_BARCODE( parent );
2182 parent->Add( barcode );
2183 group->AddItem( barcode );
2184 PCB_TEXTBOX* textbox = new PCB_TEXTBOX( parent );
2185 textbox->SetIsKnockout( true );
2186 textbox->SetText( wxT( "Do not retain as plain text" ) );
2187 parent->Add( textbox );
2188 group->AddItem( textbox );
2189
2190 PCB_SHAPE* supported = new PCB_SHAPE( parent, SHAPE_T::CIRCLE );
2191 parent->Add( supported );
2192 group->AddItem( supported );
2193 const KIID supportedUuid = supported->m_Uuid;
2194 const DOWNGRADE_TARGET& target = kicad9;
2195 auto normal = ClassifyBoardForDowngrade( &board, target );
2196 auto omit = ClassifyBoardForDowngrade( &board, target, true );
2198 BOOST_CHECK_EQUAL( omit.Count( DOWNGRADE_BUCKET::LOWER ), 0 );
2199 BOOST_CHECK_EQUAL( omit.Count( DOWNGRADE_BUCKET::DROP ), 5 );
2200 BOOST_REQUIRE_EQUAL( normal.Entries().size(), omit.Entries().size() );
2201 for( size_t i = 0; i < normal.Entries().size(); ++i )
2202 {
2203 BOOST_CHECK( normal.Entries()[i].m_feature == omit.Entries()[i].m_feature );
2204 BOOST_CHECK_EQUAL( normal.Entries()[i].m_count, omit.Entries()[i].m_count );
2205 BOOST_CHECK( normal.Entries()[i].m_detail != omit.Entries()[i].m_detail );
2206 BOOST_CHECK( !omit.Entries()[i].m_detail.IsEmpty() );
2207 }
2208
2209 // Classification is read-only.
2210 BOOST_CHECK_EQUAL( group->GetItems().size(), 6 );
2211 if( footprintOnly )
2212 DowngradeFootprintInPlace( fp, target, true );
2213 else
2214 DowngradeBoardInPlace( &board, target, true );
2215 BOOST_REQUIRE_EQUAL( group->GetItems().size(), 1 );
2216 BOOST_CHECK( *group->GetItems().begin() == supported );
2217 BOOST_CHECK( supported->m_Uuid == supportedUuid );
2218 BOOST_CHECK( !ClassifyBoardForDowngrade( &board, target, true ).IsLossy() );
2219 }
2220}
2221
2222
2223BOOST_AUTO_TEST_CASE( DropApproximationsOmitsFillAndCellContentsOnly )
2224{
2225 BOARD board;
2226 FOOTPRINT* fp = new FOOTPRINT( &board );
2227 board.Add( fp );
2228 for( BOARD_ITEM_CONTAINER* parent :
2229 { static_cast<BOARD_ITEM_CONTAINER*>( &board ), static_cast<BOARD_ITEM_CONTAINER*>( fp ) } )
2230 {
2231 PCB_SHAPE* hatch = new PCB_SHAPE( parent, SHAPE_T::RECTANGLE );
2232 hatch->SetLayer( F_SilkS );
2233 hatch->SetFillMode( FILL_T::HATCH );
2234 parent->Add( hatch );
2235 PCB_TABLE* table = new PCB_TABLE( parent, pcbIUScale.mmToIU( 0.1 ) );
2236 table->SetColCount( 2 );
2237 PCB_TABLECELL* knockout = new PCB_TABLECELL( table );
2238 knockout->SetIsKnockout( true );
2239 knockout->SetText( wxT( "knockout" ) );
2240 table->AddCell( knockout );
2241 PCB_TABLECELL* plain = new PCB_TABLECELL( table );
2242 plain->SetText( wxT( "supported" ) );
2243 table->AddCell( plain );
2244 parent->Add( table );
2245
2246 if( parent == fp )
2247 DowngradeFootprintInPlace( fp, kicad9, true );
2248 else
2249 DowngradeBoardInPlace( &board, kicad9, true );
2252 BOOST_REQUIRE_EQUAL( table->GetCells().size(), 2 );
2253 BOOST_CHECK( knockout->GetText().IsEmpty() );
2254 BOOST_CHECK( !knockout->IsKnockout() );
2255 BOOST_CHECK( plain->GetText() == wxT( "supported" ) );
2256 }
2257}
2258
2259
2260// Removing a hatch fill on a copper layer would delete copper, and the omission preference is
2261// not an electrical override. Copper keeps a solid fill under both policies. Other layers carry
2262// ink, so there the fill may go.
2263// The report must name the copper case separately. One combined row would label the copper
2264// approximation a drop as soon as the omission preference is set, and hide how many of the
2265// counted shapes are copper.
2266BOOST_AUTO_TEST_CASE( HatchedCopperAndInkFillsAreReportedSeparately )
2267{
2268 BOARD board;
2269
2270 for( int ii = 0; ii < 3; ++ii )
2271 {
2272 PCB_SHAPE* ink = new PCB_SHAPE( &board, SHAPE_T::RECTANGLE );
2273 ink->SetLayer( F_SilkS );
2274 ink->SetFillMode( FILL_T::HATCH );
2275 board.Add( ink );
2276 }
2277
2278 PCB_SHAPE* copper = new PCB_SHAPE( &board, SHAPE_T::RECTANGLE );
2279 copper->SetLayer( F_Cu );
2280 copper->SetFillMode( FILL_T::HATCH );
2281 board.Add( copper );
2282
2283 for( bool drop : { false, true } )
2284 {
2285 BOOST_TEST_CONTEXT( "Drop approximations: " << drop )
2286 {
2287 COMPATIBILITY_REPORT report = ClassifyBoardForDowngrade( &board, kicad9, drop );
2288
2289 BOOST_CHECK_EQUAL( report.Entries().size(), 2 );
2290 BOOST_CHECK_EQUAL( report.Count( DOWNGRADE_BUCKET::LOWER ), drop ? 1 : 4 );
2291 BOOST_CHECK_EQUAL( report.Count( DOWNGRADE_BUCKET::DROP ), drop ? 3 : 0 );
2292 }
2293 }
2294}
2295
2296
2297BOOST_AUTO_TEST_CASE( DropApproximationsKeepsHatchedCopperAsSolidFill )
2298{
2299 for( bool drop : { false, true } )
2300 {
2301 BOOST_TEST_CONTEXT( "Drop approximations: " << drop )
2302 {
2303 BOARD board;
2304 FOOTPRINT* fp = new FOOTPRINT( &board );
2305 board.Add( fp );
2306
2307 std::vector<PCB_SHAPE*> copper;
2308 std::vector<PCB_SHAPE*> silk;
2309
2310 for( BOARD_ITEM_CONTAINER* parent : { static_cast<BOARD_ITEM_CONTAINER*>( &board ),
2311 static_cast<BOARD_ITEM_CONTAINER*>( fp ) } )
2312 {
2313 PCB_SHAPE* onCopper = new PCB_SHAPE( parent, SHAPE_T::RECTANGLE );
2314 onCopper->SetLayer( F_Cu );
2315 onCopper->SetFillMode( FILL_T::HATCH );
2316 parent->Add( onCopper );
2317 copper.push_back( onCopper );
2318
2319 PCB_SHAPE* onSilk = new PCB_SHAPE( parent, SHAPE_T::RECTANGLE );
2320 onSilk->SetLayer( F_SilkS );
2321 onSilk->SetFillMode( FILL_T::HATCH );
2322 parent->Add( onSilk );
2323 silk.push_back( onSilk );
2324 }
2325
2326 DowngradeBoardInPlace( &board, kicad9, drop );
2327
2328 for( PCB_SHAPE* shape : copper )
2329 BOOST_CHECK( shape->GetFillMode() == FILL_T::FILLED_SHAPE );
2330
2331 for( PCB_SHAPE* shape : silk )
2332 BOOST_CHECK( shape->GetFillMode() == ( drop ? FILL_T::NO_FILL : FILL_T::FILLED_SHAPE ) );
2333 }
2334 }
2335}
2336
2337
2338BOOST_AUTO_TEST_CASE( DropApproximationsOmitsRoundedPadPrimitives )
2339{
2340 for( bool footprintOnly : { false, true } )
2341 {
2342 BOARD board;
2343 FOOTPRINT* fp = new FOOTPRINT( &board );
2344 board.Add( fp );
2345 PAD* pad = new PAD( fp );
2346 fp->Add( pad );
2347 pad->SetShape( F_Cu, PAD_SHAPE::CUSTOM );
2348 PCB_SHAPE* rounded = new PCB_SHAPE( fp, SHAPE_T::RECTANGLE );
2349 rounded->SetEnd( VECTOR2I( pcbIUScale.mmToIU( 10 ), pcbIUScale.mmToIU( 6 ) ) );
2350 rounded->SetCornerRadius( pcbIUScale.mmToIU( 1 ) );
2351 pad->AddPrimitive( F_Cu, rounded );
2352 PCB_SHAPE* supported = new PCB_SHAPE( fp, SHAPE_T::CIRCLE );
2353 pad->AddPrimitive( F_Cu, supported );
2354 const DOWNGRADE_TARGET& target = kicad9;
2355 BOOST_CHECK_EQUAL( ClassifyBoardForDowngrade( &board, target, true ).Count( DOWNGRADE_BUCKET::DROP ), 1 );
2356 if( footprintOnly )
2357 DowngradeFootprintInPlace( fp, target, true );
2358 else
2359 DowngradeBoardInPlace( &board, target, true );
2360 BOOST_REQUIRE_EQUAL( pad->GetPrimitives( F_Cu ).size(), 1 );
2361 BOOST_CHECK( pad->GetPrimitives( F_Cu ).front()->GetShape() == SHAPE_T::CIRCLE );
2362 BOOST_CHECK_EQUAL( fp->Pads().size(), 1 );
2363 }
2364}
2365
2366
2367// Removing a via deletes copper and splits a net, so the omission preference does not reach it.
2368BOOST_AUTO_TEST_CASE( ViaApproximationsSurviveDropPolicy )
2369{
2370 for( bool drop : { false, true } )
2371 {
2372 BOOST_TEST_CONTEXT( "Drop approximations: " << drop )
2373 {
2374 BOARD board;
2375 PCB_VIA* skip = new PCB_VIA( &board );
2377 board.Add( skip );
2378 PCB_VIA* buried = new PCB_VIA( &board );
2379 buried->SetViaType( VIATYPE::BURIED );
2380 board.Add( buried );
2381 PCB_VIA* supported = new PCB_VIA( &board );
2382 board.Add( supported );
2383
2384 const auto report = ClassifyBoardForDowngrade( &board, kicad9, drop );
2385
2386 BOOST_CHECK_EQUAL( report.Count( DOWNGRADE_BUCKET::LOWER ), 2 );
2387 BOOST_CHECK_EQUAL( report.Count( DOWNGRADE_BUCKET::DROP ), 0 );
2388
2389 DowngradeBoardInPlace( &board, kicad9, drop );
2390
2391 BOOST_REQUIRE_EQUAL( board.Tracks().size(), 3 );
2394 BOOST_CHECK( buried->GetViaType() == VIATYPE::BLIND );
2395 BOOST_CHECK( supported->GetViaType() == VIATYPE::THROUGH );
2396 }
2397 }
2398}
2399
2400
2401BOOST_AUTO_TEST_CASE( DropApproximationsKeepsTargetSupportedFeatures )
2402{
2403 BOARD board;
2404 PCB_SHAPE* rect = new PCB_SHAPE( &board, SHAPE_T::RECTANGLE );
2405 rect->SetEnd( VECTOR2I( pcbIUScale.mmToIU( 10 ), pcbIUScale.mmToIU( 6 ) ) );
2406 rect->SetCornerRadius( pcbIUScale.mmToIU( 1 ) );
2407 rect->SetFillMode( FILL_T::HATCH );
2408 board.Add( rect );
2409 PCB_TEXTBOX* textbox = new PCB_TEXTBOX( &board );
2410 textbox->SetIsKnockout( true );
2411 board.Add( textbox );
2412 board.Add( new PCB_BARCODE( &board ) );
2413 PCB_VIA* buried = new PCB_VIA( &board );
2414 buried->SetViaType( VIATYPE::BURIED );
2415 board.Add( buried );
2416 PCB_VIA* skip = new PCB_VIA( &board );
2418 board.Add( skip );
2419 const auto& target = kicad10;
2420 BOOST_CHECK( !ClassifyBoardForDowngrade( &board, target, true ).IsLossy() );
2421 DowngradeBoardInPlace( &board, target, true );
2422 BOOST_CHECK_EQUAL( board.Drawings().size(), 3 );
2423 BOOST_CHECK_EQUAL( board.Tracks().size(), 2 );
2424 BOOST_CHECK_EQUAL( rect->GetCornerRadius(), pcbIUScale.mmToIU( 1 ) );
2425 BOOST_CHECK( rect->GetFillMode() == FILL_T::HATCH );
2426 BOOST_CHECK( textbox->IsKnockout() );
2427 BOOST_CHECK( buried->GetViaType() == VIATYPE::BURIED );
2429}
2430
2431
2432BOOST_AUTO_TEST_CASE( DropApproximationsCannotBypassBlockRules )
2433{
2434 BOARD board;
2435 ZONE* zone = new ZONE( &board );
2437 board.Add( zone );
2438 BOOST_CHECK( ClassifyBoardForDowngrade( &board, kicad10, true ).IsBlocked() );
2439}
2440
2441
2442BOOST_AUTO_TEST_CASE( LibraryReplacementsWaitForTheDesignTransaction )
2443{
2444 KI_TEST::SCOPED_TEMP_DIR temporary( "kicad_qa_shared_downgrade_transaction" );
2445 const wxString directory = temporary.Path().wstring();
2446 const wxString library = directory + wxT( "/library.fake_mod" );
2447 const wxString board = directory + wxT( "/board.kicad_pcb" );
2448
2449 auto write = []( const wxString& aPath, const wxString& aContent )
2450 {
2451 wxFFile file( aPath, wxT( "wb" ) );
2452 BOOST_REQUIRE( file.IsOpened() && file.Write( aContent ) && file.Close() );
2453 };
2454
2455 auto read = []( const wxString& aPath )
2456 {
2457 wxFFile file( aPath, wxT( "rb" ) );
2458 wxString content;
2459 BOOST_REQUIRE( file.IsOpened() && file.ReadAll( &content ) );
2460 return content;
2461 };
2462
2463 auto noForbidden = []( const wxString& )
2464 {
2465 return wxString();
2466 };
2467 auto convert = [&]( const wxString&, const wxString& aTemporary )
2468 {
2469 write( aTemporary, wxT( "(version 123) converted" ) );
2471 };
2472
2473 write( library, wxT( "original library" ) );
2474 write( board, wxT( "original board" ) );
2475
2476 {
2477 DOWNGRADE_FILE_TRANSACTION transaction;
2479 DowngradeLibraryFilesInPlace( directory, wxT( "*.fake_mod" ), 123, noForbidden, convert, &transaction )
2480 .IsEmpty() );
2481 BOOST_CHECK_EQUAL( read( library ), wxString( wxT( "original library" ) ) );
2482 BOOST_CHECK( transaction.Stage( directory + wxT( "/missing/board.kicad_pcb" ) ).IsEmpty() );
2483 }
2484
2485 BOOST_CHECK_EQUAL( read( library ), wxString( wxT( "original library" ) ) );
2486 BOOST_CHECK_EQUAL( read( board ), wxString( wxT( "original board" ) ) );
2487
2488 {
2489 DOWNGRADE_FILE_TRANSACTION transaction;
2491 DowngradeLibraryFilesInPlace( directory, wxT( "*.fake_mod" ), 123, noForbidden, convert, &transaction )
2492 .IsEmpty() );
2493 wxString stagedBoard = transaction.Stage( board );
2494 BOOST_REQUIRE( !stagedBoard.IsEmpty() );
2495 write( stagedBoard, wxT( "converted board" ) );
2496 BOOST_REQUIRE( transaction.Commit().IsEmpty() );
2497 }
2498
2499 BOOST_CHECK_EQUAL( read( library ), wxString( wxT( "(version 123) converted" ) ) );
2500 BOOST_CHECK_EQUAL( read( board ), wxString( wxT( "converted board" ) ) );
2501 wxArrayString files;
2502 wxDir::GetAllFiles( directory, &files );
2503 BOOST_CHECK_EQUAL( files.size(), 2 );
2504}
2505
2506
2507BOOST_AUTO_TEST_CASE( DirectoryDestinationStopsAllTransactionReplacements )
2508{
2509 KI_TEST::SCOPED_TEMP_DIR temporary( "kicad_qa_downgrade_transaction_directory" );
2510 const wxString directory = temporary.Path().wstring();
2511 const wxString first = directory + wxT( "/first.kicad_pcb" );
2512 const wxString second = directory + wxT( "/second.kicad_pcb" );
2513
2514 {
2515 wxFFile file( first, wxT( "wb" ) );
2516 BOOST_REQUIRE( file.IsOpened() && file.Write( wxT( "original" ) ) && file.Close() );
2517 }
2518
2519 {
2520 DOWNGRADE_FILE_TRANSACTION transaction;
2521 wxString stagedFirst = transaction.Stage( first );
2522 wxString stagedSecond = transaction.Stage( second );
2523 BOOST_REQUIRE( !stagedFirst.IsEmpty() && !stagedSecond.IsEmpty() );
2524
2525 for( const wxString& file : { stagedFirst, stagedSecond } )
2526 {
2527 wxFFile output( file, wxT( "wb" ) );
2528 BOOST_REQUIRE( output.IsOpened() && output.Write( wxT( "converted" ) ) && output.Close() );
2529 }
2530
2531 BOOST_REQUIRE( wxMkdir( second ) );
2532 BOOST_CHECK( wxFileName( transaction.Commit() ).SameAs( wxFileName( second ) ) );
2533 BOOST_CHECK( transaction.GetRecoveryError().IsEmpty() );
2534 }
2535
2536 wxFFile input( first, wxT( "rb" ) );
2537 wxString content;
2538 BOOST_REQUIRE( input.IsOpened() && input.ReadAll( &content ) );
2539 BOOST_CHECK_EQUAL( content, wxString( wxT( "original" ) ) );
2540 BOOST_CHECK( wxDirExists( second ) );
2541 wxArrayString files;
2542 wxDir::GetAllFiles( directory, &files );
2543 BOOST_CHECK_EQUAL( files.size(), 1 );
2544}
2545
2546
2547BOOST_AUTO_TEST_CASE( ConcurrentTransactionsUseDifferentOwnedStagingFiles )
2548{
2549 KI_TEST::SCOPED_TEMP_DIR temporary( "kicad_qa_downgrade_transaction_unique" );
2550 const wxString destination = temporary.Path().wstring() + wxT( "/board.kicad_pcb" );
2551
2552 {
2555 wxString firstTemporary = first.Stage( destination );
2556 wxString secondTemporary = second.Stage( destination );
2557 BOOST_REQUIRE( !firstTemporary.IsEmpty() && !secondTemporary.IsEmpty() );
2558 BOOST_CHECK( firstTemporary != secondTemporary );
2559 BOOST_CHECK( wxFileExists( firstTemporary ) );
2560 BOOST_CHECK( wxFileExists( secondTemporary ) );
2561 first.Discard( firstTemporary );
2562 BOOST_CHECK( !wxFileExists( firstTemporary ) );
2563 BOOST_CHECK( wxFileExists( secondTemporary ) );
2564 BOOST_CHECK( !wxFileExists( destination ) );
2565 }
2566
2567 BOOST_CHECK( std::filesystem::is_empty( temporary.Path() ) );
2568}
2569
2570
2571BOOST_AUTO_TEST_CASE( TransactionSymlinkReplacementLeavesLinkedSourcesUnchanged )
2572{
2573 KI_TEST::SCOPED_TEMP_DIR temporary( "kicad_qa_downgrade_transaction_symlink" );
2574 const auto original = temporary.Path() / u8"original-μ.kicad_mod";
2575 const auto alias = temporary.Path() / "alias.kicad_mod";
2576 const auto danglingAlias = temporary.Path() / "dangling.kicad_mod";
2577
2578 {
2579 wxFFile file( original.wstring(), wxT( "wb" ) );
2580 BOOST_REQUIRE( file.IsOpened() && file.Write( wxT( "original source" ) ) && file.Close() );
2581 }
2582
2583 std::error_code error;
2584 std::filesystem::create_symlink( original.filename(), alias, error );
2585
2586 if( error )
2587 {
2588 BOOST_TEST_MESSAGE( "Symlink creation is unavailable on this system" );
2589 return;
2590 }
2591
2592 std::filesystem::create_symlink( "missing.kicad_mod", danglingAlias, error );
2593 BOOST_REQUIRE( !error );
2594
2595 {
2596 DOWNGRADE_FILE_TRANSACTION transaction;
2597
2598 for( const auto& destination : { alias, danglingAlias } )
2599 {
2600 wxString staged = transaction.Stage( destination.wstring() );
2601 BOOST_REQUIRE( !staged.IsEmpty() );
2602 wxFFile file( staged, wxT( "wb" ) );
2603 BOOST_REQUIRE( file.IsOpened() && file.Write( wxT( "converted output" ) ) && file.Close() );
2604 }
2605
2606 BOOST_REQUIRE( transaction.Commit().IsEmpty() );
2607 }
2608
2609 wxFFile file( original.wstring(), wxT( "rb" ) );
2610 wxString content;
2611 BOOST_REQUIRE( file.IsOpened() && file.ReadAll( &content ) );
2612 BOOST_CHECK_EQUAL( content, wxString( wxT( "original source" ) ) );
2613 BOOST_CHECK( !std::filesystem::is_symlink( alias ) );
2614 BOOST_CHECK( !std::filesystem::is_symlink( danglingAlias ) );
2615 BOOST_CHECK_EQUAL( std::distance( std::filesystem::directory_iterator( temporary.Path() ),
2616 std::filesystem::directory_iterator() ),
2617 3 );
2618}
2619
2620
2621static void checkFeature( const COMPATIBILITY_REPORT& aReport, const wxString& aName, DOWNGRADE_BUCKET aBucket,
2622 int aCount )
2623{
2624 for( const COMPAT_ENTRY& entry : aReport.Entries() )
2625 {
2626 if( entry.m_feature == aName )
2627 {
2628 BOOST_CHECK( entry.m_bucket == aBucket );
2629 BOOST_CHECK_EQUAL( entry.m_count, aCount );
2630 BOOST_CHECK( !entry.m_detail.IsEmpty() );
2631 return;
2632 }
2633 }
2634
2635 BOOST_ERROR( "Missing compatibility feature: " + aName.ToStdString() );
2636}
2637
2638
2639BOOST_AUTO_TEST_CASE( GeometricConstraintsDropWithoutMovingBoardOrFootprintGeometry )
2640{
2641 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
2642 {
2643 for( bool drop : { false, true } )
2644 {
2645 BOARD board;
2646 FOOTPRINT* fp = new FOOTPRINT( &board );
2647 board.Add( fp );
2648
2649 std::vector<PCB_SHAPE*> shapes;
2650
2651 for( BOARD_ITEM_CONTAINER* parent :
2652 { static_cast<BOARD_ITEM_CONTAINER*>( &board ), static_cast<BOARD_ITEM_CONTAINER*>( fp ) } )
2653 {
2654 PCB_SHAPE* shape = new PCB_SHAPE( parent, SHAPE_T::SEGMENT );
2655 shape->SetStart( VECTOR2I( 1000000, 2000000 ) );
2656 shape->SetEnd( VECTOR2I( 7000000, 2000000 ) );
2657 parent->Add( shape );
2658 shapes.push_back( shape );
2660 constraint->AddMember( shape->m_Uuid );
2661 parent->Add( constraint );
2662 }
2663
2664 const auto report = ClassifyBoardForDowngrade( &board, target, drop );
2665 BOOST_CHECK( !report.IsBlocked() );
2666 checkFeature( report, wxT( "Geometric constraints" ), DOWNGRADE_BUCKET::DROP, 2 );
2667 BOOST_CHECK_EQUAL( board.Constraints().size(), 1 );
2668 BOOST_CHECK_EQUAL( fp->Constraints().size(), 1 );
2669 DowngradeBoardInPlace( &board, target, drop );
2670 BOOST_CHECK( board.Constraints().empty() );
2671 BOOST_CHECK( fp->Constraints().empty() );
2672
2673 for( PCB_SHAPE* shape : shapes )
2674 {
2675 BOOST_CHECK( shape->GetStart() == VECTOR2I( 1000000, 2000000 ) );
2676 BOOST_CHECK( shape->GetEnd() == VECTOR2I( 7000000, 2000000 ) );
2677 }
2678 }
2679 }
2680}
2681
2682
2683BOOST_AUTO_TEST_CASE( GridAndDrillDrawingLossesAreReportedBeforeRemoval )
2684{
2685 for( bool drop : { false, true } )
2686 {
2687 BOARD board;
2688 board.Add( new PCB_GRID_ITEM( &board ) );
2689 board.Add( new PCB_DRILL_CHART( &board ) );
2690 board.Add( new PCB_DRILL_MAP( &board ) );
2691 board.GetDesignSettings().GetDrillSymbolProfile().SetName( wxT( "Fabrication symbols" ) );
2692 PCB_VIA* via = new PCB_VIA( &board );
2693 via->SetPosition( VECTOR2I( 1000000, 2000000 ) );
2694 board.Add( via );
2695
2696 const auto report = ClassifyBoardForDowngrade( &board, kicad10, drop );
2697 checkFeature( report, wxT( "Local grids" ), DOWNGRADE_BUCKET::DROP, 1 );
2698 checkFeature( report, wxT( "Drill charts and maps" ), DOWNGRADE_BUCKET::DROP, 2 );
2699 checkFeature( report, wxT( "Drill symbol configuration" ), DOWNGRADE_BUCKET::DROP, 1 );
2700 BOOST_CHECK_EQUAL( board.Drawings().size(), 3 );
2701 DowngradeBoardInPlace( &board, kicad10, drop );
2702 BOOST_CHECK( board.Drawings().empty() );
2703 BOOST_REQUIRE_EQUAL( board.Tracks().size(), 1 );
2704 BOOST_CHECK( via->GetPosition() == VECTOR2I( 1000000, 2000000 ) );
2706 }
2707}
2708
2709
2710BOOST_AUTO_TEST_CASE( StackupTableLowersToAStaticTable )
2711{
2712 for( bool drop : { false, true } )
2713 {
2714 BOARD board;
2715 board.SetCopperLayerCount( 4 );
2716
2717 PCB_STACKUP_TABLE* live = new PCB_STACKUP_TABLE( &board );
2718
2719 // The loader rejects a stackup table anywhere else
2720 live->SetLayer( Dwgs_User );
2721 live->RebuildCells( board );
2722 board.Add( live );
2723
2724 PCB_GROUP* group = new PCB_GROUP( &board );
2725 board.Add( group );
2726 group->AddItem( live );
2727
2728 const auto report = ClassifyBoardForDowngrade( &board, kicad10, drop );
2729 BOOST_CHECK( !report.IsBlocked() );
2730 checkFeature( report, wxT( "Live stackup tables" ), drop ? DOWNGRADE_BUCKET::DROP : DOWNGRADE_BUCKET::LOWER,
2731 1 );
2732
2733 DowngradeBoardInPlace( &board, kicad10, drop );
2734
2735 if( drop )
2736 {
2737 BOOST_CHECK( board.Drawings().empty() );
2738 continue;
2739 }
2740
2741 BOOST_REQUIRE_EQUAL( board.Drawings().size(), 1 );
2742
2743 BOARD_ITEM* item = *board.Drawings().begin();
2744 BOOST_REQUIRE( item->Type() == PCB_TABLE_T );
2745
2746 BOOST_CHECK( item->GetParentGroup() == group );
2747 }
2748}
2749
2750
2751// The frozen writers have no case for a generated table, so the file itself has to carry a plain one.
2752BOOST_AUTO_TEST_CASE( ExportedStackupTableIsAPlainTable )
2753{
2754 SETTINGS_MANAGER settingsManager;
2755
2756 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_downgrade_stackup", "" );
2757 const std::string src = ( tmp.Path() / "stackup.kicad_pcb" ).string();
2758
2759 wxString heading;
2760
2761 {
2762 BOARD board;
2763 board.SetCopperLayerCount( 4 );
2764
2765 PCB_STACKUP_TABLE* live = new PCB_STACKUP_TABLE( &board );
2766
2767 // The loader rejects a stackup table anywhere else
2768 live->SetLayer( Dwgs_User );
2769 live->RebuildCells( board );
2770 board.Add( live );
2771
2772 BOOST_REQUIRE( live->GetRowCount() > 1 );
2773 BOOST_REQUIRE( live->GetCell( 0, 0 ) );
2774 heading = live->GetCell( 0, 0 )->GetText();
2775 BOOST_REQUIRE( !heading.IsEmpty() );
2776
2777 KI_TEST::DumpBoardToFile( board, src );
2778 }
2779
2780 // The source really is a live table, or the export below proves nothing
2781 {
2782 std::ifstream file( src );
2783 std::string content( ( std::istreambuf_iterator<char>( file ) ), std::istreambuf_iterator<char>() );
2784 BOOST_REQUIRE( content.find( "(stackup_table" ) != std::string::npos );
2785 }
2786
2787 for( const DOWNGRADE_TARGET& target : { kicad10, kicad9 } )
2788 {
2789 BOOST_TEST_CONTEXT( "Target " << target.m_id )
2790 {
2791 const std::string dest = ( tmp.Path() / ( "out-" + target.m_id.ToStdString() + ".kicad_pcb" ) ).string();
2792
2793 COMPATIBILITY_REPORT report;
2794 BOOST_REQUIRE( ExportBoardToOlderVersion( src, dest, target, report ) );
2795
2796 std::ifstream file( dest );
2797 std::string content( ( std::istreambuf_iterator<char>( file ) ), std::istreambuf_iterator<char>() );
2798
2799 BOOST_CHECK( content.find( "(stackup_table" ) == std::string::npos );
2800 BOOST_CHECK( content.find( "(table" ) != std::string::npos );
2801
2803 std::unique_ptr<BOARD> exported( io.LoadBoard( dest, nullptr ) );
2804 BOOST_REQUIRE( exported );
2805 BOOST_REQUIRE_EQUAL( exported->Drawings().size(), 1 );
2806
2807 BOARD_ITEM* item = *exported->Drawings().begin();
2808 BOOST_REQUIRE( item->Type() == PCB_TABLE_T );
2809
2810 PCB_TABLE* flat = static_cast<PCB_TABLE*>( item );
2811 BOOST_REQUIRE( flat->GetCell( 0, 0 ) );
2812 BOOST_CHECK( flat->GetCell( 0, 0 )->GetText() == heading );
2813 }
2814 }
2815}
2816
2817
2818BOOST_AUTO_TEST_CASE( NewGeneratorsLoseEditabilityAndKeepCopperAndOuterGroups )
2819{
2820 for( bool drop : { false, true } )
2821 {
2822 BOARD board;
2823 PCB_GROUP* outer = new PCB_GROUP( &board );
2824 board.Add( outer );
2825 PCB_VIA_STITCH* stitch = new PCB_VIA_STITCH( &board );
2826 PCB_VIA_STACK* stack = new PCB_VIA_STACK( &board );
2827 board.Add( stitch );
2828 board.Add( stack );
2829 outer->AddItem( stitch );
2830 outer->AddItem( stack );
2831 std::vector<PCB_VIA*> vias;
2832
2833 for( PCB_GENERATOR* generator :
2834 { static_cast<PCB_GENERATOR*>( stitch ), static_cast<PCB_GENERATOR*>( stack ) } )
2835 {
2836 PCB_VIA* via = new PCB_VIA( &board );
2837 via->SetPosition( VECTOR2I( 1000000 * ( vias.size() + 1 ), 2000000 ) );
2838 via->SetWidth( F_Cu, 600000 );
2839 via->SetDrill( 300000 );
2840 board.Add( via );
2841 generator->AddItem( via );
2842 vias.push_back( via );
2843 }
2844
2845 const auto report = ClassifyBoardForDowngrade( &board, kicad10, drop );
2846 checkFeature( report, wxT( "Via stitching and guarding" ), DOWNGRADE_BUCKET::DROP, 1 );
2847 checkFeature( report, wxT( "Microvia stack generators" ), DOWNGRADE_BUCKET::DROP, 1 );
2848 DowngradeBoardInPlace( &board, kicad10, drop );
2849 BOOST_CHECK( board.Generators().empty() );
2850 BOOST_REQUIRE_EQUAL( board.Tracks().size(), 2 );
2851 BOOST_REQUIRE_EQUAL( outer->GetItems().size(), 2 );
2852
2853 for( size_t ii = 0; ii < vias.size(); ++ii )
2854 {
2855 BOOST_CHECK( vias[ii]->GetPosition() == VECTOR2I( 1000000 * ( ii + 1 ), 2000000 ) );
2856 BOOST_CHECK_EQUAL( vias[ii]->GetWidth( F_Cu ), 600000 );
2857 BOOST_CHECK_EQUAL( vias[ii]->GetDrill(), 300000 );
2858 BOOST_CHECK( vias[ii]->GetParentGroup() == outer );
2859 }
2860 }
2861}
2862
2863
2864BOOST_AUTO_TEST_CASE( NativeViaGeneratorFixtureExportsCopperAndOwnershipForBothTargetsAndPolicies )
2865{
2866 SETTINGS_MANAGER settingsManager;
2867 const std::string src =
2868 KI_TEST::GetPcbnewTestDataDir() + "../downgrade/regressions/via_generators/via_generators.kicad_pcb";
2869 const std::string originalBytes = KI_TEST::ReadGoldenText( src );
2871 std::unique_ptr<BOARD> source( io.LoadBoard( src, nullptr ) );
2873 BOOST_REQUIRE_EQUAL( source->GetCopperLayerCount(), 6 );
2874 BOOST_REQUIRE_EQUAL( source->Zones().size(), 3u );
2875 BOOST_REQUIRE_EQUAL( source->Generators().size(), 3u );
2876 BOOST_REQUIRE_EQUAL( source->Groups().size(), 1u );
2877 BOOST_REQUIRE( source->GroupsSanityCheck().IsEmpty() );
2878
2879 const auto copperById = []( const BOARD& aBoard )
2880 {
2881 std::map<KIID, const PCB_TRACK*> items;
2882
2883 for( const PCB_TRACK* item : aBoard.Tracks() )
2884 BOOST_REQUIRE( items.emplace( item->m_Uuid, item ).second );
2885
2886 return items;
2887 };
2888 const auto memberIds = []( const PCB_GROUP& aGroup )
2889 {
2890 std::set<KIID> ids;
2891
2892 for( const EDA_ITEM* member : aGroup.GetItems() )
2893 BOOST_REQUIRE( ids.insert( member->m_Uuid ).second );
2894
2895 return ids;
2896 };
2897 const auto serializeNative = []( BOARD* aBoard )
2898 {
2899 STRING_FORMATTER formatter;
2900 PCB_IO_KICAD_SEXPR serializer;
2901 serializer.FormatBoardToFormatter( &formatter, aBoard );
2902 return formatter.GetString();
2903 };
2904
2905 const auto sourceCopper = copperById( *source );
2906 BOOST_REQUIRE_EQUAL( sourceCopper.size(), 83u );
2907 std::set<KIID> plainVias;
2908 std::set<KIID> generatedVias;
2909 size_t sourceVias = 0;
2910 size_t sourceSegments = 0;
2911 size_t sourceMicrovias = 0;
2912
2913 for( const auto& [id, item] : sourceCopper )
2914 {
2915 if( const PCB_VIA* via = dynamic_cast<const PCB_VIA*>( item ) )
2916 {
2917 ++sourceVias;
2918
2919 if( via->GetViaType() == VIATYPE::MICROVIA )
2920 {
2921 ++sourceMicrovias;
2922 BOOST_REQUIRE( via->Padstack().Drill().is_filled.value_or( false ) );
2923 }
2924
2925 if( !via->GetParentGroup() )
2926 plainVias.insert( id );
2927 }
2928 else
2929 {
2930 BOOST_REQUIRE( item->Type() == PCB_TRACE_T );
2931 ++sourceSegments;
2932 }
2933 }
2934
2935 BOOST_REQUIRE_EQUAL( sourceVias, 80u );
2936 BOOST_REQUIRE_EQUAL( sourceSegments, 3u );
2937 BOOST_REQUIRE_EQUAL( sourceMicrovias, 2u );
2938 BOOST_REQUIRE_EQUAL( plainVias.size(), 3u );
2939
2940 PCB_VIA_STITCH* stitch = nullptr;
2941 PCB_VIA_STITCH* guard = nullptr;
2942 PCB_VIA_STACK* stack = nullptr;
2943
2944 for( PCB_GENERATOR* generator : source->Generators() )
2945 {
2946 if( PCB_VIA_STITCH* viaStitch = dynamic_cast<PCB_VIA_STITCH*>( generator ) )
2947 {
2948 BOOST_REQUIRE( source->FindNet( viaStitch->GetNetCode() ) );
2949 BOOST_REQUIRE( source->FindNet( viaStitch->GetNetCode() )->GetNetname() == wxT( "GND" ) );
2950
2951 if( viaStitch->GetMode() == PCB_VIA_STITCH_MODE::STITCH )
2952 {
2953 BOOST_REQUIRE( !stitch );
2954 stitch = viaStitch;
2955 }
2956 else
2957 {
2958 BOOST_REQUIRE( viaStitch->GetMode() == PCB_VIA_STITCH_MODE::GUARD );
2959 BOOST_REQUIRE( !guard );
2960 guard = viaStitch;
2961 BOOST_REQUIRE( source->FindNet( guard->GetGuardedNetCode() ) );
2962 BOOST_REQUIRE( source->FindNet( guard->GetGuardedNetCode() )->GetNetname() == wxT( "SIGNAL" ) );
2963 }
2964 }
2965 else
2966 {
2967 BOOST_REQUIRE( !stack );
2968 stack = dynamic_cast<PCB_VIA_STACK*>( generator );
2969 BOOST_REQUIRE( stack );
2971 BOOST_REQUIRE( stack->GetStartLayer() == F_Cu );
2972 BOOST_REQUIRE( stack->GetEndLayer() == In2_Cu );
2973 }
2974
2975 for( BOARD_ITEM* member : generator->GetBoardItems() )
2976 {
2977 BOOST_REQUIRE( member->Type() == PCB_VIA_T );
2978 BOOST_REQUIRE( member->GetParentGroup() == static_cast<EDA_GROUP*>( generator ) );
2979 BOOST_REQUIRE( sourceCopper.count( member->m_Uuid ) == 1u );
2980 BOOST_REQUIRE( generatedVias.insert( member->m_Uuid ).second );
2981 }
2982 }
2983
2984 BOOST_REQUIRE( stitch && guard && stack );
2985 BOOST_REQUIRE_EQUAL( stitch->GetItems().size(), 49u );
2986 BOOST_REQUIRE_EQUAL( guard->GetItems().size(), 26u );
2987 BOOST_REQUIRE_EQUAL( stack->GetItems().size(), 2u );
2988 BOOST_REQUIRE_EQUAL( generatedVias.size(), 77u );
2989 const auto stitchMembers = memberIds( *stitch );
2990 PCB_GROUP* outer = *source->Groups().begin();
2991 const KIID outerId = outer->m_Uuid;
2992 const wxString outerName = outer->GetName();
2993 BOOST_REQUIRE( stitch->GetParentGroup() == static_cast<EDA_GROUP*>( outer ) );
2994 BOOST_REQUIRE( !guard->GetParentGroup() && !stack->GetParentGroup() );
2995 BOOST_REQUIRE( memberIds( *outer ) == std::set<KIID>{ stitch->m_Uuid } );
2996
2997 const std::string sourceModel = serializeNative( source.get() );
2998 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_native_via_generators", "" );
2999
3000 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
3001 {
3002 const bool preTen = target.m_boardVersion == kicad9.m_boardVersion;
3003
3004 for( bool drop : { false, true } )
3005 {
3006 BOOST_TEST_CONTEXT( target.m_id.ToStdString() << " drop=" << drop )
3007 {
3008 const COMPATIBILITY_REPORT preview = ClassifyBoardForDowngrade( source.get(), target, drop );
3009 BOOST_CHECK( !preview.IsBlocked() );
3011 BOOST_CHECK_EQUAL( preview.Count( DOWNGRADE_BUCKET::DROP ), preTen ? 5 : 3 );
3012 BOOST_CHECK_EQUAL( serializeNative( source.get() ), sourceModel );
3013 const std::string dest =
3014 ( tmp.Path()
3015 / ( target.m_id.ToStdString() + ( drop ? "-drop.kicad_pcb" : "-lower.kicad_pcb" ) ) )
3016 .string();
3017 COMPATIBILITY_REPORT report;
3018 wxString unsupportedToken;
3019 BOOST_REQUIRE( ExportBoardToOlderVersion( src, dest, target, report, &unsupportedToken, wxEmptyString,
3020 drop ) );
3021 BOOST_CHECK( unsupportedToken.IsEmpty() );
3022 BOOST_CHECK( !report.IsBlocked() );
3024 BOOST_CHECK_EQUAL( report.Count( DOWNGRADE_BUCKET::DROP ), preTen ? 5 : 3 );
3025 BOOST_REQUIRE_EQUAL( report.Entries().size(), preTen ? 3u : 2u );
3026 checkFeature( report, wxT( "Via stitching and guarding" ), DOWNGRADE_BUCKET::DROP, 2 );
3027 checkFeature( report, wxT( "Microvia stack generators" ), DOWNGRADE_BUCKET::DROP, 1 );
3028
3029 if( preTen )
3030 checkFeature( report, wxT( "Via protection" ), DOWNGRADE_BUCKET::DROP, 2 );
3031
3032 BOOST_REQUIRE_EQUAL( report.Entries().size(), preview.Entries().size() );
3033
3034 for( size_t ii = 0; ii < preview.Entries().size(); ++ii )
3035 {
3036 BOOST_CHECK( report.Entries()[ii].m_bucket == preview.Entries()[ii].m_bucket );
3037 BOOST_CHECK( report.Entries()[ii].m_feature == preview.Entries()[ii].m_feature );
3038 BOOST_CHECK_EQUAL( report.Entries()[ii].m_count, preview.Entries()[ii].m_count );
3039 }
3040
3041 const std::string outputBytes = KI_TEST::ReadGoldenText( dest );
3042 BOOST_CHECK( FindUnsupportedBoardToken( wxString::FromUTF8( outputBytes ), target ).IsEmpty() );
3043 BOOST_CHECK( outputBytes.find( "(generated" ) == std::string::npos );
3044
3045 if( preTen )
3046 {
3047 for( const char* token : { "(filling", "(capping", "(covering", "(plugging" } )
3048 BOOST_CHECK( outputBytes.find( token ) == std::string::npos );
3049 }
3050
3051 std::unique_ptr<BOARD> exported( io.LoadBoard( dest, nullptr ) );
3052 BOOST_REQUIRE( exported );
3053 BOOST_CHECK_EQUAL( exported->GetFileFormatVersionAtLoad(), target.m_boardVersion );
3054 BOOST_CHECK_EQUAL( exported->GetCopperLayerCount(), 6 );
3055 BOOST_CHECK_EQUAL( exported->Zones().size(), 3u );
3056 BOOST_CHECK( exported->Generators().empty() );
3057 BOOST_REQUIRE_EQUAL( exported->Groups().size(), 1u );
3058 BOOST_CHECK( exported->GroupsSanityCheck().IsEmpty() );
3059
3060 const auto exportedCopper = copperById( *exported );
3061 BOOST_REQUIRE_EQUAL( exportedCopper.size(), sourceCopper.size() );
3062 PCB_GROUP* exportedOuter = *exported->Groups().begin();
3063 BOOST_CHECK( exportedOuter->m_Uuid == outerId );
3064 BOOST_CHECK( exportedOuter->GetName() == outerName );
3065 BOOST_CHECK( memberIds( *exportedOuter ) == stitchMembers );
3066
3067 for( const auto& [id, original] : sourceCopper )
3068 {
3069 const auto found = exportedCopper.find( id );
3070 BOOST_REQUIRE( found != exportedCopper.end() );
3071 const PCB_TRACK* item = found->second;
3072 BOOST_CHECK( item->Type() == original->Type() );
3073 BOOST_CHECK( item->GetStart() == original->GetStart() );
3074 BOOST_CHECK( item->GetEnd() == original->GetEnd() );
3075 BOOST_CHECK( item->GetLayerSet() == original->GetLayerSet() );
3076 BOOST_CHECK_EQUAL( item->GetNetname().ToStdString(), original->GetNetname().ToStdString() );
3077
3078 if( const PCB_VIA* originalVia = dynamic_cast<const PCB_VIA*>( original ) )
3079 {
3080 const PCB_VIA* via = dynamic_cast<const PCB_VIA*>( item );
3081 BOOST_REQUIRE( via );
3082 BOOST_CHECK( via->GetPosition() == originalVia->GetPosition() );
3083 BOOST_CHECK( via->GetViaType() == originalVia->GetViaType() );
3084 BOOST_CHECK( via->TopLayer() == originalVia->TopLayer() );
3085 BOOST_CHECK( via->BottomLayer() == originalVia->BottomLayer() );
3086 BOOST_CHECK_EQUAL( via->GetDrillValue(), originalVia->GetDrillValue() );
3087
3088 for( PCB_LAYER_ID layer : LSET::AllCuMask( 6 ) )
3089 BOOST_CHECK_EQUAL( via->GetWidth( layer ), originalVia->GetWidth( layer ) );
3090
3091 const PADSTACK& padstack = via->Padstack();
3092
3093 if( preTen )
3094 {
3095 // The current reader resolves omitted legacy fields to board defaults.
3096 BOOST_CHECK( !padstack.Drill().is_filled.value_or( false ) );
3097 BOOST_CHECK( !padstack.Drill().is_capped.value_or( false ) );
3098 BOOST_CHECK( !padstack.FrontOuterLayers().has_covering.value_or( false ) );
3099 BOOST_CHECK( !padstack.BackOuterLayers().has_covering.value_or( false ) );
3100 BOOST_CHECK( !padstack.FrontOuterLayers().has_plugging.value_or( false ) );
3101 BOOST_CHECK( !padstack.BackOuterLayers().has_plugging.value_or( false ) );
3102 }
3103 else
3104 {
3105 const PADSTACK& originalStack = originalVia->Padstack();
3106 BOOST_CHECK( padstack.Drill().is_filled == originalStack.Drill().is_filled );
3107 BOOST_CHECK( padstack.Drill().is_capped == originalStack.Drill().is_capped );
3109 == originalStack.FrontOuterLayers().has_covering );
3111 == originalStack.BackOuterLayers().has_covering );
3113 == originalStack.FrontOuterLayers().has_plugging );
3115 == originalStack.BackOuterLayers().has_plugging );
3116 }
3117
3118 if( plainVias.count( id ) )
3119 BOOST_CHECK( !via->GetParentGroup() );
3120 }
3121 else
3122 {
3123 BOOST_CHECK( item->GetLayer() == original->GetLayer() );
3124 BOOST_CHECK_EQUAL( item->GetWidth(), original->GetWidth() );
3125 }
3126
3127 if( stitchMembers.count( id ) )
3128 BOOST_CHECK( item->GetParentGroup() == static_cast<EDA_GROUP*>( exportedOuter ) );
3129 else
3130 BOOST_CHECK( !item->GetParentGroup() );
3131 }
3132
3133 for( BOARD_ITEM* drawing : source->Drawings() )
3134 {
3135 if( const EDA_TEXT* text = dynamic_cast<const EDA_TEXT*>( drawing ) )
3136 {
3137 const auto found = std::find_if( exported->Drawings().begin(), exported->Drawings().end(),
3138 [&]( const BOARD_ITEM* aItem )
3139 {
3140 return aItem->m_Uuid == drawing->m_Uuid;
3141 } );
3142 BOOST_REQUIRE( found != exported->Drawings().end() );
3143 const EDA_TEXT* exportedText = dynamic_cast<const EDA_TEXT*>( *found );
3144 BOOST_REQUIRE( exportedText );
3145 BOOST_CHECK( exportedText->GetText() == text->GetText() );
3146 }
3147 }
3148
3149 BOOST_CHECK_EQUAL( serializeNative( source.get() ), sourceModel );
3150 BOOST_CHECK_EQUAL( KI_TEST::ReadGoldenText( src ), originalBytes );
3151 }
3152 }
3153 }
3154}
3155
3156
3157BOOST_AUTO_TEST_CASE( NativeTuningFixturesPreserveCopperAndEraEditabilityForBothPolicies )
3158{
3159 SETTINGS_MANAGER settingsManager;
3161 const std::string lengthPath = KI_TEST::GetPcbnewTestDataDir() + "tuning_generators_load_save.kicad_pcb";
3162 const std::string timePath = KI_TEST::GetPcbnewTestDataDir() + "issue24772/fw16_MCIO8i.kicad_pcb";
3163 const std::string lengthBytes = KI_TEST::ReadGoldenText( lengthPath );
3164 const std::string timeBytes = KI_TEST::ReadGoldenText( timePath );
3165 std::unique_ptr<BOARD> lengthFixture( io.LoadBoard( lengthPath, nullptr ) );
3166 std::unique_ptr<BOARD> timeFixture( io.LoadBoard( timePath, nullptr ) );
3167 BOOST_REQUIRE( lengthFixture && timeFixture );
3168 BOOST_REQUIRE_EQUAL( lengthFixture->Generators().size(), 1u );
3169 BOOST_REQUIRE_EQUAL( timeFixture->Generators().size(), 16u );
3170 PCB_TUNING_PATTERN* originalTime = nullptr;
3171
3172 for( PCB_GENERATOR* generator : timeFixture->Generators() )
3173 {
3174 if( generator->m_Uuid == KIID( "2acf841f-25ce-450c-b8df-dbbc34cc96ac" ) )
3175 originalTime = dynamic_cast<PCB_TUNING_PATTERN*>( generator );
3176 }
3177
3178 BOOST_REQUIRE( originalTime );
3179 BOOST_REQUIRE( originalTime->GetSettings().m_isTimeDomain );
3180 BOOST_REQUIRE_EQUAL( originalTime->GetItems().size(), 1u );
3181 BOARD board;
3182 board.SetCopperLayerCount( timeFixture->GetCopperLayerCount() );
3183 board.SetEnabledLayers( timeFixture->GetEnabledLayers() );
3184 auto length = dynamic_cast<PCB_TUNING_PATTERN*>( ( *lengthFixture->Generators().begin() )->DeepClone() );
3185 auto time = dynamic_cast<PCB_TUNING_PATTERN*>( originalTime->DeepClone() );
3186 BOOST_REQUIRE( length && time );
3187 BOOST_REQUIRE( !length->GetSettings().m_isTimeDomain );
3188 BOOST_REQUIRE_GT( length->GetItems().size(), 1u );
3189
3190 const auto addCopper = [&]( PCB_TRACK* aTrack )
3191 {
3192 NETINFO_ITEM* net = board.FindNet( aTrack->GetNetname() );
3193
3194 if( !net )
3195 {
3196 net = new NETINFO_ITEM( &board, aTrack->GetNetname() );
3197 board.Add( net );
3198 }
3199
3200 aTrack->SetParent( &board );
3201 aTrack->SetNetCode( net->GetNetCode() );
3202 board.Add( aTrack );
3203 };
3204
3205 for( PCB_TUNING_PATTERN* pattern : { length, time } )
3206 {
3207 for( BOARD_ITEM* member : pattern->GetBoardItems() )
3208 {
3209 PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( member );
3210 BOOST_REQUIRE( track );
3211 addCopper( track );
3212 }
3213
3214 board.Add( pattern );
3215 }
3216
3217 PCB_TRACK* originalControl = nullptr;
3218
3219 for( PCB_TRACK* track : timeFixture->Tracks() )
3220 {
3221 if( track->Type() == PCB_TRACE_T && !dynamic_cast<PCB_GENERATOR*>( track->GetParentGroup() ) )
3222 {
3223 originalControl = track;
3224 break;
3225 }
3226 }
3227
3228 BOOST_REQUIRE( originalControl );
3229 auto control = static_cast<PCB_TRACK*>( originalControl->Clone() );
3230 control->SetParentGroup( nullptr );
3231 addCopper( control );
3232 PCB_GROUP* outer = new PCB_GROUP( &board );
3233 outer->SetName( wxT( "Native tuning ownership" ) );
3234 board.Add( outer );
3235 outer->AddItem( length );
3236 outer->AddItem( time );
3237
3238 // Populate the numeric cache through native APIs without changing fixture copper.
3239 double patternLength = 0;
3240
3241 for( BOARD_ITEM* member : length->GetBoardItems() )
3242 patternLength += static_cast<PCB_TRACK*>( member )->GetLength();
3243
3244 STRING_ANY_MAP lengthProperties = length->GetProperties();
3245
3246 // The native setter expects wxString values for these serialized string enums.
3247 for( const char* key : { "tuning_mode", "initial_side", "last_status" } )
3248 {
3249 std::string value;
3250 BOOST_REQUIRE( lengthProperties.get_to( key, value ) );
3251 lengthProperties[key] = wxAny( wxString::FromUTF8( value ) );
3252 }
3253
3254 lengthProperties["last_tuning_length"] = wxAny( patternLength / pcbIUScale.IU_PER_MM );
3255 length->SetProperties( lengthProperties );
3256 const wxString tuningInfo = length->GetRowData().back().second.GetString();
3257 BOOST_REQUIRE( !tuningInfo.IsEmpty() );
3258 const auto memberIds = []( const PCB_GROUP& aGroup )
3259 {
3260 std::set<KIID> ids;
3261
3262 for( const EDA_ITEM* member : aGroup.GetItems() )
3263 BOOST_REQUIRE( ids.insert( member->m_Uuid ).second );
3264
3265 return ids;
3266 };
3267 const auto serializeNative = []( BOARD* aBoard )
3268 {
3269 STRING_FORMATTER formatter;
3270 PCB_IO_KICAD_SEXPR serializer;
3271 serializer.FormatBoardToFormatter( &formatter, aBoard );
3272 return formatter.GetString();
3273 };
3274 std::map<KIID, const PCB_TRACK*> copper;
3275
3276 for( const PCB_TRACK* track : board.Tracks() )
3277 BOOST_REQUIRE( copper.emplace( track->m_Uuid, track ).second );
3278
3279 const auto lengthMembers = memberIds( *length );
3280 const auto timeMembers = memberIds( *time );
3281 BOOST_REQUIRE_EQUAL( copper.size(), lengthMembers.size() + timeMembers.size() + 1u );
3282 BOOST_REQUIRE( board.GroupsSanityCheck().IsEmpty() );
3283 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_native_tuning_boundaries" );
3284 const std::string src = ( tmp.Path() / "native-source.kicad_pcb" ).string();
3285 io.SaveBoard( src, board );
3286 const std::string sourceBytes = KI_TEST::ReadGoldenText( src );
3287 const std::string sourceModel = serializeNative( &board );
3288
3289 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
3290 {
3291 const bool preTen = target.m_boardVersion == kicad9.m_boardVersion;
3292
3293 for( bool drop : { false, true } )
3294 {
3295 BOOST_TEST_CONTEXT( target.m_id.ToStdString() << " drop=" << drop )
3296 {
3297 const auto preview = ClassifyBoardForDowngrade( &board, target, drop );
3298 BOOST_CHECK( !preview.IsBlocked() );
3299 BOOST_CHECK_EQUAL( preview.Count( DOWNGRADE_BUCKET::LOWER ), 0 );
3300 BOOST_CHECK_EQUAL( preview.Count( DOWNGRADE_BUCKET::DROP ), preTen ? 1 : 0 );
3301 BOOST_CHECK_EQUAL( serializeNative( &board ), sourceModel );
3302 const std::string dest =
3303 ( tmp.Path()
3304 / ( target.m_id.ToStdString() + ( drop ? "-drop.kicad_pcb" : "-lower.kicad_pcb" ) ) )
3305 .string();
3306 COMPATIBILITY_REPORT report;
3307 wxString unsupported;
3309 ExportBoardToOlderVersion( src, dest, target, report, &unsupported, wxEmptyString, drop ) );
3310 BOOST_CHECK( unsupported.IsEmpty() );
3311 BOOST_CHECK( !report.IsBlocked() );
3313 BOOST_CHECK_EQUAL( report.Count( DOWNGRADE_BUCKET::DROP ), preTen ? 1 : 0 );
3314 BOOST_REQUIRE_EQUAL( report.Entries().size(), preTen ? 1u : 0u );
3315
3316 if( preTen )
3317 checkFeature( report, wxT( "Time-domain tuning patterns" ), DOWNGRADE_BUCKET::DROP, 1 );
3318
3319 const std::string outputBytes = KI_TEST::ReadGoldenText( dest );
3320 BOOST_CHECK( FindUnsupportedBoardToken( wxString::FromUTF8( outputBytes ), target ).IsEmpty() );
3321
3322 if( preTen )
3323 {
3324 for( const char* token : { "(is_time_domain", "(target_delay", "(last_tuning_length" } )
3325 BOOST_CHECK( outputBytes.find( token ) == std::string::npos );
3326
3327 STRING_FORMATTER quoting;
3328 BOOST_CHECK( outputBytes.find( "(last_tuning " + quoting.Quotew( tuningInfo ) + ")" )
3329 != std::string::npos );
3330 }
3331 else
3332 {
3333 BOOST_CHECK( outputBytes.find( "(is_time_domain yes)" ) != std::string::npos );
3334 BOOST_CHECK( outputBytes.find( "(last_tuning_length " ) != std::string::npos );
3335 BOOST_CHECK( outputBytes.find( "(last_tuning " ) == std::string::npos );
3336 }
3337
3338 std::unique_ptr<BOARD> exported( io.LoadBoard( dest, nullptr ) );
3339 BOOST_REQUIRE( exported );
3340 BOOST_CHECK_EQUAL( exported->GetFileFormatVersionAtLoad(), target.m_boardVersion );
3341 BOOST_REQUIRE_EQUAL( exported->Generators().size(), preTen ? 1u : 2u );
3342 BOOST_REQUIRE_EQUAL( exported->Groups().size(), 1u );
3343 BOOST_CHECK( exported->GroupsSanityCheck().IsEmpty() );
3344 PCB_GROUP* exportedOuter = *exported->Groups().begin();
3345 BOOST_CHECK( exportedOuter->m_Uuid == outer->m_Uuid );
3346 std::set<KIID> expectedOuter{ length->m_Uuid };
3347
3348 if( preTen )
3349 expectedOuter.insert( timeMembers.begin(), timeMembers.end() );
3350 else
3351 expectedOuter.insert( time->m_Uuid );
3352
3353 BOOST_CHECK( memberIds( *exportedOuter ) == expectedOuter );
3354 BOOST_REQUIRE_EQUAL( exported->Tracks().size(), copper.size() );
3355
3356 for( const PCB_TRACK* track : exported->Tracks() )
3357 {
3358 const auto found = copper.find( track->m_Uuid );
3359 BOOST_REQUIRE( found != copper.end() );
3360 const PCB_TRACK* original = found->second;
3361 BOOST_CHECK( track->Type() == original->Type() );
3362 BOOST_CHECK( track->GetStart() == original->GetStart() );
3363 BOOST_CHECK( track->GetEnd() == original->GetEnd() );
3364 BOOST_CHECK( track->GetLayerSet() == original->GetLayerSet() );
3365 BOOST_CHECK_EQUAL( track->GetWidth(), original->GetWidth() );
3366 BOOST_CHECK_EQUAL( track->GetNetname().ToStdString(), original->GetNetname().ToStdString() );
3367
3368 if( const PCB_ARC* arc = dynamic_cast<const PCB_ARC*>( original ) )
3369 {
3370 const PCB_ARC* exportedArc = dynamic_cast<const PCB_ARC*>( track );
3371 BOOST_REQUIRE( exportedArc );
3372 BOOST_CHECK( exportedArc->GetMid() == arc->GetMid() );
3373 }
3374
3375 if( timeMembers.count( track->m_Uuid ) && preTen )
3376 BOOST_CHECK( track->GetParentGroup() == static_cast<EDA_GROUP*>( exportedOuter ) );
3377 else if( track->m_Uuid == control->m_Uuid )
3378 BOOST_CHECK( !track->GetParentGroup() );
3379 }
3380
3381 for( PCB_GENERATOR* generator : exported->Generators() )
3382 {
3383 auto pattern = dynamic_cast<PCB_TUNING_PATTERN*>( generator );
3384 BOOST_REQUIRE( pattern );
3385 BOOST_CHECK( pattern->GetParentGroup() == static_cast<EDA_GROUP*>( exportedOuter ) );
3386 BOOST_CHECK( pattern->m_Uuid == length->m_Uuid || ( !preTen && pattern->m_Uuid == time->m_Uuid ) );
3387 const bool isTime = pattern->m_Uuid == time->m_Uuid;
3388 BOOST_CHECK( pattern->GetSettings().m_isTimeDomain == isTime );
3389 BOOST_CHECK( memberIds( *pattern ) == ( isTime ? timeMembers : lengthMembers ) );
3390 const PCB_TUNING_PATTERN* original = isTime ? time : length;
3391 const auto properties = pattern->GetProperties();
3392 const auto originalProperties = original->GetProperties();
3393
3394 for( const char* key :
3395 { "target_length", "target_length_min", "target_length_max", "target_skew", "target_skew_min",
3396 "target_skew_max", "min_spacing", "max_amplitude", "min_amplitude" } )
3397 {
3398 double value = 0;
3399 double originalValue = 0;
3400 BOOST_REQUIRE( properties.get_to( key, value ) );
3401 BOOST_REQUIRE( originalProperties.get_to( key, originalValue ) );
3402 BOOST_CHECK_EQUAL( value, originalValue );
3403 }
3404
3405 if( !preTen )
3406 {
3407 for( const char* key :
3408 { "target_delay", "target_delay_min", "target_delay_max", "last_tuning_length" } )
3409 {
3410 double value = 0;
3411 double originalValue = 0;
3412 BOOST_REQUIRE( properties.get_to( key, value ) );
3413 BOOST_REQUIRE( originalProperties.get_to( key, originalValue ) );
3414 BOOST_CHECK_EQUAL( value, originalValue );
3415 }
3416 }
3417 }
3418
3419 BOOST_CHECK_EQUAL( serializeNative( &board ), sourceModel );
3420 BOOST_CHECK_EQUAL( KI_TEST::ReadGoldenText( src ), sourceBytes );
3421 BOOST_CHECK_EQUAL( KI_TEST::ReadGoldenText( lengthPath ), lengthBytes );
3422 BOOST_CHECK_EQUAL( KI_TEST::ReadGoldenText( timePath ), timeBytes );
3423 }
3424 }
3425 }
3426}
3427
3428
3429BOOST_AUTO_TEST_CASE( UnreviewedTuningPropertiesBlockBothTargetsAndPolicies )
3430{
3431 class UNREVIEWED_TUNING_PATTERN : public PCB_TUNING_PATTERN
3432 {
3433 public:
3435
3436 const STRING_ANY_MAP GetProperties() const override
3437 {
3439 properties.set( "future_tuning_setting", true );
3440 return properties;
3441 }
3442 };
3443
3444 BOARD board;
3445 auto pattern = new UNREVIEWED_TUNING_PATTERN( &board );
3446 auto track = new PCB_TRACK( &board );
3447 track->SetStart( VECTOR2I( 1000000, 2000000 ) );
3448 track->SetEnd( VECTOR2I( 3000000, 2000000 ) );
3449 board.Add( track );
3450 board.Add( pattern );
3451 pattern->AddItem( track );
3452
3453 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
3454 {
3455 for( bool drop : { false, true } )
3456 {
3457 const auto report = ClassifyBoardForDowngrade( &board, target, drop );
3458 checkFeature( report, wxT( "Unreviewed tuning properties" ), DOWNGRADE_BUCKET::BLOCK, 1 );
3459 BOOST_REQUIRE_EQUAL( board.Generators().size(), 1u );
3460 BOOST_CHECK( track->GetParentGroup() == static_cast<EDA_GROUP*>( pattern ) );
3461 }
3462 }
3463
3464 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_unreviewed_tuning" );
3465
3466 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
3467 {
3468 const wxString path = ( tmp.Path() / ( target.m_id.ToStdString() + ".kicad_pcb" ) ).wstring();
3469 BOOST_CHECK_THROW( SaveBoardForTarget( &board, path, target ), IO_ERROR );
3470 }
3471}
3472
3473
3474BOOST_AUTO_TEST_CASE( HistoricalTuningWritersRejectUnsafeDirectSerialization )
3475{
3476 BOARD board;
3477 auto pattern = new PCB_TUNING_PATTERN( &board );
3478 pattern->SetTargetDelay( 100000 );
3479 auto track = new PCB_TRACK( &board );
3480 track->SetStart( VECTOR2I( 1000000, 2000000 ) );
3481 track->SetEnd( VECTOR2I( 3000000, 2000000 ) );
3482 board.Add( track );
3483 board.Add( pattern );
3484 pattern->AddItem( track );
3485 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_direct_time_tuning" );
3486 BOOST_CHECK_THROW( SaveBoardForTarget( &board, ( tmp.Path() / "unsafe.kicad_pcb" ).wstring(), kicad9 ), IO_ERROR );
3487
3488 for( const char* token :
3489 { "is_time_domain", "target_delay", "target_delay_min", "target_delay_max", "last_tuning_length" } )
3490 {
3491 const wxString value = wxString::FromUTF8( "(kicad_pcb (generated (" + std::string( token ) + " 0)))" );
3492 BOOST_CHECK_EQUAL( FindUnsupportedBoardToken( value, kicad9 ), wxString::FromUTF8( token ) );
3493 BOOST_CHECK( FindUnsupportedBoardToken( value, kicad10 ).IsEmpty() );
3494 }
3495}
3496
3497
3498BOOST_AUTO_TEST_CASE( HistoricalWritersRejectDirectViaGeneratorsAtomically )
3499{
3500 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_direct_via_generators" );
3501
3502 for( bool stack : { false, true } )
3503 {
3504 BOARD board;
3505
3506 if( stack )
3507 board.Add( new PCB_VIA_STACK( &board ) );
3508 else
3509 board.Add( new PCB_VIA_STITCH( &board ) );
3510
3511 const std::string kind = stack ? "via-stack" : "via-stitch";
3512
3513 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
3514 {
3515 BOOST_TEST_CONTEXT( kind << " target=" << target.m_id.ToStdString() )
3516 {
3517 const auto absent = tmp.Path() / ( kind + "-" + target.m_id.ToStdString() + "-absent.kicad_pcb" );
3518 BOOST_CHECK_THROW( SaveBoardForTarget( &board, absent.wstring(), target ), IO_ERROR );
3519 BOOST_CHECK( !wxFileExists( absent.wstring() ) );
3520
3521 const auto existing = tmp.Path() / ( kind + "-" + target.m_id.ToStdString() + "-existing.kicad_pcb" );
3522
3523 {
3524 std::ofstream sentinel( existing, std::ios::binary );
3525 sentinel << "existing destination";
3526 BOOST_REQUIRE( sentinel.good() );
3527 }
3528
3529 BOOST_CHECK_THROW( SaveBoardForTarget( &board, existing.wstring(), target ), IO_ERROR );
3530 BOOST_CHECK_EQUAL( KI_TEST::ReadGoldenText( existing.string() ), "existing destination" );
3531 }
3532 }
3533 }
3534}
3535
3536
3537BOOST_AUTO_TEST_CASE( NativeGroupPlacementFixtureKeepsGeometryAndOwnershipForBothPolicies )
3538{
3539 SETTINGS_MANAGER settingsManager;
3540 const std::string src =
3541 KI_TEST::GetPcbnewTestDataDir() + "../downgrade/regressions/group_placement/group_placement.kicad_pcb";
3542 wxFileName projectFile( wxString::FromUTF8( src ) );
3543 projectFile.SetExt( wxT( "kicad_pro" ) );
3544 BOOST_REQUIRE( wxFileExists( projectFile.GetFullPath() ) );
3545 BOOST_REQUIRE( settingsManager.LoadProject( projectFile.GetFullPath(), false ) );
3546 const std::string sourceBytes = KI_TEST::ReadGoldenText( src );
3548 std::unique_ptr<BOARD> source( io.LoadBoard( src, nullptr ) );
3550 BOOST_REQUIRE_EQUAL( source->Zones().size(), 7u );
3551 BOOST_REQUIRE_EQUAL( source->Groups().size(), 4u );
3552 BOOST_REQUIRE_EQUAL( source->Footprints().size(), 4u );
3553 BOOST_REQUIRE( source->GroupsSanityCheck().IsEmpty() );
3554 std::map<KIID, const PCB_TEXT*> sourceNotes;
3555
3556 for( const BOARD_ITEM* drawing : source->Drawings() )
3557 {
3558 if( const PCB_TEXT* note = dynamic_cast<const PCB_TEXT*>( drawing ) )
3559 BOOST_REQUIRE( sourceNotes.emplace( note->m_Uuid, note ).second );
3560 }
3561
3562 BOOST_REQUIRE_EQUAL( sourceNotes.size(), 1u );
3563 std::map<KIID, const ZONE*> sourceZones;
3564 int placementAreas = 0;
3565 int filledOutlines = 0;
3566
3567 for( const ZONE* zone : source->Zones() )
3568 {
3569 BOOST_REQUIRE( sourceZones.emplace( zone->m_Uuid, zone ).second );
3570
3571 if( zone->GetPlacementAreaSourceType() == PLACEMENT_SOURCE_T::GROUP_PLACEMENT )
3572 {
3573 ++placementAreas;
3574 BOOST_REQUIRE( zone->GetPlacementAreaEnabled() );
3575 BOOST_REQUIRE( !zone->GetPlacementAreaSource().IsEmpty() );
3576 }
3577
3578 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
3579 filledOutlines += zone->GetFilledPolysList( layer )->OutlineCount();
3580 }
3581
3582 BOOST_REQUIRE_EQUAL( placementAreas, 4 );
3583 BOOST_REQUIRE_GT( filledOutlines, 0 );
3584 const auto memberIds = []( const PCB_GROUP& aGroup )
3585 {
3586 std::set<KIID> ids;
3587
3588 for( const EDA_ITEM* member : aGroup.GetItems() )
3589 BOOST_REQUIRE( ids.insert( member->m_Uuid ).second );
3590
3591 return ids;
3592 };
3593 const auto checkPolygons = []( const SHAPE_POLY_SET& aOriginal, const SHAPE_POLY_SET& aExported )
3594 {
3595 BOOST_REQUIRE_EQUAL( aExported.OutlineCount(), aOriginal.OutlineCount() );
3596
3597 for( int outline = 0; outline < aOriginal.OutlineCount(); ++outline )
3598 {
3599 BOOST_CHECK( aExported.COutline( outline ).CompareGeometry( aOriginal.COutline( outline ) ) );
3600 BOOST_REQUIRE_EQUAL( aExported.HoleCount( outline ), aOriginal.HoleCount( outline ) );
3601
3602 for( int hole = 0; hole < aOriginal.HoleCount( outline ); ++hole )
3603 BOOST_CHECK( aExported.CHole( outline, hole ).CompareGeometry( aOriginal.CHole( outline, hole ) ) );
3604 }
3605 };
3606 const auto serializeNative = []( BOARD* aBoard )
3607 {
3608 STRING_FORMATTER formatter;
3609 PCB_IO_KICAD_SEXPR serializer;
3610 serializer.FormatBoardToFormatter( &formatter, aBoard );
3611 return formatter.GetString();
3612 };
3613 const std::string sourceModel = serializeNative( source.get() );
3614 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_native_group_placement" );
3615 BOOST_CHECK_THROW( SaveBoardForTarget( source.get(), ( tmp.Path() / "unsafe.kicad_pcb" ).wstring(), kicad9 ),
3616 IO_ERROR );
3617 BOOST_CHECK_EQUAL( serializeNative( source.get() ), sourceModel );
3618
3619 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
3620 {
3621 const bool preTen = target.m_boardVersion == kicad9.m_boardVersion;
3622
3623 for( bool drop : { false, true } )
3624 {
3625 BOOST_TEST_CONTEXT( target.m_id.ToStdString() << " drop=" << drop )
3626 {
3627 const auto preview = ClassifyBoardForDowngrade( source.get(), target, drop );
3628 BOOST_CHECK( !preview.IsBlocked() );
3629 BOOST_CHECK_EQUAL( preview.Count( DOWNGRADE_BUCKET::DROP ), preTen ? 4 : 0 );
3630 BOOST_CHECK_EQUAL( preview.Count( DOWNGRADE_BUCKET::LOWER ), 0 );
3631 BOOST_CHECK_EQUAL( serializeNative( source.get() ), sourceModel );
3632 const std::string dest =
3633 ( tmp.Path()
3634 / ( target.m_id.ToStdString() + ( drop ? "-drop.kicad_pcb" : "-lower.kicad_pcb" ) ) )
3635 .string();
3636 COMPATIBILITY_REPORT report;
3637 wxString unsupported;
3639 ExportBoardToOlderVersion( src, dest, target, report, &unsupported, wxEmptyString, drop ) );
3640 BOOST_CHECK( unsupported.IsEmpty() );
3641 BOOST_CHECK( !report.IsBlocked() );
3642 BOOST_CHECK_EQUAL( report.Count( DOWNGRADE_BUCKET::DROP ), preTen ? 4 : 0 );
3644 BOOST_REQUIRE_EQUAL( report.Entries().size(), preTen ? 1u : 0u );
3645
3646 if( preTen )
3647 checkFeature( report, wxT( "Group placement areas" ), DOWNGRADE_BUCKET::DROP, 4 );
3648
3649 const std::string outputBytes = KI_TEST::ReadGoldenText( dest );
3650 BOOST_CHECK( FindUnsupportedBoardToken( wxString::FromUTF8( outputBytes ), target ).IsEmpty() );
3651 std::unique_ptr<BOARD> exported( io.LoadBoard( dest, nullptr ) );
3652 BOOST_REQUIRE( exported );
3653 BOOST_CHECK_EQUAL( exported->GetFileFormatVersionAtLoad(), target.m_boardVersion );
3654 BOOST_REQUIRE_EQUAL( exported->Zones().size(), source->Zones().size() );
3655 BOOST_REQUIRE_EQUAL( exported->Groups().size(), source->Groups().size() );
3656 BOOST_REQUIRE_EQUAL( exported->Footprints().size(), source->Footprints().size() );
3657 BOOST_CHECK( exported->GroupsSanityCheck().IsEmpty() );
3658
3659 for( const auto& [id, original] : sourceNotes )
3660 {
3661 const auto found = std::find_if( exported->Drawings().begin(), exported->Drawings().end(),
3662 [&]( const BOARD_ITEM* aItem )
3663 {
3664 return aItem->m_Uuid == id;
3665 } );
3666 BOOST_REQUIRE( found != exported->Drawings().end() );
3667 const PCB_TEXT* note = dynamic_cast<const PCB_TEXT*>( *found );
3668 BOOST_REQUIRE( note );
3669 BOOST_CHECK( note->GetText() == original->GetText() );
3670 BOOST_CHECK( note->GetPosition() == original->GetPosition() );
3671 BOOST_CHECK( note->GetLayer() == original->GetLayer() );
3672 }
3673
3674 for( const ZONE* zone : exported->Zones() )
3675 {
3676 const auto found = sourceZones.find( zone->m_Uuid );
3677 BOOST_REQUIRE( found != sourceZones.end() );
3678 const ZONE* original = found->second;
3679 BOOST_CHECK( zone->GetZoneName() == original->GetZoneName() );
3680 BOOST_CHECK( zone->GetLayerSet() == original->GetLayerSet() );
3681 BOOST_CHECK( zone->GetIsRuleArea() == original->GetIsRuleArea() );
3682 BOOST_CHECK( zone->GetDoNotAllowTracks() == original->GetDoNotAllowTracks() );
3683 BOOST_CHECK( zone->GetDoNotAllowVias() == original->GetDoNotAllowVias() );
3684 BOOST_CHECK( zone->GetDoNotAllowPads() == original->GetDoNotAllowPads() );
3685 BOOST_CHECK( zone->GetDoNotAllowZoneFills() == original->GetDoNotAllowZoneFills() );
3686 BOOST_CHECK( zone->GetDoNotAllowFootprints() == original->GetDoNotAllowFootprints() );
3687 BOOST_CHECK( zone->GetNetname() == original->GetNetname() );
3688 BOOST_CHECK( zone->IsFilled() == original->IsFilled() );
3689 checkPolygons( original->GetBoardOutline(), zone->GetBoardOutline() );
3690
3691 for( PCB_LAYER_ID layer : original->GetLayerSet().Seq() )
3692 {
3693 const auto originalFill = original->GetFilledPolysList( layer );
3694 const auto exportedFill = zone->GetFilledPolysList( layer );
3695 checkPolygons( *originalFill, *exportedFill );
3696
3697 for( int outline = 0; outline < originalFill->OutlineCount(); ++outline )
3698 BOOST_CHECK( zone->IsIsland( layer, outline ) == original->IsIsland( layer, outline ) );
3699 }
3700
3702 {
3703 BOOST_CHECK( !zone->GetPlacementAreaEnabled() );
3704 BOOST_CHECK( zone->GetPlacementAreaSource().IsEmpty() );
3705 BOOST_CHECK( zone->GetPlacementAreaSourceType() == PLACEMENT_SOURCE_T::SHEETNAME );
3706 }
3707 else
3708 {
3709 BOOST_CHECK( zone->GetPlacementAreaEnabled() == original->GetPlacementAreaEnabled() );
3710 BOOST_CHECK( zone->GetPlacementAreaSource() == original->GetPlacementAreaSource() );
3711 BOOST_CHECK( zone->GetPlacementAreaSourceType() == original->GetPlacementAreaSourceType() );
3712 }
3713 }
3714
3715 for( const PCB_GROUP* group : exported->Groups() )
3716 {
3717 const auto original = std::find_if( source->Groups().begin(), source->Groups().end(),
3718 [&]( const PCB_GROUP* aGroup )
3719 {
3720 return aGroup->m_Uuid == group->m_Uuid;
3721 } );
3722 BOOST_REQUIRE( original != source->Groups().end() );
3723 BOOST_CHECK( group->GetName() == ( *original )->GetName() );
3724 BOOST_CHECK( memberIds( *group ) == memberIds( **original ) );
3725 }
3726
3727 std::map<KIID, const PAD*> sourcePads;
3728
3729 for( const PAD* pad : source->GetPads() )
3730 BOOST_REQUIRE( sourcePads.emplace( pad->m_Uuid, pad ).second );
3731
3732 BOOST_REQUIRE_EQUAL( sourcePads.size(), 8u );
3733 BOOST_REQUIRE_EQUAL( exported->GetPads().size(), sourcePads.size() );
3734
3735 for( const PAD* pad : exported->GetPads() )
3736 {
3737 const auto found = sourcePads.find( pad->m_Uuid );
3738 BOOST_REQUIRE( found != sourcePads.end() );
3739 const PAD* original = found->second;
3740 BOOST_CHECK( pad->GetPosition() == original->GetPosition() );
3741 BOOST_CHECK( pad->GetOrientation() == original->GetOrientation() );
3742 BOOST_CHECK( pad->GetLayerSet() == original->GetLayerSet() );
3743 BOOST_CHECK( pad->GetNetname() == original->GetNetname() );
3744 BOOST_CHECK( pad->GetShape( F_Cu ) == original->GetShape( F_Cu ) );
3745 BOOST_CHECK( pad->GetSize( F_Cu ) == original->GetSize( F_Cu ) );
3746 BOOST_CHECK_EQUAL( pad->GetRoundRectRadiusRatio( F_Cu ),
3747 original->GetRoundRectRadiusRatio( F_Cu ) );
3748 }
3749
3750 BOOST_CHECK_EQUAL( serializeNative( source.get() ), sourceModel );
3751 BOOST_CHECK_EQUAL( KI_TEST::ReadGoldenText( src ), sourceBytes );
3752 }
3753 }
3754 }
3755}
3756
3757
3758BOOST_AUTO_TEST_CASE( GroupPlacementLinkageUsesTheSameFootprintPolicy )
3759{
3760 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
3761 {
3762 for( bool drop : { false, true } )
3763 {
3764 BOARD board;
3765 auto footprint = new FOOTPRINT( &board );
3766 auto zone = new ZONE( footprint );
3767 zone->SetIsRuleArea( true );
3768 zone->SetPlacementAreaEnabled( true );
3769 zone->SetPlacementAreaSourceType( PLACEMENT_SOURCE_T::GROUP_PLACEMENT );
3770 zone->SetPlacementAreaSource( wxT( "Repeated group" ) );
3771 zone->SetDoNotAllowTracks( true );
3772 footprint->Add( zone );
3773 board.Add( footprint );
3774 const auto report = ClassifyBoardForDowngrade( &board, target, drop );
3775 BOOST_CHECK_EQUAL( report.Count( DOWNGRADE_BUCKET::DROP ), target.m_id == kicad9.m_id ? 1 : 0 );
3776 BOOST_CHECK( zone->GetPlacementAreaEnabled() );
3777 DowngradeFootprintInPlace( footprint, target, drop );
3778 BOOST_CHECK( zone->GetIsRuleArea() );
3779 BOOST_CHECK( zone->GetDoNotAllowTracks() );
3780 BOOST_CHECK( zone->GetPlacementAreaEnabled() == ( target.m_id == kicad10.m_id ) );
3781 BOOST_CHECK( zone->GetPlacementAreaSource()
3782 == ( target.m_id == kicad10.m_id ? wxT( "Repeated group" ) : wxEmptyString ) );
3783 }
3784 }
3785}
3786
3787
3788BOOST_AUTO_TEST_CASE( GroupPlacementGuardIgnoresOrdinaryGroupsAndQuotedText )
3789{
3790 BOOST_CHECK( FindUnsupportedBoardToken( wxT( "(zone (placement (group \"SourceA\")))" ), kicad9 )
3791 == wxT( "placement/group" ) );
3792 BOOST_CHECK( FindUnsupportedBoardToken( wxT( "(zone (placement (group \"SourceA\")))" ), kicad10 ).IsEmpty() );
3793 BOOST_CHECK( FindUnsupportedBoardToken( wxT( "(group \"Ordinary\" (members \"uuid\"))" ), kicad9 ).IsEmpty() );
3794 BOOST_CHECK( FindUnsupportedBoardToken( wxT( "(gr_text \"(zone (placement (group foo)))\")" ), kicad9 ).IsEmpty() );
3795}
3796
3797
3798BOOST_AUTO_TEST_CASE( InertGroupPlacementMetadataDoesNotRequireConsent )
3799{
3800 for( bool drop : { false, true } )
3801 {
3802 BOARD board;
3803 auto emptyRuleArea = new ZONE( &board );
3804 emptyRuleArea->SetIsRuleArea( true );
3805 emptyRuleArea->SetPlacementAreaSourceType( PLACEMENT_SOURCE_T::GROUP_PLACEMENT );
3806 board.Add( emptyRuleArea );
3807 auto ordinaryZone = new ZONE( &board );
3808 ordinaryZone->SetPlacementAreaSourceType( PLACEMENT_SOURCE_T::GROUP_PLACEMENT );
3809 ordinaryZone->SetPlacementAreaEnabled( true );
3810 ordinaryZone->SetPlacementAreaSource( wxT( "Unused by ordinary copper zones" ) );
3811 board.Add( ordinaryZone );
3812 BOOST_CHECK( !ClassifyBoardForDowngrade( &board, kicad9, drop ).IsLossy() );
3813 DowngradeBoardInPlace( &board, kicad9, drop );
3814 BOOST_CHECK( emptyRuleArea->GetIsRuleArea() );
3815 BOOST_CHECK( !ordinaryZone->GetIsRuleArea() );
3816 BOOST_CHECK( emptyRuleArea->GetPlacementAreaSourceType() == PLACEMENT_SOURCE_T::SHEETNAME );
3817 BOOST_CHECK( ordinaryZone->GetPlacementAreaSourceType() == PLACEMENT_SOURCE_T::SHEETNAME );
3818 }
3819}
3820
3821
3822BOOST_AUTO_TEST_CASE( UnreviewedGeneratorKindBlocksBothPolicies )
3823{
3824 class FUTURE_GENERATOR : public PCB_VIA_STITCH
3825 {
3826 public:
3827 explicit FUTURE_GENERATOR( BOARD* aBoard ) :
3828 PCB_VIA_STITCH( aBoard )
3829 {
3830 }
3831 wxString GetGeneratorType() const override { return wxT( "future_generator" ); }
3832 };
3833
3834 BOARD board;
3835 board.Add( new FUTURE_GENERATOR( &board ) );
3836
3837 for( bool drop : { false, true } )
3838 BOOST_CHECK( ClassifyBoardForDowngrade( &board, kicad10, drop ).IsBlocked() );
3839}
3840
3841
3842BOOST_AUTO_TEST_CASE( LineEndingsLowerPrintedInkOrDropOnlyEmbellishments )
3843{
3844 for( bool drop : { false, true } )
3845 {
3846 BOARD board;
3847 FOOTPRINT* fp = new FOOTPRINT( &board );
3848 board.Add( fp );
3849 std::vector<PCB_SHAPE*> shapes;
3850 double expectedArea = 0;
3851
3852 for( BOARD_ITEM_CONTAINER* parent :
3853 { static_cast<BOARD_ITEM_CONTAINER*>( &board ), static_cast<BOARD_ITEM_CONTAINER*>( fp ) } )
3854 {
3855 PCB_SHAPE* shape = new PCB_SHAPE( parent, SHAPE_T::SEGMENT );
3856 shape->SetStart( VECTOR2I( 0, 0 ) );
3857 shape->SetEnd( VECTOR2I( 10000000, 0 ) );
3858 shape->SetWidth( 200000 );
3859 shape->SetLayer( F_SilkS );
3860 shape->SetEndEnding( LINE_ENDING( LINE_ENDING_STYLE::ARROW, 2000000, 1000000 ) );
3861 parent->Add( shape );
3862 shapes.push_back( shape );
3863 SHAPE_POLY_SET ink;
3864 shape->TransformWithLineEndingsToPolygon( ink, 0, 5000, ERROR_INSIDE );
3865 ink.Simplify();
3866 expectedArea += ink.Area();
3867 }
3868
3869 const auto report = ClassifyBoardForDowngrade( &board, kicad10, drop );
3870 checkFeature( report, wxT( "Graphic line endings" ), drop ? DOWNGRADE_BUCKET::DROP : DOWNGRADE_BUCKET::LOWER,
3871 2 );
3872 DowngradeBoardInPlace( &board, kicad10, drop );
3873
3874 if( drop )
3875 {
3876 for( PCB_SHAPE* shape : shapes )
3877 {
3878 BOOST_CHECK( shape->GetShape() == SHAPE_T::SEGMENT );
3879 BOOST_CHECK( shape->GetEnd() == VECTOR2I( 10000000, 0 ) );
3880 BOOST_CHECK( shape->GetEndEndingStyle() == LINE_ENDING_STYLE::NONE );
3881 }
3882 }
3883 else
3884 {
3885 double area = 0;
3886
3887 for( BOARD_ITEM* item : board.Drawings() )
3888 area += static_cast<PCB_SHAPE*>( item )->GetPolyShape().Area();
3889
3890 for( BOARD_ITEM* item : fp->GraphicalItems() )
3891 area += static_cast<PCB_SHAPE*>( item )->GetPolyShape().Area();
3892
3893 BOOST_CHECK_CLOSE( area, expectedArea, 0.05 );
3894 }
3895 }
3896}
3897
3898
3899BOOST_AUTO_TEST_CASE( DashedEndedLinesBlockApproximationButAllowDroppingEndings )
3900{
3901 BOARD board;
3902 PCB_SHAPE* line = new PCB_SHAPE( &board, SHAPE_T::SEGMENT );
3903 line->SetStart( VECTOR2I( 0, 0 ) );
3904 line->SetEnd( VECTOR2I( 10000000, 0 ) );
3905 line->SetWidth( 200000 );
3908 board.Add( line );
3909 BOOST_CHECK( ClassifyBoardForDowngrade( &board, kicad10 ).IsBlocked() );
3910 BOOST_CHECK( !ClassifyBoardForDowngrade( &board, kicad10, true ).IsBlocked() );
3911 DowngradeBoardInPlace( &board, kicad10, true );
3914}
3915
3916
3917BOOST_AUTO_TEST_CASE( CustomPropertiesBakeOnlyAffectedVariablesBeforeRemoval )
3918{
3919 for( bool footprintOnly : { false, true } )
3920 {
3921 BOARD board;
3922 FOOTPRINT* fp = new FOOTPRINT( &board );
3923 fp->SetReference( wxT( "42" ) );
3924 fp->SetCustomProperty( wxT( "Serial" ), wxT( "42" ) );
3925 fp->Value().SetText( wxT( "${PROPERTY.Reference}/${REFERENCE}" ) );
3926 fp->Reference().SetCustomProperty( wxT( "Owner" ), wxT( "Engineering" ) );
3927 PCB_TEXT* escaped = new PCB_TEXT( fp );
3928 escaped->SetText( wxT( "\\${PROPERTY.Serial}" ) );
3929 fp->Add( escaped );
3930 PCB_TEXT* expression = new PCB_TEXT( fp );
3931 expression->SetText( wxT( "@{${PROPERTY.Reference}+1}/${REFERENCE}" ) );
3932 fp->Add( expression );
3933 board.Add( fp );
3934 const auto report = ClassifyBoardForDowngrade( &board, kicad10 );
3935 checkFeature( report, wxT( "Custom properties" ), DOWNGRADE_BUCKET::DROP, 2 );
3936 BOOST_CHECK( !report.IsBlocked() );
3937
3938 if( footprintOnly )
3940 else
3941 DowngradeBoardInPlace( &board, kicad10 );
3942
3945 BOOST_CHECK_EQUAL( fp->Value().GetText(), wxString( "42/${REFERENCE}" ) );
3946 BOOST_CHECK_EQUAL( expression->GetText(), wxString( "43/${REFERENCE}" ) );
3947 BOOST_CHECK_EQUAL( escaped->GetText(), wxString( "\\${PROPERTY.Serial}" ) );
3948 }
3949}
3950
3951
3952BOOST_AUTO_TEST_CASE( UnresolvedPropertyVariablesBlockBothPolicies )
3953{
3954 BOARD board;
3955 FOOTPRINT* fp = new FOOTPRINT( &board );
3956 fp->Value().SetText( wxT( "${PROPERTY.Missing}" ) );
3957 board.Add( fp );
3958
3959 for( bool drop : { false, true } )
3960 BOOST_CHECK( ClassifyBoardForDowngrade( &board, kicad10, drop ).IsBlocked() );
3961}
3962
3963
3964BOOST_AUTO_TEST_CASE( UsedProjectVariablesBakeInFootprintContextAndUnusedDefinitionsDoNotBlock )
3965{
3966 KI_TEST::SCOPED_TEMP_DIR tmp( "kicad_qa_property_dependencies" );
3967 const wxString projectPath = ( tmp.Path() / "source.kicad_pro" ).string();
3968
3969 {
3970 std::ofstream project( projectPath.ToStdString() );
3971 project << R"({"meta":{"version":4},"text_variables":{"SERIAL":"${PROPERTY.Reference}","ALIAS":"${SERIAL}","UNUSED":"${PROPERTY.Missing}"}})";
3972 }
3973
3974 SETTINGS_MANAGER settings;
3975 BOOST_REQUIRE( settings.LoadProject( projectPath, false ) );
3976 BOARD board;
3977 board.SetProject( settings.GetProject( projectPath ), true );
3978
3979 std::vector<FOOTPRINT*> footprints;
3980
3981 for( const wxString& serial : { wxT( "42" ), wxT( "73" ) } )
3982 {
3983 FOOTPRINT* fp = new FOOTPRINT( &board );
3984 fp->SetReference( serial );
3985 fp->SetCustomProperty( wxT( "Serial" ), serial );
3986 fp->Value().SetText( wxT( "${ALIAS}/${REFERENCE}" ) );
3987 board.Add( fp );
3988 footprints.push_back( fp );
3989 }
3990
3991 BOOST_CHECK( !ClassifyBoardForDowngrade( &board, kicad10 ).IsBlocked() );
3992 DowngradeBoardInPlace( &board, kicad10 );
3993 BOOST_CHECK_EQUAL( footprints[0]->Value().GetText(), wxString( "42/${REFERENCE}" ) );
3994 BOOST_CHECK_EQUAL( footprints[1]->Value().GetText(), wxString( "73/${REFERENCE}" ) );
3995
3996 footprints[0]->Value().SetText( wxT( "${UNUSED}" ) );
3997 BOOST_CHECK( ClassifyBoardForDowngrade( &board, kicad10 ).IsBlocked() );
3998 BOOST_CHECK( ClassifyBoardForDowngrade( &board, kicad10, true ).IsBlocked() );
3999}
4000
4001
4002BOOST_AUTO_TEST_CASE( CachedBoardVariableDependenciesBakeInFootprintContext )
4003{
4004 BOARD board;
4005 board.SetProperties( { { wxT( "SERIAL" ), wxT( "${PROPERTY.Reference}" ) },
4006 { wxT( "UNUSED" ), wxT( "${PROPERTY.Missing}" ) } } );
4007 FOOTPRINT* fp = new FOOTPRINT( &board );
4008 fp->SetReference( wxT( "42" ) );
4009 fp->Value().SetText( wxT( "${SERIAL}/${REFERENCE}" ) );
4010 board.Add( fp );
4011 BOOST_CHECK( !ClassifyBoardForDowngrade( &board, kicad10 ).IsBlocked() );
4012 DowngradeBoardInPlace( &board, kicad10 );
4013 BOOST_CHECK_EQUAL( fp->Value().GetText(), wxString( "42/${REFERENCE}" ) );
4014}
4015
4016
4017BOOST_AUTO_TEST_CASE( MixedPropertyTextKeepsEscapedLiteralsAndSupportedVariables )
4018{
4019 BOARD board;
4020 FOOTPRINT* fp = new FOOTPRINT( &board );
4021 fp->SetReference( wxT( "42" ) );
4022 fp->SetCustomProperty( wxT( "Serial" ), wxT( "42" ) );
4023 fp->SetKeywords( wxT( "\\${REFERENCE}/\\@{1+2}" ) );
4024 fp->Value().SetText( wxT( "${PROPERTY.Reference}/\\${U1:PROPERTY.Missing}/${REFERENCE}" ) );
4025 PCB_TEXT* text = new PCB_TEXT( fp );
4026 text->SetText( wxT( "${PROPERTY.Keywords}/${REFERENCE}" ) );
4027 fp->Add( text );
4028 board.Add( fp );
4029 const wxString shown = text->GetShownText( FOR_CANVAS );
4030 BOOST_CHECK( !ClassifyBoardForDowngrade( &board, kicad10 ).IsBlocked() );
4031 DowngradeBoardInPlace( &board, kicad10 );
4032 BOOST_CHECK_EQUAL( fp->Value().GetText(), wxString( "42/\\${U1:PROPERTY.Missing}/${REFERENCE}" ) );
4033 BOOST_CHECK( !text->GetText().Contains( wxT( "PROPERTY." ) ) );
4034 BOOST_CHECK_EQUAL( text->GetShownText( FOR_CANVAS ), shown );
4035}
4036
4037
4038BOOST_AUTO_TEST_CASE( NewExpressionUnitAliasIsBakedWithoutFreezingOtherVariables )
4039{
4040 BOARD board;
4041 FOOTPRINT* fp = new FOOTPRINT( &board );
4042 fp->SetReference( wxT( "U1" ) );
4043 fp->Value().SetText( wxT( "@{1000mils}/${REFERENCE}" ) );
4044 board.Add( fp );
4045 BOOST_CHECK( !ClassifyBoardForDowngrade( &board, kicad10 ).IsBlocked() );
4046 DowngradeBoardInPlace( &board, kicad10 );
4047 BOOST_CHECK_EQUAL( fp->Value().GetText(), wxString( "25.4/${REFERENCE}" ) );
4048}
4049
4050
4051BOOST_AUTO_TEST_CASE( UnresolvedAffectedExpressionsBlockBothPolicies )
4052{
4053 for( const wxString& raw :
4054 { wxT( "@{${PROPERTY.Reference}+${MISSING}}" ), wxT( "@{unknown_function(${PROPERTY.Reference})}" ) } )
4055 {
4056 BOARD board;
4057 FOOTPRINT* fp = new FOOTPRINT( &board );
4058 fp->SetReference( wxT( "42" ) );
4059 fp->SetCustomProperty( wxT( "Serial" ), wxT( "42" ) );
4060 fp->Value().SetText( raw );
4061 board.Add( fp );
4062
4063 for( bool drop : { false, true } )
4064 BOOST_CHECK( ClassifyBoardForDowngrade( &board, kicad10, drop ).IsBlocked() );
4065 }
4066}
4067
4068
4069BOOST_AUTO_TEST_CASE( EscapedTextControlsBlockKicad9AndRemainLiteralInKicad10 )
4070{
4071 for( bool inProperty : { false, true } )
4072 {
4073 BOARD board;
4074 FOOTPRINT* fp = new FOOTPRINT( &board );
4075 fp->SetReference( wxT( "U1" ) );
4076 const wxString literal = wxT( "\\${REFERENCE}/\\@{1+2}" );
4077 fp->SetKeywords( literal );
4078 fp->Value().SetText( inProperty ? wxString( wxT( "${PROPERTY.Keywords}" ) ) : literal );
4079 board.Add( fp );
4080 const wxString shown = fp->Value().GetShownText( FOR_CANVAS );
4081
4082 for( bool drop : { false, true } )
4083 {
4084 BOOST_CHECK( ClassifyBoardForDowngrade( &board, kicad9, drop ).IsBlocked() );
4085 BOOST_CHECK( !ClassifyBoardForDowngrade( &board, kicad10, drop ).IsBlocked() );
4086 }
4087
4088 DowngradeBoardInPlace( &board, kicad10 );
4090 }
4091}
4092
4093
4094BOOST_AUTO_TEST_CASE( TitleBlockExpressionsBakeBeforeDependentFootprintText )
4095{
4096 for( bool drop : { false, true } )
4097 {
4098 BOARD board;
4099 board.GetTitleBlock().SetTitle( wxT( "@{1000mils}" ) );
4100 FOOTPRINT* fp = new FOOTPRINT( &board );
4101 fp->SetReference( wxT( "U1" ) );
4102 fp->Value().SetText( wxT( "${TITLE}/${REFERENCE}" ) );
4103 board.Add( fp );
4104 const auto report = ClassifyBoardForDowngrade( &board, kicad10, drop );
4105 BOOST_CHECK( !report.IsBlocked() );
4106 checkFeature( report, wxT( "Post-target text variables" ), DOWNGRADE_BUCKET::DROP, 2 );
4107 DowngradeBoardInPlace( &board, kicad10, drop );
4108 BOOST_CHECK_EQUAL( board.GetTitleBlock().GetTitle(), wxString( "25.4" ) );
4109 BOOST_CHECK_EQUAL( fp->Value().GetText(), wxString( "25.4/${REFERENCE}" ) );
4110 }
4111}
4112
4113
4114BOOST_AUTO_TEST_CASE( TitleBlockUnresolvablePropertyContextBlocksBothPolicies )
4115{
4116 BOARD board;
4117 board.GetTitleBlock().SetComment( 0, wxT( "${PROPERTY.Reference}" ) );
4118
4119 for( bool drop : { false, true } )
4120 BOOST_CHECK( ClassifyBoardForDowngrade( &board, kicad10, drop ).IsBlocked() );
4121}
4122
4123
4124BOOST_AUTO_TEST_CASE( TitleBlockSelfReferenceDoesNotHideUsedProjectDependencies )
4125{
4126 KI_TEST::SCOPED_TEMP_DIR temporary( "kicad_qa_title_dependencies" );
4127 const wxString projectPath = ( temporary.Path() / "source.kicad_pro" ).string();
4128
4129 {
4130 std::ofstream project( projectPath.ToStdString() );
4131 project << R"({"meta":{"version":4},"text_variables":{"TITLE":"${PROPERTY.Reference}"}})";
4132 }
4133
4134 SETTINGS_MANAGER settings;
4135 BOOST_REQUIRE( settings.LoadProject( projectPath, false ) );
4136 BOARD board;
4137 board.SetProject( settings.GetProject( projectPath ), true );
4138 board.GetTitleBlock().SetTitle( wxT( "${TITLE}" ) );
4139 FOOTPRINT* fp = new FOOTPRINT( &board );
4140 fp->SetReference( wxT( "42" ) );
4141 fp->Value().SetText( wxT( "${TITLE}" ) );
4142 board.Add( fp );
4143 BOOST_CHECK_EQUAL( fp->Value().GetShownText( FOR_CANVAS ), wxString( "42" ) );
4144
4145 for( bool drop : { false, true } )
4146 BOOST_CHECK( ClassifyBoardForDowngrade( &board, kicad10, drop ).IsBlocked() );
4147
4148 board.GetTitleBlock().SetTitle( wxT( "Ordinary title" ) );
4149 const auto report = ClassifyBoardForDowngrade( &board, kicad10 );
4150 BOOST_CHECK( !report.IsBlocked() );
4151 BOOST_CHECK( !report.IsLossy() );
4152}
4153
4154
4155BOOST_AUTO_TEST_CASE( AffectedTableExpressionsUseNativeCellCoordinates )
4156{
4157 BOARD board;
4158 FOOTPRINT* fp = new FOOTPRINT( &board );
4159 fp->SetReference( wxT( "42" ) );
4160 board.Add( fp );
4161 PCB_TABLE* table = new PCB_TABLE( fp );
4162 table->SetColCount( 1 );
4163 table->SetColWidth( 0, 10000000 );
4164 table->SetRowHeight( 0, 6000000 );
4165 PCB_TABLECELL* cell = new PCB_TABLECELL( table );
4166 cell->SetText( wxT( "@{${PROPERTY.Reference}+${ROW}}/${COL}/${REFERENCE}" ) );
4167 table->AddCell( cell );
4168 fp->Add( table );
4169 BOOST_CHECK( !ClassifyBoardForDowngrade( &board, kicad10 ).IsBlocked() );
4170 DowngradeBoardInPlace( &board, kicad10 );
4171 BOOST_CHECK_EQUAL( cell->GetText(), wxString( "43/${COL}/${REFERENCE}" ) );
4172}
4173
4174
4175BOOST_AUTO_TEST_CASE( FootprintFileUsesTheSamePostMasterPoliciesAsBoardFootprints )
4176{
4177 SETTINGS_MANAGER settingsManager;
4178 KI_TEST::SCOPED_TEMP_DIR temporary( "kicad_qa_fp_post_master" );
4179 const wxString source = ( temporary.Path() / "source.kicad_mod" ).string();
4180 FOOTPRINT footprint( nullptr );
4181 footprint.SetReference( wxT( "42" ) );
4182 footprint.Value().SetText( wxT( "${PROPERTY.Reference}/${REFERENCE}" ) );
4183 footprint.SetCustomProperty( wxT( "Owner" ), wxT( "QA" ) );
4184 footprint.SetExcludedFromSim( true );
4185 PCB_SHAPE* line = new PCB_SHAPE( &footprint, SHAPE_T::SEGMENT );
4186 line->SetStart( VECTOR2I( 0, 0 ) );
4187 line->SetEnd( VECTOR2I( 10000000, 0 ) );
4188 line->SetWidth( 200000 );
4189 line->SetLayer( F_SilkS );
4191 footprint.Add( line );
4192 PCB_CONSTRAINT* constraint = new PCB_CONSTRAINT( &footprint, PCB_CONSTRAINT_TYPE::HORIZONTAL );
4193 constraint->AddMember( line->m_Uuid );
4194 footprint.Add( constraint );
4196 io.FootprintSave( source, &footprint );
4197
4198 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
4199 {
4200 for( bool drop : { false, true } )
4201 {
4202 const wxString destination = ( temporary.Path() / "out.kicad_mod" ).string();
4203 BOOST_REQUIRE( DowngradeFootprintFileToTemp( source, destination, target, drop )
4205 wxString name;
4206 auto converted = io.ImportFootprint( destination, name );
4207 BOOST_REQUIRE( converted );
4208 BOOST_CHECK( converted->Constraints().empty() );
4209 BOOST_CHECK( !converted->HasCustomProperties() );
4210 BOOST_CHECK( !converted->IsExcludedFromSim() );
4211 BOOST_CHECK_EQUAL( converted->Value().GetText(), wxString( "42/${REFERENCE}" ) );
4212 BOOST_REQUIRE( !converted->GraphicalItems().empty() );
4213
4214 for( BOARD_ITEM* item : converted->GraphicalItems() )
4215 {
4216 BOOST_REQUIRE( item->Type() == PCB_SHAPE_T );
4217 const PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
4219 BOOST_CHECK( shape->GetShape() == ( drop ? SHAPE_T::SEGMENT : SHAPE_T::POLY ) );
4220 }
4221 }
4222 }
4223}
4224
4225
4226BOOST_AUTO_TEST_CASE( SimulationExclusionsFollowSelectedVariantAndReportTheirLoss )
4227{
4228 for( bool drop : { false, true } )
4229 {
4230 BOARD board;
4231 FOOTPRINT* fp = new FOOTPRINT( &board );
4232 fp->SetExcludedFromSim( false );
4233 fp->AddVariant( wxT( "selected" ) )->SetExcludedFromSim( true );
4234 board.Add( fp );
4235 FlattenBoardVariant( &board, wxT( "selected" ) );
4237 const auto report = ClassifyBoardForDowngrade( &board, kicad10, drop );
4238 checkFeature( report, wxT( "Footprint simulation exclusions" ), DOWNGRADE_BUCKET::DROP, 1 );
4239 DowngradeBoardInPlace( &board, kicad10, drop );
4241 for( const auto& [name, variant] : fp->GetVariants() )
4242 BOOST_CHECK( !variant.GetExcludedFromSim() );
4243 }
4244}
4245
4246
4247BOOST_AUTO_TEST_CASE( LegacyBoldWidthsPreserveNestedTextAndDoNotMutateSource )
4248{
4249 SETTINGS_MANAGER settingsManager;
4250 BOARD board;
4251 FOOTPRINT* fp = new FOOTPRINT( &board );
4252 board.Add( fp );
4253 std::vector<EDA_TEXT*> bold;
4254 PCB_TEXT* text = new PCB_TEXT( &board );
4255 text->SetText( wxT( "board bold" ) );
4256 board.Add( text );
4257 bold.push_back( text );
4258 fp->Value().SetText( wxT( "footprint bold" ) );
4259 bold.push_back( &fp->Value() );
4260 PCB_TEXT* fpText = new PCB_TEXT( fp );
4261 fpText->SetText( wxT( "graphic bold" ) );
4262 fp->Add( fpText );
4263 bold.push_back( fpText );
4264 PCB_TABLE* table = new PCB_TABLE( fp, 100000 );
4265 table->SetColCount( 1 );
4266 table->SetColWidth( 0, 10000000 );
4267 table->SetRowHeight( 0, 5000000 );
4268 PCB_TABLECELL* cell = new PCB_TABLECELL( table );
4269 cell->SetText( wxT( "cell bold" ) );
4270 table->AddCell( cell );
4271 fp->Add( table );
4272 bold.push_back( cell );
4273 PCB_DIM_ALIGNED* dimension = new PCB_DIM_ALIGNED( &board );
4274 dimension->SetStart( VECTOR2I( 0, 0 ) );
4275 dimension->SetEnd( VECTOR2I( 10000000, 0 ) );
4276 dimension->SetHeight( 2000000 );
4277 dimension->ChangeOverrideText( wxT( "dimension bold" ) );
4278 board.Add( dimension );
4279 bold.push_back( dimension );
4280
4281 for( EDA_TEXT* item : bold )
4282 {
4283 item->SetBold( true );
4284 item->SetTextThickness( 100000 );
4285 }
4286
4287 PCB_TEXT* automatic = new PCB_TEXT( &board );
4288 automatic->SetText( wxT( "auto bold" ) );
4289 automatic->SetBold( true );
4290 automatic->SetTextThickness( 0 );
4291 board.Add( automatic );
4292 PCB_TEXT* outline = new PCB_TEXT( &board );
4293 outline->SetText( wxT( "outline bold" ) );
4294 outline->SetFont( KIFONT::FONT::GetFont( wxT( "DejaVu Sans" ), true ) );
4295 outline->SetBold( true );
4296 outline->SetTextThickness( 100000 );
4297 board.Add( outline );
4298 const bool outlineAvailable = outline->GetFont() && outline->GetFont()->IsOutline();
4299 KI_TEST::SCOPED_TEMP_DIR temporary( "kicad_qa_legacy_bold_widths" );
4300
4301 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
4302 {
4303 const std::string first = ( temporary.Path() / ( target.m_id.ToStdString() + "-first.kicad_pcb" ) ).string();
4304 const std::string second = ( temporary.Path() / ( target.m_id.ToStdString() + "-second.kicad_pcb" ) ).string();
4305 SaveBoardForTarget( &board, first, target );
4306 SaveBoardForTarget( &board, second, target );
4307 const std::string content = KI_TEST::ReadGoldenText( first );
4308 BOOST_CHECK( content.find( "(thickness 0.16)" ) != std::string::npos );
4309 BOOST_CHECK( content == KI_TEST::ReadGoldenText( second ) );
4310
4311 for( EDA_TEXT* item : bold )
4312 BOOST_CHECK_EQUAL( item->GetTextThickness(), 100000 );
4313
4314 BOOST_CHECK_EQUAL( automatic->GetTextThickness(), 0 );
4315 BOOST_CHECK_EQUAL( outline->GetTextThickness(), 100000 );
4317 auto reloaded = io.LoadBoard( first );
4318 BOOST_REQUIRE( reloaded );
4319 size_t checked = 0;
4320 reloaded->RunOnChildren(
4321 [&]( BOARD_ITEM* item )
4322 {
4323 EDA_TEXT* reloadedText = dynamic_cast<EDA_TEXT*>( item );
4324
4325 if( !reloadedText || !reloadedText->IsBold() )
4326 return;
4327
4328 if( reloadedText->GetText() == wxT( "auto bold" ) )
4329 BOOST_CHECK_EQUAL( reloadedText->GetTextThickness(), 0 );
4330 else if( reloadedText->GetText() != wxT( "outline bold" ) || outlineAvailable )
4331 BOOST_CHECK_EQUAL( reloadedText->GetTextThickness(), 100000 );
4332
4333 ++checked;
4334 },
4336 BOOST_CHECK_EQUAL( checked, bold.size() + 2 );
4337 }
4338}
4339
4340
4341BOOST_AUTO_TEST_CASE( ComplexPadstackFrontAndInnerCustomOptionsRoundTripToKicad10 )
4342{
4343 SETTINGS_MANAGER settingsManager;
4344 BOARD board;
4345 board.SetCopperLayerCount( 4 );
4346 FOOTPRINT* fp = new FOOTPRINT( &board );
4347 PAD* pad = new PAD( fp );
4348 pad->SetAttribute( PAD_ATTRIB::PTH );
4349 pad->SetLayerSet( LSET::AllCuMask() );
4350 pad->Padstack().SetMode( PADSTACK::MODE::CUSTOM );
4351 pad->SetShape( F_Cu, PAD_SHAPE::OVAL );
4352 pad->SetSize( F_Cu, VECTOR2I( 2000000, 1000000 ) );
4353 pad->SetShape( In1_Cu, PAD_SHAPE::CUSTOM );
4354 pad->SetSize( In1_Cu, VECTOR2I( 500000, 500000 ) );
4355 pad->SetCustomShapeInZoneOpt( CUSTOM_SHAPE_ZONE_MODE::CONVEXHULL );
4356 PCB_SHAPE* primitive = new PCB_SHAPE( pad, SHAPE_T::SEGMENT );
4357 primitive->SetStart( VECTOR2I( -1000000, 0 ) );
4358 primitive->SetEnd( VECTOR2I( 1000000, 0 ) );
4359 primitive->SetWidth( 200000 );
4360 pad->AddPrimitive( In1_Cu, primitive );
4361 pad->SetDrillSize( VECTOR2I( 300000, 300000 ) );
4362 fp->Add( pad );
4363 board.Add( fp );
4364 KI_TEST::SCOPED_TEMP_DIR temporary( "kicad_qa_complex_pad_front" );
4365 const std::string path = ( temporary.Path() / "out.kicad_pcb" ).string();
4366 SaveBoardForTarget( &board, path, kicad10 );
4368 auto reloaded = io.LoadBoard( path );
4369 BOOST_REQUIRE( reloaded && reloaded->Footprints().size() == 1 );
4370 BOOST_REQUIRE_EQUAL( reloaded->Footprints()[0]->Pads().size(), 1 );
4371 const PAD* result = reloaded->Footprints()[0]->Pads()[0];
4372 BOOST_CHECK( result->GetShape( F_Cu ) == PAD_SHAPE::OVAL );
4373 BOOST_CHECK( result->GetSize( F_Cu ) == VECTOR2I( 2000000, 1000000 ) );
4374 BOOST_CHECK( result->GetShape( In1_Cu ) == PAD_SHAPE::CUSTOM );
4375 BOOST_REQUIRE_EQUAL( result->GetPrimitives( In1_Cu ).size(), 1 );
4376 BOOST_CHECK( result->GetCustomShapeInZoneOpt() == CUSTOM_SHAPE_ZONE_MODE::CONVEXHULL );
4377}
4378
4379
4380BOOST_AUTO_TEST_CASE( CurrentProjectSchemasAndSupportedDrcExclusionsMigrateForBothTargets )
4381{
4382 const nlohmann::json exclusion = { { "marker",
4383 { { "error_type", "DRCET_CLEARANCE" },
4384 { "position", { { "x_nm", "123" }, { "y_nm", "-456" } } },
4385 { "items",
4386 { { { "value", "11111111-1111-1111-1111-111111111111" } },
4387 { { "value", "22222222-2222-2222-2222-222222222222" } } } } } },
4388 { "comment", "accepted" } };
4389
4390 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
4391 {
4392 nlohmann::json doc = {
4393 { "meta", { { "version", 4 } } },
4394 { "board",
4395 { { "design_settings", { { "meta", { { "version", 3 } } }, { "drc_exclusions", { exclusion } } } } } }
4396 };
4397 COMPATIBILITY_REPORT report;
4398 DowngradeProjectFileJson( doc, target, report );
4399 BOOST_CHECK_EQUAL( doc["meta"]["version"].get<int>(), 3 );
4400 const auto& settings = doc["board"]["design_settings"];
4401 BOOST_CHECK_EQUAL( settings["meta"]["version"].get<int>(), 2 );
4402 BOOST_REQUIRE_EQUAL( settings["drc_exclusions"].size(), 1 );
4404 settings["drc_exclusions"][0][0].get<std::string>(),
4405 "clearance|123|-456|11111111-1111-1111-1111-111111111111|22222222-2222-2222-2222-222222222222" );
4406 BOOST_CHECK_EQUAL( settings["drc_exclusions"][0][1].get<std::string>(), "accepted" );
4407 BOOST_CHECK( !report.IsLossy() );
4408 const auto migrated = doc;
4409 COMPATIBILITY_REPORT second;
4410 DowngradeProjectFileJson( doc, target, second );
4411 BOOST_CHECK( doc == migrated );
4412 BOOST_CHECK( !second.IsLossy() );
4413 }
4414}
4415
4416
4417// Schema 4 renamed the text thickness keys and enum to line width, released targets read the old names
4418BOOST_AUTO_TEST_CASE( LineWidthSettingsDowngradeToTextThickness )
4419{
4420 const nlohmann::json exclusion = { { "marker",
4421 { { "error_type", "DRCET_LINE_WIDTH" },
4422 { "position", { { "x_nm", "1" }, { "y_nm", "2" } } },
4423 { "items", { { { "value", "11111111-1111-1111-1111-111111111111" } } } } } } };
4424
4425 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
4426 {
4427 nlohmann::json doc = {
4428 { "meta", { { "version", 4 } } },
4429 { "board",
4430 { { "design_settings",
4431 { { "meta", { { "version", 4 } } },
4432 { "rule_severities", { { "line_width", "ignore" } } },
4433 { "rules", { { "min_silk_line_width", 0.2 } } },
4434 { "drc_exclusions", { exclusion } } } } } }
4435 };
4436 COMPATIBILITY_REPORT report;
4437 DowngradeProjectFileJson( doc, target, report );
4438
4439 const auto& settings = doc["board"]["design_settings"];
4440 BOOST_CHECK_EQUAL( settings["meta"]["version"].get<int>(), 2 );
4441 BOOST_CHECK_EQUAL( settings["rule_severities"].value( "text_thickness", "" ), "ignore" );
4442 BOOST_CHECK( !settings["rule_severities"].contains( "line_width" ) );
4443 BOOST_CHECK_EQUAL( settings["rules"].value( "min_text_thickness", 0.0 ), 0.2 );
4444 BOOST_CHECK( !settings["rules"].contains( "min_silk_line_width" ) );
4445 BOOST_REQUIRE_EQUAL( settings["drc_exclusions"].size(), 1 );
4446 BOOST_CHECK( settings["drc_exclusions"][0][0].get<std::string>().starts_with( "text_thickness|1|2|" ) );
4447 }
4448}
4449
4450
4451BOOST_AUTO_TEST_CASE( UnrepresentableDrcExclusionsDropWithReports )
4452{
4453 nlohmann::json multiple = { { "marker",
4454 { { "error_type", "DRCET_CLEARANCE" },
4455 { "position", { { "x_nm", "123" }, { "y_nm", "-456" } } },
4456 { "items",
4457 { { { "value", "11111111-1111-1111-1111-111111111111" } },
4458 { { "value", "22222222-2222-2222-2222-222222222222" } },
4459 { { "value", "33333333-3333-3333-3333-333333333333" } } } } } },
4460 { "comment", "three items" } };
4461 nlohmann::json unknown = multiple;
4462 unknown["marker"]["error_type"] = "DRCET_MICROVIA_STACK_DEPTH";
4463 unknown["marker"]["items"].erase( 2 );
4464
4465 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
4466 {
4467 nlohmann::json doc = {
4468 { "board",
4469 { { "design_settings",
4470 { { "meta", { { "version", 3 } } }, { "drc_exclusions", { multiple, unknown, "malformed" } } } } } }
4471 };
4472 COMPATIBILITY_REPORT report;
4473 DowngradeProjectFileJson( doc, target, report );
4474 BOOST_CHECK( doc["board"]["design_settings"]["drc_exclusions"].empty() );
4476 }
4477}
4478
4479
4480BOOST_AUTO_TEST_CASE( PostMasterProjectSettingsReportOnlyMeaningfulLosses )
4481{
4482 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
4483 {
4484 nlohmann::json doc;
4485 doc["net_settings"]["net_chain_netclasses"] = { { { "name", "fast" } } };
4486 doc["board"]["design_settings"]["via_stack_presets"] = { { { "name", "fanout" } } };
4487 doc["board"]["design_settings"]["teardrop_parameters"] = {
4488 { { "td_target_name", "td_track_end" }, { "td_enabled", true }, { "td_max_len", 1.0 } },
4489 { { "td_enabled", false } }
4490 };
4491 COMPATIBILITY_REPORT report;
4492 DowngradeProjectFileJson( doc, target, report );
4493 BOOST_CHECK( !doc["net_settings"].contains( "net_chain_netclasses" ) );
4494 const auto& settings = doc["board"]["design_settings"];
4495 BOOST_CHECK( !settings.contains( "via_stack_presets" ) );
4496 BOOST_CHECK( !settings["teardrop_parameters"][0].contains( "td_enabled" ) );
4497 BOOST_CHECK( !settings["teardrop_parameters"][1].contains( "td_enabled" ) );
4498 BOOST_CHECK_EQUAL( settings["teardrop_parameters"][0]["td_max_len"].get<double>(), 1.0 );
4500 COMPATIBILITY_REPORT second;
4501 DowngradeProjectFileJson( doc, target, second );
4502 BOOST_CHECK( !second.IsLossy() );
4503
4504 nlohmann::json defaults;
4505 defaults["net_settings"]["net_chain_netclasses"] = nlohmann::json::array();
4506 defaults["board"]["design_settings"]["via_stack_presets"] = nlohmann::json::array();
4507 defaults["board"]["design_settings"]["teardrop_parameters"] = { { { "td_enabled", false } } };
4508 COMPATIBILITY_REPORT silent;
4509 DowngradeProjectFileJson( defaults, target, silent );
4510 BOOST_CHECK( !silent.IsLossy() );
4511 }
4512}
4513
4514
4515BOOST_AUTO_TEST_CASE( NewTuningBridgeDelayIsRemovedAndReportedForKicad10 )
4516{
4517 nlohmann::json doc = {
4518 { "tuning_profiles",
4519 { { "meta", { { "version", 2 } } },
4520 { "tuning_profiles_impedance_geometric",
4521 { { { "net_chain_bridge_prop_delay", 25 } }, { { "net_chain_bridge_prop_delay", 0 } } } } } }
4522 };
4523 COMPATIBILITY_REPORT report;
4524 DowngradeProjectFileJson( doc, kicad10, report );
4525 BOOST_CHECK_EQUAL( doc["tuning_profiles"]["meta"]["version"].get<int>(), 0 );
4527
4528 for( const auto& profile : doc["tuning_profiles"]["tuning_profiles_impedance_geometric"] )
4529 BOOST_CHECK( !profile.contains( "net_chain_bridge_prop_delay" ) );
4530}
4531
4532
4533BOOST_AUTO_TEST_CASE( NativeNetChainClassMapReportsOnlyNonemptyMappings )
4534{
4535 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
4536 {
4537 nlohmann::json doc;
4538 doc["net_settings"]["net_chain_classes"] = { { "clock", "Fast" } };
4539 COMPATIBILITY_REPORT report;
4540 DowngradeProjectFileJson( doc, target, report );
4541 BOOST_CHECK( !doc["net_settings"].contains( "net_chain_classes" ) );
4543 COMPATIBILITY_REPORT second;
4544 DowngradeProjectFileJson( doc, target, second );
4545 BOOST_CHECK( !second.IsLossy() );
4546 doc["net_settings"]["net_chain_classes"] = nlohmann::json::object();
4548 DowngradeProjectFileJson( doc, target, empty );
4549 BOOST_CHECK( !empty.IsLossy() );
4550 }
4551}
4552
4553
4554// A word the generated vocabulary lists must never be the reason a rule is dropped. That is the
4555// direction a generator mistake would take, silently losing a rule the target can read.
4556BOOST_AUTO_TEST_CASE( ReleaseVocabularyKeepsEveryRuleTheReleaseCouldRead )
4557{
4558 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
4559 {
4560 const DRC_RULE_VOCABULARY* vocabulary = FindDrcRuleVocabulary( target );
4561 BOOST_REQUIRE( vocabulary );
4562
4563 for( size_t i = 0; i < vocabulary->m_functionCount; i++ )
4564 {
4565 const wxString name = wxString::FromUTF8( vocabulary->m_functions[i] );
4566
4567 if( std::any_of( std::begin( DRC_RULE_SEMANTIC_BREAKS ), std::end( DRC_RULE_SEMANTIC_BREAKS ),
4568 [&]( const char* aBreak )
4569 {
4570 return name == aBreak;
4571 } ) )
4572 continue;
4573
4574 const wxString rule = wxT( "(version 1)(rule \"f\" (condition \"A." ) + name
4575 + wxT( "('x')\") (constraint clearance (min 0.2mm)))" );
4576
4577 BOOST_CHECK_MESSAGE( FilterDrcRulesForTarget( rule, target ).m_dropped.empty(),
4578 target.m_id + " dropped a rule calling " + name );
4579 }
4580
4581 for( size_t i = 0; i < vocabulary->m_propertyCount; i++ )
4582 {
4583 const wxString name = wxString::FromUTF8( vocabulary->m_properties[i] );
4584 const wxString rule = wxT( "(version 1)(rule \"p\" (condition \"A." ) + name
4585 + wxT( " == 1\") (constraint clearance (min 0.2mm)))" );
4586
4587 BOOST_CHECK_MESSAGE( FilterDrcRulesForTarget( rule, target ).m_dropped.empty(),
4588 target.m_id + " dropped a rule reading " + name );
4589 }
4590 }
4591}
4592
4593
4594// Adding a downgrade target without rerunning tools/generate_drc_rules_vocabulary.py must fail here.
4595BOOST_AUTO_TEST_CASE( EveryDowngradeTargetHasARuleVocabulary )
4596{
4597 for( const DOWNGRADE_TARGET& target : GetDowngradeTargets() )
4598 {
4599 BOOST_CHECK_MESSAGE( FindDrcRuleVocabulary( target ),
4600 target.m_name + " has no entry in include/drc_rules_release_vocabulary.h" );
4601 }
4602}
4603
4604
4605// A registered property is only usable if the release's evaluator can read its type. Priority
4606// is unsigned and Hatch Orientation an angle, neither readable before 11, while an enum always is.
4607BOOST_AUTO_TEST_CASE( PropertiesTheReleaseCannotEvaluateAreDropped )
4608{
4609 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
4610 {
4611 for( const wxString& property : { wxT( "A.Priority > 1" ), wxT( "A.Hatch_Orientation == 0" ),
4612 wxT( "A.Line_Color == 'red'" ) } )
4613 {
4614 const auto result = FilterDrcRulesForTarget( wxT( "(version 1)(rule \"typed\" (condition \"" ) + property
4615 + wxT( "\") (constraint clearance (min 0.2mm)))" ),
4616 target );
4617 BOOST_CHECK_MESSAGE( result.m_dropped.size() == 1, target.m_id + " kept " + property );
4618 }
4619
4620 const auto kept = FilterDrcRulesForTarget( wxT( "(version 1)(rule \"enum\" (condition \"A.Pad_Type == 'PTH'\") "
4621 "(constraint clearance (min 0.2mm)))" ),
4622 target );
4623 BOOST_CHECK( kept.m_dropped.empty() );
4624 }
4625}
4626
4627
4628// A unit may stand apart from its number. That is a value, not a keyword the target lacks.
4629BOOST_AUTO_TEST_CASE( SpacedUnitsAreNotMistakenForKeywords )
4630{
4631 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
4632 {
4633 const auto kept = FilterDrcRulesForTarget(
4634 wxT( "(version 1)(rule \"spaced\" (constraint clearance (min 0.2 mm) (opt 0.3 mil) (max 1 in)))" ),
4635 target );
4636 BOOST_CHECK_MESSAGE( kept.m_dropped.empty(), target.m_id + " dropped a rule with a spaced unit" );
4637
4638 // A unit the target cannot read is still caught when it stands apart.
4639 const auto dropped = FilterDrcRulesForTarget(
4640 wxT( "(version 1)(rule \"delay\" (constraint skew (max 5 ps)))" ), target );
4641 BOOST_CHECK_EQUAL( dropped.m_dropped.size(), target.m_id == wxT( "9.0" ) ? 1 : 0 );
4642 }
4643}
4644
4645
4646// 9.0 reads neither degrees nor picoseconds, and knows nothing of text variables. 10.0 has all three.
4647BOOST_AUTO_TEST_CASE( UnitsAndTextVariablesFollowWhatTheReleaseParses )
4648{
4649 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
4650 {
4651 const bool old = target.m_id == wxT( "9.0" );
4652
4653 auto angle = FilterDrcRulesForTarget(
4654 wxT( "(version 1)(rule \"a\" (constraint track_angle (max 45deg)))" ), target );
4655 BOOST_CHECK_EQUAL( angle.m_dropped.size(), old ? 1 : 0 );
4656
4657 auto delay = FilterDrcRulesForTarget( wxT( "(version 1)(rule \"d\" (constraint skew (max 5ps)))" ), target );
4658 BOOST_CHECK_EQUAL( delay.m_dropped.size(), old ? 1 : 0 );
4659
4660 for( const wxString& rule : { wxT( "(rule \"v\" (constraint clearance (min ${GAP})))" ),
4661 wxT( "(rule \"c\" (condition \"A.NetName == '${NET}'\") "
4662 "(constraint clearance (min 0.2mm)))" ) } )
4663 {
4664 auto variable = FilterDrcRulesForTarget( wxT( "(version 1)" ) + rule, target );
4665 BOOST_CHECK_EQUAL( variable.m_dropped.size(), old ? 1 : 0 );
4666 }
4667 }
4668}
4669
4670
4671BOOST_AUTO_TEST_CASE( WordsAddedInAPointReleaseAreNotInTheSeriesVocabulary )
4672{
4673 for( const wxString& expression : { wxT( "A.hasExactNetclass('x')" ), wxT( "A.Column_Width == 1" ),
4674 wxT( "A.Visible == 1" ) } )
4675 {
4676 const wxString rule = wxT( "(version 1)(rule \"r\" (condition \"" ) + expression
4677 + wxT( "\") (constraint clearance (min 0.2mm)))" );
4678 BOOST_CHECK_MESSAGE( FilterDrcRulesForTarget( rule, kicad9 ).m_dropped.size() == 1,
4679 "9.0 kept " + expression + " which not every 9.0.x release reads" );
4680 }
4681
4682 for( const wxString& expression : { wxT( "A.intersectsKeepout('x')" ), wxT( "A.Origin_X == 1" ) } )
4683 {
4684 const wxString rule = wxT( "(version 1)(rule \"r\" (condition \"" ) + expression
4685 + wxT( "\") (constraint clearance (min 0.2mm)))" );
4686 BOOST_CHECK_MESSAGE( FilterDrcRulesForTarget( rule, kicad10 ).m_dropped.size() == 1,
4687 "10.0 kept " + expression + " which not every 10.0.x release reads" );
4688 }
4689}
4690
4691
4692// A layer may be given unquoted, and a user layer name is not a grammar keyword.
4693BOOST_AUTO_TEST_CASE( UnquotedLayerNamesAreNotMistakenForKeywords )
4694{
4695 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
4696 {
4697 for( const wxString& layer : { wxT( "MyCustomLayer" ), wxT( "F.Cu" ), wxT( "\"In1.Cu\"" ), wxT( "outer" ) } )
4698 {
4699 const auto result = FilterDrcRulesForTarget( wxT( "(version 1)(rule \"on layer\" (layer " ) + layer
4700 + wxT( ") (constraint clearance (min 0.2mm)))" ),
4701 target );
4702 BOOST_CHECK_MESSAGE( result.m_dropped.empty(), target.m_id + " dropped a rule on layer " + layer );
4703 }
4704 }
4705}
4706
4707
4708BOOST_AUTO_TEST_CASE( MissingRuleVocabularyFailsClosed )
4709{
4711 unknown.m_id = wxT( "0.0" );
4712 unknown.m_name = wxT( "KiCad 0.0" );
4713
4714 const auto result =
4715 FilterDrcRulesForTarget( wxT( "(version 1)(rule \"r\" (constraint clearance (min 0.2mm)))" ), unknown );
4716
4717 BOOST_CHECK( !result.m_error.IsEmpty() );
4718 BOOST_CHECK( result.m_text.IsEmpty() );
4719}
4720
4721
4722BOOST_AUTO_TEST_CASE( NewDrcConstraintsAndFunctionsAreFilteredWithoutLiteralFalsePositives )
4723{
4724 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
4725 {
4726 for( const wxString& keyword : { wxT( "hole_aspect_ratio" ), wxT( "microvia_stack_depth" ) } )
4727 {
4728 const wxString rule = "(version 1)(rule \"new\" (constraint " + keyword + " (max 2)))";
4729 const auto result = FilterDrcRulesForTarget( rule, target );
4730 BOOST_CHECK( result.m_error.IsEmpty() );
4731 BOOST_CHECK_EQUAL( result.m_dropped.size(), 1 );
4732 }
4733
4734 for( const wxString& call :
4735 { wxT( "A.intersectsKeepout('x')" ), wxT( "A.intersectsArea('x')" ), wxT( "A.isStackedVia()" ),
4736 wxT( "A.ISSTACKEDVIA()" ), wxT( "A.customProperty('Owner') == 'Team'" ),
4737 wxT( "A.hasCustomProperty('Owner')" ) } )
4738 {
4739 for( const wxString& expression : { wxT( "condition" ), wxT( "assertion" ) } )
4740 {
4741 const wxString rule =
4742 expression == wxT( "condition" )
4743 ? "(rule \"new\" (condition \"" + call + "\") (constraint clearance (min 0.2mm)))"
4744 : "(rule \"new\" (constraint assertion \"" + call + "\"))";
4745 const auto result = FilterDrcRulesForTarget( wxT( "(version 1)" ) + rule, target );
4746 BOOST_CHECK( result.m_error.IsEmpty() );
4747 BOOST_CHECK_EQUAL( result.m_dropped.size(), 1 );
4748 }
4749 }
4750
4751 const wxString kept = wxT( "(rule \"customProperty\" (condition \"A.NetName == 'isStackedVia()'\") "
4752 "(constraint clearance (min 0.2mm)))\n"
4753 "(rule \"literal\" (condition \"A.NetName == 'intersectsArea()'\") "
4754 "(constraint clearance (min 0.2mm)))\n"
4755 "(rule \"uppercase literal\" (condition \"A.NetName == 'ISSTACKEDVIA()'\") "
4756 "(constraint clearance (min 0.2mm)))\n"
4757 "(rule \"legacy\" (condition \"A.insideArea('x')\") "
4758 "(constraint clearance (min 0.2mm)))\n"
4759 "(rule \"position\" (condition \"A.Start_X > 1mm && A.Start_Y > 1mm\") "
4760 "(constraint clearance (min 0.2mm)))" );
4761 const auto result = FilterDrcRulesForTarget( wxT( "(version 1)\n" ) + kept, target );
4762 BOOST_CHECK( result.m_error.IsEmpty() );
4763 BOOST_CHECK( result.m_dropped.empty() );
4764 BOOST_CHECK( result.m_text.Contains( kept ) );
4765 }
4766}
4767
4768
4769BOOST_AUTO_TEST_CASE( DrcPostTargetPropertiesAreGuardedInConditionsAndAssertions )
4770{
4771 for( const DOWNGRADE_TARGET& target : { kicad9, kicad10 } )
4772 {
4773 for( const wxString& kind : { wxT( "condition" ), wxT( "assertion" ) } )
4774 {
4775 const wxString expression = wxT( "A.Parent == A.Parent && A.NetName != 'A.parent.Reference'" );
4776 const wxString body =
4777 kind == wxT( "condition" )
4778 ? wxT( "(condition \"" ) + expression + wxT( "\") (constraint clearance (min 0.2mm))" )
4779 : wxT( "(constraint assertion \"" ) + expression + wxT( "\")" );
4780 const auto parent =
4781 FilterDrcRulesForTarget( wxT( "(version 1)(rule \"parent property\" " ) + body + ")", target );
4782 BOOST_CHECK( parent.m_error.IsEmpty() );
4783 BOOST_CHECK( parent.m_dropped.empty() );
4784 }
4785
4786 for( const wxString& property :
4787 { wxT( "A.Start_Shape" ), wxT( "A.start_shape" ), wxT( "B.End_Width" ), wxT( "AB.Scale_X" ),
4788 wxT( "A.parent.Reference" ), wxT( "A . PARENT . Reference" ), wxT( "A.Major_Radius" ),
4789 wxT( "A.Exclude_From_Simulation" ), wxT( "A.Automatically_Update_Net" ), wxT( "A.Grid_Type" ) } )
4790 {
4791 for( const wxString& kind : { wxT( "condition" ), wxT( "assertion" ) } )
4792 {
4793 const wxString expression =
4794 property + ( property.Contains( wxT( "Reference" ) ) ? wxT( " == 'U1'" ) : wxT( " == 1" ) );
4795 const wxString body =
4796 kind == wxT( "condition" )
4797 ? wxT( "(condition \"" ) + expression + wxT( "\") (constraint clearance (min 0.2mm))" )
4798 : wxT( "(constraint assertion \"" ) + expression + wxT( "\")" );
4799 const auto result =
4800 FilterDrcRulesForTarget( wxT( "(version 1)(rule \"props\" " ) + body + ")", target );
4801 BOOST_CHECK( result.m_error.IsEmpty() );
4802 BOOST_CHECK_EQUAL( result.m_dropped.size(), 1 );
4803 }
4804 }
4805
4806 for( const wxString& property :
4807 { wxT( "A.Corner_Radius" ), wxT( "A.Auto_Thickness" ), wxT( "A.Target_Delay" ) } )
4808 {
4809 for( const wxString& kind : { wxT( "condition" ), wxT( "assertion" ) } )
4810 {
4811 const wxString expression = property + wxT( " == 1" );
4812 const wxString body =
4813 kind == wxT( "condition" )
4814 ? wxT( "(condition \"" ) + expression + wxT( "\") (constraint clearance (min 0.2mm))" )
4815 : wxT( "(constraint assertion \"" ) + expression + wxT( "\")" );
4816 const auto result =
4817 FilterDrcRulesForTarget( wxT( "(version 1)(rule \"older\" " ) + body + ")", target );
4818 BOOST_CHECK( result.m_error.IsEmpty() );
4819 BOOST_CHECK_EQUAL( result.m_dropped.size(), target.m_boardVersion == kicad9.m_boardVersion ? 1 : 0 );
4820 }
4821 }
4822
4823 const wxString kept = wxT( "(rule \"literal\" (condition \"A.NetName == 'A.Start_Shape' && A.Start_X > 1mm "
4824 "&& A.End_Y > 1mm && A.Radius > 1mm\") (constraint clearance (min 0.2mm)))" );
4825 const auto result = FilterDrcRulesForTarget( wxT( "(version 1)" ) + kept, target );
4826 BOOST_CHECK( result.m_error.IsEmpty() );
4827 BOOST_CHECK( result.m_dropped.empty() );
4828 BOOST_CHECK( result.m_text.Contains( kept ) );
4829 }
4830}
4831
4832
const char * name
@ ERROR_INSIDE
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
COMPATIBILITY_REPORT ClassifyBoardForDowngrade(const BOARD *aBoard, const DOWNGRADE_TARGET &aTarget, bool aDropInsteadOfApproximate)
Report what a board would lose if exported to an older KiCad.
void SaveFootprintForTarget(FOOTPRINT *aFootprint, const wxString &aPath, const DOWNGRADE_TARGET &aTarget)
Save a single .kicad_mod footprint file for the target.
int BoardDowngradeCoveredVersion()
The format the denylist was generated against. A format bump forces a review.
void SaveBoardForTarget(BOARD *aBoard, const wxString &aPath, const DOWNGRADE_TARGET &aTarget)
Save a board stamped for the target, using the writer for that version.
void FlattenBoardVariant(BOARD *aBoard, const wxString &aVariantName)
Bake a variant's overrides into the base footprint attributes.
int FootprintLibDowngradeCoveredVersion()
The footprint library format the rules were reviewed against. Moves independently of the board.
bool ExportBoardToOlderVersion(const wxString &aSrcFile, const wxString &aDestFile, const DOWNGRADE_TARGET &aTarget, COMPATIBILITY_REPORT &aReport, wxString *aUnsupportedToken, const wxString &aVariant, bool aDropInsteadOfApproximate)
Load a board, downgrade the copy, and write it stamped for the target.
DOWNGRADE_FILE_RESULT DowngradeFootprintFileToTemp(const wxString &aSrcFile, const wxString &aTmpFile, const DOWNGRADE_TARGET &aTarget, bool aDropInsteadOfApproximate)
Load one .kicad_mod, classify it against the rule table, and write the downgraded copy to aTmpFile.
void DowngradeBoardInPlace(BOARD *aBoard, const DOWNGRADE_TARGET &aTarget, bool aDropInsteadOfApproximate)
Approximate or remove, in place, what the target cannot represent.
void DowngradeFootprintInPlace(FOOTPRINT *aFootprint, const DOWNGRADE_TARGET &aTarget, bool aDropInsteadOfApproximate)
Footprint-scoped downgrade for standalone .kicad_mod files the board pass never sees.
wxString FindUnsupportedBoardToken(const wxString &aSerialized, const DOWNGRADE_TARGET &aTarget)
Scan serialized board text for tokens the target cannot parse.
General utilities for PCB file IO for QA programs.
@ BS_ITEM_TYPE_DIELECTRIC
int GetPPI() const
int GetLegacyPPI() const
Recompute the PPI the way it was computed before the pixels/cm truncation fix.
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
std::map< PCB_LAYER_ID, ZONE_LAYER_PROPERTIES > m_ZoneLayerProperties
DRILL_SYMBOL_PROFILE & GetDrillSymbolProfile()
BOARD_STACKUP & GetStackupDescriptor()
Abstract interface for BOARD_ITEMs capable of storing other items inside.
virtual void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false)=0
Adds an item to the container.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
virtual bool IsKnockout() const
Definition board_item.h:437
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual void SetIsKnockout(bool aKnockout)
Definition board_item.h:438
Manage one layer needed to make a physical board.
DIELECTRIC_MODEL GetDielectricModel(int aDielectricSubLayer=0) const
void SetDielectricModel(DIELECTRIC_MODEL aModel, int aDielectricSubLayer=0)
void Add(BOARD_STACKUP_ITEM *aItem)
Add a new item in stackup layer.
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 GENERATORS & Generators() const
Definition board.h:485
void SetProperties(const std::map< wxString, wxString > &aProps)
Definition board.h:527
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition board.cpp:2833
TITLE_BLOCK & GetTitleBlock()
Definition board.h:1035
const TRACKS & Tracks() const
Definition board.h:463
const CONSTRAINTS & Constraints() const
Geometric constraints (#2329) owned by this board.
Definition board.h:522
void SetCopperLayerCount(int aCount)
Definition board.cpp:1161
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
Definition board.cpp:379
wxString GroupsSanityCheck(bool repair=false)
Consistency check of internal m_groups structure.
Definition board.cpp:3965
void SetEnabledLayers(const LSET &aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1222
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
const DRAWINGS & Drawings() const
Definition board.h:467
What an export to a given target will keep, approximate, drop, or block.
bool IsLossy() const
True if anything is approximated or dropped. This is what triggers the lossy warning.
bool IsBlocked() const
True if some feature makes the target impossible. The user cannot export anyway.
int Count(DOWNGRADE_BUCKET aBucket) const
const std::vector< COMPAT_ENTRY > & Entries() const
Stage related design and library files together, retaining originals until every write is ready.
const wxString & GetRecoveryError() const
Recovery details are nonempty only if restoring an original or removing a new output failed.
wxString Commit()
Replace all destinations, rolling back earlier replacements if a rename fails.
wxString Stage(const wxString &aDestination)
Return an exclusively-created sibling staging file, or empty if it cannot be created.
void Discard(const wxString &aTemporary)
Forget a skipped conversion without exposing its empty staging file as an output.
void Parse(std::vector< std::shared_ptr< DRC_RULE > > &aRules, REPORTER *aReporter)
Grouping rules and symbol assignments, shared by reference so a chart and its map can never disagree ...
void SetName(const wxString &aName)
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:43
std::unordered_set< EDA_ITEM * > & GetItems()
Definition eda_group.h:78
wxString GetName() const
Definition eda_group.h:75
void AddItem(EDA_ITEM *aItem)
Add item to group.
Definition eda_group.cpp:58
void SetName(const wxString &aName)
Definition eda_group.h:76
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
const KIID m_Uuid
Definition eda_item.h:599
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:116
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
bool HasCustomProperties() const
Definition eda_item.h:269
void SetCustomProperty(const wxString &aKey, const wxString &aValue)
Definition eda_item.h:255
void SetEndEnding(const LINE_ENDING &aEnding)
Definition eda_shape.h:190
FILL_T GetFillMode() const
Definition eda_shape.h:151
void TransformWithLineEndingsToPolygon(SHAPE_POLY_SET &aBuffer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const
Convert the shape body shortened for line endings plus line-ending geometry to polygons.
void SetLineStyle(const LINE_STYLE aStyle)
SHAPE_POLY_SET & GetPolyShape()
void SetEndEndingStyle(LINE_ENDING_STYLE aStyle)
Definition eda_shape.h:196
SHAPE_T GetShape() const
Definition eda_shape.h:178
LINE_STYLE GetLineStyle() const
LINE_ENDING_STYLE GetEndEndingStyle() const
Definition eda_shape.h:195
void SetFillMode(FILL_T aFill)
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
KIFONT::FONT * GetFont() const
Definition eda_text.h:286
void SetBold(bool aBold)
Set the text to be bold - this will also update the font if needed.
Definition eda_text.cpp:311
bool IsBold() const
Definition eda_text.h:215
virtual int GetTextThickness() const
Definition eda_text.h:159
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:237
void SetFont(KIFONT::FONT *aFont)
Definition eda_text.cpp:472
Variant information for a footprint.
Definition footprint.h:178
void SetExcludedFromSim(bool aExclude)
Definition footprint.h:199
void SetDNP(bool aDNP)
Definition footprint.h:193
void SetFieldValue(const wxString &aFieldName, const wxString &aValue)
Set a field value override for this variant.
Definition footprint.h:224
bool GetDuplicatePadNumbersAreJumpers() const
Definition footprint.h:1133
const CASE_INSENSITIVE_MAP< FOOTPRINT_VARIANT > & GetVariants() const
Get all variants.
Definition footprint.h:1011
bool IsDNP() const
Definition footprint.h:947
EDA_ANGLE GetOrientation() const
Definition footprint.h:382
PCB_3D_BODY & EnsureBody()
void SetDNP(bool aDNP=true)
Definition footprint.h:948
void SetStackupMode(FOOTPRINT_STACKUP aMode)
Set the stackup mode for this footprint.
void SetExcludedFromSim(bool aExclude=true)
Definition footprint.h:939
void SetKeywords(const wxString &aKeywords)
Definition footprint.h:453
PCB_FIELD & Value()
read/write accessors:
Definition footprint.h:831
void SetDuplicatePadNumbersAreJumpers(bool aEnabled)
Definition footprint.h:1134
CONSTRAINTS & Constraints()
Definition footprint.h:367
PCB_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this footprint.
std::deque< PAD * > & Pads()
Definition footprint.h:355
void SetReference(const wxString &aReference)
Definition footprint.h:799
bool IsExcludedFromSim() const
Definition footprint.h:938
void SetTransformScale(double aScaleX, double aScaleY)
PCB_FIELD & Reference()
Definition footprint.h:832
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Adds an item to the container.
FOOTPRINT_VARIANT * AddVariant(const wxString &aVariantName)
Add a new variant with the given name.
bool HasBody() const
Convenience accessors for now while we restrict to only one body per footprint.
Definition footprint.h:426
const wxString & GetReference() const
Definition footprint.h:793
VECTOR2I GetPosition() const override
Definition footprint.h:379
DRAWINGS & GraphicalItems()
Definition footprint.h:358
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Definition font.cpp:144
virtual bool IsOutline() const
Definition font.h:102
Definition kiid.h:46
wxString AsString() const
Definition kiid.cpp:264
std::string AsStdString() const
Definition kiid.cpp:270
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
Decorative shape (arrowhead, circle, square) at the start or end of a graphic line,...
Definition line_ending.h:62
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition lset.cpp:309
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
Handle the data for a net.
Definition netinfo.h:50
int GetNetCode() const
Definition netinfo.h:104
void SetParent(BOARD *aParent)
Definition netinfo.h:176
std::string Quotew(const wxString &aWrapee) const
Definition richio.cpp:505
A PADSTACK defines the characteristics of a single or multi-layer pad, in the IPC sense of the word.
Definition padstack.h:161
MASK_LAYER_PROPS & FrontOuterLayers()
Definition padstack.h:410
void SetUnconnectedLayerMode(UNCONNECTED_LAYER_MODE aMode)
Definition padstack.h:405
UNCONNECTED_LAYER_MODE UnconnectedLayerMode() const
Definition padstack.h:404
DRILL_PROPS & Drill()
Definition padstack.h:363
@ CUSTOM
Shapes can be defined on arbitrary layers.
Definition padstack.h:177
MASK_LAYER_PROPS & BackOuterLayers()
Definition padstack.h:413
Definition pad.h:61
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition pad.h:579
VECTOR2I GetPosition() const override
Definition pad.cpp:255
double GetRoundRectRadiusRatio(PCB_LAYER_ID aLayer) const
Definition pad.h:837
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
Definition pad.h:205
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
Definition pad.cpp:297
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
Definition pad.cpp:1672
const VECTOR2I & GetMid() const
Definition pcb_track.h:304
wxString GetShownText(RESOLUTION_CONTEXT aContext) const
void SetShowText(bool aShow)
void SetBarcodeText(const wxString &aText)
void SetWidth(int aWidth)
void SetBarcodeKind(BARCODE_T aKind)
void SetHeight(int aHeight)
void SetLayer(PCB_LAYER_ID aLayer) override
Set the drawing layer for the barcode and its text.
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc=ERROR_INSIDE, bool ignoreLineWidth=false) const override
Convert the barcode (text + symbol shapes) to polygonal geometry suitable for filling/collision tests...
A geometric constraint between board items (issue #2329).
void AddMember(const KIID &aItem, CONSTRAINT_ANCHOR aAnchor=CONSTRAINT_ANCHOR::WHOLE, int aIndex=-1)
virtual void SetEnd(const VECTOR2I &aPoint)
virtual void SetStart(const VECTOR2I &aPoint)
void ChangeOverrideText(const wxString &aValue)
For better understanding of the points that make a dimension:
void SetHeight(int aHeight)
Set the distance from the feature points to the crossbar line.
A drill chart placed on the board, kept in step with the holes.
Turns on drill symbols at the holes, for one layer.
wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
Return the string actually shown after processing of the base text.
void RebuildCells(const BOARD &aBoard, GENERATED_TABLE_REFRESH *aRefresh=nullptr)
Regenerate the cells from the board.
PCB_GENERATOR * DeepClone() const
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 FootprintSave(const wxString &aLibraryPath, const FOOTPRINT *aFootprint, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aFootprint to an existing library located at aLibraryPath.
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...
void FormatBoardToFormatter(OUTPUTFORMATTER *aOut, BOARD *aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr)
Serialize a BOARD to an OUTPUTFORMATTER without file I/O or Prettify.
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
Object to handle a bitmap image that can be inserted in a PCB.
REFERENCE_IMAGE & GetReferenceImage()
void SetEllipseCenter(const VECTOR2I &aPt) override
void SetCornerRadius(int aCornerRadius) override
void SetWidth(int aWidth) override
void SetEllipseStartAngle(const EDA_ANGLE &aA) override
void SetEllipseEndAngle(const EDA_ANGLE &aA) override
void SetEnd(const VECTOR2I &aEnd) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetEllipseMinorRadius(int aR) override
void SetStart(const VECTOR2I &aStart) override
void SetEllipseMajorRadius(int aR) override
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition pcb_shape.h:70
A board stackup table placed on the board, kept in step with the stackup.
int GetRowCount() const
Definition pcb_table.h:128
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
PCB_TABLECELL * GetCell(int aRow, int aCol) const
Definition pcb_table.h:155
void AddCell(PCB_TABLECELL *aCell)
Definition pcb_table.h:170
void SetColCount(int aCount)
Definition pcb_table.h:125
void SetTextThickness(int aWidth) override
The TextThickness is that set by the user.
Definition pcb_text.cpp:514
VECTOR2I GetPosition() const override
Definition pcb_text.h:101
int GetTextThickness() const override
Definition pcb_text.cpp:499
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition pcb_track.cpp:73
const VECTOR2I & GetStart() const
Definition pcb_track.h:100
const VECTOR2I & GetEnd() const
Definition pcb_track.h:97
virtual int GetWidth() const
Definition pcb_track.h:94
const STRING_ANY_MAP GetProperties() const override
PCB_TUNING_PATTERN(BOARD_ITEM *aParent=nullptr, PCB_LAYER_ID aLayer=F_Cu, LENGTH_TUNING_MODE aMode=LENGTH_TUNING_MODE::SINGLE)
PNS::MEANDER_SETTINGS & GetSettings()
A microvia stack: several single hop microvias, plus connecting traces for staggered stacks,...
VIA_STACK_STYLE GetStyle() const
PCB_LAYER_ID GetStartLayer() const
PCB_LAYER_ID GetEndLayer() const
wxString GetGeneratorType() const override
PCB_VIA_STITCH(BOARD_ITEM *aParent=nullptr)
int GetGuardedNetCode() const
Net being guarded in GUARD mode.
const PADSTACK & Padstack() const
Definition pcb_track.h:435
void SetViaType(VIATYPE aViaType)
Definition pcb_track.h:427
VIATYPE GetViaType() const
Definition pcb_track.h:426
bool m_isTimeDomain
Calculate tuning in the time domain.
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
bool ReadImageFile(const wxString &aFullFilename)
Read and store an image file.
const BITMAP_BASE & GetImage() const
Get the underlying image.
double GetImageScale() const
void SetImageScale(double aScale)
Set the image "zoom" value.
PROJECT * GetProject(const wxString &aFullPath) const
Retrieve a loaded project by name.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true, bool aOverrideLock=false)
Load a project or sets up a new project with a specified path.
double Area(bool aAbsolute=true) const
Return the area of this chain.
Represent a set of closed polygons.
double Area()
Return the area of this poly set.
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int NewOutline()
Creates a new empty polygon in the set and returns its index.
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
A name/value tuple with unique names and wxAny values.
bool get_to(const std::string &aKey, T &aVar) const
void set(const std::string &aKey, const T &aVar)
Implement an OUTPUTFORMATTER to a memory buffer.
Definition richio.h:430
const std::string & GetString()
Definition richio.h:453
void SetComment(int aIdx, const wxString &aComment)
Definition title_block.h:98
void SetTitle(const wxString &aTitle)
Definition title_block.h:55
const wxString & GetTitle() const
Definition title_block.h:60
A wrapper for reporting to a wxString object.
Definition reporter.h:242
Handle a list of polygons defining a copper zone.
Definition zone.h:70
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition zone.h:834
bool GetDoNotAllowVias() const
Definition zone.h:852
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
wxString GetPlacementAreaSource() const
Definition zone.h:839
std::shared_ptr< SHAPE_POLY_SET > GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition zone.h:701
bool GetDoNotAllowPads() const
Definition zone.h:854
PLACEMENT_SOURCE_T GetPlacementAreaSourceType() const
Definition zone.h:841
bool GetDoNotAllowTracks() const
Definition zone.h:853
bool IsFilled() const
Definition zone.h:306
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition zone.cpp:677
SHAPE_POLY_SET * Outline()
Definition zone.h:421
bool IsIsland(PCB_LAYER_ID aLayer, int aPolyIdx) const
Check if a given filled polygon is an insulated island.
Definition zone.cpp:1769
bool IsCopperThieving() const
Definition zone.h:349
const wxString & GetZoneName() const
Definition zone.h:160
SHAPE_POLY_SET GetBoardOutline() const
Definition zone.cpp:953
void SetFillMode(ZONE_FILL_MODE aFillMode)
Definition zone.cpp:683
void SetLayerSet(const LSET &aLayerSet) override
Definition zone.cpp:702
bool GetPlacementAreaEnabled() const
Definition zone.h:836
bool GetDoNotAllowFootprints() const
Definition zone.h:855
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition zone.h:133
bool GetDoNotAllowZoneFills() const
Definition zone.h:851
@ FOR_CANVAS
Definition common.h:92
DOWNGRADE_BUCKET
What happens to a feature when we export to an older KiCad.
@ BLOCK
Cannot be represented at all, export to this target is not possible.
@ LOWER
Approximated down to a simpler equivalent.
@ DROP
No equivalent, left out.
static bool empty(const wxTextEntryBase *aCtrl)
wxString DowngradeLibraryFilesInPlace(const wxString &aDir, const wxString &aGlob, int aStampVersion, const std::function< wxString(const wxString &)> &aFindForbidden, const std::function< DOWNGRADE_FILE_RESULT(const wxString &, const wxString &)> &aConvert, DOWNGRADE_FILE_TRANSACTION *aTransaction=nullptr, wxString *aRecoveryError=nullptr)
Downgrade every library file matching aGlob under aDir in place.
bool IsDowngradeDesignFile(const wxString &aPath)
Files the project export carries over.
DOWNGRADE_FILE_RESULT
What a per-file converter did with one library file.
@ REFUSED
The target cannot represent this file.
@ CONVERTED
The temp file holds the downgraded copy.
const std::vector< DOWNGRADE_TARGET > & GetDowngradeTargets()
Supported downgrade targets, newest first.
@ TRACK_WIDTH_CONSTRAINT
@ CLEARANCE_CONSTRAINT
constexpr const char * DRC_RULE_SEMANTIC_BREAKS[]
A function a release parses but answers differently, which the vocabulary cannot say.
const DRC_RULE_VOCABULARY * FindDrcRuleVocabulary(const DOWNGRADE_TARGET &aTarget)
The vocabulary a target release could parse, generated from its release tags by tools/generate_drc_ru...
DRC_RULES_FILTER_RESULT FilterDrcRulesForTarget(const wxString &aRulesText, const DOWNGRADE_TARGET &aTarget)
Filter a .kicad_dru file for the target.
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:474
@ DEGREES_T
Definition eda_angle.h:30
static constexpr EDA_ANGLE ANGLE_360
Definition eda_angle.h:478
@ NO_FILL
Definition eda_fill.h:30
@ HATCH
Definition eda_fill.h:34
@ FILLED_SHAPE
Fill with object color.
Definition eda_fill.h:31
@ RECURSE
Definition eda_item.h:51
SHAPE_T
Definition eda_shape.h:55
@ ELLIPSE
Definition eda_shape.h:63
@ SEGMENT
Definition eda_shape.h:57
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:58
@ ELLIPSE_ARC
Definition eda_shape.h:64
@ CUSTOM_LAYERS
Stackup handling where the footprint can have any number of copper layers, and objects on those layer...
Definition footprint.h:116
std::string source
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ Dwgs_User
Definition layer_ids.h:103
@ B_Cu
Definition layer_ids.h:61
@ In2_Cu
Definition layer_ids.h:63
@ F_SilkS
Definition layer_ids.h:96
@ In1_Cu
Definition layer_ids.h:62
@ F_Cu
Definition layer_ids.h:60
Test utilities for timestamps.
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
std::string ReadGoldenText(const std::string &aPath)
wxMemoryBuffer MakePngWithFractionalPixelsPerCm()
A tiny PNG whose embedded resolution gives a fractional pixels/cm, so the legacy truncating PPI diffe...
void DumpBoardToFile(BOARD &board, const std::filesystem::path &aFilename)
Utility function to simply write a Board out to a file.
double SerializedImageScale(const std::string &aContent, const std::string &aUuid)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
@ NON_COMPONENT
Pad with no hole that does not connect to a physical component, but rather provides a connection poin...
Definition padstack.h:106
@ PTH
Plated through hole pad.
Definition padstack.h:99
@ PRESSFIT
a PTH with a hole diameter with tight tolerances for press fit pin
Definition padstack.h:127
@ NONE
no special fabrication property
Definition padstack.h:119
BARCODE class definition.
@ HORIZONTAL
A segment (or two points) is horizontal.
Class to handle a set of BOARD_ITEMs.
#define SEXPR_FOOTPRINT_LIB_FILE_VERSION
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
@ STITCH
Fill the outline with vias with a pattern.
@ GUARD
Place vias to guard a net contained within.
void DowngradeProjectFileJson(nlohmann::json &aDoc, const DOWNGRADE_TARGET &aTarget, COMPATIBILITY_REPORT &aReport)
Migrate a .kicad_pro document down to what the target release expects.
@ RPT_SEVERITY_ERROR
One line in the compatibility report.
An older KiCad release we can export a project back to.
wxString m_text
The filtered rules file text.
wxString m_error
Invalid source syntax, do not write m_text.
std::vector< wxString > m_dropped
Names of the rules the target cannot parse.
Everything a rules file could name in one release.
std::optional< bool > is_capped
True if the drill hole should be capped.
Definition padstack.h:284
std::optional< bool > is_filled
True if the drill hole should be filled completely.
Definition padstack.h:283
std::optional< bool > has_covering
True if the pad on this side should have covering.
Definition padstack.h:266
std::optional< bool > has_plugging
True if the drill hole should be plugged on this side.
Definition padstack.h:267
std::optional< VECTOR2I > hatching_offset
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(EmptyBoardIsClean)
static size_t ParsedDrcRuleCount(const wxString &aText, const wxString &aSource)
static void checkFeature(const COMPATIBILITY_REPORT &aReport, const wxString &aName, DOWNGRADE_BUCKET aBucket, int aCount)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
const std::string table
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
std::string path
IbisParser parser & reporter
VECTOR3I expected(15, 30, 45)
static const DOWNGRADE_TARGET & kicad10
static const DOWNGRADE_TARGET & kicad9
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
wxString result
Test unit parsing edge cases and error handling.
#define M_PI
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:93
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:86
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:88
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)
Class ZONE_SETTINGS used to handle zones parameters in dialogs.