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 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, 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 void Serialize( google::protobuf::Any& aContainer ) const override;
48 bool Deserialize( const google::protobuf::Any& aContainer ) override;
49
50 static bool ClassOf( const EDA_ITEM* aItem )
51 {
52 return aItem && SCH_TEXT_T == aItem->Type();
53 }
54
55 wxString GetClass() const override
56 {
57 return wxT( "SCH_TEXT" );
58 }
59
60 wxString GetFriendlyName() const override
61 {
62 return _( "Text" );
63 }
64
65 KIFONT::FONT* GetDrawFont( const RENDER_SETTINGS* aSettings ) const override;
66
67 virtual wxString GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
68 int aDepth = 0 ) const;
69
70 wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override
71 {
72 SCHEMATIC* schematic = Schematic();
73
74 if( schematic )
75 return GetShownText( &schematic->CurrentSheet(), aAllowExtraText, aDepth );
76 else
77 return GetText();
78 }
79
80 int GetSchTextSize() const { return GetTextWidth(); }
81 void SetSchTextSize( int aSize ) { SetTextSize( VECTOR2I( aSize, aSize ) ); }
82
83 bool HasHypertext() const override;
84 bool HasHoveredHypertext() const override;
85 void DoHypertextAction( EDA_DRAW_FRAME* aFrame, const VECTOR2I& aMousePos ) const override;
86
87 void SetExcludedFromSim( bool aExclude, const SCH_SHEET_PATH* aInstance = nullptr,
88 const wxString& aVariantName = wxEmptyString ) override
89 {
90 m_excludedFromSim = aExclude;
91 }
92
93 bool GetExcludedFromSim( const SCH_SHEET_PATH* aInstance = nullptr,
94 const wxString& aVariantName = wxEmptyString ) const override
95 {
96 return m_excludedFromSim;
97 }
98
105 virtual VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const;
106
107 const BOX2I GetBoundingBox() const override;
108
109 bool operator<( const SCH_ITEM& aItem ) const override;
110
111 int GetTextOffset( const RENDER_SETTINGS* aSettings = nullptr ) const;
112
113 int GetPenWidth() const override;
114
115 void Move( const VECTOR2I& aMoveVector ) override
116 {
117 EDA_TEXT::Offset( aMoveVector );
118 }
119
120 void NormalizeJustification( bool inverse );
121
122 void MirrorHorizontally( int aCenter ) override;
123 void MirrorVertically( int aCenter ) override;
124 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
125
126 virtual void Rotate90( bool aClockwise );
127 virtual void MirrorSpinStyle( bool aLeftRight );
128
129 void BeginEdit( const VECTOR2I& aStartPoint ) override;
130 void CalcEdit( const VECTOR2I& aPosition ) override;
131
132 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
133 {
134 return SCH_ITEM::Matches( GetText(), aSearchData );
135 }
136
137 bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) override
138 {
139 return EDA_TEXT::Replace( aSearchData );
140 }
141
142 bool IsReplaceable() const override { return true; }
143
144 std::vector<int> ViewGetLayers() const override;
145
146 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
147
148 BITMAPS GetMenuImage() const override;
149
150 VECTOR2I GetPosition() const override { return EDA_TEXT::GetTextPos(); }
151 void SetPosition( const VECTOR2I& aPosition ) override
152 {
153 EDA_TEXT::SetTextPos( aPosition );
154 }
155
156 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
157 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
158 bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const override;
159
161
162 void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
163 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
164
165 EDA_ITEM* Clone() const override
166 {
167 return new SCH_TEXT( *this );
168 }
169
170 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
171
172 double Similarity( const SCH_ITEM& aItem ) const override;
173
174 bool operator==( const SCH_ITEM& aItem ) const override;
175
176#if defined(DEBUG)
177 void Show( int nestLevel, std::ostream& os ) const override;
178#endif
179
180 static HTML_MESSAGE_BOX* ShowSyntaxHelp( wxWindow* aParentWindow );
181
182protected:
183 void swapData( SCH_ITEM* aItem ) override;
184
185 const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
186
197 int compare( const SCH_ITEM& aOther, int aCompareFlags = 0 ) const override;
198
199protected:
201};
202
203
204#endif /* SCH_TEXT_H */
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
The base class for create windows for drawing purpose.
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:112
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition eda_item.h:413
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:41
const VECTOR2I & GetTextPos() const
Definition eda_text.h:298
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition eda_text.cpp:532
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:114
void SetTextPos(const VECTOR2I &aPoint)
Definition eda_text.cpp:576
int GetTextWidth() const
Definition eda_text.h:289
void Offset(const VECTOR2I &aOffset)
Definition eda_text.cpp:594
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
Definition eda_text.cpp:486
EDA_TEXT(const EDA_IU_SCALE &aIuScale, const wxString &aText=wxEmptyString)
Definition eda_text.cpp:102
FONT is an abstract base class for both outline and stroke fonts.
Definition font.h:98
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Base plotter engine class.
Definition plotter.h:136
Holds all the data relating to one schematic.
Definition schematic.h:89
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:168
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:272
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType, int aUnit=0, int aBodyStyle=0)
Definition sch_item.cpp:56
const KIFONT::METRICS & GetFontMetrics() const
Definition sch_item.cpp:783
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:436
static bool ClassOf(const EDA_ITEM *aItem)
Definition sch_text.h:50
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition sch_text.h:165
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:762
const KIFONT::METRICS & getFontMetrics() const override
Definition sch_text.h:185
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition sch_text.cpp:443
int GetSchTextSize() const
Definition sch_text.h:80
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition sch_text.cpp:281
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition sch_text.cpp:100
KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const override
Definition sch_text.cpp:334
bool m_excludedFromSim
Definition sch_text.h:200
void SetExcludedFromSim(bool aExclude, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Definition sch_text.h:87
bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Definition sch_text.h:93
void DoHypertextAction(EDA_DRAW_FRAME *aFrame, const VECTOR2I &aMousePos) const override
Definition sch_text.cpp:425
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition sch_text.h:115
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition sch_text.cpp:210
~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:249
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition sch_text.cpp:489
wxString GetClass() const override
Return the class name.
Definition sch_text.h:55
void NormalizeJustification(bool inverse)
Definition sch_text.cpp:131
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
bool operator<(const SCH_ITEM &aItem) const override
Definition sch_text.cpp:290
VECTOR2I GetPosition() const override
Definition sch_text.h:150
VECTOR2I GetOffsetToMatchSCH_FIELD(SCH_RENDER_SETTINGS *aRenderSettings) const
Definition sch_text.cpp:504
virtual void Rotate90(bool aClockwise)
Definition sch_text.cpp:261
void SetPosition(const VECTOR2I &aPosition) override
Definition sch_text.h:151
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:137
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition sch_text.h:132
std::vector< int > ViewGetLayers() const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition sch_text.cpp:495
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition sch_text.cpp:171
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:738
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition sch_text.cpp:345
int GetPenWidth() const override
Definition sch_text.cpp:328
bool HasHoveredHypertext() const override
Indicates that a hypertext link is currently active.
Definition sch_text.cpp:419
void SetSchTextSize(int aSize)
Definition sch_text.h:81
virtual wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition sch_text.cpp:366
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:521
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:449
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition sch_text.h:142
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:672
void BeginEdit(const VECTOR2I &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
Definition sch_text.cpp:483
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:124
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition sch_text.h:70
wxString GetFriendlyName() const override
Definition sch_text.h:60
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition sch_text.cpp:80
virtual void MirrorSpinStyle(bool aLeftRight)
Definition sch_text.cpp:272
bool HasHypertext() const override
Indicates that the item has at least one hypertext action.
Definition sch_text.cpp:413
bool operator==(const SCH_ITEM &aItem) const override
Definition sch_text.cpp:721
int GetTextOffset(const RENDER_SETTINGS *aSettings=nullptr) const
Definition sch_text.cpp:313
SCH_TEXT(const VECTOR2I &aPos={ 0, 0 }, const wxString &aText=wxEmptyString, SCH_LAYER_ID aLayer=LAYER_NOTES, KICAD_T aType=SCH_TEXT_T)
Definition sch_text.cpp:59
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
#define _(s)
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:451
@ LAYER_NOTES
Definition layer_ids.h:469
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:75
@ SCH_TEXT_T
Definition typeinfo.h:152
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687