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-2024 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_connection.h> // for CONNECTION_TYPE
32#include <schematic.h>
33
34
36
37class SCH_TEXT : public SCH_ITEM, public EDA_TEXT
38{
39public:
40 SCH_TEXT( const VECTOR2I& aPos = { 0, 0 }, const wxString& aText = wxEmptyString,
41 SCH_LAYER_ID aLayer = LAYER_NOTES, KICAD_T aType = SCH_TEXT_T );
42
43 SCH_TEXT( const SCH_TEXT& aText );
44
45 ~SCH_TEXT() override { }
46
47 static bool ClassOf( const EDA_ITEM* aItem )
48 {
49 return aItem && SCH_TEXT_T == aItem->Type();
50 }
51
52 wxString GetClass() const override
53 {
54 return wxT( "SCH_TEXT" );
55 }
56
57 wxString GetFriendlyName() const override
58 {
59 return _( "Text" );
60 }
61
62 virtual wxString GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
63 int aDepth = 0 ) const;
64
65 wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override
66 {
67 SCHEMATIC* schematic = Schematic();
68
69 if( schematic )
70 return GetShownText( &schematic->CurrentSheet(), aAllowExtraText, aDepth );
71 else
72 return GetText();
73 }
74
75 int GetSchTextSize() const { return GetTextWidth(); }
76 void SetSchTextSize( int aSize ) { SetTextSize( VECTOR2I( aSize, aSize ) ); }
77
78 bool IsHypertext() const override
79 {
80 return HasHyperlink();
81 }
82
83 void DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const override;
84
85 void SetExcludedFromSim( bool aExclude ) override { m_excludedFromSim = aExclude; }
86 bool GetExcludedFromSim() const override { return m_excludedFromSim; }
87
94 virtual VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const;
95
96 void SwapData( SCH_ITEM* aItem ) override;
97
98 const BOX2I GetBoundingBox() const override;
99
100 bool operator<( const SCH_ITEM& aItem ) const override;
101
102 int GetTextOffset( const RENDER_SETTINGS* aSettings = nullptr ) const;
103
104 int GetPenWidth() const override;
105
106 void Move( const VECTOR2I& aMoveVector ) override
107 {
108 EDA_TEXT::Offset( aMoveVector );
109 }
110
111 void NormalizeJustification( bool inverse );
112
113 void MirrorHorizontally( int aCenter ) override;
114 void MirrorVertically( int aCenter ) override;
115 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
116
117 virtual void Rotate90( bool aClockwise );
118 virtual void MirrorSpinStyle( bool aLeftRight );
119
120 void BeginEdit( const VECTOR2I& aStartPoint ) override;
121 void CalcEdit( const VECTOR2I& aPosition ) override;
122
123 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
124 {
125 return SCH_ITEM::Matches( GetText(), aSearchData );
126 }
127
128 bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) override
129 {
130 return EDA_TEXT::Replace( aSearchData );
131 }
132
133 bool IsReplaceable() const override { return true; }
134
135 void ViewGetLayers( int aLayers[], int& aCount ) const override;
136
137 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
138
139 BITMAPS GetMenuImage() const override;
140
141 VECTOR2I GetPosition() const override { return EDA_TEXT::GetTextPos(); }
142 void SetPosition( const VECTOR2I& aPosition ) override { EDA_TEXT::SetTextPos( aPosition ); }
143
144 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
145 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
146
147 void Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
148 const VECTOR2I& offset, bool aForceNoFill, bool aDimmed ) override;
149
150 void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
151 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
152
153 EDA_ITEM* Clone() const override
154 {
155 return new SCH_TEXT( *this );
156 }
157
158 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
159
160 double Similarity( const SCH_ITEM& aItem ) const override;
161
162 bool operator==( const SCH_ITEM& aItem ) const override;
163
164#if defined(DEBUG)
165 void Show( int nestLevel, std::ostream& os ) const override;
166#endif
167
168 static HTML_MESSAGE_BOX* ShowSyntaxHelp( wxWindow* aParentWindow );
169
170protected:
171 KIFONT::FONT* getDrawFont() const override;
172
173 const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
174
185 int compare( const SCH_ITEM& aOther, int aCompareFlags = 0 ) const override;
186
187protected:
189};
190
191
192#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:89
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:377
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 SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:419
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:94
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:464
int GetTextWidth() const
Definition: eda_text.h:244
virtual bool HasHyperlink() const
Definition: eda_text.h:380
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:482
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:390
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Base plotter engine class.
Definition: plotter.h:105
Holds all the data relating to one schematic.
Definition: schematic.h:77
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:152
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:166
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:150
const KIFONT::METRICS & GetFontMetrics() const
Definition: sch_item.cpp:466
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: sch_text.cpp:454
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_text.h:47
void DoHypertextAction(EDA_DRAW_FRAME *aFrame) const override
Definition: sch_text.cpp:444
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_text.h:153
int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: sch_text.cpp:711
const KIFONT::METRICS & getFontMetrics() const override
Definition: sch_text.h:173
bool IsHypertext() const override
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_text.h:78
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_text.cpp:461
int GetSchTextSize() const
Definition: sch_text.h:75
bool m_excludedFromSim
Definition: sch_text.h:188
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_text.h:106
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_text.cpp:158
~SCH_TEXT() override
Definition: sch_text.h:45
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_text.cpp:197
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition: sch_text.cpp:498
wxString GetClass() const override
Return the class name.
Definition: sch_text.h:52
void NormalizeJustification(bool inverse)
Definition: sch_text.cpp:79
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
Definition: sch_label.cpp:2163
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_text.cpp:244
VECTOR2I GetPosition() const override
Definition: sch_text.h:141
virtual void Rotate90(bool aClockwise)
Definition: sch_text.cpp:209
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_text.h:142
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:128
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_text.h:123
void SetExcludedFromSim(bool aExclude) override
Definition: sch_text.h:85
KIFONT::FONT * getDrawFont() const override
Definition: sch_text.cpp:288
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_text.cpp:119
void Print(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &offset, bool aForceNoFill, bool aDimmed) override
Print an item.
Definition: sch_text.cpp:299
double Similarity(const SCH_ITEM &aItem) const override
Return a measure of how likely the other object is to represent the same object.
Definition: sch_text.cpp:687
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_text.cpp:231
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_text.cpp:385
int GetPenWidth() const override
Definition: sch_text.cpp:282
void SetSchTextSize(int aSize)
Definition: sch_text.h:76
virtual wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition: sch_text.cpp:406
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:504
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Plot the item to aPlotter.
Definition: sch_text.cpp:512
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:467
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition: sch_text.h:133
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:624
void BeginEdit(const VECTOR2I &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
Definition: sch_text.cpp:492
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:72
bool GetExcludedFromSim() const override
Definition: sch_text.h:86
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_text.h:65
wxString GetFriendlyName() const override
Definition: sch_text.h:57
virtual void MirrorSpinStyle(bool aLeftRight)
Definition: sch_text.cpp:221
bool operator==(const SCH_ITEM &aItem) const override
Definition: sch_text.cpp:670
int GetTextOffset(const RENDER_SETTINGS *aSettings=nullptr) const
Definition: sch_text.cpp:267
#define _(s)
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:353
@ LAYER_NOTES
Definition: layer_ids.h:371
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ SCH_TEXT_T
Definition: typeinfo.h:151
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691