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 
106  void Init( int idfield );
107 
120  wxString GetName( bool aTranslate = true ) const;
121 
131  void SetName( const wxString& aName );
132 
133  int GetId() const { return m_id; }
134 
135  void SetId( int aId ) { m_id = aId; }
136 
137  int GetPenSize( ) const override;
138 
144  void Copy( LIB_FIELD* aTarget ) const;
145 
146  void SetFields( const std::vector <LIB_FIELD> aFields );
147 
151  bool IsVoid() const
152  {
153  return m_Text.IsEmpty();
154  }
155 
159  bool IsVisible() const { return EDA_TEXT::IsVisible(); } // why needed?
160 
161  const EDA_RECT GetBoundingBox() const override;
162 
163  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
164 
165  bool HitTest( const wxPoint& aPosition ) const override;
166 
167  bool HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const override;
168 
169  void operator=( const LIB_FIELD& field );
170 
183  wxString GetFullText( int unit = 1 ) const;
184 
185  COLOR4D GetDefaultColor() override;
186 
187  void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) ) override;
188 
189  bool ContinueEdit( const wxPoint aNextPoint ) override;
190 
191  void EndEdit( const wxPoint& aPosition, bool aAbort = false ) override;
192 
193  void Rotate() override;
194 
206  void SetText( const wxString& aText ) override;
207 
208  void SetOffset( const wxPoint& aOffset ) override;
209 
210  bool Inside( EDA_RECT& aRect ) const override;
211 
212  void Move( const wxPoint& aPosition ) override;
213 
214  wxPoint GetPosition() const override { return EDA_TEXT::GetTextPos(); }
215 
216  void MirrorHorizontal( const wxPoint& aCenter ) override;
217 
218  void MirrorVertical( const wxPoint& aCenter ) override;
219 
220  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
221 
222  void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
223  const TRANSFORM& aTransform ) override;
224 
225  int GetWidth() const override { return GetThickness(); }
226 
227  void SetWidth( int aWidth ) override { SetThickness( aWidth ); }
228 
229  wxString GetSelectMenuText() const override;
230 
231  BITMAP_DEF GetMenuImage() const override;
232 
233  EDA_ITEM* Clone() const override;
234 
235 private:
236 
249  int compare( const LIB_ITEM& aOther ) const override;
250 };
251 
252 typedef std::vector< LIB_FIELD > LIB_FIELDS;
253 
254 #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:301
int compare(const LIB_ITEM &aOther) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_field.cpp:241
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:214
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:227
Field object used in symbol libraries.
Definition: lib_field.h:59
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_field.cpp:632
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_field.cpp:289
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:358
const EDA_RECT GetBoundingBox() const override
Definition: lib_field.cpp:373
bool m_updateText
Flag to indicate text change occurred while editing.
Definition: lib_field.h:66
COLOR4D GetDefaultColor() override
Definition: lib_field.cpp:398
void SetName(const wxString &aName)
Set a user definable field name to aName.
Definition: lib_field.cpp:484
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:607
Definition of base KiCad text object.
void EndEdit(const wxPoint &aPosition, bool aAbort=false) override
End an object editing action.
Definition: lib_field.cpp:570
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:176
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:225
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:504
void calcEdit(const wxPoint &aPosition) override
Calculate the new circle at aPosition when editing.
Definition: lib_field.cpp:582
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:541
void Move(const wxPoint &aPosition) override
Move a draw object to aPosition.
Definition: lib_field.cpp:283
int GetId() const
Definition: lib_field.h:133
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
bool IsVoid() const
Definition: lib_field.h:151
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:277
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:325
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:221
unsigned STATUS_FLAGS
Definition: base_struct.h:158
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:434
int m_id
Definition: lib_field.h:61
void Rotate() override
Rotate the draw item.
Definition: lib_field.cpp:421
Base plotter engine class.
Definition: class_plotter.h:96
bool IsVisible() const
Definition: lib_field.h:159
bool IsVisible() const
Definition: eda_text.h:174
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:252
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_field.cpp:533
Class EDA_RECT handles the component boundary box.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:178
void Copy(LIB_FIELD *aTarget) const
Copy parameters of this field to another field.
Definition: lib_field.cpp:231
void SetOffset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_field.cpp:271
int GetPenSize() const override
Definition: lib_field.cpp:112
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:118
bool m_rotate
Flag to indicate a rotation occurred while editing.
Definition: lib_field.h:65
void SetId(int aId)
Definition: lib_field.h:135
bool ContinueEdit(const wxPoint aNextPoint) override
Continue an edit in progress at aPosition.
Definition: lib_field.cpp:561
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