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 <eda_item.h>
30 #include <eda_rect.h>
31 #include <fill_type.h>
32 #include <transform.h>
33 #include <gr_basic.h>
34 #include <render_settings.h>
35 
36 class LINE_READER;
37 class OUTPUTFORMATTER;
38 class LIB_PART;
39 class PLOTTER;
40 class LIB_PIN;
41 class MSG_PANEL_ITEM;
42 
44 
45 extern const int fill_tab[];
46 
47 
48 #define MINIMUM_SELECTION_DISTANCE 2 // Minimum selection distance in internal units
49 
50 
56 typedef std::vector< LIB_PIN* > LIB_PINS;
57 
58 
62 class LIB_ITEM : public EDA_ITEM
63 {
72  virtual void print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
73  const TRANSFORM& aTransform ) = 0;
74 
75  friend class LIB_PART;
76 
77 protected:
82  int m_Unit;
83 
88  int m_Convert;
89 
96 
97 public:
98 
99  LIB_ITEM( KICAD_T aType, LIB_PART* aComponent = NULL, int aUnit = 0, int aConvert = 0,
100  FILL_TYPE aFillType = FILL_TYPE::NO_FILL );
101 
102  // Do not create a copy constructor. The one generated by the compiler is adequate.
103 
104  virtual ~LIB_ITEM() { }
105 
106 
107  // Define the enums for basic
108  enum LIB_CONVERT : int { BASE = 1, DEMORGAN = 2 };
109 
117  enum COMPARE_FLAGS : int { NORMAL = 0x00, UNIT = 0x01 };
118 
123  virtual wxString GetTypeName() = 0;
124 
134  virtual void BeginEdit( const wxPoint aPosition ) {}
135 
146  virtual bool ContinueEdit( const wxPoint aPosition ) { return false; }
147 
153  virtual void EndEdit() {}
154 
164  virtual void CalcEdit( const wxPoint& aPosition ) {}
165 
166 
178  virtual void Print( RENDER_SETTINGS* aSettings, const wxPoint &aOffset, void* aData,
179  const TRANSFORM& aTransform );
180 
181  virtual int GetPenWidth() const = 0;
182 
184  {
185  return (LIB_PART*) m_Parent;
186  }
187 
188  void ViewGetLayers( int aLayers[], int& aCount ) const override;
189 
190  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override
191  {
192  // This is just here to prevent annoying compiler warnings about hidden overloaded
193  // virtual functions
194  return EDA_ITEM::HitTest( aPosition, aAccuracy );
195  }
196 
197  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
198 
202  const EDA_RECT GetBoundingBox() const override { return EDA_ITEM::GetBoundingBox(); }
203 
213  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
214 
221  bool operator==( const LIB_ITEM& aOther ) const;
222  bool operator==( const LIB_ITEM* aOther ) const
223  {
224  return *this == *aOther;
225  }
226 
233  bool operator<( const LIB_ITEM& aOther) const;
234 
240  virtual void Offset( const wxPoint& aOffset ) = 0;
241 
247  virtual void MoveTo( const wxPoint& aPosition ) = 0;
248 
249  void SetPosition( const wxPoint& aPosition ) override { MoveTo( aPosition ); }
250 
256  virtual void MirrorHorizontal( const wxPoint& aCenter ) = 0;
257 
263  virtual void MirrorVertical( const wxPoint& aCenter ) = 0;
264 
271  virtual void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) = 0;
272 
281  virtual void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
282  const TRANSFORM& aTransform ) = 0;
283 
284  virtual int GetWidth() const = 0;
285  virtual void SetWidth( int aWidth ) = 0;
286 
293  bool IsFillable() const { return m_isFillable; }
294 
295  void SetUnit( int aUnit ) { m_Unit = aUnit; }
296  int GetUnit() const { return m_Unit; }
297 
298  void SetConvert( int aConvert ) { m_Convert = aConvert; }
299  int GetConvert() const { return m_Convert; }
300 
301  void SetFillMode( FILL_TYPE aFillMode ) { m_Fill = aFillMode; }
302  FILL_TYPE GetFillMode() const { return m_Fill; }
303 
304 #if defined(DEBUG)
305  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
306 #endif
307 
308 protected:
309 
330  virtual int compare( const LIB_ITEM& aOther,
331  LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const;
332 };
333 
334 
335 #endif // _LIB_ITEM_H_
const EDA_RECT GetBoundingBox() const override
Definition: lib_item.h:202
virtual int GetPenWidth() const =0
LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to re...
Definition: richio.h:82
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: eda_item.h:162
FILL_TYPE
Enum class FILL_TYPE is the set of fill types used in plotting or drawing enclosed areas.
Definition: fill_type.h:29
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
virtual void print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform)=0
Print the item to aDC.
LIB_PART * GetParent() const
Definition: lib_item.h:183
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:56
void SetFillMode(FILL_TYPE aFillMode)
Definition: lib_item.h:301
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:82
OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a convenient ...
Definition: richio.h:328
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:164
The base class for create windows for drawing purpose.
bool operator==(const LIB_ITEM *aOther) const
Definition: lib_item.h:222
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:62
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:144
virtual void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform)
Draw an item.
Definition: lib_item.cpp:137
virtual void Offset(const wxPoint &aOffset)=0
Set the drawing object by aOffset from the current position.
FILL_TYPE m_Fill
The body fill type.
Definition: lib_item.h:94
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: eda_item.h:295
FILL_TYPE GetFillMode() const
Definition: lib_item.h:302
int GetUnit() const
Definition: lib_item.h:296
bool operator==(const LIB_ITEM &aOther) const
Test LIB_ITEM objects for equivalence.
Definition: lib_item.cpp:93
virtual ~LIB_ITEM()
Definition: lib_item.h:104
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:146
COMPARE_FLAGS
The list of flags used by the compare function.
Definition: lib_item.h:117
bool operator<(const LIB_ITEM &aOther) const
Test if another draw item is less than this draw object.
Definition: lib_item.cpp:99
virtual void Rotate(const wxPoint &aCenter, bool aRotateCCW=true)=0
Rotate the object about aCenter point.
bool m_isFillable
Definition: lib_item.h:95
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:299
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, 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:50
virtual void MoveTo(const wxPoint &aPosition)=0
Move a draw object to aPosition.
void SetConvert(int aConvert)
Definition: lib_item.h:298
virtual void BeginEdit(const wxPoint aPosition)
Begin drawing a component library draw item at aPosition.
Definition: lib_item.h:134
virtual int GetWidth() const =0
void SetUnit(int aUnit)
Definition: lib_item.h:295
Base plotter engine class.
Definition: plotter.h:130
const int fill_tab[]
Definition: lib_item.cpp:32
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:190
virtual wxString GetTypeName()=0
Provide a user-consumable name of the object type.
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: eda_item.h:147
int m_Convert
Shape identification for alternate body styles.
Definition: lib_item.h:88
void SetPosition(const wxPoint &aPosition) override
Definition: lib_item.h:249
bool IsFillable() const
Check if draw object can be filled.
Definition: lib_item.h:293
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: eda_item.cpp:89
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:54
LIB_ITEM(KICAD_T aType, LIB_PART *aComponent=NULL, int aUnit=0, int aConvert=0, FILL_TYPE aFillType=FILL_TYPE::NO_FILL)
Definition: lib_item.cpp:35
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:74
virtual void EndEdit()
End an object editing action.
Definition: lib_item.h:153