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 <class_drawpanel.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  m_eraseLastDrawItem = false;
56 }
57 
58 
60 {
61  wxString msg;
62 
63  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), GetTypeName(), CYAN ) );
64 
65  if( m_Unit == 0 )
66  msg = _( "All" );
67  else
68  msg.Printf( wxT( "%d" ), m_Unit );
69 
70  aList.push_back( MSG_PANEL_ITEM( _( "Unit" ), msg, BROWN ) );
71 
72  if( m_Convert == 0 )
73  msg = _( "All" );
74  else if( m_Convert == 1 )
75  msg = _( "no" );
76  else if( m_Convert == 2 )
77  msg = _( "yes" );
78  else
79  msg = wxT( "?" );
80 
81  aList.push_back( MSG_PANEL_ITEM( _( "Converted" ), msg, BROWN ) );
82 }
83 
84 
85 bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
86 {
87  return ( ( Type() == aOther.Type() )
88  && ( m_Unit == aOther.m_Unit )
89  && ( m_Convert == aOther.m_Convert )
90  && compare( aOther ) == 0 );
91 }
92 
93 
94 bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
95 {
96  int result = m_Convert - aOther.m_Convert;
97 
98  if( result != 0 )
99  return result < 0;
100 
101  result = m_Unit - aOther.m_Unit;
102 
103  if( result != 0 )
104  return result < 0;
105 
106  result = Type() - aOther.Type();
107 
108  if( result != 0 )
109  return result < 0;
110 
111  return ( compare( aOther ) < 0 );
112 }
113 
114 
115 void LIB_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
116  const wxPoint& aOffset, COLOR4D aColor,
117  GR_DRAWMODE aDrawMode, void* aData,
118  const TRANSFORM& aTransform )
119 {
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  {
150  drawGraphic( aPanel, aDC, aOffset, aColor, aDrawMode, aData, aTransform );
151  }
152 }
153 
154 
156 {
157  return GetLayerColor( LAYER_DEVICE );
158 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:73
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:179
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:318
virtual COLOR4D GetDefaultColor()
bool m_eraseLastDrawItem
Used when editing a new draw item to prevent drawing artifacts.
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 void calcEdit(const wxPoint &aPosition)
Calculates the attributes of an item at aPosition when it is being edited.
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:167
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:66
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:93
Definition: colors.h:59
bool m_isFillable
Flag to indicate if draw item is fillable.
Define a library symbol object.
EDA_RECT * GetClipBox()
bool operator<(const LIB_ITEM &aOther) const
Test if another draw item is less than this draw object.
virtual void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
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:162
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:52
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.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
Definition: colors.h:62