KiCad PCB EDA Suite
lib_draw_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@verizon.net>
6  * Copyright (C) 2004-2015 KiCad Developers, see change_log.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 
31 #ifndef _LIB_ITEM_H_
32 #define _LIB_ITEM_H_
33 
34 #include <base_struct.h>
35 #include <class_eda_rect.h>
36 #include <transform.h>
37 #include <gr_basic.h>
38 
39 
40 class LINE_READER;
41 class OUTPUTFORMATTER;
42 class LIB_PART;
43 class PLOTTER;
44 class LIB_ITEM;
45 class LIB_PIN;
46 class MSG_PANEL_ITEM;
47 
48 
49 extern const int fill_tab[];
50 
51 
52 #define MINIMUM_SELECTION_DISTANCE 2 // Minimum selection distance in internal units
53 
54 
60 typedef std::vector< LIB_PIN* > LIB_PINS;
61 
62 
67 class LIB_ITEM : public EDA_ITEM
68 {
84  virtual void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
85  const wxPoint& aOffset, COLOR4D aColor,
86  GR_DRAWMODE aDrawMode, void* aData,
87  const TRANSFORM& aTransform ) = 0;
88 
96  virtual void drawEditGraphics( EDA_RECT* aClipBox, wxDC* aDC, COLOR4D aColor ) {}
97 
107  virtual void calcEdit( const wxPoint& aPosition ) {}
108 
110 
112  friend class LIB_PART;
113 
114 protected:
119  int m_Unit;
120 
127 
133 
134  wxString m_typeName;
135 
138 
141 
142 public:
143 
144  LIB_ITEM( KICAD_T aType,
145  LIB_PART* aComponent = NULL,
146  int aUnit = 0,
147  int aConvert = 0,
148  FILL_T aFillType = NO_FILL );
149 
150  // Do not create a copy constructor. The one generated by the compiler is adequate.
151 
152  virtual ~LIB_ITEM() { }
153 
154  wxString GetTypeName() { return m_typeName; }
155 
171  virtual void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aPosition = wxPoint( 0, 0 ) ) {}
172 
183  virtual bool ContinueEdit( const wxPoint aPosition ) { return false; }
184 
193  virtual void EndEdit( const wxPoint& aPosition, bool aAbort = false ) { m_Flags = 0; }
194 
209  virtual void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint &aOffset,
210  COLOR4D aColor, GR_DRAWMODE aDrawMode, void* aData,
211  const TRANSFORM& aTransform );
212 
218  virtual int GetPenSize() const = 0;
219 
228  virtual bool Save( OUTPUTFORMATTER& aFormatter ) = 0;
229 
230  virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ) = 0;
231 
233  {
234  return (LIB_PART *)m_Parent;
235  }
236 
237  virtual bool HitTest( const wxPoint& aPosition ) const override
238  {
239  return EDA_ITEM::HitTest( aPosition );
240  }
241 
250  virtual bool HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const = 0;
251 
255  virtual const EDA_RECT GetBoundingBox() const override { return EDA_ITEM::GetBoundingBox(); }
256 
268  virtual void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
269 
276  bool operator==( const LIB_ITEM& aOther ) const;
277  bool operator==( const LIB_ITEM* aOther ) const
278  {
279  return *this == *aOther;
280  }
281 
288  bool operator<( const LIB_ITEM& aOther) const;
289 
296  virtual void SetOffset( const wxPoint& aOffset ) = 0;
297 
305  virtual bool Inside( EDA_RECT& aRect ) const = 0;
306 
313  virtual void Move( const wxPoint& aPosition ) = 0;
314 
321  virtual wxPoint GetPosition() const = 0;
322 
323  void SetPosition( const wxPoint& aPosition ) { Move( aPosition ); }
324 
331  virtual void MirrorHorizontal( const wxPoint& aCenter ) = 0;
332 
339  virtual void MirrorVertical( const wxPoint& aCenter ) = 0;
340 
348  virtual void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) = 0;
349 
353  virtual void Rotate() {}
354 
363  virtual void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
364  const TRANSFORM& aTransform ) = 0;
365 
372  virtual int GetWidth() const = 0;
373 
378  virtual void SetWidth( int aWidth ) = 0;
379 
388  bool IsFillable() const { return m_isFillable; }
389 
395  bool InEditMode() const { return ( m_Flags & ( IS_NEW | IS_DRAGGED | IS_MOVED | IS_RESIZED ) ) != 0; }
396 
397  void SetEraseLastDrawItem( bool aErase = true ) { m_eraseLastDrawItem = aErase; }
398 
399  virtual COLOR4D GetDefaultColor();
400 
401  void SetUnit( int aUnit ) { m_Unit = aUnit; }
402 
403  int GetUnit() const { return m_Unit; }
404 
405  void SetConvert( int aConvert ) { m_Convert = aConvert; }
406 
407  int GetConvert() const { return m_Convert; }
408 
409  void SetFillMode( FILL_T aFillMode ) { m_Fill = aFillMode; }
410 
411  FILL_T GetFillMode() const { return m_Fill; }
412 
413 #if defined(DEBUG)
414  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
415 #endif
416 
417 private:
418 
435  virtual int compare( const LIB_ITEM& aOther ) const = 0;
436 };
437 
438 
439 #endif // _LIB_ITEM_H_
virtual wxPoint GetPosition() const =0
Function GetPosition returns the current draw object position.
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:182
FILL_T GetFillMode() const
wxString m_typeName
Name of object displayed in the message panel.
void SetPosition(const wxPoint &aPosition)
void SetEraseLastDrawItem(bool aErase=true)
int GetUnit() const
virtual void BeginEdit(STATUS_FLAGS aEditMode, const wxPoint aPosition=wxPoint(0, 0))
Begin an editing a component library draw item in aEditMode at aPosition.
virtual void SetWidth(int aWidth)=0
Function SetWidth sets the width of the draw item to aWidth.
virtual COLOR4D GetDefaultColor()
virtual void Move(const wxPoint &aPosition)=0
Function Move moves a draw object to aPosition.
const int fill_tab[]
bool m_eraseLastDrawItem
Used when editing a new draw item to prevent drawing artifacts.
virtual void EndEdit(const wxPoint &aPosition, bool aAbort=false)
End an object editing action.
virtual void Plot(PLOTTER *aPlotter, const wxPoint &aOffset, bool aFill, const TRANSFORM &aTransform)=0
Plot the draw item using the plot object.
bool InEditMode() const
Return the draw item editing mode status.
int m_Unit
Unit identification for multiple parts per package.
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
virtual void MirrorHorizontal(const wxPoint &aCenter)=0
Function MirrorHorizontal mirrors 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.
virtual int compare(const LIB_ITEM &aOther) const =0
Function compare provides the draw object specific comparison called by the == and < operators...
virtual bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:90
Class LIB_ITEM is the base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
virtual void SetOffset(const wxPoint &aOffset)=0
Function Offset sets the drawing object by aOffset from the current position.
#define IS_NEW
New item, just created.
Definition: base_struct.h:127
#define IS_DRAGGED
Item being dragged.
Definition: base_struct.h:129
virtual ~LIB_ITEM()
LIB_PART * GetParent() const
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
virtual bool ContinueEdit(const wxPoint aPosition)
Continue an edit in progress at aPosition.
wxString GetTypeName()
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
virtual void drawEditGraphics(EDA_RECT *aClipBox, wxDC *aDC, COLOR4D aColor)
Draw any editing specific graphics when the item is being edited.
Definition: lib_draw_item.h:96
bool m_isFillable
Flag to indicate if draw item is fillable.
Class LIB_PART defines a library part object.
unsigned STATUS_FLAGS
Definition: base_struct.h:158
virtual bool HitTest(const wxPoint &aPosition) const
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
Definition: base_struct.h:302
virtual void MirrorVertical(const wxPoint &aCenter)=0
Function MirrorVertical mirrors the draw object along the MirrorVertical (Y) axis about aCenter point...
virtual void Rotate()
Rotate the draw item.
void SetFillMode(FILL_T aFillMode)
bool operator<(const LIB_ITEM &aOther) const
Test if another draw item is less than this draw object.
void SetConvert(int aConvert)
virtual int GetWidth() const =0
Function GetWidth return the width of the draw item.
virtual const EDA_RECT GetBoundingBox() const override
void SetUnit(int aUnit)
Base plotter engine class.
Definition: plot_common.h:86
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:60
virtual void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo displays basic info (type, part and convert) about the current item in messa...
virtual int GetPenSize() const =0
Function GetPenSize.
virtual void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, void *aData, const TRANSFORM &aTransform)
Draw an item.
virtual bool Load(LINE_READER &aLine, wxString &aErrorMsg)=0
wxPoint m_initialPos
Temporary position when moving an existing item.
virtual void drawGraphic(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, void *aData, const TRANSFORM &aTransform)=0
Function drawGraphic.
FILL_T m_Fill
The body fill type.
STATUS_FLAGS m_Flags
Flag bits for editing and other uses.
Definition: base_struct.h:189
Class EDA_RECT handles the component boundary box.
bool operator==(const LIB_ITEM &aOther) const
Test LIB_ITEM objects for equivalence.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
#define IS_RESIZED
Item being resized.
Definition: base_struct.h:128
bool IsFillable() const
Check if draw object can be filled.
int m_Convert
Shape identification for alternate body styles.
FILL_T
Enum FILL_T is the set of fill types used in plotting or drawing enclosed areas.
Definition: base_struct.h:70
virtual bool Inside(EDA_RECT &aRect) const =0
Function Inside tests if any part of the draw object is inside rectangle bounds of aRect...
Basic classes for most KiCad items.
Class 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)
bool operator==(const LIB_ITEM *aOther) const
virtual bool Save(OUTPUTFORMATTER &aFormatter)=0
Function Save writes draw item object to aFormatter in component library "*.lib" format.
wxPoint m_initialCursorPos
Initial cursor position at the beginning of a move.
int GetConvert() const
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
#define IS_MOVED
Item being moved.
Definition: base_struct.h:126