KiCad PCB EDA Suite
Loading...
Searching...
No Matches
lib_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) 2019 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
30#ifndef CLASS_LIBENTRY_FIELDS_H
31#define CLASS_LIBENTRY_FIELDS_H
32
33#include <eda_text.h>
34#include <lib_item.h>
35
36
38
39
61class LIB_FIELD : public LIB_ITEM, public EDA_TEXT
62{
63public:
64 LIB_FIELD( int aId = 2 );
65
66 LIB_FIELD( int aId, const wxString& aName );
67
68 LIB_FIELD( LIB_SYMBOL* aParent, int aId = 2, const wxString& aName = wxEmptyString );
69
70 // Do not create a copy constructor. The one generated by the compiler is adequate.
71
72 wxString GetClass() const override
73 {
74 return wxT( "LIB_FIELD" );
75 }
76
77 static inline bool ClassOf( const EDA_ITEM* aItem )
78 {
79 return aItem && aItem->Type() == LIB_FIELD_T;
80 }
81
82 wxString GetTypeName() const override
83 {
84 return _( "Field" );
85 }
86
90 void Init( int aId );
91
101 wxString GetName( bool aUseDefaultName = true ) const;
102
107 wxString GetCanonicalName() const;
108
118 void SetName( const wxString& aName );
119
120 int GetId() const { return m_id; }
121 void SetId( int aId );
122
123 int GetPenWidth() const override;
124
125 KIFONT::FONT* getDrawFont() const override;
126
127 bool IsHorizJustifyFlipped() const { return false; }
128 bool IsVertJustifyFlipped() const { return false; }
129
132
138 void Copy( LIB_FIELD* aTarget ) const;
139
140 void ViewGetLayers( int aLayers[], int& aCount ) const override;
141
142 const BOX2I GetBoundingBox() const override;
143
144 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
145
146 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
147
148 LIB_FIELD& operator=( const LIB_FIELD& field );
149
160 wxString GetFullText( int unit = 1 ) const;
161
162 wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override;
163
165
166 void BeginEdit( const VECTOR2I& aStartPoint ) override;
167
168 void Offset( const VECTOR2I& aOffset ) override;
169
170 void MoveTo( const VECTOR2I& aPosition ) override;
171
172 VECTOR2I GetPosition() const override { return EDA_TEXT::GetTextPos(); }
173
174 void MirrorHorizontal( const VECTOR2I& aCenter ) override;
175 void MirrorVertical( const VECTOR2I& aCenter ) override;
176 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) override;
177
178 void Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffset,
179 const TRANSFORM& aTransform, bool aDimmed ) const override;
180
181 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
182
183 BITMAPS GetMenuImage() const override;
184
185 EDA_ITEM* Clone() const override;
186
187 bool IsMandatory() const;
188
189 bool IsAutoAdded() const { return m_autoAdded; }
190 void SetAutoAdded( bool aAutoAdded ) { m_autoAdded = aAutoAdded; }
191
192 bool IsNameShown() const { return m_showName; }
193 void SetNameShown( bool aShown = true ) { m_showName = aShown; }
194
195 bool CanAutoplace() const { return m_allowAutoPlace; }
196 void SetCanAutoplace( bool aCanPlace ) { m_allowAutoPlace = aCanPlace; }
197
198 bool ShowInChooser() const { return m_showInChooser; }
199 void SetShowInChooser( bool aShow = true ) { m_showInChooser = aShow; }
200
201 double Similarity( const LIB_ITEM& aItem ) const override;
202
203 bool operator==( const LIB_ITEM& aItem ) const override;
204
205private:
206
219 int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const override;
220
227 void print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
228 const TRANSFORM& aTransform, bool aDimmed ) override;
229
235 void CalcEdit( const VECTOR2I& aPosition ) override;
236
237 friend class SCH_IO_KICAD_LEGACY_LIB_CACHE; // Required to access m_name.
238
239 int m_id;
240 wxString m_name;
245};
246
247#endif // CLASS_LIBENTRY_FIELDS_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
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
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:161
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:164
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
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
bool IsAutoAdded() const
Definition: lib_field.h:189
bool m_allowAutoPlace
This field can be autoplaced when converted to a SCH_FIELD.
Definition: lib_field.h:243
void SetAutoAdded(bool aAutoAdded)
Definition: lib_field.h:190
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: lib_field.cpp:197
wxString GetClass() const override
Return the class name.
Definition: lib_field.h:72
void Offset(const VECTOR2I &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_field.cpp:288
void Init(int aId)
Object constructor initialization helper.
Definition: lib_field.cpp:85
bool m_autoAdded
Was this field automatically added to a LIB_SYMBOL?
Definition: lib_field.h:241
bool ShowInChooser() const
Definition: lib_field.h:198
int m_id
Definition: lib_field.h:239
KIFONT::FONT * getDrawFont() const override
Definition: lib_field.cpp:119
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_field.cpp:324
wxString m_name
Name (not the field text value itself, that is #EDA_TEXT::m_Text)
Definition: lib_field.h:240
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: lib_field.cpp:459
void print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, void *aData, const TRANSFORM &aTransform, bool aDimmed) override
Print the field.
Definition: lib_field.cpp:130
wxString GetTypeName() const override
Provide a user-consumable name of the object type.
Definition: lib_field.h:82
bool CanAutoplace() const
Definition: lib_field.h:195
SCH_LAYER_ID GetDefaultLayer() const
Definition: lib_field.cpp:474
void Plot(PLOTTER *aPlotter, bool aBackground, const VECTOR2I &aOffset, const TRANSFORM &aTransform, bool aDimmed) const override
Plot the draw item using the plot object.
Definition: lib_field.cpp:336
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: lib_field.cpp:516
void SetId(int aId)
Definition: lib_field.cpp:107
bool operator==(const LIB_ITEM &aItem) const override
Test LIB_ITEM objects for equivalence.
Definition: lib_field.cpp:590
void SetName(const wxString &aName)
Set a user definable field name to aName.
Definition: lib_field.cpp:503
void SetShowInChooser(bool aShow=true)
Definition: lib_field.h:199
VECTOR2I GetPosition() const override
Definition: lib_field.h:172
void Copy(LIB_FIELD *aTarget) const
Copy parameters of this field to another field.
Definition: lib_field.cpp:203
bool m_showInChooser
This field is available as a data column for the chooser.
Definition: lib_field.h:244
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:406
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: lib_field.cpp:485
bool IsNameShown() const
Definition: lib_field.h:192
void BeginEdit(const VECTOR2I &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
Definition: lib_field.cpp:524
GR_TEXT_H_ALIGN_T GetEffectiveHorizJustify() const
Definition: lib_field.h:130
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: lib_field.cpp:494
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: lib_field.cpp:578
double Similarity(const LIB_ITEM &aItem) const override
Return a measure of how likely the other object is to represent the same object.
Definition: lib_field.cpp:619
int GetPenWidth() const override
Definition: lib_field.cpp:113
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: lib_field.cpp:423
GR_TEXT_V_ALIGN_T GetEffectiveVertJustify() const
Definition: lib_field.h:131
void MirrorHorizontal(const VECTOR2I &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_field.cpp:300
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the new circle at aPosition when editing.
Definition: lib_field.cpp:530
void MirrorVertical(const VECTOR2I &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_field.cpp:312
bool IsVertJustifyFlipped() const
Definition: lib_field.h:128
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: lib_field.cpp:434
bool IsMandatory() const
Definition: lib_field.cpp:584
void MoveTo(const VECTOR2I &aPosition) override
Move a draw object to aPosition.
Definition: lib_field.cpp:294
void SetNameShown(bool aShown=true)
Definition: lib_field.h:193
bool IsHorizJustifyFlipped() const
Definition: lib_field.h:127
LIB_FIELD & operator=(const LIB_FIELD &field)
Definition: lib_field.cpp:68
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: lib_field.cpp:536
void SetCanAutoplace(bool aCanPlace)
Definition: lib_field.h:196
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: lib_field.cpp:163
static bool ClassOf(const EDA_ITEM *aItem)
Definition: lib_field.h:77
int GetId() const
Definition: lib_field.h:120
bool m_showName
Render the field's name in addition to its value.
Definition: lib_field.h:242
int compare(const LIB_ITEM &aOther, int aCompareFlags=0) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_field.cpp:217
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:68
Define a library symbol object.
Definition: lib_symbol.h:99
Base plotter engine class.
Definition: plotter.h:104
A cache assistant for KiCad legacy symbol libraries.
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:46
#define _(s)
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:352
GR_TEXT_H_ALIGN_T
GR_TEXT_V_ALIGN_T
@ LIB_FIELD_T
Definition: typeinfo.h:212