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 <[email protected]>
6  * Copyright (C) 2004-2021 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 <eda_shape.h>
32 #include <transform.h>
33 #include <render_settings.h>
34 
35 class LINE_READER;
36 class OUTPUTFORMATTER;
37 class LIB_SYMBOL;
38 class PLOTTER;
39 class LIB_PIN;
40 class MSG_PANEL_ITEM;
41 
43 
44 extern const int fill_tab[];
45 
46 
47 #define MINIMUM_SELECTION_DISTANCE 2 // Minimum selection distance in internal units
48 
49 
55 typedef std::vector< LIB_PIN* > LIB_PINS;
56 
57 
61 class LIB_ITEM : public EDA_ITEM
62 {
63 public:
64  LIB_ITEM( KICAD_T aType, LIB_SYMBOL* aSymbol = nullptr, int aUnit = 0, int aConvert = 0 );
65 
66  // Do not create a copy constructor. The one generated by the compiler is adequate.
67 
68  virtual ~LIB_ITEM() { }
69 
70  // Define the enums for basic
71  enum LIB_CONVERT : int { BASE = 1, DEMORGAN = 2 };
72 
80  enum COMPARE_FLAGS : int { NORMAL = 0x00, UNIT = 0x01, EQUALITY = 0x02 };
81 
86  virtual wxString GetTypeName() const = 0;
87 
97  virtual void BeginEdit( const wxPoint& aPosition ) {}
98 
109  virtual bool ContinueEdit( const wxPoint& aPosition ) { return false; }
110 
116  virtual void EndEdit() {}
117 
127  virtual void CalcEdit( const wxPoint& aPosition ) {}
128 
140  virtual void Print( const RENDER_SETTINGS* aSettings, const wxPoint &aOffset,
141  void* aData, const TRANSFORM& aTransform );
142 
143  virtual int GetPenWidth() const = 0;
144 
145  virtual int GetEffectivePenWidth( const RENDER_SETTINGS* aSettings ) const
146  {
147  // For historical reasons, a stored value of 0 means "default width" and negative
148  // numbers meant "don't stroke".
149 
150  if( GetPenWidth() <= 0 )
151  return aSettings->GetDefaultPenWidth();
152  else
153  return std::max( GetPenWidth(), aSettings->GetMinPenWidth() );
154  }
155 
157  {
158  return (LIB_SYMBOL*) m_parent;
159  }
160 
161  void ViewGetLayers( int aLayers[], int& aCount ) const override;
162 
163  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override
164  {
165  // This is just here to prevent annoying compiler warnings about hidden overloaded
166  // virtual functions
167  return EDA_ITEM::HitTest( aPosition, aAccuracy );
168  }
169 
170  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
171 
175  const EDA_RECT GetBoundingBox() const override { return EDA_ITEM::GetBoundingBox(); }
176 
186  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
187 
194  bool operator==( const LIB_ITEM& aOther ) const;
195  bool operator==( const LIB_ITEM* aOther ) const
196  {
197  return *this == *aOther;
198  }
199 
206  bool operator<( const LIB_ITEM& aOther) const;
207 
213  virtual void Offset( const wxPoint& aOffset ) = 0;
214 
220  virtual void MoveTo( const wxPoint& aPosition ) = 0;
221 
222  void SetPosition( const wxPoint& aPosition ) override { MoveTo( aPosition ); }
223 
229  virtual void MirrorHorizontal( const wxPoint& aCenter ) = 0;
230 
236  virtual void MirrorVertical( const wxPoint& aCenter ) = 0;
237 
244  virtual void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) = 0;
245 
254  virtual void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
255  const TRANSFORM& aTransform ) const = 0;
256 
257  void SetUnit( int aUnit ) { m_unit = aUnit; }
258  int GetUnit() const { return m_unit; }
259 
260  void SetConvert( int aConvert ) { m_convert = aConvert; }
261  int GetConvert() const { return m_convert; }
262 
263 #if defined(DEBUG)
264  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
265 #endif
266 
267 protected:
288  virtual int compare( const LIB_ITEM& aOther,
289  LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const;
290 
299  virtual void print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
300  const TRANSFORM& aTransform ) = 0;
301 
302 private:
303  friend class LIB_SYMBOL;
304 
305 protected:
310  int m_unit;
311 
317 };
318 
319 
320 #endif // _LIB_ITEM_H_
const EDA_RECT GetBoundingBox() const override
Definition: lib_item.h:175
virtual int GetPenWidth() const =0
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:478
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:80
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_item.h:55
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:309
virtual int GetEffectivePenWidth(const RENDER_SETTINGS *aSettings) const
Definition: lib_item.h:145
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)
Calculate the attributes of an item at aPosition when it is being edited.
Definition: lib_item.h:127
The base class for create windows for drawing purpose.
Define a library symbol object.
Definition: lib_symbol.h:96
bool operator==(const LIB_ITEM *aOther) const
Definition: lib_item.h:195
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: lib_item.cpp:125
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
Test if aPosition is inside or on the boundary of this item.
Definition: eda_item.h:224
virtual wxString GetTypeName() const =0
Provide a user-consumable name of the object type.
virtual void Plot(PLOTTER *aPlotter, const wxPoint &aOffset, bool aFill, const TRANSFORM &aTransform) const =0
Plot the draw item using the plot object.
LIB_ITEM(KICAD_T aType, LIB_SYMBOL *aSymbol=nullptr, int aUnit=0, int aConvert=0)
Definition: lib_item.cpp:35
int m_unit
Unit identification for multiple parts per package.
Definition: lib_item.h:310
int GetUnit() const
Definition: lib_item.h:258
bool operator==(const LIB_ITEM &aOther) const
Test LIB_ITEM objects for equivalence.
Definition: lib_item.cpp:83
virtual ~LIB_ITEM()
Definition: lib_item.h:68
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
COMPARE_FLAGS
The list of flags used by the compare function.
Definition: lib_item.h:80
int m_convert
Shape identification for alternate body styles.
Definition: lib_item.h:316
bool operator<(const LIB_ITEM &aOther) const
Test if another draw item is less than this draw object.
Definition: lib_item.cpp:92
virtual void Rotate(const wxPoint &aCenter, bool aRotateCCW=true)=0
Rotate the object about aCenter point.
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:261
LIB_CONVERT
Definition: lib_item.h:71
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:43
virtual void MoveTo(const wxPoint &aPosition)=0
Move a draw object to aPosition.
void SetConvert(int aConvert)
Definition: lib_item.h:260
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:156
void SetUnit(int aUnit)
Definition: lib_item.h:257
Base plotter engine class.
Definition: plotter.h:121
virtual bool ContinueEdit(const wxPoint &aPosition)
Continue an edit in progress at aPosition.
Definition: lib_item.h:109
const int fill_tab[]
Definition: lib_item.cpp:32
virtual void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform)
Draw an item.
Definition: lib_item.cpp:118
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: lib_item.h:163
virtual void BeginEdit(const wxPoint &aPosition)
Begin drawing a symbol library draw item at aPosition.
Definition: lib_item.h:97
Handle the component boundary box.
Definition: eda_rect.h:42
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
int GetDefaultPenWidth() const
void SetPosition(const wxPoint &aPosition) override
Definition: lib_item.h:222
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:75
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:53
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:67
virtual void print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform)=0
Print the item to aDC.
virtual void EndEdit()
End an object editing action.
Definition: lib_item.h:116