KiCad PCB EDA Suite
Loading...
Searching...
No Matches
lib_item.cpp
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 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
26#include <pgm_base.h>
27#include <font/font.h>
29#include <eeschema_settings.h>
30#include <sch_draw_panel.h>
31#include <widgets/msgpanel.h>
32#include <lib_symbol.h>
33
34const int fill_tab[3] = { 'N', 'F', 'f' };
35
36
37LIB_ITEM::LIB_ITEM( KICAD_T aType, LIB_SYMBOL* aSymbol, int aUnit, int aConvert ) :
38 EDA_ITEM( aSymbol, aType ),
39 m_unit( aUnit ),
40 m_convert( aConvert ),
41 m_private( false )
42{
43}
44
45
46void LIB_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
47{
48 wxString msg;
49
50 aList.emplace_back( _( "Type" ), GetTypeName() );
51
52 if( m_unit == 0 )
53 msg = _( "All" );
54 else
56
57 aList.emplace_back( _( "Unit" ), msg );
58
60 msg = _( "no" );
62 msg = _( "yes" );
63 else
64 msg = wxT( "?" );
65
66 aList.emplace_back( _( "Converted" ), msg );
67
68 if( IsPrivate() )
69 aList.emplace_back( _( "Private" ), wxEmptyString );
70}
71
72
73int LIB_ITEM::compare( const LIB_ITEM& aOther, int aCompareFlags ) const
74{
75 if( Type() != aOther.Type() )
76 return Type() - aOther.Type();
77
78 // When comparing unit LIB_ITEM objects, we ignore the unit number.
79 if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_unit != aOther.m_unit )
80 return m_unit - aOther.m_unit;
81
82 if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_convert != aOther.m_convert )
83 return m_convert - aOther.m_convert;
84
85 if( IsPrivate() != aOther.IsPrivate() )
86 return IsPrivate() < aOther.IsPrivate();
87
88 return 0;
89}
90
91
92bool LIB_ITEM::cmp_items::operator()( const LIB_ITEM* aFirst, const LIB_ITEM* aSecond ) const
93{
94 return aFirst->compare( *aSecond, LIB_ITEM::COMPARE_FLAGS::EQUALITY ) < 0;
95}
96
97
98bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
99{
100 if( Type() != aOther.Type() )
101 return false;
102
103 return compare( aOther, LIB_ITEM::COMPARE_FLAGS::EQUALITY ) == 0;
104}
105
106
107bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
108{
109 if( Type() != aOther.Type() )
110 return Type() < aOther.Type();
111
112 return ( compare( aOther ) < 0 );
113}
114
115
117{
118 LIB_ITEM* dupe = static_cast<LIB_ITEM*>( Clone() );
119 const_cast<KIID&>( dupe->m_Uuid ) = KIID();
120
121 return dupe;
122}
123
124
125bool LIB_ITEM::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
126{
128 return false;
129
130 BOX2I sel = aRect;
131
132 if ( aAccuracy )
133 sel.Inflate( aAccuracy );
134
135 if( aContained )
136 return sel.Contains( GetBoundingBox() );
137
138 return sel.Intersects( GetBoundingBox() );
139}
140
141
142const wxString& LIB_ITEM::GetDefaultFont() const
143{
144 EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
145
146 return cfg->m_Appearance.default_font;
147}
148
149
151{
153}
154
155
156void LIB_ITEM::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
157 const TRANSFORM& aTransform, bool aDimmed )
158{
159 print( aSettings, aOffset, aData, aTransform, aDimmed );
160}
161
162
163void LIB_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
164{
165 // Basic fallback
166 aCount = 3;
167 aLayers[0] = LAYER_DEVICE;
168 aLayers[1] = LAYER_DEVICE_BACKGROUND;
169 aLayers[2] = LAYER_SELECTION_SHADOWS;
170}
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:270
bool Contains(const Vec &aPoint) const
Definition: box2.h:142
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:507
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
const KIID m_Uuid
Definition: eda_item.h:482
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:487
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:82
static const METRICS & Default()
Definition: font.cpp:52
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Definition: kiid.h:49
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:68
bool IsPrivate() const
Definition: lib_item.h:342
virtual wxString GetTypeName() const =0
Provide a user-consumable name of the object type.
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.
virtual bool operator==(const LIB_ITEM &aOther) const
Test LIB_ITEM objects for equivalence.
Definition: lib_item.cpp:98
@ 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:401
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
LIB_ITEM * Duplicate() const
Create a copy of this LIB_ITEM (with a new Uuid).
Definition: lib_item.cpp:116
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
const KIFONT::METRICS & GetFontMetrics() const
Definition: lib_item.cpp:150
@ BASE
Definition: lib_item.h:77
@ DEMORGAN
Definition: lib_item.h:77
LIB_ITEM(KICAD_T aType, LIB_SYMBOL *aSymbol=nullptr, int aUnit=0, int aConvert=0)
Definition: lib_item.cpp:37
const BOX2I GetBoundingBox() const override
Definition: lib_item.h:250
int m_unit
Unit identification for multiple parts per package.
Definition: lib_item.h:395
bool operator<(const LIB_ITEM &aOther) const
Test if another draw item is less than this draw object.
Definition: lib_item.cpp:107
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:238
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
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
Define a library symbol object.
Definition: lib_symbol.h:99
static wxString LetterSubReference(int aUnit, int aFirstId)
Definition: lib_symbol.cpp:760
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:46
#define _(s)
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
@ LAYER_DEVICE
Definition: layer_ids.h:362
@ LAYER_DEVICE_BACKGROUND
Definition: layer_ids.h:378
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:387
const int fill_tab[3]
Definition: lib_item.cpp:34
Message panel definition file.
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119
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