KiCad PCB EDA Suite
sch_field.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) 2004-2021 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 CLASS_SCH_FIELD_H
26#define CLASS_SCH_FIELD_H
27
28
29#include <eda_text.h>
30#include <sch_item.h>
31#include <template_fieldnames.h>
32#include <general.h>
33
34class SCH_EDIT_FRAME;
35class LIB_FIELD;
36
37
49class SCH_FIELD : public SCH_ITEM, public EDA_TEXT
50{
51public:
52 SCH_FIELD( const VECTOR2I& aPos, int aFieldId, SCH_ITEM* aParent,
53 const wxString& aName = wxEmptyString );
54
55 SCH_FIELD( const SCH_FIELD& aText );
56
58 { }
59
60 SCH_FIELD& operator=( const SCH_FIELD& aField );
61
62 static inline bool ClassOf( const EDA_ITEM* aItem )
63 {
64 return aItem && SCH_FIELD_T == aItem->Type();
65 }
66
67 wxString GetClass() const override
68 {
69 return wxT( "SCH_FIELD" );
70 }
71
72 bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
73 {
74 if( SCH_ITEM::IsType( aScanTypes ) )
75 return true;
76
77 for( KICAD_T scanType : aScanTypes )
78 {
80 return true;
81 else if ( scanType == SCH_FIELD_LOCATE_VALUE_T && m_id == VALUE_FIELD )
82 return true;
83 else if ( scanType == SCH_FIELD_LOCATE_FOOTPRINT_T && m_id == FOOTPRINT_FIELD )
84 return true;
85 else if ( scanType == SCH_FIELD_LOCATE_DATASHEET_T && m_id == DATASHEET_FIELD )
86 return true;
87 }
88
89 return false;
90 }
91
92 bool IsHypertext() const override
93 {
94 return m_id == 0 && m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T;
95 }
96
97 void DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const override;
98
106 wxString GetName( bool aUseDefaultName = true ) const;
107
112 wxString GetCanonicalName() const;
113
114 void SetName( const wxString& aName ) { m_name = aName; }
115
116 int GetId() const { return m_id; }
117
118 void SetId( int aId );
119
120 wxString GetShownText( int aDepth = 0 ) const override;
121
122 COLOR4D GetFieldColor() const;
123
124 void SetLastResolvedState( const SCH_ITEM* aItem ) override
125 {
126 const SCH_FIELD* aField = dynamic_cast<const SCH_FIELD*>( aItem );
127
128 if( aField )
130 }
131
135 EDA_ANGLE GetDrawRotation() const override;
136
137 const BOX2I GetBoundingBox() const override;
138
143 bool IsHorizJustifyFlipped() const;
144 bool IsVertJustifyFlipped() const;
145
148
149 bool IsNameShown() const { return m_showName; }
150 void SetNameShown( bool aShown = true ) { m_showName = aShown; }
151
152 bool CanAutoplace() const { return m_allowAutoPlace; }
153 void SetCanAutoplace( bool aCanPlace ) { m_allowAutoPlace = aCanPlace; }
154
158 bool IsVoid() const;
159
160 void SwapData( SCH_ITEM* aItem ) override;
161
169 void ImportValues( const LIB_FIELD& aSource );
170
171 int GetPenWidth() const override;
172
173 KIFONT::FONT* GetDrawFont() const override;
174
175 void ClearCaches() override;
176 void ClearRenderCache() override;
177
178 std::vector<std::unique_ptr<KIFONT::GLYPH>>*
179 GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forPosition,
180 TEXT_ATTRIBUTES& aAttrs ) const;
181
182 void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) override;
183
184 void Move( const VECTOR2I& aMoveVector ) override
185 {
186 Offset( aMoveVector );
187 }
188
189 void Rotate( const VECTOR2I& aCenter ) override;
190
198 void MirrorVertically( int aCenter ) override
199 {
200 }
201
209 void MirrorHorizontally( int aCenter ) override
210 {
211 }
212
213 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
214
215 bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr ) override;
216
217 wxString GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const override;
218 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
219
220 BITMAPS GetMenuImage() const override;
221
222 bool IsReplaceable() const override;
223
225
226 VECTOR2I GetPosition() const override;
227 void SetPosition( const VECTOR2I& aPosition ) override;
228
230
231 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
232 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
233
234 void Plot( PLOTTER* aPlotter, bool aBackground ) const override;
235
236 EDA_ITEM* Clone() const override;
237
238 bool operator <( const SCH_ITEM& aItem ) const override;
239
240#if defined(DEBUG)
241 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
242#endif
243
244private:
245 int m_id;
246
247 wxString m_name;
248
251
252 mutable bool m_renderCacheValid;
254 mutable std::vector<std::unique_ptr<KIFONT::GLYPH>> m_renderCache;
255
257};
258
259
260#endif /* CLASS_SCH_FIELD_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
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:496
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
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:389
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:105
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Field object used in symbol libraries.
Definition: lib_field.h:60
Base plotter engine class.
Definition: plotter.h:110
Schematic editor (Eeschema) main window.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:50
void ClearRenderCache() override
Definition: sch_field.cpp:287
wxString GetClass() const override
Return the class name.
Definition: sch_field.h:67
COLOR4D m_lastResolvedColor
Definition: sch_field.h:256
GR_TEXT_V_ALIGN_T GetEffectiveVertJustify() const
Definition: sch_field.cpp:542
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_field.cpp:440
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_renderCache
Definition: sch_field.h:254
void Plot(PLOTTER *aPlotter, bool aBackground) const override
Plot the schematic item to aPlotter.
Definition: sch_field.cpp:948
VECTOR2I GetPosition() const override
Definition: sch_field.cpp:1052
bool Replace(const EDA_SEARCH_DATA &aSearchData, void *aAuxData=nullptr) override
Perform a text replace using the find and replace criteria in aSearchData on items that support text ...
Definition: sch_field.cpp:638
void SetLastResolvedState(const SCH_ITEM *aItem) override
Definition: sch_field.h:124
bool m_showName
Render the field name in addition to its value.
Definition: sch_field.h:249
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_field.cpp:721
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: sch_field.h:72
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset) override
Print a schematic item.
Definition: sch_field.cpp:328
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_field.cpp:126
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_field.cpp:888
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_field.h:62
bool IsNameShown() const
Definition: sch_field.h:149
bool IsVoid() const
Definition: sch_field.cpp:556
bool IsHypertext() const override
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_field.h:92
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_field.cpp:905
bool IsHorizJustifyFlipped() const
Return whether the field will be rendered with the horizontal justification inverted due to rotation ...
Definition: sch_field.cpp:482
bool IsVertJustifyFlipped() const
Definition: sch_field.cpp:519
EDA_ANGLE GetDrawRotation() const override
Adjusters to allow EDA_TEXT to draw/print/etc.
Definition: sch_field.cpp:418
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_field.cpp:562
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_field.h:198
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_field.cpp:169
void SetCanAutoplace(bool aCanPlace)
Definition: sch_field.h:153
void DoHypertextAction(EDA_DRAW_FRAME *aFrame) const override
Definition: sch_field.cpp:772
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_field.cpp:729
KIFONT::FONT * GetDrawFont() const override
Definition: sch_field.cpp:269
int GetPenWidth() const override
Definition: sch_field.cpp:263
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: sch_field.cpp:843
COLOR4D GetFieldColor() const
Definition: sch_field.cpp:400
int GetId() const
Definition: sch_field.h:116
SCH_FIELD & operator=(const SCH_FIELD &aField)
Definition: sch_field.cpp:100
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_field.cpp:1074
VECTOR2I GetLibPosition() const
Definition: sch_field.h:224
SCH_FIELD(const VECTOR2I &aPos, int aFieldId, SCH_ITEM *aParent, const wxString &aName=wxEmptyString)
Definition: sch_field.cpp:59
bool m_renderCacheValid
Definition: sch_field.h:252
~SCH_FIELD()
Definition: sch_field.h:57
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition: sch_field.cpp:610
GR_TEXT_H_ALIGN_T GetEffectiveHorizJustify() const
Definition: sch_field.cpp:505
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:811
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_field.cpp:1032
void ImportValues(const LIB_FIELD &aSource)
Copy parameters from a LIB_FIELD source.
Definition: sch_field.cpp:375
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_field.cpp:383
void SetName(const wxString &aName)
Definition: sch_field.h:114
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_field.h:184
VECTOR2I m_renderCachePos
Definition: sch_field.h:253
bool CanAutoplace() const
Definition: sch_field.h:152
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const wxString &forResolvedText, const VECTOR2I &forPosition, TEXT_ATTRIBUTES &aAttrs) const
Definition: sch_field.cpp:295
void SetId(int aId)
Definition: sch_field.cpp:132
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_field.cpp:735
void ClearCaches() override
Definition: sch_field.cpp:280
VECTOR2I GetParentPosition() const
Definition: sch_field.cpp:1068
int m_id
Field index,.
Definition: sch_field.h:245
wxString m_name
Definition: sch_field.h:247
void SetNameShown(bool aShown=true)
Definition: sch_field.h:150
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_field.h:209
bool m_allowAutoPlace
This field can be autoplaced.
Definition: sch_field.h:250
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: sch_item.h:162
@ DATASHEET_FIELD
name of datasheet
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
GR_TEXT_H_ALIGN_T
GR_TEXT_V_ALIGN_T
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ SCH_FIELD_LOCATE_REFERENCE_T
Definition: typeinfo.h:163
@ SCH_FIELD_LOCATE_FOOTPRINT_T
Definition: typeinfo.h:165
@ SCH_FIELD_T
Definition: typeinfo.h:154
@ SCH_FIELD_LOCATE_VALUE_T
Definition: typeinfo.h:164
@ SCH_FIELD_LOCATE_DATASHEET_T
Definition: typeinfo.h:166
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:151