KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_text.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2004 Jean-Pierre Charras, [email protected]
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <memory>
24
25#include <board_item.h>
26#include <eda_text.h>
28
29
30class LINE_READER;
31class MSG_PANEL_ITEM;
32class FOOTPRINT;
34
35namespace kiapi::board::types
36{
37 class BoardText;
38}
39
40
49
50
51class PCB_TEXT : public BOARD_ITEM, public EDA_TEXT
52{
53public:
54 PCB_TEXT( BOARD_ITEM* parent, KICAD_T idtype = PCB_TEXT_T );
55
56 PCB_TEXT( FOOTPRINT* aParent, KICAD_T idtype = PCB_TEXT_T );
57
58 PCB_TEXT( const PCB_TEXT& aOther );
59 PCB_TEXT& operator=( const PCB_TEXT& aOther );
60
61 PCB_TEXT( PCB_TEXT&& ) noexcept = default;
62 PCB_TEXT& operator=( PCB_TEXT&& ) noexcept = default;
63
64 ~PCB_TEXT();
65
66 void CopyFrom( const BOARD_ITEM* aOther ) override;
67
68 static bool ClassOf( const EDA_ITEM* aItem ) { return aItem && PCB_TEXT_T == aItem->Type(); }
69
70 bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
71 {
72 if( BOARD_ITEM::IsType( aScanTypes ) )
73 return true;
74
75 for( KICAD_T scanType : aScanTypes )
76 {
77 if( scanType == PCB_LOCATE_TEXT_T )
78 return true;
79 }
80
81 return false;
82 }
83
84 void Serialize( google::protobuf::Any& aContainer ) const override;
85 bool Deserialize( const google::protobuf::Any& aContainer ) override;
86
87 void Serialize( kiapi::board::types::BoardText& aOutput ) const;
88 bool Deserialize( const kiapi::board::types::BoardText& aInput );
89
90 void StyleFromSettings( const BOARD_DESIGN_SETTINGS& aSettings, bool aCheckSide ) override;
91
95 void KeepUpright();
96
97 wxString GetShownText( RESOLUTION_CONTEXT aContext, int aDepth = 0 ) const override;
98
99 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
100
101 VECTOR2I GetPosition() const override { return GetTextPos(); }
102
103 void SetPosition( const VECTOR2I& aPos ) override { SetTextPos( aPos ); }
104
105 void Move( const VECTOR2I& aMoveVector ) override { Offset( aMoveVector ); }
106
107 VECTOR2I GetTextPos() const override;
108 void Offset( const VECTOR2I& aOffset ) override;
109
110 // Lib-frame setters for the parser (board-frame setters bake the parent scale).
111 void SetLibTextPos( const VECTOR2I& aPos );
112 void SetLibTextSize( const VECTOR2I& aSize );
113 void SetLibTextThickness( int aWidth );
114
115 VECTOR2I GetTextSize() const override;
116 void SetTextSize( VECTOR2I aNewSize, bool aEnforceMinTextSize = true ) override;
117
118 int GetTextThickness() const override;
119 void SetTextThickness( int aWidth ) override;
120
121 EDA_ANGLE GetTextAngle() const override;
122 void SetTextAngle( const EDA_ANGLE& aAngle ) override;
123
128 EDA_ANGLE GetLibTextAngle() const { return m_libTextAngle.GetAngle(); }
129
130 void SetLibTextAngle( const EDA_ANGLE& aAngle ) { m_libTextAngle = aAngle; }
131
132 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
133
134 void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
135
136 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
137
138 void OnFootprintRescaled( double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I& aAnchor,
139 const EDA_ANGLE& aParentRotate ) override;
140
141 void OnFootprintTransformed() override;
142
143 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
144
145 bool TextHitTest( const VECTOR2I& aPoint, int aAccuracy = 0 ) const override;
146 bool TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy = 0 ) const override;
147 bool TextHitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const;
148
149 bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override
150 {
151 return TextHitTest( aPosition, aAccuracy );
152 }
153
154 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override
155 {
156 return TextHitTest( aRect, aContained, aAccuracy );
157 }
158
159 bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const override
160 {
161 return TextHitTest( aPoly, aContained );
162 }
163
164 wxString GetClass() const override { return wxT( "PCB_TEXT" ); }
165
175 void TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc ) const;
176
177 double GetCoverageArea( int aTextMargin ) const override;
178
179 void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError,
180 ERROR_LOC aErrorLoc, bool aIgnoreLineWidth = false ) const override;
181
182 // @copydoc BOARD_ITEM::GetEffectiveShape
183 std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
185 DRC_CONSTRAINT_T aUsage = NULL_CONSTRAINT ) const override;
186
187 const SHAPE_POLY_SET& GetKnockoutCache( const KIFONT::FONT* aFont, const wxString& forResolvedText,
188 int aMaxError ) const;
189
190 virtual wxString GetTextTypeDescription() const;
191
192 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
193
194 BITMAPS GetMenuImage() const override;
195
201 static HTML_MESSAGE_BOX* ShowSyntaxHelp( wxWindow* aParentWindow );
202
206 EDA_ANGLE GetDrawRotation() const override;
207
208 const BOX2I ViewBBox() const override;
209
210 std::vector<int> ViewGetLayers() const override;
211
212 double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
213
214 const BOX2I GetBoundingBox() const override;
215
216 EDA_ITEM* Clone() const override;
217
218 double Similarity( const BOARD_ITEM& aBoardItem ) const override;
219
220 bool operator==( const PCB_TEXT& aOther ) const;
221 bool operator==( const BOARD_ITEM& aBoardItem ) const override;
222
223#if defined( DEBUG )
224 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
225#endif
226
227protected:
232 void buildBoundingHull( SHAPE_POLY_SET* aBuffer, const SHAPE_POLY_SET& aRenderedText, int aClearance ) const;
233
234 void swapData( BOARD_ITEM* aImage ) override;
235
236 int getKnockoutMargin() const;
237
238 const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
239
240private:
241 mutable std::unique_ptr<PCB_TEXT_KNOCKOUT_CACHE_DATA> m_knockout_cache;
242
243 EDA_ORIENTATION m_libTextAngle; // Text angle in parent footprint's lib frame
244};
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
Container for design settings for a BOARD object.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:85
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:87
const KIFONT::METRICS & GetFontMetrics() 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.
Definition eda_item.h:98
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition eda_item.h:214
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
An "orientation", held as an angle constrained to the range [0, 360) degrees.
Definition eda_angle.h:473
virtual void SetTextPos(const VECTOR2I &aPoint)
Definition eda_text.cpp:556
EDA_TEXT(const EDA_IU_SCALE &aIuScale, const wxString &aText=wxEmptyString)
Definition eda_text.cpp:98
FONT is an abstract base class for both outline and stroke fonts.
Definition font.h:94
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:68
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition richio.h:65
EDA_MSG_PANEL items for displaying messages.
Definition msgpanel.h:50
void CopyFrom(const BOARD_ITEM *aOther) override
Definition pcb_text.cpp:107
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.
Definition pcb_text.cpp:312
double Similarity(const BOARD_ITEM &aBoardItem) const override
Return a measure of how likely the other object is to represent the same object.
Definition pcb_text.cpp:888
EDA_ANGLE GetLibTextAngle() const
Text angle in the parent footprint's lib frame, or absolute when not in a footprint.
Definition pcb_text.h:128
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth=false) const override
Convert the item shape to a closed polygon.
Definition pcb_text.cpp:860
void SetTextThickness(int aWidth) override
The TextThickness is that set by the user.
Definition pcb_text.cpp:512
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition pcb_text.cpp:675
const KIFONT::METRICS & getFontMetrics() const override
Definition pcb_text.h:238
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &aSettings, bool aCheckSide) override
Definition pcb_text.cpp:371
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition pcb_text.cpp:242
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
Definition pcb_text.cpp:631
EDA_ANGLE GetTextAngle() const override
Definition pcb_text.cpp:560
void swapData(BOARD_ITEM *aImage) override
Definition pcb_text.cpp:701
bool HitTest(const VECTOR2I &aPosition, int aAccuracy) const override
Test if aPosition is inside or on the boundary of this item.
Definition pcb_text.h:149
void KeepUpright()
Called when rotating the parent footprint.
Definition pcb_text.cpp:390
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition pcb_text.cpp:214
double GetCoverageArea(int aTextMargin) const override
Return the board area this item covers, used to rank candidates under the cursor so a click on a smal...
Definition pcb_text.cpp:852
void Offset(const VECTOR2I &aOffset) override
Definition pcb_text.cpp:525
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition pcb_text.cpp:139
bool HitTest(const BOX2I &aRect, bool aContained, int aAccuracy=0) const override
Test if aRect intersects this item.
Definition pcb_text.h:154
void SetLibTextAngle(const EDA_ANGLE &aAngle)
Definition pcb_text.h:130
const SHAPE_POLY_SET & GetKnockoutCache(const KIFONT::FONT *aFont, const wxString &forResolvedText, int aMaxError) const
Definition pcb_text.cpp:724
void SetLibTextThickness(int aWidth)
Definition pcb_text.cpp:554
void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
Definition pcb_text.cpp:595
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition pcb_text.cpp:257
static bool ClassOf(const EDA_ITEM *aItem)
Definition pcb_text.h:68
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true) override
Definition pcb_text.cpp:484
EDA_ORIENTATION m_libTextAngle
Definition pcb_text.h:243
void SetLibTextSize(const VECTOR2I &aSize)
Definition pcb_text.cpp:548
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition pcb_text.h:70
VECTOR2I GetTextPos() const override
Definition pcb_text.cpp:461
VECTOR2I GetPosition() const override
Definition pcb_text.h:101
PCB_TEXT(BOARD_ITEM *parent, KICAD_T idtype=PCB_TEXT_T)
Definition pcb_text.cpp:49
std::unique_ptr< PCB_TEXT_KNOCKOUT_CACHE_DATA > m_knockout_cache
Definition pcb_text.h:241
void SetPosition(const VECTOR2I &aPos) override
Definition pcb_text.h:103
PCB_TEXT(PCB_TEXT &&) noexcept=default
bool operator==(const PCB_TEXT &aOther) const
Definition pcb_text.cpp:882
bool HitTest(const SHAPE_LINE_CHAIN &aPoly, bool aContained) const override
Test if aPoly intersects this item.
Definition pcb_text.h:159
int getKnockoutMargin() const
Definition pcb_text.cpp:365
void OnFootprintRescaled(double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I &aAnchor, const EDA_ANGLE &aParentRotate) override
Apply a parent footprint scale to this item.
Definition pcb_text.cpp:616
void TransformTextToPolySet(SHAPE_POLY_SET &aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc) const
Convert the text to a polygonSet describing the actual character strokes (one per segment).
Definition pcb_text.cpp:787
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition pcb_text.cpp:411
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition pcb_text.cpp:709
virtual wxString GetTextTypeDescription() const
Definition pcb_text.cpp:669
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
Definition pcb_text.cpp:248
void buildBoundingHull(SHAPE_POLY_SET *aBuffer, const SHAPE_POLY_SET &aRenderedText, int aClearance) const
Build a nominally rectangular bounding box for the rendered text.
Definition pcb_text.cpp:759
bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const override
Test if aPoint is within the bounds of this object.
Definition pcb_text.cpp:426
wxString GetClass() const override
Return the class name.
Definition pcb_text.h:164
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition pcb_text.h:105
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition pcb_text.cpp:695
int GetTextThickness() const override
Definition pcb_text.cpp:497
void OnFootprintTransformed() override
Hook for items inside a footprint to refresh after the FP transform changes (translate,...
Definition pcb_text.cpp:623
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
Display a syntax help window for text variables and expressions.
Definition pcb_text.cpp:899
EDA_ANGLE GetDrawRotation() const override
Definition pcb_text.cpp:220
void SetTextAngle(const EDA_ANGLE &aAngle) override
Definition pcb_text.cpp:572
wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition pcb_text.cpp:178
VECTOR2I GetTextSize() const override
Definition pcb_text.cpp:470
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition pcb_text.cpp:167
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition pcb_text.cpp:583
void SetLibTextPos(const VECTOR2I &aPos)
Definition pcb_text.cpp:542
PCB_TEXT & operator=(const PCB_TEXT &aOther)
Definition pcb_text.cpp:88
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition pcb_text.cpp:689
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
RESOLUTION_CONTEXT
Definition common.h:91
@ NULL_CONSTRAINT
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition layer_ids.h:180
@ DEFAULT
Flashing follows connectivity.
Definition layer_ids.h:181
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
FLIP_DIRECTION
Definition mirror.h:23
TEXT_ATTRIBUTES text_attrs
Definition pcb_text.h:44
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:84
@ PCB_LOCATE_TEXT_T
Definition typeinfo.h:122
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708