KiCad PCB EDA Suite
Loading...
Searching...
No Matches
padstack.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 (C) 2024 Jon Evans <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <utility> // std::as_const
22
23#include <convert_basic_shapes_to_polygon.h> // RECT_CHAMFER_POSITIONS
24#include "padstack.h"
25#include <api/api_enums.h>
26#include <api/api_utils.h>
27#include <api/api_pcb_utils.h>
28#include <api/board/board_types.pb.h>
31#include <layer_range.h>
32#include <macros.h>
33#include <magic_enum.hpp>
34#include <pad.h>
35#include <board.h>
36#include <pcb_shape.h>
37#include <properties/property.h>
39
40
44
45
71
72
74{
75 m_parent = aOther.m_parent;
76 *this = aOther;
77
79 [&]( PCB_LAYER_ID aLayer )
80 {
81 for( std::shared_ptr<PCB_SHAPE>& shape : CopperLayer( aLayer ).custom_shapes )
82 shape->SetParent( m_parent );
83 } );
84}
85
86
88{
89 // NOTE: m_parent is not copied from operator=, because this operator is commonly used to
90 // update the padstack properties, and such an update must not change the parent PAD to point to
91 // the parent of some different padstack.
92
93 m_mode = aOther.m_mode;
94 m_layerSet = aOther.m_layerSet;
95 SetCustomName( aOther.CustomName() );
102 m_drill = aOther.m_drill;
107
108 // Data consistency enforcement logic that used to live in the pad properties dialog.
109 // While it might be tempting to put these in the individual property setters, there's no
110 // well-defined order in which they're called, and many of the consistency checks are
111 // between multiple properties.
112
114 [&]( PCB_LAYER_ID aLayer )
115 {
116 PAD_SHAPE shape = Shape( aLayer );
117
118 // Make sure leftover primitives don't stick around
119 ClearPrimitives( aLayer );
120
121 // For custom pad shape, duplicate primitives of the pad to copy
122 if( shape == PAD_SHAPE::CUSTOM )
123 ReplacePrimitives( aOther.Primitives( aLayer ), aLayer );
124
125 // rounded rect pads with radius ratio = 0 are in fact rect pads.
126 // So set the right shape (and perhaps issues with a radius = 0)
127 if( shape == PAD_SHAPE::ROUNDRECT && RoundRectRadiusRatio( aLayer ) == 0.0 )
129 } );
130
131 return *this;
132}
133
134
135bool PADSTACK::operator==( const PADSTACK& aOther ) const
136{
137 if( m_mode != aOther.m_mode )
138 return false;
139
140 if( m_layerSet != aOther.m_layerSet )
141 return false;
142
143 if( m_customName && aOther.m_customName )
144 {
145 if( *m_customName != *aOther.m_customName )
146 return false;
147 }
148 else if( (bool) m_customName != (bool) aOther.m_customName )
149 {
150 return false;
151 }
152
153 if( m_orientation != aOther.m_orientation )
154 return false;
155
156 if( m_frontMaskProps != aOther.m_frontMaskProps )
157 return false;
158
159 if( m_backMaskProps != aOther.m_backMaskProps )
160 return false;
161
163 return false;
164
166 return false;
167
168 if( m_drill != aOther.m_drill )
169 return false;
170
171 if( m_secondaryDrill != aOther.m_secondaryDrill )
172 return false;
173
174 if( m_tertiaryDrill != aOther.m_tertiaryDrill )
175 return false;
176
178 return false;
179
181 return false;
182
183 bool copperMatches = true;
184
186 [&]( PCB_LAYER_ID aLayer )
187 {
188 if( CopperLayer( aLayer ) != aOther.CopperLayer( aLayer ) )
189 copperMatches = false;
190 } );
191
192 return copperMatches;
193}
194
195
196bool PADSTACK::unpackCopperLayer( const kiapi::board::types::PadStackLayer& aProto )
197{
198 using namespace kiapi::board::types;
200
201 if( m_mode == MODE::NORMAL && layer != ALL_LAYERS )
202 return false;
203
204 if( m_mode == MODE::FRONT_INNER_BACK && layer != F_Cu && layer != INNER_LAYERS && layer != B_Cu )
205 return false;
206
207 SetSize( kiapi::common::UnpackVector2( aProto.size() ), layer );
208 SetShape( FromProtoEnum<PAD_SHAPE>( aProto.shape() ), layer );
209 Offset( layer ) = kiapi::common::UnpackVector2( aProto.offset() );
210 SetAnchorShape( FromProtoEnum<PAD_SHAPE>( aProto.custom_anchor_shape() ), layer );
211
212 SHAPE_PROPS& props = CopperLayer( layer ).shape;
213 props.chamfered_rect_ratio = aProto.chamfer_ratio();
214 props.round_rect_radius_ratio = aProto.corner_rounding_ratio();
215
216 if( Shape( layer ) == PAD_SHAPE::TRAPEZOID && aProto.has_trapezoid_delta() )
217 TrapezoidDeltaSize( layer ) = kiapi::common::UnpackVector2( aProto.trapezoid_delta() );
218
219 if( aProto.chamfered_corners().top_left() )
221
222 if( aProto.chamfered_corners().top_right() )
224
225 if( aProto.chamfered_corners().bottom_left() )
227
228 if( aProto.chamfered_corners().bottom_right() )
230
231 ClearPrimitives( layer );
232 google::protobuf::Any a;
233
234 for( const BoardGraphicShape& shapeProto : aProto.custom_shapes() )
235 {
236 if( a.PackFrom( shapeProto ) )
237 {
238 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( m_parent );
239
240 if( shape->Deserialize( a ) )
241 AddPrimitive( shape.release(), layer );
242 }
243 }
244
245 return true;
246}
247
248
249bool PADSTACK::Deserialize( const kiapi::board::types::PadStack& padstack )
250{
251 using namespace kiapi::board::types;
252
253 auto unpackOptional = []<typename ProtoEnum>( const ProtoEnum& aProto,
254 std::optional<bool>& aDest, ProtoEnum aTrueValue,
255 ProtoEnum aFalseValue )
256 {
257 if( aProto == aTrueValue )
258 aDest = true;
259 else if( aProto == aFalseValue )
260 aDest = false;
261 else
262 aDest = std::nullopt;
263 };
264
265 auto unpackPostMachining = []( const PostMachiningProperties& aProto,
267 {
268 switch( aProto.mode() )
269 {
270 case VDPM_NOT_POST_MACHINED: aDest.mode = PAD_DRILL_POST_MACHINING_MODE::NOT_POST_MACHINED; break;
271 case VDPM_COUNTERBORE: aDest.mode = PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE; break;
272 case VDPM_COUNTERSINK: aDest.mode = PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK; break;
273 default: aDest.mode = std::nullopt; break;
274 }
275
276 aDest.size = kiapi::common::UnpackDistance( aProto.size() );
277 aDest.depth = kiapi::common::UnpackDistance( aProto.depth() );
278 aDest.angle = EDA_ANGLE( aProto.angle().value_degrees(), DEGREES_T ).AsTenthsOfADegree();
279 };
280
281
282 m_mode = FromProtoEnum<MODE>( padstack.type() );
283 SetLayerSet( kiapi::board::UnpackLayerSet( padstack.layers() ) );
284 SetOrientation( EDA_ANGLE( padstack.angle().value_degrees(), DEGREES_T ) );
285
286 Drill().size = kiapi::common::UnpackVector2( padstack.drill().diameter() );
287 Drill().start = FromProtoEnum<PCB_LAYER_ID>( padstack.drill().start_layer() );
288 Drill().end = FromProtoEnum<PCB_LAYER_ID>( padstack.drill().end_layer() );
289 unpackOptional( padstack.drill().capped(), Drill().is_capped, VDCM_CAPPED, VDCM_UNCAPPED );
290 unpackOptional( padstack.drill().filled(), Drill().is_filled, VDFM_FILLED, VDFM_UNFILLED );
291
292 if( padstack.has_front_post_machining() )
293 unpackPostMachining( padstack.front_post_machining(), FrontPostMachining() );
294
295 if( padstack.has_back_post_machining() )
296 unpackPostMachining( padstack.back_post_machining(), BackPostMachining() );
297
298 Drill().shape = FromProtoEnum<PAD_DRILL_SHAPE>( padstack.drill().shape() );
299
300 if( padstack.has_secondary_drill() )
301 {
302 const DrillProperties& secondary = padstack.secondary_drill();
303
304 SecondaryDrill().size = kiapi::common::UnpackVector2( secondary.diameter() );
305 SecondaryDrill().start = FromProtoEnum<PCB_LAYER_ID>( secondary.start_layer() );
306 SecondaryDrill().end = FromProtoEnum<PCB_LAYER_ID>( secondary.end_layer() );
307 SecondaryDrill().shape = FromProtoEnum<PAD_DRILL_SHAPE>( secondary.shape() );
308
309 unpackOptional( secondary.capped(), SecondaryDrill().is_capped, VDCM_CAPPED, VDCM_UNCAPPED );
310 unpackOptional( secondary.filled(), SecondaryDrill().is_filled, VDFM_FILLED, VDFM_UNFILLED );
311 }
312 else
313 {
314 SecondaryDrill().size = { 0, 0 };
318 SecondaryDrill().is_capped = std::nullopt;
319 SecondaryDrill().is_filled = std::nullopt;
320 }
321
322 if( padstack.has_tertiary_drill() )
323 {
324 const DrillProperties& tertiary = padstack.tertiary_drill();
325
326 TertiaryDrill().size = kiapi::common::UnpackVector2( tertiary.diameter() );
327 TertiaryDrill().start = FromProtoEnum<PCB_LAYER_ID>( tertiary.start_layer() );
328 TertiaryDrill().end = FromProtoEnum<PCB_LAYER_ID>( tertiary.end_layer() );
329 TertiaryDrill().shape = FromProtoEnum<PAD_DRILL_SHAPE>( tertiary.shape() );
330
331 unpackOptional( tertiary.capped(), TertiaryDrill().is_capped, VDCM_CAPPED, VDCM_UNCAPPED );
332 unpackOptional( tertiary.filled(), TertiaryDrill().is_filled, VDFM_FILLED, VDFM_UNFILLED );
333 }
334 else
335 {
336 TertiaryDrill().size = { 0, 0 };
340 TertiaryDrill().is_capped = std::nullopt;
341 TertiaryDrill().is_filled = std::nullopt;
342 }
343
344 for( const PadStackLayer& layer : padstack.copper_layers() )
345 {
346 if( !unpackCopperLayer( layer ) )
347 return false;
348 }
349
350 CopperLayer( ALL_LAYERS ).thermal_gap = std::nullopt;
352
353 if( padstack.has_zone_settings() )
354 {
356 FromProtoEnum<ZONE_CONNECTION>( padstack.zone_settings().zone_connection() );
357
358 if( padstack.zone_settings().has_thermal_spokes() )
359 {
360 const ThermalSpokeSettings& thermals = padstack.zone_settings().thermal_spokes();
361
362 if( thermals.has_gap() )
363 CopperLayer( ALL_LAYERS ).thermal_gap = thermals.gap().value_nm();
364
365 if( thermals.has_width() )
366 CopperLayer( ALL_LAYERS ).thermal_spoke_width = thermals.width().value_nm();
367
368 SetThermalSpokeAngle( EDA_ANGLE( thermals.angle().value_degrees(), DEGREES_T ), F_Cu );
369 }
370 }
371 else
372 {
375 }
376
378 FromProtoEnum<UNCONNECTED_LAYER_MODE>( padstack.unconnected_layer_removal() ) );
379
380 unpackOptional( padstack.front_outer_layers().solder_mask_mode(),
381 FrontOuterLayers().has_solder_mask, SMM_MASKED, SMM_UNMASKED );
382
383 unpackOptional( padstack.back_outer_layers().solder_mask_mode(),
384 BackOuterLayers().has_solder_mask, SMM_MASKED, SMM_UNMASKED );
385
386 unpackOptional( padstack.front_outer_layers().covering_mode(), FrontOuterLayers().has_covering,
387 VCM_COVERED, VCM_UNCOVERED );
388
389 unpackOptional( padstack.back_outer_layers().covering_mode(), BackOuterLayers().has_covering,
390 VCM_COVERED, VCM_UNCOVERED );
391
392 unpackOptional( padstack.front_outer_layers().plugging_mode(), FrontOuterLayers().has_plugging,
393 VPM_PLUGGED, VPM_UNPLUGGED );
394
395 unpackOptional( padstack.back_outer_layers().plugging_mode(), BackOuterLayers().has_plugging,
396 VPM_PLUGGED, VPM_UNPLUGGED );
397
398 unpackOptional( padstack.front_outer_layers().solder_paste_mode(),
399 FrontOuterLayers().has_solder_paste, SPM_PASTE, SPM_NO_PASTE );
400
401 unpackOptional( padstack.back_outer_layers().solder_paste_mode(),
402 BackOuterLayers().has_solder_paste, SPM_PASTE, SPM_NO_PASTE );
403
404 if( padstack.front_outer_layers().has_solder_mask_settings()
405 && padstack.front_outer_layers().solder_mask_settings().has_solder_mask_margin() )
406 {
408 padstack.front_outer_layers().solder_mask_settings().solder_mask_margin().value_nm();
409 }
410 else
411 {
412 FrontOuterLayers().solder_mask_margin = std::nullopt;
413 }
414
415 if( padstack.back_outer_layers().has_solder_mask_settings()
416 && padstack.back_outer_layers().solder_mask_settings().has_solder_mask_margin() )
417 {
419 padstack.back_outer_layers().solder_mask_settings().solder_mask_margin().value_nm();
420 }
421 else
422 {
423 BackOuterLayers().solder_mask_margin = std::nullopt;
424 }
425
426 if( padstack.front_outer_layers().has_solder_paste_settings()
427 && padstack.front_outer_layers().solder_paste_settings().has_solder_paste_margin() )
428 {
430 padstack.front_outer_layers().solder_paste_settings().solder_paste_margin().value_nm();
431 }
432 else
433 {
434 FrontOuterLayers().solder_paste_margin = std::nullopt;
435 }
436
437 if( padstack.back_outer_layers().has_solder_paste_settings()
438 && padstack.back_outer_layers().solder_paste_settings().has_solder_paste_margin() )
439 {
441 padstack.back_outer_layers().solder_paste_settings().solder_paste_margin().value_nm();
442 }
443 else
444 {
445 BackOuterLayers().solder_paste_margin = std::nullopt;
446 }
447
448 if( padstack.front_outer_layers().has_solder_paste_settings()
449 && padstack.front_outer_layers().solder_paste_settings().has_solder_paste_margin_ratio() )
450 {
452 padstack.front_outer_layers().solder_paste_settings().solder_paste_margin_ratio().value();
453 }
454 else
455 {
457 }
458
459 if( padstack.back_outer_layers().has_solder_paste_settings()
460 && padstack.back_outer_layers().solder_paste_settings().has_solder_paste_margin_ratio() )
461 {
463 padstack.back_outer_layers().solder_paste_settings().solder_paste_margin_ratio().value();
464 }
465 else
466 {
468 }
469
470
471 return true;
472}
473
474
475bool PADSTACK::Deserialize( const google::protobuf::Any& aContainer )
476{
477 kiapi::board::types::PadStack padstack;
478
479 if( !aContainer.UnpackTo( &padstack ) )
480 return false;
481
482 return Deserialize( padstack );
483}
484
485
486// A backdrill's side is identified by its start layer (F_Cu = top, B_Cu = bottom), not by which
487// drill slot it occupies. Reads scan both slots so a board written by KiCad 10.0 - which stored the
488// top backdrill in the tertiary slot - is understood, and writes always stamp the start layer so a
489// backdrill saved here is read back correctly by older KiCad. Presence is keyed on the drill size.
491{
492 PCB_LAYER_ID side = aTop ? F_Cu : B_Cu;
493
494 if( m_secondaryDrill.size.x > 0 && m_secondaryDrill.start == side )
495 return &m_secondaryDrill;
496
497 if( m_tertiaryDrill.size.x > 0 && m_tertiaryDrill.start == side )
498 return &m_tertiaryDrill;
499
500 return nullptr;
501}
502
503
505{
506 return const_cast<DRILL_PROPS*>( std::as_const( *this ).findBackdrillDrill( aTop ) );
507}
508
509
511{
512 if( DRILL_PROPS* existing = findBackdrillDrill( aTop ) )
513 return *existing;
514
517 PCB_LAYER_ID otherSide = aTop ? B_Cu : F_Cu;
518
519 // Displace to the other slot only when the canonical home is already taken by the opposite
520 // side, which happens when extending a backdrill on a board written by KiCad 10.0.
521 if( home.size.x > 0 && home.start == otherSide )
522 return other;
523
524 return home;
525}
526
527
529{
530 PCB_LAYER_ID side = aTop ? F_Cu : B_Cu;
531
532 if( m_secondaryDrill.start == side )
533 m_secondaryDrill.size = { 0, 0 };
534
535 if( m_tertiaryDrill.start == side )
536 m_tertiaryDrill.size = { 0, 0 };
537}
538
539
541{
542 bool hasTop = findBackdrillDrill( true ) != nullptr;
543 bool hasBottom = findBackdrillDrill( false ) != nullptr;
544
545 if( hasTop && hasBottom )
547
548 if( hasTop )
550
551 if( hasBottom )
553
555}
556
557
559{
560 auto apply =
561 [this]( bool aTop, bool aWant )
562 {
563 if( aWant )
564 {
565 DRILL_PROPS& drill = backdrillWriteSlot( aTop );
566 drill.start = aTop ? F_Cu : B_Cu;
568
569 if( drill.end == UNDEFINED_LAYER )
570 drill.end = drill.start; // Must-cut a single copper layer
571
572 if( drill.size.x <= 0 )
573 drill.size = m_drill.size * 1.1; // Backdrill slightly larger than main drill
574 }
575 else
576 {
577 clearBackdrillSide( aTop );
578 }
579 };
580
581 apply( true, aMode == BACKDRILL_MODE::BACKDRILL_TOP || aMode == BACKDRILL_MODE::BACKDRILL_BOTH );
582 apply( false, aMode == BACKDRILL_MODE::BACKDRILL_BOTTOM || aMode == BACKDRILL_MODE::BACKDRILL_BOTH );
583}
584
585
586std::optional<int> PADSTACK::GetBackdrillSize( bool aTop ) const
587{
588 if( const DRILL_PROPS* drill = findBackdrillDrill( aTop ) )
589 return drill->size.x;
590
591 return std::nullopt;
592}
593
594
595void PADSTACK::SetBackdrillSize( bool aTop, std::optional<int> aSize )
596{
597 if( aSize.has_value() )
598 {
599 DRILL_PROPS& target = backdrillWriteSlot( aTop );
600 target.size = { *aSize, *aSize };
602 target.start = aTop ? F_Cu : B_Cu;
603 }
604 else
605 {
606 clearBackdrillSide( aTop );
607 }
608}
609
610
612{
613 if( const DRILL_PROPS* drill = findBackdrillDrill( aTop ) )
614 return drill->end;
615
616 return UNDEFINED_LAYER;
617}
618
619
621{
622 // A backdrill with no must-cut layer does not exist (matching the via layer sanitizer), so
623 // clearing the must-cut clears the side rather than leaving a sizeful drill with no end.
624 if( aLayer == UNDEFINED_LAYER )
625 {
626 clearBackdrillSide( aTop );
627 return;
628 }
629
630 DRILL_PROPS& target = backdrillWriteSlot( aTop );
631
632 target.end = aLayer;
633 target.start = aTop ? F_Cu : B_Cu;
634}
635
636void PADSTACK::Serialize( kiapi::board::types::PadStack& padstack ) const
637{
638 using namespace kiapi::board::types;
639
640 padstack.set_type( ToProtoEnum<MODE, PadStackType>( m_mode ) );
641 kiapi::board::PackLayerSet( *padstack.mutable_layers(), m_layerSet );
642 padstack.mutable_angle()->set_value_degrees( m_orientation.GetAngle().AsDegrees() );
643
644 kiapi::common::PackVector2( *padstack.mutable_drill()->mutable_diameter(), m_drill.size );
645 padstack.mutable_drill()->set_start_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( m_drill.start ) );
646 padstack.mutable_drill()->set_end_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( m_drill.end ) );
647 padstack.mutable_drill()->set_shape( ToProtoEnum<PAD_DRILL_SHAPE, kiapi::board::types::DrillShape>( m_drill.shape ) );
648
649 if( m_drill.is_capped.has_value() )
650 padstack.mutable_drill()->set_capped( m_drill.is_capped.value() ? VDCM_CAPPED : VDCM_UNCAPPED );
651
652 if( m_drill.is_filled.has_value() )
653 padstack.mutable_drill()->set_filled( m_drill.is_filled.value() ? VDFM_FILLED : VDFM_UNFILLED );
654
655 if( m_secondaryDrill.size.x > 0 )
656 {
657 DrillProperties* secondary = padstack.mutable_secondary_drill();
658 kiapi::common::PackVector2( *secondary->mutable_diameter(), m_secondaryDrill.size );
659 secondary->set_start_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( m_secondaryDrill.start ) );
660 secondary->set_end_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( m_secondaryDrill.end ) );
662
663 if( m_secondaryDrill.is_capped.has_value() )
664 secondary->set_capped( m_secondaryDrill.is_capped.value() ? VDCM_CAPPED : VDCM_UNCAPPED );
665
666 if( m_secondaryDrill.is_filled.has_value() )
667 secondary->set_filled( m_secondaryDrill.is_filled.value() ? VDFM_FILLED : VDFM_UNFILLED );
668 }
669
670 if( m_tertiaryDrill.size.x > 0 )
671 {
672 DrillProperties* tertiary = padstack.mutable_tertiary_drill();
673 kiapi::common::PackVector2( *tertiary->mutable_diameter(), m_tertiaryDrill.size );
674 tertiary->set_start_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( m_tertiaryDrill.start ) );
675 tertiary->set_end_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( m_tertiaryDrill.end ) );
677
678 if( m_tertiaryDrill.is_capped.has_value() )
679 tertiary->set_capped( m_tertiaryDrill.is_capped.value() ? VDCM_CAPPED : VDCM_UNCAPPED );
680
681 if( m_tertiaryDrill.is_filled.has_value() )
682 tertiary->set_filled( m_tertiaryDrill.is_filled.value() ? VDFM_FILLED : VDFM_UNFILLED );
683 }
684
685 auto packPostMachining = []( const PADSTACK::POST_MACHINING_PROPS& aProps,
686 PostMachiningProperties* aProto )
687 {
688 if( aProps.mode.has_value() )
689 {
690 switch( aProps.mode.value() )
691 {
692 case PAD_DRILL_POST_MACHINING_MODE::NOT_POST_MACHINED: aProto->set_mode( VDPM_NOT_POST_MACHINED ); break;
693 case PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE: aProto->set_mode( VDPM_COUNTERBORE ); break;
694 case PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK: aProto->set_mode( VDPM_COUNTERSINK ); break;
695 default: break;
696 }
697 }
698
699 kiapi::common::PackDistance( *aProto->mutable_size(), aProps.size );
700 kiapi::common::PackDistance( *aProto->mutable_depth(), aProps.depth );
701 aProto->mutable_angle()->set_value_degrees( EDA_ANGLE( aProps.angle / 10.0, DEGREES_T ).AsDegrees() );
702 };
703
704 if( m_frontPostMachining.mode.has_value() || m_frontPostMachining.size > 0 )
705 packPostMachining( m_frontPostMachining, padstack.mutable_front_post_machining() );
706
707 if( m_backPostMachining.mode.has_value() || m_backPostMachining.size > 0 )
708 packPostMachining( m_backPostMachining, padstack.mutable_back_post_machining() );
709
711 [&]( PCB_LAYER_ID aLayer )
712 {
713 PadStackLayer* layer = padstack.add_copper_layers();
714 const COPPER_LAYER_PROPS& props = CopperLayer( aLayer );
715
716 layer->set_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( aLayer ) );
717 kiapi::common::PackVector2( *layer->mutable_size(), props.shape.size );
719 kiapi::common::PackVector2( *layer->mutable_offset(), props.shape.offset );
720 layer->set_custom_anchor_shape( ToProtoEnum<PAD_SHAPE, kiapi::board::types::PadStackShape>( props.shape.anchor_shape ) );
721 layer->set_chamfer_ratio( props.shape.chamfered_rect_ratio );
722 layer->set_corner_rounding_ratio( props.shape.round_rect_radius_ratio );
723
724 if( props.shape.shape == PAD_SHAPE::TRAPEZOID )
725 kiapi::common::PackVector2( *layer->mutable_trapezoid_delta(), props.shape.trapezoid_delta_size );
726
728 layer->mutable_chamfered_corners()->set_top_left( true );
729
731 layer->mutable_chamfered_corners()->set_top_right( true );
732
734 layer->mutable_chamfered_corners()->set_bottom_left( true );
735
737 layer->mutable_chamfered_corners()->set_bottom_right( true );
738
739 for( const std::shared_ptr<PCB_SHAPE>& shape : props.custom_shapes )
740 {
741 google::protobuf::Any a;
742 shape->Serialize( a );
743
744 if( !a.UnpackTo( layer->add_custom_shapes() ) )
745 wxFAIL_MSG( wxT( "Failed to unpack PADSTACK from internal serialization" ) );
746 }
747 } );
748
749 if( CopperLayer( ALL_LAYERS ).zone_connection.has_value() )
750 {
751 padstack.mutable_zone_settings()->set_zone_connection(
753 }
754
755 if( CopperLayer( ALL_LAYERS ).thermal_gap.has_value() )
756 {
757 padstack.mutable_zone_settings()->mutable_thermal_spokes()->mutable_gap()->set_value_nm(
758 CopperLayer( ALL_LAYERS ).thermal_gap.value() );
759 }
760
761 if( CopperLayer( ALL_LAYERS ).thermal_spoke_width.has_value() )
762 {
763 padstack.mutable_zone_settings()->mutable_thermal_spokes()->mutable_width()->set_value_nm(
764 CopperLayer( ALL_LAYERS ).thermal_spoke_width.value() );
765 }
766
767 if( CopperLayer( ALL_LAYERS ).thermal_spoke_angle.has_value() )
768 {
769 padstack.mutable_zone_settings()->mutable_thermal_spokes()->mutable_angle()->set_value_degrees(
770 CopperLayer( ALL_LAYERS ).thermal_spoke_angle.value().GetAngle().AsDegrees() );
771 }
772
773 padstack.set_unconnected_layer_removal( ToProtoEnum<UNCONNECTED_LAYER_MODE,
774 kiapi::board::types::UnconnectedLayerRemoval>( m_unconnectedLayerMode ) );
775
776 if( FrontOuterLayers().has_solder_mask.has_value() )
777 {
778 padstack.mutable_front_outer_layers()->set_solder_mask_mode(
779 FrontOuterLayers().has_solder_mask.value() ? SMM_MASKED : SMM_UNMASKED );
780 }
781
782 if( BackOuterLayers().has_solder_mask.has_value() )
783 {
784 padstack.mutable_back_outer_layers()->set_solder_mask_mode(
785 BackOuterLayers().has_solder_mask.value() ? SMM_MASKED : SMM_UNMASKED );
786 }
787
788 if( FrontOuterLayers().has_covering.has_value() )
789 {
790 padstack.mutable_front_outer_layers()->set_covering_mode(
791 FrontOuterLayers().has_covering.value() ? VCM_COVERED : VCM_UNCOVERED );
792 }
793
794 if( BackOuterLayers().has_covering.has_value() )
795 {
796 padstack.mutable_back_outer_layers()->set_covering_mode(
797 BackOuterLayers().has_covering.value() ? VCM_COVERED : VCM_UNCOVERED );
798 }
799
800 if( FrontOuterLayers().has_plugging.has_value() )
801 {
802 padstack.mutable_front_outer_layers()->set_plugging_mode(
803 FrontOuterLayers().has_plugging.value() ? VPM_PLUGGED : VPM_UNPLUGGED );
804 }
805
806 if( BackOuterLayers().has_plugging.has_value() )
807 {
808 padstack.mutable_back_outer_layers()->set_plugging_mode(
809 BackOuterLayers().has_plugging.value() ? VPM_PLUGGED : VPM_UNPLUGGED );
810 }
811
812 if( FrontOuterLayers().has_solder_paste.has_value() )
813 {
814 padstack.mutable_front_outer_layers()->set_solder_paste_mode(
815 FrontOuterLayers().has_solder_paste.value() ? SPM_PASTE : SPM_NO_PASTE );
816 }
817
818 if( BackOuterLayers().has_solder_paste.has_value() )
819 {
820 padstack.mutable_back_outer_layers()->set_solder_paste_mode(
821 BackOuterLayers().has_solder_paste.value() ? SPM_PASTE : SPM_NO_PASTE );
822 }
823
824 if( FrontOuterLayers().solder_mask_margin.has_value() )
825 {
826 padstack.mutable_front_outer_layers()->mutable_solder_mask_settings()->mutable_solder_mask_margin()->set_value_nm(
827 FrontOuterLayers().solder_mask_margin.value() );
828 }
829
830 if( BackOuterLayers().solder_mask_margin.has_value() )
831 {
832 padstack.mutable_back_outer_layers()->mutable_solder_mask_settings()->mutable_solder_mask_margin()->set_value_nm(
833 BackOuterLayers().solder_mask_margin.value() );
834 }
835
836 if( FrontOuterLayers().solder_paste_margin.has_value() )
837 {
838 padstack.mutable_front_outer_layers()->mutable_solder_paste_settings()->mutable_solder_paste_margin()->set_value_nm(
839 FrontOuterLayers().solder_paste_margin.value() );
840 }
841
842 if( BackOuterLayers().solder_paste_margin.has_value() )
843 {
844 padstack.mutable_back_outer_layers()->mutable_solder_paste_settings()->mutable_solder_paste_margin()->set_value_nm(
845 BackOuterLayers().solder_paste_margin.value() );
846 }
847
848 if( FrontOuterLayers().solder_paste_margin_ratio.has_value() )
849 {
850 padstack.mutable_front_outer_layers()->mutable_solder_paste_settings()->mutable_solder_paste_margin_ratio()->set_value(
851 FrontOuterLayers().solder_paste_margin_ratio.value() );
852 }
853
854 if( BackOuterLayers().solder_paste_margin_ratio.has_value() )
855 {
856 padstack.mutable_back_outer_layers()->mutable_solder_paste_settings()->mutable_solder_paste_margin_ratio()->set_value(
857 BackOuterLayers().solder_paste_margin_ratio.value() );
858 }
859
860}
861
862
863void PADSTACK::Serialize( google::protobuf::Any& aContainer ) const
864{
865 kiapi::board::types::PadStack padstack;
866 Serialize( padstack );
867
868 if( !aContainer.PackFrom( padstack ) )
869 wxFAIL_MSG( wxT( "Failed to pack PADSTACK" ) );
870}
871
872
873void PADSTACK::SetSize( const VECTOR2I& aSize, PCB_LAYER_ID aLayer )
874{
875 VECTOR2I size = aSize;
876
877 if( size.x < 0 )
878 size.x = 0;
879
880 if( size.y < 0 )
881 size.y = 0;
882
883 CopperLayer( aLayer ).shape.size = size;
884}
885
886
888{
889 return CopperLayer( aLayer ).shape.size;
890}
891
892
894{
895 return CopperLayer( aLayer ).shape.shape;
896}
897
898
900{
901 CopperLayer( aLayer ).shape.shape = aShape;
902}
903
904
906{
907 return m_drill.shape;
908}
909
910
912{
913 m_drill.shape = aShape;
914}
915
916
918{
919 return CopperLayer( aLayer ).shape.offset;
920}
921
922
924{
925 return CopperLayer( aLayer ).shape.offset;
926}
927
928
929void PADSTACK::SetOffset( const VECTOR2I& aOffset, PCB_LAYER_ID aLayer )
930{
931 CopperLayer( aLayer ).shape.offset = aOffset;
932}
933
934
936{
937 return CopperLayer( aLayer ).shape.anchor_shape;
938}
939
940
942{
943 CopperLayer( aLayer ).shape.anchor_shape = aShape;
944}
945
946
951
952
954{
955 return CopperLayer( aLayer ).shape.trapezoid_delta_size;
956}
957
958
960{
962}
963
964
966{
967 CopperLayer( aLayer ).shape.round_rect_radius_ratio = aRatio;
968}
969
970
972{
973 const VECTOR2I& size = Size( aLayer );
974 return KiROUND( std::min( size.x, size.y ) * RoundRectRadiusRatio( aLayer ) );
975}
976
977
978void PADSTACK::SetRoundRectRadius( double aRadius, PCB_LAYER_ID aLayer )
979{
980 const VECTOR2I& size = Size( aLayer );
981 int min_r = std::min( size.x, size.y );
982
983 if( min_r > 0 )
984 SetRoundRectRadiusRatio( aRadius / min_r, aLayer );
985}
986
987
989{
990 return CopperLayer( aLayer ).shape.chamfered_rect_ratio;
991}
992
993
994void PADSTACK::SetChamferRatio( double aRatio, PCB_LAYER_ID aLayer )
995{
996 CopperLayer( aLayer ).shape.chamfered_rect_ratio = aRatio;
997}
998
999
1004
1005
1007{
1009}
1010
1011
1012void PADSTACK::SetChamferPositions( int aPositions, PCB_LAYER_ID aLayer )
1013{
1014 CopperLayer( aLayer ).shape.chamfered_rect_positions = aPositions;
1015}
1016
1017
1018std::optional<int>& PADSTACK::Clearance( PCB_LAYER_ID aLayer )
1019{
1020 return CopperLayer( aLayer ).clearance;
1021}
1022
1023
1024const std::optional<int>& PADSTACK::Clearance( PCB_LAYER_ID aLayer ) const
1025{
1026 return CopperLayer( aLayer ).clearance;
1027}
1028
1029
1030std::optional<int>& PADSTACK::SolderMaskMargin( PCB_LAYER_ID aLayer )
1031{
1032 if( IsFrontLayer( aLayer ) )
1034 else if( IsBackLayer( aLayer ) )
1036 else
1037 return FrontOuterLayers().solder_mask_margin; // Should not happen
1038}
1039
1040
1041const std::optional<int>& PADSTACK::SolderMaskMargin( PCB_LAYER_ID aLayer ) const
1042{
1043 if( IsFrontLayer( aLayer ) )
1045 else if( IsBackLayer( aLayer ) )
1047 else
1048 return FrontOuterLayers().solder_mask_margin; // Should not happen
1049}
1050
1051
1052std::optional<int>& PADSTACK::SolderPasteMargin( PCB_LAYER_ID aLayer )
1053{
1054 if( IsFrontLayer( aLayer ) )
1056 else if( IsBackLayer( aLayer ) )
1058 else
1059 return FrontOuterLayers().solder_paste_margin; // Should not happen
1060}
1061
1062
1063const std::optional<int>& PADSTACK::SolderPasteMargin( PCB_LAYER_ID aLayer ) const
1064{
1065 if( IsFrontLayer( aLayer ) )
1067 else if( IsBackLayer( aLayer ) )
1069 else
1070 return FrontOuterLayers().solder_paste_margin; // Should not happen
1071}
1072
1073
1074std::optional<double>& PADSTACK::SolderPasteMarginRatio( PCB_LAYER_ID aLayer )
1075{
1076 if( IsFrontLayer( aLayer ) )
1078 else if( IsBackLayer( aLayer ) )
1080 else
1081 return FrontOuterLayers().solder_paste_margin_ratio; // Should not happen
1082}
1083
1084
1085const std::optional<double>& PADSTACK::SolderPasteMarginRatio( PCB_LAYER_ID aLayer ) const
1086{
1087 if( IsFrontLayer( aLayer ) )
1089 else if( IsBackLayer( aLayer ) )
1091 else
1092 return FrontOuterLayers().solder_paste_margin_ratio; // Should not happen
1093}
1094
1095
1096std::optional<ZONE_CONNECTION>& PADSTACK::ZoneConnection( PCB_LAYER_ID aLayer )
1097{
1098 return CopperLayer( aLayer ).zone_connection;
1099}
1100
1101
1102const std::optional<ZONE_CONNECTION>& PADSTACK::ZoneConnection( PCB_LAYER_ID aLayer ) const
1103{
1104 return CopperLayer( aLayer ).zone_connection;
1105}
1106
1107
1108std::optional<int>& PADSTACK::ThermalSpokeWidth( PCB_LAYER_ID aLayer )
1109{
1110 return CopperLayer( aLayer ).thermal_spoke_width;
1111}
1112
1113
1114const std::optional<int>& PADSTACK::ThermalSpokeWidth( PCB_LAYER_ID aLayer ) const
1115{
1116 return CopperLayer( aLayer ).thermal_spoke_width;
1117}
1118
1119
1120std::optional<int>& PADSTACK::ThermalGap( PCB_LAYER_ID aLayer )
1121{
1122 return CopperLayer( aLayer ).thermal_gap;
1123}
1124
1125
1126const std::optional<int>& PADSTACK::ThermalGap( PCB_LAYER_ID aLayer ) const
1127{
1128 return CopperLayer( aLayer ).thermal_gap;
1129}
1130
1131
1133{
1134 PAD_SHAPE shape = Shape( aLayer );
1135
1136 if( shape == PAD_SHAPE::CUSTOM )
1137 shape = AnchorShape( aLayer );
1138
1139 return shape == PAD_SHAPE::CIRCLE ? ANGLE_45 : ANGLE_90;
1140}
1141
1142
1144{
1145 if( CopperLayer( aLayer ).thermal_spoke_angle.has_value() )
1146 return CopperLayer( aLayer ).thermal_spoke_angle.value().GetAngle();
1147
1148 return DefaultThermalSpokeAngleForShape( aLayer );
1149}
1150
1151
1153{
1154 CopperLayer( aLayer ).thermal_spoke_angle = aAngle;
1155}
1156
1157
1158std::vector<std::shared_ptr<PCB_SHAPE>>& PADSTACK::Primitives( PCB_LAYER_ID aLayer )
1159{
1160 return CopperLayer( aLayer ).custom_shapes;
1161}
1162
1163
1164const std::vector<std::shared_ptr<PCB_SHAPE>>& PADSTACK::Primitives( PCB_LAYER_ID aLayer ) const
1165{
1166 return CopperLayer( aLayer ).custom_shapes;
1167}
1168
1169
1171{
1172 CopperLayer( aLayer ).custom_shapes.emplace_back( aShape );
1173}
1174
1175
1176void PADSTACK::AppendPrimitives( const std::vector<std::shared_ptr<PCB_SHAPE>>& aList,
1177 PCB_LAYER_ID aLayer )
1178{
1179 std::vector<std::shared_ptr<PCB_SHAPE>>& list = CopperLayer( aLayer ).custom_shapes;
1180
1181 for( const std::shared_ptr<PCB_SHAPE>& item : aList )
1182 {
1183 PCB_SHAPE* new_shape = static_cast<PCB_SHAPE*>( item->Clone() );
1184 new_shape->SetParent( m_parent );
1185 list.emplace_back( new_shape );
1186 }
1187}
1188
1189
1190void PADSTACK::ReplacePrimitives( const std::vector<std::shared_ptr<PCB_SHAPE>>& aList,
1191 PCB_LAYER_ID aLayer )
1192{
1193 ClearPrimitives( aLayer );
1194 AppendPrimitives( aList, aLayer );
1195}
1196
1197
1199{
1200 CopperLayer( aLayer ).custom_shapes.clear();
1201}
1202
1203
1205{
1206 if( m_mode == MODE::NORMAL )
1207 return m_copperProps[ALL_LAYERS];
1208
1209 PCB_LAYER_ID key = aLayer;
1210
1212 {
1213 if( IsFrontLayer( aLayer ) )
1214 key = F_Cu;
1215 else if( IsBackLayer( aLayer ) )
1216 key = B_Cu;
1217 else
1218 key = INNER_LAYERS;
1219 }
1220
1221 // A write for an undefined non-copper layer must land where the readers look. Copper layers
1222 // keep their own entry, which per-layer padstacks rely on.
1223 if( m_mode == MODE::CUSTOM && IsNonCopperLayer( aLayer ) )
1224 return const_cast<COPPER_LAYER_PROPS&>( std::as_const( *this ).CopperLayer( aLayer ) );
1225
1226 // A layer without an entry reads through to another one, so a new entry starts from what was read
1227 const bool readsThrough = m_copperProps.contains( ALL_LAYERS )
1228 || ( m_mode == MODE::CUSTOM && !m_copperProps.empty() );
1229
1230 if( !m_copperProps.contains( key ) && readsThrough )
1231 {
1232 COPPER_LAYER_PROPS inherited = std::as_const( *this ).CopperLayer( aLayer );
1233
1234 // the new layer owns its primitives, as flipping or editing one layer must not change the other
1235 for( std::shared_ptr<PCB_SHAPE>& shape : inherited.custom_shapes )
1236 {
1237 shape.reset( static_cast<PCB_SHAPE*>( shape->Clone() ) );
1238 shape->SetParent( m_parent );
1239 }
1240
1241 return m_copperProps.emplace( key, std::move( inherited ) ).first->second;
1242 }
1243
1244 return m_copperProps[key];
1245}
1246
1247
1249{
1251 {
1252 if( IsFrontLayer( aLayer ) && m_copperProps.contains( F_Cu ) )
1253 return m_copperProps.at( F_Cu );
1254 else if( IsBackLayer( aLayer ) && m_copperProps.contains( B_Cu ) )
1255 return m_copperProps.at( B_Cu );
1256 else if( m_copperProps.contains( INNER_LAYERS ) )
1257 return m_copperProps.at( INNER_LAYERS );
1258 }
1259 else if( m_mode == MODE::CUSTOM )
1260 {
1261 if( IsFrontLayer( aLayer ) && m_copperProps.contains( F_Cu ) )
1262 return m_copperProps.at( F_Cu );
1263 else if( IsBackLayer( aLayer ) && m_copperProps.contains( B_Cu ) )
1264 return m_copperProps.at( B_Cu );
1265
1266 if( m_copperProps.count( aLayer ) )
1267 return m_copperProps.at( aLayer );
1268
1269 // For CUSTOM mode, fall back to ALL_LAYERS if available (e.g. for layers not yet
1270 // explicitly defined). If ALL_LAYERS is also absent (e.g. after a FlipLayers()
1271 // that renamed the only entry from F_Cu to B_Cu), return whatever entry is first.
1272 if( m_copperProps.count( ALL_LAYERS ) )
1273 return m_copperProps.at( ALL_LAYERS );
1274
1275 wxASSERT( !m_copperProps.empty() );
1276 return m_copperProps.begin()->second;
1277 }
1278
1279 return m_copperProps.at( ALL_LAYERS );
1280}
1281
1282
1283void PADSTACK::ForEachUniqueLayer( const std::function<void( PCB_LAYER_ID )>& aMethod ) const
1284{
1285 if( m_mode == MODE::NORMAL )
1286 {
1287 aMethod( ALL_LAYERS );
1288 }
1289 else if( m_mode == MODE::FRONT_INNER_BACK )
1290 {
1291 aMethod( F_Cu );
1292 aMethod( INNER_LAYERS );
1293 aMethod( B_Cu );
1294 }
1295 else
1296 {
1297 for( const auto& [layer, props] : m_copperProps )
1298 aMethod( layer );
1299 }
1300}
1301
1302
1303std::vector<PCB_LAYER_ID> PADSTACK::UniqueLayers() const
1304{
1305 std::vector<PCB_LAYER_ID> layers;
1306
1308 [&]( PCB_LAYER_ID layer )
1309 {
1310 layers.push_back( layer );
1311 } );
1312
1313 return layers;
1314}
1315
1316
1318{
1319 if( m_mode == MODE::NORMAL )
1320 return ALL_LAYERS;
1321
1322 if( m_mode == MODE::FRONT_INNER_BACK || IsNonCopperLayer( aLayer ) )
1323 {
1324 PCB_LAYER_ID candidate;
1325
1326 if( IsFrontLayer( aLayer ) )
1327 candidate = F_Cu;
1328 else if( IsBackLayer( aLayer ) )
1329 candidate = B_Cu;
1330 else
1331 candidate = INNER_LAYERS;
1332
1333 // FRONT_INNER_BACK always has all three sides.
1334 // In CUSTOM mode only return the side if the pad actually defines it.
1335 if( m_mode == MODE::FRONT_INNER_BACK || m_copperProps.count( candidate ) )
1336 return candidate;
1337 }
1338
1339 if( m_copperProps.count( aLayer ) )
1340 return aLayer;
1341
1342 // For CUSTOM mode, if ALL_LAYERS is present use it as the default; otherwise return the
1343 // first available layer (e.g. after FlipLayers renamed ALL_LAYERS from F_Cu to B_Cu).
1344 if( m_copperProps.count( ALL_LAYERS ) )
1345 return ALL_LAYERS;
1346
1347 wxASSERT( !m_copperProps.empty() );
1348 return m_copperProps.begin()->first;
1349}
1350
1351
1353{
1354 LSET layers;
1355
1356 if( m_mode == MODE::NORMAL && aOther.m_mode == MODE::NORMAL )
1357 {
1358 layers.set( ALL_LAYERS );
1359 }
1360 else
1361 {
1363 [&]( PCB_LAYER_ID layer )
1364 {
1365 layers.set( layer );
1366 } );
1367 aOther.ForEachUniqueLayer(
1368 [&]( PCB_LAYER_ID layer )
1369 {
1370 layers.set( layer );
1371 } );
1372 }
1373
1374 return layers;
1375}
1376
1377
1378// Only an oblong drill's narrow axis is cleared all the way round the hole
1379static int effectiveDrillDiameter( const VECTOR2I& aSize )
1380{
1381 return aSize.y > 0 ? std::min( aSize.x, aSize.y ) : aSize.x;
1382}
1383
1384
1385static int surfaceKnockout( const BOARD_STACKUP& aStackup, const PADSTACK::POST_MACHINING_PROPS& aProps,
1386 PCB_LAYER_ID aSurface, PCB_LAYER_ID aLayer )
1387{
1388 if( !aProps.mode.has_value()
1391 || aProps.size <= 0 )
1392 {
1393 return 0;
1394 }
1395
1396 bool tapered = *aProps.mode == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK && aProps.angle > 0;
1397 double tanHalfAngle = tapered ? tan( ( aProps.angle / 10.0 ) * M_PI / 360.0 ) : 0.0;
1398 int depth = aProps.depth;
1399
1400 // A countersink given no depth bottoms out where its taper closes on the drill
1401 if( depth <= 0 && tapered )
1402 depth = static_cast<int>( ( aProps.size / 2.0 ) / tanHalfAngle );
1403
1404 if( depth <= 0 )
1405 return 0;
1406
1407 int layerDist = aStackup.GetLayerDistance( aSurface, aLayer );
1408
1409 if( layerDist >= depth )
1410 return 0;
1411
1412 return std::max( 0, aProps.size - static_cast<int>( 2.0 * layerDist * tanHalfAngle ) );
1413}
1414
1415
1417{
1418 return std::max( surfaceKnockout( aStackup, m_frontPostMachining, F_Cu, aLayer ),
1419 surfaceKnockout( aStackup, m_backPostMachining, B_Cu, aLayer ) );
1420}
1421
1422
1423int PADSTACK::MachiningKnockout( const BOARD& aBoard, PCB_LAYER_ID aLayer ) const
1424{
1425 if( m_secondaryDrill.size.x <= 0 && m_tertiaryDrill.size.x <= 0
1426 && !m_frontPostMachining.mode.has_value() && !m_backPostMachining.mode.has_value() )
1427 {
1428 return 0;
1429 }
1430
1431 int knockout = PostMachiningKnockout( aBoard.GetDesignSettings().GetStackupDescriptor(), aLayer );
1432
1433 for( const DRILL_PROPS* drill : { &m_secondaryDrill, &m_tertiaryDrill } )
1434 {
1435 if( drill->size.x <= 0 || drill->start == UNDEFINED_LAYER || drill->end == UNDEFINED_LAYER )
1436 continue;
1437
1438 // An off-stack endpoint would widen the span onto layers the drill never reaches
1439 if( !aBoard.IsLayerEnabled( drill->start ) || !aBoard.IsLayerEnabled( drill->end ) )
1440 continue;
1441
1442 // Contains honours copper Z-order; comparing raw PCB_LAYER_ID values instead puts B_Cu
1443 // above the inner layers and mis-spans any bottom-anchored backdrill
1444 if( LAYER_RANGE::Contains( drill->start, drill->end, aLayer ) )
1445 knockout = std::max( knockout, effectiveDrillDiameter( drill->size ) );
1446 }
1447
1448 return knockout;
1449}
1450
1451
1453{
1454 int maxHoleSize = Drill().size.x;
1455
1458
1461 {
1462 maxHoleSize = std::max( maxHoleSize, frontPM.size );
1463 }
1464
1467 {
1468 maxHoleSize = std::max( maxHoleSize, backPM.size );
1469 }
1470
1471 const PADSTACK::DRILL_PROPS& secondaryDrill = SecondaryDrill();
1472 const PADSTACK::DRILL_PROPS& tertiaryDrill = TertiaryDrill();
1473
1474 if( secondaryDrill.start != UNDEFINED_LAYER && secondaryDrill.end != UNDEFINED_LAYER )
1475 maxHoleSize = std::max( maxHoleSize, secondaryDrill.size.x );
1476
1477 if( tertiaryDrill.start != UNDEFINED_LAYER && tertiaryDrill.end != UNDEFINED_LAYER )
1478 maxHoleSize = std::max( maxHoleSize, tertiaryDrill.size.x );
1479
1480 return maxHoleSize;
1481}
1482
1483
1484std::optional<bool> PADSTACK::IsTented( PCB_LAYER_ID aSide ) const
1485{
1486 if( IsFrontLayer( aSide ) )
1488 else if( IsBackLayer( aSide ) )
1490 else
1491 return std::nullopt;
1492}
1493
1494
1495std::optional<bool> PADSTACK::IsCovered( PCB_LAYER_ID aSide ) const
1496{
1497 if( IsFrontLayer( aSide ) )
1499 else if( IsBackLayer( aSide ) )
1501 else
1502 return std::nullopt;
1503}
1504
1505
1506std::optional<bool> PADSTACK::IsPlugged( PCB_LAYER_ID aSide ) const
1507{
1508 if( IsFrontLayer( aSide ) )
1510 else if( IsBackLayer( aSide ) )
1512 else
1513 return std::nullopt;
1514}
1515
1516
1517std::optional<bool> PADSTACK::IsCapped() const
1518{
1519 return m_drill.is_capped;
1520}
1521
1522
1523std::optional<bool> PADSTACK::IsFilled() const
1524{
1525 return m_drill.is_filled;
1526}
1527
1528
1529#define TEST( a, b ) { if( a != b ) return a - b; }
1530
1531
1532int PADSTACK::Compare( const PADSTACK* aLeft, const PADSTACK* aRight )
1533{
1534 int diff;
1535
1536 TEST( (int) aLeft->m_mode, (int) aRight->m_mode );
1537
1538 if( aLeft->m_layerSet != aRight->m_layerSet )
1539 return aLeft->m_layerSet.Seq() < aRight->m_layerSet.Seq();
1540
1541 if( ( diff = wxString( aLeft->CustomName() ).Cmp( aRight->CustomName() ) ) != 0 )
1542 return diff;
1543
1546
1547 if( ( diff = aLeft->m_frontMaskProps.Compare( aRight->m_frontMaskProps ) ) != 0 )
1548 return diff;
1549
1550 if( ( diff = aLeft->m_backMaskProps.Compare( aRight->m_backMaskProps ) ) != 0 )
1551 return diff;
1552
1553 TEST( (int) aLeft->m_unconnectedLayerMode, (int) aRight->m_unconnectedLayerMode );
1554 TEST( (int) aLeft->m_customShapeInZoneMode, (int) aRight->m_customShapeInZoneMode );
1555
1556 if( ( diff = aLeft->m_drill.Compare( aRight->m_drill ) ) != 0 )
1557 return diff;
1558
1559 if( ( diff = aLeft->m_secondaryDrill.Compare( aRight->m_secondaryDrill ) ) != 0 )
1560 return diff;
1561
1562 if( ( diff = aLeft->m_tertiaryDrill.Compare( aRight->m_tertiaryDrill ) ) != 0 )
1563 return diff;
1564
1565 if( ( diff = aLeft->m_frontPostMachining.Compare( aRight->m_frontPostMachining ) ) != 0 )
1566 return diff;
1567
1568 if( ( diff = aLeft->m_backPostMachining.Compare( aRight->m_backPostMachining ) ) != 0 )
1569 return diff;
1570
1571 aLeft->ForEachUniqueLayer(
1572 [&]( PCB_LAYER_ID aLayer )
1573 {
1574 if( diff != 0 ) // we want to return the first non-matching layer
1575 return;
1576
1577 diff = aLeft->CopperLayer( aLayer ).Compare( aRight->CopperLayer( aLayer ) );
1578 } );
1579
1580 if( diff != 0 )
1581 return diff;
1582
1583 return 0;
1584}
1585
1586
1588{
1589 return m_copperProps.count( aLayer ) > 0;
1590}
1591
1592
1593double PADSTACK::Similarity( const PADSTACK& aOther ) const
1594{
1595 double similarity = 1.0;
1596
1597 if( m_mode != aOther.m_mode )
1598 similarity *= 0.9;
1599
1600 if( m_layerSet != aOther.m_layerSet )
1601 similarity *= 0.9;
1602
1603 if( CustomName() != aOther.CustomName() )
1604 similarity *= 0.9;
1605
1606 if( m_orientation != aOther.m_orientation )
1607 similarity *= 0.9;
1608
1609 if( m_frontMaskProps != aOther.m_frontMaskProps )
1610 similarity *= 0.9;
1611
1612 if( m_backMaskProps != aOther.m_backMaskProps )
1613 similarity *= 0.9;
1614
1616 similarity *= 0.9;
1617
1619 similarity *= 0.9;
1620
1621 if( m_drill != aOther.m_drill )
1622 similarity *= 0.9;
1623
1624 if( m_secondaryDrill != aOther.m_secondaryDrill )
1625 similarity *= 0.9;
1626
1627 if( m_tertiaryDrill != aOther.m_tertiaryDrill )
1628 similarity *= 0.9;
1629
1631 similarity *= 0.9;
1632
1634 similarity *= 0.9;
1635
1637 [&]( PCB_LAYER_ID aLayer )
1638 {
1639 similarity *= CopperLayer( aLayer ).Similarity( aOther.CopperLayer( aLayer ) );
1640 } );
1641
1642 return similarity;
1643}
1644
1645
1647{
1648 auto flipLayer = [aBoard]( PCB_LAYER_ID aLayer )
1649 {
1650 return aBoard ? aBoard->FlipLayer( aLayer ) : ::FlipLayer( aLayer );
1651 };
1652
1654 {
1655 std::unordered_map<PCB_LAYER_ID, COPPER_LAYER_PROPS> oldCopperProps = m_copperProps;
1656 m_copperProps.clear();
1657
1658 m_copperProps[flipLayer( F_Cu )] = oldCopperProps[F_Cu];
1659 m_copperProps[INNER_LAYERS] = oldCopperProps[INNER_LAYERS];
1660 m_copperProps[flipLayer( B_Cu )] = oldCopperProps[B_Cu];
1661 }
1662 else if( m_mode == MODE::CUSTOM )
1663 {
1664 std::unordered_map<PCB_LAYER_ID, COPPER_LAYER_PROPS> oldCopperProps = m_copperProps;
1665 m_copperProps.clear();
1666
1667 for( const auto& [layer, props] : oldCopperProps )
1668 m_copperProps[flipLayer( layer )] = props;
1669 }
1670
1671 std::swap( m_frontMaskProps, m_backMaskProps );
1672
1673 m_drill.start = flipLayer( m_drill.start );
1674 m_drill.end = flipLayer( m_drill.end );
1675
1676 m_secondaryDrill.start = flipLayer( m_secondaryDrill.start );
1677 m_secondaryDrill.end = flipLayer( m_secondaryDrill.end );
1678
1679 m_tertiaryDrill.start = flipLayer( m_tertiaryDrill.start );
1680 m_tertiaryDrill.end = flipLayer( m_tertiaryDrill.end );
1681
1683}
1684
1685
1687{
1688 return m_drill.start;
1689}
1690
1691
1693{
1694 return m_drill.end;
1695}
1696
1697
1698wxString PADSTACK::Name() const
1699{
1700 return CustomName();
1701}
1702
1703
1704const wxChar* PADSTACK::CustomName() const
1705{
1706 if( m_customName )
1707 return m_customName->wx_str();
1708
1709 return wxEmptyString;
1710}
1711
1712
1713void PADSTACK::SetCustomName( const wxString& aCustomName )
1714{
1715 if( aCustomName.IsEmpty() )
1716 {
1717 m_customName.reset();
1718 }
1719 else if( m_customName )
1720 {
1721 *m_customName = aCustomName;
1722 }
1723 else
1724 {
1725 m_customName = std::make_unique<wxString>( aCustomName );
1726 }
1727}
1728
1729
1733 size( 0, 0 ),
1734 offset( 0, 0 ),
1736 chamfered_rect_ratio( 0.0 ),
1738 trapezoid_delta_size( 0, 0 )
1739{
1740}
1741
1742
1744{
1745 return shape == aOther.shape &&
1746 anchor_shape == aOther.anchor_shape &&
1747 size == aOther.size &&
1748 offset == aOther.offset &&
1753}
1754
1755
1757{
1758 TEST( (int) shape, (int) aOther.shape );
1759 TEST( (int) anchor_shape, (int) aOther.anchor_shape );
1760 TEST( size.x, aOther.size.x );
1761
1763 TEST( size.y, aOther.size.y );
1764
1765 TEST( offset.x, aOther.offset.x );
1766 TEST( offset.y, aOther.offset.y );
1767
1768 if( abs( round_rect_radius_ratio - aOther.round_rect_radius_ratio ) > 0.0001 )
1769 return round_rect_radius_ratio > aOther.round_rect_radius_ratio ? 1 : -1;
1770
1771 if( abs( chamfered_rect_ratio - aOther.chamfered_rect_ratio ) > 0.0001 )
1772 return chamfered_rect_ratio > aOther.chamfered_rect_ratio ? 1 : -1;
1773
1775
1776 return 0;
1777}
1778
1779
1781{
1782 if( !( shape == aOther.shape ) ) return false;
1783 if( zone_connection != aOther.zone_connection ) return false;
1784 if( thermal_spoke_width != aOther.thermal_spoke_width ) return false;
1785 if( thermal_spoke_angle != aOther.thermal_spoke_angle ) return false;
1786 if( thermal_gap != aOther.thermal_gap ) return false;
1787 if( clearance != aOther.clearance ) return false;
1788
1789 if( custom_shapes.size() != aOther.custom_shapes.size() ) return false;
1790
1791 for( size_t ii = 0; ii < custom_shapes.size(); ++ii )
1792 {
1793 if( !( *custom_shapes[ii] == *aOther.custom_shapes[ii] ) )
1794 return false;
1795 }
1796
1797 return true;
1798}
1799
1800
1802{
1803 double similarity = 1.0;
1804
1805 if( shape != aOther.shape )
1806 similarity *= 0.5;
1807
1808 if( zone_connection != aOther.zone_connection )
1809 similarity *= 0.9;
1810
1812 similarity *= 0.9;
1813
1815 similarity *= 0.9;
1816
1817 if( thermal_gap != aOther.thermal_gap )
1818 similarity *= 0.9;
1819
1820 if( clearance != aOther.clearance )
1821 similarity *= 0.9;
1822
1823 if( custom_shapes != aOther.custom_shapes )
1824 similarity *= 0.5;
1825
1826 return similarity;
1827}
1828
1829
1830#define TEST_OPT( a, b, v ) \
1831 { \
1832 if( a.has_value() != b.has_value() ) \
1833 return a.has_value() - b.has_value(); \
1834 if( (int) a.value_or( v ) - (int) b.value_or( v ) != 0 ) \
1835 return (int) a.value_or( v ) - (int) b.value_or( v ); \
1836 }
1837
1838#define TEST_OPT_ORIENTATION( a, b, v ) \
1839 { \
1840 if( a.has_value() != b.has_value() ) \
1841 return a.has_value() - b.has_value(); \
1842 const EDA_ANGLE aVal = a.value_or( EDA_ORIENTATION( v ) ).GetAngle(); \
1843 const EDA_ANGLE bVal = b.value_or( EDA_ORIENTATION( v ) ).GetAngle(); \
1844 if( abs( aVal.AsDegrees() - bVal.AsDegrees() ) > 0.001 ) \
1845 return aVal.AsDegrees() > bVal.AsDegrees() ? 1 : -1; \
1846 }
1847
1848
1850{
1851 int diff;
1852
1853 if( ( diff = shape.Compare( aOther.shape ) ) != 0 )
1854 return diff;
1855
1859 TEST_OPT( thermal_gap, aOther.thermal_gap, 0 );
1860 TEST_OPT( clearance, aOther.clearance, 0 );
1861
1862 if( ( diff = (int) custom_shapes.size() - (int) aOther.custom_shapes.size() ) != 0 )
1863 return diff;
1864
1865 for( int ii = 0; ii < (int) custom_shapes.size(); ++ii )
1866 {
1867 if( ( diff = custom_shapes[ii]->Compare( aOther.custom_shapes[ii].get() ) ) != 0 )
1868 return diff;
1869 }
1870
1871 return 0;
1872}
1873
1874
1885
1886
1888{
1891
1892 if( solder_paste_margin_ratio.has_value() != aOther.solder_paste_margin_ratio.has_value() )
1893 return solder_paste_margin_ratio.has_value() - aOther.solder_paste_margin_ratio.has_value();
1894 if( abs( solder_paste_margin_ratio.value_or( 0.0 ) - aOther.solder_paste_margin_ratio.value_or( 0.0 ) ) > 0.0001 )
1895 return solder_paste_margin_ratio.value_or( 0.0 ) > aOther.solder_paste_margin_ratio.value_or( 0.0 ) ? 1 : -1;
1896
1897 TEST_OPT( has_solder_mask, aOther.has_solder_mask, false );
1898 TEST_OPT( has_solder_paste, aOther.has_solder_paste, false );
1899 TEST_OPT( has_covering, aOther.has_covering, false );
1900 TEST_OPT( has_plugging, aOther.has_plugging, false );
1901
1902 return 0;
1903}
1904
1905
1907{
1908 return size == aOther.size &&
1909 shape == aOther.shape &&
1910 start == aOther.start &&
1911 end == aOther.end &&
1912 is_filled == aOther.is_filled &&
1913 is_capped == aOther.is_capped;
1914}
1915
1916
1918{
1919 TEST( (int) shape, (int) aOther.shape );
1920
1921 TEST( size.x, aOther.size.x );
1922
1924 TEST( size.y, aOther.size.y );
1925
1926 TEST( (int) start, (int) aOther.start );
1927 TEST( (int) end, (int) aOther.end );
1928
1929 TEST_OPT( is_filled, aOther.is_filled, false );
1930 TEST_OPT( is_capped, aOther.is_capped, false );
1931
1932 return 0;
1933}
1934
1935
1937{
1938 return mode == aOther.mode &&
1939 size == aOther.size &&
1940 depth == aOther.depth &&
1941 angle == aOther.angle;
1942}
1943
1944
1946{
1948 TEST( size, aOther.size );
1949 TEST( depth, aOther.depth );
1950 TEST( angle, aOther.angle );
1951
1952 return 0;
1953}
1954
1955
1957{
1958 m_mode = aMode;
1959}
KICOMMON_API types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICOMMON_API KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:56
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
BASE_SET & set(size_t pos)
Definition base_set.h:126
BOARD_STACKUP & GetStackupDescriptor()
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
Manage layers needed to make a physical board.
int GetLayerDistance(PCB_LAYER_ID aFirstLayer, PCB_LAYER_ID aSecondLayer) const
Calculate the distance (height) between the two given copper layers.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
bool IsLayerEnabled(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition board.cpp:1229
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayer) const
Definition board.cpp:1148
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
int AsTenthsOfADegree() const
Definition eda_angle.h:117
double AsDegrees() const
Definition eda_angle.h:115
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
EDA_ANGLE GetAngle() const
Definition eda_angle.h:557
static bool Contains(int aStart_layer, int aEnd_layer, int aTest_layer)
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition lset.cpp:309
std::optional< bool > IsFilled() const
bool operator==(const PADSTACK &aOther) const
Definition padstack.cpp:135
std::optional< int > & Clearance(PCB_LAYER_ID aLayer=F_Cu)
void AddPrimitive(PCB_SHAPE *aShape, PCB_LAYER_ID aLayer)
Adds a custom shape primitive to the padstack.
void ReplacePrimitives(const std::vector< std::shared_ptr< PCB_SHAPE > > &aPrimitivesList, PCB_LAYER_ID aLayer)
Clears the existing primitive list (freeing the owned shapes) and adds copies of the given shapes to ...
void SetBackdrillMode(BACKDRILL_MODE aMode)
Definition padstack.cpp:558
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition padstack.cpp:475
MASK_LAYER_PROPS & FrontOuterLayers()
Definition padstack.h:410
double Similarity(const PADSTACK &aOther) const
Return a measure of how likely the other object is to represent the same object.
int RoundRectRadius(PCB_LAYER_ID aLayer) const
Definition padstack.cpp:971
void SetDrillShape(PAD_DRILL_SHAPE aShape)
Definition padstack.cpp:911
int GetMaxHoleSize() const
std::optional< double > & SolderPasteMarginRatio(PCB_LAYER_ID aLayer=F_Cu)
void SetBackdrillSize(bool aTop, std::optional< int > aSize)
Definition padstack.cpp:595
DRILL_PROPS m_drill
!
Definition padstack.h:614
void ForEachUniqueLayer(const std::function< void(PCB_LAYER_ID)> &aMethod) const
Runs the given callable for each active unique copper layer in this padstack, meaning F_Cu for MODE::...
void SetThermalSpokeAngle(EDA_ANGLE aAngle, PCB_LAYER_ID aLayer=F_Cu)
void SetRoundRectRadiusRatio(double aRatio, PCB_LAYER_ID aLayer)
Definition padstack.cpp:965
UNCONNECTED_LAYER_MODE m_unconnectedLayerMode
Definition padstack.h:603
void ClearPrimitives(PCB_LAYER_ID aLayer)
void SetUnconnectedLayerMode(UNCONNECTED_LAYER_MODE aMode)
Definition padstack.h:405
void SetCustomName(const wxString &aCustomName)
bool HasExplicitDefinitionForLayer(PCB_LAYER_ID aLayer) const
Check if the padstack has an explicit definition for the given layer.
std::optional< bool > IsTented(PCB_LAYER_ID aSide) const
Checks if this padstack is tented (covered in soldermask) on the given side.
void SetMode(MODE aMode)
int MachiningKnockout(const BOARD &aBoard, PCB_LAYER_ID aLayer) const
Get the diameter of copper removed from aLayer by backdrilling or post-machining.
std::optional< int > & ThermalSpokeWidth(PCB_LAYER_ID aLayer=F_Cu)
std::optional< int > & SolderPasteMargin(PCB_LAYER_ID aLayer=F_Cu)
void FlipLayers(BOARD *aBoard)
Flips the padstack layers in the case that the pad's parent footprint is flipped to the other side of...
POST_MACHINING_PROPS m_backPostMachining
Definition padstack.h:623
std::optional< int > & SolderMaskMargin(PCB_LAYER_ID aLayer=F_Cu)
const DRILL_PROPS * findBackdrillDrill(bool aTop) const
Return the drill slot holding the top (aTop true) or bottom backdrill, identified by its start layer ...
Definition padstack.cpp:490
void SetChamferRatio(double aRatio, PCB_LAYER_ID aLayer)
Definition padstack.cpp:994
PCB_LAYER_ID EffectiveLayerFor(PCB_LAYER_ID aLayer) const
Determines which geometry layer should be used for the given input layer.
PADSTACK & operator=(const PADSTACK &aOther)
Definition padstack.cpp:87
void SetOffset(const VECTOR2I &aOffset, PCB_LAYER_ID aLayer)
Definition padstack.cpp:929
void SetShape(PAD_SHAPE aShape, PCB_LAYER_ID aLayer)
Definition padstack.cpp:899
EDA_ANGLE DefaultThermalSpokeAngleForShape(PCB_LAYER_ID aLayer=F_Cu) const
VECTOR2I & TrapezoidDeltaSize(PCB_LAYER_ID aLayer)
Definition padstack.cpp:947
DRILL_PROPS m_secondaryDrill
! A back-drill, whose side is given by its start layer rather than by which slot it occupies
Definition padstack.h:617
void clearBackdrillSide(bool aTop)
Clear every slot whose start layer marks it as the given backdrill side, so a malformed padstack with...
Definition padstack.cpp:528
VECTOR2I & Offset(PCB_LAYER_ID aLayer)
Definition padstack.cpp:917
MASK_LAYER_PROPS m_backMaskProps
! The overrides applied to back outer technical layers
Definition padstack.h:601
COPPER_LAYER_PROPS & CopperLayer(PCB_LAYER_ID aLayer)
EDA_ANGLE ThermalSpokeAngle(PCB_LAYER_ID aLayer=F_Cu) const
CUSTOM_SHAPE_ZONE_MODE m_customShapeInZoneMode
How to build the custom shape in zone, to create the clearance area: CUSTOM_SHAPE_ZONE_MODE::OUTLINE ...
Definition padstack.h:610
bool unpackCopperLayer(const kiapi::board::types::PadStackLayer &aProto)
Definition padstack.cpp:196
PAD_DRILL_SHAPE DrillShape() const
Definition padstack.cpp:905
void SetChamferPositions(int aPositions, PCB_LAYER_ID aLayer)
POST_MACHINING_PROPS & FrontPostMachining()
Definition padstack.h:372
DRILL_PROPS m_tertiaryDrill
! The other back-drill; see findBackdrillDrill() for why either slot may hold either side
Definition padstack.h:620
void SetRoundRectRadius(double aRadius, PCB_LAYER_ID aLayer)
Definition padstack.cpp:978
std::optional< bool > IsPlugged(PCB_LAYER_ID aSide) const
LSET RelevantShapeLayers(const PADSTACK &aOther) const
Returns the set of layers that must be considered if checking one padstack against another.
std::optional< int > & ThermalGap(PCB_LAYER_ID aLayer=F_Cu)
DRILL_PROPS & TertiaryDrill()
Definition padstack.h:369
PAD_SHAPE Shape(PCB_LAYER_ID aLayer) const
Definition padstack.cpp:893
DRILL_PROPS & Drill()
Definition padstack.h:363
void SetAnchorShape(PAD_SHAPE aShape, PCB_LAYER_ID aLayer)
Definition padstack.cpp:941
EDA_ORIENTATION m_orientation
! The rotation of the pad relative to an outer reference frame
Definition padstack.h:593
BOARD_ITEM * m_parent
! The BOARD_ITEM this PADSTACK belongs to; will be used as the parent for owned shapes
Definition padstack.h:581
PADSTACK(BOARD_ITEM *aParent)
Definition padstack.cpp:46
std::optional< bool > IsCapped() const
std::vector< PCB_LAYER_ID > UniqueLayers() const
void SetBackdrillEndLayer(bool aTop, PCB_LAYER_ID aLayer)
Definition padstack.cpp:620
LSET m_layerSet
! The board layers that this padstack is active on
Definition padstack.h:587
std::optional< int > GetBackdrillSize(bool aTop) const
Definition padstack.cpp:586
std::unordered_map< PCB_LAYER_ID, COPPER_LAYER_PROPS > m_copperProps
Definition padstack.h:595
BACKDRILL_MODE GetBackdrillMode() const
Definition padstack.cpp:540
static int Compare(const PADSTACK *aPadstackRef, const PADSTACK *aPadstackCmp)
Compare two padstacks and return 0 if they are equal.
PCB_LAYER_ID EndLayer() const
std::optional< bool > IsCovered(PCB_LAYER_ID aSide) const
DRILL_PROPS & backdrillWriteSlot(bool aTop)
Return the slot to write a backdrill side into, reusing the slot already holding that side or otherwi...
Definition padstack.cpp:510
int & ChamferPositions(PCB_LAYER_ID aLayer)
MASK_LAYER_PROPS m_frontMaskProps
! The overrides applied to front outer technical layers
Definition padstack.h:598
int PostMachiningKnockout(const BOARD_STACKUP &aStackup, PCB_LAYER_ID aLayer) const
Get the diameter the front and back post-machining operations cut into aLayer.
const VECTOR2I & Size(PCB_LAYER_ID aLayer) const
Definition padstack.cpp:887
MODE
! Copper geometry mode: controls how many unique copper layer shapes this padstack has
Definition padstack.h:174
@ NORMAL
Shape is the same on all layers.
Definition padstack.h:175
@ CUSTOM
Shapes can be defined on arbitrary layers.
Definition padstack.h:177
@ FRONT_INNER_BACK
Up to three shapes can be defined (F_Cu, inner copper layers, B_Cu)
Definition padstack.h:176
void AppendPrimitives(const std::vector< std::shared_ptr< PCB_SHAPE > > &aPrimitivesList, PCB_LAYER_ID aLayer)
Appends a copy of each shape in the given list to this padstack's custom shape list.
DRILL_PROPS & SecondaryDrill()
Definition padstack.h:366
double RoundRectRadiusRatio(PCB_LAYER_ID aLayer) const
Definition padstack.cpp:959
PCB_LAYER_ID GetBackdrillEndLayer(bool aTop) const
Definition padstack.cpp:611
PCB_LAYER_ID StartLayer() const
POST_MACHINING_PROPS & BackPostMachining()
Definition padstack.h:375
POST_MACHINING_PROPS m_frontPostMachining
Definition padstack.h:622
std::unique_ptr< wxString > m_customName
! An override for the IPC-7351 padstack name
Definition padstack.h:590
PAD_SHAPE AnchorShape(PCB_LAYER_ID aLayer) const
Definition padstack.cpp:935
MASK_LAYER_PROPS & BackOuterLayers()
Definition padstack.h:413
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition padstack.cpp:863
wxString Name() const
! Returns the name of this padstack in IPC-7351 format
void SetSize(const VECTOR2I &aSize, PCB_LAYER_ID aLayer)
Definition padstack.cpp:873
void SetOrientation(const EDA_ANGLE &aAngle)
Definition padstack.h:361
double ChamferRatio(PCB_LAYER_ID aLayer) const
Definition padstack.cpp:988
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:184
const wxChar * CustomName() const
static constexpr PCB_LAYER_ID INNER_LAYERS
! The layer identifier to use for "inner layers" on top/inner/bottom padstacks
Definition padstack.h:187
void SetLayerSet(const LSET &aSet)
Definition padstack.h:338
std::optional< ZONE_CONNECTION > & ZoneConnection(PCB_LAYER_ID aLayer=F_Cu)
@ NORMAL
Padstack for a footprint pad.
Definition padstack.h:167
MODE m_mode
! The copper layer variation mode this padstack is in
Definition padstack.h:584
std::vector< std::shared_ptr< PCB_SHAPE > > & Primitives(PCB_LAYER_ID aLayer)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:474
@ DEGREES_T
Definition eda_angle.h:30
static constexpr EDA_ANGLE ANGLE_45
Definition eda_angle.h:473
#define TEST(a, b)
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition layer_id.cpp:182
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
Definition layer_ids.h:847
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
Definition layer_ids.h:870
bool IsNonCopperLayer(int aLayerId)
Test whether a layer is a non copper layer.
Definition layer_ids.h:777
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ B_Cu
Definition layer_ids.h:61
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ F_Cu
Definition layer_ids.h:60
This file contains miscellaneous commonly used macros and functions.
void PackLayerSet(google::protobuf::RepeatedField< int > &aOutput, const LSET &aLayerSet)
LSET UnpackLayerSet(const google::protobuf::RepeatedField< int > &aProtoLayerSet)
KICOMMON_API int UnpackDistance(const types::Distance &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackDistance(types::Distance &aOutput, int aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
#define TEST_OPT_ORIENTATION(a, b, v)
static int effectiveDrillDiameter(const VECTOR2I &aSize)
#define TEST_OPT(a, b, v)
static int surfaceKnockout(const BOARD_STACKUP &aStackup, const PADSTACK::POST_MACHINING_PROPS &aProps, PCB_LAYER_ID aSurface, PCB_LAYER_ID aLayer)
PAD_DRILL_POST_MACHINING_MODE
Definition padstack.h:77
PAD_DRILL_SHAPE
The set of pad drill shapes, used with PAD::{Set,Get}DrillShape()
Definition padstack.h:70
CUSTOM_SHAPE_ZONE_MODE
Definition padstack.h:141
BACKDRILL_MODE
Definition padstack.h:85
PAD_SHAPE
The set of pad shapes, used with PAD::{Set,Get}Shape()
Definition padstack.h:53
@ ROUNDRECT
Definition padstack.h:58
@ TRAPEZOID
Definition padstack.h:57
@ RECTANGLE
Definition padstack.h:55
UNCONNECTED_LAYER_MODE
Definition padstack.h:132
#define IMPLEMENT_ENUM_TO_WXANY(type)
Definition property.h:916
The features of a padstack that can vary between copper layers All parameters are optional; leaving t...
Definition padstack.h:234
double Similarity(const COPPER_LAYER_PROPS &aOther) const
std::optional< ZONE_CONNECTION > zone_connection
Definition padstack.h:236
int Compare(const COPPER_LAYER_PROPS &aOther) const
std::optional< int > thermal_spoke_width
Definition padstack.h:237
std::vector< std::shared_ptr< PCB_SHAPE > > custom_shapes
Definition padstack.h:246
bool operator==(const COPPER_LAYER_PROPS &aOther) const
std::optional< EDA_ORIENTATION > thermal_spoke_angle
Definition padstack.h:238
std::optional< int > clearance
Definition padstack.h:240
std::optional< int > thermal_gap
Definition padstack.h:239
The properties of a padstack drill.
Definition padstack.h:277
PCB_LAYER_ID start
Definition padstack.h:280
PCB_LAYER_ID end
Definition padstack.h:281
bool operator==(const DRILL_PROPS &aOther) const
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
PAD_DRILL_SHAPE shape
Definition padstack.h:279
int Compare(const DRILL_PROPS &aOther) const
The features of a padstack that can vary on outer layers.
Definition padstack.h:259
bool operator==(const MASK_LAYER_PROPS &aOther) const
std::optional< int > solder_mask_margin
Definition padstack.h:260
int Compare(const MASK_LAYER_PROPS &aOther) const
std::optional< bool > has_covering
True if the pad on this side should have covering.
Definition padstack.h:266
std::optional< int > solder_paste_margin
Definition padstack.h:261
std::optional< double > solder_paste_margin_ratio
Definition padstack.h:262
std::optional< bool > has_solder_mask
True if this outer layer has mask (is not tented)
Definition padstack.h:264
std::optional< bool > has_solder_paste
True if this outer layer has solder paste.
Definition padstack.h:265
std::optional< bool > has_plugging
True if the drill hole should be plugged on this side.
Definition padstack.h:267
std::optional< PAD_DRILL_POST_MACHINING_MODE > mode
Definition padstack.h:292
bool operator==(const POST_MACHINING_PROPS &aOther) const
int Compare(const POST_MACHINING_PROPS &aOther) const
VECTOR2I trapezoid_delta_size
Delta for PAD_SHAPE::TRAPEZOID; half the delta squeezes one end and half expands the other.
Definition padstack.h:214
int Compare(const SHAPE_PROPS &aOther) const
VECTOR2I offset
Offset of the shape center from the pad center.
Definition padstack.h:204
bool operator==(const SHAPE_PROPS &aOther) const
VECTOR2I size
Size of the shape, or of the anchor pad for custom shape pads.
Definition padstack.h:195
double chamfered_rect_ratio
Size of chamfer: ratio of smallest of X,Y size.
Definition padstack.h:207
double round_rect_radius_ratio
Definition padstack.h:206
PAD_SHAPE shape
Shape of the pad.
Definition padstack.h:193
PAD_SHAPE anchor_shape
Shape of the anchor when shape == PAD_SHAPE::CUSTOM.
Definition padstack.h:194
#define M_PI
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
@ NONE
Pads are not covered.
Definition zones.h:45