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) 2022 CERN
6 * Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#ifndef CLASS_SCH_FIELD_H
27#define CLASS_SCH_FIELD_H
28
29
30#include <eda_text.h>
31#include <sch_item.h>
32#include <template_fieldnames.h>
33#include <general.h>
34
35class SCH_EDIT_FRAME;
36class LIB_FIELD;
37
38
50class SCH_FIELD : public SCH_ITEM, public EDA_TEXT
51{
52public:
53 SCH_FIELD( const VECTOR2I& aPos, int aFieldId, SCH_ITEM* aParent,
54 const wxString& aName = wxEmptyString );
55
56 SCH_FIELD( SCH_ITEM* aParent, int aFieldId, const wxString& aName = wxEmptyString );
57
58 SCH_FIELD( const SCH_FIELD& aText );
59
61 { }
62
63 SCH_FIELD& operator=( const SCH_FIELD& aField );
64
65 static inline bool ClassOf( const EDA_ITEM* aItem )
66 {
67 return aItem && SCH_FIELD_T == aItem->Type();
68 }
69
70 wxString GetClass() const override
71 {
72 return wxT( "SCH_FIELD" );
73 }
74
75 bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
76 {
77 if( SCH_ITEM::IsType( aScanTypes ) )
78 return true;
79
80 for( KICAD_T scanType : aScanTypes )
81 {
83 return true;
84 else if ( scanType == SCH_FIELD_LOCATE_VALUE_T && m_id == VALUE_FIELD )
85 return true;
86 else if ( scanType == SCH_FIELD_LOCATE_FOOTPRINT_T && m_id == FOOTPRINT_FIELD )
87 return true;
88 else if ( scanType == SCH_FIELD_LOCATE_DATASHEET_T && m_id == DATASHEET_FIELD )
89 return true;
90 }
91
92 return false;
93 }
94
95 bool IsHypertext() const override
96 {
97 return m_id == 0 && m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T;
98 }
99
100 void DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const override;
101
109 wxString GetName( bool aUseDefaultName = true ) const;
110
115 wxString GetCanonicalName() const;
116
117 void SetName( const wxString& aName ) { m_name = aName; }
118
123 const wxString& GetInternalName() { return m_name; }
124
125 int GetId() const { return m_id; }
126
127 void SetId( int aId );
128
129 wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override;
130
131 COLOR4D GetFieldColor() const;
132
133 void SetLastResolvedState( const SCH_ITEM* aItem ) override
134 {
135 const SCH_FIELD* aField = dynamic_cast<const SCH_FIELD*>( aItem );
136
137 if( aField )
139 }
140
144 EDA_ANGLE GetDrawRotation() const override;
145
146 const BOX2I GetBoundingBox() const override;
147
152 bool IsHorizJustifyFlipped() const;
153 bool IsVertJustifyFlipped() const;
154
157
158 bool IsNameShown() const { return m_showName; }
159 void SetNameShown( bool aShown = true ) { m_showName = aShown; }
160
161 bool CanAutoplace() const { return m_allowAutoPlace; }
162 void SetCanAutoplace( bool aCanPlace ) { m_allowAutoPlace = aCanPlace; }
163
164 void SwapData( SCH_ITEM* aItem ) override;
165
173 void ImportValues( const LIB_FIELD& aSource );
174
175 int GetPenWidth() const override;
176
177 void ClearCaches() override;
178 void ClearRenderCache() override;
179
180 std::vector<std::unique_ptr<KIFONT::GLYPH>>*
181 GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forPosition,
182 TEXT_ATTRIBUTES& aAttrs ) const;
183
184 void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) override;
185
186 void Move( const VECTOR2I& aMoveVector ) override
187 {
188 Offset( aMoveVector );
189 }
190
191 void Rotate( const VECTOR2I& aCenter ) override;
192
200 void MirrorVertically( int aCenter ) override
201 {
202 }
203
211 void MirrorHorizontally( int aCenter ) override
212 {
213 }
214
215 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
216
217 bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr ) override;
218
219 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
220 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
221
222 BITMAPS GetMenuImage() const override;
223
224 bool IsReplaceable() const override;
225
227
228 VECTOR2I GetPosition() const override;
229 void SetPosition( const VECTOR2I& aPosition ) override;
230
232
233 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
234 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
235
236 void Plot( PLOTTER* aPlotter, bool aBackground ) const override;
237
238 EDA_ITEM* Clone() const override;
239
240 bool operator <( const SCH_ITEM& aItem ) const override;
241
242#if defined(DEBUG)
243 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
244#endif
245
246protected:
247 KIFONT::FONT* getDrawFont() const override;
248
249private:
250 int m_id;
251
252 wxString m_name;
253
256
257 mutable bool m_renderCacheValid;
259 mutable std::vector<std::unique_ptr<KIFONT::GLYPH>> m_renderCache;
260
262};
263
264
265#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:208
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:61
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:51
void ClearRenderCache() override
Definition: sch_field.cpp:268
wxString GetClass() const override
Return the class name.
Definition: sch_field.h:70
COLOR4D m_lastResolvedColor
Definition: sch_field.h:261
GR_TEXT_V_ALIGN_T GetEffectiveVertJustify() const
Definition: sch_field.cpp:550
wxString GetShownText(int aDepth=0, bool aAllowExtraText=true) const override
Return the string actually shown after processing of the base text.
Definition: sch_field.cpp:175
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_field.cpp:448
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_renderCache
Definition: sch_field.h:259
void Plot(PLOTTER *aPlotter, bool aBackground) const override
Plot the schematic item to aPlotter.
Definition: sch_field.cpp:952
VECTOR2I GetPosition() const override
Definition: sch_field.cpp:1061
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:640
void SetLastResolvedState(const SCH_ITEM *aItem) override
Definition: sch_field.h:133
bool m_showName
Render the field name in addition to its value.
Definition: sch_field.h:254
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_field.cpp:723
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: sch_field.h:75
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset) override
Print a schematic item.
Definition: sch_field.cpp:315
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_field.cpp:132
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_field.cpp:892
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_field.h:65
bool IsNameShown() const
Definition: sch_field.h:158
bool IsHypertext() const override
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_field.h:95
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:909
bool IsHorizJustifyFlipped() const
Return whether the field will be rendered with the horizontal justification inverted due to rotation ...
Definition: sch_field.cpp:490
bool IsVertJustifyFlipped() const
Definition: sch_field.cpp:527
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: sch_field.cpp:731
EDA_ANGLE GetDrawRotation() const override
Adjusters to allow EDA_TEXT to draw/print/etc.
Definition: sch_field.cpp:426
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_field.cpp:564
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_field.h:200
void SetCanAutoplace(bool aCanPlace)
Definition: sch_field.h:162
void DoHypertextAction(EDA_DRAW_FRAME *aFrame) const override
Definition: sch_field.cpp:774
int GetPenWidth() const override
Definition: sch_field.cpp:244
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:845
COLOR4D GetFieldColor() const
Definition: sch_field.cpp:406
int GetId() const
Definition: sch_field.h:125
SCH_FIELD & operator=(const SCH_FIELD &aField)
Definition: sch_field.cpp:106
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_field.cpp:1083
VECTOR2I GetLibPosition() const
Definition: sch_field.h:226
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:257
~SCH_FIELD()
Definition: sch_field.h:60
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition: sch_field.cpp:612
GR_TEXT_H_ALIGN_T GetEffectiveHorizJustify() const
Definition: sch_field.cpp:513
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:813
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_field.cpp:1041
void ImportValues(const LIB_FIELD &aSource)
Copy parameters from a LIB_FIELD source.
Definition: sch_field.cpp:381
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_field.cpp:389
void SetName(const wxString &aName)
Definition: sch_field.h:117
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_field.h:186
VECTOR2I m_renderCachePos
Definition: sch_field.h:258
bool CanAutoplace() const
Definition: sch_field.h:161
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const wxString &forResolvedText, const VECTOR2I &forPosition, TEXT_ATTRIBUTES &aAttrs) const
Definition: sch_field.cpp:276
void SetId(int aId)
Definition: sch_field.cpp: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_field.cpp:737
void ClearCaches() override
Definition: sch_field.cpp:261
VECTOR2I GetParentPosition() const
Definition: sch_field.cpp:1077
int m_id
Field index,.
Definition: sch_field.h:250
const wxString & GetInternalName()
Get the initial name of the field set at creation (or set by SetName()).
Definition: sch_field.h:123
wxString m_name
Definition: sch_field.h:252
void SetNameShown(bool aShown=true)
Definition: sch_field.h:159
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_field.h:211
KIFONT::FONT * getDrawFont() const override
Definition: sch_field.cpp:250
bool m_allowAutoPlace
This field can be autoplaced.
Definition: sch_field.h:255
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:164
@ SCH_FIELD_LOCATE_FOOTPRINT_T
Definition: typeinfo.h:166
@ SCH_FIELD_T
Definition: typeinfo.h:155
@ SCH_FIELD_LOCATE_VALUE_T
Definition: typeinfo.h:165
@ SCH_FIELD_LOCATE_DATASHEET_T
Definition: typeinfo.h:167
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:152