42#include <api/board/board_types.pb.h>
48 m_borderEnabled( true )
69 using namespace kiapi::common::types;
71 types::BoardTextBox boardText;
72 boardText.set_layer( ToProtoEnum<PCB_LAYER_ID, types::BoardLayer>(
GetLayer() ) );
74 boardText.set_locked(
IsLocked() ? LockedState::LS_LOCKED : LockedState::LS_UNLOCKED );
76 TextBox&
text = *boardText.mutable_textbox();
83 TextAttributes* attrs =
text.mutable_attributes();
86 attrs->set_font_name(
GetFont()->GetName().ToStdString() );
88 attrs->set_horizontal_alignment(
89 ToProtoEnum<GR_TEXT_H_ALIGN_T, HorizontalAlignment>(
GetHorizJustify() ) );
91 attrs->set_vertical_alignment(
92 ToProtoEnum<GR_TEXT_V_ALIGN_T, VerticalAlignment>(
GetVertJustify() ) );
98 attrs->set_bold(
IsBold() );
106 aContainer.PackFrom( boardText );
113 types::BoardTextBox boardText;
115 if( !aContainer.UnpackTo( &boardText ) )
119 SetLayer( FromProtoEnum<PCB_LAYER_ID, types::BoardLayer>( boardText.layer() ) );
120 SetLocked( boardText.locked() == kiapi::common::types::LockedState::LS_LOCKED );
122 const kiapi::common::types::TextBox&
text = boardText.textbox();
126 SetText( wxString(
text.text().c_str(), wxConvUTF8 ) );
129 if(
text.has_attributes() )
142 if( !
text.attributes().font_name().empty() )
145 wxString(
text.attributes().font_name().c_str(), wxConvUTF8 ), attrs.
m_Bold,
153 FromProtoEnum<GR_TEXT_H_ALIGN_T, kiapi::common::types::HorizontalAlignment>(
154 text.attributes().horizontal_alignment() );
156 attrs.
m_Valign = FromProtoEnum<GR_TEXT_V_ALIGN_T, kiapi::common::types::VerticalAlignment>(
157 text.attributes().vertical_alignment() );
267 std::vector<VECTOR2I> pts;
307 for(
const VECTOR2I& corner : corners )
309 if( corner.x < minX.
x )
312 if( corner.x > maxX.
x )
315 if( corner.y < minY.
y )
318 if( corner.y > maxY.
y )
324 pts.emplace_back( minX );
325 pts.emplace_back( minY );
329 pts.emplace_back( maxY );
330 pts.emplace_back( minX );
334 pts.emplace_back( maxX );
335 pts.emplace_back( maxY );
339 pts.emplace_back( minY );
340 pts.emplace_back( maxX );
372 switch( effectiveAlignment )
375 textAnchor = corners[0];
379 textAnchor = ( corners[0] + corners[1] ) / 2;
383 textAnchor = corners[1];
387 wxFAIL_MSG( wxT(
"Indeterminate state legal only in dialogs." ) );
392 return textAnchor + offset;
398 constexpr double HIDE = std::numeric_limits<double>::max();
435 std::function<bool( wxString* )>
resolver = [&]( wxString* token ) ->
bool
437 if( parentFootprint && parentFootprint->
ResolveTextVar( token, aDepth + 1 ) )
440 if( token->IsSameAs( wxT(
"LAYER" ) ) )
462 int colWidth = ( corners[1] - corners[0] ).EuclideanNorm();
487 aList.emplace_back(
_(
"Status" ),
_(
"Locked" ) );
490 aList.emplace_back(
_(
"Mirror" ),
IsMirrored() ?
_(
"Yes" ) :
_(
"No" ) );
491 aList.emplace_back(
_(
"Angle" ), wxString::Format(
"%g",
GetTextAngle().AsDegrees() ) );
493 aList.emplace_back(
_(
"Font" ),
GetFont() ?
GetFont()->GetName() :
_(
"Default" ) );
498 aList.emplace_back(
_(
"Box Width" ),
501 aList.emplace_back(
_(
"Box Height" ),
523 VECTOR2I diag = corners[2] - corners[0];
532 SetEnd(
VECTOR2I( corners[0].x + abs( diag.
x ), corners[0].y - abs( diag.
y ) ) );
534 SetEnd(
VECTOR2I( corners[0].x - abs( diag.
x ), corners[0].y - abs( diag.
y ) ) );
536 SetEnd(
VECTOR2I( corners[0].x - abs( diag.
x ), corners[0].y + abs( diag.
y ) ) );
538 SetEnd(
VECTOR2I( corners[0].x + abs( diag.
x ), corners[0].y + abs( diag.
y ) ) );
548 if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
591 return wxString::Format(
_(
"PCB Text Box '%s' on %s" ),
599 return BITMAPS::add_textbox;
653 for(
const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
654 buffer.
Append( point.x, point.y );
662 aClearance += aMaxError;
664 buffer.
Inflate( aClearance, CORNER_STRATEGY::ROUND_ALL_CORNERS, aMaxError,
true );
676 int aClearance,
int aMaxError,
ERROR_LOC aErrorLoc,
677 bool aIgnoreLineWidth )
const
682 int width =
GetWidth() + ( 2 * aClearance );
684 if(
GetShape() == SHAPE_T::RECTANGLE )
702 else if(
GetShape() == SHAPE_T::POLY )
708 for(
int ii = 0; ii < poly.
PointCount(); ++ii )
748 return *
this == other;
766 double similarity = 1.0;
795 if( plotDashTypeEnum.
Choices().GetCount() == 0 )
797 plotDashTypeEnum.
Map( LINE_STYLE::DEFAULT,
_HKI(
"Default" ) )
798 .
Map( LINE_STYLE::SOLID,
_HKI(
"Solid" ) )
799 .
Map( LINE_STYLE::DASH,
_HKI(
"Dashed" ) )
800 .
Map( LINE_STYLE::DOT,
_HKI(
"Dotted" ) )
801 .
Map( LINE_STYLE::DASHDOT,
_HKI(
"Dash-Dot" ) )
802 .
Map( LINE_STYLE::DASHDOTDOT,
_HKI(
"Dash-Dot-Dot" ) );
825 const wxString borderProps =
_(
"Border Properties" );
835 lineStyleSetter, lineStyleGetter ),
840 PROPERTY_DISPLAY::PT_SIZE ),
843 const wxString marginProps =
_(
"Margins" );
847 PROPERTY_DISPLAY::PT_SIZE ),
851 PROPERTY_DISPLAY::PT_SIZE ),
855 PROPERTY_DISPLAY::PT_SIZE ),
859 PROPERTY_DISPLAY::PT_SIZE ),
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
BITMAPS
A list of all bitmap identifiers.
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
Container for design settings for a BOARD object.
bool GetTextUpright(PCB_LAYER_ID aLayer) const
int GetTextThickness(PCB_LAYER_ID aLayer) const
Return the default text thickness from the layer class for the given layer.
bool GetTextItalic(PCB_LAYER_ID aLayer) const
VECTOR2I GetTextSize(PCB_LAYER_ID aLayer) const
Return the default text size 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 void SetLocked(bool aLocked)
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
const KIFONT::METRICS & GetFontMetrics() const
virtual bool IsLocked() const
bool IsSideSpecific() const
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Information pertinent to a Pcbnew printed circuit board.
bool ResolveTextVar(wxString *token, int aDepth) const
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
constexpr coord_type GetLeft() const
constexpr bool Contains(const Vec &aPoint) const
constexpr coord_type GetRight() const
constexpr coord_type GetTop() const
constexpr bool Intersects(const BOX2< Vec > &aRect) const
constexpr coord_type GetBottom() const
bool IsHorizontal() const
EDA_ANGLE Normalized() const
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 Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
void SetLineStyle(const LINE_STYLE aStyle)
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)
std::vector< VECTOR2I > GetRectCorners() const
void SetEnd(const VECTOR2I &aEnd)
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
int GetTextHeight() const
const EDA_ANGLE & GetTextAngle() const
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
bool IsMultilineAllowed() const
virtual const wxString & GetText() const
Return the string associated with the text object.
bool IsKeepUpright() const
KIFONT::FONT * GetFont() const
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
void SetMirrored(bool isMirrored)
virtual EDA_ANGLE GetDrawRotation() const
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
void Offset(const VECTOR2I &aOffset)
GR_TEXT_H_ALIGN_T GetHorizJustify() const
bool HasTextVars() const
Indicates the ShownText has text var references which need to be processed.
virtual KIFONT::FONT * getDrawFont() const
double GetLineSpacing() const
double Similarity(const EDA_TEXT &aOther) const
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
const TEXT_ATTRIBUTES & GetAttributes() const
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
double GetTextAngleDegrees() const
std::shared_ptr< SHAPE_COMPOUND > GetEffectiveTextShape(bool aTriangulate=true, const BOX2I &aBBox=BOX2I(), const EDA_ANGLE &aAngle=ANGLE_0) const
build a list of segments (SHAPE_SEGMENT) to describe a text shape.
void SetKeepUpright(bool aKeepUpright)
GR_TEXT_V_ALIGN_T GetVertJustify() const
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
virtual void SetText(const wxString &aText)
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
int GetTextThickness() const
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
bool operator==(const EDA_TEXT &aRhs) const
void SetMultilineAllowed(bool aAllow)
VECTOR2I GetTextSize() const
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
ENUM_MAP & Map(T aValue, const wxString &aName)
static ENUM_MAP< T > & Instance()
FONT is an abstract base class for both outline and stroke fonts.
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttributes, const METRICS &aFontMetrics) const
Draw a string.
void LinebreakText(wxString &aText, int aColumnWidth, const VECTOR2I &aGlyphSize, int aThickness, bool aBold, bool aItalic) const
Insert characters into text to ensure that no lines are wider than aColumnWidth.
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
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 Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
int GetWidth() const override
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 SetPosition(const VECTOR2I &aPos) 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).
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
STROKE_PARAMS GetStroke() const override
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings) override
void Move(const VECTOR2I &aMoveVector) override
Move this object.
VECTOR2I GetPosition() const override
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
bool HitTest(const VECTOR2I &aPosition, int aAccuracy) const override
Test if aPosition is inside or on the boundary of this item.
virtual void swapData(BOARD_ITEM *aImage) override
void SetBorderWidth(const int aSize)
double Similarity(const BOARD_ITEM &aBoardItem) const override
Return a measure of how likely the other object is to represent the same object.
bool IsBorderEnabled() const
Disables the border, this is done by changing the stroke internally.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
int GetMarginBottom() const
PCB_TEXTBOX(BOARD_ITEM *aParent, KICAD_T aType=PCB_TEXTBOX_T)
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth=false) const override
Convert the shape to a closed polygon.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
bool m_borderEnabled
Controls drawing the border (as defined by the stroke members)
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
void SetBorderEnabled(bool enabled)
void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
void TransformTextToPolySet(SHAPE_POLY_SET &aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc) const
Function TransformTextToPolySet Convert the text to a polygonSet describing the actual character stro...
std::vector< VECTOR2I > GetAnchorAndOppositeCorner() const
EDA_ITEM * Clone() const override
Tests whether the border is disabled, as configured by the stroke.
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.
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
VECTOR2I GetDrawPos() const override
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
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 SetMarginTop(int aTop)
void SetLeft(int aVal) override
int GetMarginLeft() const
void SetMarginLeft(int aLeft)
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
void SetMarginBottom(int aBottom)
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
int GetMarginRight() const
void SetRight(int aVal) override
std::vector< int > ViewGetLayers() const override
void SetTop(int aVal) override
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
void SetTextAngle(const EDA_ANGLE &aAngle) override
bool operator==(const PCB_TEXTBOX &aOther) const
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
void SetMarginRight(int aRight)
void Move(const VECTOR2I &aMoveVector) override
Move this object.
int GetLegacyTextMargin() const
void SetBottom(int aVal) override
VECTOR2I GetTopLeft() const override
VECTOR2I GetBotRight() const override
bool IsVisible() const override
int GetBorderWidth() const
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings) override
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 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...
virtual const VECTOR2I GetPoint(int aIndex) const override
int PointCount() const
Return the number of points (vertices) in this line chain.
virtual const SEG GetSegment(int aIndex) const override
int SegmentCount() const
Return the number of segments in this line chain.
Represent a set of closed polygons.
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
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)
void Simplify(POLYGON_MODE aFastMode)
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFastMo...
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int NewOutline()
Creates a new empty polygon in the set and returns its index.
void SetWidth(int aWidth)
void GetMsgPanelInfo(UNITS_PROVIDER *aUnitsProvider, std::vector< MSG_PANEL_ITEM > &aList, bool aIncludeStyle=true, bool aIncludeWidth=true)
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_90
static constexpr EDA_ANGLE ANGLE_270
static constexpr EDA_ANGLE ANGLE_180
#define PCB_EDIT_FRAME_NAME
static FILENAME_RESOLVER * resolver
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.
@ LAYER_LOCKED_ITEM_SHADOW
shadow layer for locked items
PCB_LAYER_ID
A quick note on layer IDs:
This file contains miscellaneous commonly used macros and functions.
KICOMMON_API wxString EllipsizeMenuText(const wxString &aString)
Ellipsize text (at the end) to be no more than 36 characters.
KICOMMON_API wxString EllipsizeStatusText(wxWindow *aWindow, const wxString &aString)
Ellipsize text (at the end) to be no more than 1/3 of the window width.
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
static struct PCB_TEXTBOX_DESC _PCB_TEXTBOX_DESC
wxString UnescapeString(const wxString &aSource)
LINE_STYLE
Dashed line types.
@ GR_TEXT_H_ALIGN_INDETERMINATE
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
VECTOR2< int32_t > VECTOR2I