forked from KiCad/kicad-source-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib_field.h
218 lines (172 loc) · 6.67 KB
/
lib_field.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_field.h
*/
#ifndef CLASS_LIBENTRY_FIELDS_H
#define CLASS_LIBENTRY_FIELDS_H
#include <eda_text.h>
#include <lib_item.h>
class SCH_LEGACY_PLUGIN_CACHE;
/**
* Field object used in symbol libraries. At least MANDATORY_FIELDS are always present
* in a ram resident library symbol. All constructors must ensure this because
* the component property editor assumes it.
* <p>
* A field is a string linked to a component. Unlike purely graphical text, fields can
* be used in netlist generation and other tools (BOM).
*
* The first 4 fields have a special meaning:
*
* 0 = REFERENCE_FIELD
* 1 = VALUE_FIELD
* 2 = FOOTPRINT_FIELD (default Footprint)
* 3 = DATASHEET_FIELD (user doc link)
*
* others = free fields
* </p>
*
* @see enum MANDATORY_FIELD_T
*/
class LIB_FIELD : public LIB_ITEM, public EDA_TEXT
{
int m_id; ///< @see enum MANDATORY_FIELD_T
wxString m_name; ///< Name (not the field text value itself, that is .m_Text)
/**
* Print the field.
* <p>
* If \a aData not NULL, \a aData must point a wxString which is used instead of
* the m_Text
* </p>
*/
void print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
const TRANSFORM& aTransform ) override;
/**
* Calculate the new circle at \a aPosition when editing.
*
* @param aPosition - The position to edit the circle in drawing coordinates.
*/
void CalcEdit( const wxPoint& aPosition ) override;
friend class SCH_LEGACY_PLUGIN_CACHE; // Required to access m_name.
public:
LIB_FIELD( int idfield = 2 );
LIB_FIELD( int aID, const wxString& aName );
LIB_FIELD( LIB_PART * aParent, int idfield = 2 );
// Do not create a copy constructor. The one generated by the compiler is adequate.
~LIB_FIELD();
wxString GetClass() const override
{
return wxT( "LIB_FIELD" );
}
wxString GetTypeName() const override
{
return _( "Field" );
}
/**
* Object constructor initialization helper.
*/
void Init( int idfield );
/**
* Returns the field name.
*
* The first four field IDs are reserved and therefore always return their respective
* names.
*
* The user definable fields will return FieldN where N is the ID of the field when the
* m_name member is empyt unless false is passed to \a aUseDefaultName.
*/
wxString GetName( bool aUseDefaultName = true ) const;
/**
* Get a non-language-specific name for a field which can be used for storage, variable
* look-up, etc.
*/
wxString GetCanonicalName() const;
/**
* Set a user definable field name to \a aName.
*
* Reserved fields such as value and reference are not renamed. If the field name is
* changed, the field modified flag is set. If the field is the child of a component,
* the parent component's modified flag is also set.
*
* @param aName - User defined field name.
*/
void SetName( const wxString& aName );
int GetId() const { return m_id; }
void SetId( int aId ) { m_id = aId; }
int GetPenWidth() const override;
/**
* Copy parameters of this field to another field. Pointers are not copied.
*
* @param aTarget Target field to copy values to.
*/
void Copy( LIB_FIELD* aTarget ) const;
void ViewGetLayers( int aLayers[], int& aCount ) const override;
const EDA_RECT GetBoundingBox() const override;
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
LIB_FIELD& operator=( const LIB_FIELD& field );
/**
* Return the text of a field.
*
* If the field is the reference field, the unit number is used to
* create a pseudo reference text. If the base reference field is U,
* the string U?A will be returned for unit = 1.
*
* @param unit - The package unit number. Only effects reference field.
* @return Field text.
*/
wxString GetFullText( int unit = 1 ) const;
SCH_LAYER_ID GetDefaultLayer() const;
void BeginEdit( const wxPoint aStartPoint ) override;
void Offset( const wxPoint& aOffset ) override;
void MoveTo( const wxPoint& aPosition ) override;
wxPoint GetPosition() const override { return EDA_TEXT::GetTextPos(); }
void MirrorHorizontal( const wxPoint& aCenter ) override;
void MirrorVertical( const wxPoint& aCenter ) override;
void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
const TRANSFORM& aTransform ) const override;
int GetWidth() const override { return GetTextThickness(); }
void SetWidth( int aWidth ) override { SetTextThickness( aWidth ); }
wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
BITMAPS GetMenuImage() const override;
EDA_ITEM* Clone() const override;
bool IsMandatory() const;
private:
/**
* @copydoc LIB_ITEM::compare()
*
* The field specific sort order is as follows:
*
* - Field ID, REFERENCE, VALUE, etc.
* - Field string, case insensitive compare.
* - Field horizontal (X) position.
* - Field vertical (Y) position.
* - Field width.
* - Field height.
*/
int compare( const LIB_ITEM& aOther,
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
};
#endif // CLASS_LIBENTRY_FIELDS_H