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) 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
60class LIB_FIELD : public LIB_ITEM, public EDA_TEXT
61{
62public:
63 LIB_FIELD( int aId = 2 );
64
65 LIB_FIELD( int aId, const wxString& aName );
66
67 LIB_FIELD( LIB_SYMBOL* aParent, int aId = 2, const wxString& aName = wxEmptyString );
68
69 // Do not create a copy constructor. The one generated by the compiler is adequate.
70
71 wxString GetClass() const override
72 {
73 return wxT( "LIB_FIELD" );
74 }
75
76 wxString GetTypeName() const override
77 {
78 return _( "Field" );
79 }
80
84 void Init( int aId );
85
95 wxString GetName( bool aUseDefaultName = true ) const;
96
101 wxString GetCanonicalName() const;
102
112 void SetName( const wxString& aName );
113
114 int GetId() const { return m_id; }
115 void SetId( int aId );
116
117 int GetPenWidth() const override;
118
119 KIFONT::FONT* getDrawFont() const override;
120
126 void Copy( LIB_FIELD* aTarget ) const;
127
128 void ViewGetLayers( int aLayers[], int& aCount ) const override;
129
130 const BOX2I GetBoundingBox() const override;
131
132 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
133
134 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
135
136 LIB_FIELD& operator=( const LIB_FIELD& field );
137
148 wxString GetFullText( int unit = 1 ) const;
149
150 wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override;
151
153
154 void BeginEdit( const VECTOR2I& aStartPoint ) override;
155
156 void Offset( const VECTOR2I& aOffset ) override;
157
158 void MoveTo( const VECTOR2I& aPosition ) override;
159
160 VECTOR2I GetPosition() const override { return EDA_TEXT::GetTextPos(); }
161
162 void MirrorHorizontal( const VECTOR2I& aCenter ) override;
163 void MirrorVertical( const VECTOR2I& aCenter ) override;
164 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) override;
165
166 void Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffset,
167 const TRANSFORM& aTransform, bool aDimmed ) const override;
168
169 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
170
171 BITMAPS GetMenuImage() const override;
172
173 EDA_ITEM* Clone() const override;
174
175 bool IsMandatory() const;
176
177 bool IsAutoAdded() const { return m_autoAdded; }
178 void SetAutoAdded( bool aAutoAdded ) { m_autoAdded = aAutoAdded; }
179
180 bool IsNameShown() const { return m_showName; }
181 void SetNameShown( bool aShown = true ) { m_showName = aShown; }
182
183 bool CanAutoplace() const { return m_allowAutoPlace; }
184 void SetCanAutoplace( bool aCanPlace ) { m_allowAutoPlace = aCanPlace; }
185
186 bool ShowInChooser() const { return m_showInChooser; }
187 void SetShowInChooser( bool aShow = true ) { m_showInChooser = aShow; }
188
189private:
190
203 int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const override;
204
211 void print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
212 const TRANSFORM& aTransform, bool aDimmed ) override;
213
219 void CalcEdit( const VECTOR2I& aPosition ) override;
220
221 friend class SCH_LEGACY_PLUGIN_CACHE; // Required to access m_name.
222
223 int m_id;
224 wxString m_name;
229};
230
231#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:208
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:61
bool IsAutoAdded() const
Definition: lib_field.h:177
bool m_allowAutoPlace
This field can be autoplaced when converted to a SCH_FIELD.
Definition: lib_field.h:227
void SetAutoAdded(bool aAutoAdded)
Definition: lib_field.h:178
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: lib_field.cpp:198
wxString GetClass() const override
Return the class name.
Definition: lib_field.h:71
void Offset(const VECTOR2I &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_field.cpp:279
void Init(int aId)
Object constructor initialization helper.
Definition: lib_field.cpp:86
bool m_autoAdded
Was this field automatically added to a LIB_SYMBOL?
Definition: lib_field.h:225
bool ShowInChooser() const
Definition: lib_field.h:186
int m_id
Definition: lib_field.h:223
KIFONT::FONT * getDrawFont() const override
Definition: lib_field.cpp:120
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_field.cpp:315
wxString m_name
Name (not the field text value itself, that is #EDA_TEXT::m_Text)
Definition: lib_field.h:224
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:444
void print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, void *aData, const TRANSFORM &aTransform, bool aDimmed) override
Print the field.
Definition: lib_field.cpp:131
wxString GetTypeName() const override
Provide a user-consumable name of the object type.
Definition: lib_field.h:76
bool CanAutoplace() const
Definition: lib_field.h:183
SCH_LAYER_ID GetDefaultLayer() const
Definition: lib_field.cpp:459
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:327
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: lib_field.cpp:511
void SetId(int aId)
Definition: lib_field.cpp:108
void SetName(const wxString &aName)
Set a user definable field name to aName.
Definition: lib_field.cpp:494
void SetShowInChooser(bool aShow=true)
Definition: lib_field.h:187
VECTOR2I GetPosition() const override
Definition: lib_field.h:160
void Copy(LIB_FIELD *aTarget) const
Copy parameters of this field to another field.
Definition: lib_field.cpp:208
bool m_showInChooser
This field is available as a data column for the chooser.
Definition: lib_field.h:228
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:391
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: lib_field.cpp:470
bool IsNameShown() const
Definition: lib_field.h:180
void BeginEdit(const VECTOR2I &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
Definition: lib_field.cpp:517
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:479
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: lib_field.cpp:568
int GetPenWidth() const override
Definition: lib_field.cpp:114
void MirrorHorizontal(const VECTOR2I &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_field.cpp:291
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the new circle at aPosition when editing.
Definition: lib_field.cpp:523
void MirrorVertical(const VECTOR2I &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_field.cpp:303
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: lib_field.cpp:419
bool IsMandatory() const
Definition: lib_field.cpp:574
LIB_FIELD(int aId=2)
Definition: lib_field.cpp:52
void MoveTo(const VECTOR2I &aPosition) override
Move a draw object to aPosition.
Definition: lib_field.cpp:285
void SetNameShown(bool aShown=true)
Definition: lib_field.h:181
LIB_FIELD & operator=(const LIB_FIELD &field)
Definition: lib_field.cpp:69
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:529
void SetCanAutoplace(bool aCanPlace)
Definition: lib_field.h:184
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:164
int GetId() const
Definition: lib_field.h:114
wxString GetShownText(int aDepth=0, bool aAllowExtraText=true) const override
Return the string actually shown after processing of the base text.
Definition: lib_field.cpp:408
bool m_showName
Render the field's name in addition to its value.
Definition: lib_field.h:226
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:222
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:99
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