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-2011 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 
60 class LIB_FIELD : public LIB_ITEM, public EDA_TEXT
61 {
62  int m_id;
63  wxString m_name;
64 
65  wxString m_savedText;
66  bool m_rotate;
67  bool m_updateText;
68 
76  void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
77  COLOR4D aColor, GR_DRAWMODE aDrawMode, void* aData,
78  const TRANSFORM& aTransform ) override;
79 
85  void calcEdit( const wxPoint& aPosition ) override;
86 
87  friend class SCH_LEGACY_PLUGIN_CACHE; // Required to access m_name.
88 
89 public:
90 
91  LIB_FIELD( int idfield = 2 );
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 
107  void Init( int idfield );
108 
121  wxString GetName( bool aTranslate = true ) const;
122 
134  void SetName( const wxString& aName );
135 
136  int GetId() const { return m_id; }
137 
138  void SetId( int aId ) { m_id = aId; }
139 
140  int GetPenSize( ) const override;
141 
142  bool Save( OUTPUTFORMATTER& aFormatter ) override;
143 
144  bool Load( LINE_READER& aLineReader, wxString& errorMsg ) override;
145 
151  void Copy( LIB_FIELD* aTarget ) const;
152 
153  void SetFields( const std::vector <LIB_FIELD> aFields );
154 
159  bool IsVoid() const
160  {
161  return m_Text.IsEmpty();
162  }
163 
168  bool IsVisible() const { return EDA_TEXT::IsVisible(); } // why needed?
169 
170  const EDA_RECT GetBoundingBox() const override;
171 
172  void GetMsgPanelInfo( 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() 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
Function MirrorVertical mirrors the draw object along the MirrorVertical (Y) axis about aCenter point...
Definition: lib_field.cpp:476
int compare(const LIB_ITEM &aOther) const override
Function compare provides the draw object specific comparison called by the == and < operators...
Definition: lib_field.cpp:412
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
wxString m_Text
Definition: eda_text.h:346
bool Load(LINE_READER &aLineReader, wxString &errorMsg) override
Definition: lib_field.cpp:157
PNG memory record (file in memory).
Definition: bitmap_types.h:38
wxString m_savedText
Temporary storage for the string when edition.
Definition: lib_field.h:65
LIB_FIELD(int idfield=2)
Definition: lib_field.cpp:57
const wxPoint & GetTextPos() const
Definition: eda_text.h:224
wxPoint GetPosition() const override
Function GetPosition returns the current draw object position.
Definition: lib_field.h:223
void SetFields(const std::vector< LIB_FIELD > aFields)
void SetWidth(int aWidth) override
Function SetWidth sets the width of the draw item to aWidth.
Definition: lib_field.h:236
Class LIB_FIELD is used in symbol libraries.
Definition: lib_field.h:60
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_field.cpp:807
void MirrorHorizontal(const wxPoint &aCenter) override
Function MirrorHorizontal mirrors the draw object along the horizontal (X) axis about aCenter point...
Definition: lib_field.cpp:464
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:533
const EDA_RECT GetBoundingBox() const override
Definition: lib_field.cpp:548
bool m_updateText
Flag to indicate text change occurred while editing.
Definition: lib_field.h:67
COLOR4D GetDefaultColor() override
Definition: lib_field.cpp:573
void SetName(const wxString &aName)
Function SetName.
Definition: lib_field.cpp:659
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo displays basic info (type, part and convert) about the current item in messa...
Definition: lib_field.cpp:782
Definition of base KiCad text object.
bool Save(OUTPUTFORMATTER &aFormatter) override
Function Save writes draw item object to aFormatter in component library "*.lib" format.
Definition: lib_field.cpp:112
void EndEdit(const wxPoint &aPosition, bool aAbort=false) override
End an object editing action.
Definition: lib_field.cpp:745
Class LIB_ITEM is the base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:77
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:154
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:347
Class SCH_LEGACY_PLUGIN_CACHE is a cache assistant for the part library portion of the SCH_PLUGIN API...
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels...
Definition: eda_text.h:114
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
int GetWidth() const override
Function GetWidth return the width of the draw item.
Definition: lib_field.h:234
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:679
void calcEdit(const wxPoint &aPosition) override
Calculate the new circle at aPosition when editing.
Definition: lib_field.cpp:757
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:716
void Move(const wxPoint &aPosition) override
Function Move moves a draw object to aPosition.
Definition: lib_field.cpp:458
int GetId() const
Definition: lib_field.h:136
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
bool IsVoid() const
Function IsVoid.
Definition: lib_field.h:159
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_field.h:99
bool Inside(EDA_RECT &aRect) const override
Function Inside tests if any part of the draw object is inside rectangle bounds of aRect...
Definition: lib_field.cpp:448
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:500
Class LIB_PART defines a library part 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:392
unsigned STATUS_FLAGS
Definition: base_struct.h:144
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:609
int m_id
Definition: lib_field.h:62
void Rotate() override
Rotate the draw item.
Definition: lib_field.cpp:596
Base plotter engine class.
Definition: plot_common.h:86
bool IsVisible() const
Function IsVisible.
Definition: lib_field.h:168
bool IsVisible() const
Definition: eda_text.h:176
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:261
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_field.cpp:708
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:151
void Copy(LIB_FIELD *aTarget) const
Copy parameters of this field to another field.
Definition: lib_field.cpp:402
void SetOffset(const wxPoint &aOffset) override
Function Offset sets the drawing object by aOffset from the current position.
Definition: lib_field.cpp:442
int GetPenSize() const override
Function GetPenSize.
Definition: lib_field.cpp:283
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:63
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:289
bool m_rotate
Flag to indicate a rotation occurred while editing.
Definition: lib_field.h:66
void SetId(int aId)
Definition: lib_field.h:138
bool ContinueEdit(const wxPoint aNextPoint) override
Continue an edit in progress at aPosition.
Definition: lib_field.cpp:736
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:148
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39