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 <stambaughw@verizon.net>
6  * Copyright (C) 2004-2021 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 <sch_draw_panel.h>
27 #include <widgets/msgpanel.h>
28 #include <lib_symbol.h>
29 #include <general.h>
30 #include <lib_item.h>
31 
32 const int fill_tab[3] = { 'N', 'F', 'f' };
33 
34 
35 LIB_ITEM::LIB_ITEM( KICAD_T aType, LIB_SYMBOL* aSymbol, int aUnit, int aConvert ) :
36  EDA_ITEM( aSymbol, aType ),
37  m_unit( aUnit ),
38  m_convert( aConvert )
39 {
40 }
41 
42 
43 void LIB_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
44 {
45  wxString msg;
46 
47  aList.emplace_back( _( "Type" ), GetTypeName() );
48 
49  if( m_unit == 0 )
50  msg = _( "All" );
51  else
52  msg.Printf( wxT( "%d" ), m_unit );
53 
54  aList.emplace_back( _( "Unit" ), msg );
55 
56  if( m_convert == LIB_ITEM::LIB_CONVERT::BASE )
57  msg = _( "no" );
58  else if( m_convert == LIB_ITEM::LIB_CONVERT::DEMORGAN )
59  msg = _( "yes" );
60  else
61  msg = wxT( "?" );
62 
63  aList.emplace_back( _( "Converted" ), msg );
64 }
65 
66 
67 int LIB_ITEM::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
68 {
69  if( Type() != aOther.Type() )
70  return Type() - aOther.Type();
71 
72  // When comparing unit LIB_ITEM objects, we ignore the unit number.
73  if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_unit != aOther.m_unit )
74  return m_unit - aOther.m_unit;
75 
76  if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_convert != aOther.m_convert )
77  return m_convert - aOther.m_convert;
78 
79  return 0;
80 }
81 
82 
83 bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
84 {
85  return compare( aOther ) == 0;
86 }
87 
88 
89 bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
90 {
91  return ( compare( aOther ) < 0 );
92 }
93 
94 
95 bool LIB_ITEM::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
96 {
98  return false;
99 
100  EDA_RECT sel = aRect;
101 
102  if ( aAccuracy )
103  sel.Inflate( aAccuracy );
104 
105  if( aContained )
106  return sel.Contains( GetBoundingBox() );
107 
108  return sel.Intersects( GetBoundingBox() );
109 }
110 
111 
112 void LIB_ITEM::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset,
113  void* aData, const TRANSFORM& aTransform )
114 {
115  print( aSettings, aOffset, aData, aTransform );
116 }
117 
118 
119 void LIB_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
120 {
121  // Basic fallback
122  aCount = 3;
123  aLayers[0] = LAYER_DEVICE;
124  aLayers[1] = LAYER_DEVICE_BACKGROUND;
125  aLayers[2] = LAYER_SELECTION_SHADOWS;
126 }
127 
128 
const EDA_RECT GetBoundingBox() const override
Definition: lib_item.h:175
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:481
The base class for create windows for drawing purpose.
Define a library symbol object.
Definition: lib_symbol.h:96
bool Contains(const wxPoint &aPoint) const
Definition: eda_rect.cpp:57
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
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:119
virtual wxString GetTypeName() const =0
Provide a user-consumable name of the object type.
LIB_ITEM(KICAD_T aType, LIB_SYMBOL *aSymbol=nullptr, int aUnit=0, int aConvert=0)
Definition: lib_item.cpp:35
int m_unit
Unit identification for multiple parts per package.
Definition: lib_item.h:310
bool operator==(const LIB_ITEM &aOther) const
Test LIB_ITEM objects for equivalence.
Definition: lib_item.cpp:83
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
COMPARE_FLAGS
The list of flags used by the compare function.
Definition: lib_item.h:80
int m_convert
Shape identification for alternate body styles.
Definition: lib_item.h:316
bool operator<(const LIB_ITEM &aOther) const
Test if another draw item is less than this draw object.
Definition: lib_item.cpp:89
const int fill_tab[3]
Definition: lib_item.cpp:32
#define STRUCT_DELETED
flag indication structures to be erased
#define _(s)
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:43
#define SKIP_STRUCT
flag indicating that the structure should be ignored
virtual void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform)
Draw an item.
Definition: lib_item.cpp:112
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is contained within or on the bounding box of an item.
Definition: lib_item.h:163
Handle the component boundary box.
Definition: eda_rect.h:42
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
bool Intersects(const EDA_RECT &aRect) const
Test for a common area between rectangles.
Definition: eda_rect.cpp:150
Message panel definition file.
virtual int compare(const LIB_ITEM &aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags=LIB_ITEM::COMPARE_FLAGS::NORMAL) const
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_item.cpp:67
virtual void print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform)=0
Print the item to aDC.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:364
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113