KiCad PCB EDA Suite
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) 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
29#ifndef CLASS_LIBENTRY_FIELDS_H
30#define CLASS_LIBENTRY_FIELDS_H
31
32#include <eda_text.h>
33#include <lib_item.h>
34
35
37
38
59class LIB_FIELD : public LIB_ITEM, public EDA_TEXT
60{
61public:
62 LIB_FIELD( int aId = 2 );
63
64 LIB_FIELD( int aId, const wxString& aName );
65
66 LIB_FIELD( LIB_SYMBOL* aParent, int aId = 2 );
67
68 // Do not create a copy constructor. The one generated by the compiler is adequate.
69
70 ~LIB_FIELD();
71
72 wxString GetClass() const override
73 {
74 return wxT( "LIB_FIELD" );
75 }
76
77 wxString GetTypeName() const override
78 {
79 return _( "Field" );
80 }
81
85 void Init( int aId );
86
96 wxString GetName( bool aUseDefaultName = true ) const;
97
102 wxString GetCanonicalName() const;
103
113 void SetName( const wxString& aName );
114
115 int GetId() const { return m_id; }
116 void SetId( int aId );
117
118 int GetPenWidth() const override;
119
120 KIFONT::FONT* GetDrawFont() const override;
121
127 void Copy( LIB_FIELD* aTarget ) const;
128
129 void ViewGetLayers( int aLayers[], int& aCount ) const override;
130
131 const BOX2I GetBoundingBox() const override;
132
133 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
134
135 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
136
137 LIB_FIELD& operator=( const LIB_FIELD& field );
138
149 wxString GetFullText( int unit = 1 ) const;
150
151 wxString GetShownText( int aDepth = 0 ) const override;
152
154
155 void BeginEdit( const VECTOR2I& aStartPoint ) override;
156
157 void Offset( const VECTOR2I& aOffset ) override;
158
159 void MoveTo( const VECTOR2I& aPosition ) override;
160
161 VECTOR2I GetPosition() const override { return EDA_TEXT::GetTextPos(); }
162
163 void MirrorHorizontal( const VECTOR2I& aCenter ) override;
164 void MirrorVertical( const VECTOR2I& aCenter ) override;
165 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) override;
166
167 void Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffset,
168 const TRANSFORM& aTransform, bool aDimmed ) const override;
169
170 wxString GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const override;
171
172 BITMAPS GetMenuImage() const override;
173
174 EDA_ITEM* Clone() const override;
175
176 bool IsMandatory() const;
177
178 bool IsAutoAdded() const { return m_autoAdded; }
179 void SetAutoAdded( bool aAutoAdded ) { m_autoAdded = aAutoAdded; }
180
181 bool IsNameShown() const { return m_showName; }
182 void SetNameShown( bool aShown = true ) { m_showName = aShown; }
183
184 bool CanAutoplace() const { return m_allowAutoPlace; }
185 void SetCanAutoplace( bool aCanPlace ) { m_allowAutoPlace = aCanPlace; }
186
187 bool ShowInChooser() const { return m_showInChooser; }
188 void SetShowInChooser( bool aShow = true ) { m_showInChooser = aShow; }
189
190private:
191
204 int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const override;
205
212 void print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
213 const TRANSFORM& aTransform, bool aDimmed ) override;
214
220 void CalcEdit( const VECTOR2I& aPosition ) override;
221
222 friend class SCH_LEGACY_PLUGIN_CACHE; // Required to access m_name.
223
224 int m_id;
225 wxString m_name;
230};
231
232#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
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
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:105
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
bool IsAutoAdded() const
Definition: lib_field.h:178
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: lib_field.cpp:397
bool m_allowAutoPlace
This field can be autoplaced when converted to a SCH_FIELD.
Definition: lib_field.h:228
void SetAutoAdded(bool aAutoAdded)
Definition: lib_field.h:179
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: lib_field.cpp:196
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:277
void Init(int aId)
Object constructor initialization helper.
Definition: lib_field.cpp:89
bool m_autoAdded
Was this field automatically added to a LIB_SYMBOL?
Definition: lib_field.h:226
bool ShowInChooser() const
Definition: lib_field.h:187
int m_id
Definition: lib_field.h:224
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_field.cpp:313
wxString m_name
Name (not the field text value itself, that is #EDA_TEXT::m_Text)
Definition: lib_field.h:225
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:433
void print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, void *aData, const TRANSFORM &aTransform, bool aDimmed) override
Print the field.
Definition: lib_field.cpp:137
wxString GetTypeName() const override
Provide a user-consumable name of the object type.
Definition: lib_field.h:77
bool CanAutoplace() const
Definition: lib_field.h:184
SCH_LAYER_ID GetDefaultLayer() const
Definition: lib_field.cpp:448
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:325
void SetId(int aId)
Definition: lib_field.cpp:113
void SetName(const wxString &aName)
Set a user definable field name to aName.
Definition: lib_field.cpp:483
void SetShowInChooser(bool aShow=true)
Definition: lib_field.h:188
VECTOR2I GetPosition() const override
Definition: lib_field.h:161
void Copy(LIB_FIELD *aTarget) const
Copy parameters of this field to another field.
Definition: lib_field.cpp:206
bool m_showInChooser
This field is available as a data column for the chooser.
Definition: lib_field.h:229
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:380
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: lib_field.cpp:459
bool IsNameShown() const
Definition: lib_field.h:181
void BeginEdit(const VECTOR2I &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
Definition: lib_field.cpp:506
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:468
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: lib_field.cpp:557
KIFONT::FONT * GetDrawFont() const override
Definition: lib_field.cpp:126
int GetPenWidth() const override
Definition: lib_field.cpp:120
void MirrorHorizontal(const VECTOR2I &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_field.cpp:289
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the new circle at aPosition when editing.
Definition: lib_field.cpp:512
void MirrorVertical(const VECTOR2I &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_field.cpp:301
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: lib_field.cpp:408
bool IsMandatory() const
Definition: lib_field.cpp:563
LIB_FIELD(int aId=2)
Definition: lib_field.cpp:50
void MoveTo(const VECTOR2I &aPosition) override
Move a draw object to aPosition.
Definition: lib_field.cpp:283
void SetNameShown(bool aShown=true)
Definition: lib_field.h:182
LIB_FIELD & operator=(const LIB_FIELD &field)
Definition: lib_field.cpp:72
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: lib_field.cpp:500
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:518
void SetCanAutoplace(bool aCanPlace)
Definition: lib_field.h:185
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:162
int GetId() const
Definition: lib_field.h:115
bool m_showName
Render the field's name in addition to its value.
Definition: lib_field.h:227
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:220
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
Define a library symbol object.
Definition: lib_symbol.h:98
Base plotter engine class.
Definition: plotter.h:110
A cache assistant for KiCad legacy symbol libraries.
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:47
#define _(s)
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:341