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 bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
77 {
78  return ( ( Type() == aOther.Type() )
79  && ( m_Unit == aOther.m_Unit )
80  && ( m_Convert == aOther.m_Convert )
81  && compare( aOther ) == 0 );
82 }
83 
84 
85 bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
86 {
87  int result = m_Convert - aOther.m_Convert;
88 
89  if( result != 0 )
90  return result < 0;
91 
92  result = m_Unit - aOther.m_Unit;
93 
94  if( result != 0 )
95  return result < 0;
96 
97  result = Type() - aOther.Type();
98 
99  if( result != 0 )
100  return result < 0;
101 
102  return ( compare( aOther ) < 0 );
103 }
104 
105 
106 bool LIB_ITEM::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
107 {
108  if( m_Flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
109  return false;
110 
111  EDA_RECT sel = aRect;
112 
113  if ( aAccuracy )
114  sel.Inflate( aAccuracy );
115 
116  if( aContained )
117  return sel.Contains( GetBoundingBox() );
118 
119  return sel.Intersects( GetBoundingBox() );
120 }
121 
122 
123 void LIB_ITEM::Print( wxDC* aDC, const wxPoint& aOffset, void* aData, const TRANSFORM& aTransform )
124 {
125  print( aDC, 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 
140 {
141  return GetLayerColor( LAYER_DEVICE );
142 }
const EDA_RECT GetBoundingBox() const override
Definition: lib_item.h:196
void GetMsgPanelInfo(EDA_UNITS_T aUnits, 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
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:180
virtual COLOR4D GetDefaultColor()
Definition: lib_item.cpp:139
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: base_struct.h:131
int m_Unit
Unit identification for multiple parts per package.
Definition: lib_item.h:82
virtual int compare(const LIB_ITEM &aOther) const =0
Provide the draw object specific comparison called by the == and < operators.
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:160
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:129
virtual void print(wxDC *aDC, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform)=0
Print the item to aDC.
bool operator==(const LIB_ITEM &aOther) const
Test LIB_ITEM objects for equivalence.
Definition: lib_item.cpp:76
Class for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
bool operator<(const LIB_ITEM &aOther) const
Test if another draw item is less than this draw object.
Definition: lib_item.cpp:85
Definition: colors.h:59
const int fill_tab[3]
Definition: lib_item.cpp:34
bool m_isFillable
Definition: lib_item.h:95
Define a library symbol object.
#define STRUCT_DELETED
flag indication structures to be erased
Definition: base_struct.h:129
#define _(s)
FILL_T m_Fill
The body fill type.
Definition: lib_item.h:94
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:184
STATUS_FLAGS m_Flags
Flag bits for editing and other uses.
Definition: base_struct.h:187
virtual wxString GetTypeName()=0
Provide a user-consumable name of the object type.
virtual void Print(wxDC *aDC, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform)
Draw an item.
Definition: lib_item.cpp:123
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
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:88
FILL_T
Enum FILL_T is the set of fill types used in plotting or drawing enclosed areas.
Definition: base_struct.h:42
Class 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.
EDA_UNITS_T
Definition: common.h:133
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:210
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
Definition: colors.h:62