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-2019 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 
29 #include <general.h>
30 #include <lib_item.h>
31 
32 const int fill_tab[3] = { 'N', 'F', 'f' };
33 
34 
36  LIB_SYMBOL* aSymbol,
37  int aUnit,
38  int aConvert,
39  FILL_TYPE aFillType ) :
40  EDA_ITEM( aType )
41 {
42  m_unit = aUnit;
43  m_convert = aConvert;
44  m_fill = aFillType;
45  m_parent = (EDA_ITEM*) aSymbol;
46  m_isFillable = false;
47 }
48 
49 
51 {
52  wxString msg;
53 
54  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), GetTypeName() ) );
55 
56  if( m_unit == 0 )
57  msg = _( "All" );
58  else
59  msg.Printf( wxT( "%d" ), m_unit );
60 
61  aList.push_back( MSG_PANEL_ITEM( _( "Unit" ), msg ) );
62 
63  if( m_convert == LIB_ITEM::LIB_CONVERT::BASE )
64  msg = _( "no" );
65  else if( m_convert == LIB_ITEM::LIB_CONVERT::DEMORGAN )
66  msg = _( "yes" );
67  else
68  msg = wxT( "?" );
69 
70  aList.push_back( MSG_PANEL_ITEM( _( "Converted" ), msg ) );
71 }
72 
73 
74 int LIB_ITEM::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS 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( m_fill != aOther.m_fill )
87  return static_cast<int>( m_fill ) - static_cast<int>( aOther.m_fill );
88 
89  return 0;
90 }
91 
92 
93 bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
94 {
95  return compare( aOther ) == 0;
96 }
97 
98 
99 bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
100 {
101  return ( compare( aOther ) < 0 );
102 }
103 
104 
105 bool LIB_ITEM::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
106 {
107  if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
108  return false;
109 
110  EDA_RECT sel = aRect;
111 
112  if ( aAccuracy )
113  sel.Inflate( aAccuracy );
114 
115  if( aContained )
116  return sel.Contains( GetBoundingBox() );
117 
118  return sel.Intersects( GetBoundingBox() );
119 }
120 
121 
122 void LIB_ITEM::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset,
123  void* aData, const TRANSFORM& aTransform )
124 {
125  print( aSettings, aOffset, aData, aTransform );
126 }
127 
128 
129 void LIB_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
130 {
131  // Basic fallback
132  aCount = 3;
133  aLayers[0] = LAYER_DEVICE;
134  aLayers[1] = LAYER_DEVICE_BACKGROUND;
135  aLayers[2] = LAYER_SELECTION_SHADOWS;
136 }
137 
138 
const EDA_RECT GetBoundingBox() const override
Definition: lib_item.h:165
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:479
FILL_TYPE
The set of fill types used in plotting or drawing enclosed areas.
Definition: fill_type.h:28
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
FILL_TYPE m_fill
The body fill type.
Definition: lib_item.h:326
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:129
virtual wxString GetTypeName() const =0
Provide a user-consumable name of the object type.
int m_unit
Unit identification for multiple parts per package.
Definition: lib_item.h:314
bool operator==(const LIB_ITEM &aOther) const
Test LIB_ITEM objects for equivalence.
Definition: lib_item.cpp:93
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:81
int m_convert
Shape identification for alternate body styles.
Definition: lib_item.h:320
bool operator<(const LIB_ITEM &aOther) const
Test if another draw item is less than this draw object.
Definition: lib_item.cpp:99
const int fill_tab[3]
Definition: lib_item.cpp:32
bool m_isFillable
Definition: lib_item.h:327
#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:50
LIB_ITEM(KICAD_T aType, LIB_SYMBOL *aSymbol=nullptr, int aUnit=0, int aConvert=0, FILL_TYPE aFillType=FILL_TYPE::NO_FILL)
Definition: lib_item.cpp:35
#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:122
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:153
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
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:97
bool Intersects(const EDA_RECT &aRect) const
Test for a common area between rectangles.
Definition: eda_rect.cpp:150
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:53
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:74
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