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>
28#include <eeschema_settings.h>
29#include <sch_draw_panel.h>
30#include <widgets/msgpanel.h>
31#include <lib_symbol.h>
32
33const int fill_tab[3] = { 'N', 'F', 'f' };
34
35
36LIB_ITEM::LIB_ITEM( KICAD_T aType, LIB_SYMBOL* aSymbol, int aUnit, int aConvert ) :
37 EDA_ITEM( aSymbol, aType ),
38 m_unit( aUnit ),
39 m_convert( aConvert ),
40 m_private( false )
41{
42}
43
44
45void LIB_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
46{
47 wxString msg;
48
49 aList.emplace_back( _( "Type" ), GetTypeName() );
50
51 if( m_unit == 0 )
52 msg = _( "All" );
53 else
54 msg = LIB_SYMBOL::SubReference( m_unit, false );
55
56 aList.emplace_back( _( "Unit" ), msg );
57
59 msg = _( "no" );
61 msg = _( "yes" );
62 else
63 msg = wxT( "?" );
64
65 aList.emplace_back( _( "Converted" ), msg );
66
67 if( IsPrivate() )
68 aList.emplace_back( _( "Private" ), wxEmptyString );
69}
70
71
72int LIB_ITEM::compare( const LIB_ITEM& aOther, int aCompareFlags ) const
73{
74 if( Type() != aOther.Type() )
75 return Type() - aOther.Type();
76
77 // When comparing unit LIB_ITEM objects, we ignore the unit number.
78 if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_unit != aOther.m_unit )
79 return m_unit - aOther.m_unit;
80
81 if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_convert != aOther.m_convert )
82 return m_convert - aOther.m_convert;
83
84 if( IsPrivate() != aOther.IsPrivate() )
85 return IsPrivate() < aOther.IsPrivate();
86
87 return 0;
88}
89
90
91bool LIB_ITEM::cmp_items::operator()( const LIB_ITEM* aFirst, const LIB_ITEM* aSecond ) const
92{
93 return aFirst->compare( *aSecond, LIB_ITEM::COMPARE_FLAGS::EQUALITY ) < 0;
94}
95
96
97bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
98{
99 if( Type() != aOther.Type() )
100 return false;
101
102 return compare( aOther, LIB_ITEM::COMPARE_FLAGS::EQUALITY ) == 0;
103}
104
105
106bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
107{
108 if( Type() != aOther.Type() )
109 return Type() < aOther.Type();
110
111 return ( compare( aOther ) < 0 );
112}
113
114
115bool LIB_ITEM::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
116{
118 return false;
119
120 BOX2I sel = aRect;
121
122 if ( aAccuracy )
123 sel.Inflate( aAccuracy );
124
125 if( aContained )
126 return sel.Contains( GetBoundingBox() );
127
128 return sel.Intersects( GetBoundingBox() );
129}
130
131
132const wxString& LIB_ITEM::GetDefaultFont() const
133{
134 EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
135
136 return cfg->m_Appearance.default_font;
137}
138
139
140void LIB_ITEM::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
141 const TRANSFORM& aTransform, bool aDimmed )
142{
143 print( aSettings, aOffset, aData, aTransform, aDimmed );
144}
145
146
147void LIB_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
148{
149 // Basic fallback
150 aCount = 3;
151 aLayers[0] = LAYER_DEVICE;
152 aLayers[1] = LAYER_DEVICE_BACKGROUND;
153 aLayers[2] = LAYER_SELECTION_SHADOWS;
154}
155
156
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:269
bool Contains(const Vec &aPoint) const
Definition: box2.h:141
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:506
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
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:480
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
bool IsPrivate() const
Definition: lib_item.h:299
virtual wxString GetTypeName() const =0
Provide a user-consumable name of the object type.
const wxString & GetDefaultFont() const
Definition: lib_item.cpp:132
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:97
@ 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:358
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:72
virtual void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, void *aData, const TRANSFORM &aTransform, bool aDimmed)
Draw an item.
Definition: lib_item.cpp:140
@ BASE
Definition: lib_item.h:70
@ DEMORGAN
Definition: lib_item.h:70
LIB_ITEM(KICAD_T aType, LIB_SYMBOL *aSymbol=nullptr, int aUnit=0, int aConvert=0)
Definition: lib_item.cpp:36
const BOX2I GetBoundingBox() const override
Definition: lib_item.h:207
int m_unit
Unit identification for multiple parts per package.
Definition: lib_item.h:352
bool operator<(const LIB_ITEM &aOther) const
Test if another draw item is less than this draw object.
Definition: lib_item.cpp:106
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:195
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:45
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:147
Define a library symbol object.
Definition: lib_symbol.h:99
static wxString SubReference(int aUnit, bool aAddSeparator=true)
Definition: lib_symbol.cpp:720
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:361
@ LAYER_DEVICE_BACKGROUND
Definition: layer_ids.h:376
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:385
const int fill_tab[3]
Definition: lib_item.cpp:33
Message panel definition file.
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:115
bool operator()(const LIB_ITEM *aFirst, const LIB_ITEM *aSecond) const
Definition: lib_item.cpp:91
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78