KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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
41namespace KIFONT
42{
43class FONT;
44class METRICS;
45}
46
47
49
50extern const int fill_tab[];
51
52
53#define MINIMUM_SELECTION_DISTANCE 2 // Minimum selection distance in internal units
54
55
61typedef std::vector< LIB_PIN* > LIB_PINS;
62
63
67class LIB_ITEM : public EDA_ITEM
68{
69public:
70 LIB_ITEM( KICAD_T aType, LIB_SYMBOL* aSymbol = nullptr, int aUnit = 0, int aConvert = 0 );
71
72 // Do not create a copy constructor. The one generated by the compiler is adequate.
73
74 virtual ~LIB_ITEM() { }
75
76 // Define the enums for basic
77 enum LIB_CONVERT : int { BASE = 1, DEMORGAN = 2 };
78
89 enum COMPARE_FLAGS : int
90 {
91 UNIT = 0x01,
92 EQUALITY = 0x02,
93 ERC = 0x04
94 };
95
100 virtual wxString GetTypeName() const = 0;
101
102 static inline bool ClassOf( const EDA_ITEM* aItem )
103 {
104 if( !aItem )
105 return false;
106
107 switch ( aItem->Type() )
108 {
109 case LIB_SHAPE_T:
110 case LIB_TEXT_T:
111 case LIB_TEXTBOX_T:
112 case LIB_PIN_T:
113 case LIB_FIELD_T:
114 return true;
115 default:
116 break;
117 }
118
119 return false;
120 }
121
125 LIB_ITEM* Duplicate() const;
126
136 virtual void BeginEdit( const VECTOR2I& aPosition ) {}
137
148 virtual bool ContinueEdit( const VECTOR2I& aPosition ) { return false; }
149
155 virtual void EndEdit( bool aClosed = false ) {}
156
166 virtual void CalcEdit( const VECTOR2I& aPosition ) {}
167
180 virtual void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
181 const TRANSFORM& aTransform, bool aDimmed );
182
183 virtual int GetPenWidth() const = 0;
184
185 const wxString& GetDefaultFont() const;
186
187 const KIFONT::METRICS& GetFontMetrics() const;
188
189 virtual int GetEffectivePenWidth( const RENDER_SETTINGS* aSettings ) const
190 {
191 // For historical reasons, a stored value of 0 means "default width" and negative
192 // numbers meant "don't stroke".
193
194 if( GetPenWidth() < 0 )
195 return 0;
196 else if( GetPenWidth() == 0 )
197 return std::max( aSettings->GetDefaultPenWidth(), aSettings->GetMinPenWidth() );
198 else
199 return std::max( GetPenWidth(), aSettings->GetMinPenWidth() );
200 }
201
203 {
204 return (LIB_SYMBOL*) m_parent;
205 }
206
207 void ViewGetLayers( int aLayers[], int& aCount ) const override;
208
209 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override
210 {
211 // This is just here to prevent annoying compiler warnings about hidden overloaded
212 // virtual functions
213 return EDA_ITEM::HitTest( aPosition, aAccuracy );
214 }
215
216 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
217
221 const BOX2I GetBoundingBox() const override { return EDA_ITEM::GetBoundingBox(); }
222
232 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
233
240 bool operator==( const LIB_ITEM& aOther ) const;
241 bool operator==( const LIB_ITEM* aOther ) const
242 {
243 return *this == *aOther;
244 }
245
252 bool operator<( const LIB_ITEM& aOther) const;
253
259 virtual void Offset( const VECTOR2I& aOffset ) = 0;
260
266 virtual void MoveTo( const VECTOR2I& aPosition ) = 0;
267
268 void SetPosition( const VECTOR2I& aPosition ) override { MoveTo( aPosition ); }
269
275 virtual void MirrorHorizontal( const VECTOR2I& aCenter ) = 0;
276
282 virtual void MirrorVertical( const VECTOR2I& aCenter ) = 0;
283
290 virtual void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) = 0;
291
303 virtual void Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffset,
304 const TRANSFORM& aTransform, bool aDimmed ) const = 0;
305
306 void SetUnit( int aUnit ) { m_unit = aUnit; }
307 int GetUnit() const { return m_unit; }
308
309 void SetConvert( int aConvert ) { m_convert = aConvert; }
310 int GetConvert() const { return m_convert; }
311
312 void SetPrivate( bool aPrivate ) { m_private = aPrivate; }
313 bool IsPrivate() const { return m_private; }
314
316 {
317 bool operator()( const LIB_ITEM* aFirst, const LIB_ITEM* aSecond ) const;
318 };
319
320#if defined(DEBUG)
321 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
322#endif
323
324protected:
345 virtual int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const;
346
355 virtual void print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
356 const TRANSFORM& aTransform, bool aDimmed ) = 0;
357
358private:
359 friend class LIB_SYMBOL;
360
361protected:
367
373
378};
379
380
381#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
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
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:212
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:485
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
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:68
bool IsPrivate() const
Definition: lib_item.h:313
virtual ~LIB_ITEM()
Definition: lib_item.h:74
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 void EndEdit(bool aClosed=false)
End an object editing action.
Definition: lib_item.h:155
virtual int GetPenWidth() const =0
const wxString & GetDefaultFont() const
Definition: lib_item.cpp:142
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:98
bool operator==(const LIB_ITEM *aOther) const
Definition: lib_item.h:241
virtual void CalcEdit(const VECTOR2I &aPosition)
Calculate the attributes of an item at aPosition when it is being edited.
Definition: lib_item.h:166
COMPARE_FLAGS
The list of flags used by the compare function.
Definition: lib_item.h:90
@ EQUALITY
Definition: lib_item.h:92
@ UNIT
Definition: lib_item.h:91
int m_convert
Shape identification for alternate body styles.
Definition: lib_item.h:372
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:73
int GetUnit() const
Definition: lib_item.h:307
virtual int GetEffectivePenWidth(const RENDER_SETTINGS *aSettings) const
Definition: lib_item.h:189
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.
LIB_ITEM * Duplicate() const
Create a copy of this LIB_ITEM (with a new Uuid).
Definition: lib_item.cpp:116
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:156
static bool ClassOf(const EDA_ITEM *aItem)
Definition: lib_item.h:102
void SetPrivate(bool aPrivate)
Definition: lib_item.h:312
virtual void MoveTo(const VECTOR2I &aPosition)=0
Move a draw object to aPosition.
const KIFONT::METRICS & GetFontMetrics() const
Definition: lib_item.cpp:150
bool m_private
Private items are shown only in the Symbol Editor.
Definition: lib_item.h:377
LIB_CONVERT
Definition: lib_item.h:77
@ BASE
Definition: lib_item.h:77
@ DEMORGAN
Definition: lib_item.h:77
int GetConvert() const
Definition: lib_item.h:310
const BOX2I GetBoundingBox() const override
Definition: lib_item.h:221
int m_unit
Unit identification for multiple parts per package.
Definition: lib_item.h:366
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:148
bool operator<(const LIB_ITEM &aOther) const
Test if another draw item is less than this draw object.
Definition: lib_item.cpp:107
void SetPosition(const VECTOR2I &aPosition) override
Definition: lib_item.h:268
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:209
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:46
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:202
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:163
virtual void BeginEdit(const VECTOR2I &aPosition)
Begin drawing a symbol library draw item at aPosition.
Definition: lib_item.h:136
void SetConvert(int aConvert)
Definition: lib_item.h:309
void SetUnit(int aUnit)
Definition: lib_item.h:306
Define a library symbol object.
Definition: lib_symbol.h:99
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:93
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:322
Base plotter engine class.
Definition: plotter.h:104
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:46
const int fill_tab[]
Definition: lib_item.cpp:34
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_item.h:61
bool operator()(const LIB_ITEM *aFirst, const LIB_ITEM *aSecond) const
Definition: lib_item.cpp:92
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ LIB_TEXT_T
Definition: typeinfo.h:199
@ LIB_TEXTBOX_T
Definition: typeinfo.h:200
@ LIB_SHAPE_T
Definition: typeinfo.h:198
@ LIB_PIN_T
Definition: typeinfo.h:201
@ LIB_FIELD_T
Definition: typeinfo.h:207