KiCad PCB EDA Suite
lib_item.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) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr
5  * Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef _LIB_ITEM_H_
27 #define _LIB_ITEM_H_
28 
29 #include <base_struct.h>
30 #include <eda_rect.h>
31 #include <transform.h>
32 #include <gr_basic.h>
33 
34 
35 class LINE_READER;
36 class OUTPUTFORMATTER;
37 class LIB_PART;
38 class PLOTTER;
39 class LIB_PIN;
40 class MSG_PANEL_ITEM;
41 
42 
43 extern const int fill_tab[];
44 
45 
46 #define MINIMUM_SELECTION_DISTANCE 2 // Minimum selection distance in internal units
47 
48 
54 typedef std::vector< LIB_PIN* > LIB_PINS;
55 
56 
60 class LIB_ITEM : public EDA_ITEM
61 {
71  virtual void print( wxDC* aDC, const wxPoint& aOffset, void* aData,
72  const TRANSFORM& aTransform ) = 0;
73 
74  friend class LIB_PART;
75 
76 protected:
81  int m_Unit;
82 
87  int m_Convert;
88 
95 
96 public:
97 
98  LIB_ITEM( KICAD_T aType, LIB_PART* aComponent = NULL, int aUnit = 0, int aConvert = 0,
99  FILL_T aFillType = NO_FILL );
100 
101  // Do not create a copy constructor. The one generated by the compiler is adequate.
102 
103  virtual ~LIB_ITEM() { }
104 
105 
106  // Define the enums for basic
107  enum LIB_CONVERT : int { BASE = 1, DEMORGAN = 2 };
108 
116  enum COMPARE_FLAGS : int { NORMAL = 0x00, UNIT = 0x01 };
117 
122  virtual wxString GetTypeName() = 0;
123 
133  virtual void BeginEdit( const wxPoint aPosition ) {}
134 
145  virtual bool ContinueEdit( const wxPoint aPosition ) { return false; }
146 
152  virtual void EndEdit() {}
153 
163  virtual void CalcEdit( const wxPoint& aPosition ) {}
164 
165 
177  virtual void Print( wxDC* aDC, const wxPoint &aOffset, void* aData,
178  const TRANSFORM& aTransform );
179 
183  virtual int GetPenSize() const = 0;
184 
186  {
187  return (LIB_PART*) m_Parent;
188  }
189 
190  void ViewGetLayers( int aLayers[], int& aCount ) const override;
191 
192  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override
193  {
194  // This is just here to prevent annoying compiler warnings about hidden overloaded
195  // virtual functions
196  return EDA_ITEM::HitTest( aPosition, aAccuracy );
197  }
198 
199  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
200 
204  const EDA_RECT GetBoundingBox() const override { return EDA_ITEM::GetBoundingBox(); }
205 
215  void GetMsgPanelInfo( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList ) override;
216 
223  bool operator==( const LIB_ITEM& aOther ) const;
224  bool operator==( const LIB_ITEM* aOther ) const
225  {
226  return *this == *aOther;
227  }
228 
235  bool operator<( const LIB_ITEM& aOther) const;
236 
242  virtual void Offset( const wxPoint& aOffset ) = 0;
243 
250  virtual bool Inside( EDA_RECT& aRect ) const = 0;
251 
257  virtual void MoveTo( const wxPoint& aPosition ) = 0;
258 
259  virtual wxPoint GetPosition() const = 0;
260  void SetPosition( const wxPoint& aPosition ) { MoveTo( aPosition ); }
261 
267  virtual void MirrorHorizontal( const wxPoint& aCenter ) = 0;
268 
274  virtual void MirrorVertical( const wxPoint& aCenter ) = 0;
275 
282  virtual void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) = 0;
283 
292  virtual void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
293  const TRANSFORM& aTransform ) = 0;
294 
295  virtual int GetWidth() const = 0;
296  virtual void SetWidth( int aWidth ) = 0;
297 
304  bool IsFillable() const { return m_isFillable; }
305 
306  virtual COLOR4D GetDefaultColor();
307 
308  void SetUnit( int aUnit ) { m_Unit = aUnit; }
309  int GetUnit() const { return m_Unit; }
310 
311  void SetConvert( int aConvert ) { m_Convert = aConvert; }
312  int GetConvert() const { return m_Convert; }
313 
314  void SetFillMode( FILL_T aFillMode ) { m_Fill = aFillMode; }
315  FILL_T GetFillMode() const { return m_Fill; }
316 
317 #if defined(DEBUG)
318  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
319 #endif
320 
321 protected:
322 
343  virtual int compare( const LIB_ITEM& aOther,
344  LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const;
345 };
346 
347 
348 #endif // _LIB_ITEM_H_
const EDA_RECT GetBoundingBox() const override
Definition: lib_item.h:204
virtual wxPoint GetPosition() const =0
EDA_UNITS
Definition: common.h:184
LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to re...
Definition: richio.h:81
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:183
void GetMsgPanelInfo(EDA_UNITS aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
Definition: lib_item.cpp:52
void SetPosition(const wxPoint &aPosition)
Definition: lib_item.h:260
LIB_PART * GetParent() const
Definition: lib_item.h:185
virtual void SetWidth(int aWidth)=0
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_item.h:54
virtual COLOR4D GetDefaultColor()
Definition: lib_item.cpp:152
FILL_T GetFillMode() const
Definition: lib_item.h:315
virtual void Plot(PLOTTER *aPlotter, const wxPoint &aOffset, bool aFill, const TRANSFORM &aTransform)=0
Plot the draw item using the plot object.
int m_Unit
Unit identification for multiple parts per package.
Definition: lib_item.h:81
OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a convenient ...
Definition: richio.h:327
virtual void MirrorHorizontal(const wxPoint &aCenter)=0
Mirror the draw object along the horizontal (X) axis about aCenter point.
virtual void CalcEdit(const wxPoint &aPosition)
Calculates the attributes of an item at aPosition when it is being edited.
Definition: lib_item.h:163
bool operator==(const LIB_ITEM *aOther) const
Definition: lib_item.h:224
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
The base class for drawable items used by schematic library components.
Definition: lib_item.h:60
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_item.cpp:142
virtual void Offset(const wxPoint &aOffset)=0
Set the drawing object by aOffset from the current position.
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: base_struct.h:332
virtual void print(wxDC *aDC, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform)=0
Print the item to aDC.
int GetUnit() const
Definition: lib_item.h:309
bool operator==(const LIB_ITEM &aOther) const
Test LIB_ITEM objects for equivalence.
Definition: lib_item.cpp:92
virtual ~LIB_ITEM()
Definition: lib_item.h:103
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
#define NULL
virtual bool ContinueEdit(const wxPoint aPosition)
Continue an edit in progress at aPosition.
Definition: lib_item.h:145
COMPARE_FLAGS
The list of flags used by the compare function.
Definition: lib_item.h:116
bool operator<(const LIB_ITEM &aOther) const
Test if another draw item is less than this draw object.
Definition: lib_item.cpp:98
virtual void Rotate(const wxPoint &aCenter, bool aRotateCCW=true)=0
Rotate the object about aCenter point.
bool m_isFillable
Definition: lib_item.h:94
Define a library symbol object.
virtual void MirrorVertical(const wxPoint &aCenter)=0
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
int GetConvert() const
Definition: lib_item.h:312
void SetFillMode(FILL_T aFillMode)
Definition: lib_item.h:314
virtual void MoveTo(const wxPoint &aPosition)=0
Move a draw object to aPosition.
void SetConvert(int aConvert)
Definition: lib_item.h:311
virtual void BeginEdit(const wxPoint aPosition)
Begin drawing a component library draw item at aPosition.
Definition: lib_item.h:133
virtual int GetWidth() const =0
void SetUnit(int aUnit)
Definition: lib_item.h:308
Base plotter engine class.
Definition: plotter.h:104
virtual int GetPenSize() const =0
const int fill_tab[]
Definition: lib_item.cpp:34
FILL_T m_Fill
The body fill type.
Definition: lib_item.h:93
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_item.h:192
virtual wxString GetTypeName()=0
Provide a user-consumable name of the object type.
virtual void Print(wxDC *aDC, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform)
Draw an item.
Definition: lib_item.cpp:136
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:166
int m_Convert
Shape identification for alternate body styles.
Definition: lib_item.h:87
FILL_T
Enum FILL_T is the set of fill types used in plotting or drawing enclosed areas.
Definition: base_struct.h:42
bool IsFillable() const
Check if draw object can be filled.
Definition: lib_item.h:304
virtual bool Inside(EDA_RECT &aRect) const =0
Test if any part of the draw object is inside rectangle bounds of aRect.
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
LIB_ITEM(KICAD_T aType, LIB_PART *aComponent=NULL, int aUnit=0, int aConvert=0, FILL_T aFillType=NO_FILL)
Definition: lib_item.cpp:37
virtual int compare(const LIB_ITEM &aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags=LIB_ITEM::COMPARE_FLAGS::NORMAL) const
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_item.cpp:76
virtual void EndEdit()
End an object editing action.
Definition: lib_item.h:152
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:40