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_draw_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 
64  wxString m_savedText;
65  bool m_rotate;
66  bool m_updateText;
67 
75  void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void* aData,
76  const TRANSFORM& aTransform ) override;
77 
83  void CalcEdit( const wxPoint& aPosition ) override;
84 
85  friend class SCH_LEGACY_PLUGIN_CACHE; // Required to access m_name.
86 
87 public:
88 
89  LIB_FIELD( int idfield = 2 );
90 
91  LIB_FIELD( int aID, wxString& aName );
92 
93  LIB_FIELD( LIB_PART * aParent, int idfield = 2 );
94 
95  // Do not create a copy constructor. The one generated by the compiler is adequate.
96 
97  ~LIB_FIELD();
98 
99  wxString GetClass() const override
100  {
101  return wxT( "LIB_FIELD" );
102  }
103 
104  wxString GetTypeName() override
105  {
106  return _( "Field" );
107  }
108 
112  void Init( int idfield );
113 
126  wxString GetName( bool aTranslate = true ) const;
127 
137  void SetName( const wxString& aName );
138 
139  int GetId() const { return m_id; }
140 
141  void SetId( int aId ) { m_id = aId; }
142 
143  int GetPenSize( ) const override;
144 
150  void Copy( LIB_FIELD* aTarget ) const;
151 
155  bool IsVoid() const
156  {
157  return m_Text.IsEmpty();
158  }
159 
160  void ViewGetLayers( int aLayers[], int& aCount ) const override;
161 
165  bool IsVisible() const { return EDA_TEXT::IsVisible(); } // why needed?
166 
167  const EDA_RECT GetBoundingBox() const override;
168 
169  void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
170 
171  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
172 
173  void operator=( const LIB_FIELD& field );
174 
187  wxString GetFullText( int unit = 1 ) const;
188 
189  COLOR4D GetDefaultColor() override;
190 
191  void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aStartPoint ) override;
192  void EndEdit( const wxPoint& aPosition ) override;
193 
194  void Rotate() override;
195 
207  void SetText( const wxString& aText ) override;
208 
209  void Offset( const wxPoint& aOffset ) override;
210 
211  bool Inside( EDA_RECT& aRect ) const override;
212 
213  void MoveTo( const wxPoint& aPosition ) override;
214 
215  wxPoint GetPosition() const override { return EDA_TEXT::GetTextPos(); }
216 
217  void MirrorHorizontal( const wxPoint& aCenter ) override;
218  void MirrorVertical( const wxPoint& aCenter ) override;
219  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
220 
221  void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
222  const TRANSFORM& aTransform ) override;
223 
224  int GetWidth() const override { return GetThickness(); }
225  void SetWidth( int aWidth ) override { SetThickness( aWidth ); }
226 
227  wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
228 
229  BITMAP_DEF GetMenuImage() const override;
230 
231  EDA_ITEM* Clone() const override;
232 
233 private:
234 
247  int compare( const LIB_ITEM& aOther ) const override;
248 };
249 
250 typedef std::vector< LIB_FIELD > LIB_FIELDS;
251 
252 #endif // CLASS_LIBENTRY_FIELDS_H
wxString GetName(bool aTranslate=true) const
Returns the field name.
Definition: lib_field.cpp:408
void MirrorVertical(const wxPoint &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_field.cpp:274
int compare(const LIB_ITEM &aOther) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_field.cpp:214
wxString m_Text
Definition: eda_text.h:378
wxString m_savedText
Temporary storage for the string when editing.
Definition: lib_field.h:64
LIB_FIELD(int idfield=2)
Definition: lib_field.cpp:57
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:159
void drawGraphic(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform) override
Draw the field.
Definition: lib_field.cpp:136
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_field.h:215
void CalcEdit(const wxPoint &aPosition) override
Calculate the new circle at aPosition when editing.
Definition: lib_field.cpp:505
bool IsVisible() const
Definition: eda_text.h:193
void SetWidth(int aWidth) override
Set the width of the draw item to aWidth.
Definition: lib_field.h:225
bool IsVoid() const
Definition: lib_field.h:155
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:474
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:171
wxString GetTypeName() override
Provide a user-consumable name of the object type.
Definition: lib_field.h:104
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_field.cpp:554
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_field.cpp:262
int GetId() const
Definition: lib_field.h:139
void MoveTo(const wxPoint &aPosition) override
Move a draw object to aPosition.
Definition: lib_field.cpp:256
const EDA_RECT GetBoundingBox() const override
Definition: lib_field.cpp:346
bool m_updateText
Flag to indicate text change occurred while editing.
Definition: lib_field.h:66
COLOR4D GetDefaultColor() override
Definition: lib_field.cpp:384
void SetName(const wxString &aName)
Set a user definable field name to aName.
Definition: lib_field.cpp:433
Definition of base KiCad text object.
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
Definition: lib_field.cpp:530
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
void Offset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_field.cpp:244
A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_PLU...
bool IsVisible() const
Definition: lib_field.h:165
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels,...
Definition: eda_text.h:128
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:371
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
int GetWidth() const override
Return the width of the draw item.
Definition: lib_field.h:224
void operator=(const LIB_FIELD &field)
Definition: lib_field.cpp:77
void SetText(const wxString &aText) override
Sets the field text to aText.
Definition: lib_field.cpp:453
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_field.h:99
void Copy(LIB_FIELD *aTarget) const
Copy parameters of this field to another field.
Definition: lib_field.cpp:204
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:250
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:298
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:194
unsigned STATUS_FLAGS
Definition: base_struct.h:150
void Init(int idfield)
Object constructor initialization helper.
Definition: lib_field.cpp:88
int m_id
Definition: lib_field.h:61
void Rotate() override
Rotate the draw item.
Definition: lib_field.cpp:395
Base plotter engine class.
Definition: plotter.h:97
void BeginEdit(STATUS_FLAGS aEditMode, const wxPoint aStartPoint) override
Begin an editing a component library draw item in aEditMode at aPosition.
Definition: lib_field.cpp:480
void EndEdit(const wxPoint &aPosition) override
End an object editing action.
Definition: lib_field.cpp:496
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:250
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:331
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:157
const wxPoint & GetTextPos() const
Definition: eda_text.h:241
int GetPenSize() const override
Definition: lib_field.cpp:118
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:62
bool m_rotate
Flag to indicate a rotation occurred while editing.
Definition: lib_field.h:65
void SetId(int aId)
Definition: lib_field.h:141
EDA_UNITS_T
Definition: common.h:157
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:165
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39