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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef SCH_TEXT_H
22#define SCH_TEXT_H
23
24
25#include <eda_text.h>
26#include <sch_item.h>
27#include <sch_connection.h> // for CONNECTION_TYPE
28#include <schematic.h>
29
30
32
33class SCH_TEXT : public SCH_ITEM, public EDA_TEXT
34{
35public:
36 SCH_TEXT( const VECTOR2I& aPos = { 0, 0 }, const wxString& aText = wxEmptyString,
37 SCH_LAYER_ID aLayer = LAYER_NOTES, KICAD_T aType = SCH_TEXT_T );
38
39 SCH_TEXT( const SCH_TEXT& aText );
40
41 ~SCH_TEXT() override { }
42
43 void Serialize( google::protobuf::Any& aContainer ) const override;
44 bool Deserialize( const google::protobuf::Any& aContainer ) override;
45
46 static bool ClassOf( const EDA_ITEM* aItem )
47 {
48 return aItem && SCH_TEXT_T == aItem->Type();
49 }
50
51 wxString GetClass() const override
52 {
53 return wxT( "SCH_TEXT" );
54 }
55
56 wxString GetFriendlyName() const override
57 {
58 return _( "Text" );
59 }
60
61 KIFONT::FONT* GetDrawFont( const RENDER_SETTINGS* aSettings ) const override;
62
63 virtual wxString GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
64 int aDepth = 0 ) const;
65
66 wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override
67 {
68 SCHEMATIC* schematic = Schematic();
69
70 if( schematic )
71 return GetShownText( &schematic->CurrentSheet(), aAllowExtraText, aDepth );
72 else
73 return GetText();
74 }
75
76 int GetSchTextSize() const { return GetTextWidth(); }
77 void SetSchTextSize( int aSize ) { SetTextSize( VECTOR2I( aSize, aSize ) ); }
78
79 bool HasHypertext() const override;
80 bool HasHoveredHypertext() const override;
81 void DoHypertextAction( EDA_DRAW_FRAME* aFrame, const VECTOR2I& aMousePos ) const override;
82
83 void SetExcludedFromSim( bool aExclude, const SCH_SHEET_PATH* aInstance = nullptr,
84 const wxString& aVariantName = wxEmptyString ) override
85 {
86 m_excludedFromSim = aExclude;
87 }
88
89 bool GetExcludedFromSim( const SCH_SHEET_PATH* aInstance = nullptr,
90 const wxString& aVariantName = wxEmptyString ) const override
91 {
92 return m_excludedFromSim;
93 }
94
101 virtual VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const;
102
103 const BOX2I GetBoundingBox() const override;
104
105 bool operator<( const SCH_ITEM& aItem ) const override;
106
107 int GetTextOffset( const RENDER_SETTINGS* aSettings = nullptr ) const;
108
109 int GetPenWidth() const override;
110
111 void Move( const VECTOR2I& aMoveVector ) override
112 {
113 EDA_TEXT::Offset( aMoveVector );
114 }
115
116 void NormalizeJustification( bool inverse );
117
118 void MirrorHorizontally( int aCenter ) override;
119 void MirrorVertically( int aCenter ) override;
120 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
121
122 virtual void Rotate90( bool aClockwise );
123 virtual void MirrorSpinStyle( bool aLeftRight );
124
125 void BeginEdit( const VECTOR2I& aStartPoint ) override;
126 void CalcEdit( const VECTOR2I& aPosition ) override;
127
128 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
129 {
130 return SCH_ITEM::Matches( GetText(), aSearchData );
131 }
132
133 bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) override
134 {
135 return EDA_TEXT::Replace( aSearchData );
136 }
137
138 bool IsReplaceable() const override { return true; }
139
140 std::vector<int> ViewGetLayers() const override;
141
142 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
143
144 BITMAPS GetMenuImage() const override;
145
146 VECTOR2I GetPosition() const override { return EDA_TEXT::GetTextPos(); }
147 void SetPosition( const VECTOR2I& aPosition ) override
148 {
149 EDA_TEXT::SetTextPos( aPosition );
150 }
151
152 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
153 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
154 bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const override;
155
157
158 void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
159 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
160
161 EDA_ITEM* Clone() const override
162 {
163 return new SCH_TEXT( *this );
164 }
165
166 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
167
168 double Similarity( const SCH_ITEM& aItem ) const override;
169
170 bool operator==( const SCH_ITEM& aItem ) const override;
171
172#if defined(DEBUG)
173 void Show( int nestLevel, std::ostream& os ) const override;
174#endif
175
176 static HTML_MESSAGE_BOX* ShowSyntaxHelp( wxWindow* aParentWindow );
177
178protected:
179 void swapData( SCH_ITEM* aItem ) override;
180
181 const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
182
193 int compare( const SCH_ITEM& aOther, int aCompareFlags = 0 ) const override;
194
195protected:
197};
198
199
200#endif /* SCH_TEXT_H */
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
The base class for create windows for drawing purpose.
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition eda_item.h:416
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:37
virtual VECTOR2I GetTextPos() const
Definition eda_text.h:294
virtual 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:110
virtual void SetTextPos(const VECTOR2I &aPoint)
Definition eda_text.cpp:576
virtual void Offset(const VECTOR2I &aOffset)
Definition eda_text.cpp:595
virtual int GetTextWidth() const
Definition eda_text.h:285
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
Definition eda_text.cpp:482
EDA_TEXT(const EDA_IU_SCALE &aIuScale, const wxString &aText=wxEmptyString)
Definition eda_text.cpp:98
FONT is an abstract base class for both outline and stroke fonts.
Definition font.h:94
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Base plotter engine class.
Definition plotter.h:133
Holds all the data relating to one schematic.
Definition schematic.h:90
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:268
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType, int aUnit=0, int aBodyStyle=0)
Definition sch_item.cpp:52
const KIFONT::METRICS & GetFontMetrics() const
Definition sch_item.cpp:781
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:432
static bool ClassOf(const EDA_ITEM *aItem)
Definition sch_text.h:46
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition sch_text.h:161
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:758
const KIFONT::METRICS & getFontMetrics() const override
Definition sch_text.h:181
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition sch_text.cpp:439
int GetSchTextSize() const
Definition sch_text.h:76
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition sch_text.cpp:277
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition sch_text.cpp:96
KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const override
Definition sch_text.cpp:330
bool m_excludedFromSim
Definition sch_text.h:196
void SetExcludedFromSim(bool aExclude, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Definition sch_text.h:83
bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Definition sch_text.h:89
void DoHypertextAction(EDA_DRAW_FRAME *aFrame, const VECTOR2I &aMousePos) const override
Definition sch_text.cpp:421
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition sch_text.h:111
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition sch_text.cpp:206
~SCH_TEXT() override
Definition sch_text.h:41
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition sch_text.cpp:245
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition sch_text.cpp:485
wxString GetClass() const override
Return the class name.
Definition sch_text.h:51
void NormalizeJustification(bool inverse)
Definition sch_text.cpp:127
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
bool operator<(const SCH_ITEM &aItem) const override
Definition sch_text.cpp:286
VECTOR2I GetPosition() const override
Definition sch_text.h:146
VECTOR2I GetOffsetToMatchSCH_FIELD(SCH_RENDER_SETTINGS *aRenderSettings) const
Definition sch_text.cpp:500
virtual void Rotate90(bool aClockwise)
Definition sch_text.cpp:257
void SetPosition(const VECTOR2I &aPosition) override
Definition sch_text.h:147
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:133
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition sch_text.h:128
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:491
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition sch_text.cpp:167
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:734
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition sch_text.cpp:341
int GetPenWidth() const override
Definition sch_text.cpp:324
bool HasHoveredHypertext() const override
Indicates that a hypertext link is currently active.
Definition sch_text.cpp:415
void SetSchTextSize(int aSize)
Definition sch_text.h:77
virtual wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition sch_text.cpp:362
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:517
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:445
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition sch_text.h:138
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:668
void BeginEdit(const VECTOR2I &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
Definition sch_text.cpp:479
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:120
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition sch_text.h:66
wxString GetFriendlyName() const override
Definition sch_text.h:56
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition sch_text.cpp:76
virtual void MirrorSpinStyle(bool aLeftRight)
Definition sch_text.cpp:268
bool HasHypertext() const override
Indicates that the item has at least one hypertext action.
Definition sch_text.cpp:409
bool operator==(const SCH_ITEM &aItem) const override
Definition sch_text.cpp:717
int GetTextOffset(const RENDER_SETTINGS *aSettings=nullptr) const
Definition sch_text.cpp:309
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:55
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:447
@ LAYER_NOTES
Definition layer_ids.h:465
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:71
@ SCH_TEXT_T
Definition typeinfo.h:148
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683