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 (C) 1992-2023 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef PCB_TEXT_H
26#define PCB_TEXT_H
27
28#include <eda_text.h>
29#include <board_item.h>
30
31
32class LINE_READER;
33class MSG_PANEL_ITEM;
34class FOOTPRINT;
35
36
37class PCB_TEXT : public BOARD_ITEM, public EDA_TEXT
38{
39public:
40 PCB_TEXT( BOARD_ITEM* parent, KICAD_T idtype = PCB_TEXT_T );
41
42 PCB_TEXT( FOOTPRINT* aParent, KICAD_T idtype = PCB_TEXT_T );
43
44 // Do not create a copy constructor & operator=.
45 // The ones generated by the compiler are adequate.
46
47 ~PCB_TEXT();
48
49 static inline bool ClassOf( const EDA_ITEM* aItem )
50 {
51 return aItem && PCB_TEXT_T == aItem->Type();
52 }
53
54 bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
55 {
56 if( BOARD_ITEM::IsType( aScanTypes ) )
57 return true;
58
59 for( KICAD_T scanType : aScanTypes )
60 {
61 if( scanType == PCB_LOCATE_TEXT_T )
62 return true;
63 }
64
65 return false;
66 }
67
68 void Serialize( google::protobuf::Any &aContainer ) const override;
69 bool Deserialize( const google::protobuf::Any &aContainer ) override;
70
71 void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings ) override;
72
76 void KeepUpright();
77
78 wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override;
79
80 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
81
82 virtual VECTOR2I GetPosition() const override
83 {
84 return EDA_TEXT::GetTextPos();
85 }
86
87 virtual void SetPosition( const VECTOR2I& aPos ) override
88 {
90 }
91
92 void Move( const VECTOR2I& aMoveVector ) override
93 {
94 EDA_TEXT::Offset( aMoveVector );
95 }
96
97 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
98
99 void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
100
101 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
102
103 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
104
105 bool TextHitTest( const VECTOR2I& aPoint, int aAccuracy = 0 ) const override;
106 bool TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy = 0 ) const override;
107
108 bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override
109 {
110 return TextHitTest( aPosition, aAccuracy );
111 }
112
113 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override
114 {
115 return TextHitTest( aRect, aContained, aAccuracy );
116 }
117
118 wxString GetClass() const override
119 {
120 return wxT( "PCB_TEXT" );
121 }
122
131 void TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, int aMaxError,
132 ERROR_LOC aErrorLoc ) const;
133
134 void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
135 int aMaxError, ERROR_LOC aErrorLoc,
136 bool aIgnoreLineWidth = false ) const override;
137
138 // @copydoc BOARD_ITEM::GetEffectiveShape
139 virtual std::shared_ptr<SHAPE>
141 FLASHING aFlash = FLASHING::DEFAULT ) const override;
142
143 virtual wxString GetTextTypeDescription() const;
144
145 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
146
147 BITMAPS GetMenuImage() const override;
148
153 EDA_ANGLE GetDrawRotation() const override;
154
155 const BOX2I ViewBBox() const override;
156
157 void ViewGetLayers( int aLayers[], int& aCount ) const override;
158
160 double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
161
162 // Virtual function
163 const BOX2I GetBoundingBox() const override;
164
165 EDA_ITEM* Clone() const override;
166
167 double Similarity( const BOARD_ITEM& aBoardItem ) const override;
168
169 bool operator==( const PCB_TEXT& aOther ) const;
170 bool operator==( const BOARD_ITEM& aBoardItem ) const override;
171
172#if defined(DEBUG)
173 virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
174#endif
175
176protected:
181 void buildBoundingHull( SHAPE_POLY_SET* aBuffer, const SHAPE_POLY_SET& aRenderedText,
182 int aClearance ) const;
183
184 virtual void swapData( BOARD_ITEM* aImage ) override;
185
186 int getKnockoutMargin() const;
187
188 const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
189};
190
191#endif // #define PCB_TEXT_H
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
Definition: approximation.h:32
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
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:80
const KIFONT::METRICS & GetFontMetrics() const
Definition: board_item.cpp:100
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:89
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:176
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:79
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:253
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:449
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:467
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:93
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:54
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:318
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:651
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:622
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: pcb_text.cpp:486
const KIFONT::METRICS & getFontMetrics() const override
Definition: pcb_text.h:188
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: pcb_text.cpp:249
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
Definition: pcb_text.cpp:460
virtual void swapData(BOARD_ITEM *aImage) override
Definition: pcb_text.cpp:512
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: pcb_text.cpp:520
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:108
void KeepUpright()
Called when rotating the parent footprint.
Definition: pcb_text.cpp:369
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: pcb_text.cpp:221
void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
Definition: pcb_text.cpp:439
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: pcb_text.cpp:87
bool HitTest(const BOX2I &aRect, bool aContained, int aAccuracy=0) const override
Test if aRect intersects this item.
Definition: pcb_text.h:113
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: pcb_text.cpp:186
static bool ClassOf(const EDA_ITEM *aItem)
Definition: pcb_text.h:49
~PCB_TEXT()
Definition: pcb_text.cpp:82
virtual VECTOR2I GetPosition() const override
Definition: pcb_text.h:82
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: pcb_text.h:54
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition: pcb_text.cpp:266
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings) override
Definition: pcb_text.cpp:359
bool operator==(const PCB_TEXT &aOther) const
Definition: pcb_text.cpp:645
int getKnockoutMargin() const
Definition: pcb_text.cpp:353
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...
Definition: pcb_text.cpp:564
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_text.cpp:388
virtual wxString GetTextTypeDescription() const
Definition: pcb_text.cpp:480
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:535
bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const override
Test if aPoint is within the bounds of this object.
Definition: pcb_text.cpp:403
virtual void SetPosition(const VECTOR2I &aPos) override
Definition: pcb_text.h:87
wxString GetClass() const override
Return the class name.
Definition: pcb_text.h:118
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: pcb_text.h:92
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_text.cpp:506
EDA_ANGLE GetDrawRotation() const override
Definition: pcb_text.cpp:227
void ViewGetLayers(int aLayers[], int &aCount) const override
Definition: pcb_text.cpp:255
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: pcb_text.cpp:132
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_text.cpp:427
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_text.cpp:500
Represent a set of closed polygons.
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:147
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
FLIP_DIRECTION
Definition: mirror.h:27
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
@ PCB_LOCATE_TEXT_T
Definition: typeinfo.h:126