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( int aID, wxString& aName );
93 
94  LIB_FIELD( LIB_PART * aParent, int idfield = 2 );
95 
96  // Do not create a copy constructor. The one generated by the compiler is adequate.
97 
98  ~LIB_FIELD();
99 
100  wxString GetClass() const override
101  {
102  return wxT( "LIB_FIELD" );
103  }
104 
105  wxString GetTypeName() override
106  {
107  return _( "Field" );
108  }
109 
113  void Init( int idfield );
114 
127  wxString GetName( bool aTranslate = true ) const;
128 
138  void SetName( const wxString& aName );
139 
140  int GetId() const { return m_id; }
141 
142  void SetId( int aId ) { m_id = aId; }
143 
144  int GetPenSize( ) const override;
145 
151  void Copy( LIB_FIELD* aTarget ) const;
152 
153  void SetFields( const std::vector <LIB_FIELD> aFields );
154 
158  bool IsVoid() const
159  {
160  return m_Text.IsEmpty();
161  }
162 
163  void ViewGetLayers( int aLayers[], int& aCount ) const override;
164 
168  bool IsVisible() const { return EDA_TEXT::IsVisible(); } // why needed?
169 
170  const EDA_RECT GetBoundingBox() const override;
171 
172  void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
173 
174  bool HitTest( const wxPoint& aPosition ) const override;
175 
176  bool HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const override;
177 
178  void operator=( const LIB_FIELD& field );
179 
192  wxString GetFullText( int unit = 1 ) const;
193 
194  COLOR4D GetDefaultColor() override;
195 
196  void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) ) override;
197 
198  bool ContinueEdit( const wxPoint aNextPoint ) override;
199 
200  void EndEdit( const wxPoint& aPosition, bool aAbort = false ) override;
201 
202  void Rotate() override;
203 
215  void SetText( const wxString& aText ) override;
216 
217  void SetOffset( const wxPoint& aOffset ) override;
218 
219  bool Inside( EDA_RECT& aRect ) const override;
220 
221  void Move( const wxPoint& aPosition ) override;
222 
223  wxPoint GetPosition() const override { return EDA_TEXT::GetTextPos(); }
224 
225  void MirrorHorizontal( const wxPoint& aCenter ) override;
226 
227  void MirrorVertical( const wxPoint& aCenter ) override;
228 
229  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
230 
231  void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
232  const TRANSFORM& aTransform ) override;
233 
234  int GetWidth() const override { return GetThickness(); }
235 
236  void SetWidth( int aWidth ) override { SetThickness( aWidth ); }
237 
238  wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
239 
240  BITMAP_DEF GetMenuImage() const override;
241 
242  EDA_ITEM* Clone() const override;
243 
244 private:
245 
258  int compare( const LIB_ITEM& aOther ) const override;
259 };
260 
261 typedef std::vector< LIB_FIELD > LIB_FIELDS;
262 
263 #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:314
int compare(const LIB_ITEM &aOther) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_field.cpp:254
wxString m_Text
Definition: eda_text.h:374
PNG memory record (file in memory).
Definition: bitmap_types.h:43
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
const wxPoint & GetTextPos() const
Definition: eda_text.h:237
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_field.h:223
void CalcEdit(const wxPoint &aPosition) override
Calculate the new circle at aPosition when editing.
Definition: lib_field.cpp:584
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:236
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:539
wxString GetTypeName() override
Provide a user-consumable name of the object type.
Definition: lib_field.h:105
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_field.cpp:633
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_field.cpp:302
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:371
const EDA_RECT GetBoundingBox() const override
Definition: lib_field.cpp:386
bool m_updateText
Flag to indicate text change occurred while editing.
Definition: lib_field.h:66
COLOR4D GetDefaultColor() override
Definition: lib_field.cpp:424
void SetName(const wxString &aName)
Set a user definable field name to aName.
Definition: lib_field.cpp:498
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:609
void EndEdit(const wxPoint &aPosition, bool aAbort=false) override
End an object editing action.
Definition: lib_field.cpp:573
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:167
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:189
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:127
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:411
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:234
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:518
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:545
void Move(const wxPoint &aPosition) override
Move a draw object to aPosition.
Definition: lib_field.cpp:296
int GetId() const
Definition: lib_field.h:140
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
bool IsVoid() const
Definition: lib_field.h:158
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_field.h:100
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:290
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:338
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:234
unsigned STATUS_FLAGS
Definition: base_struct.h:147
void Init(int idfield)
Object constructor initialization helper.
Definition: lib_field.cpp:88
wxString GetName(bool aTranslate=true) const
Returns the field name.
Definition: lib_field.cpp:448
int m_id
Definition: lib_field.h:61
void Rotate() override
Rotate the draw item.
Definition: lib_field.cpp:435
Base plotter engine class.
Definition: plotter.h:97
bool IsVisible() const
Definition: lib_field.h:168
bool IsVisible() const
Definition: eda_text.h:189
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:261
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:154
void Copy(LIB_FIELD *aTarget) const
Copy parameters of this field to another field.
Definition: lib_field.cpp:244
void SetOffset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_field.cpp:284
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
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:136
bool m_rotate
Flag to indicate a rotation occurred while editing.
Definition: lib_field.h:65
void SetId(int aId)
Definition: lib_field.h:142
EDA_UNITS_T
Definition: common.h:160
bool ContinueEdit(const wxPoint aNextPoint) override
Continue an edit in progress at aPosition.
Definition: lib_field.cpp:564
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:161
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39