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-2024 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;
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 = INVALID_FIELD,
57 const wxString& aName = wxEmptyString );
58
59 SCH_FIELD( const SCH_FIELD& aText );
60
61 ~SCH_FIELD() override
62 { }
63
64 SCH_FIELD& operator=( const SCH_FIELD& aField );
65
66 static 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 wxString GetFriendlyName() const override
97 {
98 return _( "Field" );
99 }
100
101 bool IsHypertext() const override
102 {
103 return GetCanonicalName() == wxT( "Intersheetrefs" );
104 }
105
106 void DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const override;
107
115 wxString GetName( bool aUseDefaultName = true ) const;
116
121 wxString GetCanonicalName() const;
122
123 void SetName( const wxString& aName );
124
125 void SetText( const wxString& aText ) override;
126
131 const wxString& GetInternalName() { return m_name; }
132
133 int GetId() const { return m_id; }
134
135 void SetId( int aId );
136
142 wxString GetShownName() const;
143 wxString GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
144 int aDepth = 0 ) const;
145
146 wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override;
147
157 wxString GetFullText( int unit = 1 ) const;
158
163 bool IsEmpty()
164 {
165 wxString name( m_name );
166 wxString value( GetText() );
167
168 return name.Trim().empty() && value.Trim().empty();
169 }
170
171 int GetSchTextSize() const { return GetTextWidth(); }
172 void SetSchTextSize( int aSize ) { SetTextSize( VECTOR2I( aSize, aSize ) ); }
173
174 COLOR4D GetFieldColor() const;
175
176 void SetLastResolvedState( const SCH_ITEM* aItem ) override
177 {
178 const SCH_FIELD* aField = dynamic_cast<const SCH_FIELD*>( aItem );
179
180 if( aField )
182 }
183
184 void ViewGetLayers( int aLayers[], int& aCount ) const override;
185
187
191 EDA_ANGLE GetDrawRotation() const override;
192
193 const BOX2I GetBoundingBox() const override;
194
199 bool IsHorizJustifyFlipped() const;
200 bool IsVertJustifyFlipped() const;
201
204
205 bool IsNameShown() const { return m_showName; }
206 void SetNameShown( bool aShown = true ) { m_showName = aShown; }
207
214 bool IsNamedVariable() const { return m_isNamedVariable; }
215
216 bool CanAutoplace() const { return m_allowAutoPlace; }
217 void SetCanAutoplace( bool aCanPlace ) { m_allowAutoPlace = aCanPlace; }
218
219 void SwapData( SCH_ITEM* aItem ) override;
220
221 int GetPenWidth() const override;
222
223 bool IsAutoAdded() const { return m_autoAdded; }
224 void SetAutoAdded( bool aAutoAdded ) { m_autoAdded = aAutoAdded; }
225
226 bool ShowInChooser() const { return m_showInChooser; }
227 void SetShowInChooser( bool aShow = true ) { m_showInChooser = aShow; }
228
229 void ClearCaches() override;
230 void ClearRenderCache() override;
231
232 std::vector<std::unique_ptr<KIFONT::GLYPH>>*
233 GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forPosition,
234 TEXT_ATTRIBUTES& aAttrs ) const;
235
236 void Move( const VECTOR2I& aMoveVector ) override
237 {
238 Offset( aMoveVector );
239 }
240
241 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
242
243 void MirrorVertically( int aCenter ) override;
244 void MirrorHorizontally( int aCenter ) override;
245
246 void BeginEdit( const VECTOR2I& aStartPoint ) override;
247 void CalcEdit( const VECTOR2I& aPosition ) override;
248
249 void OnScintillaCharAdded( SCINTILLA_TRICKS* aScintillaTricks, wxStyledTextEvent &aEvent ) const;
250
251 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
252
253 bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr ) override;
254
255 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
256 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
257
258 BITMAPS GetMenuImage() const override;
259
260 bool IsReplaceable() const override;
261
263
264 VECTOR2I GetPosition() const override;
265 void SetPosition( const VECTOR2I& aPosition ) override;
266
268
269 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
270 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
271
272 void Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
273 const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed ) override;
274
275 void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
276 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
277
278 EDA_ITEM* Clone() const override;
279
287 void ImportValues( const SCH_FIELD& aSource );
288
294 void Copy( SCH_FIELD* aTarget ) const;
295
296 bool IsMandatory() const;
297
298 bool operator <( const SCH_ITEM& aItem ) const override;
299
300 double Similarity( const SCH_ITEM& aItem ) const override;
301
302 bool operator==( const SCH_ITEM& aItem ) const override;
303 bool operator==( const SCH_FIELD& aItem ) const;
304
305#if defined(DEBUG)
306 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
307#endif
308
309protected:
310 KIFONT::FONT* getDrawFont() const override;
311
312 const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
313
326 int compare( const SCH_ITEM& aOther, int aCompareFlags = 0 ) const override;
327
328private:
329 int m_id;
330
331 wxString m_name;
332
337
340
341 mutable bool m_renderCacheValid;
343 mutable std::vector<std::unique_ptr<KIFONT::GLYPH>> m_renderCache;
344
346};
347
348
349#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:88
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:83
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:234
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:372
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
int GetTextWidth() const
Definition: eda_text.h:225
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:435
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
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:51
void ClearRenderCache() override
Definition: sch_field.cpp:344
int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: sch_field.cpp:1510
wxString GetClass() const override
Return the class name.
Definition: sch_field.h:71
COLOR4D m_lastResolvedColor
Definition: sch_field.h:345
bool IsAutoAdded() const
Definition: sch_field.h:223
GR_TEXT_V_ALIGN_T GetEffectiveVertJustify() const
Definition: sch_field.cpp:683
bool IsMandatory() const
Definition: sch_field.cpp:1398
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_field.cpp:965
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: sch_field.cpp:305
~SCH_FIELD() override
Definition: sch_field.h:61
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_field.cpp:586
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_renderCache
Definition: sch_field.h:343
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:528
VECTOR2I GetPosition() const override
Definition: sch_field.cpp:1376
int GetSchTextSize() const
Definition: sch_field.h:171
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:883
void SetLastResolvedState(const SCH_ITEM *aItem) override
Definition: sch_field.h:176
bool m_showName
Render the field name in addition to its value.
Definition: sch_field.h:333
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_field.cpp:1245
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
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_field.cpp:142
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_field.cpp:1176
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_field.h:66
bool IsNameShown() const
Definition: sch_field.h:205
bool IsHypertext() const override
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_field.h:101
bool m_autoAdded
Was this field automatically added to a LIB_SYMBOL?
Definition: sch_field.h:338
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:1469
void Print(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aForceNoFill, bool aDimmed) override
Print an item.
Definition: sch_field.cpp:397
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:1193
SCH_LAYER_ID GetDefaultLayer() const
Definition: sch_field.cpp:536
bool IsHorizJustifyFlipped() const
Return whether the field will be rendered with the horizontal justification inverted due to rotation ...
Definition: sch_field.cpp:623
bool IsVertJustifyFlipped() const
Definition: sch_field.cpp:660
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: sch_field.cpp:1011
EDA_ANGLE GetDrawRotation() const override
Adjusters to allow EDA_TEXT to draw/print/etc.
Definition: sch_field.cpp:564
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition: sch_field.cpp:1005
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_field.cpp:697
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_field.cpp:987
void SetCanAutoplace(bool aCanPlace)
Definition: sch_field.h:217
bool m_isNamedVariable
If the field name is a variable name, e.g.
Definition: sch_field.h:335
void DoHypertextAction(EDA_DRAW_FRAME *aFrame) const override
Definition: sch_field.cpp:1056
int GetPenWidth() const override
Definition: sch_field.cpp:320
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:1143
COLOR4D GetFieldColor() const
Definition: sch_field.cpp:508
bool IsNamedVariable() const
Named variables are fields whose names are variables like ${VAR}.
Definition: sch_field.h:214
wxString GetFriendlyName() const override
Definition: sch_field.h:96
int GetId() const
Definition: sch_field.h:133
bool operator==(const SCH_ITEM &aItem) const override
Definition: sch_field.cpp:1430
SCH_FIELD & operator=(const SCH_FIELD &aField)
Definition: sch_field.cpp:113
void ImportValues(const SCH_FIELD &aSource)
Copy parameters from a SCH_FIELD source.
Definition: sch_field.cpp:481
void SetAutoAdded(bool aAutoAdded)
Definition: sch_field.h:224
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_field.cpp:1407
wxString GetShownName() const
Gets the fields name as displayed on the schematic or in the symbol fields table.
Definition: sch_field.cpp:191
VECTOR2I GetLibPosition() const
Definition: sch_field.h:262
bool IsEmpty()
Return true if both the name and value of the field are empty.
Definition: sch_field.h:163
bool m_renderCacheValid
Definition: sch_field.h:341
void BeginEdit(const VECTOR2I &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
Definition: sch_field.cpp:999
void SetShowInChooser(bool aShow=true)
Definition: sch_field.h:227
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition: sch_field.cpp:865
void SetSchTextSize(int aSize)
Definition: sch_field.h:172
GR_TEXT_H_ALIGN_T GetEffectiveHorizJustify() const
Definition: sch_field.cpp:646
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:1118
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_field.cpp:1356
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_field.cpp:489
void SetName(const wxString &aName)
Definition: sch_field.cpp:1097
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition: sch_field.cpp:197
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_field.h:236
VECTOR2I m_renderCachePos
Definition: sch_field.h:342
bool CanAutoplace() const
Definition: sch_field.h:216
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const wxString &forResolvedText, const VECTOR2I &forPosition, TEXT_ATTRIBUTES &aAttrs) const
Definition: sch_field.cpp:352
void SetId(int aId)
Definition: sch_field.cpp:154
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:1017
bool ShowInChooser() const
Definition: sch_field.h:226
void ClearCaches() override
Definition: sch_field.cpp:337
void SetText(const wxString &aText) override
Definition: sch_field.cpp:1107
VECTOR2I GetParentPosition() const
Definition: sch_field.cpp:1392
int m_id
Field index,.
Definition: sch_field.h:329
const KIFONT::METRICS & getFontMetrics() const override
Definition: sch_field.h:312
const wxString & GetInternalName()
Get the initial name of the field set at creation (or set by SetName()).
Definition: sch_field.h:131
bool m_showInChooser
This field is available as a data column for the chooser.
Definition: sch_field.h:339
void OnScintillaCharAdded(SCINTILLA_TRICKS *aScintillaTricks, wxStyledTextEvent &aEvent) const
Definition: sch_field.cpp:746
wxString m_name
Definition: sch_field.h:331
void SetNameShown(bool aShown=true)
Definition: sch_field.h:206
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_field.cpp:975
void Copy(SCH_FIELD *aTarget) const
Copy parameters of this field to another field.
Definition: sch_field.cpp:148
KIFONT::FONT * getDrawFont() const override
Definition: sch_field.cpp:326
bool m_allowAutoPlace
This field can be autoplaced.
Definition: sch_field.h:334
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:174
const KIFONT::METRICS & GetFontMetrics() const
Definition: sch_item.cpp:455
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: sch_item.h:189
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.
#define _(s)
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:353
@ DATASHEET_FIELD
name of datasheet
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ INVALID_FIELD
The field ID hasn't been set yet; field is invalid.
@ 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:179
@ SCH_FIELD_LOCATE_FOOTPRINT_T
Definition: typeinfo.h:181
@ SCH_FIELD_T
Definition: typeinfo.h:150
@ SCH_FIELD_LOCATE_VALUE_T
Definition: typeinfo.h:180
@ SCH_FIELD_LOCATE_DATASHEET_T
Definition: typeinfo.h:182
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588