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_shape.h>
31#include <transform.h>
32#include <render_settings.h>
33
34class LINE_READER;
35class OUTPUTFORMATTER;
36class LIB_SYMBOL;
37class PLOTTER;
38class LIB_PIN;
39class MSG_PANEL_ITEM;
40
42
43extern const int fill_tab[];
44
45
46#define MINIMUM_SELECTION_DISTANCE 2 // Minimum selection distance in internal units
47
48
54typedef std::vector< LIB_PIN* > LIB_PINS;
55
56
60class LIB_ITEM : public EDA_ITEM
61{
62public:
63 LIB_ITEM( KICAD_T aType, LIB_SYMBOL* aSymbol = nullptr, int aUnit = 0, int aConvert = 0 );
64
65 // Do not create a copy constructor. The one generated by the compiler is adequate.
66
67 virtual ~LIB_ITEM() { }
68
69 // Define the enums for basic
70 enum LIB_CONVERT : int { BASE = 1, DEMORGAN = 2 };
71
82 enum COMPARE_FLAGS : int
83 {
84 UNIT = 0x01,
85 EQUALITY = 0x02,
86 ERC = 0x04
87 };
88
93 virtual wxString GetTypeName() const = 0;
94
104 virtual void BeginEdit( const VECTOR2I& aPosition ) {}
105
116 virtual bool ContinueEdit( const VECTOR2I& aPosition ) { return false; }
117
123 virtual void EndEdit() {}
124
134 virtual void CalcEdit( const VECTOR2I& aPosition ) {}
135
148 virtual void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
149 const TRANSFORM& aTransform, bool aDimmed );
150
151 virtual int GetPenWidth() const = 0;
152
153 const wxString& GetDefaultFont() const;
154
155 virtual int GetEffectivePenWidth( const RENDER_SETTINGS* aSettings ) const
156 {
157 // For historical reasons, a stored value of 0 means "default width" and negative
158 // numbers meant "don't stroke".
159
160 if( GetPenWidth() < 0 )
161 return 0;
162 else if( GetPenWidth() == 0 )
163 return std::max( aSettings->GetDefaultPenWidth(), aSettings->GetMinPenWidth() );
164 else
165 return std::max( GetPenWidth(), aSettings->GetMinPenWidth() );
166 }
167
169 {
170 return (LIB_SYMBOL*) m_parent;
171 }
172
173 void ViewGetLayers( int aLayers[], int& aCount ) const override;
174
175 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override
176 {
177 // This is just here to prevent annoying compiler warnings about hidden overloaded
178 // virtual functions
179 return EDA_ITEM::HitTest( aPosition, aAccuracy );
180 }
181
182 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
183
187 const BOX2I GetBoundingBox() const override { return EDA_ITEM::GetBoundingBox(); }
188
198 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
199
206 bool operator==( const LIB_ITEM& aOther ) const;
207 bool operator==( const LIB_ITEM* aOther ) const
208 {
209 return *this == *aOther;
210 }
211
218 bool operator<( const LIB_ITEM& aOther) const;
219
225 virtual void Offset( const VECTOR2I& aOffset ) = 0;
226
232 virtual void MoveTo( const VECTOR2I& aPosition ) = 0;
233
234 void SetPosition( const VECTOR2I& aPosition ) override { MoveTo( aPosition ); }
235
241 virtual void MirrorHorizontal( const VECTOR2I& aCenter ) = 0;
242
248 virtual void MirrorVertical( const VECTOR2I& aCenter ) = 0;
249
256 virtual void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) = 0;
257
269 virtual void Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffset,
270 const TRANSFORM& aTransform, bool aDimmed ) const = 0;
271
272 void SetUnit( int aUnit ) { m_unit = aUnit; }
273 int GetUnit() const { return m_unit; }
274
275 void SetConvert( int aConvert ) { m_convert = aConvert; }
276 int GetConvert() const { return m_convert; }
277
278 void SetPrivate( bool aPrivate ) { m_private = aPrivate; }
279 bool IsPrivate() const { return m_private; }
280
281#if defined(DEBUG)
282 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
283#endif
284
285protected:
306 virtual int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const;
307
316 virtual void print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
317 const TRANSFORM& aTransform, bool aDimmed ) = 0;
318
319private:
320 friend class LIB_SYMBOL;
321
322protected:
328
334
339};
340
341
342#endif // _LIB_ITEM_H_
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:74
virtual bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const
Test if aPosition is inside or on the boundary of this item.
Definition: eda_item.h:224
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:498
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
int GetDefaultPenWidth() const
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
bool IsPrivate() const
Definition: lib_item.h:279
virtual void EndEdit()
End an object editing action.
Definition: lib_item.h:123
virtual ~LIB_ITEM()
Definition: lib_item.h:67
virtual wxString GetTypeName() const =0
Provide a user-consumable name of the object type.
virtual void Plot(PLOTTER *aPlotter, bool aBackground, const VECTOR2I &aOffset, const TRANSFORM &aTransform, bool aDimmed) const =0
Plot the draw item using the plot object.
virtual int GetPenWidth() const =0
const wxString & GetDefaultFont() const
Definition: lib_item.cpp:128
virtual void print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, void *aData, const TRANSFORM &aTransform, bool aDimmed)=0
Print the item to aDC.
bool operator==(const LIB_ITEM &aOther) const
Test LIB_ITEM objects for equivalence.
Definition: lib_item.cpp:93
bool operator==(const LIB_ITEM *aOther) const
Definition: lib_item.h:207
virtual void CalcEdit(const VECTOR2I &aPosition)
Calculate the attributes of an item at aPosition when it is being edited.
Definition: lib_item.h:134
COMPARE_FLAGS
The list of flags used by the compare function.
Definition: lib_item.h:83
@ EQUALITY
Definition: lib_item.h:85
@ UNIT
Definition: lib_item.h:84
int m_convert
Shape identification for alternate body styles.
Definition: lib_item.h:333
virtual int compare(const LIB_ITEM &aOther, int aCompareFlags=0) const
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_item.cpp:74
int GetUnit() const
Definition: lib_item.h:273
virtual int GetEffectivePenWidth(const RENDER_SETTINGS *aSettings) const
Definition: lib_item.h:155
virtual void MirrorHorizontal(const VECTOR2I &aCenter)=0
Mirror the draw object along the horizontal (X) axis about aCenter point.
virtual void Rotate(const VECTOR2I &aCenter, bool aRotateCCW=true)=0
Rotate the object about aCenter point.
virtual void MirrorVertical(const VECTOR2I &aCenter)=0
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
virtual void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, void *aData, const TRANSFORM &aTransform, bool aDimmed)
Draw an item.
Definition: lib_item.cpp:136
void SetPrivate(bool aPrivate)
Definition: lib_item.h:278
virtual void MoveTo(const VECTOR2I &aPosition)=0
Move a draw object to aPosition.
bool m_private
Private items are shown only in the Symbol Editor.
Definition: lib_item.h:338
LIB_CONVERT
Definition: lib_item.h:70
@ BASE
Definition: lib_item.h:70
@ DEMORGAN
Definition: lib_item.h:70
int GetConvert() const
Definition: lib_item.h:276
LIB_ITEM(KICAD_T aType, LIB_SYMBOL *aSymbol=nullptr, int aUnit=0, int aConvert=0)
Definition: lib_item.cpp:38
const BOX2I GetBoundingBox() const override
Definition: lib_item.h:187
int m_unit
Unit identification for multiple parts per package.
Definition: lib_item.h:327
virtual void Offset(const VECTOR2I &aOffset)=0
Set the drawing object by aOffset from the current position.
virtual bool ContinueEdit(const VECTOR2I &aPosition)
Continue an edit in progress at aPosition.
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:102
void SetPosition(const VECTOR2I &aPosition) override
Definition: lib_item.h:234
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: lib_item.h:175
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:47
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:168
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:143
virtual void BeginEdit(const VECTOR2I &aPosition)
Begin drawing a symbol library draw item at aPosition.
Definition: lib_item.h:104
void SetConvert(int aConvert)
Definition: lib_item.h:275
void SetUnit(int aUnit)
Definition: lib_item.h:272
Define a library symbol object.
Definition: lib_symbol.h:98
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:81
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:54
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:310
Base plotter engine class.
Definition: plotter.h:110
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:47
const int fill_tab[]
Definition: lib_item.cpp:35
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_item.h:54
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78