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 <fctsys.h>
27 #include <gr_basic.h>
28 #include <sch_draw_panel.h>
29 #include <msgpanel.h>
30 
31 #include <general.h>
32 #include <lib_item.h>
33 
34 const int fill_tab[3] = { 'N', 'F', 'f' };
35 
36 
38  LIB_PART* aComponent,
39  int aUnit,
40  int aConvert,
41  FILL_T aFillType ) :
42  EDA_ITEM( aType )
43 {
44  m_Unit = aUnit;
45  m_Convert = aConvert;
46  m_Fill = aFillType;
47  m_Parent = (EDA_ITEM*) aComponent;
48  m_isFillable = false;
49 }
50 
51 
53 {
54  wxString msg;
55 
56  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), GetTypeName(), CYAN ) );
57 
58  if( m_Unit == 0 )
59  msg = _( "All" );
60  else
61  msg.Printf( wxT( "%d" ), m_Unit );
62 
63  aList.push_back( MSG_PANEL_ITEM( _( "Unit" ), msg, BROWN ) );
64 
65  if( m_Convert == LIB_ITEM::LIB_CONVERT::BASE )
66  msg = _( "no" );
67  else if( m_Convert == LIB_ITEM::LIB_CONVERT::DEMORGAN )
68  msg = _( "yes" );
69  else
70  msg = wxT( "?" );
71 
72  aList.push_back( MSG_PANEL_ITEM( _( "Converted" ), msg, BROWN ) );
73 }
74 
75 
76 int LIB_ITEM::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
77 {
78  if( Type() != aOther.Type() )
79  return Type() - aOther.Type();
80 
81  // When comparing unit LIB_ITEM objects, we ignore the unit number.
82  if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_Unit != aOther.m_Unit )
83  return m_Unit - aOther.m_Unit;
84 
85  if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_Convert != aOther.m_Convert )
86  return m_Convert - m_Convert;
87 
88  if( m_Fill != aOther.m_Fill )
89  return m_Fill - aOther.m_Fill;
90 
91  return 0;
92 }
93 
94 
95 bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
96 {
97  return compare( aOther ) == 0;
98 }
99 
100 
101 bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
102 {
103  int result = m_Convert - aOther.m_Convert;
104 
105  if( result != 0 )
106  return result < 0;
107 
108  result = m_Unit - aOther.m_Unit;
109 
110  if( result != 0 )
111  return result < 0;
112 
113  result = Type() - aOther.Type();
114 
115  if( result != 0 )
116  return result < 0;
117 
118  return ( compare( aOther ) < 0 );
119 }
120 
121 
122 bool LIB_ITEM::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
123 {
124  if( m_Flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
125  return false;
126 
127  EDA_RECT sel = aRect;
128 
129  if ( aAccuracy )
130  sel.Inflate( aAccuracy );
131 
132  if( aContained )
133  return sel.Contains( GetBoundingBox() );
134 
135  return sel.Intersects( GetBoundingBox() );
136 }
137 
138 
139 void LIB_ITEM::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
140  const TRANSFORM& aTransform )
141 {
142  print( aSettings, aOffset, aData, aTransform );
143 }
144 
145 
146 void LIB_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
147 {
148  // Basic fallback
149  aCount = 3;
150  aLayers[0] = LAYER_DEVICE;
151  aLayers[1] = LAYER_DEVICE_BACKGROUND;
152  aLayers[2] = LAYER_SELECTION_SHADOWS;
153 }
154 
155 
const EDA_RECT GetBoundingBox() const override
Definition: lib_item.h:201
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:174
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.
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: base_struct.h:128
Definition: color4d.h:61
int m_Unit
Unit identification for multiple parts per package.
Definition: lib_item.h:81
The base class for create windows for drawing purpose.
bool Contains(const wxPoint &aPoint) const
Function Contains.
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:61
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:146
virtual void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform)
Draw an item.
Definition: lib_item.cpp:139
bool operator==(const LIB_ITEM &aOther) const
Test LIB_ITEM objects for equivalence.
Definition: lib_item.cpp:95
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:116
bool operator<(const LIB_ITEM &aOther) const
Test if another draw item is less than this draw object.
Definition: lib_item.cpp:101
const int fill_tab[3]
Definition: lib_item.cpp:34
bool m_isFillable
Definition: lib_item.h:94
Define a library symbol object.
#define STRUCT_DELETED
flag indication structures to be erased
Definition: base_struct.h:126
Definition: color4d.h:58
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:52
#define _(s)
Definition: 3d_actions.cpp:33
FILL_T m_Fill
The body fill type.
Definition: lib_item.h:93
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:189
STATUS_FLAGS m_Flags
Definition: base_struct.h:176
virtual wxString GetTypeName()=0
Provide a user-consumable name of the object type.
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: base_struct.h:159
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
int m_Convert
Shape identification for alternate body styles.
Definition: lib_item.h:87
FILL_T
Enum FILL_T is the set of fill types used in plotting or drawing enclosed areas.
Definition: base_struct.h:42
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
LIB_ITEM(KICAD_T aType, LIB_PART *aComponent=NULL, int aUnit=0, int aConvert=0, FILL_T aFillType=NO_FILL)
Definition: lib_item.cpp:37
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:76
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193