27#include <google/protobuf/any.pb.h>
28#include <magic_enum.hpp>
42#include <api/board/board_types.pb.h>
68 kiapi::board::types::GraphicShape msg;
71 msg.set_layer( ToProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>(
GetLayer() ) );
72 msg.set_locked(
IsLocked() ? kiapi::common::types::LockedState::LS_LOCKED
73 : kiapi::common::types::LockedState::LS_UNLOCKED );
74 msg.mutable_net()->mutable_code()->set_value(
GetNetCode() );
77 kiapi::common::types::StrokeAttributes* stroke
78 = msg.mutable_attributes()->mutable_stroke();
79 kiapi::common::types::GraphicFillAttributes* fill = msg.mutable_attributes()->mutable_fill();
81 stroke->mutable_width()->set_value_nm(
GetWidth() );
85 case LINE_STYLE::DEFAULT: stroke->set_style( kiapi::common::types::SLS_DEFAULT );
break;
86 case LINE_STYLE::SOLID: stroke->set_style( kiapi::common::types::SLS_SOLID );
break;
87 case LINE_STYLE::DASH: stroke->set_style( kiapi::common::types::SLS_DASH );
break;
88 case LINE_STYLE::DOT: stroke->set_style( kiapi::common::types::SLS_DOT );
break;
89 case LINE_STYLE::DASHDOT: stroke->set_style( kiapi::common::types::SLS_DASHDOT );
break;
90 case LINE_STYLE::DASHDOTDOT: stroke->set_style( kiapi::common::types::SLS_DASHDOTDOT );
break;
96 case FILL_T::FILLED_SHAPE: fill->set_fill_type( kiapi::common::types::GFT_FILLED );
break;
97 default: fill->set_fill_type( kiapi::common::types::GFT_UNFILLED );
break;
102 case SHAPE_T::SEGMENT:
104 kiapi::board::types::GraphicSegmentAttributes* segment = msg.mutable_segment();
110 case SHAPE_T::RECTANGLE:
112 kiapi::board::types::GraphicRectangleAttributes* rectangle = msg.mutable_rectangle();
120 kiapi::board::types::GraphicArcAttributes* arc = msg.mutable_arc();
127 case SHAPE_T::CIRCLE:
129 kiapi::board::types::GraphicCircleAttributes* circle = msg.mutable_circle();
137 kiapi::common::types::PolySet* polyset = msg.mutable_polygon();
146 kiapi::common::types::PolygonWithHoles* polyMsg = polyset->mutable_polygons()->Add();
149 if( poly.size() > 1 )
151 for(
size_t hole = 1; hole < poly.size(); ++hole )
153 kiapi::common::types::PolyLine* pl = polyMsg->mutable_holes()->Add();
161 case SHAPE_T::BEZIER:
163 kiapi::board::types::GraphicBezierAttributes* bezier = msg.mutable_bezier();
172 wxASSERT_MSG(
false,
"Unhandled shape in PCB_SHAPE::Serialize" );
175 aContainer.PackFrom( msg );
181 kiapi::board::types::GraphicShape msg;
183 if( !aContainer.UnpackTo( &msg ) )
199 SetLocked( msg.locked() == kiapi::common::types::LS_LOCKED );
200 SetLayer( FromProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( msg.layer() ) );
203 SetFilled( msg.attributes().fill().fill_type() == kiapi::common::types::GFT_FILLED );
204 SetWidth( msg.attributes().stroke().width().value_nm() );
206 switch( msg.attributes().stroke().style() )
208 case kiapi::common::types::SLS_DEFAULT:
SetLineStyle( LINE_STYLE::DEFAULT );
break;
209 case kiapi::common::types::SLS_SOLID:
SetLineStyle( LINE_STYLE::SOLID );
break;
210 case kiapi::common::types::SLS_DASH:
SetLineStyle( LINE_STYLE::DASH );
break;
211 case kiapi::common::types::SLS_DOT:
SetLineStyle( LINE_STYLE::DOT );
break;
212 case kiapi::common::types::SLS_DASHDOT:
SetLineStyle( LINE_STYLE::DASHDOT );
break;
213 case kiapi::common::types::SLS_DASHDOTDOT:
SetLineStyle( LINE_STYLE::DASHDOTDOT );
break;
217 if( msg.has_segment() )
223 else if( msg.has_rectangle() )
229 else if( msg.has_arc() )
236 else if( msg.has_circle() )
242 else if( msg.has_polygon() )
245 const auto& polyMsg = msg.polygon().polygons();
249 for(
const kiapi::common::types::PolygonWithHoles& polygonWithHoles : polyMsg )
255 for(
const kiapi::common::types::PolyLine& holeMsg : polygonWithHoles.holes() )
263 else if( msg.has_bezier() )
281 bool sametype =
false;
283 for(
KICAD_T scanType : aScanTypes )
288 sametype =
m_shape == SHAPE_T::ARC;
290 sametype =
m_shape == SHAPE_T::CIRCLE;
292 sametype =
m_shape == SHAPE_T::RECTANGLE;
294 sametype =
m_shape == SHAPE_T::SEGMENT;
296 sametype =
m_shape == SHAPE_T::POLY;
298 sametype =
m_shape == SHAPE_T::BEZIER;
326 std::vector<VECTOR2I> ret;
341 case SHAPE_T::SEGMENT:
342 case SHAPE_T::BEZIER:
344 ret.emplace_back(
GetEnd() );
348 for(
auto iter =
GetPolyShape().CIterate(); iter; ++iter )
349 ret.emplace_back( *iter );
353 case SHAPE_T::RECTANGLE:
355 ret.emplace_back( pt );
390 case SHAPE_T::CIRCLE:
396 case SHAPE_T::RECTANGLE:
416 case SHAPE_T::BEZIER:
427 std::vector<VECTOR2I> pts;
429 if(
GetShape() == SHAPE_T::RECTANGLE )
433 else if(
GetShape() == SHAPE_T::POLY )
438 pts.emplace_back( pt );
446 while( pts.size() < 4 )
447 pts.emplace_back( pts.back() +
VECTOR2I( 10, 10 ) );
467 if(
m_shape == SHAPE_T::RECTANGLE )
472 BOX2I rect( start, end - start );
478 else if(
m_shape == SHAPE_T::POLY )
483 return seg.A.y == seg.B.y;
489 return seg.A.x == seg.B.x;
497 if( horizontal( outline.
Segment( 0 ) )
498 && vertical( outline.
Segment( 1 ) )
499 && horizontal( outline.
Segment( 2 ) )
500 && vertical( outline.
Segment( 3 ) ) )
508 else if( vertical( outline.
Segment( 0 ) )
509 && horizontal( outline.
Segment( 1 ) )
510 && vertical( outline.
Segment( 2 ) )
511 && horizontal( outline.
Segment( 3 ) ) )
526 rotate( aRotCentre, aAngle );
532 flip( aCentre, aFlipLeftRight );
546 case SHAPE_T::SEGMENT:
547 case SHAPE_T::RECTANGLE:
548 case SHAPE_T::CIRCLE:
549 case SHAPE_T::BEZIER:
550 if( aMirrorAroundXAxis )
576 m_poly.
Mirror( !aMirrorAroundXAxis, aMirrorAroundXAxis, aCentre );
587 PAD* parentPad =
nullptr;
593 for(
PAD*
pad : fp->Pads() )
595 if(
pad->IsEntered() )
606 if(
GetShape() == SHAPE_T::SEGMENT )
629 constexpr double HIDE = std::numeric_limits<double>::max();
630 constexpr double SHOW = 0.0;
686 aList.emplace_back(
_(
"Footprint" ), parent->GetReference() );
689 aList.emplace_back(
_(
"Type" ),
_(
"Drawing" ) );
692 aList.emplace_back(
_(
"Status" ),
_(
"Locked" ) );
717 return BITMAPS::show_mod_edge;
719 return BITMAPS::add_dashed_line;
767 if( aFirst->
Type() != aSecond->
Type() )
768 return aFirst->
Type() < aSecond->
Type();
787 int aClearance,
int aError,
ERROR_LOC aErrorLoc,
788 bool ignoreLineWidth )
const
830 double similarity = 1.0;
870 if( layerEnum.
Choices().GetCount() == 0 )
882 _HKI(
"Layer" ), shapeLayerSetter, shapeLayerGetter );
892 return shape->GetShape() == SHAPE_T::POLY;
898 _HKI(
"Position X" ), isPolygon );
900 _HKI(
"Position Y" ), isPolygon );
909 return shape->IsOnCopperLayer();
918 [](
BOARD* aBoard ) ->
bool
920 if( aBoard && aBoard->IsFootprintHolder() )
922 for(
FOOTPRINT* fp : aBoard->Footprints() )
924 for(
PAD*
pad : fp->Pads() )
926 if(
pad->IsEntered() )
935 auto showNumberBoxProperty =
940 if( shape->GetShape() == SHAPE_T::RECTANGLE )
941 return isPadEditMode( shape->GetBoard() );
947 auto showSpokeTemplateProperty =
952 if( shape->GetShape() == SHAPE_T::SEGMENT )
953 return isPadEditMode( shape->GetBoard() );
959 const wxString groupPadPrimitives =
_HKI(
"Pad Primitives" );
constexpr EDA_IU_SCALE pcbIUScale
BITMAPS
A list of all bitmap identifiers.
#define DEFAULT_LINE_WIDTH
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
wxString GetNetnameMsg() const
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
wxString GetNetname() const
NETINFO_ITEM * m_netinfo
Store all information about the net that item belongs to.
Container for design settings for a BOARD object.
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...
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual void SetLocked(bool aLocked)
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 IsLocked() 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.
BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
const Vec & GetPosition() const
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
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
Linked list: Link (parent struct)
const VECTOR2I & GetBezierC2() const
void SetBezierC2(const VECTOR2I &aPt)
void rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle)
void flip(const VECTOR2I &aCentre, bool aFlipLeftRight)
FILL_T GetFillMode() const
void RebuildBezierToSegmentsPointsList(int aMinSegLen)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
void SetLineStyle(const LINE_STYLE aStyle)
virtual std::vector< SHAPE * > MakeEffectiveShapes(bool aEdgeOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
SHAPE_POLY_SET & GetPolyShape()
void ShapeGetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
void SetFilled(bool aFlag)
bool operator==(const EDA_SHAPE &aOther) const
void SetPolyShape(const SHAPE_POLY_SET &aShape)
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
void SetStart(const VECTOR2I &aStart)
LINE_STYLE GetLineStyle() const
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
void SetShape(SHAPE_T aShape)
void SwapShape(EDA_SHAPE *aImage)
std::vector< VECTOR2I > GetRectCorners() const
void SetEnd(const VECTOR2I &aEnd)
void SetBezierC1(const VECTOR2I &aPt)
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Set the three controlling points for an arc.
wxString SHAPE_T_asString() const
double Similarity(const EDA_SHAPE &aOther) const
const VECTOR2I & GetBezierC1() const
virtual int GetWidth() const
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const
Convert the shape to a closed polygon.
void SetWidth(int aWidth)
VECTOR2I GetArcMid() 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.
PCB_LAYER_ID GetPrimaryHighContrastLayer() const
Return the board layer which is in high-contrast mode.
bool GetHighContrast() const
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
std::string AsStdString() const
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
static LSET AllLayersMask()
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
int GetThermalSpokeWidth() const
bool operator==(const BOARD_ITEM &aBoardItem) const override
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 swapData(BOARD_ITEM *aImage) override
bool IsConnected() const override
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
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.
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 ViewGetLayers(int aLayers[], int &aCount) const override
const VECTOR2I GetFocusPosition() const override
Allows items to return their visual center rather than their anchor.
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
virtual std::vector< VECTOR2I > GetCorners() const
Return 4 corners for a rectangle or rotated rectangle (stored as a poly).
bool IsProxyItem() const override
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 StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings) override
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.
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
virtual void Mirror(const VECTOR2I &aCentre, bool aMirrorAroundXAxis)
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.
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.
int SegmentCount() const
Return the number of segments in this line chain.
const std::vector< VECTOR2I > & CPoints() const
Represent a set of closed polygons.
POLYGON & Polygon(int aIndex)
Return the aIndex-th subpolygon in the set.
int AddPolygon(const POLYGON &apolygon)
Adds a polygon to the set.
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
void Mirror(bool aX=true, bool aY=false, const VECTOR2I &aRef={ 0, 0 })
Mirror the line points about y or x (or both)
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.
void SetWidth(int aWidth)
#define PCB_EDIT_FRAME_NAME
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
int GetNetnameLayer(int aLayer)
Returns a netname layer corresponding to the given layer.
@ LAYER_LOCKED_ITEM_SHADOW
shadow layer for locked items
@ LAYER_FOOTPRINTS_FR
show footprints on front
@ LAYER_FOOTPRINTS_BK
show footprints on back
PCB_LAYER_ID
A quick note on layer IDs:
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
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)
void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
void PackVector2(kiapi::common::types::Vector2 &aOutput, const VECTOR2I aInput)
VECTOR2I UnpackVector2(const types::Vector2 &aInput)
void PackPolyLine(kiapi::common::types::PolyLine &aOutput, const SHAPE_LINE_CHAIN &aSlc)
SHAPE_LINE_CHAIN UnpackPolyLine(const kiapi::common::types::PolyLine &aInput)
static struct PCB_SHAPE_DESC _PCB_SHAPE_DESC
static bool isCopper(const PNS::ITEM *aItem)
constexpr int mmToIU(double mm) const
bool operator()(const BOARD_ITEM *aFirst, const BOARD_ITEM *aSecond) const
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_LOCATE_BOARD_EDGE_T
@ PCB_SHAPE_LOCATE_CIRCLE_T
@ PCB_SHAPE_LOCATE_SEGMENT_T
@ PCB_SHAPE_LOCATE_RECT_T
@ PCB_SHAPE_LOCATE_BEZIER_T
@ PCB_SHAPE_LOCATE_POLY_T
#define ZONE_THERMAL_RELIEF_COPPER_WIDTH_MM