KiCad PCB EDA Suite
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-2022 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#include <general.h>
33#include <lib_item.h>
34
35const int fill_tab[3] = { 'N', 'F', 'f' };
36
37
38LIB_ITEM::LIB_ITEM( KICAD_T aType, LIB_SYMBOL* aSymbol, int aUnit, int aConvert ) :
39 EDA_ITEM( aSymbol, aType ),
40 m_unit( aUnit ),
41 m_convert( aConvert ),
42 m_private( false )
43{
44}
45
46
47void LIB_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
48{
49 wxString msg;
50
51 aList.emplace_back( _( "Type" ), GetTypeName() );
52
53 if( m_unit == 0 )
54 msg = _( "All" );
55 else
56 msg = LIB_SYMBOL::SubReference( m_unit, false );
57
58 aList.emplace_back( _( "Unit" ), msg );
59
60 if( m_convert == LIB_ITEM::LIB_CONVERT::BASE )
61 msg = _( "no" );
62 else if( m_convert == LIB_ITEM::LIB_CONVERT::DEMORGAN )
63 msg = _( "yes" );
64 else
65 msg = wxT( "?" );
66
67 aList.emplace_back( _( "Converted" ), msg );
68
69 if( IsPrivate() )
70 aList.emplace_back( _( "Private" ), wxEmptyString );
71}
72
73
74int LIB_ITEM::compare( const LIB_ITEM& aOther, int aCompareFlags ) const
75{
76 if( Type() != aOther.Type() )
77 return Type() - aOther.Type();
78
79 // When comparing unit LIB_ITEM objects, we ignore the unit number.
80 if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_unit != aOther.m_unit )
81 return m_unit - aOther.m_unit;
82
83 if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_convert != aOther.m_convert )
84 return m_convert - aOther.m_convert;
85
86 if( IsPrivate() != aOther.IsPrivate() )
87 return IsPrivate() < aOther.IsPrivate();
88
89 return 0;
90}
91
92
93bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
94{
95 if( Type() != aOther.Type() )
96 return false;
97
98 return compare( aOther, LIB_ITEM::COMPARE_FLAGS::EQUALITY ) == 0;
99}
100
101
102bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
103{
104 if( Type() != aOther.Type() )
105 return Type() < aOther.Type();
106
107 return ( compare( aOther ) < 0 );
108}
109
110
111bool LIB_ITEM::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
112{
114 return false;
115
116 BOX2I sel = aRect;
117
118 if ( aAccuracy )
119 sel.Inflate( aAccuracy );
120
121 if( aContained )
122 return sel.Contains( GetBoundingBox() );
123
124 return sel.Intersects( GetBoundingBox() );
125}
126
127
128const wxString& LIB_ITEM::GetDefaultFont() const
129{
130 EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
131
132 return cfg->m_Appearance.default_font;
133}
134
135
136void LIB_ITEM::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
137 const TRANSFORM& aTransform, bool aDimmed )
138{
139 print( aSettings, aOffset, aData, aTransform, aDimmed );
140}
141
142
143void LIB_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
144{
145 // Basic fallback
146 aCount = 3;
147 aLayers[0] = LAYER_DEVICE;
148 aLayers[1] = LAYER_DEVICE_BACKGROUND;
149 aLayers[2] = LAYER_SELECTION_SHADOWS;
150}
151
152
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:498
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:279
virtual wxString GetTypeName() const =0
Provide a user-consumable name of the object type.
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
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
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
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
bool operator<(const LIB_ITEM &aOther) const
Test if another draw item is less than this draw object.
Definition: lib_item.cpp:102
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
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
Define a library symbol object.
Definition: lib_symbol.h:99
static wxString SubReference(int aUnit, bool aAddSeparator=true)
Definition: lib_symbol.cpp:584
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:47
#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:357
@ LAYER_DEVICE_BACKGROUND
Definition: layer_ids.h:372
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:381
const int fill_tab[3]
Definition: lib_item.cpp:35
Message panel definition file.
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78