KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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#include "scintilla_tricks.h"
35
36class SCH_EDIT_FRAME;
37class LIB_FIELD;
38
39
51class SCH_FIELD : public SCH_ITEM, public EDA_TEXT
52{
53public:
54 SCH_FIELD( const VECTOR2I& aPos, int aFieldId, SCH_ITEM* aParent,
55 const wxString& aName = wxEmptyString );
56
57 SCH_FIELD( SCH_ITEM* aParent, int aFieldId, const wxString& aName = wxEmptyString );
58
59 SCH_FIELD( const SCH_FIELD& aText );
60
62 { }
63
64 SCH_FIELD& operator=( const SCH_FIELD& aField );
65
66 static inline bool ClassOf( const EDA_ITEM* aItem )
67 {
68 return aItem && SCH_FIELD_T == aItem->Type();
69 }
70
71 wxString GetClass() const override
72 {
73 return wxT( "SCH_FIELD" );
74 }
75
76 bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
77 {
78 if( SCH_ITEM::IsType( aScanTypes ) )
79 return true;
80
81 for( KICAD_T scanType : aScanTypes )
82 {
84 return true;
85 else if ( scanType == SCH_FIELD_LOCATE_VALUE_T && m_id == VALUE_FIELD )
86 return true;
87 else if ( scanType == SCH_FIELD_LOCATE_FOOTPRINT_T && m_id == FOOTPRINT_FIELD )
88 return true;
89 else if ( scanType == SCH_FIELD_LOCATE_DATASHEET_T && m_id == DATASHEET_FIELD )
90 return true;
91 }
92
93 return false;
94 }
95
96 bool IsHypertext() const override
97 {
98 return GetCanonicalName() == wxT( "Intersheetrefs" );
99 }
100
101 void DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const override;
102
110 wxString GetName( bool aUseDefaultName = true ) const;
111
116 wxString GetCanonicalName() const;
117
118 void SetName( const wxString& aName );
119
120 void SetText( const wxString& aText ) override;
121
126 const wxString& GetInternalName() { return m_name; }
127
128 int GetId() const { return m_id; }
129
130 void SetId( int aId );
131
137 wxString GetShownName() const;
138 wxString GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
139 int aDepth = 0 ) const;
140
141 wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override;
142
147 bool IsEmpty()
148 {
149 wxString name( m_name );
150 wxString value( GetText() );
151
152 return name.Trim().empty() && value.Trim().empty();
153 }
154
155 int GetSchTextSize() const { return GetTextWidth(); }
156 void SetSchTextSize( int aSize ) { SetTextSize( VECTOR2I( aSize, aSize ) ); }
157
158 COLOR4D GetFieldColor() const;
159
160 void SetLastResolvedState( const SCH_ITEM* aItem ) override
161 {
162 const SCH_FIELD* aField = dynamic_cast<const SCH_FIELD*>( aItem );
163
164 if( aField )
166 }
167
168 void ViewGetLayers( int aLayers[], int& aCount ) const override;
169
173 EDA_ANGLE GetDrawRotation() const override;
174
175 const BOX2I GetBoundingBox() const override;
176
181 bool IsHorizJustifyFlipped() const;
182 bool IsVertJustifyFlipped() const;
183
186
187 bool IsNameShown() const { return m_showName; }
188 void SetNameShown( bool aShown = true ) { m_showName = aShown; }
189
196 bool IsNamedVariable() const { return m_isNamedVariable; }
197
198 bool CanAutoplace() const { return m_allowAutoPlace; }
199 void SetCanAutoplace( bool aCanPlace ) { m_allowAutoPlace = aCanPlace; }
200
201 void SwapData( SCH_ITEM* aItem ) override;
202
210 void ImportValues( const LIB_FIELD& aSource );
211
212 int GetPenWidth() const override;
213
214 void ClearCaches() override;
215 void ClearRenderCache() override;
216
217 std::vector<std::unique_ptr<KIFONT::GLYPH>>*
218 GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forPosition,
219 TEXT_ATTRIBUTES& aAttrs ) const;
220
221 void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) override;
222
223 void Move( const VECTOR2I& aMoveVector ) override
224 {
225 Offset( aMoveVector );
226 }
227
228 void Rotate( const VECTOR2I& aCenter ) override;
229
237 void MirrorVertically( int aCenter ) override
238 {
239 }
240
248 void MirrorHorizontally( int aCenter ) override
249 {
250 }
251
252 void OnScintillaCharAdded( SCINTILLA_TRICKS* aScintillaTricks, wxStyledTextEvent &aEvent ) const;
253
254 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
255
256 bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr ) override;
257
258 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
259 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
260
261 BITMAPS GetMenuImage() const override;
262
263 bool IsReplaceable() const override;
264
266
267 VECTOR2I GetPosition() const override;
268 void SetPosition( const VECTOR2I& aPosition ) override;
269
271
272 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
273 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
274
275 void Plot( PLOTTER* aPlotter, bool aBackground,
276 const SCH_PLOT_SETTINGS& aPlotSettings ) const override;
277
278 EDA_ITEM* Clone() const override;
279
280 bool operator <( const SCH_ITEM& aItem ) const override;
281
282 double Similarity( const SCH_ITEM& aItem ) const override;
283
284 bool operator==( const SCH_ITEM& aItem ) const override;
285
286#if defined(DEBUG)
287 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
288#endif
289
290protected:
291 KIFONT::FONT* getDrawFont() const override;
292
293 const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
294
295private:
296 int m_id;
297
298 wxString m_name;
299
304
305 mutable bool m_renderCacheValid;
307 mutable std::vector<std::unique_ptr<KIFONT::GLYPH>> m_renderCache;
308
310};
311
312
313#endif /* CLASS_SCH_FIELD_H */
const char * name
Definition: DXF_plotter.cpp:57
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
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:80
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:231
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:374
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:95
int GetTextWidth() const
Definition: eda_text.h:222
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:437
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
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:62
Base plotter engine class.
Definition: plotter.h:104
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:52
void ClearRenderCache() override
Definition: sch_field.cpp:299
wxString GetClass() const override
Return the class name.
Definition: sch_field.h:71
COLOR4D m_lastResolvedColor
Definition: sch_field.h:309
GR_TEXT_V_ALIGN_T GetEffectiveVertJustify() const
Definition: sch_field.cpp:612
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_field.cpp:510
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_renderCache
Definition: sch_field.h:307
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: sch_field.cpp:473
VECTOR2I GetPosition() const override
Definition: sch_field.cpp:1274
int GetSchTextSize() const
Definition: sch_field.h:155
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:812
void SetLastResolvedState(const SCH_ITEM *aItem) override
Definition: sch_field.h:160
bool m_showName
Render the field name in addition to its value.
Definition: sch_field.h:300
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_field.cpp:894
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: sch_field.h:76
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset) override
Print a schematic item.
Definition: sch_field.cpp:352
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_field.cpp:139
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_field.cpp:1088
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_field.h:66
bool IsNameShown() const
Definition: sch_field.h:187
bool IsHypertext() const override
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_field.h:96
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_field.cpp:1347
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:1105
bool IsHorizJustifyFlipped() const
Return whether the field will be rendered with the horizontal justification inverted due to rotation ...
Definition: sch_field.cpp:552
bool IsVertJustifyFlipped() const
Definition: sch_field.cpp:589
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: sch_field.cpp:902
EDA_ANGLE GetDrawRotation() const override
Adjusters to allow EDA_TEXT to draw/print/etc.
Definition: sch_field.cpp:488
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_field.cpp:626
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_field.h:237
void SetCanAutoplace(bool aCanPlace)
Definition: sch_field.h:199
bool m_isNamedVariable
If the field name is a variable name, e.g.
Definition: sch_field.h:302
void DoHypertextAction(EDA_DRAW_FRAME *aFrame) const override
Definition: sch_field.cpp:947
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_SETTINGS &aPlotSettings) const override
Plot the schematic item to aPlotter.
Definition: sch_field.cpp:1148
int GetPenWidth() const override
Definition: sch_field.cpp:275
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:1039
COLOR4D GetFieldColor() const
Definition: sch_field.cpp:453
bool IsNamedVariable() const
Named variables are fields whose names are variables like ${VAR}.
Definition: sch_field.h:196
int GetId() const
Definition: sch_field.h:128
bool operator==(const SCH_ITEM &aItem) const override
Definition: sch_field.cpp:1318
SCH_FIELD & operator=(const SCH_FIELD &aField)
Definition: sch_field.cpp:110
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_field.cpp:1296
wxString GetShownName() const
Gets the fields name as displayed on the schematic or in the symbol fields table.
Definition: sch_field.cpp:182
VECTOR2I GetLibPosition() const
Definition: sch_field.h:265
bool IsEmpty()
Return true if both the name and value of the field are empty.
Definition: sch_field.h:147
bool m_renderCacheValid
Definition: sch_field.h:305
~SCH_FIELD()
Definition: sch_field.h:61
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition: sch_field.cpp:794
void SetSchTextSize(int aSize)
Definition: sch_field.h:156
GR_TEXT_H_ALIGN_T GetEffectiveHorizJustify() const
Definition: sch_field.cpp:575
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:1007
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_field.cpp:1254
void ImportValues(const LIB_FIELD &aSource)
Copy parameters from a LIB_FIELD source.
Definition: sch_field.cpp:425
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_field.cpp:433
void SetName(const wxString &aName)
Definition: sch_field.cpp:986
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition: sch_field.cpp:188
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_field.h:223
VECTOR2I m_renderCachePos
Definition: sch_field.h:306
bool CanAutoplace() const
Definition: sch_field.h:198
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const wxString &forResolvedText, const VECTOR2I &forPosition, TEXT_ATTRIBUTES &aAttrs) const
Definition: sch_field.cpp:307
void SetId(int aId)
Definition: sch_field.cpp:145
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:908
void ClearCaches() override
Definition: sch_field.cpp:292
void SetText(const wxString &aText) override
Definition: sch_field.cpp:996
VECTOR2I GetParentPosition() const
Definition: sch_field.cpp:1290
int m_id
Field index,.
Definition: sch_field.h:296
const KIFONT::METRICS & getFontMetrics() const override
Definition: sch_field.h:293
const wxString & GetInternalName()
Get the initial name of the field set at creation (or set by SetName()).
Definition: sch_field.h:126
void OnScintillaCharAdded(SCINTILLA_TRICKS *aScintillaTricks, wxStyledTextEvent &aEvent) const
Definition: sch_field.cpp:675
wxString m_name
Definition: sch_field.h:298
void SetNameShown(bool aShown=true)
Definition: sch_field.h:188
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_field.h:248
KIFONT::FONT * getDrawFont() const override
Definition: sch_field.cpp:281
bool m_allowAutoPlace
This field can be autoplaced.
Definition: sch_field.h:301
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:165
const KIFONT::METRICS & GetFontMetrics() const
Definition: sch_item.cpp:331
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: sch_item.h:180
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
@ 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:168
@ SCH_FIELD_LOCATE_FOOTPRINT_T
Definition: typeinfo.h:170
@ SCH_FIELD_T
Definition: typeinfo.h:159
@ SCH_FIELD_LOCATE_VALUE_T
Definition: typeinfo.h:169
@ SCH_FIELD_LOCATE_DATASHEET_T
Definition: typeinfo.h:171
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588