KiCad PCB EDA Suite
lib_draw_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-2015 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 
30 #include <fctsys.h>
31 #include <gr_basic.h>
32 #include <sch_draw_panel.h>
33 #include <msgpanel.h>
34 
35 #include <general.h>
36 #include <lib_draw_item.h>
37 
38 const int fill_tab[3] = { 'N', 'F', 'f' };
39 
40 
42  LIB_PART* aComponent,
43  int aUnit,
44  int aConvert,
45  FILL_T aFillType ) :
46  EDA_ITEM( aType )
47 {
48  m_Unit = aUnit;
49  m_Convert = aConvert;
50  m_Fill = aFillType;
51  m_Parent = (EDA_ITEM*) aComponent;
52  m_isFillable = false;
53 }
54 
55 
57 {
58  wxString msg;
59 
60  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), GetTypeName(), CYAN ) );
61 
62  if( m_Unit == 0 )
63  msg = _( "All" );
64  else
65  msg.Printf( wxT( "%d" ), m_Unit );
66 
67  aList.push_back( MSG_PANEL_ITEM( _( "Unit" ), msg, BROWN ) );
68 
69  if( m_Convert == LIB_ITEM::LIB_CONVERT::BASE )
70  msg = _( "no" );
71  else if( m_Convert == LIB_ITEM::LIB_CONVERT::DEMORGAN )
72  msg = _( "yes" );
73  else
74  msg = wxT( "?" );
75 
76  aList.push_back( MSG_PANEL_ITEM( _( "Converted" ), msg, BROWN ) );
77 }
78 
79 
80 bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
81 {
82  return ( ( Type() == aOther.Type() )
83  && ( m_Unit == aOther.m_Unit )
84  && ( m_Convert == aOther.m_Convert )
85  && compare( aOther ) == 0 );
86 }
87 
88 
89 bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
90 {
91  int result = m_Convert - aOther.m_Convert;
92 
93  if( result != 0 )
94  return result < 0;
95 
96  result = m_Unit - aOther.m_Unit;
97 
98  if( result != 0 )
99  return result < 0;
100 
101  result = Type() - aOther.Type();
102 
103  if( result != 0 )
104  return result < 0;
105 
106  return ( compare( aOther ) < 0 );
107 }
108 
109 
110 bool LIB_ITEM::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
111 {
112  if( m_Flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
113  return false;
114 
115  EDA_RECT sel = aRect;
116 
117  if ( aAccuracy )
118  sel.Inflate( aAccuracy );
119 
120  if( aContained )
121  return sel.Contains( GetBoundingBox() );
122 
123  return sel.Intersects( GetBoundingBox() );
124 }
125 
126 
127 void LIB_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void* aData,
128  const TRANSFORM& aTransform )
129 {
130  drawGraphic( aPanel, aDC, aOffset, aData, aTransform );
131 }
132 
133 
134 void LIB_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
135 {
136  // Basic fallback
137  aCount = 2;
138  aLayers[0] = LAYER_DEVICE;
139  aLayers[1] = LAYER_DEVICE_BACKGROUND;
140 }
141 
142 
144 {
145  return GetLayerColor( LAYER_DEVICE );
146 }
const EDA_RECT GetBoundingBox() const override
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.
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:174
virtual COLOR4D GetDefaultColor()
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: base_struct.h:125
int m_Unit
Unit identification for multiple parts per package.
Definition: lib_draw_item.h:89
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:174
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_draw_item.h:67
void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
bool operator==(const LIB_ITEM &aOther) const
Test LIB_ITEM objects for equivalence.
Class for tranforming 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: colors.h:59
bool m_isFillable
Flag to indicate if draw item is fillable.
Define a library symbol object.
#define STRUCT_DELETED
flag indication structures to be erased
Definition: base_struct.h:123
const int fill_tab[3]
FILL_T m_Fill
The body fill type.
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.
STATUS_FLAGS m_Flags
Flag bits for editing and other uses.
Definition: base_struct.h:181
virtual wxString GetTypeName()=0
Provide a user-consumable name of the object type.
virtual void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform)
Draw an item.
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:157
virtual void drawGraphic(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform)=0
Draw the item on aPanel.
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_draw_item.h:96
FILL_T
Enum FILL_T is the set of fill types used in plotting or drawing enclosed areas.
Definition: base_struct.h:54
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)
Message panel definition file.
EDA_UNITS_T
Definition: common.h:157
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:204
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
Definition: colors.h:62