26#include <api/board/board_types.pb.h>
28#include <magic_enum.hpp>
86 if( shape != PAD_SHAPE::CUSTOM )
92 SetShape( PAD_SHAPE::RECTANGLE, aLayer );
131 bool copperMatches =
true;
137 copperMatches =
false;
140 return copperMatches;
146 using namespace kiapi::board::types;
149 if( !aContainer.UnpackTo( &padstack ) )
152 m_mode = FromProtoEnum<MODE>( padstack.type() );
160 Drill().
start = FromProtoEnum<PCB_LAYER_ID>( padstack.start_layer() );
161 Drill().
end = FromProtoEnum<PCB_LAYER_ID>( padstack.end_layer() );
165 if( padstack.layers_size() == 1 )
167 const PadStackLayer& layer = padstack.layers( 0 );
170 SetShape( FromProtoEnum<PAD_SHAPE>( layer.shape() ),
F_Cu );
177 if( layer.chamfered_corners().top_left() )
180 if( layer.chamfered_corners().top_right() )
183 if( layer.chamfered_corners().bottom_left() )
186 if( layer.chamfered_corners().bottom_right() )
190 google::protobuf::Any a;
192 for(
const GraphicShape& shapeProto : layer.custom_shapes() )
194 a.PackFrom( shapeProto );
195 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>(
m_parent );
197 if( shape->Deserialize( a ) )
201 if( layer.has_zone_settings() )
204 FromProtoEnum<ZONE_CONNECTION>( layer.zone_settings().zone_connection() );
206 if( layer.zone_settings().has_thermal_spokes() )
208 const ThermalSpokeSettings& thermals = layer.zone_settings().thermal_spokes();
225 FromProtoEnum<UNCONNECTED_LAYER_MODE>( padstack.unconnected_layer_removal() ) );
228 [](
const SolderMaskMode& aProto, std::optional<bool>& aDest )
232 case kiapi::board::types::SMM_MASKED:
236 case kiapi::board::types::SMM_UNMASKED:
241 case kiapi::board::types::SMM_FROM_DESIGN_RULES:
242 aDest = std::nullopt;
247 unpackMask( padstack.front_outer_layers().solder_mask_mode(),
250 unpackMask( padstack.back_outer_layers().solder_mask_mode(),
254 [](
const SolderPasteMode& aProto, std::optional<bool>& aDest )
258 case kiapi::board::types::SPM_PASTE:
262 case kiapi::board::types::SPM_NO_PASTE:
267 case kiapi::board::types::SPM_FROM_DESIGN_RULES:
268 aDest = std::nullopt;
273 unpackPaste( padstack.front_outer_layers().solder_paste_mode(),
276 unpackPaste( padstack.back_outer_layers().solder_paste_mode(),
279 if( padstack.front_outer_layers().has_solder_mask_settings()
280 && padstack.front_outer_layers().solder_mask_settings().has_solder_mask_margin() )
283 padstack.front_outer_layers().solder_mask_settings().solder_mask_margin().value_nm();
290 if( padstack.back_outer_layers().has_solder_mask_settings()
291 && padstack.back_outer_layers().solder_mask_settings().has_solder_mask_margin() )
294 padstack.back_outer_layers().solder_mask_settings().solder_mask_margin().value_nm();
301 if( padstack.front_outer_layers().has_solder_paste_settings()
302 && padstack.front_outer_layers().solder_paste_settings().has_solder_paste_margin() )
305 padstack.front_outer_layers().solder_paste_settings().solder_paste_margin().value_nm();
312 if( padstack.back_outer_layers().has_solder_paste_settings()
313 && padstack.back_outer_layers().solder_paste_settings().has_solder_paste_margin() )
316 padstack.back_outer_layers().solder_paste_settings().solder_paste_margin().value_nm();
323 if( padstack.front_outer_layers().has_solder_paste_settings()
324 && padstack.front_outer_layers().solder_paste_settings().has_solder_paste_margin_ratio() )
327 padstack.front_outer_layers().solder_paste_settings().solder_paste_margin_ratio().value();
334 if( padstack.back_outer_layers().has_solder_paste_settings()
335 && padstack.back_outer_layers().solder_paste_settings().has_solder_paste_margin_ratio() )
338 padstack.back_outer_layers().solder_paste_settings().solder_paste_margin_ratio().value();
352 using namespace kiapi::board::types;
355 padstack.set_type( ToProtoEnum<MODE, PadStackType>(
m_mode ) );
356 padstack.set_start_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>(
StartLayer() ) );
357 padstack.set_end_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>(
EndLayer() ) );
362 PadStackLayer* stackLayer = padstack.add_layers();
365 stackLayer->set_shape( ToProtoEnum<PAD_SHAPE, PadStackShape>(
Shape(
ALL_LAYERS ) ) );
366 stackLayer->set_custom_anchor_shape( ToProtoEnum<PAD_SHAPE, PadStackShape>(
AnchorShape(
ALL_LAYERS ) ) );
370 google::protobuf::Any a;
375 shape->Serialize( a );
376 GraphicShape* s = stackLayer->add_custom_shapes();
386 ZoneConnectionSettings* zoneSettings = stackLayer->mutable_zone_settings();
387 ThermalSpokeSettings* thermalSettings = zoneSettings->mutable_thermal_spokes();
391 zoneSettings->set_zone_connection( ToProtoEnum<ZONE_CONNECTION, ZoneConnectionStyle>(
399 padstack.set_unconnected_layer_removal(
403 []<
typename ProtoEnum>(
const std::optional<bool>& aVal, ProtoEnum aTrueVal,
404 ProtoEnum aFalseVal, ProtoEnum aNullVal ) -> ProtoEnum
406 if( aVal.has_value() )
407 return *aVal ? aTrueVal : aFalseVal;
412 PadStackOuterLayer* frontOuter = padstack.mutable_front_outer_layers();
413 PadStackOuterLayer* backOuter = padstack.mutable_back_outer_layers();
415 frontOuter->set_solder_mask_mode( packOptional(
FrontOuterLayers().has_solder_mask,
416 SMM_MASKED, SMM_UNMASKED,
417 SMM_FROM_DESIGN_RULES ) );
419 backOuter->set_solder_mask_mode( packOptional(
BackOuterLayers().has_solder_mask,
420 SMM_MASKED, SMM_UNMASKED,
421 SMM_FROM_DESIGN_RULES ) );
423 frontOuter->set_solder_paste_mode( packOptional(
FrontOuterLayers().has_solder_paste,
424 SPM_PASTE, SPM_NO_PASTE,
425 SPM_FROM_DESIGN_RULES ) );
427 backOuter->set_solder_paste_mode( packOptional(
BackOuterLayers().has_solder_paste,
428 SPM_PASTE, SPM_NO_PASTE,
429 SPM_FROM_DESIGN_RULES ) );
433 frontOuter->mutable_solder_mask_settings()->mutable_solder_mask_margin()->set_value_nm(
439 backOuter->mutable_solder_mask_settings()->mutable_solder_mask_margin()->set_value_nm(
445 frontOuter->mutable_solder_paste_settings()->mutable_solder_paste_margin()->set_value_nm(
451 backOuter->mutable_solder_paste_settings()->mutable_solder_paste_margin()->set_value_nm(
457 frontOuter->mutable_solder_paste_settings()->mutable_solder_paste_margin_ratio()->set_value(
463 backOuter->mutable_solder_paste_settings()->mutable_solder_paste_margin_ratio()->set_value(
467 aContainer.PackFrom( padstack );
475 auto compareCopperProps =
478 if( ( diff =
static_cast<int>( aPadstackRef->
Shape( aLayer ) ) -
479 static_cast<int>( aPadstackCmp->
Shape( aLayer ) ) ) != 0 )
482 if( ( diff = aPadstackRef->
Size( aLayer ).
x - aPadstackCmp->
Size( aLayer ).
x ) != 0 )
485 if( ( diff = aPadstackRef->
Size( aLayer ).
y - aPadstackCmp->
Size( aLayer ).
y ) != 0 )
488 if( ( diff = aPadstackRef->
Offset( aLayer ).
x
489 - aPadstackCmp->
Offset( aLayer ).
x ) != 0 )
492 if( ( diff = aPadstackRef->
Offset( aLayer ).
y
493 - aPadstackCmp->
Offset( aLayer ).
y ) != 0 )
525 if( ( diff =
static_cast<int>( aPadstackRef->
Primitives( aLayer ).size() ) -
526 static_cast<int>( aPadstackCmp->
Primitives( aLayer ).size() ) ) != 0 )
536 if( ( diff =
static_cast<int>( aPadstackRef->
DrillShape() ) -
537 static_cast<int>( aPadstackCmp->
DrillShape() ) ) != 0 )
552 double similarity = 1.0;
557 if(
Shape( aLayer ) != aOther.
Shape( aLayer ) )
560 if(
Size( aLayer ) != aOther.
Size( aLayer ) )
637 return wxEmptyString;
656 round_rect_corner_radius( 0 ),
657 round_rect_radius_ratio( 0.25 ),
658 chamfered_rect_ratio( 0.2 ),
666 return shape == aOther.
shape && offset == aOther.
offset
676 if( shape != aOther.
shape )
694 if( !std::equal( custom_shapes.begin(), custom_shapes.end(),
696 [](
const std::shared_ptr<PCB_SHAPE>& aFirst,
697 const std::shared_ptr<PCB_SHAPE>& aSecond )
699 return *aFirst == *aSecond;
721 return size == aOther.
size && shape == aOther.
shape
722 && start == aOther.
start && end == aOther.
end;
737 [](
const auto& aEntry )
739 const auto& [key, value] = aEntry;
759 parentPad->SetDirty();
788 switch(
static_cast<int>( aLayer ) )
822 wxString::Format( wxT(
"Unhandled layer %d in PADSTACK::EffectiveLayerFor" ),
849 "Attempt to retrieve layer " + std::string( magic_enum::enum_name( layer ) ) +
" from a "
850 "padstack that does not contain it" );
953 int min_r = std::min( size.
x, size.
y );
1083 return ( defaults.
shape.
shape == PAD_SHAPE::CIRCLE
1084 || ( defaults.
shape.
shape == PAD_SHAPE::CUSTOM
1125 for(
const std::shared_ptr<PCB_SHAPE>& prim : aPrimitivesList )
1135 if( aPrimitivesList.size() )
1154 wxCHECK_MSG(
false, std::nullopt,
"IsTented expects a front or back layer" );
@ NORMAL
Use all material properties from model file.
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
BASE_SET & reset(size_t pos)
int compare(const BASE_SET &other) const
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Represent basic circle geometry with utility geometry functions.
A PADSTACK defines the characteristics of a single or multi-layer pad, in the IPC sense of the word.
bool operator==(const PADSTACK &aOther) const
CUSTOM_SHAPE_ZONE_MODE CustomShapeInZoneMode() const
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 ...
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
MASK_LAYER_PROPS & FrontOuterLayers()
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
void SetDrillShape(PAD_DRILL_SHAPE aShape)
std::optional< double > & SolderPasteMarginRatio(PCB_LAYER_ID aLayer=F_Cu)
wxString m_customName
! An override for the IPC-7351 padstack name
DRILL_PROPS m_drill
! The primary drill parameters, which also define the start and end layers for through-hole vias and ...
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)
UNCONNECTED_LAYER_MODE m_unconnectedLayerMode
void ClearPrimitives(PCB_LAYER_ID aLayer)
void SetUnconnectedLayerMode(UNCONNECTED_LAYER_MODE aMode)
std::optional< bool > IsTented(PCB_LAYER_ID aSide) const
Checks if this padstack is tented (covered in soldermask) on the given side.
std::optional< int > & ThermalSpokeWidth(PCB_LAYER_ID aLayer=F_Cu)
std::optional< int > & SolderPasteMargin(PCB_LAYER_ID aLayer=F_Cu)
std::optional< int > & SolderMaskMargin(PCB_LAYER_ID aLayer=F_Cu)
void SetChamferRatio(double aRatio, PCB_LAYER_ID aLayer)
const LSET & LayerSet() const
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)
void SetShape(PAD_SHAPE aShape, PCB_LAYER_ID aLayer)
EDA_ANGLE DefaultThermalSpokeAngleForShape(PCB_LAYER_ID aLayer=F_Cu) const
VECTOR2I & TrapezoidDeltaSize(PCB_LAYER_ID aLayer)
DRILL_PROPS m_secondaryDrill
! Secondary drill, used to define back-drilling
VECTOR2I & Offset(PCB_LAYER_ID aLayer)
MASK_LAYER_PROPS m_backMaskProps
! The overrides applied to back outer technical layers
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 ...
PAD_DRILL_SHAPE DrillShape() const
void SetChamferPositions(int aPositions, PCB_LAYER_ID aLayer)
void SetRoundRectRadius(double aRadius, PCB_LAYER_ID aLayer)
std::optional< int > & ThermalGap(PCB_LAYER_ID aLayer=F_Cu)
PAD_SHAPE Shape(PCB_LAYER_ID aLayer) const
void SetAnchorShape(PAD_SHAPE aShape, PCB_LAYER_ID aLayer)
BOARD_ITEM * m_parent
! The BOARD_ITEM this PADSTACK belongs to; will be used as the parent for owned shapes
PADSTACK(BOARD_ITEM *aParent)
LSET m_layerSet
! The board layers that this padstack is active on
std::unordered_map< PCB_LAYER_ID, COPPER_LAYER_PROPS > m_copperProps
! The properties applied to copper layers if they aren't overridden
static int Compare(const PADSTACK *aPadstackRef, const PADSTACK *aPadstackCmp)
Compare two padstacks and return 0 if they are equal.
PCB_LAYER_ID EndLayer() const
int & ChamferPositions(PCB_LAYER_ID aLayer)
MASK_LAYER_PROPS m_frontMaskProps
! The overrides applied to front outer technical layers
const VECTOR2I & Size(PCB_LAYER_ID aLayer) const
MODE
! Copper geometry mode: controls how many unique copper layer shapes this padstack has
@ NORMAL
Shape is the same on all layers.
@ CUSTOM
Shapes can be defined on arbitrary layers.
@ FRONT_INNER_BACK
Up to three shapes can be defined (F_Cu, inner copper layers, B_Cu)
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.
double RoundRectRadiusRatio(PCB_LAYER_ID aLayer) const
UNCONNECTED_LAYER_MODE
! Whether or not to remove the copper shape for unconnected layers
PCB_LAYER_ID StartLayer() const
PAD_SHAPE AnchorShape(PCB_LAYER_ID aLayer) const
MASK_LAYER_PROPS & BackOuterLayers()
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
wxString Name() const
! Returns the name of this padstack in IPC-7351 format
void SetSize(const VECTOR2I &aSize, PCB_LAYER_ID aLayer)
double ChamferRatio(PCB_LAYER_ID aLayer) const
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
EDA_ANGLE GetOrientation() const
static constexpr PCB_LAYER_ID INNER_LAYERS
! The layer identifier to use for "inner layers" on top/inner/bottom padstacks
void SetLayerSet(const LSET &aSet)
std::optional< ZONE_CONNECTION > & ZoneConnection(PCB_LAYER_ID aLayer=F_Cu)
MODE m_mode
! The copper layer variation mode this padstack is in
EDA_ANGLE m_orientation
! The rotation of the pad relative to an outer reference frame
std::vector< std::shared_ptr< PCB_SHAPE > > & Primitives(PCB_LAYER_ID aLayer)
@ RECT_CHAMFER_BOTTOM_RIGHT
@ RECT_CHAMFER_BOTTOM_LEFT
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_90
static constexpr EDA_ANGLE ANGLE_45
@ LAYER_PAD_FR_NETNAMES
Additional netnames layers (not associated with a PCB layer)
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
@ LAYER_PAD_PLATEDHOLES
to draw pad holes (plated)
@ LAYER_PADS_TH
multilayer pads, usually with holes
@ LAYER_VIA_HOLES
to draw via holes (pad holes do not use this layer)
PCB_LAYER_ID
A quick note on layer IDs:
void PackLayerSet(google::protobuf::RepeatedField< int > &aOutput, const LSET &aLayerSet)
LSET UnpackLayerSet(const google::protobuf::RepeatedField< int > &aProtoLayerSet)
void PackVector2(kiapi::common::types::Vector2 &aOutput, const VECTOR2I aInput)
VECTOR2I UnpackVector2(const types::Vector2 &aInput)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
PAD_DRILL_SHAPE
The set of pad drill shapes, used with PAD::{Set,Get}DrillShape()
PAD_SHAPE
The set of pad shapes, used with PAD::{Set,Get}Shape()
#define IMPLEMENT_ENUM_TO_WXANY(type)
The features of a padstack that can vary between copper layers All parameters are optional; leaving t...
std::optional< ZONE_CONNECTION > zone_connection
std::optional< int > thermal_spoke_width
std::vector< std::shared_ptr< PCB_SHAPE > > custom_shapes
bool operator==(const COPPER_LAYER_PROPS &aOther) const
std::optional< EDA_ANGLE > thermal_spoke_angle
std::optional< int > clearance
std::optional< int > thermal_gap
! The properties of a padstack drill. Drill position is always the pad position (origin).
bool operator==(const DRILL_PROPS &aOther) const
VECTOR2I size
Drill diameter (x == y) or slot dimensions (x != y)
! The features of a padstack that can vary on outer layers.
bool operator==(const MASK_LAYER_PROPS &aOther) const
std::optional< int > solder_mask_margin
std::optional< int > solder_paste_margin
std::optional< double > solder_paste_margin_ratio
std::optional< bool > has_solder_mask
True if this outer layer has mask (is not tented)
std::optional< bool > has_solder_paste
True if this outer layer has solder paste.
! The set of properties that define a pad's shape on a given layer
int chamfered_rect_positions
VECTOR2I trapezoid_delta_size
Delta for PAD_SHAPE::TRAPEZOID; half the delta squeezes one end and half expands the other.
double round_rect_corner_radius
VECTOR2I offset
Offset of the shape center from the pad center.
bool operator==(const SHAPE_PROPS &aOther) const
VECTOR2I size
Size of the shape, or of the anchor pad for custom shape pads.
double chamfered_rect_ratio
Size of chamfer: ratio of smallest of X,Y size.
double round_rect_radius_ratio
PAD_SHAPE shape
Shape of the pad.
PAD_SHAPE anchor_shape
Shape of the anchor when shape == PAD_SHAPE::CUSTOM.