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 //#define DRAW_ARC_WITH_ANGLE // Used to draw arcs
41 
42 
44  LIB_PART* aComponent,
45  int aUnit,
46  int aConvert,
47  FILL_T aFillType ) :
48  EDA_ITEM( aType )
49 {
50  m_Unit = aUnit;
51  m_Convert = aConvert;
52  m_Fill = aFillType;
53  m_Parent = (EDA_ITEM*) aComponent;
54  m_isFillable = false;
55 }
56 
57 
59 {
60  wxString msg;
61 
62  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), GetTypeName(), CYAN ) );
63 
64  if( m_Unit == 0 )
65  msg = _( "All" );
66  else
67  msg.Printf( wxT( "%d" ), m_Unit );
68 
69  aList.push_back( MSG_PANEL_ITEM( _( "Unit" ), msg, BROWN ) );
70 
71  if( m_Convert == 0 )
72  msg = _( "All" );
73  else if( m_Convert == 1 )
74  msg = _( "no" );
75  else if( m_Convert == 2 )
76  msg = _( "yes" );
77  else
78  msg = wxT( "?" );
79 
80  aList.push_back( MSG_PANEL_ITEM( _( "Converted" ), msg, BROWN ) );
81 }
82 
83 
84 bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
85 {
86  return ( ( Type() == aOther.Type() )
87  && ( m_Unit == aOther.m_Unit )
88  && ( m_Convert == aOther.m_Convert )
89  && compare( aOther ) == 0 );
90 }
91 
92 
93 bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
94 {
95  int result = m_Convert - aOther.m_Convert;
96 
97  if( result != 0 )
98  return result < 0;
99 
100  result = m_Unit - aOther.m_Unit;
101 
102  if( result != 0 )
103  return result < 0;
104 
105  result = Type() - aOther.Type();
106 
107  if( result != 0 )
108  return result < 0;
109 
110  return ( compare( aOther ) < 0 );
111 }
112 
113 
114 void LIB_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
115  const wxPoint& aOffset, COLOR4D aColor,
116  GR_DRAWMODE aDrawMode, void* aData,
117  const TRANSFORM& aTransform )
118 {
119  #if 0
120  if( InEditMode() )
121  {
122  // Temporarily disable filling while the item is being edited.
123  FILL_T fillMode = m_Fill;
125 
126  m_Fill = NO_FILL;
127 
128 #ifndef USE_WX_OVERLAY
129  // Erase the old items using the previous attributes.
130  if( m_eraseLastDrawItem )
131  {
132  GRSetDrawMode( aDC, g_XorMode );
133  drawEditGraphics( aPanel->GetClipBox(), aDC, color );
134  drawGraphic( aPanel, aDC, wxPoint( 0, 0 ), color, g_XorMode, aData,
135  aTransform );
136  }
137 #endif
138  // Calculate the new attributes at the current cursor position.
139  CalcEdit( aOffset );
140 
141  // Draw the items using the new attributes.
142  drawEditGraphics( aPanel->GetClipBox(), aDC, color );
143  drawGraphic( aPanel, aDC, wxPoint( 0, 0 ), color, g_XorMode, aData,
144  aTransform );
145 
146  m_Fill = fillMode;
147  }
148  else
149  #endif
150  {
151  drawGraphic( aPanel, aDC, aOffset, aColor, aDrawMode, aData, aTransform );
152  }
153 }
154 
155 
156 void LIB_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
157 {
158  // Basic fallback
159  aCount = 2;
160  aLayers[0] = LAYER_DEVICE;
161  aLayers[1] = LAYER_DEVICE_BACKGROUND;
162 }
163 
164 
166 {
167  return GetLayerColor( LAYER_DEVICE );
168 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:74
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
virtual 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:171
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:223
virtual COLOR4D GetDefaultColor()
int color
Definition: DXF_plotter.cpp:62
bool InEditMode() const
Return the draw item editing mode status.
int m_Unit
Unit identification for multiple parts per package.
virtual EDA_RECT * GetClipBox()
virtual int compare(const LIB_ITEM &aOther) const =0
Provide the draw object specific comparison called by the == and < operators.
virtual void CalcEdit(const wxPoint &aPosition)
Calculates the attributes of an item at aPosition when it is being edited.
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:174
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...
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
virtual void drawEditGraphics(EDA_RECT *aClipBox, wxDC *aDC, COLOR4D aColor)
Draw any editing specific graphics when the item is being edited.
Definition: lib_draw_item.h:94
Definition: colors.h:59
bool m_isFillable
Flag to indicate if draw item is fillable.
Define a library symbol object.
bool operator<(const LIB_ITEM &aOther) const
Test if another draw item is less than this draw object.
const int fill_tab[3]
virtual void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, void *aData, const TRANSFORM &aTransform)
Draw an item.
virtual void drawGraphic(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, void *aData, const TRANSFORM &aTransform)=0
Draw the item on aPanel.
FILL_T m_Fill
The body fill type.
virtual wxString GetTypeName()=0
Provide a user-consumable name of the object type.
bool operator==(const LIB_ITEM &aOther) const
Test LIB_ITEM objects for equivalence.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
int m_Convert
Shape identification for alternate body styles.
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:159
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
Definition: colors.h:62