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_PART* aComponent,
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*) aComponent;
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 - 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  int result = m_Convert - aOther.m_Convert;
102 
103  if( result != 0 )
104  return result < 0;
105 
106  result = m_Unit - aOther.m_Unit;
107 
108  if( result != 0 )
109  return result < 0;
110 
111  result = Type() - aOther.Type();
112 
113  if( result != 0 )
114  return result < 0;
115 
116  return ( compare( aOther ) < 0 );
117 }
118 
119 
120 bool LIB_ITEM::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
121 {
122  if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
123  return false;
124 
125  EDA_RECT sel = aRect;
126 
127  if ( aAccuracy )
128  sel.Inflate( aAccuracy );
129 
130  if( aContained )
131  return sel.Contains( GetBoundingBox() );
132 
133  return sel.Intersects( GetBoundingBox() );
134 }
135 
136 
137 void LIB_ITEM::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
138  const TRANSFORM& aTransform )
139 {
140  print( aSettings, aOffset, aData, aTransform );
141 }
142 
143 
144 void LIB_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
145 {
146  // Basic fallback
147  aCount = 3;
148  aLayers[0] = LAYER_DEVICE;
149  aLayers[1] = LAYER_DEVICE_BACKGROUND;
150  aLayers[2] = LAYER_SELECTION_SHADOWS;
151 }
152 
153 
const EDA_RECT GetBoundingBox() const override
Definition: lib_item.h:202
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:162
FILL_TYPE
Enum class FILL_TYPE is the set of fill types used in plotting or drawing enclosed areas.
Definition: fill_type.h:29
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
virtual void print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform)=0
Print the item to aDC.
int m_Unit
Unit identification for multiple parts per package.
Definition: lib_item.h:82
The base class for create windows for drawing purpose.
bool Contains(const wxPoint &aPoint) const
Function Contains.
Definition: eda_rect.cpp:57
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
The base class for drawable items used by schematic library components.
Definition: lib_item.h:62
void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
Definition: lib_item.cpp:144
virtual void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform)
Draw an item.
Definition: lib_item.cpp:137
FILL_TYPE m_Fill
The body fill type.
Definition: lib_item.h:94
virtual wxString GetTypeName() const =0
Provide a user-consumable name of the object type.
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:117
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:95
Define a library symbol object.
#define STRUCT_DELETED
flag indication structures to be erased
Definition: eda_item.h:115
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
#define _(s)
Definition: 3d_actions.cpp:33
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: lib_item.h:190
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:97
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
Definition: eda_rect.cpp:150
int m_Convert
Shape identification for alternate body styles.
Definition: lib_item.h:88
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:54
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: eda_item.h:117
STATUS_FLAGS m_flags
Definition: eda_item.h:164
LIB_ITEM(KICAD_T aType, LIB_PART *aComponent=NULL, int aUnit=0, int aConvert=0, FILL_TYPE aFillType=FILL_TYPE::NO_FILL)
Definition: lib_item.cpp:35
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
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:363
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181