KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_textbox.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#ifndef PCB_TEXTBOX_H
22#define PCB_TEXTBOX_H
23
24#include <eda_text.h>
25#include <pcb_shape.h>
26
27
28class LINE_READER;
29class MSG_PANEL_ITEM;
30
31namespace kiapi::board::types
32{
33 class BoardTextBox;
34}
35
36
37class PCB_TEXTBOX : public PCB_SHAPE, public EDA_TEXT
38{
39public:
40 PCB_TEXTBOX( BOARD_ITEM* aParent, KICAD_T aType = PCB_TEXTBOX_T );
41
42 // Do not create a copy constructor & operator=.
43 // The ones generated by the compiler are adequate.
44
46
47 void CopyFrom( const BOARD_ITEM* aOther ) override;
48
49 static inline bool ClassOf( const EDA_ITEM* aItem )
50 {
51 return aItem && PCB_TEXTBOX_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 Serialize( kiapi::board::types::BoardTextBox& aOutput ) const;
72 bool Deserialize( const kiapi::board::types::BoardTextBox& aInput );
73
74 wxString GetFriendlyName() const override { return _( "Text Box" ); }
75
76 VECTOR2I GetTopLeft() const override;
77 VECTOR2I GetBotRight() const override;
78
79 std::vector<VECTOR2I> GetCorners() const override;
80
81 /*
82 * @return a PCB_SHAPE type POLYGON of the box of the TEXTBOX, according to the box shape
83 * and the textbox rotation
84 * The base PCB_SHAPE of a textbox is a RECTANGLE, so creating some issues when orientation
85 * is not 0 is some draw functions
86 */
88
89 std::vector<VECTOR2I> GetCornersInSequence( EDA_ANGLE angle ) const override;
90
91 // Keep the lib shape as RECTANGLE even if a runtime polygon conversion happens.
92 void SetShape( SHAPE_T aShape ) override;
93
99 VECTOR2I GetMinSize() const;
100
101 void SetTop( int aVal ) override;
102 void SetLeft( int aVal ) override;
103 void SetRight( int aVal ) override;
104 void SetBottom( int aVal ) override;
105
106 void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings, bool aCheckSide ) override;
107
108 int GetLegacyTextMargin() const;
109
110 void SetMarginLeft( int aLeft ) { m_marginLeft = aLeft; }
111 void SetMarginTop( int aTop ) { m_marginTop = aTop; }
112 void SetMarginRight( int aRight ) { m_marginRight = aRight; }
113 void SetMarginBottom( int aBottom ) { m_marginBottom = aBottom; }
114
115 int GetMarginLeft() const { return m_marginLeft; }
116 int GetMarginTop() const { return m_marginTop; }
117 int GetMarginRight() const { return m_marginRight; }
118 int GetMarginBottom() const { return m_marginBottom; }
119
120 VECTOR2I GetDrawPos() const override;
121 VECTOR2I GetDrawPos( bool aIsFlipped ) const;
122
123 EDA_ANGLE GetTextAngle() const override;
124 void SetTextAngle( const EDA_ANGLE& aAngle ) override;
125
130 EDA_ANGLE GetLibTextAngle() const { return m_libTextAngle.GetAngle(); }
131 void SetLibTextAngle( const EDA_ANGLE& aAngle ) { m_libTextAngle = aAngle; }
132
133 wxString GetShownText( RESOLUTION_CONTEXT aContext, int aDepth = 0 ) const override;
134
135 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
136
137 void Move( const VECTOR2I& aMoveVector ) override;
138
139 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
140
141 void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
142
143 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
144
145 void OnFootprintTransformed() override;
146
147 void OnFootprintRescaled( double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I& aAnchor,
148 const EDA_ANGLE& aParentRotate ) override;
149
150 VECTOR2I GetTextSize() const override;
151 void SetTextSize( VECTOR2I aNewSize, bool aEnforceMinTextSize = true ) override;
152
153 int GetTextThickness() const override;
154 void SetTextThickness( int aWidth ) override;
155
156 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
157
158 const BOX2I GetBoundingBox() const override;
159
160 bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override;
161
162 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
163
164 bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const override;
165
166 wxString GetClass() const override
167 {
168 return wxT( "PCB_TEXTBOX" );
169 }
170
180 void TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, int aMaxError,
181 ERROR_LOC aErrorLoc ) const;
182
183 double GetCoverageArea( int aTextMargin ) const override;
184
185 void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
186 int aMaxError, ERROR_LOC aErrorLoc,
187 bool aIgnoreLineWidth = false ) const override;
188
190 std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
192 DRC_CONSTRAINT_T aUsage = NULL_CONSTRAINT ) const override;
193
194 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
195
196 BITMAPS GetMenuImage() const override;
197
198 double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
199
200 std::vector<int> ViewGetLayers() const override;
201
202 EDA_ITEM* Clone() const override;
203
205 bool IsBorderEnabled() const;
206
208 void SetBorderEnabled( bool enabled );
209
210 void SetBorderWidth( const int aSize );
211 int GetBorderWidth() const { return m_stroke.GetWidth(); }
212
213 double Similarity( const BOARD_ITEM& aBoardItem ) const override;
214
215 bool operator==( const PCB_TEXTBOX& aOther ) const;
216 bool operator==( const BOARD_ITEM& aBoardItem ) const override;
217
218protected:
219 EDA_ANGLE getDrawRotation() const override { return GetDrawRotation(); }
220
221 virtual void swapData( BOARD_ITEM* aImage ) override;
222
223 // Inverse of OnFootprintTransformed (move center, scale half-extents, keep
224 // the box axis-aligned). A true inverse at any angle.
225 void syncLibCoords() override;
226
227 const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
228
229protected:
231
232private:
237 EDA_ORIENTATION m_libTextAngle; // Text angle in parent footprint's lib frame
238};
239
240#endif // #define PCB_TEXTBOX_H
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:84
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:86
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
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
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
An "orientation", held as an angle constrained to the range [0, 360) degrees.
Definition eda_angle.h:473
STROKE_PARAMS m_stroke
Definition eda_shape.h:739
virtual EDA_ANGLE GetDrawRotation() const
Definition eda_text.h:425
EDA_TEXT(const EDA_IU_SCALE &aIuScale, const wxString &aText=wxEmptyString)
Definition eda_text.cpp:98
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
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
PCB_SHAPE(BOARD_ITEM *aParent, KICAD_T aItemType, SHAPE_T aShapeType)
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
Tests whether the border is disabled, as configured by the stroke.
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...
wxString GetFriendlyName() const override
Definition pcb_textbox.h:74
void SetLibTextAngle(const EDA_ANGLE &aAngle)
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
int GetMarginBottom() const
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings, bool aCheckSide) override
EDA_ANGLE GetTextAngle() const override
PCB_TEXTBOX(BOARD_ITEM *aParent, KICAD_T aType=PCB_TEXTBOX_T)
const KIFONT::METRICS & getFontMetrics() const override
int GetTextThickness() const override
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)
Disables the border, this is done by changing the stroke internally.
void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
void OnFootprintTransformed() override
Hook for items inside a footprint to refresh after the FP transform changes (translate,...
VECTOR2I GetMinSize() const
Return the minimum height needed to contain the textbox's wrapped text content plus margins.
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).
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition pcb_textbox.h:54
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
void OnFootprintRescaled(double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I &aAnchor, const EDA_ANGLE &aParentRotate) override
Apply a parent footprint scale to this item.
VECTOR2I GetTextSize() const override
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
void SetShape(SHAPE_T aShape) override
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
EDA_ORIENTATION m_libTextAngle
void SetMarginLeft(int aLeft)
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
void SetMarginBottom(int aBottom)
std::vector< VECTOR2I > GetCornersInSequence(EDA_ANGLE angle) const override
static bool ClassOf(const EDA_ITEM *aItem)
Definition pcb_textbox.h:49
int GetMarginRight() const
void SetRight(int aVal) override
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
void SetTop(int aVal) override
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
int GetMarginTop() const
void SetTextAngle(const EDA_ANGLE &aAngle) override
bool operator==(const PCB_TEXTBOX &aOther) const
void SetTextThickness(int aWidth) override
The TextThickness is that set by the user.
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
EDA_ANGLE getDrawRotation() const override
void syncLibCoords() override
void SetBottom(int aVal) override
PCB_SHAPE GetPolygonalBoxShape() const
VECTOR2I GetTopLeft() const override
VECTOR2I GetBotRight() const override
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true) override
void CopyFrom(const BOARD_ITEM *aOther) override
int GetBorderWidth() const
wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
Return the string actually shown after processing of the base text.
EDA_ANGLE GetLibTextAngle() const
Text angle in the parent footprint's lib frame, or absolute when not in a footprint.
std::vector< VECTOR2I > GetCorners() const override
Return 4 corners for a rectangle or rotated rectangle (stored as a poly).
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.
wxString GetClass() const override
Return the class name.
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:89
DRC_CONSTRAINT_T
Definition drc_rule.h:49
@ NULL_CONSTRAINT
Definition drc_rule.h:50
#define _(s)
SHAPE_T
Definition eda_shape.h:54
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
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:85
@ PCB_LOCATE_TEXT_T
Definition typeinfo.h:122
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708