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) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 2004-2017 KiCad Developers, see change_log.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,
76  COLOR4D aColor, GR_DRAWMODE aDrawMode, void* aData,
77  const TRANSFORM& aTransform ) override;
78 
84  void calcEdit( const wxPoint& aPosition ) override;
85 
86  friend class SCH_LEGACY_PLUGIN_CACHE; // Required to access m_name.
87 
88 public:
89 
90  LIB_FIELD( int idfield = 2 );
91 
92  LIB_FIELD( LIB_PART * aParent, int idfield = 2 );
93 
94  // Do not create a copy constructor. The one generated by the compiler is adequate.
95 
96  ~LIB_FIELD();
97 
98  wxString GetClass() const override
99  {
100  return wxT( "LIB_FIELD" );
101  }
102 
103  wxString GetTypeName() override
104  {
105  return _( "Field" );
106  }
107 
111  void Init( int idfield );
112 
125  wxString GetName( bool aTranslate = true ) const;
126 
136  void SetName( const wxString& aName );
137 
138  int GetId() const { return m_id; }
139 
140  void SetId( int aId ) { m_id = aId; }
141 
142  int GetPenSize( ) const override;
143 
149  void Copy( LIB_FIELD* aTarget ) const;
150 
151  void SetFields( const std::vector <LIB_FIELD> aFields );
152 
156  bool IsVoid() const
157  {
158  return m_Text.IsEmpty();
159  }
160 
164  bool IsVisible() const { return EDA_TEXT::IsVisible(); } // why needed?
165 
166  const EDA_RECT GetBoundingBox() const override;
167 
168  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
169 
170  bool HitTest( const wxPoint& aPosition ) const override;
171 
172  bool HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const override;
173 
174  void operator=( const LIB_FIELD& field );
175 
188  wxString GetFullText( int unit = 1 ) const;
189 
190  COLOR4D GetDefaultColor() override;
191 
192  void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) ) override;
193 
194  bool ContinueEdit( const wxPoint aNextPoint ) override;
195 
196  void EndEdit( const wxPoint& aPosition, bool aAbort = false ) override;
197 
198  void Rotate() override;
199 
211  void SetText( const wxString& aText ) override;
212 
213  void SetOffset( const wxPoint& aOffset ) override;
214 
215  bool Inside( EDA_RECT& aRect ) const override;
216 
217  void Move( const wxPoint& aPosition ) override;
218 
219  wxPoint GetPosition() const override { return EDA_TEXT::GetTextPos(); }
220 
221  void MirrorHorizontal( const wxPoint& aCenter ) override;
222 
223  void MirrorVertical( const wxPoint& aCenter ) override;
224 
225  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
226 
227  void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
228  const TRANSFORM& aTransform ) override;
229 
230  int GetWidth() const override { return GetThickness(); }
231 
232  void SetWidth( int aWidth ) override { SetThickness( aWidth ); }
233 
234  wxString GetSelectMenuText() const override;
235 
236  BITMAP_DEF GetMenuImage() const override;
237 
238  EDA_ITEM* Clone() const override;
239 
240 private:
241 
254  int compare( const LIB_ITEM& aOther ) const override;
255 };
256 
257 typedef std::vector< LIB_FIELD > LIB_FIELDS;
258 
259 #endif // CLASS_LIBENTRY_FIELDS_H
void MirrorVertical(const wxPoint &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_field.cpp:299
int compare(const LIB_ITEM &aOther) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_field.cpp:239
wxString m_Text
Definition: eda_text.h:344
PNG memory record (file in memory).
Definition: bitmap_types.h:41
wxString m_savedText
Temporary storage for the string when edition.
Definition: lib_field.h:64
LIB_FIELD(int idfield=2)
Definition: lib_field.cpp:57
const wxPoint & GetTextPos() const
Definition: eda_text.h:222
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_field.h:219
void SetFields(const std::vector< LIB_FIELD > aFields)
void SetWidth(int aWidth) override
Set the width of the draw item to aWidth.
Definition: lib_field.h:232
Field object used in symbol libraries.
Definition: lib_field.h:59
wxString GetTypeName() override
Provide a user-consumable name of the object type.
Definition: lib_field.h:103
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_field.cpp:634
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_field.cpp:287
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:356
const EDA_RECT GetBoundingBox() const override
Definition: lib_field.cpp:371
bool m_updateText
Flag to indicate text change occurred while editing.
Definition: lib_field.h:66
COLOR4D GetDefaultColor() override
Definition: lib_field.cpp:396
void SetName(const wxString &aName)
Set a user definable field name to aName.
Definition: lib_field.cpp:482
void GetMsgPanelInfo(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:609
Definition of base KiCad text object.
void EndEdit(const wxPoint &aPosition, bool aAbort=false) override
End an object editing action.
Definition: lib_field.cpp:572
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:66
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:152
bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
Definition: lib_field.cpp:174
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:112
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:230
void operator=(const LIB_FIELD &field)
Definition: lib_field.cpp:69
void SetText(const wxString &aText) override
Sets the field text to aText.
Definition: lib_field.cpp:502
void calcEdit(const wxPoint &aPosition) override
Calculate the new circle at aPosition when editing.
Definition: lib_field.cpp:584
void BeginEdit(STATUS_FLAGS aEditMode, const wxPoint aStartPoint=wxPoint(0, 0)) override
Begin an editing a component library draw item in aEditMode at aPosition.
Definition: lib_field.cpp:543
void Move(const wxPoint &aPosition) override
Move a draw object to aPosition.
Definition: lib_field.cpp:281
int GetId() const
Definition: lib_field.h:138
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
bool IsVoid() const
Definition: lib_field.h:156
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_field.h:98
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:275
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:323
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:219
unsigned STATUS_FLAGS
Definition: base_struct.h:142
void Init(int idfield)
Object constructor initialization helper.
Definition: lib_field.cpp:80
wxString GetName(bool aTranslate=true) const
Returns the field name.
Definition: lib_field.cpp:432
int m_id
Definition: lib_field.h:61
void Rotate() override
Rotate the draw item.
Definition: lib_field.cpp:419
Base plotter engine class.
Definition: plotter.h:96
bool IsVisible() const
Definition: lib_field.h:164
bool IsVisible() const
Definition: eda_text.h:174
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:257
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_field.cpp:535
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:162
void Copy(LIB_FIELD *aTarget) const
Copy parameters of this field to another field.
Definition: lib_field.cpp:229
void SetOffset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_field.cpp:269
int GetPenSize() const override
Definition: lib_field.cpp:110
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:62
void drawGraphic(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, void *aData, const TRANSFORM &aTransform) override
Draw the field.
Definition: lib_field.cpp:116
bool m_rotate
Flag to indicate a rotation occurred while editing.
Definition: lib_field.h:65
void SetId(int aId)
Definition: lib_field.h:140
bool ContinueEdit(const wxPoint aNextPoint) override
Continue an edit in progress at aPosition.
Definition: lib_field.cpp:563
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:146
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39