26#include <api/board/board_types.pb.h>
29#include <magic_enum.hpp>
77 for( std::shared_ptr<PCB_SHAPE>& shape :
CopperLayer( aLayer ).custom_shapes )
172 bool copperMatches =
true;
178 copperMatches =
false;
181 return copperMatches;
208 if( aProto.chamfered_corners().top_left() )
211 if( aProto.chamfered_corners().top_right() )
214 if( aProto.chamfered_corners().bottom_left() )
217 if( aProto.chamfered_corners().bottom_right() )
221 google::protobuf::Any a;
223 for(
const BoardGraphicShape& shapeProto : aProto.custom_shapes() )
225 a.PackFrom( shapeProto );
226 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>(
m_parent );
228 if( shape->Deserialize( a ) )
241 auto unpackOptional = []<
typename ProtoEnum>(
const ProtoEnum& aProto,
242 std::optional<bool>& aDest, ProtoEnum aTrueValue,
243 ProtoEnum aFalseValue )
245 if( aProto == aTrueValue )
247 else if( aProto == aFalseValue )
250 aDest = std::nullopt;
253 auto unpackPostMachining = [](
const PostMachiningProperties& aProto,
256 switch( aProto.mode() )
261 default: aDest.mode = std::nullopt;
break;
264 aDest.size = aProto.size();
265 aDest.depth = aProto.depth();
266 aDest.angle = aProto.angle();
269 if( !aContainer.UnpackTo( &padstack ) )
279 unpackOptional( padstack.drill().capped(),
Drill().is_capped, VDCM_CAPPED, VDCM_UNCAPPED );
280 unpackOptional( padstack.drill().filled(),
Drill().is_filled, VDFM_FILLED, VDFM_UNFILLED );
282 if( padstack.has_front_post_machining() )
285 if( padstack.has_back_post_machining() )
290 if( padstack.has_secondary_drill() )
292 const DrillProperties& secondary = padstack.secondary_drill();
299 unpackOptional( secondary.capped(),
SecondaryDrill().is_capped, VDCM_CAPPED, VDCM_UNCAPPED );
300 unpackOptional( secondary.filled(),
SecondaryDrill().is_filled, VDFM_FILLED, VDFM_UNFILLED );
312 if( padstack.has_tertiary_drill() )
314 const DrillProperties& tertiary = padstack.tertiary_drill();
321 unpackOptional( tertiary.capped(),
TertiaryDrill().is_capped, VDCM_CAPPED, VDCM_UNCAPPED );
322 unpackOptional( tertiary.filled(),
TertiaryDrill().is_filled, VDFM_FILLED, VDFM_UNFILLED );
334 for(
const PadStackLayer& layer : padstack.copper_layers() )
343 if( padstack.has_zone_settings() )
348 if( padstack.zone_settings().has_thermal_spokes() )
350 const ThermalSpokeSettings& thermals = padstack.zone_settings().thermal_spokes();
352 if( thermals.has_gap() )
355 if( thermals.has_width() )
370 unpackOptional( padstack.front_outer_layers().solder_mask_mode(),
373 unpackOptional( padstack.back_outer_layers().solder_mask_mode(),
376 unpackOptional( padstack.front_outer_layers().covering_mode(),
FrontOuterLayers().has_covering,
377 VCM_COVERED, VCM_UNCOVERED );
379 unpackOptional( padstack.back_outer_layers().covering_mode(),
BackOuterLayers().has_covering,
380 VCM_COVERED, VCM_UNCOVERED );
382 unpackOptional( padstack.front_outer_layers().plugging_mode(),
FrontOuterLayers().has_plugging,
383 VPM_PLUGGED, VPM_UNPLUGGED );
385 unpackOptional( padstack.back_outer_layers().plugging_mode(),
BackOuterLayers().has_plugging,
386 VPM_PLUGGED, VPM_UNPLUGGED );
388 unpackOptional( padstack.front_outer_layers().solder_paste_mode(),
391 unpackOptional( padstack.back_outer_layers().solder_paste_mode(),
394 if( padstack.front_outer_layers().has_solder_mask_settings()
395 && padstack.front_outer_layers().solder_mask_settings().has_solder_mask_margin() )
398 padstack.front_outer_layers().solder_mask_settings().solder_mask_margin().value_nm();
405 if( padstack.back_outer_layers().has_solder_mask_settings()
406 && padstack.back_outer_layers().solder_mask_settings().has_solder_mask_margin() )
409 padstack.back_outer_layers().solder_mask_settings().solder_mask_margin().value_nm();
416 if( padstack.front_outer_layers().has_solder_paste_settings()
417 && padstack.front_outer_layers().solder_paste_settings().has_solder_paste_margin() )
420 padstack.front_outer_layers().solder_paste_settings().solder_paste_margin().value_nm();
427 if( padstack.back_outer_layers().has_solder_paste_settings()
428 && padstack.back_outer_layers().solder_paste_settings().has_solder_paste_margin() )
431 padstack.back_outer_layers().solder_paste_settings().solder_paste_margin().value_nm();
438 if( padstack.front_outer_layers().has_solder_paste_settings()
439 && padstack.front_outer_layers().solder_paste_settings().has_solder_paste_margin_ratio() )
442 padstack.front_outer_layers().solder_paste_settings().solder_paste_margin_ratio().value();
449 if( padstack.back_outer_layers().has_solder_paste_settings()
450 && padstack.back_outer_layers().solder_paste_settings().has_solder_paste_margin_ratio() )
453 padstack.back_outer_layers().solder_paste_settings().solder_paste_margin_ratio().value();
470 if( !hasSecondary && !hasTertiary )
473 if( hasSecondary && hasTertiary )
500 if( aDrill.
size.
x <= 0 )
504 aDrill.
start = aStart;
509 aDrill.
start = aStart;
583 if( aSize.has_value() )
585 target->
size = { *aSize, *aSize };
592 target->
size = { 0, 0 };
630 target->
end = aLayer;
641 padstack.mutable_angle()->set_value_degrees(
m_orientation.AsDegrees() );
648 if(
m_drill.is_capped.has_value() )
649 padstack.mutable_drill()->set_capped(
m_drill.is_capped.value() ? VDCM_CAPPED : VDCM_UNCAPPED );
651 if(
m_drill.is_filled.has_value() )
652 padstack.mutable_drill()->set_filled(
m_drill.is_filled.value() ? VDFM_FILLED : VDFM_UNFILLED );
656 DrillProperties* secondary = padstack.mutable_secondary_drill();
663 secondary->set_capped(
m_secondaryDrill.is_capped.value() ? VDCM_CAPPED : VDCM_UNCAPPED );
666 secondary->set_filled(
m_secondaryDrill.is_filled.value() ? VDFM_FILLED : VDFM_UNFILLED );
671 DrillProperties* tertiary = padstack.mutable_tertiary_drill();
678 tertiary->set_capped(
m_tertiaryDrill.is_capped.value() ? VDCM_CAPPED : VDCM_UNCAPPED );
681 tertiary->set_filled(
m_tertiaryDrill.is_filled.value() ? VDFM_FILLED : VDFM_UNFILLED );
685 PostMachiningProperties* aProto )
687 if( aProps.
mode.has_value() )
689 switch( aProps.
mode.value() )
698 aProto->set_size( aProps.
size );
699 aProto->set_depth( aProps.
depth );
700 aProto->set_angle( aProps.
angle );
712 PadStackLayer* layer = padstack.add_copper_layers();
727 layer->mutable_chamfered_corners()->set_top_left(
true );
730 layer->mutable_chamfered_corners()->set_top_right(
true );
733 layer->mutable_chamfered_corners()->set_bottom_left(
true );
736 layer->mutable_chamfered_corners()->set_bottom_right(
true );
738 for(
const std::shared_ptr<PCB_SHAPE>& shape : props.
custom_shapes )
740 google::protobuf::Any a;
741 shape->Serialize( a );
742 a.UnpackTo( layer->add_custom_shapes() );
748 padstack.mutable_zone_settings()->set_zone_connection(
754 padstack.mutable_zone_settings()->mutable_thermal_spokes()->mutable_gap()->set_value_nm(
760 padstack.mutable_zone_settings()->mutable_thermal_spokes()->mutable_width()->set_value_nm(
766 padstack.mutable_zone_settings()->mutable_thermal_spokes()->mutable_angle()->set_value_degrees(
775 padstack.mutable_front_outer_layers()->set_solder_mask_mode(
781 padstack.mutable_back_outer_layers()->set_solder_mask_mode(
782 BackOuterLayers().has_solder_mask.value() ? SMM_MASKED : SMM_UNMASKED );
787 padstack.mutable_front_outer_layers()->set_covering_mode(
793 padstack.mutable_back_outer_layers()->set_covering_mode(
794 BackOuterLayers().has_covering.value() ? VCM_COVERED : VCM_UNCOVERED );
799 padstack.mutable_front_outer_layers()->set_plugging_mode(
805 padstack.mutable_back_outer_layers()->set_plugging_mode(
806 BackOuterLayers().has_plugging.value() ? VPM_PLUGGED : VPM_UNPLUGGED );
811 padstack.mutable_front_outer_layers()->set_solder_paste_mode(
817 padstack.mutable_back_outer_layers()->set_solder_paste_mode(
818 BackOuterLayers().has_solder_paste.value() ? SPM_PASTE : SPM_NO_PASTE );
823 padstack.mutable_front_outer_layers()->mutable_solder_mask_settings()->mutable_solder_mask_margin()->set_value_nm(
829 padstack.mutable_back_outer_layers()->mutable_solder_mask_settings()->mutable_solder_mask_margin()->set_value_nm(
835 padstack.mutable_front_outer_layers()->mutable_solder_paste_settings()->mutable_solder_paste_margin()->set_value_nm(
841 padstack.mutable_back_outer_layers()->mutable_solder_paste_settings()->mutable_solder_paste_margin()->set_value_nm(
847 padstack.mutable_front_outer_layers()->mutable_solder_paste_settings()->mutable_solder_paste_margin_ratio()->set_value(
853 padstack.mutable_back_outer_layers()->mutable_solder_paste_settings()->mutable_solder_paste_margin_ratio()->set_value(
857 aContainer.PackFrom( padstack );
963 int min_r = std::min( size.
x, size.
y );
1128 if(
CopperLayer( aLayer ).thermal_spoke_angle.has_value() )
1164 for(
const std::shared_ptr<PCB_SHAPE>& item : aList )
1168 list.emplace_back( new_shape );
1249 std::vector<PCB_LAYER_ID> layers;
1254 layers.push_back( layer );
1296 layers.
set( layer );
1301 layers.
set( layer );
1316 return std::nullopt;
1327 return std::nullopt;
1338 return std::nullopt;
1354#define TEST( a, b ) { if( a != b ) return a - b; }
1419 double similarity = 1.0;
1474 std::unordered_map<PCB_LAYER_ID, COPPER_LAYER_PROPS> oldCopperProps =
m_copperProps;
1483 std::unordered_map<PCB_LAYER_ID, COPPER_LAYER_PROPS> oldCopperProps =
m_copperProps;
1486 for(
const auto& [layer, props] : oldCopperProps )
1575 if( !(
shape == aOther.
shape ) )
return false;
1592 double similarity = 1.0;
1619#define TEST_OPT( a, b, v ) \
1621 if( a.has_value() != b.has_value() ) \
1622 return a.has_value() - b.has_value(); \
1623 if( (int) a.value_or( v ) - (int) b.value_or( v ) != 0 ) \
1624 return (int) a.value_or( v ) - (int) b.value_or( v ); \
1627#define TEST_OPT_ANGLE( a, b, v ) \
1629 if( a.has_value() != b.has_value() ) \
1630 return a.has_value() - b.has_value(); \
1631 if( abs( a.value_or( v ).AsDegrees() - b.value_or( v ).AsDegrees() ) > 0.001 ) \
1632 return a.value_or( v ).AsDegrees() > b.value_or( v ).AsDegrees() ? 1 : -1; \
1640 if( ( diff =
shape.Compare( aOther.
shape ) ) != 0 )
types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
BASE_SET & set(size_t pos)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Information pertinent to a Pcbnew printed circuit board.
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayer) const
int AsTenthsOfADegree() const
virtual void SetParent(EDA_ITEM *aParent)
LSET is a set of PCB_LAYER_IDs.
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
std::optional< bool > IsFilled() const
bool operator==(const PADSTACK &aOther) 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 ...
void SetBackdrillMode(BACKDRILL_MODE aMode)
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
void SetBackdrillSize(bool aTop, std::optional< int > aSize)
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)
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.
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
std::optional< int > & SolderMaskMargin(PCB_LAYER_ID aLayer=F_Cu)
void SetChamferRatio(double aRatio, PCB_LAYER_ID aLayer)
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 starting from the bottom side
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 ...
bool unpackCopperLayer(const kiapi::board::types::PadStackLayer &aProto)
PAD_DRILL_SHAPE DrillShape() const
void SetChamferPositions(int aPositions, PCB_LAYER_ID aLayer)
POST_MACHINING_PROPS & FrontPostMachining()
DRILL_PROPS m_tertiaryDrill
! Tertiary drill, used to define back-drilling starting from the top side
void SetRoundRectRadius(double aRadius, PCB_LAYER_ID aLayer)
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()
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)
std::optional< bool > IsCapped() const
std::vector< PCB_LAYER_ID > UniqueLayers() const
void SetBackdrillEndLayer(bool aTop, PCB_LAYER_ID aLayer)
LSET m_layerSet
! The board layers that this padstack is active on
std::optional< int > GetBackdrillSize(bool aTop) const
std::unordered_map< PCB_LAYER_ID, COPPER_LAYER_PROPS > m_copperProps
! The properties applied to copper layers if they aren't overridden
BACKDRILL_MODE GetBackdrillMode() const
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
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.
DRILL_PROPS & SecondaryDrill()
double RoundRectRadiusRatio(PCB_LAYER_ID aLayer) const
PCB_LAYER_ID GetBackdrillEndLayer(bool aTop) const
PCB_LAYER_ID StartLayer() const
POST_MACHINING_PROPS & BackPostMachining()
POST_MACHINING_PROPS m_frontPostMachining
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
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)
@ NORMAL
Padstack for a footprint pad.
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
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.
PCB_LAYER_ID
A quick note on layer IDs:
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 VECTOR2I UnpackVector2(const types::Vector2 &aInput)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput)
#define TEST_OPT_ANGLE(a, b, v)
#define TEST_OPT(a, b, v)
PAD_DRILL_POST_MACHINING_MODE
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...
double Similarity(const COPPER_LAYER_PROPS &aOther) const
std::optional< ZONE_CONNECTION > zone_connection
int Compare(const COPPER_LAYER_PROPS &aOther) const
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)
std::optional< bool > is_capped
True if the drill hole should be capped.
std::optional< bool > is_filled
True if the drill hole should be filled completely.
int Compare(const DRILL_PROPS &aOther) const
bool operator==(const MASK_LAYER_PROPS &aOther) const
std::optional< int > solder_mask_margin
int Compare(const MASK_LAYER_PROPS &aOther) const
std::optional< bool > has_covering
True if the pad on this side should have covering.
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.
std::optional< bool > has_plugging
True if the drill hole should be plugged on this side.
std::optional< PAD_DRILL_POST_MACHINING_MODE > mode
bool operator==(const POST_MACHINING_PROPS &aOther) const
int Compare(const POST_MACHINING_PROPS &aOther) const
int chamfered_rect_positions
VECTOR2I trapezoid_delta_size
Delta for PAD_SHAPE::TRAPEZOID; half the delta squeezes one end and half expands the other.
int Compare(const SHAPE_PROPS &aOther) const
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.
VECTOR2< int32_t > VECTOR2I
@ NONE
Pads are not covered.