1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356
|
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2024 Jon Evans <jon@craftyjon.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <convert_basic_shapes_to_polygon.h> // RECT_CHAMFER_POSITIONS
#include "padstack.h"
#include <api/api_enums.h>
#include <api/api_utils.h>
#include <api/api_pcb_utils.h>
#include <api/board/board_types.pb.h>
#include <layer_range.h>
#include <macros.h>
#include <magic_enum.hpp>
#include <pad.h>
#include <pcb_shape.h>
PADSTACK::PADSTACK( BOARD_ITEM* aParent ) :
m_parent( aParent ),
m_mode( MODE::NORMAL ),
m_orientation( ANGLE_0 ),
m_unconnectedLayerMode( UNCONNECTED_LAYER_MODE::KEEP_ALL ),
m_customShapeInZoneMode( CUSTOM_SHAPE_ZONE_MODE::OUTLINE )
{
m_copperProps[PADSTACK::ALL_LAYERS].shape = SHAPE_PROPS();
m_copperProps[PADSTACK::ALL_LAYERS].zone_connection = ZONE_CONNECTION::INHERITED;
m_copperProps[PADSTACK::ALL_LAYERS].thermal_spoke_width = std::nullopt;
m_copperProps[PADSTACK::ALL_LAYERS].thermal_spoke_angle = ANGLE_45;
m_copperProps[PADSTACK::ALL_LAYERS].thermal_gap = std::nullopt;
m_drill.shape = PAD_DRILL_SHAPE::CIRCLE;
m_drill.start = F_Cu;
m_drill.end = B_Cu;
m_secondaryDrill.shape = PAD_DRILL_SHAPE::UNDEFINED;
m_secondaryDrill.start = UNDEFINED_LAYER;
m_secondaryDrill.end = UNDEFINED_LAYER;
}
PADSTACK::PADSTACK( const PADSTACK& aOther )
{
m_parent = aOther.m_parent;
*this = aOther;
ForEachUniqueLayer(
[&]( PCB_LAYER_ID aLayer )
{
for( std::shared_ptr<PCB_SHAPE>& shape : CopperLayer( aLayer ).custom_shapes )
shape->SetParent( m_parent );
} );
}
PADSTACK& PADSTACK::operator=( const PADSTACK &aOther )
{
// NOTE: m_parent is not copied from operator=, because this operator is commonly used to
// update the padstack properties, and such an update must not change the parent PAD to point to
// the parent of some different padstack.
m_mode = aOther.m_mode;
m_layerSet = aOther.m_layerSet;
m_customName = aOther.m_customName;
m_orientation = aOther.m_orientation;
m_copperProps = aOther.m_copperProps;
m_frontMaskProps = aOther.m_frontMaskProps;
m_backMaskProps = aOther.m_backMaskProps;
m_unconnectedLayerMode = aOther.m_unconnectedLayerMode;
m_customShapeInZoneMode = aOther.m_customShapeInZoneMode;
m_drill = aOther.m_drill;
m_secondaryDrill = aOther.m_secondaryDrill;
// Data consistency enforcement logic that used to live in the pad properties dialog
// TODO(JE) Should these move to individual property setters, so that they are always
// enforced even through the properties panel and API?
ForEachUniqueLayer(
[&]( PCB_LAYER_ID aLayer )
{
PAD_SHAPE shape = Shape( aLayer );
// Make sure leftover primitives don't stick around
ClearPrimitives( aLayer );
// For custom pad shape, duplicate primitives of the pad to copy
if( shape == PAD_SHAPE::CUSTOM )
ReplacePrimitives( aOther.Primitives( aLayer ), aLayer );
// rounded rect pads with radius ratio = 0 are in fact rect pads.
// So set the right shape (and perhaps issues with a radius = 0)
if( shape == PAD_SHAPE::ROUNDRECT && RoundRectRadiusRatio( aLayer ) == 0.0 )
SetShape( PAD_SHAPE::RECTANGLE, aLayer );
} );
return *this;
}
bool PADSTACK::operator==( const PADSTACK& aOther ) const
{
if( m_mode != aOther.m_mode )
return false;
if( m_layerSet != aOther.m_layerSet )
return false;
if( m_customName != aOther.m_customName )
return false;
if( m_orientation != aOther.m_orientation )
return false;
if( m_frontMaskProps != aOther.m_frontMaskProps )
return false;
if( m_backMaskProps != aOther.m_backMaskProps )
return false;
if( m_unconnectedLayerMode != aOther.m_unconnectedLayerMode )
return false;
if( m_customShapeInZoneMode != aOther.m_customShapeInZoneMode )
return false;
if( m_drill != aOther.m_drill )
return false;
if( m_secondaryDrill != aOther.m_secondaryDrill )
return false;
bool copperMatches = true;
ForEachUniqueLayer(
[&]( PCB_LAYER_ID aLayer )
{
if( CopperLayer( aLayer ) != aOther.CopperLayer( aLayer ) )
copperMatches = false;
} );
return copperMatches;
}
bool PADSTACK::unpackCopperLayer( const kiapi::board::types::PadStackLayer& aProto )
{
using namespace kiapi::board::types;
PCB_LAYER_ID layer = FromProtoEnum<PCB_LAYER_ID, BoardLayer>( aProto.layer() );
if( m_mode == MODE::NORMAL && layer != ALL_LAYERS )
return false;
if( m_mode == MODE::FRONT_INNER_BACK && layer != F_Cu && layer != INNER_LAYERS && layer != B_Cu )
return false;
SetSize( kiapi::common::UnpackVector2( aProto.size() ), layer );
SetShape( FromProtoEnum<PAD_SHAPE>( aProto.shape() ), layer );
Offset( layer ) = kiapi::common::UnpackVector2( aProto.offset() );
SetAnchorShape( FromProtoEnum<PAD_SHAPE>( aProto.custom_anchor_shape() ), layer );
SHAPE_PROPS& props = CopperLayer( layer ).shape;
props.chamfered_rect_ratio = aProto.chamfer_ratio();
props.round_rect_radius_ratio = aProto.corner_rounding_ratio();
if( Shape( layer ) == PAD_SHAPE::TRAPEZOID && aProto.has_trapezoid_delta() )
TrapezoidDeltaSize( layer ) = kiapi::common::UnpackVector2( aProto.trapezoid_delta() );
if( aProto.chamfered_corners().top_left() )
props.chamfered_rect_positions |= RECT_CHAMFER_TOP_LEFT;
if( aProto.chamfered_corners().top_right() )
props.chamfered_rect_positions |= RECT_CHAMFER_TOP_RIGHT;
if( aProto.chamfered_corners().bottom_left() )
props.chamfered_rect_positions |= RECT_CHAMFER_BOTTOM_LEFT;
if( aProto.chamfered_corners().bottom_right() )
props.chamfered_rect_positions |= RECT_CHAMFER_BOTTOM_RIGHT;
ClearPrimitives( layer );
google::protobuf::Any a;
for( const BoardGraphicShape& shapeProto : aProto.custom_shapes() )
{
a.PackFrom( shapeProto );
std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( m_parent );
if( shape->Deserialize( a ) )
AddPrimitive( shape.release(), layer );
}
return true;
}
bool PADSTACK::Deserialize( const google::protobuf::Any& aContainer )
{
using namespace kiapi::board::types;
PadStack padstack;
if( !aContainer.UnpackTo( &padstack ) )
return false;
m_mode = FromProtoEnum<MODE>( padstack.type() );
SetLayerSet( kiapi::board::UnpackLayerSet( padstack.layers() ) );
m_orientation = EDA_ANGLE( padstack.angle().value_degrees(), DEGREES_T );
Drill().size = kiapi::common::UnpackVector2( padstack.drill().diameter() );
Drill().start = FromProtoEnum<PCB_LAYER_ID>( padstack.drill().start_layer() );
Drill().end = FromProtoEnum<PCB_LAYER_ID>( padstack.drill().end_layer() );
for( const PadStackLayer& layer : padstack.copper_layers() )
{
if( !unpackCopperLayer( layer ) )
return false;
}
CopperLayer( ALL_LAYERS ).thermal_gap = std::nullopt;
CopperLayer( ALL_LAYERS ).thermal_spoke_width = std::nullopt;
if( padstack.has_zone_settings() )
{
CopperLayer( ALL_LAYERS ).zone_connection =
FromProtoEnum<ZONE_CONNECTION>( padstack.zone_settings().zone_connection() );
if( padstack.zone_settings().has_thermal_spokes() )
{
const ThermalSpokeSettings& thermals = padstack.zone_settings().thermal_spokes();
if( thermals.has_gap() )
CopperLayer( ALL_LAYERS ).thermal_gap = thermals.gap().value_nm();
if( thermals.has_width() )
CopperLayer( ALL_LAYERS ).thermal_spoke_width = thermals.width().value_nm();
SetThermalSpokeAngle( EDA_ANGLE( thermals.angle().value_degrees(), DEGREES_T ), F_Cu );
}
}
else
{
CopperLayer( ALL_LAYERS ).zone_connection = ZONE_CONNECTION::INHERITED;
CopperLayer( ALL_LAYERS ).thermal_spoke_angle = DefaultThermalSpokeAngleForShape( F_Cu );
}
SetUnconnectedLayerMode(
FromProtoEnum<UNCONNECTED_LAYER_MODE>( padstack.unconnected_layer_removal() ) );
auto unpackMask =
[]( const SolderMaskMode& aProto, std::optional<bool>& aDest )
{
switch( aProto )
{
case kiapi::board::types::SMM_MASKED:
aDest = true;
break;
case kiapi::board::types::SMM_UNMASKED:
aDest = false;
break;
default:
case kiapi::board::types::SMM_FROM_DESIGN_RULES:
aDest = std::nullopt;
break;
}
};
unpackMask( padstack.front_outer_layers().solder_mask_mode(),
FrontOuterLayers().has_solder_mask );
unpackMask( padstack.back_outer_layers().solder_mask_mode(),
BackOuterLayers().has_solder_mask );
auto unpackPaste =
[]( const SolderPasteMode& aProto, std::optional<bool>& aDest )
{
switch( aProto )
{
case kiapi::board::types::SPM_PASTE:
aDest = true;
break;
case kiapi::board::types::SPM_NO_PASTE:
aDest = false;
break;
default:
case kiapi::board::types::SPM_FROM_DESIGN_RULES:
aDest = std::nullopt;
break;
}
};
unpackPaste( padstack.front_outer_layers().solder_paste_mode(),
FrontOuterLayers().has_solder_paste );
unpackPaste( padstack.back_outer_layers().solder_paste_mode(),
BackOuterLayers().has_solder_paste );
if( padstack.front_outer_layers().has_solder_mask_settings()
&& padstack.front_outer_layers().solder_mask_settings().has_solder_mask_margin() )
{
FrontOuterLayers().solder_mask_margin =
padstack.front_outer_layers().solder_mask_settings().solder_mask_margin().value_nm();
}
else
{
FrontOuterLayers().solder_mask_margin = std::nullopt;
}
if( padstack.back_outer_layers().has_solder_mask_settings()
&& padstack.back_outer_layers().solder_mask_settings().has_solder_mask_margin() )
{
BackOuterLayers().solder_mask_margin =
padstack.back_outer_layers().solder_mask_settings().solder_mask_margin().value_nm();
}
else
{
BackOuterLayers().solder_mask_margin = std::nullopt;
}
if( padstack.front_outer_layers().has_solder_paste_settings()
&& padstack.front_outer_layers().solder_paste_settings().has_solder_paste_margin() )
{
FrontOuterLayers().solder_paste_margin =
padstack.front_outer_layers().solder_paste_settings().solder_paste_margin().value_nm();
}
else
{
FrontOuterLayers().solder_paste_margin = std::nullopt;
}
if( padstack.back_outer_layers().has_solder_paste_settings()
&& padstack.back_outer_layers().solder_paste_settings().has_solder_paste_margin() )
{
BackOuterLayers().solder_paste_margin =
padstack.back_outer_layers().solder_paste_settings().solder_paste_margin().value_nm();
}
else
{
BackOuterLayers().solder_paste_margin = std::nullopt;
}
if( padstack.front_outer_layers().has_solder_paste_settings()
&& padstack.front_outer_layers().solder_paste_settings().has_solder_paste_margin_ratio() )
{
FrontOuterLayers().solder_paste_margin_ratio =
padstack.front_outer_layers().solder_paste_settings().solder_paste_margin_ratio().value();
}
else
{
FrontOuterLayers().solder_paste_margin_ratio = std::nullopt;
}
if( padstack.back_outer_layers().has_solder_paste_settings()
&& padstack.back_outer_layers().solder_paste_settings().has_solder_paste_margin_ratio() )
{
BackOuterLayers().solder_paste_margin_ratio =
padstack.back_outer_layers().solder_paste_settings().solder_paste_margin_ratio().value();
}
else
{
BackOuterLayers().solder_paste_margin_ratio = std::nullopt;
}
return true;
}
void PADSTACK::packCopperLayer( PCB_LAYER_ID aLayer, kiapi::board::types::PadStack& aProto ) const
{
using namespace kiapi::board::types;
PadStackLayer* stackLayer = aProto.add_copper_layers();
stackLayer->set_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( aLayer ) );
kiapi::common::PackVector2( *stackLayer->mutable_size(), Size( aLayer ) );
kiapi::common::PackVector2( *stackLayer->mutable_offset(), Offset( aLayer ) );
stackLayer->set_shape( ToProtoEnum<PAD_SHAPE, PadStackShape>( Shape( aLayer ) ) );
stackLayer->set_custom_anchor_shape(
ToProtoEnum<PAD_SHAPE, PadStackShape>( AnchorShape( aLayer ) ) );
stackLayer->set_chamfer_ratio( CopperLayer( aLayer ).shape.chamfered_rect_ratio );
stackLayer->set_corner_rounding_ratio( CopperLayer( aLayer ).shape.round_rect_radius_ratio );
if( Shape( aLayer ) == PAD_SHAPE::TRAPEZOID )
{
kiapi::common::PackVector2( *stackLayer->mutable_trapezoid_delta(),
TrapezoidDeltaSize( aLayer ) );
}
google::protobuf::Any a;
for( const std::shared_ptr<PCB_SHAPE>& shape : Primitives( aLayer ) )
{
shape->Serialize( a );
BoardGraphicShape* s = stackLayer->add_custom_shapes();
a.UnpackTo( s );
}
const int& corners = CopperLayer( aLayer ).shape.chamfered_rect_positions;
stackLayer->mutable_chamfered_corners()->set_top_left( corners & RECT_CHAMFER_TOP_LEFT );
stackLayer->mutable_chamfered_corners()->set_top_right( corners & RECT_CHAMFER_TOP_RIGHT );
stackLayer->mutable_chamfered_corners()->set_bottom_left( corners & RECT_CHAMFER_BOTTOM_LEFT );
stackLayer->mutable_chamfered_corners()->set_bottom_right( corners & RECT_CHAMFER_BOTTOM_RIGHT );
}
void PADSTACK::Serialize( google::protobuf::Any& aContainer ) const
{
using namespace kiapi::board::types;
PadStack padstack;
padstack.set_type( ToProtoEnum<MODE, PadStackType>( m_mode ) );
kiapi::board::PackLayerSet( *padstack.mutable_layers(), m_layerSet );
padstack.mutable_angle()->set_value_degrees( m_orientation.AsDegrees() );
DrillProperties* drill = padstack.mutable_drill();
drill->set_start_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( StartLayer() ) );
drill->set_end_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( EndLayer() ) );
kiapi::common::PackVector2( *drill->mutable_diameter(), Drill().size );
ForEachUniqueLayer( [&]( PCB_LAYER_ID aLayer )
{
packCopperLayer( aLayer, padstack );
} );
ZoneConnectionSettings* zoneSettings = padstack.mutable_zone_settings();
ThermalSpokeSettings* thermalSettings = zoneSettings->mutable_thermal_spokes();
if( CopperLayer( ALL_LAYERS ).zone_connection.has_value() )
{
zoneSettings->set_zone_connection( ToProtoEnum<ZONE_CONNECTION, ZoneConnectionStyle>(
*CopperLayer( ALL_LAYERS ).zone_connection ) );
}
if( std::optional<int> width = CopperLayer( ALL_LAYERS ).thermal_spoke_width )
thermalSettings->mutable_width()->set_value_nm( *width );
if( std::optional<int> gap = CopperLayer( ALL_LAYERS ).thermal_gap )
thermalSettings->mutable_gap()->set_value_nm( *gap );
thermalSettings->mutable_angle()->set_value_degrees( ThermalSpokeAngle( F_Cu ).AsDegrees() );
padstack.set_unconnected_layer_removal(
ToProtoEnum<UNCONNECTED_LAYER_MODE, UnconnectedLayerRemoval>( m_unconnectedLayerMode ) );
auto packOptional =
[]<typename ProtoEnum>( const std::optional<bool>& aVal, ProtoEnum aTrueVal,
ProtoEnum aFalseVal, ProtoEnum aNullVal ) -> ProtoEnum
{
if( aVal.has_value() )
return *aVal ? aTrueVal : aFalseVal;
return aNullVal;
};
PadStackOuterLayer* frontOuter = padstack.mutable_front_outer_layers();
PadStackOuterLayer* backOuter = padstack.mutable_back_outer_layers();
frontOuter->set_solder_mask_mode( packOptional( FrontOuterLayers().has_solder_mask,
SMM_MASKED, SMM_UNMASKED,
SMM_FROM_DESIGN_RULES ) );
backOuter->set_solder_mask_mode( packOptional( BackOuterLayers().has_solder_mask,
SMM_MASKED, SMM_UNMASKED,
SMM_FROM_DESIGN_RULES ) );
frontOuter->set_solder_paste_mode( packOptional( FrontOuterLayers().has_solder_paste,
SPM_PASTE, SPM_NO_PASTE,
SPM_FROM_DESIGN_RULES ) );
backOuter->set_solder_paste_mode( packOptional( BackOuterLayers().has_solder_paste,
SPM_PASTE, SPM_NO_PASTE,
SPM_FROM_DESIGN_RULES ) );
if( FrontOuterLayers().solder_mask_margin.has_value() )
{
frontOuter->mutable_solder_mask_settings()->mutable_solder_mask_margin()->set_value_nm(
*FrontOuterLayers().solder_mask_margin );
}
if( BackOuterLayers().solder_mask_margin.has_value() )
{
backOuter->mutable_solder_mask_settings()->mutable_solder_mask_margin()->set_value_nm(
*BackOuterLayers().solder_mask_margin );
}
if( FrontOuterLayers().solder_paste_margin.has_value() )
{
frontOuter->mutable_solder_paste_settings()->mutable_solder_paste_margin()->set_value_nm(
*FrontOuterLayers().solder_paste_margin );
}
if( BackOuterLayers().solder_paste_margin.has_value() )
{
backOuter->mutable_solder_paste_settings()->mutable_solder_paste_margin()->set_value_nm(
*BackOuterLayers().solder_paste_margin );
}
if( FrontOuterLayers().solder_paste_margin_ratio.has_value() )
{
frontOuter->mutable_solder_paste_settings()->mutable_solder_paste_margin_ratio()->set_value(
*FrontOuterLayers().solder_paste_margin_ratio );
}
if( BackOuterLayers().solder_paste_margin_ratio.has_value() )
{
backOuter->mutable_solder_paste_settings()->mutable_solder_paste_margin_ratio()->set_value(
*BackOuterLayers().solder_paste_margin_ratio );
}
aContainer.PackFrom( padstack );
}
int PADSTACK::Compare( const PADSTACK* aPadstackRef, const PADSTACK* aPadstackCmp )
{
int diff;
auto compareCopperProps =
[&]( PCB_LAYER_ID aLayer )
{
if( ( diff = static_cast<int>( aPadstackRef->Shape( aLayer ) ) -
static_cast<int>( aPadstackCmp->Shape( aLayer ) ) ) != 0 )
return diff;
if( ( diff = aPadstackRef->Size( aLayer ).x - aPadstackCmp->Size( aLayer ).x ) != 0 )
return diff;
if( ( diff = aPadstackRef->Size( aLayer ).y - aPadstackCmp->Size( aLayer ).y ) != 0 )
return diff;
if( ( diff = aPadstackRef->Offset( aLayer ).x
- aPadstackCmp->Offset( aLayer ).x ) != 0 )
return diff;
if( ( diff = aPadstackRef->Offset( aLayer ).y
- aPadstackCmp->Offset( aLayer ).y ) != 0 )
return diff;
if( ( diff = aPadstackRef->TrapezoidDeltaSize( aLayer ).x
- aPadstackCmp->TrapezoidDeltaSize( aLayer ).x )
!= 0 )
{
return diff;
}
if( ( diff = aPadstackRef->TrapezoidDeltaSize( aLayer ).y
- aPadstackCmp->TrapezoidDeltaSize( aLayer ).y )
!= 0 )
{
return diff;
}
if( ( diff = aPadstackRef->RoundRectRadiusRatio( aLayer )
- aPadstackCmp->RoundRectRadiusRatio( aLayer ) )
!= 0 )
{
return diff;
}
if( ( diff = aPadstackRef->ChamferPositions( aLayer )
- aPadstackCmp->ChamferPositions( aLayer ) ) != 0 )
return diff;
if( ( diff = aPadstackRef->ChamferRatio( aLayer )
- aPadstackCmp->ChamferRatio( aLayer ) ) != 0 )
return diff;
if( ( diff = static_cast<int>( aPadstackRef->Primitives( aLayer ).size() ) -
static_cast<int>( aPadstackCmp->Primitives( aLayer ).size() ) ) != 0 )
return diff;
// @todo: Compare custom pad primitives for pads that have the same number of primitives
// here. Currently there is no compare function for PCB_SHAPE objects.
return 0;
};
aPadstackRef->ForEachUniqueLayer( compareCopperProps );
if( diff )
return diff;
if( ( diff = static_cast<int>( aPadstackRef->DrillShape() ) -
static_cast<int>( aPadstackCmp->DrillShape() ) ) != 0 )
return diff;
if( ( diff = aPadstackRef->Drill().size.x - aPadstackCmp->Drill().size.x ) != 0 )
return diff;
if( ( diff = aPadstackRef->Drill().size.y - aPadstackCmp->Drill().size.y ) != 0 )
return diff;
return aPadstackRef->LayerSet().compare( aPadstackCmp->LayerSet() );
}
double PADSTACK::Similarity( const PADSTACK& aOther ) const
{
double similarity = 1.0;
ForEachUniqueLayer(
[&]( PCB_LAYER_ID aLayer )
{
if( Shape( aLayer ) != aOther.Shape( aLayer ) )
similarity *= 0.9;
if( Size( aLayer ) != aOther.Size( aLayer ) )
similarity *= 0.9;
if( Offset( aLayer ) != aOther.Offset( aLayer ) )
similarity *= 0.9;
if( RoundRectRadiusRatio( aLayer ) != aOther.RoundRectRadiusRatio( aLayer ) )
similarity *= 0.9;
if( ChamferRatio( aLayer ) != aOther.ChamferRatio( aLayer ) )
similarity *= 0.9;
if( ChamferPositions( aLayer ) != aOther.ChamferPositions( aLayer ) )
similarity *= 0.9;
if( Primitives( aLayer ).size() != aOther.Primitives( aLayer ).size() )
similarity *= 0.9;
if( AnchorShape( aLayer ) != aOther.AnchorShape( aLayer ) )
similarity *= 0.9;
} );
if( Drill() != aOther.Drill() )
similarity *= 0.9;
if( DrillShape() != aOther.DrillShape() )
similarity *= 0.9;
if( GetOrientation() != aOther.GetOrientation() )
similarity *= 0.9;
if( ZoneConnection() != aOther.ZoneConnection() )
similarity *= 0.9;
if( ThermalSpokeWidth() != aOther.ThermalSpokeWidth() )
similarity *= 0.9;
if( ThermalSpokeAngle() != aOther.ThermalSpokeAngle() )
similarity *= 0.9;
if( ThermalGap() != aOther.ThermalGap() )
similarity *= 0.9;
if( CustomShapeInZoneMode() != aOther.CustomShapeInZoneMode() )
similarity *= 0.9;
if( Clearance() != aOther.Clearance() )
similarity *= 0.9;
if( SolderMaskMargin() != aOther.SolderMaskMargin() )
similarity *= 0.9;
if( SolderPasteMargin() != aOther.SolderPasteMargin() )
similarity *= 0.9;
if( SolderPasteMarginRatio() != aOther.SolderPasteMarginRatio() )
similarity *= 0.9;
if( ThermalGap() != aOther.ThermalGap() )
similarity *= 0.9;
if( ThermalSpokeWidth() != aOther.ThermalSpokeWidth() )
similarity *= 0.9;
if( ThermalSpokeAngle() != aOther.ThermalSpokeAngle() )
similarity *= 0.9;
if( LayerSet() != aOther.LayerSet() )
similarity *= 0.9;
return similarity;
}
wxString PADSTACK::Name() const
{
// TODO
return wxEmptyString;
}
PCB_LAYER_ID PADSTACK::StartLayer() const
{
return m_drill.start;
}
PCB_LAYER_ID PADSTACK::EndLayer() const
{
return m_drill.end;
}
void PADSTACK::FlipLayers( int aCopperLayerCount )
{
switch( m_mode )
{
case MODE::NORMAL:
// Same shape on all layers; nothing to do
break;
case MODE::CUSTOM:
{
if( aCopperLayerCount > 2 )
{
int innerCount = ( aCopperLayerCount - 2 );
int halfInnerLayerCount = innerCount / 2;
PCB_LAYER_ID lastInner
= static_cast<PCB_LAYER_ID>( In1_Cu + ( innerCount - 1 ) * 2 );
PCB_LAYER_ID midpointInner
= static_cast<PCB_LAYER_ID>( In1_Cu + ( halfInnerLayerCount - 1 ) * 2 );
for( PCB_LAYER_ID layer : LAYER_RANGE( In1_Cu, midpointInner, MAX_CU_LAYERS ) )
{
auto conjugate =
magic_enum::enum_cast<PCB_LAYER_ID>( lastInner - ( layer - In1_Cu ) );
wxCHECK2_MSG( conjugate.has_value() && m_copperProps.contains( conjugate.value() ),
continue, "Invalid inner layer conjugate!" );
std::swap( m_copperProps[layer], m_copperProps[conjugate.value()] );
}
}
KI_FALLTHROUGH;
}
case MODE::FRONT_INNER_BACK:
std::swap( m_copperProps[F_Cu], m_copperProps[B_Cu] );
std::swap( m_frontMaskProps, m_backMaskProps );
break;
}
}
PADSTACK::SHAPE_PROPS::SHAPE_PROPS() :
shape( PAD_SHAPE::CIRCLE ),
anchor_shape( PAD_SHAPE::CIRCLE ),
round_rect_corner_radius( 0 ),
round_rect_radius_ratio( 0.25 ),
chamfered_rect_ratio( 0.2 ),
chamfered_rect_positions( RECT_NO_CHAMFER )
{
}
bool PADSTACK::SHAPE_PROPS::operator==( const SHAPE_PROPS& aOther ) const
{
return shape == aOther.shape && offset == aOther.offset
&& round_rect_corner_radius == aOther.round_rect_corner_radius
&& round_rect_radius_ratio == aOther.round_rect_radius_ratio
&& chamfered_rect_ratio == aOther.chamfered_rect_ratio
&& chamfered_rect_positions == aOther.chamfered_rect_positions;
}
bool PADSTACK::COPPER_LAYER_PROPS::operator==( const COPPER_LAYER_PROPS& aOther ) const
{
if( shape != aOther.shape )
return false;
if( zone_connection != aOther.zone_connection )
return false;
if( thermal_spoke_width != aOther.thermal_spoke_width )
return false;
if( thermal_spoke_angle != aOther.thermal_spoke_angle )
return false;
if( thermal_gap != aOther.thermal_gap )
return false;
if( custom_shapes.size() != aOther.custom_shapes.size() )
return false;
if( !std::equal( custom_shapes.begin(), custom_shapes.end(),
aOther.custom_shapes.begin(), aOther.custom_shapes.end(),
[]( const std::shared_ptr<PCB_SHAPE>& aFirst,
const std::shared_ptr<PCB_SHAPE>& aSecond )
{
return *aFirst == *aSecond;
} ) )
{
return false;
}
return true;
}
bool PADSTACK::MASK_LAYER_PROPS::operator==( const MASK_LAYER_PROPS& aOther ) const
{
return solder_mask_margin == aOther.solder_mask_margin
&& solder_paste_margin == aOther.solder_paste_margin
&& solder_paste_margin_ratio == aOther.solder_paste_margin_ratio
&& has_solder_mask == aOther.has_solder_mask
&& has_solder_paste == aOther.has_solder_paste;
}
bool PADSTACK::DRILL_PROPS::operator==( const DRILL_PROPS& aOther ) const
{
return size == aOther.size && shape == aOther.shape
&& start == aOther.start && end == aOther.end;
}
void PADSTACK::SetMode( MODE aMode )
{
if( m_mode == aMode )
return;
switch( aMode )
{
case MODE::NORMAL:
std::erase_if( m_copperProps,
[]( const auto& aEntry )
{
const auto& [key, value] = aEntry;
return key != ALL_LAYERS;
} );
break;
case MODE::FRONT_INNER_BACK:
// When coming from normal, these layers may be missing or have junk values
if( m_mode == MODE::NORMAL )
{
m_copperProps[INNER_LAYERS] = m_copperProps[ALL_LAYERS];
m_copperProps[B_Cu] = m_copperProps[ALL_LAYERS];
}
break;
case MODE::CUSTOM:
{
PCB_LAYER_ID innerLayerTemplate = ( m_mode == MODE::NORMAL ) ? ALL_LAYERS : INNER_LAYERS;
for( PCB_LAYER_ID layer : LAYER_RANGE( In1_Cu, In30_Cu, MAX_CU_LAYERS ) )
m_copperProps[layer] = m_copperProps[innerLayerTemplate];
if( m_mode == MODE::NORMAL )
m_copperProps[B_Cu] = m_copperProps[ALL_LAYERS];
break;
}
}
m_mode = aMode;
// Changing mode invalidates cached shapes
// TODO(JE) clean this up -- maybe PADSTACK should own shape caches
if( PAD* parentPad = dynamic_cast<PAD*>( m_parent ) )
parentPad->SetDirty();
}
void PADSTACK::ForEachUniqueLayer( const std::function<void( PCB_LAYER_ID )>& aMethod ) const
{
switch( Mode() )
{
case MODE::NORMAL:
aMethod( F_Cu );
break;
case MODE::FRONT_INNER_BACK:
aMethod( F_Cu );
aMethod( INNER_LAYERS );
aMethod( B_Cu );
break;
case MODE::CUSTOM:
{
int layerCount = m_parent ? m_parent->BoardCopperLayerCount() : MAX_CU_LAYERS;
for( PCB_LAYER_ID layer : LAYER_RANGE( F_Cu, B_Cu, layerCount ) )
aMethod( layer );
break;
}
}
}
std::vector<PCB_LAYER_ID> PADSTACK::UniqueLayers() const
{
switch( Mode() )
{
default:
case MODE::NORMAL:
return { F_Cu };
case MODE::FRONT_INNER_BACK:
return { F_Cu, INNER_LAYERS, B_Cu };
case MODE::CUSTOM:
{
std::vector<PCB_LAYER_ID> layers;
int layerCount = m_parent ? m_parent->BoardCopperLayerCount() : MAX_CU_LAYERS;
for( PCB_LAYER_ID layer : LAYER_RANGE( F_Cu, B_Cu, layerCount ) )
layers.push_back( layer );
return layers;
}
}
}
PCB_LAYER_ID PADSTACK::EffectiveLayerFor( PCB_LAYER_ID aLayer ) const
{
switch( static_cast<int>( aLayer ) )
{
case LAYER_PAD_FR_NETNAMES:
return F_Cu;
case LAYER_PAD_BK_NETNAMES:
return Mode() == MODE::NORMAL ? F_Cu : B_Cu;
// For these, just give the front copper geometry, it doesn't matter.
case LAYER_PAD_NETNAMES:
case LAYER_VIA_NETNAMES:
case LAYER_PADS:
case LAYER_PAD_PLATEDHOLES:
case LAYER_VIA_HOLES:
case LAYER_PAD_HOLEWALLS:
case LAYER_VIA_HOLEWALLS:
return ALL_LAYERS;
default:
break;
}
switch( Mode() )
{
case MODE::CUSTOM:
case MODE::FRONT_INNER_BACK:
{
PCB_LAYER_ID boardCuLayer = aLayer;
if( IsViaCopperLayer( aLayer ) )
boardCuLayer = ToLAYER_ID( static_cast<int>( aLayer ) - LAYER_VIA_COPPER_START );
else if( IsPadCopperLayer( aLayer ) )
boardCuLayer = ToLAYER_ID( static_cast<int>( aLayer ) - LAYER_PAD_COPPER_START );
else if( IsClearanceLayer( aLayer ) )
boardCuLayer = ToLAYER_ID( static_cast<int>( aLayer ) - LAYER_CLEARANCE_START );
if( IsFrontLayer( boardCuLayer ) )
return F_Cu;
if( IsBackLayer( boardCuLayer ) )
return B_Cu;
wxASSERT_MSG( IsCopperLayer( boardCuLayer ),
wxString::Format( wxT( "Unhandled layer %d in PADSTACK::EffectiveLayerFor" ),
aLayer ) );
if( Mode() == MODE::FRONT_INNER_BACK )
return INNER_LAYERS;
// Custom padstack: Clamp to parent board's stackup if present
if( m_parent )
{
LSET boardCopper = m_parent->BoardLayerSet() & LSET::AllCuMask();
if( boardCopper.Contains( boardCuLayer ) )
return boardCuLayer;
// We're asked for an inner copper layer not present in the board. There is no right
// answer here, so fall back on the front shape
wxFAIL_MSG( "Asked for inner padstack layer not present on the board" );
return ALL_LAYERS;
}
// No parent, just pass through
return boardCuLayer;
}
case MODE::NORMAL:
break;
}
return F_Cu;
}
LSET PADSTACK::RelevantShapeLayers( const PADSTACK& aOther ) const
{
LSET ret;
#ifdef DEBUG
if( m_parent && aOther.m_parent
&& ( m_mode == MODE::CUSTOM || aOther.m_mode == MODE::CUSTOM ) )
{
wxASSERT_MSG( m_parent->BoardCopperLayerCount() == aOther.m_parent->BoardCopperLayerCount(),
wxT( "Expected both padstacks to have the same board copper layer count" ) );
}
#endif
ForEachUniqueLayer( [&]( PCB_LAYER_ID aLayer ) { ret.set( aLayer ); } );
aOther.ForEachUniqueLayer( [&]( PCB_LAYER_ID aLayer ) { ret.set( aLayer ); } );
return ret;
}
PADSTACK::COPPER_LAYER_PROPS& PADSTACK::CopperLayer( PCB_LAYER_ID aLayer )
{
PCB_LAYER_ID layer = EffectiveLayerFor( aLayer );
// Create on-demand
return m_copperProps[layer];
}
const PADSTACK::COPPER_LAYER_PROPS& PADSTACK::CopperLayer( PCB_LAYER_ID aLayer ) const
{
PCB_LAYER_ID layer = EffectiveLayerFor( aLayer );
auto it = m_copperProps.find( layer );
wxCHECK_MSG( it != m_copperProps.end(), m_copperProps.at( ALL_LAYERS ),
"Attempt to retrieve layer " + std::string( magic_enum::enum_name( layer ) ) + " from a "
"padstack that does not contain it" );
return it->second;
}
PAD_SHAPE PADSTACK::Shape( PCB_LAYER_ID aLayer ) const
{
return CopperLayer( aLayer ).shape.shape;
}
void PADSTACK::SetShape( PAD_SHAPE aShape, PCB_LAYER_ID aLayer )
{
CopperLayer( aLayer ).shape.shape = aShape;
}
void PADSTACK::SetSize( const VECTOR2I& aSize, PCB_LAYER_ID aLayer )
{
// File formats do not enforce that sizes are always positive, but KiCad requires it
VECTOR2I& size = CopperLayer( aLayer ).shape.size;
size.x = std::abs( aSize.x );
size.y = std::abs( aSize.y );
}
const VECTOR2I& PADSTACK::Size( PCB_LAYER_ID aLayer ) const
{
return CopperLayer( aLayer ).shape.size;
}
PAD_DRILL_SHAPE PADSTACK::DrillShape() const
{
return m_drill.shape;
}
void PADSTACK::SetDrillShape( PAD_DRILL_SHAPE aShape )
{
m_drill.shape = aShape;
}
VECTOR2I& PADSTACK::Offset( PCB_LAYER_ID aLayer )
{
return CopperLayer( aLayer ).shape.offset;
}
const VECTOR2I& PADSTACK::Offset( PCB_LAYER_ID aLayer ) const
{
return CopperLayer( aLayer ).shape.offset;
}
PAD_SHAPE PADSTACK::AnchorShape( PCB_LAYER_ID aLayer ) const
{
return CopperLayer( aLayer ).shape.anchor_shape;
}
void PADSTACK::SetAnchorShape( PAD_SHAPE aShape, PCB_LAYER_ID aLayer )
{
CopperLayer( aLayer ).shape.anchor_shape = aShape;
}
VECTOR2I& PADSTACK::TrapezoidDeltaSize( PCB_LAYER_ID aLayer )
{
return CopperLayer( aLayer ).shape.trapezoid_delta_size;
}
const VECTOR2I& PADSTACK::TrapezoidDeltaSize( PCB_LAYER_ID aLayer ) const
{
return CopperLayer( aLayer ).shape.trapezoid_delta_size;
}
double PADSTACK::RoundRectRadiusRatio( PCB_LAYER_ID aLayer ) const
{
return CopperLayer( aLayer ).shape.round_rect_radius_ratio;
}
void PADSTACK::SetRoundRectRadiusRatio( double aRatio, PCB_LAYER_ID aLayer )
{
CopperLayer( aLayer ).shape.round_rect_radius_ratio = aRatio;
}
int PADSTACK::RoundRectRadius( PCB_LAYER_ID aLayer ) const
{
const VECTOR2I& size = Size( aLayer );
return KiROUND( std::min( size.x, size.y ) * RoundRectRadiusRatio( aLayer ) );
}
void PADSTACK::SetRoundRectRadius( double aRadius, PCB_LAYER_ID aLayer )
{
const VECTOR2I& size = Size( aLayer );
int min_r = std::min( size.x, size.y );
if( min_r > 0 )
SetRoundRectRadiusRatio( aRadius / min_r, aLayer );
}
double PADSTACK::ChamferRatio( PCB_LAYER_ID aLayer ) const
{
return CopperLayer( aLayer ).shape.chamfered_rect_ratio;
}
void PADSTACK::SetChamferRatio( double aRatio, PCB_LAYER_ID aLayer )
{
CopperLayer( aLayer ).shape.chamfered_rect_ratio = aRatio;
}
int& PADSTACK::ChamferPositions( PCB_LAYER_ID aLayer )
{
return CopperLayer( aLayer ).shape.chamfered_rect_positions;
}
const int& PADSTACK::ChamferPositions( PCB_LAYER_ID aLayer ) const
{
return CopperLayer( aLayer ).shape.chamfered_rect_positions;
}
void PADSTACK::SetChamferPositions( int aPositions, PCB_LAYER_ID aLayer )
{
CopperLayer( aLayer ).shape.chamfered_rect_positions = aPositions;
}
std::optional<int>& PADSTACK::Clearance( PCB_LAYER_ID aLayer )
{
return CopperLayer( aLayer ).clearance;
}
const std::optional<int>& PADSTACK::Clearance( PCB_LAYER_ID aLayer ) const
{
return CopperLayer( aLayer ).clearance;
}
std::optional<int>& PADSTACK::SolderMaskMargin( PCB_LAYER_ID aLayer )
{
return IsFrontLayer( aLayer ) ? m_frontMaskProps.solder_mask_margin
: m_backMaskProps.solder_mask_margin;
}
const std::optional<int>& PADSTACK::SolderMaskMargin( PCB_LAYER_ID aLayer ) const
{
return IsFrontLayer( aLayer ) ? m_frontMaskProps.solder_mask_margin
: m_backMaskProps.solder_mask_margin;
}
std::optional<int>& PADSTACK::SolderPasteMargin( PCB_LAYER_ID aLayer )
{
return IsFrontLayer( aLayer ) ? m_frontMaskProps.solder_paste_margin
: m_backMaskProps.solder_paste_margin;
}
const std::optional<int>& PADSTACK::SolderPasteMargin( PCB_LAYER_ID aLayer ) const
{
return IsFrontLayer( aLayer ) ? m_frontMaskProps.solder_paste_margin
: m_backMaskProps.solder_paste_margin;}
std::optional<double>& PADSTACK::SolderPasteMarginRatio( PCB_LAYER_ID aLayer )
{
return IsFrontLayer( aLayer ) ? m_frontMaskProps.solder_paste_margin_ratio
: m_backMaskProps.solder_paste_margin_ratio;
}
const std::optional<double>& PADSTACK::SolderPasteMarginRatio( PCB_LAYER_ID aLayer ) const
{
return IsFrontLayer( aLayer ) ? m_frontMaskProps.solder_paste_margin_ratio
: m_backMaskProps.solder_paste_margin_ratio;
}
std::optional<ZONE_CONNECTION>& PADSTACK::ZoneConnection( PCB_LAYER_ID aLayer )
{
return CopperLayer( aLayer ).zone_connection;
}
const std::optional<ZONE_CONNECTION>& PADSTACK::ZoneConnection( PCB_LAYER_ID aLayer ) const
{
return CopperLayer( aLayer ).zone_connection;
}
std::optional<int>& PADSTACK::ThermalSpokeWidth( PCB_LAYER_ID aLayer )
{
return CopperLayer( aLayer ).thermal_spoke_width;
}
const std::optional<int>& PADSTACK::ThermalSpokeWidth( PCB_LAYER_ID aLayer ) const
{
return CopperLayer( aLayer ).thermal_spoke_width;
}
std::optional<int>& PADSTACK::ThermalGap( PCB_LAYER_ID aLayer )
{
return CopperLayer( aLayer ).thermal_gap;
}
const std::optional<int>& PADSTACK::ThermalGap( PCB_LAYER_ID aLayer ) const
{
return CopperLayer( aLayer ).thermal_gap;
}
EDA_ANGLE PADSTACK::DefaultThermalSpokeAngleForShape( PCB_LAYER_ID aLayer ) const
{
const COPPER_LAYER_PROPS& defaults = CopperLayer( aLayer );
return ( defaults.shape.shape == PAD_SHAPE::CIRCLE
|| ( defaults.shape.shape == PAD_SHAPE::CUSTOM
&& defaults.shape.anchor_shape == PAD_SHAPE::CIRCLE ) )
? ANGLE_45 : ANGLE_90;
}
EDA_ANGLE PADSTACK::ThermalSpokeAngle( PCB_LAYER_ID aLayer ) const
{
const COPPER_LAYER_PROPS& defaults = CopperLayer( aLayer );
return defaults.thermal_spoke_angle.value_or( DefaultThermalSpokeAngleForShape( aLayer ) );
}
void PADSTACK::SetThermalSpokeAngle( EDA_ANGLE aAngle, PCB_LAYER_ID aLayer )
{
CopperLayer( aLayer ).thermal_spoke_angle = aAngle;
}
std::vector<std::shared_ptr<PCB_SHAPE>>& PADSTACK::Primitives( PCB_LAYER_ID aLayer )
{
return CopperLayer( aLayer ).custom_shapes;
}
const std::vector<std::shared_ptr<PCB_SHAPE>>& PADSTACK::Primitives( PCB_LAYER_ID aLayer ) const
{
return CopperLayer( aLayer ).custom_shapes;
}
void PADSTACK::AddPrimitive( PCB_SHAPE* aShape, PCB_LAYER_ID aLayer )
{
aShape->SetParent( m_parent );
CopperLayer( aLayer ).custom_shapes.emplace_back( aShape );
}
void PADSTACK::AppendPrimitives( const std::vector<std::shared_ptr<PCB_SHAPE>>& aPrimitivesList,
PCB_LAYER_ID aLayer )
{
for( const std::shared_ptr<PCB_SHAPE>& prim : aPrimitivesList )
AddPrimitive( new PCB_SHAPE( *prim ), aLayer );
}
void PADSTACK::ReplacePrimitives( const std::vector<std::shared_ptr<PCB_SHAPE>>& aPrimitivesList,
PCB_LAYER_ID aLayer )
{
ClearPrimitives( aLayer );
if( aPrimitivesList.size() )
AppendPrimitives( aPrimitivesList, aLayer );
}
void PADSTACK::ClearPrimitives( PCB_LAYER_ID aLayer )
{
CopperLayer( aLayer ).custom_shapes.clear();
}
std::optional<bool> PADSTACK::IsTented( PCB_LAYER_ID aSide ) const
{
if( IsFrontLayer( aSide ) )
return m_frontMaskProps.has_solder_mask;
if( IsBackLayer( aSide ) )
return m_backMaskProps.has_solder_mask;
wxCHECK_MSG( false, std::nullopt, "IsTented expects a front or back layer" );
}
IMPLEMENT_ENUM_TO_WXANY( PADSTACK::UNCONNECTED_LAYER_MODE )
|