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 body styles
77 enum BODY_STYLE : int
78 {
79 BASE = 1,
80 DEMORGAN = 2
81 };
82
93 enum COMPARE_FLAGS : int
94 {
95 UNIT = 0x01,
96 EQUALITY = 0x02,
97 ERC = 0x04
98 };
99
104 virtual wxString GetTypeName() const = 0;
105
106 static inline bool ClassOf( const EDA_ITEM* aItem )
107 {
108 if( !aItem )
109 return false;
110
111 switch ( aItem->Type() )
112 {
113 case LIB_SHAPE_T:
114 case LIB_TEXT_T:
115 case LIB_TEXTBOX_T:
116 case LIB_PIN_T:
117 case LIB_FIELD_T:
118 return true;
119 default:
120 break;
121 }
122
123 return false;
124 }
125
126 static wxString GetUnitDescription( int aUnit );
127 static wxString GetBodyStyleDescription( int aBodyStyle );
128
132 LIB_ITEM* Duplicate() const;
133
143 virtual void BeginEdit( const VECTOR2I& aPosition ) {}
144
155 virtual bool ContinueEdit( const VECTOR2I& aPosition ) { return false; }
156
162 virtual void EndEdit( bool aClosed = false ) {}
163
173 virtual void CalcEdit( const VECTOR2I& aPosition ) {}
174
187 virtual void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
188 const TRANSFORM& aTransform, bool aDimmed );
189
190 virtual int GetPenWidth() const = 0;
191
192 const wxString& GetDefaultFont() const;
193
194 const KIFONT::METRICS& GetFontMetrics() const;
195
196 virtual int GetEffectivePenWidth( const RENDER_SETTINGS* aSettings ) const
197 {
198 // For historical reasons, a stored value of 0 means "default width" and negative
199 // numbers meant "don't stroke".
200
201 if( GetPenWidth() < 0 )
202 return 0;
203 else if( GetPenWidth() == 0 )
204 return std::max( aSettings->GetDefaultPenWidth(), aSettings->GetMinPenWidth() );
205 else
206 return std::max( GetPenWidth(), aSettings->GetMinPenWidth() );
207 }
208
209 LIB_SYMBOL* GetParent() const // Replace EDA_ITEM::GetParent() with a more useful return-type
210 {
211 return (LIB_SYMBOL*) m_parent;
212 }
213
220 virtual double Similarity( const LIB_ITEM& aItem ) const = 0;
221
227 double SimilarityBase( const LIB_ITEM& aItem ) const
228 {
229 double similarity = 1.0;
230
231 if( m_unit != aItem.m_unit )
232 similarity *= 0.9;
233
234 if( m_bodyStyle != aItem.m_bodyStyle )
235 similarity *= 0.9;
236
237 if( m_private != aItem.m_private )
238 similarity *= 0.9;
239
240 return similarity;
241 }
242
243 void ViewGetLayers( int aLayers[], int& aCount ) const override;
244
245 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override
246 {
247 // This is just here to prevent annoying compiler warnings about hidden overloaded
248 // virtual functions
249 return EDA_ITEM::HitTest( aPosition, aAccuracy );
250 }
251
252 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
253
257 const BOX2I GetBoundingBox() const override { return EDA_ITEM::GetBoundingBox(); }
258
268 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
269
276 virtual 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
295 virtual void Offset( const VECTOR2I& aOffset ) = 0;
296
302 virtual void MoveTo( const VECTOR2I& aPosition ) = 0;
303
304 void SetPosition( const VECTOR2I& aPosition ) override { MoveTo( aPosition ); }
305
311 virtual void MirrorHorizontal( const VECTOR2I& aCenter ) = 0;
312
318 virtual void MirrorVertical( const VECTOR2I& aCenter ) = 0;
319
326 virtual void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) = 0;
327
339 virtual void Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffset,
340 const TRANSFORM& aTransform, bool aDimmed ) const = 0;
341
342 void SetUnit( int aUnit ) { m_unit = aUnit; }
343 int GetUnit() const { return m_unit; }
344
345 void SetBodyStyle( int aBodyStyle ) { m_bodyStyle = aBodyStyle; }
346 int GetBodyStyle() const { return m_bodyStyle; }
347
348 void SetPrivate( bool aPrivate ) { m_private = aPrivate; }
349 bool IsPrivate() const { return m_private; }
350
352 {
353 bool operator()( const LIB_ITEM* aFirst, const LIB_ITEM* aSecond ) const;
354 };
355
356#if defined(DEBUG)
357 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
358#endif
359
360protected:
381 virtual int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const;
382
391 virtual void print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
392 const TRANSFORM& aTransform, bool aDimmed ) = 0;
393
394private:
395 friend class LIB_SYMBOL;
396
397protected:
403
409
414};
415
416
417#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:349
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:162
virtual int GetPenWidth() const =0
const wxString & GetDefaultFont() const
Definition: lib_item.cpp:157
virtual void print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, void *aData, const TRANSFORM &aTransform, bool aDimmed)=0
Print the item to aDC.
virtual bool operator==(const LIB_ITEM &aOther) const
Test LIB_ITEM objects for equivalence.
Definition: lib_item.cpp:113
bool operator==(const LIB_ITEM *aOther) const
Definition: lib_item.h:277
virtual void CalcEdit(const VECTOR2I &aPosition)
Calculate the attributes of an item at aPosition when it is being edited.
Definition: lib_item.h:173
int GetBodyStyle() const
Definition: lib_item.h:346
COMPARE_FLAGS
The list of flags used by the compare function.
Definition: lib_item.h:94
@ EQUALITY
Definition: lib_item.h:96
@ UNIT
Definition: lib_item.h:95
virtual double Similarity(const LIB_ITEM &aItem) const =0
Return a measure of how likely the other object is to represent the same object.
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:88
int GetUnit() const
Definition: lib_item.h:343
virtual int GetEffectivePenWidth(const RENDER_SETTINGS *aSettings) const
Definition: lib_item.h:196
static wxString GetUnitDescription(int aUnit)
Definition: lib_item.cpp:46
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:131
virtual void MirrorVertical(const VECTOR2I &aCenter)=0
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
double SimilarityBase(const LIB_ITEM &aItem) const
Calculate the boilerplate similarity for all LIB_ITEMs without preventing the use above of a pure vir...
Definition: lib_item.h:227
virtual void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, void *aData, const TRANSFORM &aTransform, bool aDimmed)
Draw an item.
Definition: lib_item.cpp:171
static bool ClassOf(const EDA_ITEM *aItem)
Definition: lib_item.h:106
void SetPrivate(bool aPrivate)
Definition: lib_item.h:348
virtual void MoveTo(const VECTOR2I &aPosition)=0
Move a draw object to aPosition.
const KIFONT::METRICS & GetFontMetrics() const
Definition: lib_item.cpp:165
int m_bodyStyle
Shape identification for alternate body styles.
Definition: lib_item.h:408
bool m_private
Private items are shown only in the Symbol Editor.
Definition: lib_item.h:413
const BOX2I GetBoundingBox() const override
Definition: lib_item.h:257
int m_unit
Unit identification for multiple parts per package.
Definition: lib_item.h:402
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:155
bool operator<(const LIB_ITEM &aOther) const
Test if another draw item is less than this draw object.
Definition: lib_item.cpp:122
void SetPosition(const VECTOR2I &aPosition) override
Definition: lib_item.h:304
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:245
static wxString GetBodyStyleDescription(int aBodyStyle)
Definition: lib_item.cpp:55
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:68
void SetBodyStyle(int aBodyStyle)
Definition: lib_item.h:345
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:209
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:178
virtual void BeginEdit(const VECTOR2I &aPosition)
Begin drawing a symbol library draw item at aPosition.
Definition: lib_item.h:143
void SetUnit(int aUnit)
Definition: lib_item.h:342
BODY_STYLE
Definition: lib_item.h:78
@ BASE
Definition: lib_item.h:79
@ DEMORGAN
Definition: lib_item.h:80
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:107
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ LIB_TEXT_T
Definition: typeinfo.h:204
@ LIB_TEXTBOX_T
Definition: typeinfo.h:205
@ LIB_SHAPE_T
Definition: typeinfo.h:203
@ LIB_PIN_T
Definition: typeinfo.h:206
@ LIB_FIELD_T
Definition: typeinfo.h:212