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 
59 class LIB_FIELD : public LIB_ITEM, public EDA_TEXT
60 {
61 public:
62  LIB_FIELD( int idfield = 2 );
63 
64  LIB_FIELD( int aID, const wxString& aName );
65 
66  LIB_FIELD( LIB_SYMBOL* aParent, int idfield = 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 idfield );
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 ) { m_id = aId; }
117 
118  int GetPenWidth() const override;
119 
125  void Copy( LIB_FIELD* aTarget ) const;
126 
127  void ViewGetLayers( int aLayers[], int& aCount ) const override;
128 
129  const EDA_RECT GetBoundingBox() const override;
130 
131  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
132 
133  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
134 
135  LIB_FIELD& operator=( const LIB_FIELD& field );
136 
147  wxString GetFullText( int unit = 1 ) const;
148 
150 
151  void BeginEdit( const wxPoint& aStartPoint ) override;
152 
153  void Offset( const wxPoint& aOffset ) override;
154 
155  void MoveTo( const wxPoint& aPosition ) override;
156 
157  wxPoint GetPosition() const override { return EDA_TEXT::GetTextPos(); }
158 
159  void MirrorHorizontal( const wxPoint& aCenter ) override;
160  void MirrorVertical( const wxPoint& aCenter ) override;
161  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
162 
163  void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
164  const TRANSFORM& aTransform ) const override;
165 
166  int GetWidth() const override { return GetTextThickness(); }
167  void SetWidth( int aWidth ) override { SetTextThickness( aWidth ); }
168 
169  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
170 
171  BITMAPS GetMenuImage() const override;
172 
173  EDA_ITEM* Clone() const override;
174 
175  bool IsMandatory() const;
176 
177 private:
178 
191  int compare( const LIB_ITEM& aOther,
192  LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
193 
200  void print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
201  const TRANSFORM& aTransform ) override;
202 
208  void CalcEdit( const wxPoint& aPosition ) override;
209 
210  friend class SCH_LEGACY_PLUGIN_CACHE; // Required to access m_name.
211 
212  int m_id;
213  wxString m_name;
214 };
215 
216 #endif // CLASS_LIBENTRY_FIELDS_H
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:423
void MirrorVertical(const wxPoint &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_field.cpp:233
void print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform) override
Print the field.
Definition: lib_field.cpp:106
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: lib_field.cpp:403
LIB_FIELD(int idfield=2)
Definition: lib_field.cpp:50
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is contained within or on the bounding box of an item.
Definition: lib_field.cpp:120
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
wxPoint GetPosition() const override
Definition: lib_field.h:157
wxString GetTypeName() const override
Provide a user-consumable name of the object type.
Definition: lib_field.h:77
void CalcEdit(const wxPoint &aPosition) override
Calculate the new circle at aPosition when editing.
Definition: lib_field.cpp:417
void SetWidth(int aWidth) override
Definition: lib_field.h:167
Field object used in symbol libraries.
Definition: lib_field.h:59
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_field.cpp:221
int GetId() const
Definition: lib_field.h:115
void MoveTo(const wxPoint &aPosition) override
Move a draw object to aPosition.
Definition: lib_field.cpp:215
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: lib_field.cpp:312
int GetTextThickness() const
Definition: eda_text.h:167
The base class for create windows for drawing purpose.
void SetName(const wxString &aName)
Set a user definable field name to aName.
Definition: lib_field.cpp:386
Define a library symbol object.
Definition: lib_symbol.h:96
int GetPenWidth() const override
Definition: lib_field.cpp:100
wxString GetName(bool aUseDefaultName=true) const
Return the field name.
Definition: lib_field.cpp:363
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
void Offset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_field.cpp:209
A cache assistant for the symbol library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_P...
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:119
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:337
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
int GetWidth() const override
Definition: lib_field.h:166
COMPARE_FLAGS
The list of flags used by the compare function.
Definition: lib_item.h:81
wxString GetClass() const override
Return the class name.
Definition: lib_field.h:72
void Copy(LIB_FIELD *aTarget) const
Copy parameters of this field to another field.
Definition: lib_field.cpp:164
void Rotate(const wxPoint &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_field.cpp:245
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:372
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: lib_field.cpp:154
LIB_FIELD & operator=(const LIB_FIELD &field)
Definition: lib_field.cpp:70
#define _(s)
void Init(int idfield)
Object constructor initialization helper.
Definition: lib_field.cpp:83
SCH_LAYER_ID
Eeschema drawing layers.
void BeginEdit(const wxPoint &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
Definition: lib_field.cpp:411
EDA_UNITS
Definition: eda_units.h:38
int m_id
Definition: lib_field.h:212
void Plot(PLOTTER *aPlotter, const wxPoint &aOffset, bool aFill, const TRANSFORM &aTransform) const override
Plot the draw item using the plot object.
Definition: lib_field.cpp:257
Base plotter engine class.
Definition: plotter.h:121
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
Handle the component boundary box.
Definition: eda_rect.h:42
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:295
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
SCH_LAYER_ID GetDefaultLayer() const
Definition: lib_field.cpp:352
const wxPoint & GetTextPos() const
Definition: eda_text.h:254
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:166
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:213
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: lib_field.cpp:447
void SetId(int aId)
Definition: lib_field.h:116
int compare(const LIB_ITEM &aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags=LIB_ITEM::COMPARE_FLAGS::NORMAL) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_field.cpp:174
bool IsMandatory() const
Definition: lib_field.cpp:453