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 <wxstruct.h>
34 #include <msgpanel.h>
35 
36 #include <general.h>
37 #include <lib_draw_item.h>
38 
39 const int fill_tab[3] = { 'N', 'F', 'f' };
40 
41 //#define DRAW_ARC_WITH_ANGLE // Used to draw arcs
42 
43 
45  LIB_PART* aComponent,
46  int aUnit,
47  int aConvert,
48  FILL_T aFillType ) :
49  EDA_ITEM( aType )
50 {
51  m_Unit = aUnit;
52  m_Convert = aConvert;
53  m_Fill = aFillType;
54  m_Parent = (EDA_ITEM*) aComponent;
55  m_typeName = _( "Undefined" );
56  m_isFillable = false;
57  m_eraseLastDrawItem = false;
58 }
59 
60 
62 {
63  wxString msg;
64 
65  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), m_typeName, CYAN ) );
66 
67  if( m_Unit == 0 )
68  msg = _( "All" );
69  else
70  msg.Printf( wxT( "%d" ), m_Unit );
71 
72  aList.push_back( MSG_PANEL_ITEM( _( "Unit" ), msg, BROWN ) );
73 
74  if( m_Convert == 0 )
75  msg = _( "All" );
76  else if( m_Convert == 1 )
77  msg = _( "no" );
78  else if( m_Convert == 2 )
79  msg = _( "yes" );
80  else
81  msg = wxT( "?" );
82 
83  aList.push_back( MSG_PANEL_ITEM( _( "Converted" ), msg, BROWN ) );
84 }
85 
86 
87 bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
88 {
89  return ( ( Type() == aOther.Type() )
90  && ( m_Unit == aOther.m_Unit )
91  && ( m_Convert == aOther.m_Convert )
92  && compare( aOther ) == 0 );
93 }
94 
95 
96 bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
97 {
98  int result = m_Convert - aOther.m_Convert;
99 
100  if( result != 0 )
101  return result < 0;
102 
103  result = m_Unit - aOther.m_Unit;
104 
105  if( result != 0 )
106  return result < 0;
107 
108  result = Type() - aOther.Type();
109 
110  if( result != 0 )
111  return result < 0;
112 
113  return ( compare( aOther ) < 0 );
114 }
115 
116 
117 void LIB_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
118  const wxPoint& aOffset, COLOR4D aColor,
119  GR_DRAWMODE aDrawMode, void* aData,
120  const TRANSFORM& aTransform )
121 {
122  if( InEditMode() )
123  {
124  // Temporarily disable filling while the item is being edited.
125  FILL_T fillMode = m_Fill;
127 
128  m_Fill = NO_FILL;
129 
130 #ifndef USE_WX_OVERLAY
131  // Erase the old items using the previous attributes.
132  if( m_eraseLastDrawItem )
133  {
134  GRSetDrawMode( aDC, g_XorMode );
135  drawEditGraphics( aPanel->GetClipBox(), aDC, color );
136  drawGraphic( aPanel, aDC, wxPoint( 0, 0 ), color, g_XorMode, aData,
137  aTransform );
138  }
139 #endif
140  // Calculate the new attributes at the current cursor position.
141  calcEdit( aOffset );
142 
143  // Draw the items using the new attributes.
144  drawEditGraphics( aPanel->GetClipBox(), aDC, color );
145  drawGraphic( aPanel, aDC, wxPoint( 0, 0 ), color, g_XorMode, aData,
146  aTransform );
147 
148  m_Fill = fillMode;
149  }
150  else
151  {
152  drawGraphic( aPanel, aDC, aOffset, aColor, aDrawMode, aData, aTransform );
153  }
154 }
155 
156 
158 {
159  return GetLayerColor( LAYER_DEVICE );
160 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:51
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:182
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:290
wxString m_typeName
Name of object displayed in the message panel.
virtual COLOR4D GetDefaultColor()
bool m_eraseLastDrawItem
Used when editing a new draw item to prevent drawing artifacts.
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
Function compare provides 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:90
Class LIB_ITEM is the base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
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:41
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:96
Base window classes and related definitions.
Definition: colors.h:59
bool m_isFillable
Flag to indicate if draw item is fillable.
Class LIB_PART defines a library part 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
Function GetMsgPanelInfo displays basic info (type, part and convert) about the current item in messa...
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
Function drawGraphic.
FILL_T m_Fill
The body fill 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:165
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:70
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