29#include <google/protobuf/any.pb.h>
30#include <magic_enum.hpp>
47#include <api/board/board_types.pb.h>
78 *
this = *
static_cast<const PCB_SHAPE*
>( aOther );
86 BoardGraphicShape msg;
90 msg.mutable_id()->set_value(
m_Uuid.AsStdString() );
91 msg.set_locked(
IsLocked() ? types::LockedState::LS_LOCKED : types::LockedState::LS_UNLOCKED );
93 google::protobuf::Any
any;
95 any.UnpackTo( msg.mutable_shape() );
99 aContainer.PackFrom( msg );
108 BoardGraphicShape msg;
110 if( !aContainer.UnpackTo( &msg ) )
126 SetLocked( msg.locked() == types::LS_LOCKED );
130 google::protobuf::Any
any;
131 any.PackFrom( msg.shape() );
145 bool sametype =
false;
147 for(
KICAD_T scanType : aScanTypes )
197 &&
GetBoard()->GetDesignSettings().m_DRCEngine->HasRulesForConstraintType(
214 margin =
board->GetDesignSettings().m_SolderMaskExpansion;
219 margin = std::max( margin, -
GetWidth() / 2 );
249 if( layermask.test(
F_Cu ) )
252 if( layermask.test(
B_Cu ) )
275 std::vector<VECTOR2I> ret;
291 ret.emplace_back( pt.m_point );
302 ret.emplace_back(
GetEnd() );
306 for(
auto iter =
GetPolyShape().CIterate(); iter; ++iter )
307 ret.emplace_back( *iter );
313 ret.emplace_back( pt );
321 const double cosPhi = std::cos( phi );
322 const double sinPhi = std::sin( phi );
340 const double cosPhi = std::cos( phi );
341 const double sinPhi = std::sin( phi );
344 auto eval = [&](
double theta ) ->
VECTOR2I
346 const double lx = a * std::cos( theta );
347 const double ly = b * std::sin( theta );
354 if( thetaEnd < thetaStart )
355 thetaEnd += 2.0 *
M_PI;
357 ret.emplace_back( eval( thetaStart ) );
358 ret.emplace_back( eval( thetaEnd ) );
359 ret.emplace_back( eval( 0.5 * ( thetaStart + thetaEnd ) ) );
397 item->TransformShapeToPolygon( knockouts, layer, margin, maxError,
ERROR_OUTSIDE );
410 if( item->GetLayer() == layer && item->GetBoundingBox().Intersects( bbox ) )
411 knockoutItem( item );
421 knockouts.
Append( footprint->GetCourtyard( layer ) );
424 footprint->RunOnChildren(
432 knockoutItem( item );
502 std::vector<VECTOR2I> pts;
513 pts.emplace_back( pt );
521 while( pts.size() < 4 )
522 pts.emplace_back( pts.back() +
VECTOR2I( 10, 10 ) );
558 return seg.A.y == seg.B.y;
564 return seg.A.x == seg.B.x;
572 if( horizontal( outline.
Segment( 0 ) )
573 && vertical( outline.
Segment( 1 ) )
574 && horizontal( outline.
Segment( 2 ) )
575 && vertical( outline.
Segment( 3 ) ) )
583 else if( vertical( outline.
Segment( 0 ) )
584 && horizontal( outline.
Segment( 1 ) )
585 && vertical( outline.
Segment( 2 ) )
586 && horizontal( outline.
Segment( 3 ) ) )
609 if( ( start.
x >
end.x )
610 || ( start.
x ==
end.x && start.
y <
end.y ) )
623 rotate( aRotCentre, aAngle );
629 flip( aCentre, aFlipDirection );
637 flip( aCentre, aFlipDirection );
643 PAD* parentPad =
nullptr;
649 for(
PAD*
pad : fp->Pads() )
651 if(
pad->IsEntered() )
707 checkLayer = parent->GetLayer();
722 std::vector<int> layers;
734 layers.push_back(
F_Mask );
736 layers.push_back(
B_Mask );
752 aList.emplace_back(
_(
"Footprint" ), parent->GetReference() );
755 aList.emplace_back(
_(
"Type" ),
_(
"Drawing" ) );
758 aList.emplace_back(
_(
"Status" ),
_(
"Locked" ) );
784 return wxString::Format(
_(
"%s %s of %s on %s" ),
792 return wxString::Format(
_(
"%s %s on %s" ),
802 return wxString::Format(
_(
"%s of %s on %s" ),
809 return wxString::Format(
_(
"%s on %s" ),
878 if( aFirst->
Type() != aSecond->
Type() )
879 return aFirst->
Type() < aSecond->
Type();
898 int aClearance,
int aError,
ERROR_LOC aErrorLoc,
899 bool ignoreLineWidth )
const
907 int aClearance,
int aError,
ERROR_LOC aErrorLoc,
921 return *
this == other;
967 double similarity = 1.0;
1013 if( layerEnum.
Choices().GetCount() == 0 )
1025 _HKI(
"Layer" ), shapeLayerSetter, shapeLayerGetter );
1030 auto isPolygonOrEllipse = [](
INSPECTABLE* aItem ) ->
bool
1034 const SHAPE_T t = shape->GetShape();
1041 isPolygonOrEllipse );
1043 isPolygonOrEllipse );
1050 auto isNotBezierOrEllipseArc = [](
INSPECTABLE* aItem ) ->
bool
1054 const SHAPE_T t = shape->GetShape();
1061 isNotBezierOrEllipseArc );
1072 auto isNotCircleOrEllipse = [](
INSPECTABLE* aItem ) ->
bool
1076 const SHAPE_T t = shape->GetShape();
1083 isNotCircleOrEllipse );
1085 isNotCircleOrEllipse );
1087 isNotCircleOrEllipse );
1089 isNotCircleOrEllipse );
1091 _HKI(
"Center X" ), isCircle );
1093 _HKI(
"Center Y" ), isCircle );
1095 _HKI(
"Radius" ), isCircle );
1101 return shape->IsOnCopperLayer();
1109 auto isPadEditMode =
1110 [](
BOARD* aBoard ) ->
bool
1112 if( aBoard && aBoard->IsFootprintHolder() )
1114 for(
FOOTPRINT* fp : aBoard->Footprints() )
1116 for(
PAD*
pad : fp->Pads() )
1118 if(
pad->IsEntered() )
1127 auto showNumberBoxProperty =
1133 return isPadEditMode( shape->GetBoard() );
1139 auto showSpokeTemplateProperty =
1145 return isPadEditMode( shape->GetBoard() );
1151 const wxString groupPadPrimitives =
_HKI(
"Pad Primitives" );
1156 groupPadPrimitives )
1162 groupPadPrimitives )
1166 const wxString groupTechLayers =
_HKI(
"Technical Layers" );
1168 auto isExternalCuLayer =
1171 if(
auto shape =
dynamic_cast<PCB_SHAPE*
>( aItem ) )
types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
constexpr EDA_IU_SCALE pcbIUScale
constexpr int ARC_LOW_DEF
BITMAPS
A list of all bitmap identifiers.
#define DEFAULT_LINE_WIDTH
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
wxString GetNetnameMsg() const
virtual bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
wxString GetNetname() const
BOARD_CONNECTED_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
void PackNet(kiapi::board::types::Net *aProto) const
NETINFO_ITEM * m_netinfo
Store all information about the net that item belongs to.
void UnpackNet(const kiapi::board::types::Net &aProto)
Assigns a net to this item from an API message.
Container for design settings for a BOARD object.
std::shared_ptr< DRC_ENGINE > m_DRCEngine
int GetLineThickness(PCB_LAYER_ID aLayer) const
Return the default graphic segment thickness from the layer class for the given layer.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
void SetUuidDirect(const KIID &aUuid)
Raw UUID assignment.
void SetLocked(bool aLocked) override
bool IsLocked() const override
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
virtual bool IsOnCopperLayer() const
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Information pertinent to a Pcbnew printed circuit board.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
constexpr const Vec & GetPosition() const
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr const Vec GetEnd() const
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Represent basic circle geometry with utility geometry functions.
The base class for create windows for drawing purpose.
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
KICAD_T Type() const
Returns the type of object.
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
EDA_ITEM * m_parent
Owner.
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
virtual int GetHatchLineSpacing() const
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false, bool includeFill=false) const
Convert the shape to a closed polygon.
int GetEllipseMinorRadius() const
const VECTOR2I & GetEllipseCenter() const
void rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle)
EDA_ANGLE GetEllipseEndAngle() const
int GetEllipseMajorRadius() const
virtual std::vector< SHAPE * > MakeEffectiveShapes(bool aEdgeOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
SHAPE_POLY_SET & GetPolyShape()
EDA_ANGLE GetEllipseRotation() const
void ShapeGetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
bool operator==(const EDA_SHAPE &aOther) const
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
void flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
EDA_SHAPE(SHAPE_T aType, int aLineWidth, FILL_T aFill)
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
void SetStart(const VECTOR2I &aStart)
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
void SwapShape(EDA_SHAPE *aImage)
std::vector< VECTOR2I > GetRectCorners() const
EDA_ANGLE GetEllipseStartAngle() const
virtual void UpdateHatching() const
void SetEnd(const VECTOR2I &aEnd)
wxString SHAPE_T_asString() const
double Similarity(const EDA_SHAPE &aOther) const
virtual int GetWidth() const
void SetWidth(int aWidth)
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
VECTOR2I GetArcMid() const
virtual bool IsVisible() const
ENUM_MAP & Map(T aValue, const wxString &aName)
static ENUM_MAP< T > & Instance()
ENUM_MAP & Undefined(T aValue)
Class that other classes need to inherit from, in order to be inspectable.
Contains methods for drawing PCB-specific items.
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
PCB specific render settings.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
PCB_LAYER_ID GetPrimaryHighContrastLayer() const
Return the board layer which is in high-contrast mode.
bool GetHighContrast() const
static constexpr double LOD_HIDE
Return this constant from ViewGetLOD() to hide the item unconditionally.
static constexpr double LOD_SHOW
Return this constant from ViewGetLOD() to show the item unconditionally.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
bool IsLayerVisibleCached(int aLayer) const
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
LSET is a set of PCB_LAYER_IDs.
void RunOnLayers(const std::function< void(PCB_LAYER_ID)> &aFunction) const
Execute a function on each layer of the LSET.
static const LSET & AllLayersMask()
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
std::optional< int > GetLocalThermalSpokeWidthOverride() const
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
virtual void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings, bool aCheckSide) override
void swapData(BOARD_ITEM *aImage) override
bool IsConnected() const override
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
SHAPE_POLY_SET getHatchingKnockouts() const override
std::optional< int > GetLocalSolderMaskMargin() const
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
PCB_SHAPE(BOARD_ITEM *aParent, KICAD_T aItemType, SHAPE_T aShapeType)
int GetWidth() const override
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
bool HasSolderMask() const
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const override
Make a set of SHAPE objects representing the PCB_SHAPE.
void SetHasSolderMask(bool aVal)
std::optional< int > m_solderMaskMargin
int GetSolderMaskExpansion() const
void NormalizeForCompare() override
Normalize coordinates to compare 2 similar PCB_SHAPES similat to Normalize(), but also normalize SEGM...
void TransformShapeToPolySet(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, KIGFX::RENDER_SETTINGS *aRenderSettings=nullptr) const override
Convert the item shape to a polyset.
const VECTOR2I GetFocusPosition() const override
Allows items to return their visual center rather than their anchor.
virtual void SetLayerSet(const LSET &aLayers) override
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
virtual std::vector< VECTOR2I > GetCorners() const
Return 4 corners for a rectangle or rotated rectangle (stored as a poly).
bool IsProxyItem() const override
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
bool operator==(const PCB_SHAPE &aShape) const
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
wxString GetFriendlyName() const override
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the shape to a closed polygon.
void SetIsProxyItem(bool aIsProxy=true) override
void SetLocalSolderMaskMargin(std::optional< int > aMargin)
void Move(const VECTOR2I &aMoveVector) override
Move this object.
std::vector< VECTOR2I > GetConnectionPoints() const
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
int getMaxError() const override
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
void UpdateHatching() const override
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
void Scale(double aScale)
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
void Normalize() override
Perform any normalization required after a user rotate and/or flip.
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
void CopyFrom(const BOARD_ITEM *aOther) override
std::vector< int > ViewGetLayers() const override
double Similarity(const BOARD_ITEM &aBoardItem) const override
Return a measure of how likely the other object is to represent the same object.
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
PROPERTY_BASE & SetIsHiddenFromRulesEditor(bool aHide=true)
Provide class metadata.Helper macro to map type hashes to names.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
void Mask(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName)
Sets a base class property as masked in a derived class.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void OverrideAvailability(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName, std::function< bool(INSPECTABLE *)> aFunc)
Sets an override availability functor for a base class property of a given derived class.
PROPERTY_BASE & ReplaceProperty(size_t aBase, const wxString &aName, PROPERTY_BASE *aNew, const wxString &aGroup=wxEmptyString)
Replace an existing property for a specific type.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
SEG Segment(int aIndex) const
Return a copy of the aIndex-th segment in the line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int OutlineCount() const
Return the number of outlines in the set.
A type-safe container of any type.
@ SOLDER_MASK_EXPANSION_CONSTRAINT
#define PCB_EDIT_FRAME_NAME
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
bool IsSolderMaskLayer(int aLayer)
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
int GetNetnameLayer(int aLayer)
Return a netname layer corresponding to the given layer.
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
@ LAYER_LOCKED_ITEM_SHADOW
Shadow layer for locked items.
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
bool IsExternalCopperLayer(int aLayerId)
Test whether a layer is an external (F_Cu or B_Cu) copper layer.
PCB_LAYER_ID
A quick note on layer IDs:
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
#define UNIMPLEMENTED_FOR(type)
std::vector< TYPED_POINT2I > GetCircleKeyPoints(const CIRCLE &aCircle, bool aIncludeCenter)
Get key points of an CIRCLE.
static struct PCB_SHAPE_DESC _PCB_SHAPE_DESC
static bool isCopper(const PNS::ITEM *aItem)
@ PT_SIZE
Size expressed in distance units (mm/inch)
Utility functions for working with shapes.
bool operator()(const BOARD_ITEM *aFirst, const BOARD_ITEM *aSecond) const
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
@ PCB_SHAPE_LOCATE_ELLIPSE_ARC_T
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_LOCATE_BOARD_EDGE_T
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
@ PCB_SHAPE_LOCATE_CIRCLE_T
@ PCB_SHAPE_LOCATE_SEGMENT_T
@ PCB_SHAPE_LOCATE_RECT_T
@ PCB_SHAPE_LOCATE_ELLIPSE_T
@ PCB_SHAPE_LOCATE_BEZIER_T
@ PCB_SHAPE_LOCATE_POLY_T
VECTOR2< int32_t > VECTOR2I
#define ZONE_THERMAL_RELIEF_COPPER_WIDTH_MM