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-2020 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  int m_id;
62  wxString m_name;
63 
71  void print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
72  const TRANSFORM& aTransform ) override;
73 
79  void CalcEdit( const wxPoint& aPosition ) override;
80 
81  friend class SCH_LEGACY_PLUGIN_CACHE; // Required to access m_name.
82 
83 public:
84 
85  LIB_FIELD( int idfield = 2 );
86 
87  LIB_FIELD( int aID, const wxString& aName );
88 
89  LIB_FIELD( LIB_PART * aParent, int idfield = 2 );
90 
91  // Do not create a copy constructor. The one generated by the compiler is adequate.
92 
93  ~LIB_FIELD();
94 
95  wxString GetClass() const override
96  {
97  return wxT( "LIB_FIELD" );
98  }
99 
100  wxString GetTypeName() override
101  {
102  return _( "Field" );
103  }
104 
108  void Init( int idfield );
109 
119  wxString GetName( bool aUseDefaultName = true ) const;
120 
125  wxString GetCanonicalName() const;
126 
136  void SetName( const wxString& aName );
137 
138  int GetId() const { return m_id; }
139  void SetId( int aId ) { m_id = aId; }
140 
141  int GetPenWidth() const override;
142 
148  void Copy( LIB_FIELD* aTarget ) const;
149 
150  void ViewGetLayers( int aLayers[], int& aCount ) const override;
151 
152  const EDA_RECT GetBoundingBox() const override;
153 
154  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
155 
156  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
157 
158  LIB_FIELD& operator=( const LIB_FIELD& field );
159 
170  wxString GetFullText( int unit = 1 ) const;
171 
173 
174  void BeginEdit( const wxPoint aStartPoint ) override;
175 
176  void Offset( const wxPoint& aOffset ) override;
177 
178  void MoveTo( const wxPoint& aPosition ) override;
179 
180  const wxPoint GetPosition() const override { return EDA_TEXT::GetTextPos(); }
181 
182  void MirrorHorizontal( const wxPoint& aCenter ) override;
183  void MirrorVertical( const wxPoint& aCenter ) override;
184  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
185 
186  void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
187  const TRANSFORM& aTransform ) override;
188 
189  int GetWidth() const override { return GetTextThickness(); }
190  void SetWidth( int aWidth ) override { SetTextThickness( aWidth ); }
191 
192  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
193 
194  BITMAP_DEF GetMenuImage() const override;
195 
196  EDA_ITEM* Clone() const override;
197 
198  bool IsMandatory() const;
199 
200 private:
201 
214  int compare( const LIB_ITEM& aOther,
215  LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
216 };
217 
218 typedef std::vector< LIB_FIELD > LIB_FIELDS;
219 
220 #endif // CLASS_LIBENTRY_FIELDS_H
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Definition: lib_field.cpp:426
EDA_UNITS
Definition: common.h:196
void MirrorVertical(const wxPoint &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_field.cpp:236
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_field.cpp:406
PNG memory record (file in memory).
Definition: bitmap_def.h:29
LIB_FIELD(int idfield=2)
Definition: lib_field.cpp:53
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: lib_field.cpp:123
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
void CalcEdit(const wxPoint &aPosition) override
Calculate the new circle at aPosition when editing.
Definition: lib_field.cpp:420
void SetWidth(int aWidth) override
Definition: lib_field.h:190
Field object used in symbol libraries.
Definition: lib_field.h:59
void print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform) override
Print the field.
Definition: lib_field.cpp:109
wxString GetTypeName() override
Provide a user-consumable name of the object type.
Definition: lib_field.h:100
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_field.cpp:450
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_field.cpp:224
int GetId() const
Definition: lib_field.h:138
void MoveTo(const wxPoint &aPosition) override
Move a draw object to aPosition.
Definition: lib_field.cpp:218
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: lib_field.cpp:315
int GetTextThickness() const
Definition: eda_text.h:158
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:389
int GetPenWidth() const override
Definition: lib_field.cpp:103
const wxPoint GetPosition() const override
Definition: lib_field.h:180
wxString GetName(bool aUseDefaultName=true) const
Returns the field name.
Definition: lib_field.cpp:366
The base class for drawable items used by schematic library components.
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:212
A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_PLU...
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:112
void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
Definition: lib_field.cpp:340
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
int GetWidth() const override
Definition: lib_field.h:189
COMPARE_FLAGS
The list of flags used by the compare function.
Definition: lib_item.h:116
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_field.h:95
void Copy(LIB_FIELD *aTarget) const
Copy parameters of this field to another field.
Definition: lib_field.cpp:167
void Rotate(const wxPoint &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_field.cpp:248
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:375
void Plot(PLOTTER *aPlotter, const wxPoint &aOffset, bool aFill, const TRANSFORM &aTransform) override
Plot the draw item using the plot object.
Definition: lib_field.cpp:260
Define a library symbol object.
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: lib_field.cpp:157
LIB_FIELD & operator=(const LIB_FIELD &field)
Definition: lib_field.cpp:73
void Init(int idfield)
Object constructor initialization helper.
Definition: lib_field.cpp:86
SCH_LAYER_ID GetDefaultLayer()
Definition: lib_field.cpp:355
SCH_LAYER_ID
Eeschema drawing layers.
int m_id
Definition: lib_field.h:61
Base plotter engine class.
Definition: plotter.h:104
void BeginEdit(const wxPoint aStartPoint) override
Begin drawing a component library draw item at aPosition.
Definition: lib_field.cpp:414
#define _(s)
Definition: 3d_actions.cpp:33
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:218
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:298
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:163
const wxPoint & GetTextPos() const
Definition: eda_text.h:247
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:157
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:62
void SetId(int aId)
Definition: lib_field.h:139
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:177
bool IsMandatory() const
Definition: lib_field.cpp:456