KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 virtual wxString GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
132 int aDepth = 0 ) const;
133
134 wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override
135 {
136 return GetShownText( nullptr, aAllowExtraText, aDepth );
137 }
138
139 bool IsHypertext() const override
140 {
141 return HasHyperlink();
142 }
143
144 void DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const override;
145
146 void SetExcludeFromSim( bool aExclude ) override { m_excludeFromSim = aExclude; }
147 bool GetExcludeFromSim() const override { return m_excludeFromSim; }
148
156 virtual void SetTextSpinStyle( TEXT_SPIN_STYLE aSpinStyle );
158
159 virtual LABEL_FLAG_SHAPE GetShape() const { return L_UNSPECIFIED; }
160 virtual void SetShape( LABEL_FLAG_SHAPE aShape ) { }
161
168 virtual VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const;
169
170 void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& offset ) override;
171
172 void SwapData( SCH_ITEM* aItem ) override;
173
174 const BOX2I GetBoundingBox() const override;
175
176 bool operator<( const SCH_ITEM& aItem ) const override;
177
178 int GetTextOffset( const RENDER_SETTINGS* aSettings = nullptr ) const;
179
180 int GetPenWidth() const override;
181
182 void Move( const VECTOR2I& aMoveVector ) override
183 {
184 EDA_TEXT::Offset( aMoveVector );
185 }
186
187 void MirrorHorizontally( int aCenter ) override;
188 void MirrorVertically( int aCenter ) override;
189 void Rotate( const VECTOR2I& aCenter ) override;
190
191 virtual void Rotate90( bool aClockwise );
192 virtual void MirrorSpinStyle( bool aLeftRight );
193
194 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
195 {
196 return SCH_ITEM::Matches( GetText(), aSearchData );
197 }
198
199 bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) override
200 {
201 return EDA_TEXT::Replace( aSearchData );
202 }
203
204 virtual bool IsReplaceable() const override { return true; }
205
206 void ViewGetLayers( int aLayers[], int& aCount ) const override;
207
208 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
209
210 BITMAPS GetMenuImage() const override;
211
212 VECTOR2I GetPosition() const override { return EDA_TEXT::GetTextPos(); }
213 void SetPosition( const VECTOR2I& aPosition ) override { EDA_TEXT::SetTextPos( aPosition ); }
214
215 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
216 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
217
218 void Plot( PLOTTER* aPlotter, bool aBackground ) const override;
219
220 EDA_ITEM* Clone() const override
221 {
222 return new SCH_TEXT( *this );
223 }
224
225 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
226
227#if defined(DEBUG)
228 void Show( int nestLevel, std::ostream& os ) const override;
229#endif
230
231 static HTML_MESSAGE_BOX* ShowSyntaxHelp( wxWindow* aParentWindow );
232
233protected:
234 KIFONT::FONT* getDrawFont() const override;
235
236protected:
248
250};
251
252
253#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:365
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:211
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:383
virtual bool HasHyperlink() const
Definition: eda_text.h:327
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:401
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:330
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
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_text.h:121
void DoHypertextAction(EDA_DRAW_FRAME *aFrame) const override
Definition: sch_text.cpp:388
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_text.h:220
bool IsHypertext() const override
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_text.h:139
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_text.cpp:404
~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:182
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_text.cpp:154
void Plot(PLOTTER *aPlotter, bool aBackground) const override
Plot the schematic item to aPlotter.
Definition: sch_text.cpp:438
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
Definition: sch_label.cpp:1804
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_text.cpp:243
VECTOR2I GetPosition() const override
Definition: sch_text.h:212
virtual void SetShape(LABEL_FLAG_SHAPE aShape)
Definition: sch_text.h:160
virtual void Rotate90(bool aClockwise)
Definition: sch_text.cpp:175
virtual bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition: sch_text.h:204
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_text.h:213
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:199
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_text.h:194
KIFONT::FONT * getDrawFont() const override
Definition: sch_text.cpp:287
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_text.cpp:145
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_text.cpp:163
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_text.cpp:231
TEXT_SPIN_STYLE GetTextSpinStyle() const
Definition: sch_text.h:157
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_text.cpp:329
virtual LABEL_FLAG_SHAPE GetShape() const
Definition: sch_text.h:159
virtual wxString GetClass() const override
Return the class name.
Definition: sch_text.h:126
int GetPenWidth() const override
Definition: sch_text.cpp:281
bool m_excludeFromSim
Definition: sch_text.h:249
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:193
virtual wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition: sch_text.cpp:350
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:430
TEXT_SPIN_STYLE m_spin_style
The orientation of text and any associated drawing elements of derived objects.
Definition: sch_text.h:247
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &offset) override
Print a schematic item.
Definition: sch_text.cpp:298
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:410
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: sch_text.cpp:398
void SetExcludeFromSim(bool aExclude) override
Definition: sch_text.h:146
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:497
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:138
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_text.h:134
bool GetExcludeFromSim() const override
Definition: sch_text.h:147
virtual void MirrorSpinStyle(bool aLeftRight)
Definition: sch_text.cpp:184
int GetTextOffset(const RENDER_SETTINGS *aSettings=nullptr) const
Definition: sch_text.cpp:266
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:140