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-2019 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( wxDC* aDC, 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, 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 
122  wxString GetName( bool aTranslate = true ) const;
123 
133  void SetName( const wxString& aName );
134 
135  int GetId() const { return m_id; }
136  void SetId( int aId ) { m_id = aId; }
137 
138  int GetPenSize( ) const override;
139 
145  void Copy( LIB_FIELD* aTarget ) const;
146 
147  void ViewGetLayers( int aLayers[], int& aCount ) const override;
148 
149  const EDA_RECT GetBoundingBox() const override;
150 
151  void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
152 
153  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
154 
155  LIB_FIELD& operator=( const LIB_FIELD& field );
156 
167  wxString GetFullText( int unit = 1 ) const;
168 
169  COLOR4D GetDefaultColor() override;
170 
171  void BeginEdit( const wxPoint aStartPoint ) override;
172 
173  void Offset( const wxPoint& aOffset ) override;
174 
175  bool Inside( EDA_RECT& aRect ) const override;
176 
177  void MoveTo( const wxPoint& aPosition ) override;
178 
179  wxPoint GetPosition() const override { return EDA_TEXT::GetTextPos(); }
180 
181  void MirrorHorizontal( const wxPoint& aCenter ) override;
182  void MirrorVertical( const wxPoint& aCenter ) override;
183  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
184 
185  void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
186  const TRANSFORM& aTransform ) override;
187 
188  int GetWidth() const override { return GetThickness(); }
189  void SetWidth( int aWidth ) override { SetThickness( aWidth ); }
190 
191  wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
192 
193  BITMAP_DEF GetMenuImage() const override;
194 
195  EDA_ITEM* Clone() const override;
196 
197 private:
198 
211  int compare( const LIB_ITEM& aOther ) const override;
212 };
213 
214 typedef std::vector< LIB_FIELD > LIB_FIELDS;
215 
216 #endif // CLASS_LIBENTRY_FIELDS_H
wxString GetName(bool aTranslate=true) const
Returns the field name.
Definition: lib_field.cpp:366
void MirrorVertical(const wxPoint &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_field.cpp:247
int compare(const LIB_ITEM &aOther) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_field.cpp:187
LIB_FIELD(int idfield=2)
Definition: lib_field.cpp:51
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:135
wxPoint GetPosition() const override
Definition: lib_field.h:179
void CalcEdit(const wxPoint &aPosition) override
Calculate the new circle at aPosition when editing.
Definition: lib_field.cpp:423
void SetWidth(int aWidth) override
Definition: lib_field.h:189
Field object used in symbol libraries.
Definition: lib_field.h:59
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_field.cpp:411
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:148
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:453
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_field.cpp:235
int GetId() const
Definition: lib_field.h:135
void MoveTo(const wxPoint &aPosition) override
Move a draw object to aPosition.
Definition: lib_field.cpp:229
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: lib_field.cpp:315
COLOR4D GetDefaultColor() override
Definition: lib_field.cpp:355
void SetName(const wxString &aName)
Set a user definable field name to aName.
Definition: lib_field.cpp:391
void GetMsgPanelInfo(EDA_UNITS_T aUnits, 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:429
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:217
A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_PLU...
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels,...
Definition: eda_text.h:109
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
Class for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
int GetWidth() const override
Definition: lib_field.h:188
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:177
bool Inside(EDA_RECT &aRect) const override
Test if any part of the draw object is inside rectangle bounds of aRect.
Definition: lib_field.cpp:223
void Rotate(const wxPoint &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_field.cpp:259
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:271
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:167
LIB_FIELD & operator=(const LIB_FIELD &field)
Definition: lib_field.cpp:71
void Init(int idfield)
Object constructor initialization helper.
Definition: lib_field.cpp:84
#define _(s)
void print(wxDC *aDC, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform) override
Print the field.
Definition: lib_field.cpp:122
int m_id
Definition: lib_field.h:61
Base plotter engine class.
Definition: plotter.h:97
void BeginEdit(const wxPoint aStartPoint) override
Begin drawing a component library draw item at aPosition.
Definition: lib_field.cpp:417
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:214
Class 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:300
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
const wxPoint & GetTextPos() const
Definition: eda_text.h:232
int GetPenSize() const override
Definition: lib_field.cpp:104
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:136
EDA_UNITS_T
Definition: common.h:133
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:142
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39