KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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
21
22#include <downgrade_scan.h>
25
26#include <algorithm>
27#include <cctype>
28#include <functional>
29#include <memory>
30#include <set>
31#include <string>
32#include <vector>
33
34#include <wx/ffile.h>
35#include <wx/filefn.h>
36
37#include <base_units.h>
38#include <board.h>
40#include <footprint.h>
42#include <pad.h>
43#include <pcb_barcode.h>
44#include <pcb_shape.h>
45#include <pcb_stackup_table.h>
46#include <pcb_table.h>
47#include <pcb_tablecell.h>
48#include <pcb_textbox.h>
49#include <pcb_track.h>
50#include <pcb_point.h>
51#include <pcb_reference_image.h>
52#include <zone.h>
53#include <zone_settings.h>
54#include <netinfo.h>
55#include <eda_group.h>
56#include <eda_shape.h>
57#include <pcb_group.h>
58#include <pcb_dimension.h>
59#include <pcb_generator.h>
60#include <pcb_text.h>
61#include <project.h>
62#include <common.h>
65#include <layer_ids.h>
66#include <lset.h>
74
75
76// Board format date each feature landed. A rule fires only when the target predates this.
77static constexpr int VER_USER_LAYERS = 20241229;
78static constexpr int VER_TEXTBOX_KNOCKOUT = 20250210;
79static constexpr int VER_SHAPE_HATCH = 20250222;
80static constexpr int VER_VIA_PROTECTION = 20250228;
81static constexpr int VER_ZONE_DEFAULTS = 20250302;
82static constexpr int VER_JUMPER_PADS = 20250324;
83static constexpr int VER_VIA_SPLIT = 20250926;
84static constexpr int VER_SKIP_VIA = 20250801;
85static constexpr int VER_PRESSFIT = 20250811;
86static constexpr int VER_POST_MACHINING = 20251101;
87static constexpr int VER_PCB_POINTS = 20250901;
88static constexpr int VER_ROUNDED_RECT = 20250829;
89static constexpr int VER_FP_UNITS = 20250909;
90static constexpr int VER_BARCODE = 20250914;
91static constexpr int VER_PAD_DIE_DELAY = 20250401;
92static constexpr int VER_TIME_DOMAIN_TUNING = 20250401;
93// Group placement arrived without a format bump while 20250401 was current.
94static constexpr int VER_GROUP_PLACEMENT = 20250401;
95static constexpr int VER_CELL_KNOCKOUT = 20260603;
96static constexpr int VER_BACKDRILL = 20251101;
97static constexpr int VER_EXTRUDED_BODY = 20260410;
98static constexpr int VER_ELLIPSE = 20260508;
99static constexpr int VER_THIEVING = 20260513;
100static constexpr int VER_NET_CHAINS = 20260512;
101static constexpr int VER_PAD_SIM = 20260521;
102static constexpr int VER_DIELECTRIC = 20260511;
103static constexpr int VER_GROUP_LIB_ID = 20250513;
104static constexpr int VER_IMAGE_PPI = 20260623;
105static constexpr int VER_CONSTRAINTS = 20260624;
106static constexpr int VER_GRIDS = 20260728;
107static constexpr int VER_VIA_STITCH = 20260816;
108static constexpr int VER_PROPERTY_VARIABLES = 20260817;
109static constexpr int VER_LINE_ENDINGS = 20260818;
110static constexpr int VER_SIM_EXCLUSION = 20260828;
111static constexpr int VER_VIA_STACK = 20260830;
112static constexpr int VER_CUSTOM_PROPERTIES = 20260831;
113static constexpr int VER_DRILL_DRAWINGS = 20260901;
114static constexpr int VER_FOOTPRINT_HEIGHT = 20261017;
115static constexpr int VER_LINKED_PLACEMENT = 20261018;
116static constexpr int VER_IMAGE_ROTATION = 20261025;
117static constexpr int VER_IMAGE_OPACITY = 20261025;
118static constexpr int VER_FP_LIB_HEADER = 20261028;
119static constexpr int VER_STACKUP_TABLE = 20261030;
120static constexpr int VER_NON_COMPONENT_PAD = 20261031;
121
122// The board format these rules were written against. When SEXPR_BOARD_FILE_VERSION moves past
123// it, ClassifyBoardForDowngrade asserts in debug builds until the new format is covered.
124//
125// 1. Find the commit that bumped the version and read what it added to common/pcb.keywords.
126// 2. If the new data is only written to the project file, nothing is needed here. Look at
127// project_file_downgrade.cpp instead. The 20250309 component class rules and the tuning
128// profile part of 20250401 were both that kind of bump.
129// 3. Otherwise add a VER_ constant above, a BOARD_RULE row that counts and strips the feature,
130// and a dated row in BOARD_TOKENS or BOARD_VALUES for each new node head or bareword value.
131// 4. Set this constant to the new version.
132static constexpr int BOARD_DOWNGRADE_COVERED = 20261031;
133
134// The footprint library format these rules were reviewed against. It moves independently of the
135// board format, so it needs its own gate.
136static constexpr int FOOTPRINT_LIB_DOWNGRADE_COVERED = 20261031;
137
138
139static bool isEllipse( const BOARD_ITEM* aItem )
140{
141 if( aItem->Type() != PCB_SHAPE_T )
142 return false;
143
144 SHAPE_T shape = static_cast<const PCB_SHAPE*>( aItem )->GetShape();
145 return shape == SHAPE_T::ELLIPSE || shape == SHAPE_T::ELLIPSE_ARC;
146}
147
148
149static bool isHatchedShape( const BOARD_ITEM* aItem )
150{
151 return aItem->Type() == PCB_SHAPE_T && static_cast<const PCB_SHAPE*>( aItem )->IsHatchedFill();
152}
153
154
155// A hatched fill on copper is copper, so losing it changes the board electrically. Elsewhere it is
156// ink. The two cases are reported and transformed separately.
157static bool isHatchedCopperShape( const BOARD_ITEM* aItem )
158{
159 return isHatchedShape( aItem ) && IsCopperLayer( aItem->GetLayer() );
160}
161
162
163static bool isHatchedInkShape( const BOARD_ITEM* aItem )
164{
165 return isHatchedShape( aItem ) && !IsCopperLayer( aItem->GetLayer() );
166}
167
168
169// FOOTPRINT::Remove does not detach group membership the way BOARD::Remove does, so items
170// deleted from a footprint must leave their group first or the writer walks a dangling pointer.
171static void detachFromGroup( BOARD_ITEM* aItem )
172{
173 if( EDA_GROUP* group = aItem->GetParentGroup() )
174 group->RemoveItem( aItem );
175}
176
177
178static void ellipseToPolygon( PCB_SHAPE* aShape, int aMaxError )
179{
180 // A board polygon is always closed, so an elliptical arc becomes a filled polygon of
181 // its stroked ink instead of an open outline.
182 if( aShape->GetShape() == SHAPE_T::ELLIPSE_ARC )
183 {
184 aShape->SetWidth( std::max( aShape->GetWidth(), 2 * aMaxError ) );
185
186 SHAPE_POLY_SET poly;
187 aShape->EDA_SHAPE::TransformShapeToPolygon( poly, 0, aMaxError, ERROR_INSIDE, false );
188 poly.Simplify();
189
190 // The writers save one outline per shape, so holes must become cuts.
191 poly.Fracture();
192
193 aShape->SetShape( SHAPE_T::POLY );
194 aShape->SetPolyShape( poly );
196 aShape->SetWidth( 0 );
197 return;
198 }
199
200 SHAPE_ELLIPSE ellipse( aShape->GetEllipseCenter(), aShape->GetEllipseMajorRadius(), aShape->GetEllipseMinorRadius(),
201 aShape->GetEllipseRotation() );
202
203 SHAPE_LINE_CHAIN chain = ellipse.ConvertToPolyline( aMaxError );
204 chain.SetClosed( true );
205
206 SHAPE_POLY_SET poly;
207 poly.AddOutline( chain );
208
209 aShape->SetShape( SHAPE_T::POLY );
210 aShape->SetPolyShape( poly );
211}
212
213
214// Per-footprint rule scopes. The board apply functions delegate to these, and
215// DowngradeFootprintInPlace runs them from the same rule table, so the standalone
216// .kicad_mod path cannot drift from the board path.
217static int footprintMaxError( const FOOTPRINT* aFootprint )
218{
219 return aFootprint->GetBoard() ? aFootprint->GetBoard()->GetDesignSettings().m_MaxError : pcbIUScale.mmToIU( 0.005 );
220}
221
222
223// Defined below with the rounded-rectangle helpers. Ellipses can also live in a custom pad.
224static void forEachPadPrimitive( FOOTPRINT* aFootprint, const std::function<void( PCB_SHAPE* )>& aFunc );
225
226
227static void lowerEllipsesFp( FOOTPRINT* aFootprint )
228{
229 int maxError = footprintMaxError( aFootprint );
230
231 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
232 {
233 if( isEllipse( item ) )
234 ellipseToPolygon( static_cast<PCB_SHAPE*>( item ), maxError );
235 }
236
237 forEachPadPrimitive( aFootprint,
238 [&]( PCB_SHAPE* aPrimitive )
239 {
240 if( isEllipse( aPrimitive ) )
241 ellipseToPolygon( aPrimitive, maxError );
242 } );
243}
244
245
246static void setHatchedFillsFp( FOOTPRINT* aFootprint, const std::function<bool( const BOARD_ITEM* )>& aMatches,
247 FILL_T aFill )
248{
249 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
250 {
251 if( aMatches( item ) )
252 static_cast<PCB_SHAPE*>( item )->SetFillMode( aFill );
253 }
254}
255
256
257// The sexpr writer only saves outline 0 of a polygon shape, so a barcode's ink must be
258// split into one shape per outline or all but one module would be lost on save.
259static std::vector<PCB_SHAPE*> barcodeToShapes( PCB_BARCODE* aBarcode, BOARD_ITEM_CONTAINER* aParent )
260{
261 SHAPE_POLY_SET poly;
262 aBarcode->TransformShapeToPolygon( poly, aBarcode->GetLayer(), 0, 0, ERROR_INSIDE );
263 poly.Simplify();
264
265 // Each shape below carries a single outline, so holes must become cuts first or a
266 // finder ring would print as a solid square.
267 poly.Fracture();
268
269 std::vector<PCB_SHAPE*> shapes;
270
271 for( int ii = 0; ii < poly.OutlineCount(); ++ii )
272 {
273 PCB_SHAPE* shape = new PCB_SHAPE( aParent, SHAPE_T::POLY );
274
275 SHAPE_POLY_SET single;
276 single.AddOutline( poly.Outline( ii ) );
277
278 shape->SetPolyShape( single );
280 shape->SetWidth( 0 );
281 shape->SetLayer( aBarcode->GetLayer() );
282 shape->SetLocked( aBarcode->IsLocked() );
283 shapes.push_back( shape );
284 }
285
286 return shapes;
287}
288
289
290static void lowerBarcodesFp( FOOTPRINT* aFootprint )
291{
292 std::vector<PCB_BARCODE*> barcodes;
293
294 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
295 {
296 if( item->Type() == PCB_BARCODE_T )
297 barcodes.push_back( static_cast<PCB_BARCODE*>( item ) );
298 }
299
300 for( PCB_BARCODE* barcode : barcodes )
301 {
302 EDA_GROUP* group = barcode->GetParentGroup();
303
304 for( PCB_SHAPE* shape : barcodeToShapes( barcode, aFootprint ) )
305 {
306 aFootprint->Add( shape );
307
308 if( group )
309 group->AddItem( shape );
310 }
311
312 detachFromGroup( barcode );
313 aFootprint->Remove( barcode );
314 delete barcode;
315 }
316}
317
318
319static void dropPcbPointsFp( FOOTPRINT* aFootprint )
320{
321 for( PCB_POINT* point : aFootprint->Points() )
322 {
323 detachFromGroup( point );
324 delete point;
325 }
326
327 aFootprint->Points().clear();
328}
329
330
331static void dropExtrudedBodiesFp( FOOTPRINT* aFootprint )
332{
333 aFootprint->ClearBody();
334}
335
336
337static void dropFootprintHeightsFp( FOOTPRINT* aFootprint )
338{
339 aFootprint->SetHeight( 0 );
340}
341
342
343static void dropPadSimTypesFp( FOOTPRINT* aFootprint )
344{
345 for( PAD* pad : aFootprint->Pads() )
346 pad->SetSimElectricalType( PAD_SIM_ELECTRICAL_TYPE::NONE );
347}
348
349
350static void dropUnitInfoFp( FOOTPRINT* aFootprint )
351{
352 aFootprint->SetUnitInfo( {} );
353}
354
355
356static void dropJumperPadsFp( FOOTPRINT* aFootprint )
357{
358 aFootprint->JumperPadGroups().Clear();
359 aFootprint->SetDuplicatePadNumbersAreJumpers( false );
360}
361
362
363static void dropPcbVariantsFp( FOOTPRINT* aFootprint )
364{
365 std::vector<wxString> names;
366
367 for( const auto& [name, variant] : aFootprint->GetVariants() )
368 names.push_back( name );
369
370 for( const wxString& name : names )
371 aFootprint->DeleteVariant( name );
372}
373
374
375static void dropPostMachiningFp( FOOTPRINT* aFootprint )
376{
377 for( PAD* pad : aFootprint->Pads() )
378 {
379 pad->Padstack().FrontPostMachining().mode.reset();
380 pad->Padstack().BackPostMachining().mode.reset();
381 }
382}
383
384
385static void dropPressFitPadsFp( FOOTPRINT* aFootprint )
386{
387 for( PAD* pad : aFootprint->Pads() )
388 {
389 if( pad->GetProperty() == PAD_PROP::PRESSFIT )
390 pad->SetProperty( PAD_PROP::NONE );
391 }
392}
393
394
395static void dropDieDelaysFp( FOOTPRINT* aFootprint )
396{
397 for( PAD* pad : aFootprint->Pads() )
398 pad->SetPadToDieDelay( 0 );
399}
400
401
402static void dropGroupDesignBlocksFp( FOOTPRINT* aFootprint )
403{
404 for( PCB_GROUP* group : aFootprint->Groups() )
405 group->SetDesignBlockLibId( LIB_ID() );
406}
407
408
409static int countNetChains( const BOARD* aBoard )
410{
411 int count = 0;
412
413 // Match what the writer emits: a named chain, or a net with terminal pads but no chain name.
414 for( NETINFO_ITEM* net : aBoard->GetNetInfo() )
415 {
416 if( !net->GetNetChain().IsEmpty() || net->GetTerminalPad( 0 ) || net->GetTerminalPad( 1 ) )
417 count++;
418 }
419
420 return count;
421}
422
423
424static void dropNetChains( BOARD* aBoard )
425{
426 for( NETINFO_ITEM* net : aBoard->GetNetInfo() )
427 {
428 net->SetNetChain( wxEmptyString );
429 net->ClearTerminalPad( 0 ); // terminal_pad is part of the net-chain feature
430 net->ClearTerminalPad( 1 );
431 }
432
433 std::vector<wxString> chains;
434
435 for( const auto& [chain, color] : aBoard->GetNetChainColors() )
436 chains.push_back( chain );
437
438 for( const wxString& chain : chains )
440}
441
442
443static int countEllipses( const BOARD* aBoard )
444{
445 int count = 0;
446
447 for( BOARD_ITEM* item : aBoard->Drawings() )
448 {
449 if( isEllipse( item ) )
450 count++;
451 }
452
453 for( FOOTPRINT* fp : aBoard->Footprints() )
454 {
455 for( BOARD_ITEM* item : fp->GraphicalItems() )
456 {
457 if( isEllipse( item ) )
458 count++;
459 }
460
462 [&]( PCB_SHAPE* aPrimitive )
463 {
464 if( isEllipse( aPrimitive ) )
465 count++;
466 } );
467 }
468
469 return count;
470}
471
472
473static void lowerEllipses( BOARD* aBoard )
474{
475 int maxError = aBoard->GetDesignSettings().m_MaxError;
476
477 for( BOARD_ITEM* item : aBoard->Drawings() )
478 {
479 if( isEllipse( item ) )
480 ellipseToPolygon( static_cast<PCB_SHAPE*>( item ), maxError );
481 }
482
483 for( FOOTPRINT* fp : aBoard->Footprints() )
484 lowerEllipsesFp( fp );
485}
486
487
488static int countExtrudedBodies( const BOARD* aBoard )
489{
490 int count = 0;
491
492 for( FOOTPRINT* fp : aBoard->Footprints() )
493 {
494 if( fp->HasBody() )
495 count++;
496 }
497
498 return count;
499}
500
501
502static void dropExtrudedBodies( BOARD* aBoard )
503{
504 for( FOOTPRINT* fp : aBoard->Footprints() )
506}
507
508
509static int countFootprintHeights( const BOARD* aBoard )
510{
511 int count = 0;
512
513 for( FOOTPRINT* fp : aBoard->Footprints() )
514 {
515 if( fp->GetHeight() != 0 )
516 count++;
517 }
518
519 return count;
520}
521
522
523static void dropFootprintHeights( BOARD* aBoard )
524{
525 for( FOOTPRINT* fp : aBoard->Footprints() )
527}
528
529
530static int countThievingZones( const BOARD* aBoard )
531{
532 int count = 0;
533
534 for( ZONE* zone : aBoard->Zones() )
535 {
536 if( zone->IsCopperThieving() )
537 count++;
538 }
539
540 for( FOOTPRINT* fp : aBoard->Footprints() )
541 {
542 for( ZONE* zone : fp->Zones() )
543 {
544 if( zone->IsCopperThieving() )
545 count++;
546 }
547 }
548
549 return count;
550}
551
552
553static int countPadSimTypes( const BOARD* aBoard )
554{
555 int count = 0;
556
557 for( PAD* pad : aBoard->GetPads() )
558 {
559 if( pad->GetSimElectricalType() != PAD_SIM_ELECTRICAL_TYPE::NONE )
560 count++;
561 }
562
563 return count;
564}
565
566
567static void dropPadSimTypes( BOARD* aBoard )
568{
569 for( FOOTPRINT* fp : aBoard->Footprints() )
570 dropPadSimTypesFp( fp );
571}
572
573
574static int countUnitInfo( const BOARD* aBoard )
575{
576 int count = 0;
577
578 for( FOOTPRINT* fp : aBoard->Footprints() )
579 {
580 // Every footprint carries a default single unit. Only more than one unit holds real
581 // gate-swap information, so only that is a reportable loss.
582 if( fp->GetUnitInfo().size() > 1 )
583 count++;
584 }
585
586 return count;
587}
588
589
590static void dropUnitInfo( BOARD* aBoard )
591{
592 for( FOOTPRINT* fp : aBoard->Footprints() )
593 dropUnitInfoFp( fp );
594}
595
596
597static int countBarcodes( const BOARD* aBoard )
598{
599 int count = 0;
600
601 for( BOARD_ITEM* item : aBoard->Drawings() )
602 {
603 if( item->Type() == PCB_BARCODE_T )
604 count++;
605 }
606
607 for( FOOTPRINT* fp : aBoard->Footprints() )
608 {
609 for( BOARD_ITEM* item : fp->GraphicalItems() )
610 {
611 if( item->Type() == PCB_BARCODE_T )
612 count++;
613 }
614 }
615
616 return count;
617}
618
619
620static void lowerBarcodes( BOARD* aBoard )
621{
622 std::vector<PCB_BARCODE*> barcodes;
623
624 for( BOARD_ITEM* item : aBoard->Drawings() )
625 {
626 if( item->Type() == PCB_BARCODE_T )
627 barcodes.push_back( static_cast<PCB_BARCODE*>( item ) );
628 }
629
630 for( PCB_BARCODE* barcode : barcodes )
631 {
632 EDA_GROUP* group = barcode->GetParentGroup();
633
634 for( PCB_SHAPE* shape : barcodeToShapes( barcode, aBoard ) )
635 {
636 aBoard->Add( shape );
637
638 if( group )
639 group->AddItem( shape );
640 }
641
642 aBoard->Remove( barcode );
643 delete barcode;
644 }
645
646 for( FOOTPRINT* fp : aBoard->Footprints() )
647 lowerBarcodesFp( fp );
648}
649
650
651static int countPcbVariants( const BOARD* aBoard )
652{
653 int count = aBoard->GetVariantNames().empty() ? 0 : 1;
654
655 for( FOOTPRINT* fp : aBoard->Footprints() )
656 {
657 if( !fp->GetVariants().empty() )
658 count++;
659 }
660
661 return count;
662}
663
664
665static void dropPcbVariants( BOARD* aBoard )
666{
667 aBoard->SetVariantNames( {} );
668 aBoard->SetCurrentVariant( wxEmptyString );
669
670 for( FOOTPRINT* fp : aBoard->Footprints() )
671 dropPcbVariantsFp( fp );
672}
673
674
675static int countJumperPads( const BOARD* aBoard )
676{
677 int count = 0;
678
679 for( FOOTPRINT* fp : aBoard->Footprints() )
680 {
681 if( !fp->JumperPadGroups().IsEmpty() || fp->GetDuplicatePadNumbersAreJumpers() )
682 count++;
683 }
684
685 return count;
686}
687
688
689static void dropJumperPads( BOARD* aBoard )
690{
691 for( FOOTPRINT* fp : aBoard->Footprints() )
692 dropJumperPadsFp( fp );
693}
694
695
696static bool hasBackdrill( const PADSTACK& aPadstack )
697{
698 return aPadstack.SecondaryDrill().size.x > 0 || aPadstack.TertiaryDrill().size.x > 0;
699}
700
701
702static int countBackdrills( const BOARD* aBoard )
703{
704 int count = 0;
705
706 for( PAD* pad : aBoard->GetPads() )
707 {
708 if( hasBackdrill( pad->Padstack() ) )
709 count++;
710 }
711
712 for( PCB_TRACK* track : aBoard->Tracks() )
713 {
714 if( track->Type() == PCB_VIA_T && hasBackdrill( static_cast<PCB_VIA*>( track )->Padstack() ) )
715 count++;
716 }
717
718 return count;
719}
720
721
722static bool hasPostMachining( const PADSTACK& aPadstack )
723{
724 auto set =
725 []( const PADSTACK::POST_MACHINING_PROPS& aProps )
726 {
727 return aProps.mode.has_value() && aProps.mode != PAD_DRILL_POST_MACHINING_MODE::NOT_POST_MACHINED;
728 };
729
730 return set( aPadstack.FrontPostMachining() ) || set( aPadstack.BackPostMachining() );
731}
732
733
734static int countPostMachining( const BOARD* aBoard )
735{
736 int count = 0;
737
738 for( PAD* pad : aBoard->GetPads() )
739 {
740 if( hasPostMachining( pad->Padstack() ) )
741 count++;
742 }
743
744 for( PCB_TRACK* track : aBoard->Tracks() )
745 {
746 if( track->Type() == PCB_VIA_T && hasPostMachining( static_cast<PCB_VIA*>( track )->Padstack() ) )
747 count++;
748 }
749
750 return count;
751}
752
753
754static void dropPostMachining( BOARD* aBoard )
755{
756 auto clear =
757 []( PADSTACK& aPadstack )
758 {
759 aPadstack.FrontPostMachining().mode.reset();
760 aPadstack.BackPostMachining().mode.reset();
761 };
762
763 for( FOOTPRINT* fp : aBoard->Footprints() )
765
766 for( PCB_TRACK* track : aBoard->Tracks() )
767 {
768 if( track->Type() == PCB_VIA_T )
769 clear( static_cast<PCB_VIA*>( track )->Padstack() );
770 }
771}
772
773
774static int countPressFitPads( const BOARD* aBoard )
775{
776 int count = 0;
777
778 for( PAD* pad : aBoard->GetPads() )
779 {
780 if( pad->GetProperty() == PAD_PROP::PRESSFIT )
781 count++;
782 }
783
784 return count;
785}
786
787
788static void dropPressFitPads( BOARD* aBoard )
789{
790 for( FOOTPRINT* fp : aBoard->Footprints() )
791 dropPressFitPadsFp( fp );
792}
793
794
795static int countBuriedVias( const BOARD* aBoard )
796{
797 int count = 0;
798
799 for( PCB_TRACK* track : aBoard->Tracks() )
800 {
801 if( track->Type() == PCB_VIA_T && static_cast<PCB_VIA*>( track )->GetViaType() == VIATYPE::BURIED )
802 count++;
803 }
804
805 return count;
806}
807
808
809// The old format had one blind type covering both, so a buried via becomes blind.
810static void lowerBuriedVias( BOARD* aBoard )
811{
812 for( PCB_TRACK* track : aBoard->Tracks() )
813 {
814 if( track->Type() == PCB_VIA_T )
815 {
816 PCB_VIA* via = static_cast<PCB_VIA*>( track );
817
818 if( via->GetViaType() == VIATYPE::BURIED )
819 via->SetViaType( VIATYPE::BLIND );
820 }
821 }
822}
823
824
825static int countZoneDefaults( const BOARD* aBoard )
826{
827 return aBoard->GetDesignSettings().m_ZoneLayerProperties.empty() ? 0 : 1;
828}
829
830
831static void dropZoneDefaults( BOARD* aBoard )
832{
834}
835
836
837static int countSkipVias( const BOARD* aBoard )
838{
839 int count = 0;
840
841 for( PCB_TRACK* track : aBoard->Tracks() )
842 {
843 if( track->Type() == PCB_VIA_T )
844 {
845 PCB_VIA* via = static_cast<PCB_VIA*>( track );
846
847 if( via->Padstack().UnconnectedLayerMode() == UNCONNECTED_LAYER_MODE::START_END_ONLY )
848 count++;
849 }
850 }
851
852 return count;
853}
854
855
856// Skip vias keep copper only on the start and end layers. The nearest older mode keeps the outer
857// rings and drops the inner ones, so use that.
858static void lowerSkipVias( BOARD* aBoard )
859{
860 for( PCB_TRACK* track : aBoard->Tracks() )
861 {
862 if( track->Type() != PCB_VIA_T )
863 continue;
864
865 PADSTACK& padstack = static_cast<PCB_VIA*>( track )->Padstack();
866
869 }
870}
871
872
873static int countDieDelays( const BOARD* aBoard )
874{
875 int count = 0;
876
877 for( PAD* pad : aBoard->GetPads() )
878 {
879 if( pad->GetPadToDieDelay() != 0 )
880 count++;
881 }
882
883 return count;
884}
885
886
887static void dropDieDelays( BOARD* aBoard )
888{
889 for( FOOTPRINT* fp : aBoard->Footprints() )
890 dropDieDelaysFp( fp );
891}
892
893
894static int countHatchedFills( const BOARD* aBoard, const std::function<bool( const BOARD_ITEM* )>& aMatches )
895{
896 int count = 0;
897
898 for( BOARD_ITEM* item : aBoard->Drawings() )
899 {
900 if( aMatches( item ) )
901 count++;
902 }
903
904 for( FOOTPRINT* fp : aBoard->Footprints() )
905 {
906 for( BOARD_ITEM* item : fp->GraphicalItems() )
907 {
908 if( aMatches( item ) )
909 count++;
910 }
911 }
912
913 return count;
914}
915
916
917static void setHatchedFills( BOARD* aBoard, const std::function<bool( const BOARD_ITEM* )>& aMatches, FILL_T aFill )
918{
919 for( BOARD_ITEM* item : aBoard->Drawings() )
920 {
921 if( aMatches( item ) )
922 static_cast<PCB_SHAPE*>( item )->SetFillMode( aFill );
923 }
924
925 for( FOOTPRINT* fp : aBoard->Footprints() )
926 setHatchedFillsFp( fp, aMatches, aFill );
927}
928
929
930static int countPcbPoints( const BOARD* aBoard )
931{
932 int count = static_cast<int>( aBoard->Points().size() );
933
934 for( FOOTPRINT* fp : aBoard->Footprints() )
935 count += static_cast<int>( fp->Points().size() );
936
937 return count;
938}
939
940
941static void dropPcbPoints( BOARD* aBoard )
942{
943 std::vector<BOARD_ITEM*> points( aBoard->Points().begin(), aBoard->Points().end() );
944
945 for( BOARD_ITEM* item : points )
946 {
947 aBoard->Remove( item );
948 delete item;
949 }
950
951 for( FOOTPRINT* fp : aBoard->Footprints() )
952 dropPcbPointsFp( fp );
953}
954
955
956static int countHighUserLayers( const BOARD* aBoard )
957{
958 const LSET& enabled = aBoard->GetEnabledLayers();
959 int count = 0;
960
961 // User_10 and up only exist since 20241229. Odd ids in this range are the user layers.
962 for( int layer = User_10; layer <= User_45; layer += 2 )
963 {
964 if( enabled.Contains( PCB_LAYER_ID( layer ) ) )
965 count++;
966 }
967
968 return count;
969}
970
971
972static bool hasViaProtection( const PCB_VIA* aVia )
973{
974 const PADSTACK& padstack = aVia->Padstack();
975
976 return padstack.Drill().is_filled.has_value()
977 || padstack.Drill().is_capped.has_value()
978 || padstack.FrontOuterLayers().has_covering.has_value()
979 || padstack.BackOuterLayers().has_covering.has_value()
980 || padstack.FrontOuterLayers().has_plugging.has_value()
981 || padstack.BackOuterLayers().has_plugging.has_value();
982}
983
984
985static int countViaProtection( const BOARD* aBoard )
986{
987 int count = 0;
988
989 for( PCB_TRACK* track : aBoard->Tracks() )
990 {
991 if( track->Type() == PCB_VIA_T && hasViaProtection( static_cast<PCB_VIA*>( track ) ) )
992 count++;
993 }
994
995 const BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings();
996
998 || bds.m_FillVias )
999 {
1000 count++;
1001 }
1002
1003 return count;
1004}
1005
1006
1007static void dropViaProtection( BOARD* aBoard )
1008{
1009 for( PCB_TRACK* track : aBoard->Tracks() )
1010 {
1011 if( track->Type() != PCB_VIA_T )
1012 continue;
1013
1014 PADSTACK& padstack = static_cast<PCB_VIA*>( track )->Padstack();
1015
1016 padstack.Drill().is_filled.reset();
1017 padstack.Drill().is_capped.reset();
1018 padstack.FrontOuterLayers().has_covering.reset();
1019 padstack.BackOuterLayers().has_covering.reset();
1020 padstack.FrontOuterLayers().has_plugging.reset();
1021 padstack.BackOuterLayers().has_plugging.reset();
1022 }
1023
1025
1026 bds.m_CoverViasFront = false;
1027 bds.m_CoverViasBack = false;
1028 bds.m_PlugViasFront = false;
1029 bds.m_PlugViasBack = false;
1030 bds.m_CapVias = false;
1031 bds.m_FillVias = false;
1032}
1033
1034
1035static int countDielectricModels( const BOARD* aBoard )
1036{
1037 const BOARD_STACKUP& stackup = aBoard->GetDesignSettings().GetStackupDescriptor();
1038
1039 int count = 0;
1040
1041 for( BOARD_STACKUP_ITEM* item : stackup.GetList() )
1042 {
1043 if( item->GetType() != BS_ITEM_TYPE_DIELECTRIC )
1044 continue;
1045
1046 for( int idx = 0; idx < item->GetSublayersCount(); idx++ )
1047 {
1048 if( item->GetDielectricModel( idx ) != DIELECTRIC_MODEL::CONSTANT )
1049 count++;
1050 }
1051 }
1052
1053 return count;
1054}
1055
1056
1057static void dropDielectricModels( BOARD* aBoard )
1058{
1060
1061 for( BOARD_STACKUP_ITEM* item : stackup.GetList() )
1062 {
1063 if( item->GetType() != BS_ITEM_TYPE_DIELECTRIC )
1064 continue;
1065
1066 for( int idx = 0; idx < item->GetSublayersCount(); idx++ )
1067 item->SetDielectricModel( DIELECTRIC_MODEL::CONSTANT, idx );
1068 }
1069}
1070
1071
1072static int countGroupDesignBlocks( const BOARD* aBoard )
1073{
1074 int count = 0;
1075
1076 for( PCB_GROUP* group : aBoard->Groups() )
1077 {
1078 if( group->HasDesignBlockLink() )
1079 count++;
1080 }
1081
1082 for( FOOTPRINT* fp : aBoard->Footprints() )
1083 {
1084 for( PCB_GROUP* group : fp->Groups() )
1085 {
1086 if( group->HasDesignBlockLink() )
1087 count++;
1088 }
1089 }
1090
1091 return count;
1092}
1093
1094
1095static void dropGroupDesignBlocks( BOARD* aBoard )
1096{
1097 for( PCB_GROUP* group : aBoard->Groups() )
1098 group->SetDesignBlockLibId( LIB_ID() );
1099
1100 for( FOOTPRINT* fp : aBoard->Footprints() )
1102}
1103
1104
1105static int countScaledFootprints( const BOARD* aBoard )
1106{
1107 int count = 0;
1108
1109 for( FOOTPRINT* fp : aBoard->Footprints() )
1110 {
1111 if( !fp->GetTransform().HasUnitScale() )
1112 count++;
1113 }
1114
1115 return count;
1116}
1117
1118
1119static bool isRoundedRect( const BOARD_ITEM* aItem )
1120{
1121 if( aItem->Type() != PCB_SHAPE_T )
1122 return false;
1123
1124 const PCB_SHAPE* shape = static_cast<const PCB_SHAPE*>( aItem );
1125 return shape->GetShape() == SHAPE_T::RECTANGLE && shape->GetCornerRadius() > 0;
1126}
1127
1128
1129static void roundedRectToPolygon( PCB_SHAPE* aShape, int aMaxError )
1130{
1131 int radius = aShape->GetCornerRadius();
1132
1133 SHAPE_POLY_SET poly;
1134 poly.NewOutline();
1135
1136 for( const VECTOR2I& corner : aShape->GetRectCorners() )
1137 poly.Append( corner );
1138
1139 poly = poly.Fillet( radius, aMaxError );
1140
1141 aShape->SetCornerRadius( 0 );
1142 aShape->SetShape( SHAPE_T::POLY );
1143 aShape->SetPolyShape( poly );
1144}
1145
1146
1147// Rounded rectangles can also live in custom pad primitives.
1148static void forEachPadPrimitive( FOOTPRINT* aFootprint, const std::function<void( PCB_SHAPE* )>& aFunc )
1149{
1150 for( PAD* pad : aFootprint->Pads() )
1151 {
1152 pad->Padstack().ForEachUniqueLayer(
1153 [&]( PCB_LAYER_ID aLayer )
1154 {
1155 for( const std::shared_ptr<PCB_SHAPE>& primitive : pad->GetPrimitives( aLayer ) )
1156 aFunc( primitive.get() );
1157 } );
1158 }
1159}
1160
1161
1162static int countRoundedRectsFp( const FOOTPRINT* aFootprint )
1163{
1164 int count = 0;
1165
1166 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
1167 {
1168 if( isRoundedRect( item ) )
1169 count++;
1170 }
1171
1172 forEachPadPrimitive( const_cast<FOOTPRINT*>( aFootprint ),
1173 [&]( PCB_SHAPE* aPrimitive )
1174 {
1175 if( isRoundedRect( aPrimitive ) )
1176 count++;
1177 } );
1178
1179 return count;
1180}
1181
1182
1183static void lowerRoundedRectsFp( FOOTPRINT* aFootprint )
1184{
1185 int maxError = footprintMaxError( aFootprint );
1186
1187 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
1188 {
1189 if( isRoundedRect( item ) )
1190 roundedRectToPolygon( static_cast<PCB_SHAPE*>( item ), maxError );
1191 }
1192
1193 forEachPadPrimitive( aFootprint,
1194 [&]( PCB_SHAPE* aPrimitive )
1195 {
1196 if( isRoundedRect( aPrimitive ) )
1197 roundedRectToPolygon( aPrimitive, maxError );
1198 } );
1199}
1200
1201
1202static int countRoundedRects( const BOARD* aBoard )
1203{
1204 int count = 0;
1205
1206 for( BOARD_ITEM* item : aBoard->Drawings() )
1207 {
1208 if( isRoundedRect( item ) )
1209 count++;
1210 }
1211
1212 for( FOOTPRINT* fp : aBoard->Footprints() )
1213 count += countRoundedRectsFp( fp );
1214
1215 return count;
1216}
1217
1218
1219static void lowerRoundedRects( BOARD* aBoard )
1220{
1221 int maxError = aBoard->GetDesignSettings().m_MaxError;
1222
1223 for( BOARD_ITEM* item : aBoard->Drawings() )
1224 {
1225 if( isRoundedRect( item ) )
1226 roundedRectToPolygon( static_cast<PCB_SHAPE*>( item ), maxError );
1227 }
1228
1229 for( FOOTPRINT* fp : aBoard->Footprints() )
1230 lowerRoundedRectsFp( fp );
1231}
1232
1233
1234static int countKnockoutTextBoxesFp( const FOOTPRINT* aFootprint )
1235{
1236 int count = 0;
1237
1238 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
1239 {
1240 if( item->Type() == PCB_TEXTBOX_T && item->IsKnockout() )
1241 count++;
1242 }
1243
1244 return count;
1245}
1246
1247
1248static void dropKnockoutTextBoxesFp( FOOTPRINT* aFootprint )
1249{
1250 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
1251 {
1252 if( item->Type() == PCB_TEXTBOX_T && item->IsKnockout() )
1253 item->SetIsKnockout( false );
1254 }
1255}
1256
1257
1258static int countKnockoutTextBoxes( const BOARD* aBoard )
1259{
1260 int count = 0;
1261
1262 for( BOARD_ITEM* item : aBoard->Drawings() )
1263 {
1264 if( item->Type() == PCB_TEXTBOX_T && item->IsKnockout() )
1265 count++;
1266 }
1267
1268 for( FOOTPRINT* fp : aBoard->Footprints() )
1269 count += countKnockoutTextBoxesFp( fp );
1270
1271 return count;
1272}
1273
1274
1275static void dropKnockoutTextBoxes( BOARD* aBoard )
1276{
1277 for( BOARD_ITEM* item : aBoard->Drawings() )
1278 {
1279 if( item->Type() == PCB_TEXTBOX_T && item->IsKnockout() )
1280 item->SetIsKnockout( false );
1281 }
1282
1283 for( FOOTPRINT* fp : aBoard->Footprints() )
1285}
1286
1287
1288static int countKnockoutCellsIn( const BOARD_ITEM* aItem )
1289{
1290 if( aItem->Type() != PCB_TABLE_T )
1291 return 0;
1292
1293 int count = 0;
1294
1295 for( PCB_TABLECELL* cell : static_cast<const PCB_TABLE*>( aItem )->GetCells() )
1296 {
1297 if( cell->IsKnockout() )
1298 count++;
1299 }
1300
1301 return count;
1302}
1303
1304
1305static int countKnockoutTableCells( const BOARD* aBoard )
1306{
1307 int count = 0;
1308
1309 for( BOARD_ITEM* item : aBoard->Drawings() )
1310 count += countKnockoutCellsIn( item );
1311
1312 for( FOOTPRINT* fp : aBoard->Footprints() )
1313 {
1314 for( BOARD_ITEM* item : fp->GraphicalItems() )
1315 count += countKnockoutCellsIn( item );
1316 }
1317
1318 return count;
1319}
1320
1321
1322static void dropKnockoutCellsIn( BOARD_ITEM* aItem )
1323{
1324 if( aItem->Type() != PCB_TABLE_T )
1325 return;
1326
1327 for( PCB_TABLECELL* cell : static_cast<PCB_TABLE*>( aItem )->GetCells() )
1328 {
1329 if( cell->IsKnockout() )
1330 cell->SetIsKnockout( false );
1331 }
1332}
1333
1334
1335static void dropKnockoutTableCellsFp( FOOTPRINT* aFootprint )
1336{
1337 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
1338 dropKnockoutCellsIn( item );
1339}
1340
1341
1342static void dropKnockoutTableCells( BOARD* aBoard )
1343{
1344 for( BOARD_ITEM* item : aBoard->Drawings() )
1345 dropKnockoutCellsIn( item );
1346
1347 for( FOOTPRINT* fp : aBoard->Footprints() )
1349}
1350
1351
1352static int countZoneLayerProperties( const BOARD* aBoard )
1353{
1354 int count = 0;
1355
1356 for( ZONE* zone : aBoard->Zones() )
1357 {
1358 if( !zone->LayerProperties().empty() )
1359 count++;
1360 }
1361
1362 for( FOOTPRINT* fp : aBoard->Footprints() )
1363 {
1364 for( ZONE* zone : fp->Zones() )
1365 {
1366 if( !zone->LayerProperties().empty() )
1367 count++;
1368 }
1369 }
1370
1371 return count;
1372}
1373
1374
1375static void dropZoneLayerPropertiesFp( FOOTPRINT* aFootprint )
1376{
1377 for( ZONE* zone : aFootprint->Zones() )
1378 zone->SetLayerProperties( {} );
1379}
1380
1381
1382static void dropZoneLayerProperties( BOARD* aBoard )
1383{
1384 for( ZONE* zone : aBoard->Zones() )
1385 zone->SetLayerProperties( {} );
1386
1387 for( FOOTPRINT* fp : aBoard->Footprints() )
1389}
1390
1391
1392static bool hasGroupPlacementLinkage( const ZONE* aZone )
1393{
1394 return aZone->GetIsRuleArea()
1396 && ( aZone->GetPlacementAreaEnabled() || !aZone->GetPlacementAreaSource().IsEmpty() );
1397}
1398
1399
1400static int countGroupPlacementAreas( const BOARD* aBoard )
1401{
1402 int count = std::count_if( aBoard->Zones().begin(), aBoard->Zones().end(), hasGroupPlacementLinkage );
1403
1404 for( const FOOTPRINT* footprint : aBoard->Footprints() )
1405 count += std::count_if( footprint->Zones().begin(), footprint->Zones().end(), hasGroupPlacementLinkage );
1406
1407 return count;
1408}
1409
1410
1411static void dropGroupPlacementLinkage( ZONE* aZone )
1412{
1414 {
1415 aZone->SetPlacementAreaEnabled( false );
1416 aZone->SetPlacementAreaSource( wxEmptyString );
1418 }
1419}
1420
1421
1422static void dropGroupPlacementAreasFp( FOOTPRINT* aFootprint )
1423{
1424 for( ZONE* zone : aFootprint->Zones() )
1426}
1427
1428
1429static void dropGroupPlacementAreas( BOARD* aBoard )
1430{
1431 for( ZONE* zone : aBoard->Zones() )
1433
1434 for( FOOTPRINT* footprint : aBoard->Footprints() )
1435 dropGroupPlacementAreasFp( footprint );
1436}
1437
1438
1439static int countCustomFpStackups( const BOARD* aBoard )
1440{
1441 int count = 0;
1442
1443 for( FOOTPRINT* fp : aBoard->Footprints() )
1444 {
1445 if( fp->GetStackupMode() != FOOTPRINT_STACKUP::EXPAND_INNER_LAYERS )
1446 count++;
1447 }
1448
1449 return count;
1450}
1451
1452
1453static int countNonComponentPads( const BOARD* aBoard )
1454{
1455 int count = 0;
1456
1457 for( const FOOTPRINT* fp : aBoard->Footprints() )
1458 {
1459 for( const PAD* pad : fp->Pads() )
1460 {
1461 if( pad->GetAttribute() == PAD_ATTRIB::NON_COMPONENT )
1462 count++;
1463 }
1464 }
1465
1466 return count;
1467}
1468
1469
1470// Omission is distinct from lowering: do not leave replacement polygons, plain knockout
1471// text, or electrically different vias behind when the user declines approximations.
1472static void omitGraphicsFp( FOOTPRINT* aFootprint, const std::function<bool( const BOARD_ITEM* )>& aMatches )
1473{
1474 std::vector<BOARD_ITEM*> remove;
1475
1476 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
1477 {
1478 if( aMatches( item ) )
1479 remove.push_back( item );
1480 }
1481
1482 for( BOARD_ITEM* item : remove )
1483 {
1484 detachFromGroup( item );
1485 aFootprint->Remove( item );
1486 delete item;
1487 }
1488}
1489
1490
1491static void omitGraphics( BOARD* aBoard, const std::function<bool( const BOARD_ITEM* )>& aMatches )
1492{
1493 std::vector<BOARD_ITEM*> remove;
1494
1495 for( BOARD_ITEM* item : aBoard->Drawings() )
1496 {
1497 if( aMatches( item ) )
1498 remove.push_back( item );
1499 }
1500
1501 for( BOARD_ITEM* item : remove )
1502 {
1503 aBoard->Remove( item );
1504 delete item;
1505 }
1506
1507 for( FOOTPRINT* fp : aBoard->Footprints() )
1508 omitGraphicsFp( fp, aMatches );
1509}
1510
1511
1512static void omitPadPrimitives( FOOTPRINT* aFootprint, const std::function<bool( const BOARD_ITEM* )>& aMatches )
1513{
1514 for( PAD* pad : aFootprint->Pads() )
1515 {
1516 pad->Padstack().ForEachUniqueLayer(
1517 [&]( PCB_LAYER_ID aLayer )
1518 {
1519 std::erase_if( pad->Padstack().Primitives( aLayer ),
1520 [&]( const std::shared_ptr<PCB_SHAPE>& aPrimitive )
1521 {
1522 return aMatches( aPrimitive.get() );
1523 } );
1524 } );
1525 pad->SetDirty();
1526 }
1527}
1528
1529
1530static void omitEllipsesFp( FOOTPRINT* aFootprint )
1531{
1532 omitGraphicsFp( aFootprint, isEllipse );
1533 omitPadPrimitives( aFootprint, isEllipse );
1534}
1535static void omitEllipses( BOARD* aBoard )
1536{
1537 omitGraphics( aBoard, isEllipse );
1538
1539 for( FOOTPRINT* fp : aBoard->Footprints() )
1541}
1542
1543static bool isBarcode( const BOARD_ITEM* aItem )
1544{
1545 return aItem->Type() == PCB_BARCODE_T;
1546}
1547static void omitBarcodesFp( FOOTPRINT* aFootprint )
1548{
1549 omitGraphicsFp( aFootprint, isBarcode );
1550}
1551static void omitBarcodes( BOARD* aBoard )
1552{
1553 omitGraphics( aBoard, isBarcode );
1554}
1555
1556static bool isKnockoutTextBox( const BOARD_ITEM* aItem )
1557{
1558 return aItem->Type() == PCB_TEXTBOX_T && aItem->IsKnockout();
1559}
1560
1561static void omitKnockoutTextBoxesFp( FOOTPRINT* aFootprint )
1562{
1563 omitGraphicsFp( aFootprint, isKnockoutTextBox );
1564}
1565static void omitKnockoutTextBoxes( BOARD* aBoard )
1566{
1568}
1569
1570
1571static void omitRoundedRectsFp( FOOTPRINT* aFootprint )
1572{
1573 omitGraphicsFp( aFootprint, isRoundedRect );
1574 omitPadPrimitives( aFootprint, isRoundedRect );
1575}
1576
1577
1578static void omitRoundedRects( BOARD* aBoard )
1579{
1580 omitGraphics( aBoard, isRoundedRect );
1581
1582 for( FOOTPRINT* fp : aBoard->Footprints() )
1584}
1585
1586
1588{
1589 if( aItem->Type() != PCB_TABLE_T )
1590 return;
1591
1592 for( PCB_TABLECELL* cell : static_cast<PCB_TABLE*>( aItem )->GetCells() )
1593 {
1594 if( cell->IsKnockout() )
1595 {
1596 // Keep the supported grid structure, but not a plain-text approximation of the ink.
1597 cell->SetText( wxEmptyString );
1598 cell->SetIsKnockout( false );
1599 }
1600 }
1601}
1602
1603
1604static void omitKnockoutTableCellsFp( FOOTPRINT* aFootprint )
1605{
1606 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
1608}
1609
1610
1611static void omitKnockoutTableCells( BOARD* aBoard )
1612{
1613 for( BOARD_ITEM* item : aBoard->Drawings() )
1615
1616 for( FOOTPRINT* fp : aBoard->Footprints() )
1618}
1619
1620
1621static int countConstraints( const BOARD* aBoard )
1622{
1623 int count = aBoard->Constraints().size();
1624
1625 for( const FOOTPRINT* fp : aBoard->Footprints() )
1626 count += fp->Constraints().size();
1627
1628 return count;
1629}
1630
1631
1632static void dropConstraintsFp( FOOTPRINT* aFootprint )
1633{
1634 const auto constraints = aFootprint->Constraints();
1635
1636 for( PCB_CONSTRAINT* constraint : constraints )
1637 {
1638 detachFromGroup( constraint );
1639 aFootprint->Remove( constraint );
1640 delete constraint;
1641 }
1642}
1643
1644
1645static void dropConstraints( BOARD* aBoard )
1646{
1647 const auto constraints = aBoard->Constraints();
1648
1649 for( PCB_CONSTRAINT* constraint : constraints )
1650 {
1651 aBoard->Remove( constraint );
1652 delete constraint;
1653 }
1654
1655 for( FOOTPRINT* fp : aBoard->Footprints() )
1656 dropConstraintsFp( fp );
1657}
1658
1659
1660static bool isGrid( const BOARD_ITEM* aItem )
1661{
1662 return aItem->Type() == PCB_GRID_ITEM_T;
1663}
1664
1665
1666static bool isDrillDrawing( const BOARD_ITEM* aItem )
1667{
1668 return aItem->Type() == PCB_DRILL_CHART_T || aItem->Type() == PCB_DRILL_MAP_T;
1669}
1670
1671
1672static int countDrawings( const BOARD* aBoard, const std::function<bool( const BOARD_ITEM* )>& aMatches )
1673{
1674 return std::count_if( aBoard->Drawings().begin(), aBoard->Drawings().end(), aMatches );
1675}
1676
1677
1678static int countGrids( const BOARD* aBoard )
1679{
1680 return countDrawings( aBoard, isGrid );
1681}
1682
1683
1684static void dropGrids( BOARD* aBoard )
1685{
1686 omitGraphics( aBoard, isGrid );
1687}
1688
1689
1690static bool isStackupTable( const BOARD_ITEM* aItem )
1691{
1692 return aItem->Type() == PCB_STACKUP_TABLE_T;
1693}
1694
1695
1696static int countStackupTables( const BOARD* aBoard )
1697{
1698 return countDrawings( aBoard, isStackupTable );
1699}
1700
1701
1702static void omitStackupTables( BOARD* aBoard )
1703{
1704 omitGraphics( aBoard, isStackupTable );
1705}
1706
1707
1713{
1714 PCB_TABLE* table = new PCB_TABLE( aParent, aTable->GetBorderWidth() );
1715
1716 table->SetLayer( aTable->GetLayer() );
1717 table->SetLocked( aTable->IsLocked() );
1718 table->SetBorderStroke( aTable->GetBorderStroke() );
1719 table->SetSeparatorsStroke( aTable->GetSeparatorsStroke() );
1720 table->SetStrokeExternal( aTable->StrokeExternal() );
1721 table->SetStrokeHeaderSeparator( aTable->StrokeHeaderSeparator() );
1722 table->SetStrokeColumns( aTable->StrokeColumns() );
1723 table->SetStrokeRows( aTable->StrokeRows() );
1724
1725 const int cols = aTable->GetColCount();
1726 const int rows = aTable->GetRowCount();
1727
1728 table->SetColCount( cols );
1729
1730 for( int col = 0; col < cols; ++col )
1731 table->SetColWidth( col, aTable->GetColWidth( col ) );
1732
1733 for( int row = 0; row < rows; ++row )
1734 table->SetRowHeight( row, aTable->GetRowHeight( row ) );
1735
1736 for( PCB_TABLECELL* cell : aTable->GetCells() )
1737 table->AddCell( static_cast<PCB_TABLECELL*>( cell->Clone() ) );
1738
1739 return table;
1740}
1741
1742
1743static void lowerStackupTables( BOARD* aBoard )
1744{
1745 // Nothing on the downgrade path refreshes generated tables, and a saved table can be stale.
1746 RefreshGeneratedTables( *aBoard );
1747
1748 std::vector<PCB_STACKUP_TABLE*> tables;
1749
1750 for( BOARD_ITEM* item : aBoard->Drawings() )
1751 {
1752 if( isStackupTable( item ) )
1753 tables.push_back( static_cast<PCB_STACKUP_TABLE*>( item ) );
1754 }
1755
1756 for( PCB_STACKUP_TABLE* live : tables )
1757 {
1758 EDA_GROUP* group = live->GetParentGroup();
1759 PCB_TABLE* flat = stackupTableToTable( live, aBoard );
1760
1761 aBoard->Add( flat );
1762
1763 if( group )
1764 group->AddItem( flat );
1765
1766 detachFromGroup( live );
1767 aBoard->Remove( live );
1768 delete live;
1769 }
1770}
1771
1772
1773static int countReferenceImageRotations( const BOARD* aBoard )
1774{
1775 const auto isRotatedReferenceImage = []( const BOARD_ITEM* aItem )
1776 {
1777 if( aItem->Type() != PCB_REFERENCE_IMAGE_T )
1778 return false;
1779
1780 const PCB_REFERENCE_IMAGE& refImage = static_cast<const PCB_REFERENCE_IMAGE&>( *aItem );
1781 return !refImage.GetReferenceImage().GetOrientation().IsZero();
1782 };
1783
1784 size_t count = std::count_if( aBoard->Drawings().begin(), aBoard->Drawings().end(), isRotatedReferenceImage );
1785
1786 for( FOOTPRINT* fp : aBoard->Footprints() )
1787 {
1788 count += std::count_if( fp->GraphicalItems().begin(), fp->GraphicalItems().end(), isRotatedReferenceImage );
1789 }
1790
1791 return static_cast<int>( count );
1792}
1793
1794
1795static int countReferenceImageOpacities( const BOARD* aBoard )
1796{
1797 const auto isReferenceImageWithOpacity = []( const BOARD_ITEM* aItem )
1798 {
1799 if( aItem->Type() != PCB_REFERENCE_IMAGE_T )
1800 return false;
1801
1802 const PCB_REFERENCE_IMAGE& refImage = static_cast<const PCB_REFERENCE_IMAGE&>( *aItem );
1803 return refImage.GetReferenceImage().GetOpacity() < 1.0;
1804 };
1805
1806 size_t count = std::count_if( aBoard->Drawings().begin(), aBoard->Drawings().end(), isReferenceImageWithOpacity );
1807
1808 for( FOOTPRINT* fp : aBoard->Footprints() )
1809 {
1810 count += std::count_if( fp->GraphicalItems().begin(), fp->GraphicalItems().end(), isReferenceImageWithOpacity );
1811 }
1812
1813 return static_cast<int>( count );
1814}
1815
1816
1818{
1819 const auto clearOpacity = []( BOARD_ITEM* aItem )
1820 {
1821 if( aItem->Type() == PCB_REFERENCE_IMAGE_T )
1822 static_cast<PCB_REFERENCE_IMAGE*>( aItem )->GetReferenceImage().SetOpacity( 1.0 );
1823 };
1824
1825 for( BOARD_ITEM* item : aBoard->Drawings() )
1826 clearOpacity( item );
1827
1828 for( FOOTPRINT* fp : aBoard->Footprints() )
1829 {
1830 for( BOARD_ITEM* item : fp->GraphicalItems() )
1831 clearOpacity( item );
1832 }
1833}
1834
1835
1836static int countDrillDrawings( const BOARD* aBoard )
1837{
1838 return countDrawings( aBoard, isDrillDrawing );
1839}
1840
1841
1842static void dropDrillDrawings( BOARD* aBoard )
1843{
1844 omitGraphics( aBoard, isDrillDrawing );
1845}
1846
1847
1848static int countDrillSymbolConfiguration( const BOARD* aBoard )
1849{
1850 return aBoard->GetDesignSettings().GetDrillSymbolProfile() == DRILL_SYMBOL_PROFILE() ? 0 : 1;
1851}
1852
1853
1858
1859
1860static int countGenerators( const BOARD* aBoard, const wxString& aType )
1861{
1862 return std::count_if( aBoard->Generators().begin(), aBoard->Generators().end(),
1863 [&]( const PCB_GENERATOR* aGenerator )
1864 {
1865 return aGenerator->GetGeneratorType() == aType;
1866 } );
1867}
1868
1869
1870static void dropGenerators( BOARD* aBoard, const std::function<bool( const PCB_GENERATOR* )>& aMatches )
1871{
1872 const auto generators = aBoard->Generators();
1873
1874 for( PCB_GENERATOR* generator : generators )
1875 {
1876 if( !aMatches( generator ) )
1877 continue;
1878
1879 EDA_GROUP* outer = generator->GetParentGroup();
1880 const auto members = generator->GetItems();
1881 generator->RemoveAll();
1882
1883 if( outer )
1884 {
1885 for( EDA_ITEM* member : members )
1886 outer->AddItem( member );
1887 }
1888
1889 aBoard->Remove( generator );
1890 delete generator;
1891 }
1892}
1893
1894
1895static void dropGenerators( BOARD* aBoard, const wxString& aType )
1896{
1897 dropGenerators( aBoard,
1898 [&]( const PCB_GENERATOR* aGenerator )
1899 {
1900 return aGenerator->GetGeneratorType() == aType;
1901 } );
1902}
1903
1904
1905static bool isTimeDomainTuning( const PCB_GENERATOR* aGenerator )
1906{
1907 const auto pattern = dynamic_cast<const PCB_TUNING_PATTERN*>( aGenerator );
1908 return pattern && !pattern->GetItems().empty() && pattern->GetSettings().m_isTimeDomain;
1909}
1910
1911
1912static int countTimeDomainTuning( const BOARD* aBoard )
1913{
1914 return std::count_if( aBoard->Generators().begin(), aBoard->Generators().end(), isTimeDomainTuning );
1915}
1916
1917
1918static void dropTimeDomainTuning( BOARD* aBoard )
1919{
1921}
1922
1923
1924static int countUnreviewedTuningProperties( const BOARD* aBoard )
1925{
1926 return std::count_if( aBoard->Generators().begin(), aBoard->Generators().end(),
1927 []( const PCB_GENERATOR* aGenerator )
1928 {
1929 if( aGenerator->GetGeneratorType() != wxT( "tuning_pattern" ) )
1930 return false;
1931
1932 return !dynamic_cast<const PCB_TUNING_PATTERN*>( aGenerator )
1933 || !KICAD_FORMAT::LEGACY::AreTuningPropertiesReviewed(
1934 aGenerator->GetProperties() );
1935 } );
1936}
1937
1938
1939static int countUnknownGenerators( const BOARD* aBoard )
1940{
1941 int count = 0;
1942
1943 for( PCB_GENERATOR* generator : aBoard->Generators() )
1944 {
1945 const wxString type = generator->GetGeneratorType();
1946
1947 if( type != wxT( "tuning_pattern" ) && type != wxT( "via_stitch" ) && type != wxT( "via_stack" ) )
1948 ++count;
1949
1950 for( EDA_ITEM* member : generator->GetItems() )
1951 {
1952 // Detached children would disappear when ownership metadata is removed.
1953 if( !dynamic_cast<BOARD_ITEM*>( member )
1954 || !aBoard->IsItemIndexedById( static_cast<BOARD_ITEM*>( member ) ) )
1955 {
1956 ++count;
1957 break;
1958 }
1959 }
1960 }
1961
1962 return count;
1963}
1964
1965
1966static bool isUnreviewedDrawing( const BOARD_ITEM* aItem )
1967{
1968 switch( aItem->Type() )
1969 {
1970 case PCB_SHAPE_T:
1971 case PCB_TEXT_T:
1972 case PCB_FIELD_T:
1973 case PCB_TEXTBOX_T:
1974 case PCB_TABLE_T:
1975 case PCB_DIM_ALIGNED_T:
1976 case PCB_DIM_CENTER_T:
1977 case PCB_DIM_RADIAL_T:
1979 case PCB_DIM_LEADER_T:
1981 case PCB_TARGET_T:
1982 case PCB_BARCODE_T:
1983 case PCB_GRID_ITEM_T:
1984 case PCB_DRILL_CHART_T:
1985 case PCB_DRILL_MAP_T:
1986 case PCB_STACKUP_TABLE_T: return false;
1987
1988 default: return true;
1989 }
1990}
1991
1992
1993static int countUnreviewedDrawings( const BOARD* aBoard )
1994{
1995 int count = countDrawings( aBoard, isUnreviewedDrawing );
1996
1997 for( FOOTPRINT* fp : aBoard->Footprints() )
1998 {
1999 count += std::count_if( fp->GraphicalItems().begin(), fp->GraphicalItems().end(), isUnreviewedDrawing );
2000 }
2001
2002 return count;
2003}
2004
2005
2006static void visitFootprintItems( const FOOTPRINT* aFootprint, const std::function<void( BOARD_ITEM* )>& aVisit )
2007{
2008 aVisit( const_cast<FOOTPRINT*>( aFootprint ) );
2009 aFootprint->RunOnChildren( aVisit, RECURSE_MODE::RECURSE );
2010}
2011
2012
2013static void visitBoardItems( const BOARD* aBoard, const std::function<void( BOARD_ITEM* )>& aVisit )
2014{
2015 aBoard->RunOnChildren( aVisit, RECURSE_MODE::RECURSE );
2016
2017 // Generators are omitted by BOARD::RunOnChildren.
2018 for( PCB_GENERATOR* generator : aBoard->Generators() )
2019 {
2020 aVisit( generator );
2021
2022 for( const auto& [name, item] : generator->GetTemplateItems() )
2023 {
2024 if( item )
2025 aVisit( const_cast<BOARD_ITEM*>( item ) );
2026 }
2027 }
2028}
2029
2030
2031static int countCustomProperties( const BOARD* aBoard )
2032{
2033 int count = 0;
2034 visitBoardItems( aBoard,
2035 [&]( BOARD_ITEM* aItem )
2036 {
2037 if( aItem && aItem->HasCustomProperties() )
2038 ++count;
2039 } );
2040 return count;
2041}
2042
2043
2044static void dropCustomPropertiesFp( FOOTPRINT* aFootprint )
2045{
2046 visitFootprintItems( aFootprint,
2047 []( BOARD_ITEM* aItem )
2048 {
2049 if( aItem )
2050 aItem->ClearCustomProperties();
2051 } );
2052}
2053
2054
2055static void dropCustomProperties( BOARD* aBoard )
2056{
2057 visitBoardItems( aBoard,
2058 []( BOARD_ITEM* aItem )
2059 {
2060 if( aItem )
2061 aItem->ClearCustomProperties();
2062 } );
2063}
2064
2065
2066static int countLinkedPlacementAreas( const BOARD* aBoard )
2067{
2068 int count = 0;
2069
2070 for( const ZONE* zone : aBoard->Zones() )
2071 {
2072 if( zone->GetLinkSet() != niluuid )
2073 ++count;
2074 }
2075
2076 return count;
2077}
2078
2079
2080static void dropLinkedPlacementAreas( BOARD* aBoard )
2081{
2082 for( ZONE* zone : aBoard->Zones() )
2083 {
2084 zone->SetLinkSet( niluuid );
2085 zone->SetRepeatOptions( REPEAT_LAYOUT_OPTIONS() );
2086 }
2087}
2088
2089
2090static int countSimulationExclusions( const BOARD* aBoard )
2091{
2092 int count = 0;
2093
2094 for( const FOOTPRINT* fp : aBoard->Footprints() )
2095 {
2096 bool excluded = fp->IsExcludedFromSim();
2097
2098 for( const auto& [name, variant] : fp->GetVariants() )
2099 excluded = excluded || variant.GetExcludedFromSim();
2100
2101 if( excluded )
2102 ++count;
2103 }
2104
2105 return count;
2106}
2107
2108
2109static void dropSimulationExclusionsFp( FOOTPRINT* aFootprint )
2110{
2111 aFootprint->SetExcludedFromSim( false );
2112
2113 for( const auto& [name, variant] : aFootprint->GetVariants() )
2114 aFootprint->GetVariant( name )->SetExcludedFromSim( false );
2115}
2116
2117
2118static void dropSimulationExclusions( BOARD* aBoard )
2119{
2120 for( FOOTPRINT* fp : aBoard->Footprints() )
2122}
2123
2124
2125static bool hasLineEndings( const BOARD_ITEM* aItem )
2126{
2127 if( !aItem || aItem->Type() != PCB_SHAPE_T )
2128 return false;
2129
2130 const PCB_SHAPE* shape = static_cast<const PCB_SHAPE*>( aItem );
2133}
2134
2135
2136static bool unsafeLineEndings( const PCB_SHAPE* aShape )
2137{
2138 VECTOR2I start, end;
2139
2140 if( !aShape->GetLineEndingEndpoints( start, end ) )
2141 return false;
2142
2143 const auto unsafeStroke =
2144 []( const STROKE_PARAMS& aStroke )
2145 {
2146 return ( aStroke.GetLineStyle() != LINE_STYLE::DEFAULT && aStroke.GetLineStyle() != LINE_STYLE::SOLID )
2147 || aStroke.GetColor() != KIGFX::COLOR4D::UNSPECIFIED;
2148 };
2149
2150 // The native polygon helper does not preserve dash patterns or ending colors.
2151 return aShape->GetEffectiveWidth() <= 0
2152 || ( aShape->GetLineStyle() != LINE_STYLE::DEFAULT && aShape->GetLineStyle() != LINE_STYLE::SOLID )
2153 || unsafeStroke( aShape->GetStartEnding().GetStroke() )
2154 || unsafeStroke( aShape->GetEndEnding().GetStroke() );
2155}
2156
2157
2158static int countLineEndings( const BOARD* aBoard, bool aUnsafeOnly = false )
2159{
2160 int count = 0;
2161 visitBoardItems( aBoard,
2162 [&]( BOARD_ITEM* aItem )
2163 {
2164 if( hasLineEndings( aItem )
2165 && ( !aUnsafeOnly || unsafeLineEndings( static_cast<PCB_SHAPE*>( aItem ) ) ) )
2166 ++count;
2167 } );
2168 return count;
2169}
2170
2171
2172static void clearLineEndings( PCB_SHAPE* aShape )
2173{
2174 aShape->SetStartEnding( LINE_ENDING() );
2175 aShape->SetEndEnding( LINE_ENDING() );
2176}
2177
2178
2179static void lowerLineEndingShape( PCB_SHAPE* aShape, int aMaxError )
2180{
2181 VECTOR2I start, end;
2182
2183 if( !aShape->GetLineEndingEndpoints( start, end ) )
2184 {
2185 clearLineEndings( aShape );
2186 return;
2187 }
2188
2189 SHAPE_POLY_SET ink;
2190 aShape->TransformWithLineEndingsToPolygon( ink, 0, aMaxError, ERROR_INSIDE );
2191 ink.Simplify();
2192 ink.Fracture();
2193 EDA_GROUP* group = aShape->GetParentGroup();
2194 BOARD_ITEM_CONTAINER* parent = aShape->GetParent();
2195
2196 for( int outline = 0; outline < ink.OutlineCount(); ++outline )
2197 {
2198 PCB_SHAPE* polygon = outline == 0 ? aShape : new PCB_SHAPE( *aShape );
2199 SHAPE_POLY_SET poly;
2200 poly.AddOutline( ink.COutline( outline ) );
2201 polygon->SetShape( SHAPE_T::POLY );
2202 polygon->SetPolyShape( poly );
2203 polygon->SetWidth( 0 );
2204 polygon->SetFillMode( FILL_T::FILLED_SHAPE );
2205 polygon->SetLineStyle( LINE_STYLE::SOLID );
2207
2208 if( outline > 0 )
2209 {
2210 const_cast<KIID&>( polygon->m_Uuid ) = KIID();
2211 polygon->SetParentGroup( nullptr );
2212 parent->Add( polygon );
2213
2214 if( group )
2215 group->AddItem( polygon );
2216 }
2217 }
2218
2219 if( ink.OutlineCount() == 0 )
2220 clearLineEndings( aShape );
2221}
2222
2223
2224static void transformLineEndingsFp( FOOTPRINT* aFootprint, bool aOmit )
2225{
2226 std::vector<PCB_SHAPE*> shapes;
2227 visitFootprintItems( aFootprint,
2228 [&]( BOARD_ITEM* aItem )
2229 {
2230 if( hasLineEndings( aItem ) )
2231 shapes.push_back( static_cast<PCB_SHAPE*>( aItem ) );
2232 } );
2233
2234 for( PCB_SHAPE* shape : shapes )
2235 {
2236 if( aOmit )
2237 clearLineEndings( shape );
2238 else if( !unsafeLineEndings( shape ) )
2239 lowerLineEndingShape( shape, footprintMaxError( aFootprint ) );
2240 }
2241}
2242
2243
2244static void transformLineEndings( BOARD* aBoard, bool aOmit )
2245{
2246 std::vector<PCB_SHAPE*> shapes;
2247 visitBoardItems( aBoard,
2248 [&]( BOARD_ITEM* aItem )
2249 {
2250 if( hasLineEndings( aItem ) )
2251 shapes.push_back( static_cast<PCB_SHAPE*>( aItem ) );
2252 } );
2253
2254 for( PCB_SHAPE* shape : shapes )
2255 {
2256 if( aOmit )
2257 clearLineEndings( shape );
2258 else if( !unsafeLineEndings( shape ) )
2260 }
2261}
2262
2263
2264static int titleFieldIndex( const wxString& aName )
2265{
2266 if( aName == wxT( "TITLE" ) )
2267 return 0;
2268 if( aName == wxT( "ISSUE_DATE" ) )
2269 return 1;
2270 if( aName == wxT( "REVISION" ) )
2271 return 2;
2272 if( aName == wxT( "COMPANY" ) )
2273 return 3;
2274 if( aName.length() == 8 && aName.StartsWith( wxT( "COMMENT" ) ) && aName[7] >= '1' && aName[7] <= '9' )
2275 return 4 + aName[7].GetValue() - '1';
2276 return -1;
2277}
2278
2279
2280static const wxString& titleFieldText( const TITLE_BLOCK& aTitle, int aIndex )
2281{
2282 switch( aIndex )
2283 {
2284 case 0: return aTitle.GetTitle();
2285 case 1: return aTitle.GetDate();
2286 case 2: return aTitle.GetRevision();
2287 case 3: return aTitle.GetCompany();
2288 default: return aTitle.GetComment( aIndex - 4 );
2289 }
2290}
2291
2292
2293static bool postTargetText( const wxString& aText, const BOARD* aBoard, int aTargetVersion,
2294 std::set<wxString>& aDependencies, int aDepth = 0 )
2295{
2296 if( aDepth > 32 )
2297 return true;
2298
2299 for( size_t pos = 0; pos + 1 < aText.length(); ++pos )
2300 {
2301 if( aText[pos] == '\\'
2302 && pos + 2 < aText.length()
2303 && ( aText[pos + 1] == '$' || aText[pos + 1] == '@' )
2304 && aText[pos + 2] == '{' )
2305 {
2306 if( aTargetVersion <= PCB_WRITER_V9::FORMAT_VERSION )
2307 return true;
2308
2309 int braces = 1;
2310 pos += 3;
2311
2312 for( ; pos < aText.length() && braces; ++pos )
2313 braces += aText[pos] == '{' ? 1 : ( aText[pos] == '}' ? -1 : 0 );
2314
2315 --pos;
2316 continue;
2317 }
2318
2319 if( aText[pos] == '@'
2320 && aText[pos + 1] == '{'
2321 && ( aTargetVersion <= PCB_WRITER_V9::FORMAT_VERSION || aText.Mid( pos ).Contains( wxT( "mils" ) ) ) )
2322 {
2323 return true;
2324 }
2325
2326 if( aText[pos] == '$'
2327 && aText[pos + 1] == '{'
2328 && aText.Mid( pos + 2 ).BeforeFirst( '}' ).AfterFirst( ':' ).StartsWith( wxT( "PROPERTY." ) ) )
2329 {
2330 return true;
2331 }
2332 }
2333
2334 for( const auto& reference : ExtractTextVarReferences( aText ) )
2335 {
2336 const wxString& name = reference.primary;
2337
2338 if( name.StartsWith( wxT( "PROPERTY." ) )
2339 || reference.secondary.StartsWith( wxT( "PROPERTY." ) )
2340 || name == wxT( "DRILL_OPERATIONS" )
2341 || name == wxT( "DRILL_SITES" )
2342 || name == wxT( "DRILL_GROUPS" ) )
2343 {
2344 return true;
2345 }
2346
2347 if( aBoard && titleFieldIndex( name ) >= 0 )
2348 {
2349 wxString resolved = name;
2350
2351 if( aBoard->GetTitleBlock().TextVarResolver( &resolved, aBoard->GetProject(), INTERNAL ) )
2352 {
2354
2355 if( aDependencies.insert( name ).second
2356 && postTargetText( resolved, aBoard, aTargetVersion, aDependencies, aDepth + 1 ) )
2357 return true;
2358
2359 continue;
2360 }
2361 }
2362
2363 if( aBoard )
2364 {
2365 const wxString* value = nullptr;
2366
2367 if( aBoard->GetProject() )
2368 {
2369 const std::map<wxString, wxString>& variables = aBoard->GetProject()->GetTextVars();
2370 auto variable = variables.find( name );
2371
2372 if( variable != variables.end() )
2373 value = &variable->second;
2374 }
2375
2376 if( !value )
2377 {
2378 const std::map<wxString, wxString>& properties = aBoard->GetProperties();
2379 auto property = properties.find( name );
2380
2381 if( property != properties.end() )
2382 value = &property->second;
2383 }
2384
2385 if( value
2386 && aDependencies.insert( name ).second
2387 && postTargetText( *value, aBoard, aTargetVersion, aDependencies, aDepth + 1 ) )
2388 {
2389 return true;
2390 }
2391 }
2392 }
2393
2394 return false;
2395}
2396
2397
2398static bool postTargetText( const wxString& aText, const BOARD* aBoard, int aTargetVersion )
2399{
2400 std::set<wxString> dependencies;
2401 return postTargetText( aText, aBoard, aTargetVersion, dependencies );
2402}
2403
2404
2406{
2407 std::vector<std::pair<BOARD_ITEM*, wxString>> m_replacements;
2408 std::vector<std::pair<int, wxString>> m_titleReplacements;
2409 BOARD* m_board = nullptr;
2410 int m_blocked = 0;
2411};
2412
2413
2414static bool hasActiveExpression( const wxString& aText )
2415{
2416 for( size_t pos = 0; pos + 1 < aText.length(); ++pos )
2417 {
2418 if( aText[pos] == '\\' && pos + 2 < aText.length() && ( aText[pos + 1] == '$' || aText[pos + 1] == '@' )
2419 && aText[pos + 2] == '{' )
2420 {
2421 int braces = 1;
2422 pos += 3;
2423
2424 for( ; pos < aText.length() && braces; ++pos )
2425 braces += aText[pos] == '{' ? 1 : ( aText[pos] == '}' ? -1 : 0 );
2426
2427 --pos;
2428 }
2429 else if( aText[pos] == '@' && aText[pos + 1] == '{' )
2430 {
2431 return true;
2432 }
2433 }
2434
2435 return false;
2436}
2437
2438
2439static void planTextItem( BOARD_ITEM* aItem, int aTargetVersion, TEXT_DOWNGRADE_PLAN& aPlan,
2440 const std::function<bool( wxString* )>* aResolver = nullptr )
2441{
2442 if( !aItem )
2443 return;
2444
2445 EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
2446 PCB_BARCODE* barcode = dynamic_cast<PCB_BARCODE*>( aItem );
2447 PCB_DIMENSION_BASE* dimension = dynamic_cast<PCB_DIMENSION_BASE*>( aItem );
2448
2449 if( !text && !barcode )
2450 return;
2451
2452 if( dimension && !dimension->GetOverrideTextEnabled() )
2453 return;
2454
2455 const wxString raw = dimension ? dimension->GetOverrideText() : ( text ? text->GetText() : barcode->GetText() );
2456 BOARD* board = aItem->GetBoard();
2457
2458 if( !postTargetText( raw, board, aTargetVersion ) )
2459 return;
2460
2461 std::function<bool( wxString* )> resolver =
2462 [&]( wxString* aToken )
2463 {
2464 if( aResolver )
2465 return ( *aResolver )( aToken );
2466
2467 if( *aToken == wxT( "LAYER" ) && board )
2468 {
2469 *aToken = board->GetLayerName( aItem->GetLayer() );
2470 return true;
2471 }
2472
2473 FOOTPRINT* fp = aItem->GetParentFootprint();
2474 return ( fp && fp->ResolveTextVar( aToken, 0 ) ) || ( board && board->ResolveTextVar( aToken, 0 ) );
2475 };
2476
2477 wxString result;
2478 bool blocked = false;
2479
2480 for( size_t pos = 0; pos < raw.length(); )
2481 {
2482 size_t start = pos;
2483 bool escaped = raw[pos] == '\\'
2484 && pos + 2 < raw.length()
2485 && ( raw[pos + 1] == '$' || raw[pos + 1] == '@' )
2486 && raw[pos + 2] == '{';
2487 size_t marker = escaped ? pos + 1 : pos;
2488
2489 if( marker + 1 >= raw.length() || ( raw[marker] != '$' && raw[marker] != '@' ) || raw[marker + 1] != '{' )
2490 {
2491 result += raw[pos++];
2492 continue;
2493 }
2494
2495 int braces = 1;
2496 pos = marker + 2;
2497
2498 while( pos < raw.length() && braces )
2499 {
2500 braces += raw[pos] == '{' ? 1 : ( raw[pos] == '}' ? -1 : 0 );
2501 ++pos;
2502 }
2503
2504 wxString block = raw.Mid( start, pos - start );
2505
2506 if( escaped || !postTargetText( block, board, aTargetVersion ) )
2507 {
2508 result += block;
2509 continue;
2510 }
2511
2512 if( braces )
2513 {
2514 blocked = true;
2515 break;
2516 }
2517
2518 if( !aResolver )
2519 {
2520 // Resolve only the affected token using the native item-context semantics.
2521 if( auto cell = dynamic_cast<PCB_TABLECELL*>( aItem ) )
2522 {
2523 if( cell->GetRow() < 0 || cell->GetColumn() < 0 )
2524 {
2525 blocked = true;
2526 break;
2527 }
2528
2529 PCB_TABLE table( *static_cast<PCB_TABLE*>( cell->GetParent() ) );
2530 PCB_TABLECELL* temporary = table.GetCell( cell->GetRow(), cell->GetColumn() );
2531
2532 if( !temporary )
2533 {
2534 blocked = true;
2535 break;
2536 }
2537
2538 temporary->SetText( block );
2539 block = temporary->GetUnwrappedShownText( INTERNAL );
2540 }
2541 else
2542 {
2543 PCB_TEXT temporary( aItem->GetParent() );
2544 temporary.SetLayer( aItem->GetLayer() );
2545 temporary.SetText( block );
2546 block = temporary.GetShownText( INTERNAL );
2547 }
2548
2549 if( hasActiveExpression( block ) )
2550 blocked = true;
2551 }
2552 else
2553 {
2554 for( int depth = 0; depth < 32; ++depth )
2555 {
2556 wxString expanded = ExpandTextVars( block, &resolver, INTERNAL );
2557
2558 if( hasActiveExpression( expanded ) )
2559 {
2560 EXPRESSION_EVALUATOR evaluator;
2561 expanded = evaluator.Evaluate( expanded );
2562
2563 if( evaluator.HasErrors() )
2564 {
2565 blocked = true;
2566 break;
2567 }
2568 }
2569
2570 if( expanded == block )
2571 break;
2572
2573 block = expanded;
2574 }
2575
2576 if( hasActiveExpression( block ) )
2577 blocked = true;
2578 }
2579
2581
2582 if( postTargetText( block, board, aTargetVersion )
2583 || block.Contains( wxT( "<Unresolved:" ) )
2584 || block.Contains( wxT( "<Unknown reference:" ) ) )
2585 {
2586 blocked = true;
2587 }
2588
2589 result += block;
2590 }
2591
2592 if( aTargetVersion <= PCB_WRITER_V9::FORMAT_VERSION
2593 && ( result.Contains( wxT( "\\${" ) ) || result.Contains( wxT( "\\@{" ) ) ) )
2594 blocked = true;
2595
2596 if( blocked )
2597 ++aPlan.m_blocked;
2598 else if( result != raw )
2599 aPlan.m_replacements.emplace_back( aItem, result );
2600}
2601
2602
2603static TEXT_DOWNGRADE_PLAN planBoardText( const BOARD* aBoard, int aTargetVersion )
2604{
2606 plan.m_board = const_cast<BOARD*>( aBoard );
2607 visitBoardItems( aBoard,
2608 [&]( BOARD_ITEM* aItem )
2609 {
2610 planTextItem( aItem, aTargetVersion, plan );
2611 } );
2612
2613 std::function<bool( wxString* )> resolver = [&]( wxString* aToken )
2614 {
2615 if( *aToken == wxT( "FILENAME" )
2616 || *aToken == wxT( "FILEPATH" )
2617 || *aToken == wxT( "VARIANT" )
2618 || *aToken == wxT( "VARIANT_DESC" ) )
2619 {
2620 return aBoard->ResolveTextVar( aToken, 0 );
2621 }
2622
2623 return aBoard->GetTitleBlock().TextVarResolver( aToken, aBoard->GetProject(), INTERNAL )
2624 || ( aBoard->GetProject() && aBoard->GetProject()->TextVarResolver( aToken ) );
2625 };
2626
2627 // Worksheet metadata has no footprint context or fixed plotted layer.
2628 for( int field = 0; field < 13; ++field )
2629 {
2630 PCB_TEXT temporary( const_cast<BOARD*>( aBoard ) );
2631 temporary.SetText( titleFieldText( aBoard->GetTitleBlock(), field ) );
2632 TEXT_DOWNGRADE_PLAN title;
2633 planTextItem( &temporary, aTargetVersion, title, &resolver );
2634 plan.m_blocked += title.m_blocked;
2635
2636 if( !title.m_replacements.empty() )
2637 plan.m_titleReplacements.emplace_back( field, title.m_replacements.front().second );
2638 }
2639
2640 return plan;
2641}
2642
2643
2644static void applyTextPlan( const TEXT_DOWNGRADE_PLAN& aPlan )
2645{
2646 for( const auto& [item, value] : aPlan.m_replacements )
2647 {
2648 if( auto dimension = dynamic_cast<PCB_DIMENSION_BASE*>( item ) )
2649 dimension->ChangeOverrideText( value );
2650 else if( auto text = dynamic_cast<EDA_TEXT*>( item ) )
2651 text->SetText( value );
2652 else if( auto barcode = dynamic_cast<PCB_BARCODE*>( item ) )
2653 barcode->SetBarcodeText( value );
2654 }
2655
2656 for( const auto& [field, value] : aPlan.m_titleReplacements )
2657 {
2658 TITLE_BLOCK& title = aPlan.m_board->GetTitleBlock();
2659
2660 switch( field )
2661 {
2662 case 0: title.SetTitle( value ); break;
2663 case 1: title.SetDate( value ); break;
2664 case 2: title.SetRevision( value ); break;
2665 case 3: title.SetCompany( value ); break;
2666 default: title.SetComment( field - 4, value ); break;
2667 }
2668 }
2669}
2670
2671
2672// One row per feature. The report and the transform both walk this list, so they cannot drift.
2673// To add a feature, add a row. A null apply means the feature blocks the export.
2675{
2678 wxString m_feature;
2679 wxString m_detail;
2680 std::function<int( const BOARD* )> m_count;
2681 std::function<void( BOARD* )> m_apply;
2682 std::function<void( FOOTPRINT* )> m_applyFp = {};
2683 std::function<void( BOARD* )> m_omit = {};
2684 std::function<void( FOOTPRINT* )> m_omitFp = {};
2685 wxString m_omitDetail = {};
2686
2690};
2691
2692
2693static std::vector<BOARD_RULE> boardRules()
2694{
2695 // clang-format off
2696 return {
2697 { VER_CONSTRAINTS, DOWNGRADE_BUCKET::BLOCK, _( "Unreviewed generated objects" ),
2698 _( "Unknown generator kinds or detached generated children cannot be safely exported." ),
2699 countUnknownGenerators, nullptr },
2700 { VER_CONSTRAINTS, DOWNGRADE_BUCKET::BLOCK, _( "Unreviewed tuning properties" ),
2701 _( "The tuning generator contains properties outside the reviewed historical schemas." ),
2703 { VER_TIME_DOMAIN_TUNING, DOWNGRADE_BUCKET::DROP, _( "Time-domain tuning patterns" ),
2704 _( "Generator editability is removed. Existing generated copper and group membership are kept." ),
2706 { VER_GROUP_PLACEMENT, DOWNGRADE_BUCKET::DROP, _( "Group placement areas" ),
2707 _( "Group placement linkage is removed. Zone geometry, keepout settings, groups, and copper are kept." ),
2709 { VER_CONSTRAINTS, DOWNGRADE_BUCKET::BLOCK, _( "Unreviewed board graphics" ),
2710 _( "An unrecognized graphic item cannot be safely represented by the target writer." ),
2711 countUnreviewedDrawings, nullptr },
2712 { VER_CONSTRAINTS, DOWNGRADE_BUCKET::DROP, _( "Geometric constraints" ),
2713 _( "Solver relationships are removed. Existing geometry is kept in its current position." ), countConstraints,
2715 { VER_GRIDS, DOWNGRADE_BUCKET::DROP, _( "Local grids" ),
2716 _( "Placement, snapping, and routing grid configuration is removed. Copper is unchanged." ), countGrids,
2717 dropGrids },
2718 { VER_VIA_STITCH, DOWNGRADE_BUCKET::DROP, _( "Via stitching and guarding" ),
2719 _( "Generator editability is removed. Existing generated copper and group membership are kept." ),
2720 []( const BOARD* b )
2721 {
2722 return countGenerators( b, wxT( "via_stitch" ) );
2723 },
2724 []( BOARD* b )
2725 {
2726 dropGenerators( b, wxT( "via_stitch" ) );
2727 } },
2728 { VER_VIA_STACK, DOWNGRADE_BUCKET::DROP, _( "Microvia stack generators" ),
2729 _( "Generator editability is removed. Existing generated copper and group membership are kept." ),
2730 []( const BOARD* b )
2731 {
2732 return countGenerators( b, wxT( "via_stack" ) );
2733 },
2734 []( BOARD* b )
2735 {
2736 dropGenerators( b, wxT( "via_stack" ) );
2737 } },
2738 { VER_LINE_ENDINGS, DOWNGRADE_BUCKET::LOWER, _( "Graphic line endings" ),
2739 _( "Converted to printed polygons with the shortened line body. Ending editability is lost." ),
2740 []( const BOARD* b )
2741 {
2742 return countLineEndings( b );
2743 },
2744 []( BOARD* b )
2745 {
2746 transformLineEndings( b, false );
2747 },
2748 []( FOOTPRINT* f )
2749 {
2750 transformLineEndingsFp( f, false );
2751 },
2752 []( BOARD* b )
2753 {
2754 transformLineEndings( b, true );
2755 },
2756 []( FOOTPRINT* f )
2757 {
2758 transformLineEndingsFp( f, true );
2759 },
2760 _( "Endpoint embellishments are removed. The supported line body and its style are kept." ) },
2761 { VER_SIM_EXCLUSION, DOWNGRADE_BUCKET::DROP, _( "Footprint simulation exclusions" ),
2762 _( "Simulation exclusions are removed. The target may include these footprints in simulation." ),
2764 { VER_CUSTOM_PROPERTIES, DOWNGRADE_BUCKET::DROP, _( "Custom properties" ),
2765 _( "Custom item metadata is removed after affected displayed text has been resolved." ),
2767 { VER_DRILL_DRAWINGS, DOWNGRADE_BUCKET::DROP, _( "Drill charts and maps" ),
2768 _( "Drill chart tables and drill map symbols are removed from the fabrication drawings. Holes are kept." ),
2770 { VER_DRILL_DRAWINGS, DOWNGRADE_BUCKET::DROP, _( "Drill symbol configuration" ),
2771 _( "Drill symbol assignments and display settings are removed. Holes are unchanged." ),
2773 { VER_LINKED_PLACEMENT, DOWNGRADE_BUCKET::DROP, _( "Linked placement rule areas" ),
2774 _( "Links between placement rule areas and their saved repeat layout options are removed. "
2775 "The copied layouts are kept." ),
2777 { VER_IMAGE_ROTATION, DOWNGRADE_BUCKET::BLOCK, _( "Rotated reference images" ),
2778 _( "The target cannot store an image rotation." ),
2780 { VER_IMAGE_OPACITY, DOWNGRADE_BUCKET::DROP, _( "Reference image opacity" ),
2781 _( "The target cannot store an image opacity. Opacity will be ignored." ),
2783 { VER_NET_CHAINS, DOWNGRADE_BUCKET::DROP, _( "Net chains" ),
2784 _( "No equivalent in the target. Connectivity will change." ),
2786 { VER_ELLIPSE, DOWNGRADE_BUCKET::LOWER, _( "Ellipse graphics" ),
2787 _( "Approximated by a polygon." ),
2789 _( "Ellipse graphics are omitted instead of approximated." ) },
2790 { VER_EXTRUDED_BODY, DOWNGRADE_BUCKET::DROP, _( "Extruded 3D bodies" ),
2791 _( "No equivalent in the target. The 3D body is left out." ),
2793 { VER_FOOTPRINT_HEIGHT, DOWNGRADE_BUCKET::DROP, _( "Footprint overall height" ),
2794 _( "No equivalent in the target. The footprint height is left out." ),
2796 { VER_THIEVING, DOWNGRADE_BUCKET::BLOCK, _( "Copper-thieving zones" ),
2797 _( "A refill in the target would turn the pattern into solid copper." ),
2798 countThievingZones, nullptr },
2799 { VER_PAD_SIM, DOWNGRADE_BUCKET::DROP, _( "Pad simulation types" ),
2800 _( "The simulation electrical type is left out." ),
2802 { VER_FP_UNITS, DOWNGRADE_BUCKET::DROP, _( "Footprint unit metadata" ),
2803 _( "Pin-to-unit assignments used for gate swapping are removed." ),
2805 { VER_BARCODE, DOWNGRADE_BUCKET::LOWER, _( "Barcodes" ),
2806 _( "Converted to the printed polygons. No longer editable as a barcode." ),
2808 _( "Barcodes are omitted instead of converted to polygons." ) },
2809 { FIRST_PCB_VARIANTS, DOWNGRADE_BUCKET::DROP, _( "PCB variants" ),
2810 _( "Variant registry and per-footprint overrides are removed." ),
2812 { VER_JUMPER_PADS, DOWNGRADE_BUCKET::DROP, _( "Jumper pad groups" ),
2813 _( "Jumper pad groupings are removed." ),
2815 { VER_BACKDRILL, DOWNGRADE_BUCKET::BLOCK, _( "Backdrill / tertiary drill" ),
2816 _( "Backdrilling changes copper connectivity and cannot be represented." ),
2817 countBackdrills, nullptr },
2818 { VER_POST_MACHINING, DOWNGRADE_BUCKET::DROP, _( "Counterbore / countersink" ),
2819 _( "Drill post-machining is removed." ), countPostMachining, dropPostMachining, dropPostMachiningFp },
2820 { VER_PRESSFIT, DOWNGRADE_BUCKET::DROP, _( "Press-fit pads" ),
2821 _( "The press-fit fabrication property is removed." ),
2823 { VER_SKIP_VIA, DOWNGRADE_BUCKET::LOWER, _( "Skip vias" ),
2824 _( "Approximated by keeping only the start and end layers." ),
2827 {},
2828 {},
2829 {},
2830 {},
2831 true },
2832 { VER_VIA_SPLIT, DOWNGRADE_BUCKET::LOWER, _( "Buried vias" ),
2833 _( "Written with the older combined blind type." ),
2836 {},
2837 {},
2838 {},
2839 {},
2840 true },
2841 { VER_ZONE_DEFAULTS, DOWNGRADE_BUCKET::DROP, _( "Zone layer defaults" ),
2842 _( "Per-layer zone defaults are removed." ),
2844 { VER_PAD_DIE_DELAY, DOWNGRADE_BUCKET::DROP, _( "Pad-to-die delays" ),
2845 _( "Pad-to-die delay is removed." ),
2847 { VER_SHAPE_HATCH, DOWNGRADE_BUCKET::LOWER, _( "Hatched shape fills" ),
2848 _( "Converted to a solid fill." ),
2849 []( const BOARD* b )
2850 {
2852 },
2853 []( BOARD* b )
2854 {
2856 },
2857 []( FOOTPRINT* f )
2858 {
2860 },
2861 []( BOARD* b )
2862 {
2864 },
2865 []( FOOTPRINT* f )
2866 {
2868 },
2869 _( "The hatch fill is omitted. The supported outline is kept." ) },
2870 { VER_SHAPE_HATCH, DOWNGRADE_BUCKET::LOWER, _( "Hatched copper fills" ),
2871 _( "Converted to a solid fill. Copper geometry may change." ),
2872 []( const BOARD* b )
2873 {
2875 },
2876 []( BOARD* b )
2877 {
2879 },
2880 []( FOOTPRINT* f )
2881 {
2883 },
2884 {},
2885 {},
2886 {},
2887 true },
2888 { VER_PCB_POINTS, DOWNGRADE_BUCKET::DROP, _( "PCB points" ),
2889 _( "No equivalent in the target. Points are removed." ),
2891 { VER_VIA_PROTECTION, DOWNGRADE_BUCKET::DROP, _( "Via protection" ),
2892 _( "IPC-4761 covering, plugging, capping, and filling are removed." ),
2894 { VER_DIELECTRIC, DOWNGRADE_BUCKET::DROP, _( "Dielectric frequency models" ),
2895 _( "The frequency-dependent dielectric model is removed." ),
2897 { VER_GROUP_LIB_ID, DOWNGRADE_BUCKET::DROP, _( "Group design block links" ),
2898 _( "The link from a group to its design block is removed." ),
2900 { VER_STACKUP_TABLE, DOWNGRADE_BUCKET::LOWER, _( "Live stackup tables" ),
2901 _( "Converted to a static table with the same contents. Column configuration and the "
2902 "link to the board stackup are lost." ),
2904 _( "Stackup tables are omitted instead of converted to static tables." ) },
2905 { VER_TEXTBOX_KNOCKOUT, DOWNGRADE_BUCKET::LOWER, _( "Knockout text boxes" ),
2906 _( "Drawn as plain text boxes." ),
2909 _( "Knockout text boxes are omitted instead of drawn as plain text." ) },
2910 { VER_ROUNDED_RECT, DOWNGRADE_BUCKET::LOWER, _( "Rounded rectangles" ),
2911 _( "Approximated by a polygon." ),
2913 _( "Rounded rectangles and rounded custom pad primitives are omitted. Copper geometry may change." ) },
2914 { VER_CELL_KNOCKOUT, DOWNGRADE_BUCKET::LOWER, _( "Knockout table cells" ),
2915 _( "Drawn as plain cells." ),
2918 _( "Knockout cell contents are omitted; empty cells and the table grid are kept." ) },
2919 { VER_ZONE_DEFAULTS, DOWNGRADE_BUCKET::DROP, _( "Per-zone layer properties" ),
2920 _( "The per-layer overrides are removed." ),
2922 { VER_USER_LAYERS, DOWNGRADE_BUCKET::BLOCK, _( "User layers past User_9" ),
2923 _( "The target supports only 9 user layers." ),
2924 countHighUserLayers, nullptr },
2925 { FIRST_FP_CUSTOM_STACKUP, DOWNGRADE_BUCKET::BLOCK, _( "Custom footprint stackups" ),
2926 _( "The target would expand the footprint's inner layers and change its connectivity." ),
2927 countCustomFpStackups, nullptr },
2928 { FIRST_FP_AFFINE_TRANSFORM, DOWNGRADE_BUCKET::BLOCK, _( "Scaled footprints" ),
2929 _( "The target cannot represent a scaled footprint." ),
2930 countScaledFootprints, nullptr },
2931 {
2933 // Theoretically, can degrade to SMD/CONN but it affects Gerbers attributes
2935 _( "Non-component pads" ),
2936 _( "The target cannot represent non-component pads." ),
2938 nullptr,
2939 },
2940 };
2941 // clang-format on
2942}
2943
2944
2946 bool aDropInsteadOfApproximate )
2947{
2948 // The rules were written against a specific format. Warn developers when the format has
2949 // moved on, since a frozen writer silently omits features that have no rule yet.
2951 wxT( "Board format changed. Review the downgrade rules and denylist, then update "
2952 "BOARD_DOWNGRADE_COVERED." ) );
2953
2954 COMPATIBILITY_REPORT report;
2955
2957 {
2958 report.Add( DOWNGRADE_BUCKET::BLOCK, _( "Unreviewed board format" ),
2959 _( "The current board format has changed since the downgrade rules were reviewed." ), 1 );
2960 }
2961
2962 if( aBoard->GetPlotOptions().GetFormat() == PLOT_FORMAT::PNG )
2963 {
2964 report.Add( DOWNGRADE_BUCKET::DROP, _( "PNG plot selection" ),
2965 _( "The unsupported plot format is reset to Gerber." ), 1 );
2966 }
2967
2969 {
2970 const TEXT_DOWNGRADE_PLAN text = planBoardText( aBoard, aTarget.m_boardVersion );
2971
2972 if( text.m_blocked )
2973 {
2974 report.Add( DOWNGRADE_BUCKET::BLOCK, _( "Unresolved post-target text" ),
2975 _( "Affected property variables or expressions could not be safely resolved." ),
2976 text.m_blocked );
2977 }
2978
2979 if( !text.m_replacements.empty() || !text.m_titleReplacements.empty() )
2980 {
2981 report.Add( DOWNGRADE_BUCKET::DROP, _( "Post-target text variables" ),
2982 _( "Affected displayed text is resolved to its current value and loses dynamic evaluation." ),
2983 text.m_replacements.size() + text.m_titleReplacements.size() );
2984 }
2985 }
2986
2987 if( aTarget.m_boardVersion < VER_LINE_ENDINGS && !aDropInsteadOfApproximate )
2988 {
2989 if( int unsafe = countLineEndings( aBoard, true ); unsafe > 0 )
2990 {
2991 report.Add( DOWNGRADE_BUCKET::BLOCK, _( "Styled graphic line endings" ),
2992 _( "Dashed, colored, or unresolved-width line endings cannot be faithfully converted. "
2993 "The omission policy can remove just the endpoint embellishments." ),
2994 unsafe );
2995 }
2996 }
2997
2998 for( const BOARD_RULE& rule : boardRules() )
2999 {
3000 if( aTarget.m_boardVersion >= rule.m_introducedIn )
3001 continue;
3002
3003 if( int count = rule.m_count( aBoard ); count > 0 )
3004 {
3005 bool omit = aDropInsteadOfApproximate
3006 && rule.m_bucket == DOWNGRADE_BUCKET::LOWER
3007 && !rule.m_keepUnderOmitPolicy;
3008
3009 report.Add( omit ? DOWNGRADE_BUCKET::DROP : rule.m_bucket,
3010 rule.m_feature,
3011 omit ? rule.m_omitDetail : rule.m_detail,
3012 count );
3013 }
3014 }
3015
3016 return report;
3017}
3018
3019
3020// The stored scale compensates for the truncated pixels/cm PPI that targets before 20260623
3021// compute, so it must be rewound. The catalog keeps images with a silent correction, so this
3022// is not a table rule and adds no report row.
3024{
3025 REFERENCE_IMAGE& ref = aImage->GetReferenceImage();
3026 int legacyPPI = ref.GetImage().GetLegacyPPI();
3027
3028 if( legacyPPI > 0 && ref.GetImage().GetPPI() != legacyPPI )
3029 ref.SetImageScale( ref.GetImageScale() * legacyPPI / ref.GetImage().GetPPI() );
3030}
3031
3032
3034{
3035 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
3036 {
3037 if( item->Type() == PCB_REFERENCE_IMAGE_T )
3038 compensateImageScale( static_cast<PCB_REFERENCE_IMAGE*>( item ) );
3039 }
3040}
3041
3042
3044{
3045 for( BOARD_ITEM* item : aBoard->Drawings() )
3046 {
3047 if( item->Type() == PCB_REFERENCE_IMAGE_T )
3048 compensateImageScale( static_cast<PCB_REFERENCE_IMAGE*>( item ) );
3049 }
3050
3051 for( FOOTPRINT* fp : aBoard->Footprints() )
3053}
3054
3055
3056void DowngradeBoardInPlace( BOARD* aBoard, const DOWNGRADE_TARGET& aTarget, bool aDropInsteadOfApproximate )
3057{
3058 if( aBoard->GetPlotOptions().GetFormat() == PLOT_FORMAT::PNG )
3059 {
3060 PCB_PLOT_PARAMS options = aBoard->GetPlotOptions();
3061 options.SetFormat( PLOT_FORMAT::GERBER );
3062 aBoard->SetPlotOptions( options );
3063 }
3064
3066 applyTextPlan( planBoardText( aBoard, aTarget.m_boardVersion ) );
3067
3068 if( aTarget.m_boardVersion < VER_IMAGE_PPI )
3070
3071 for( const BOARD_RULE& rule : boardRules() )
3072 {
3073 if( aTarget.m_boardVersion >= rule.m_introducedIn )
3074 continue;
3075
3076 bool omit = aDropInsteadOfApproximate
3077 && rule.m_bucket == DOWNGRADE_BUCKET::LOWER
3078 && !rule.m_keepUnderOmitPolicy;
3079
3080 const std::function<void( BOARD* )>& apply = omit ? rule.m_omit : rule.m_apply;
3081
3082 wxASSERT_MSG( !omit || apply, wxT( "A LOWER rule needs an omission transform." ) );
3083
3084 if( apply )
3085 apply( aBoard );
3086 }
3087}
3088
3089
3090// A library footprint carries the same post-target features as one on a board, but it lives in its
3091// own .kicad_mod, so the board rules never see it. This applies the footprint-scoped subset.
3092void DowngradeFootprintInPlace( FOOTPRINT* aFootprint, const DOWNGRADE_TARGET& aTarget, bool aDropInsteadOfApproximate )
3093{
3095 {
3097 visitFootprintItems( aFootprint,
3098 [&]( BOARD_ITEM* item )
3099 {
3100 planTextItem( item, aTarget.m_boardVersion, text );
3101 } );
3103 }
3104
3105 if( aTarget.m_boardVersion < VER_IMAGE_PPI )
3107
3108 for( const BOARD_RULE& rule : boardRules() )
3109 {
3110 if( aTarget.m_boardVersion >= rule.m_introducedIn )
3111 continue;
3112
3113 bool omit = aDropInsteadOfApproximate
3114 && rule.m_bucket == DOWNGRADE_BUCKET::LOWER
3115 && !rule.m_keepUnderOmitPolicy;
3116
3117 const std::function<void(FOOTPRINT*)>& apply = omit ? rule.m_omitFp : rule.m_applyFp;
3118
3119 wxASSERT_MSG( !omit || !rule.m_applyFp || apply, wxT( "A footprint LOWER rule needs an omission transform." ) );
3120
3121 if( apply )
3122 apply( aFootprint );
3123 }
3124}
3125
3126
3127// Node heads dated by the format that introduced them. The versioned writers cannot emit these,
3128// so this gate is a safety net against a wrong or miswired writer. To add a token, add a row
3129// with its format version.
3130static constexpr DATED_TOKEN BOARD_TOKENS[] = {
3131 { "is_time_domain", VER_TIME_DOMAIN_TUNING },
3132 { "target_delay", VER_TIME_DOMAIN_TUNING },
3133 { "target_delay_min", VER_TIME_DOMAIN_TUNING },
3134 { "target_delay_max", VER_TIME_DOMAIN_TUNING },
3135 { "last_tuning_length", VER_TIME_DOMAIN_TUNING },
3136 { "constraint", VER_CONSTRAINTS },
3137 { "grid_item", VER_GRIDS },
3138 { "start_shape", VER_LINE_ENDINGS },
3139 { "end_shape", VER_LINE_ENDINGS },
3140 { "custom_property", VER_CUSTOM_PROPERTIES },
3141 { "exclude_from_sim", VER_SIM_EXCLUSION },
3142 { "drill_chart", VER_DRILL_DRAWINGS },
3143 { "drill_map", VER_DRILL_DRAWINGS },
3144 { "drill_symbol_profile", VER_DRILL_DRAWINGS },
3145 { "stackup_table", VER_STACKUP_TABLE },
3146 { "kicad_footprint_lib", VER_FP_LIB_HEADER },
3147 { "link", VER_LINKED_PLACEMENT },
3148 { "connected_routing", VER_LINKED_PLACEMENT },
3149 { "other_items", VER_LINKED_PLACEMENT },
3150 { "group_items", VER_LINKED_PLACEMENT },
3151 { "locked_items", VER_LINKED_PLACEMENT },
3152 { "templates", VER_VIA_STITCH },
3153 { "hatch_position", VER_ZONE_DEFAULTS },
3154 { "covering", VER_VIA_PROTECTION },
3155 { "plugging", VER_VIA_PROTECTION },
3156 { "capping", VER_VIA_PROTECTION },
3157 { "filling", VER_VIA_PROTECTION },
3158 { "depth", VER_VIA_PROTECTION },
3159 { "zone_defaults", VER_ZONE_DEFAULTS },
3160 { "jumper_pad_groups", VER_JUMPER_PADS },
3161 { "lib_id", VER_GROUP_LIB_ID },
3162 { "start_end_only", VER_SKIP_VIA },
3163 { "point", VER_PCB_POINTS },
3164 { "unit", VER_FP_UNITS },
3165 { "pins", VER_FP_UNITS },
3166 { "barcode", VER_BARCODE },
3167 { "ecc_level", VER_BARCODE },
3168 { "text", VER_BARCODE },
3169 { "text_height", VER_BARCODE },
3170 { "die_delay", VER_PAD_DIE_DELAY },
3171 { "backdrill", VER_BACKDRILL },
3172 { "tertiary_drill", VER_BACKDRILL },
3173 { "front_post_machining", VER_POST_MACHINING },
3174 { "back_post_machining", VER_POST_MACHINING },
3175 { "variant", FIRST_PCB_VARIANTS },
3176 { "variants", FIRST_PCB_VARIANTS },
3177 { "field", FIRST_PCB_VARIANTS },
3178 { "description", FIRST_PCB_VARIANTS },
3179 { "body_pcb_gap", VER_EXTRUDED_BODY },
3180 { "overall_height", VER_EXTRUDED_BODY },
3181 { "gr_ellipse", VER_ELLIPSE },
3182 { "gr_ellipse_arc", VER_ELLIPSE },
3183 { "fp_ellipse", VER_ELLIPSE },
3184 { "fp_ellipse_arc", VER_ELLIPSE },
3185 { "dielectric_model", VER_DIELECTRIC },
3186 { "spec_frequency", VER_DIELECTRIC },
3187 { "constant", VER_DIELECTRIC },
3188 { "net_chain", VER_NET_CHAINS },
3189 { "net_chains", VER_NET_CHAINS },
3190 { "terminal_pad", VER_NET_CHAINS },
3191 { "thieving", VER_THIEVING },
3192 { "rotation_angle", VER_ELLIPSE },
3193 { "stagger", VER_THIEVING },
3194 { "sim_electrical_type", VER_PAD_SIM },
3195 { "transform", FIRST_FP_AFFINE_TRANSFORM },
3196};
3197
3198// Bareword values the target cannot parse. The node scan cannot see these.
3199// Hatch fill values cannot be listed here, unlike the schematic gate. Zones legitimately emit
3200// hatch tokens in every target format, so a hatched shape fill leak is invisible to this gate.
3201static constexpr DATED_TOKEN BOARD_VALUES[] = {
3202 { "exclude_from_sim", VER_SIM_EXCLUSION },
3203 { "via_stitch", VER_VIA_STITCH },
3204 { "via_stack", VER_VIA_STACK },
3205 { "pad_prop_pressfit", VER_PRESSFIT },
3206 { "copper_only", VER_NON_COMPONENT_PAD },
3207 { "buried", VER_VIA_SPLIT },
3208};
3209
3210
3215
3216
3221
3222
3223// Each target has its own writer, extracted from that release. A target without a writer writes
3224// nothing, and the fail-closed check downstream refuses the export.
3225void SaveBoardForTarget( BOARD* aBoard, const wxString& aPath, const DOWNGRADE_TARGET& aTarget )
3226{
3228 PCB_WRITER_V10().SaveBoard( aPath, aBoard );
3229 else if( aTarget.m_boardVersion == PCB_WRITER_V9::FORMAT_VERSION )
3230 PCB_WRITER_V9().SaveBoard( aPath, aBoard );
3231 else
3232 wxFAIL_MSG( wxT( "No writer for this downgrade target." ) );
3233}
3234
3235
3236void SaveFootprintForTarget( FOOTPRINT* aFootprint, const wxString& aPath, const DOWNGRADE_TARGET& aTarget )
3237{
3239 PCB_WRITER_V10().SaveFootprintFile( aPath, aFootprint );
3240 else if( aTarget.m_boardVersion == PCB_WRITER_V9::FORMAT_VERSION )
3241 PCB_WRITER_V9().SaveFootprintFile( aPath, aFootprint );
3242 else
3243 wxFAIL_MSG( wxT( "No writer for this downgrade target." ) );
3244}
3245
3246
3247static bool containsGroupPlacementSource( const std::string& aText )
3248{
3249 const std::string text = StripSexprStrings( aText );
3250 std::vector<std::string> path;
3251
3252 for( size_t position = 0; position < text.size(); ++position )
3253 {
3254 if( text[position] == '(' )
3255 {
3256 size_t begin = position + 1;
3257
3258 while( begin < text.size() && std::isspace( static_cast<unsigned char>( text[begin] ) ) )
3259 ++begin;
3260
3261 size_t end = begin;
3262
3263 while( end < text.size()
3264 && ( std::isalnum( static_cast<unsigned char>( text[end] ) ) || text[end] == '_' ) )
3265 ++end;
3266
3267 const std::string head = text.substr( begin, end - begin );
3268
3269 if( head == "group" && path.size() >= 2 && path.back() == "placement" && path[path.size() - 2] == "zone" )
3270 return true;
3271
3272 path.push_back( head );
3273 position = end > begin ? end - 1 : position;
3274 }
3275 else if( text[position] == ')' && !path.empty() )
3276 {
3277 path.pop_back();
3278 }
3279 }
3280
3281 return false;
3282}
3283
3284
3285wxString FindUnsupportedBoardToken( const wxString& aSerialized, const DOWNGRADE_TARGET& aTarget )
3286{
3288 return wxEmptyString;
3289
3290 if( aTarget.m_boardVersion < VER_GROUP_PLACEMENT && containsGroupPlacementSource( aSerialized.ToStdString() ) )
3291 return wxT( "placement/group" );
3292
3293 return FindUnsupportedToken( aSerialized, BOARD_TOKENS, std::size( BOARD_TOKENS ), BOARD_VALUES,
3294 std::size( BOARD_VALUES ), aTarget.m_boardVersion );
3295}
3296
3297
3298void FlattenBoardVariant( BOARD* aBoard, const wxString& aVariantName )
3299{
3300 for( FOOTPRINT* fp : aBoard->Footprints() )
3301 {
3302 fp->SetDNP( fp->GetDNPForVariant( aVariantName ) );
3303 fp->SetExcludedFromBOM( fp->GetExcludedFromBOMForVariant( aVariantName ) );
3304 fp->SetExcludedFromPosFiles( fp->GetExcludedFromPosFilesForVariant( aVariantName ) );
3305 fp->SetExcludedFromSim( fp->GetExcludedFromSimForVariant( aVariantName ) );
3306
3307 if( const FOOTPRINT_VARIANT* variant = fp->GetVariant( aVariantName ) )
3308 {
3309 for( const auto& [name, value] : variant->GetFields() )
3310 {
3311 if( PCB_FIELD* field = fp->GetField( name ) )
3312 field->SetText( value );
3313 }
3314 }
3315 }
3316}
3317
3318
3319DOWNGRADE_FILE_RESULT DowngradeFootprintFileToTemp( const wxString& aSrcFile, const wxString& aTmpFile,
3320 const DOWNGRADE_TARGET& aTarget, bool aDropInsteadOfApproximate )
3321{
3322 PCB_IO_KICAD_SEXPR loader;
3323 wxString nameOut;
3324 std::unique_ptr<FOOTPRINT> owned = loader.ImportFootprint( aSrcFile, nameOut );
3325
3326 if( !owned )
3328
3329 // The scratch board lets the block rules decide, so this stays in step with the rule
3330 // table instead of repeating a subset of it.
3331 BOARD scratch;
3332 FOOTPRINT* fp = owned.get();
3333 scratch.Add( owned.release() );
3334
3335 if( ClassifyBoardForDowngrade( &scratch, aTarget, aDropInsteadOfApproximate ).IsBlocked() )
3337
3338 // Detached before writing, like a real library save. The writers clip a parented
3339 // footprint's zone layers and padstacks to the board's layer set. Remove does not clear
3340 // the parent pointer, so that is explicit.
3341 scratch.Remove( fp );
3342 owned.reset( fp );
3343 fp->SetParent( nullptr );
3344
3345 DowngradeFootprintInPlace( fp, aTarget, aDropInsteadOfApproximate );
3346 SaveFootprintForTarget( fp, aTmpFile, aTarget );
3348}
3349
3350
3351bool ExportBoardToOlderVersion( const wxString& aSrcFile, const wxString& aDestFile, const DOWNGRADE_TARGET& aTarget,
3352 COMPATIBILITY_REPORT& aReport, wxString* aUnsupportedToken, const wxString& aVariant,
3353 bool aDropInsteadOfApproximate )
3354{
3355 if( aUnsupportedToken )
3356 aUnsupportedToken->clear();
3357
3358 SETTINGS_MANAGER projectSettings;
3359 wxFileName projectFile( aSrcFile );
3360 projectFile.SetExt( FILEEXT::ProjectFileExtension );
3361 projectFile.MakeAbsolute();
3362 projectSettings.LoadProject( projectFile.GetFullPath(), false );
3363
3365 std::unique_ptr<BOARD> board( pi.LoadBoard( aSrcFile, nullptr ) );
3366
3367 if( !board )
3368 return false;
3369
3370 // Resolve project variables before replacing dynamic items with fixed geometry.
3371 board->SetProject( projectSettings.GetProject( projectFile.GetFullPath() ), true );
3372
3373 if( !aVariant.IsEmpty() )
3374 FlattenBoardVariant( board.get(), aVariant );
3375
3376 aReport = ClassifyBoardForDowngrade( board.get(), aTarget, aDropInsteadOfApproximate );
3377
3378 if( aReport.IsBlocked() )
3379 return false;
3380
3381 DowngradeBoardInPlace( board.get(), aTarget, aDropInsteadOfApproximate );
3382
3383 // Write to a sibling temp and verify that before it replaces the destination, so a failed
3384 // export never destroys a pre-existing output file. The writer resolves symlinks on purpose,
3385 // so reserve the name exclusively rather than spelling out a guessable one.
3386 const wxString tmpFile = wxFileName::CreateTempFileName( aDestFile + wxT( ".downgrade_tmp." ) );
3387
3388 if( tmpFile.IsEmpty() )
3389 return false;
3390
3391 // Release the reservation so the writer's own exclusive create still sees a new target and
3392 // keeps the permissions an ordinary save would give it.
3393 wxRemoveFile( tmpFile );
3394
3395 try
3396 {
3397 SaveBoardForTarget( board.get(), tmpFile, aTarget );
3398 }
3399 catch( ... )
3400 {
3401 wxRemoveFile( tmpFile );
3402 throw;
3403 }
3404
3405 // Fail closed. Discard the temp if it still uses a token the target cannot parse, or if it
3406 // cannot be read back to verify.
3407 wxString bad;
3408
3409 bool good = VerifyDowngradedFile(
3410 tmpFile, aTarget.m_boardVersion,
3411 [&]( const wxString& aText )
3412 {
3413 return FindUnsupportedBoardToken( aText, aTarget );
3414 },
3415 &bad );
3416
3417 if( !good )
3418 {
3419 wxRemoveFile( tmpFile );
3420
3421 if( aUnsupportedToken )
3422 *aUnsupportedToken = bad;
3423
3424 return false;
3425 }
3426
3427 if( !wxRenameFile( tmpFile, aDestFile, true ) )
3428 {
3429 wxRemoveFile( tmpFile );
3430 return false;
3431 }
3432
3433 return true;
3434}
const char * name
@ ERROR_INSIDE
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
static void dropDielectricModels(BOARD *aBoard)
static void dropUnitInfoFp(FOOTPRINT *aFootprint)
COMPATIBILITY_REPORT ClassifyBoardForDowngrade(const BOARD *aBoard, const DOWNGRADE_TARGET &aTarget, bool aDropInsteadOfApproximate)
Report what a board would lose if exported to an older KiCad.
static void dropUnitInfo(BOARD *aBoard)
static void transformLineEndingsFp(FOOTPRINT *aFootprint, bool aOmit)
static constexpr int VER_IMAGE_PPI
static constexpr int VER_USER_LAYERS
static int countLinkedPlacementAreas(const BOARD *aBoard)
static constexpr int VER_JUMPER_PADS
static void dropKnockoutTableCells(BOARD *aBoard)
static void lowerBarcodes(BOARD *aBoard)
static void dropLinkedPlacementAreas(BOARD *aBoard)
static void dropPressFitPadsFp(FOOTPRINT *aFootprint)
static int countDieDelays(const BOARD *aBoard)
static bool hasViaProtection(const PCB_VIA *aVia)
static void detachFromGroup(BOARD_ITEM *aItem)
static void dropTimeDomainTuning(BOARD *aBoard)
static void dropJumperPadsFp(FOOTPRINT *aFootprint)
static void dropCustomProperties(BOARD *aBoard)
static int countCustomFpStackups(const BOARD *aBoard)
static constexpr int VER_NON_COMPONENT_PAD
static int countFootprintHeights(const BOARD *aBoard)
static constexpr int VER_DRILL_DRAWINGS
static int countHatchedFills(const BOARD *aBoard, const std::function< bool(const BOARD_ITEM *)> &aMatches)
static constexpr int VER_THIEVING
static bool isDrillDrawing(const BOARD_ITEM *aItem)
static void lowerRoundedRects(BOARD *aBoard)
void SaveFootprintForTarget(FOOTPRINT *aFootprint, const wxString &aPath, const DOWNGRADE_TARGET &aTarget)
Save a single .kicad_mod footprint file for the target.
static constexpr int VER_DIELECTRIC
static constexpr int BOARD_DOWNGRADE_COVERED
static int countKnockoutTextBoxesFp(const FOOTPRINT *aFootprint)
static void dropKnockoutCellsIn(BOARD_ITEM *aItem)
static void omitBarcodesFp(FOOTPRINT *aFootprint)
static constexpr int VER_IMAGE_ROTATION
static int countLineEndings(const BOARD *aBoard, bool aUnsafeOnly=false)
static void lowerBuriedVias(BOARD *aBoard)
static void dropPostMachiningFp(FOOTPRINT *aFootprint)
static int countPcbPoints(const BOARD *aBoard)
static int countGrids(const BOARD *aBoard)
static void omitGraphicsFp(FOOTPRINT *aFootprint, const std::function< bool(const BOARD_ITEM *)> &aMatches)
static constexpr int VER_PRESSFIT
static void dropKnockoutTextBoxes(BOARD *aBoard)
int BoardDowngradeCoveredVersion()
The format the denylist was generated against. A format bump forces a review.
static void forEachPadPrimitive(FOOTPRINT *aFootprint, const std::function< void(PCB_SHAPE *)> &aFunc)
static bool isBarcode(const BOARD_ITEM *aItem)
static bool hasActiveExpression(const wxString &aText)
static int countZoneDefaults(const BOARD *aBoard)
static bool isUnreviewedDrawing(const BOARD_ITEM *aItem)
static void dropViaProtection(BOARD *aBoard)
static void omitKnockoutTextBoxesFp(FOOTPRINT *aFootprint)
static void dropJumperPads(BOARD *aBoard)
static void dropGrids(BOARD *aBoard)
static constexpr int VER_SIM_EXCLUSION
static int countStackupTables(const BOARD *aBoard)
static int countJumperPads(const BOARD *aBoard)
static int countPostMachining(const BOARD *aBoard)
static int countSkipVias(const BOARD *aBoard)
static int countPadSimTypes(const BOARD *aBoard)
static void planTextItem(BOARD_ITEM *aItem, int aTargetVersion, TEXT_DOWNGRADE_PLAN &aPlan, const std::function< bool(wxString *)> *aResolver=nullptr)
static const wxString & titleFieldText(const TITLE_BLOCK &aTitle, int aIndex)
static void dropFootprintHeights(BOARD *aBoard)
static void roundedRectToPolygon(PCB_SHAPE *aShape, int aMaxError)
static int countHighUserLayers(const BOARD *aBoard)
static bool hasBackdrill(const PADSTACK &aPadstack)
static void dropZoneLayerProperties(BOARD *aBoard)
static int countBackdrills(const BOARD *aBoard)
static int countNetChains(const BOARD *aBoard)
static int countNonComponentPads(const BOARD *aBoard)
static void setHatchedFills(BOARD *aBoard, const std::function< bool(const BOARD_ITEM *)> &aMatches, FILL_T aFill)
static std::vector< BOARD_RULE > boardRules()
static void dropConstraints(BOARD *aBoard)
static int countKnockoutCellsIn(const BOARD_ITEM *aItem)
static constexpr int VER_ZONE_DEFAULTS
static constexpr int VER_SHAPE_HATCH
static int countRoundedRectsFp(const FOOTPRINT *aFootprint)
static void omitGraphics(BOARD *aBoard, const std::function< bool(const BOARD_ITEM *)> &aMatches)
void SaveBoardForTarget(BOARD *aBoard, const wxString &aPath, const DOWNGRADE_TARGET &aTarget)
Save a board stamped for the target, using the writer for that version.
static int countGroupDesignBlocks(const BOARD *aBoard)
static void omitEllipses(BOARD *aBoard)
static int countScaledFootprints(const BOARD *aBoard)
static int countSimulationExclusions(const BOARD *aBoard)
static int footprintMaxError(const FOOTPRINT *aFootprint)
static bool isGrid(const BOARD_ITEM *aItem)
void FlattenBoardVariant(BOARD *aBoard, const wxString &aVariantName)
Bake a variant's overrides into the base footprint attributes.
static void dropPcbVariantsFp(FOOTPRINT *aFootprint)
static int countZoneLayerProperties(const BOARD *aBoard)
static void dropConstraintsFp(FOOTPRINT *aFootprint)
static void omitKnockoutTableCells(BOARD *aBoard)
static void dropExtrudedBodiesFp(FOOTPRINT *aFootprint)
static void setHatchedFillsFp(FOOTPRINT *aFootprint, const std::function< bool(const BOARD_ITEM *)> &aMatches, FILL_T aFill)
static int countGroupPlacementAreas(const BOARD *aBoard)
static void transformLineEndings(BOARD *aBoard, bool aOmit)
static constexpr int VER_PAD_DIE_DELAY
static constexpr int VER_VIA_SPLIT
static int countUnreviewedDrawings(const BOARD *aBoard)
static constexpr int VER_VIA_STITCH
static void omitEllipsesFp(FOOTPRINT *aFootprint)
static void dropGroupPlacementLinkage(ZONE *aZone)
static void dropDieDelaysFp(FOOTPRINT *aFootprint)
static constexpr int VER_NET_CHAINS
static void dropExtrudedBodies(BOARD *aBoard)
static bool isHatchedShape(const BOARD_ITEM *aItem)
static constexpr DATED_TOKEN BOARD_VALUES[]
static int countBuriedVias(const BOARD *aBoard)
static void dropNetChains(BOARD *aBoard)
static constexpr int VER_TIME_DOMAIN_TUNING
static bool isKnockoutTextBox(const BOARD_ITEM *aItem)
static int countUnknownGenerators(const BOARD *aBoard)
static constexpr int VER_VIA_STACK
static constexpr int VER_ELLIPSE
static int countDrillSymbolConfiguration(const BOARD *aBoard)
static void omitRoundedRectsFp(FOOTPRINT *aFootprint)
static void dropDrillDrawings(BOARD *aBoard)
static PCB_TABLE * stackupTableToTable(const PCB_STACKUP_TABLE *aTable, BOARD_ITEM *aParent)
Cells are cloned, not moved, because a table deletes its own cells.
static bool isTimeDomainTuning(const PCB_GENERATOR *aGenerator)
static constexpr int VER_CELL_KNOCKOUT
static constexpr int VER_GRIDS
static constexpr int VER_PROPERTY_VARIABLES
static void dropZoneDefaults(BOARD *aBoard)
static void dropReferenceImageOpacities(BOARD *aBoard)
static void dropFootprintHeightsFp(FOOTPRINT *aFootprint)
static int countTimeDomainTuning(const BOARD *aBoard)
static int countCustomProperties(const BOARD *aBoard)
static void dropPadSimTypesFp(FOOTPRINT *aFootprint)
int FootprintLibDowngradeCoveredVersion()
The footprint library format the rules were reviewed against. Moves independently of the board.
static bool isHatchedCopperShape(const BOARD_ITEM *aItem)
static constexpr int VER_TEXTBOX_KNOCKOUT
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.
static void dropPcbVariants(BOARD *aBoard)
static void dropGroupPlacementAreas(BOARD *aBoard)
static constexpr int VER_FOOTPRINT_HEIGHT
static void dropPressFitPads(BOARD *aBoard)
static void dropPostMachining(BOARD *aBoard)
static TEXT_DOWNGRADE_PLAN planBoardText(const BOARD *aBoard, int aTargetVersion)
static constexpr int VER_FP_UNITS
static int countBarcodes(const BOARD *aBoard)
static void lowerLineEndingShape(PCB_SHAPE *aShape, int aMaxError)
static void dropSimulationExclusions(BOARD *aBoard)
static void omitStackupTables(BOARD *aBoard)
static bool hasLineEndings(const BOARD_ITEM *aItem)
static constexpr int VER_IMAGE_OPACITY
static int countGenerators(const BOARD *aBoard, const wxString &aType)
static constexpr int VER_GROUP_LIB_ID
static int countEllipses(const BOARD *aBoard)
static void ellipseToPolygon(PCB_SHAPE *aShape, int aMaxError)
static void dropSimulationExclusionsFp(FOOTPRINT *aFootprint)
static int countExtrudedBodies(const BOARD *aBoard)
static void lowerSkipVias(BOARD *aBoard)
static void dropPcbPoints(BOARD *aBoard)
static void visitBoardItems(const BOARD *aBoard, const std::function< void(BOARD_ITEM *)> &aVisit)
static constexpr int VER_LINE_ENDINGS
static int countViaProtection(const BOARD *aBoard)
static int countUnitInfo(const BOARD *aBoard)
static constexpr int VER_CONSTRAINTS
static int countDrawings(const BOARD *aBoard, const std::function< bool(const BOARD_ITEM *)> &aMatches)
static bool postTargetText(const wxString &aText, const BOARD *aBoard, int aTargetVersion, std::set< wxString > &aDependencies, int aDepth=0)
static void compensateImageScale(PCB_REFERENCE_IMAGE *aImage)
static void omitKnockoutTextBoxes(BOARD *aBoard)
static int countReferenceImageRotations(const BOARD *aBoard)
static void dropKnockoutTextBoxesFp(FOOTPRINT *aFootprint)
static void clearLineEndings(PCB_SHAPE *aShape)
static int countReferenceImageOpacities(const BOARD *aBoard)
static void lowerEllipses(BOARD *aBoard)
static bool isStackupTable(const BOARD_ITEM *aItem)
static void dropDieDelays(BOARD *aBoard)
static constexpr int VER_STACKUP_TABLE
static constexpr int VER_PCB_POINTS
static void omitKnockoutTableCellsFp(FOOTPRINT *aFootprint)
static bool unsafeLineEndings(const PCB_SHAPE *aShape)
static std::vector< PCB_SHAPE * > barcodeToShapes(PCB_BARCODE *aBarcode, BOARD_ITEM_CONTAINER *aParent)
static constexpr int VER_BACKDRILL
static void omitBarcodes(BOARD *aBoard)
static void dropGroupDesignBlocks(BOARD *aBoard)
static int countDrillDrawings(const BOARD *aBoard)
static bool hasPostMachining(const PADSTACK &aPadstack)
static void lowerEllipsesFp(FOOTPRINT *aFootprint)
static void dropPcbPointsFp(FOOTPRINT *aFootprint)
static void lowerRoundedRectsFp(FOOTPRINT *aFootprint)
static bool isEllipse(const BOARD_ITEM *aItem)
static void lowerBarcodesFp(FOOTPRINT *aFootprint)
static void compensateReferenceImageScales(BOARD *aBoard)
static void visitFootprintItems(const FOOTPRINT *aFootprint, const std::function< void(BOARD_ITEM *)> &aVisit)
static constexpr int VER_VIA_PROTECTION
static bool isRoundedRect(const BOARD_ITEM *aItem)
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.
static int countPcbVariants(const BOARD *aBoard)
static bool containsGroupPlacementSource(const std::string &aText)
static void applyTextPlan(const TEXT_DOWNGRADE_PLAN &aPlan)
void DowngradeBoardInPlace(BOARD *aBoard, const DOWNGRADE_TARGET &aTarget, bool aDropInsteadOfApproximate)
Approximate or remove, in place, what the target cannot represent.
static int countConstraints(const BOARD *aBoard)
static void dropGroupDesignBlocksFp(FOOTPRINT *aFootprint)
static int countKnockoutTableCells(const BOARD *aBoard)
static constexpr int VER_POST_MACHINING
static int countUnreviewedTuningProperties(const BOARD *aBoard)
void DowngradeFootprintInPlace(FOOTPRINT *aFootprint, const DOWNGRADE_TARGET &aTarget, bool aDropInsteadOfApproximate)
Footprint-scoped downgrade for standalone .kicad_mod files the board pass never sees.
static int countPressFitPads(const BOARD *aBoard)
static constexpr int VER_PAD_SIM
static constexpr int VER_BARCODE
static void omitKnockoutCellContents(BOARD_ITEM *aItem)
static void dropZoneLayerPropertiesFp(FOOTPRINT *aFootprint)
static bool hasGroupPlacementLinkage(const ZONE *aZone)
static constexpr int FOOTPRINT_LIB_DOWNGRADE_COVERED
static int countThievingZones(const BOARD *aBoard)
static constexpr int VER_FP_LIB_HEADER
static int countKnockoutTextBoxes(const BOARD *aBoard)
static void omitPadPrimitives(FOOTPRINT *aFootprint, const std::function< bool(const BOARD_ITEM *)> &aMatches)
static constexpr int VER_CUSTOM_PROPERTIES
static void dropCustomPropertiesFp(FOOTPRINT *aFootprint)
static constexpr int VER_EXTRUDED_BODY
static int countDielectricModels(const BOARD *aBoard)
static int countRoundedRects(const BOARD *aBoard)
static void dropPadSimTypes(BOARD *aBoard)
static constexpr int VER_ROUNDED_RECT
static void omitRoundedRects(BOARD *aBoard)
static int titleFieldIndex(const wxString &aName)
static void dropGroupPlacementAreasFp(FOOTPRINT *aFootprint)
static constexpr int VER_SKIP_VIA
static constexpr int VER_LINKED_PLACEMENT
static constexpr DATED_TOKEN BOARD_TOKENS[]
static bool isHatchedInkShape(const BOARD_ITEM *aItem)
static void compensateReferenceImageScalesFp(FOOTPRINT *aFootprint)
static void dropDrillSymbolConfiguration(BOARD *aBoard)
static void dropGenerators(BOARD *aBoard, const std::function< bool(const PCB_GENERATOR *)> &aMatches)
wxString FindUnsupportedBoardToken(const wxString &aSerialized, const DOWNGRADE_TARGET &aTarget)
Scan serialized board text for tokens the target cannot parse.
static void lowerStackupTables(BOARD *aBoard)
static constexpr int VER_GROUP_PLACEMENT
static void dropKnockoutTableCellsFp(FOOTPRINT *aFootprint)
constexpr int FIRST_FP_CUSTOM_STACKUP
First board format that stores custom footprint stackups.
constexpr int FIRST_PCB_VARIANTS
First board format that stores variants.
@ BS_ITEM_TYPE_DIELECTRIC
int GetPPI() const
int GetLegacyPPI() const
Recompute the PPI the way it was computed before the pixels/cm truncation fix.
Container for design settings for a BOARD object.
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
void SetLocked(bool aLocked) override
Definition board_item.h:441
virtual bool IsKnockout() const
Definition board_item.h:437
bool IsLocked() const override
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:397
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:281
Manage one layer needed to make a physical board.
Manage layers needed to make a physical board.
const std::vector< BOARD_STACKUP_ITEM * > & GetList() const
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
void SetPlotOptions(const PCB_PLOT_PARAMS &aOptions)
Definition board.h:1033
const NETINFO_LIST & GetNetInfo() const
Definition board.h:1241
void SetCurrentVariant(const wxString &aVariant)
Definition board.cpp:3016
void SetVariantNames(const std::vector< wxString > &aNames)
Definition board.h:534
const std::vector< wxString > & GetVariantNames() const
Definition board.h:533
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
void SetNetChainColor(const wxString &aChain, const KIGFX::COLOR4D &aColor)
Per-net-chain colour override (empty COLOR4D::UNSPECIFIED = no override).
Definition board.h:1360
const GENERATORS & Generators() const
Definition board.h:485
const PCB_POINTS & Points() const
Definition board.h:499
const std::map< wxString, KIGFX::COLOR4D > & GetNetChainColors() const
Definition board.h:1374
const ZONES & Zones() const
Definition board.h:469
const GROUPS & Groups() const
The groups must maintain the following invariants.
Definition board.h:518
bool ResolveTextVar(wxString *token, int aDepth) const
Definition board.cpp:708
const std::vector< PAD * > GetPads() const
Return a reference to a list of all the pads.
Definition board.cpp:3771
TITLE_BLOCK & GetTitleBlock()
Definition board.h:1035
const std::map< wxString, wxString > & GetProperties() const
Definition board.h:526
const FOOTPRINTS & Footprints() const
Definition board.h:465
const TRACKS & Tracks() const
Definition board.h:463
const CONSTRAINTS & Constraints() const
Geometric constraints (#2329) owned by this board.
Definition board.h:522
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition board.h:1032
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition board.cpp:960
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const override
Invoke a function on all children.
Definition board.cpp:865
PROJECT * GetProject() const
Definition board.h:774
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition board.cpp:1202
void Remove(BOARD_ITEM *aBoardItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
Definition board.cpp:1723
bool IsItemIndexedById(const BOARD_ITEM *aItem) const
Return true if aItem is currently indexed.
Definition board.h:1737
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.
void Add(DOWNGRADE_BUCKET aBucket, const wxString &aFeature, const wxString &aDetail=wxEmptyString, int aCount=1)
bool IsBlocked() const
True if some feature makes the target impossible. The user cannot export anyway.
Grouping rules and symbol assignments, shared by reference so a chart and its map can never disagree ...
bool IsZero() const
Definition eda_angle.h:135
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
void AddItem(EDA_ITEM *aItem)
Add item to group.
Definition eda_group.cpp:58
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
void ClearCustomProperties()
Definition eda_item.h:270
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
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
int GetEllipseMinorRadius() const
Definition eda_shape.h:404
const VECTOR2I & GetEllipseCenter() const
Definition eda_shape.h:386
void SetEndEnding(const LINE_ENDING &aEnding)
Definition eda_shape.h:190
int GetEllipseMajorRadius() const
Definition eda_shape.h:395
virtual int GetEffectiveWidth() const
Definition eda_shape.h:167
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.
EDA_ANGLE GetEllipseRotation() const
Definition eda_shape.h:413
SHAPE_T GetShape() const
Definition eda_shape.h:178
void SetStartEnding(const LINE_ENDING &aEnding)
Definition eda_shape.h:184
bool GetLineEndingEndpoints(VECTOR2I &aStartPoint, VECTOR2I &aEndPoint) const
Return the source endpoints used to place line endings.
LINE_ENDING_STYLE GetStartEndingStyle() const
Definition eda_shape.h:192
LINE_STYLE GetLineStyle() const
std::vector< VECTOR2I > GetRectCorners() const
const LINE_ENDING & GetStartEnding() const
Definition eda_shape.h:180
const LINE_ENDING & GetEndEnding() const
Definition eda_shape.h:186
LINE_ENDING_STYLE GetEndEndingStyle() const
Definition eda_shape.h:195
int GetCornerRadius() const
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 void SetText(const wxString &aText)
Definition eda_text.cpp:237
High-level wrapper for evaluating mathematical and string expressions in wxString format.
wxString Evaluate(const wxString &aInput)
Main evaluation function - processes input string and evaluates all '@{}' expressions.
bool HasErrors() const
Check if the last evaluation had errors.
Variant information for a footprint.
Definition footprint.h:178
void SetExcludedFromSim(bool aExclude)
Definition footprint.h:199
const CASE_INSENSITIVE_MAP< FOOTPRINT_VARIANT > & GetVariants() const
Get all variants.
Definition footprint.h:1011
ZONES & Zones()
Definition footprint.h:361
void Remove(BOARD_ITEM *aItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
PCB_POINTS & Points()
Definition footprint.h:370
void SetExcludedFromSim(bool aExclude=true)
Definition footprint.h:939
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const override
Invoke a function on all children.
const FOOTPRINT_VARIANT * GetVariant(const wxString &aVariantName) const
Get a variant by name.
void SetDuplicatePadNumbersAreJumpers(bool aEnabled)
Definition footprint.h:1134
CONSTRAINTS & Constraints()
Definition footprint.h:367
std::deque< PAD * > & Pads()
Definition footprint.h:355
bool ResolveTextVar(wxString *aToken, int aDepth=0) const
Resolve any references to system tokens supported by the component.
void DeleteVariant(const wxString &aVariantName)
Delete a variant by name.
void SetHeight(int aHeight)
Definition footprint.h:439
JUMPER_GROUP_SET & JumperPadGroups()
Each jumper pad group is a set of pad numbers that should be treated as internally connected.
Definition footprint.h:1140
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Adds an item to the container.
void SetUnitInfo(const std::vector< FP_UNIT_INFO > &aUnits)
Definition footprint.h:908
GROUPS & Groups()
Definition footprint.h:364
void ClearBody()
DRAWINGS & GraphicalItems()
Definition footprint.h:358
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:400
Definition kiid.h:46
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
const STROKE_PARAMS & GetStroke() const
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition lset.h:63
Handle the data for a net.
Definition netinfo.h:50
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
POST_MACHINING_PROPS & FrontPostMachining()
Definition padstack.h:372
UNCONNECTED_LAYER_MODE UnconnectedLayerMode() const
Definition padstack.h:404
DRILL_PROPS & TertiaryDrill()
Definition padstack.h:369
DRILL_PROPS & Drill()
Definition padstack.h:363
DRILL_PROPS & SecondaryDrill()
Definition padstack.h:366
POST_MACHINING_PROPS & BackPostMachining()
Definition padstack.h:375
MASK_LAYER_PROPS & BackOuterLayers()
Definition padstack.h:413
Definition pad.h:61
wxString GetText() const
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).
Abstract dimension API.
wxString GetOverrideText() const
bool GetOverrideTextEnabled() const
virtual wxString GetGeneratorType() 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.
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
Parameters and options when plotting/printing a board.
PLOT_FORMAT GetFormat() const
void SetFormat(PLOT_FORMAT aFormat)
A PCB_POINT is a 0-dimensional point that is used to mark a position on a PCB, or more usually a foot...
Definition pcb_point.h:39
Object to handle a bitmap image that can be inserted in a PCB.
void SetOpacity(double aOpacity)
REFERENCE_IMAGE & GetReferenceImage()
void SetCornerRadius(int aCornerRadius) override
void SetWidth(int aWidth) override
int GetWidth() const override
void SetShape(SHAPE_T aShape) override
Definition pcb_shape.h:214
void SetPolyShape(const SHAPE_POLY_SET &aShape) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
A board stackup table placed on the board, kept in step with the stackup.
wxString GetUnwrappedShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const
GetShownText() before it is line-broken to the cell's width, i.e.
bool StrokeRows() const
Definition pcb_table.h:110
int GetRowCount() const
Definition pcb_table.h:128
bool StrokeHeaderSeparator() const
Definition pcb_table.h:68
bool StrokeColumns() const
Definition pcb_table.h:107
bool StrokeExternal() const
Definition pcb_table.h:65
std::vector< PCB_TABLECELL * > GetCells() const
Definition pcb_table.h:165
int GetBorderWidth() const
Definition pcb_table.h:74
int GetColCount() const
Definition pcb_table.h:126
const STROKE_PARAMS & GetSeparatorsStroke() const
Definition pcb_table.h:89
const STROKE_PARAMS & GetBorderStroke() const
Definition pcb_table.h:71
int GetColWidth(int aCol) const
Definition pcb_table.h:137
int GetRowHeight(int aRow) const
Definition pcb_table.h:147
wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition pcb_text.cpp:180
const PADSTACK & Padstack() const
Definition pcb_track.h:435
VIATYPE GetViaType() const
Definition pcb_track.h:426
Writes a board or footprint in the KiCad 10.0 file format.
static constexpr int FORMAT_VERSION
void SaveFootprintFile(const wxString &aFileName, FOOTPRINT *aFootprint)
void SaveBoard(const wxString &aFileName, BOARD *aBoard)
Writes a board or footprint in the KiCad 9.0 file format.
static constexpr int FORMAT_VERSION
void SaveFootprintFile(const wxString &aFileName, FOOTPRINT *aFootprint)
void SaveBoard(const wxString &aFileName, BOARD *aBoard)
virtual bool TextVarResolver(wxString *aToken) const
Definition project.cpp:178
virtual std::map< wxString, wxString > & GetTextVars() const
Definition project.cpp:223
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
EDA_ANGLE GetOrientation() const
double GetOpacity() const
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.
SHAPE_LINE_CHAIN ConvertToPolyline(int aMaxError) const
Build a polyline approximation of the ellipse or arc.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
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.
int OutlineCount() const
Return the number of outlines in the set.
SHAPE_POLY_SET Fillet(int aRadius, int aErrorMax)
Return a filleted version of the polygon set.
void Fracture(bool aSimplify=true)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
Simple container to manage line stroke parameters.
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition title_block.h:38
const wxString & GetCompany() const
Definition title_block.h:93
void SetRevision(const wxString &aRevision)
Definition title_block.h:78
void SetComment(int aIdx, const wxString &aComment)
Definition title_block.h:98
bool TextVarResolver(wxString *aToken, const PROJECT *aProject, RESOLUTION_CONTEXT aContext) const
const wxString & GetRevision() const
Definition title_block.h:83
void SetTitle(const wxString &aTitle)
Definition title_block.h:55
const wxString & GetDate() const
Definition title_block.h:73
const wxString & GetComment(int aIdx) const
void SetCompany(const wxString &aCompany)
Definition title_block.h:88
const wxString & GetTitle() const
Definition title_block.h:60
void SetDate(const wxString &aDate)
Set the date field, and defaults to the current time and date.
Definition title_block.h:68
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
wxString GetPlacementAreaSource() const
Definition zone.h:839
void SetPlacementAreaSource(const wxString &aSource)
Definition zone.h:840
PLACEMENT_SOURCE_T GetPlacementAreaSourceType() const
Definition zone.h:841
void SetPlacementAreaSourceType(PLACEMENT_SOURCE_T aType)
Definition zone.h:842
bool GetPlacementAreaEnabled() const
Definition zone.h:836
void SetPlacementAreaEnabled(bool aEnabled)
Definition zone.h:837
void FinalizeTextVarExpansion(wxString &aText, RESOLUTION_CONTEXT aContext)
Definition common.cpp:88
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, RESOLUTION_CONTEXT aContext)
Definition common.cpp:60
std::vector< TEXT_VAR_REF_KEY > ExtractTextVarReferences(const wxString &aSource)
Lex-scan aSource and return every ${...} reference that appears, without resolving.
Definition common.cpp:468
@ INTERNAL
Definition common.h:96
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.
wxString FindUnsupportedToken(const wxString &aSerialized, const DATED_TOKEN *aNodes, size_t aNodeCount, const DATED_TOKEN *aValues, size_t aValueCount, int aTargetVersion)
Scan serialized s-expression text against dated node and value denylists.
std::string StripSexprStrings(const std::string &aText)
Drop quoted strings so a token inside a text value cannot cause a false refusal.
DOWNGRADE_FILE_RESULT
What a per-file converter did with one library file.
@ SKIPPED
Not a convertible file, leave it alone.
@ REFUSED
The target cannot represent this file.
@ CONVERTED
The temp file holds the downgraded copy.
bool VerifyDowngradedFile(const wxString &aPath, int aStampVersion, const std::function< wxString(const wxString &)> &aFindForbidden, wxString *aForbidden=nullptr)
Read back a downgraded output and require the target stamp plus a clean token scan.
#define _(s)
FILL_T
Definition eda_fill.h:29
@ NO_FILL
Definition eda_fill.h:30
@ 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
@ 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
@ EXPAND_INNER_LAYERS
The 'normal' stackup handling, where there is a single inner layer (In1) and rule areas using it expa...
Definition footprint.h:111
int RefreshGeneratedTables(BOARD &aBoard)
Bring every generated table on the board up to date and return how many were rebuilt.
static const std::string ProjectFileExtension
KIID niluuid(0)
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:744
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ User_45
Definition layer_ids.h:164
@ User_10
Definition layer_ids.h:129
static std::vector< PENDING_PROPERTY > plan(const EDA_ITEM &aSource, const EDA_ITEM &aTarget, const std::set< wxString > &aEnabledKeys)
Target properties to write, paired with values read off the source.
@ NON_COMPONENT
Pad with no hole that does not connect to a physical component, but rather provides a connection poin...
Definition padstack.h:106
@ 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.
Class to handle a set of BOARD_ITEMs.
#define FIRST_FP_AFFINE_TRANSFORM
First version that stores footprint children in library frame.
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
static int countCustomProperties(const SCH_SCREEN *aScreen)
static void lowerEllipses(SCH_SCREEN *aScreen)
static void omitEllipses(SCH_SCREEN *aScreen)
static bool isEllipse(const SCH_ITEM *aItem)
static void lowerRoundedRects(SCH_SCREEN *aScreen)
static bool isRoundedRect(const SCH_ITEM *aItem)
static int countRoundedRects(const SCH_SCREEN *aScreen)
static void omitRoundedRects(SCH_SCREEN *aScreen)
static void dropCustomProperties(SCH_SCREEN *aScreen)
static int countEllipses(const SCH_SCREEN *aScreen)
std::function< void(BOARD *)> m_omit
std::function< void(BOARD *)> m_apply
DOWNGRADE_BUCKET m_bucket
std::function< void(FOOTPRINT *)> m_applyFp
Footprint-scoped part, for .kicad_mod files.
std::function< void(FOOTPRINT *)> m_omitFp
wxString m_omitDetail
std::function< int(const BOARD *)> m_count
bool m_keepUnderOmitPolicy
An approximation the omission preference must not remove, because removing it would change the board ...
A token dated by the format that introduced it, for the fail-closed downgrade gates.
An older KiCad release we can export a project back to.
int m_boardVersion
SEXPR_BOARD_FILE_VERSION for the target.
VECTOR2I size
Drill diameter (x == y) or slot dimensions (x != y)
Definition padstack.h:278
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
Options for copying a placement rule area onto the others linked to it.
std::vector< std::pair< int, wxString > > m_titleReplacements
std::map< EDA_TEXT *, wxString > m_replacements
const std::string table
std::vector< DATABASE_CONNECTION::ROW > rows
netlist clear()
std::string path
const SHAPE_LINE_CHAIN chain
int radius
VECTOR2I end
wxString result
Test unit parsing edge cases and error handling.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition typeinfo.h:98
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition typeinfo.h:95
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ PCB_DRILL_MAP_T
class PCB_DRILL_MAP, drill symbols drawn at the holes
Definition typeinfo.h:240
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition typeinfo.h:96
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:85
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:84
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition typeinfo.h:81
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:82
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:93
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition typeinfo.h:99
@ PCB_GRID_ITEM_T
a subgrid placed on a board
Definition typeinfo.h:238
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:94
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:86
@ PCB_STACKUP_TABLE_T
class PCB_STACKUP_TABLE, a live stackup table derived from PCB_TABLE
Definition typeinfo.h:242
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition typeinfo.h:97
@ PCB_DRILL_CHART_T
class PCB_DRILL_CHART, a live drill chart derived from PCB_TABLE
Definition typeinfo.h:239
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
static PIECE polygon(std::vector< VIA_CROSS_SECTION_GEOMETRY::POINT > aPoints, bool aMixed=false)
Definition of file extensions used in Kicad.
Class ZONE_SETTINGS used to handle zones parameters in dialogs.