KiCad PCB EDA Suite
sch_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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 1992-2022 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 SCH_TEXT_H
26#define SCH_TEXT_H
27
28
29#include <eda_text.h>
30#include <sch_item.h>
31#include <sch_field.h>
32#include <sch_connection.h> // for CONNECTION_TYPE
33
34
36
37/*
38 * Spin style for text items of all kinds on schematics
39 * Basically a higher level abstraction of rotation and justification of text
40 */
42{
43public:
44 enum SPIN : int
45 {
46 LEFT = 0,
47 UP = 1,
48 RIGHT = 2,
49 BOTTOM = 3
50 };
51
52
53 TEXT_SPIN_STYLE() = default;
54 constexpr TEXT_SPIN_STYLE( SPIN aSpin ) : m_spin( aSpin )
55 {
56 }
57
58 constexpr bool operator==( SPIN a ) const
59 {
60 return m_spin == a;
61 }
62
63 constexpr bool operator!=( SPIN a ) const
64 {
65 return m_spin != a;
66 }
67
68 operator int() const
69 {
70 return static_cast<int>( m_spin );
71 }
72
74
76
81
86
87private:
89};
90
91
92/*
93 * Label and flag shapes used with text objects.
94 */
96{
102
109
110
111class SCH_TEXT : public SCH_ITEM, public EDA_TEXT
112{
113public:
114 SCH_TEXT( const VECTOR2I& aPos = { 0, 0 }, const wxString& aText = wxEmptyString,
115 KICAD_T aType = SCH_TEXT_T );
116
117 SCH_TEXT( const SCH_TEXT& aText );
118
120
121 static inline bool ClassOf( const EDA_ITEM* aItem )
122 {
123 return aItem && SCH_TEXT_T == aItem->Type();
124 }
125
126 virtual wxString GetClass() const override
127 {
128 return wxT( "SCH_TEXT" );
129 }
130
131 wxString GetShownText( int aDepth = 0 ) const override;
132
133 bool IsHypertext() const override
134 {
135 return HasHyperlink();
136 }
137
138 void DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const override;
139
147 virtual void SetTextSpinStyle( TEXT_SPIN_STYLE aSpinStyle );
149
150 virtual LABEL_FLAG_SHAPE GetShape() const { return L_UNSPECIFIED; }
151 virtual void SetShape( LABEL_FLAG_SHAPE aShape ) { }
152
159 virtual VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const;
160
161 void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& offset ) override;
162
163 void SwapData( SCH_ITEM* aItem ) override;
164
165 const BOX2I GetBoundingBox() const override;
166
167 bool operator<( const SCH_ITEM& aItem ) const override;
168
169 int GetTextOffset( const RENDER_SETTINGS* aSettings = nullptr ) const;
170
171 int GetPenWidth() const override;
172
173 KIFONT::FONT* GetDrawFont() const override;
174
175 void Move( const VECTOR2I& aMoveVector ) override
176 {
177 EDA_TEXT::Offset( aMoveVector );
178 }
179
180 void MirrorHorizontally( int aCenter ) override;
181 void MirrorVertically( int aCenter ) override;
182 void Rotate( const VECTOR2I& aCenter ) override;
183
184 virtual void Rotate90( bool aClockwise );
185 virtual void MirrorSpinStyle( bool aLeftRight );
186
187 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
188 {
189 return SCH_ITEM::Matches( GetText(), aSearchData );
190 }
191
192 bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) override
193 {
194 return EDA_TEXT::Replace( aSearchData );
195 }
196
197 virtual bool IsReplaceable() const override { return true; }
198
199 void ViewGetLayers( int aLayers[], int& aCount ) const override;
200
201 wxString GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const override;
202
203 BITMAPS GetMenuImage() const override;
204
205 VECTOR2I GetPosition() const override { return EDA_TEXT::GetTextPos(); }
206 void SetPosition( const VECTOR2I& aPosition ) override { EDA_TEXT::SetTextPos( aPosition ); }
207
208 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
209 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
210
211 void Plot( PLOTTER* aPlotter, bool aBackground ) const override;
212
213 EDA_ITEM* Clone() const override
214 {
215 return new SCH_TEXT( *this );
216 }
217
218 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
219
220#if defined(DEBUG)
221 void Show( int nestLevel, std::ostream& os ) const override;
222#endif
223
224 static HTML_MESSAGE_BOX* ShowSyntaxHelp( wxWindow* aParentWindow );
225
226protected:
238};
239
240
241#endif /* SCH_TEXT_H */
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
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:85
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:382
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:72
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:198
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:371
virtual bool HasHyperlink() const
Definition: eda_text.h:324
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:389
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:318
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:105
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Base plotter engine class.
Definition: plotter.h:110
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_text.h:121
void DoHypertextAction(EDA_DRAW_FRAME *aFrame) const override
Definition: sch_text.cpp:386
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_text.h:213
bool IsHypertext() const override
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_text.h:133
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_text.cpp:402
~SCH_TEXT()
Definition: sch_text.h:119
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_text.h:175
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_text.cpp:149
void Plot(PLOTTER *aPlotter, bool aBackground) const override
Plot the schematic item to aPlotter.
Definition: sch_text.cpp:436
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
Definition: sch_label.cpp:1638
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_text.cpp:238
VECTOR2I GetPosition() const override
Definition: sch_text.h:205
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_text.cpp:337
virtual void SetShape(LABEL_FLAG_SHAPE aShape)
Definition: sch_text.h:151
virtual void Rotate90(bool aClockwise)
Definition: sch_text.cpp:170
virtual bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition: sch_text.h:197
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_text.h:206
bool Replace(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) override
Perform a text replace using the find and replace criteria in aSearchData on items that support text ...
Definition: sch_text.h:192
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_text.h:187
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_text.cpp:140
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_text.cpp:158
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_text.cpp:226
wxString GetSelectMenuText(UNITS_PROVIDER *aUnitsProvider) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: sch_text.cpp:396
TEXT_SPIN_STYLE GetTextSpinStyle() const
Definition: sch_text.h:148
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_text.cpp:316
virtual LABEL_FLAG_SHAPE GetShape() const
Definition: sch_text.h:150
virtual wxString GetClass() const override
Return the class name.
Definition: sch_text.h:126
KIFONT::FONT * GetDrawFont() const override
Definition: sch_text.cpp:279
int GetPenWidth() const override
Definition: sch_text.cpp:273
virtual void SetTextSpinStyle(TEXT_SPIN_STYLE aSpinStyle)
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:188
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition: sch_text.cpp:428
TEXT_SPIN_STYLE m_spin_style
The orientation of text and any associated drawing elements of derived objects.
Definition: sch_text.h:237
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &offset) override
Print a schematic item.
Definition: sch_text.cpp:290
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_text.cpp:408
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: sch_text.cpp:488
virtual VECTOR2I GetSchematicTextOffset(const RENDER_SETTINGS *aSettings) const
This offset depends on the orientation, the type of text, and the area required to draw the associate...
Definition: sch_text.cpp:134
SCH_TEXT(const VECTOR2I &aPos={ 0, 0 }, const wxString &aText=wxEmptyString, KICAD_T aType=SCH_TEXT_T)
Definition: sch_text.cpp:115
virtual void MirrorSpinStyle(bool aLeftRight)
Definition: sch_text.cpp:179
int GetTextOffset(const RENDER_SETTINGS *aSettings=nullptr) const
Definition: sch_text.cpp:258
constexpr TEXT_SPIN_STYLE(SPIN aSpin)
Definition: sch_text.h:54
TEXT_SPIN_STYLE RotateCW()
Definition: sch_text.cpp:51
constexpr bool operator!=(SPIN a) const
Definition: sch_text.h:63
TEXT_SPIN_STYLE MirrorY()
Mirror the label spin style across the Y axis or simply swaps left and right.
Definition: sch_text.cpp:99
TEXT_SPIN_STYLE RotateCCW()
Definition: sch_text.cpp:67
TEXT_SPIN_STYLE()=default
TEXT_SPIN_STYLE MirrorX()
Mirror the label spin style across the X axis or simply swaps up and bottom.
Definition: sch_text.cpp:83
constexpr bool operator==(SPIN a) const
Definition: sch_text.h:58
LABEL_FLAG_SHAPE
Definition: sch_text.h:96
@ L_BIDI
Definition: sch_text.h:99
@ L_TRISTATE
Definition: sch_text.h:100
@ L_UNSPECIFIED
Definition: sch_text.h:101
@ F_DOT
Definition: sch_text.h:104
@ F_ROUND
Definition: sch_text.h:105
@ F_FIRST
Definition: sch_text.h:103
@ L_OUTPUT
Definition: sch_text.h:98
@ F_DIAMOND
Definition: sch_text.h:106
@ L_INPUT
Definition: sch_text.h:97
@ F_RECTANGLE
Definition: sch_text.h:107
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ SCH_TEXT_T
Definition: typeinfo.h:149