KiCad PCB EDA Suite
hotkeys_footprint_editor.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) 2010-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
29 #include <fctsys.h>
30 #include <pcbnew.h>
31 #include <footprint_edit_frame.h>
32 #include <pcbnew_id.h>
33 #include <class_drawpanel.h>
34 #include <confirm.h>
35 #include <board_design_settings.h>
36 #include <origin_viewitem.h>
37 #include <tools/pcbnew_control.h>
38 
39 #include <hotkeys.h>
40 
41 /* How to add a new hotkey:
42  * See hotkeys.cpp
43  */
44 
46 {
48 
49  if( HK_Descr == NULL )
50  HK_Descr = GetDescriptorFromCommand( aCommand, module_edit_Hotkey_List );
51 
52  return HK_Descr;
53 }
54 
55 
56 bool FOOTPRINT_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
57  EDA_ITEM* aItem )
58 {
59  if( aHotKey == 0 )
60  return false;
61 
62  bool blockActive = GetScreen()->m_BlockLocate.GetCommand() != BLOCK_IDLE;
63  BOARD_ITEM* item = GetCurItem();
64  bool ItemFree = (item == 0) || (item->GetFlags() == 0);
65  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
66  cmd.SetEventObject( this );
67 
68  /* Convert lower to upper case (the usual toupper function has problem with non ascii
69  * codes like function keys */
70  if( (aHotKey >= 'a') && (aHotKey <= 'z') )
71  aHotKey += 'A' - 'a';
72 
74 
75  if( HK_Descr == NULL )
76  HK_Descr = GetDescriptorFromHotkey( aHotKey, module_edit_Hotkey_List );
77 
78  if( HK_Descr == NULL )
79  return false;
80 
81  switch( HK_Descr->m_Idcommand )
82  {
83  default:
84  case HK_NOT_FOUND:
85  return false;
86 
87  case HK_HELP: // Display Current hotkey list
89  break;
90 
91  case HK_RESET_LOCAL_COORD: // set local (relative) coordinate origin
93  break;
94 
95  case HK_LEFT_CLICK:
96  OnLeftClick( aDC, aPosition );
97  break;
98 
99  case HK_LEFT_DCLICK: // Simulate a double left click: generate 2 events
100  OnLeftClick( aDC, aPosition );
101  OnLeftDClick( aDC, aPosition );
102  break;
103 
104  case HK_SET_GRID_ORIGIN:
105  PCBNEW_CONTROL::SetGridOrigin( GetGalCanvas()->GetView(), this,
108  m_canvas->Refresh();
109  break;
110 
112  PCBNEW_CONTROL::SetGridOrigin( GetGalCanvas()->GetView(), this,
114  wxPoint( 0, 0 ) );
115  m_canvas->Refresh();
116  break;
117 
118  case HK_SWITCH_UNITS:
121  GetEventHandler()->ProcessEvent( cmd );
122  break;
123 
124  case HK_ZOOM_IN:
125  cmd.SetId( ID_KEY_ZOOM_IN );
126  GetEventHandler()->ProcessEvent( cmd );
127  break;
128 
129  case HK_ZOOM_OUT:
130  cmd.SetId( ID_KEY_ZOOM_OUT );
131  GetEventHandler()->ProcessEvent( cmd );
132  break;
133 
134  case HK_ZOOM_REDRAW:
135  cmd.SetId( ID_ZOOM_REDRAW );
136  GetEventHandler()->ProcessEvent( cmd );
137  break;
138 
139  case HK_ZOOM_CENTER:
140  cmd.SetId( ID_POPUP_ZOOM_CENTER );
141  GetEventHandler()->ProcessEvent( cmd );
142  break;
143 
144  case HK_ZOOM_SELECTION:
145  cmd.SetId( ID_ZOOM_SELECTION );
146  GetEventHandler()->ProcessEvent( cmd );
147  break;
148 
149  case HK_UNDO:
150  case HK_REDO:
151  if( ItemFree && !blockActive )
152  {
153  wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, HK_Descr->m_IdMenuEvent );
154  wxPostEvent( this, event );
155  }
156  break;
157 
158  case HK_ZOOM_AUTO:
159  cmd.SetId( ID_ZOOM_PAGE );
160  GetEventHandler()->ProcessEvent( cmd );
161  break;
162 
163  case HK_EDIT_ITEM:
165  break;
166 
167  case HK_DELETE:
169  break;
170 
171  case HK_MOVE_ITEM:
173  break;
174 
175  case HK_MOVE_ITEM_EXACT:
176  if( blockActive )
177  {
178  cmd.SetId( ID_POPUP_MOVE_BLOCK_EXACT );
179  GetEventHandler()->ProcessEvent( cmd );
180  }
181  else
182  {
184  }
185  break;
186 
187  case HK_ROTATE_ITEM:
189  break;
190 
191  case HK_DUPLICATE_ITEM:
193  OnHotkeyDuplicateItem( HK_Descr->m_Idcommand );
194  break;
195 
196  case HK_CREATE_ARRAY:
198  }
199 
200  return true;
201 }
202 
203 
205 {
206  BOARD_ITEM* item = GetCurItem();
207  bool itemCurrentlyEdited = item && item->GetFlags();
208  bool blockActive = GetScreen()->m_BlockLocate.GetCommand() != BLOCK_IDLE;
209 
210  if( aFailIfCurrentlyEdited )
211  {
212  if( itemCurrentlyEdited || blockActive )
213  return NULL;
214 
215  item = ModeditLocateAndDisplay();
216  }
217  else
218  {
219  if( blockActive )
220  return NULL;
221 
222  if( !itemCurrentlyEdited )
223  item = ModeditLocateAndDisplay();
224  }
225 
226  // set item if we can, but don't clear if not
227  if( item )
228  SetCurItem( item );
229 
230  return item;
231 }
232 
233 
235 {
236  BOARD_ITEM* item = PrepareItemForHotkey( true );
237 
238  if( item == NULL )
239  return false;
240 
241  int evt_type = 0; // Used to post a wxCommandEvent on demand
242 
243  switch( item->Type() )
244  {
245  case PCB_MODULE_T:
246  if( aIdCommand == HK_EDIT_ITEM )
248 
249  break;
250 
251  case PCB_PAD_T:
252  if( aIdCommand == HK_EDIT_ITEM )
253  evt_type = ID_POPUP_PCB_EDIT_PAD;
254 
255  break;
256 
257  case PCB_MODULE_TEXT_T:
258  if( aIdCommand == HK_EDIT_ITEM )
259  evt_type = ID_POPUP_PCB_EDIT_TEXTMODULE;
260 
261  break;
262 
263  case PCB_MODULE_EDGE_T:
264  if( aIdCommand == HK_EDIT_ITEM )
266 
267  break;
268 
269  default:
270  break;
271  }
272 
273  return PostCommandMenuEvent( evt_type );
274 }
275 
276 
278 {
279  BOARD_ITEM* item = PrepareItemForHotkey( true );
280 
281  if( item == NULL )
282  return false;
283 
284  int evt_type = 0; // Used to post a wxCommandEvent on demand
285 
286  switch( item->Type() )
287  {
288  case PCB_PAD_T:
289  if( aIdCommand == HK_DELETE )
290  evt_type = ID_POPUP_PCB_DELETE_PAD;
291 
292  break;
293 
294  case PCB_MODULE_TEXT_T:
295  if( aIdCommand == HK_DELETE )
297 
298  break;
299 
300  case PCB_MODULE_EDGE_T:
301  if( aIdCommand == HK_DELETE )
302  evt_type = ID_POPUP_PCB_DELETE_EDGE;
303 
304  break;
305 
306  default:
307  break;
308  }
309 
310  return PostCommandMenuEvent( evt_type );
311 }
312 
313 
315 {
316  BOARD_ITEM* item = PrepareItemForHotkey( true );
317 
318  if( item == NULL )
319  return false;
320 
321  int evt_type = 0; // Used to post a wxCommandEvent on demand
322 
323  switch( item->Type() )
324  {
325  case PCB_PAD_T:
326  if( aIdCommand == HK_MOVE_ITEM )
328 
329  break;
330 
331  case PCB_MODULE_TEXT_T:
332  if( aIdCommand == HK_MOVE_ITEM )
334 
335  break;
336 
337  case PCB_MODULE_EDGE_T:
338  if( aIdCommand == HK_MOVE_ITEM )
339  evt_type = ID_POPUP_PCB_MOVE_EDGE;
340 
341  break;
342 
343  default:
344  break;
345  }
346 
347  return PostCommandMenuEvent( evt_type );
348 }
349 
350 
352 {
353  BOARD_ITEM* item = PrepareItemForHotkey( false );
354 
355  if( item == NULL )
356  return false;
357 
358  int evt_type = 0; // Used to post a wxCommandEvent on demand
359 
360  switch( item->Type() )
361  {
362  case PCB_PAD_T:
363  case PCB_MODULE_EDGE_T:
364  case PCB_MODULE_TEXT_T:
365  evt_type = ID_POPUP_PCB_MOVE_EXACT;
366  break;
367  default:
368  break;
369  }
370 
371  return PostCommandMenuEvent( evt_type );
372 }
373 
374 
376 {
377  BOARD_ITEM* item = PrepareItemForHotkey( true );
378 
379  if( item == NULL )
380  return false;
381 
382  int evt_type = 0; // Used to post a wxCommandEvent on demand
383 
384  switch( item->Type() )
385  {
386  case PCB_PAD_T:
387  case PCB_MODULE_EDGE_T:
388  case PCB_MODULE_TEXT_T:
389  if( aIdCommand == HK_DUPLICATE_ITEM )
390  evt_type = ID_POPUP_PCB_DUPLICATE_ITEM;
391  else
393 
394  break;
395 
396  default:
397  break;
398  }
399 
400  return PostCommandMenuEvent( evt_type );
401 }
402 
403 
405 {
406  BOARD_ITEM* item = PrepareItemForHotkey( false );
407 
408  if( item == NULL )
409  return false;
410 
411  int evt_type = 0; // Used to post a wxCommandEvent on demand
412 
413  switch( item->Type() )
414  {
415  case PCB_MODULE_TEXT_T:
416  if( aIdCommand == HK_ROTATE_ITEM ) // Rotation
418 
419  break;
420 
421  default:
422  break;
423  }
424 
425  return PostCommandMenuEvent( evt_type );
426 }
void OnLeftDClick(wxDC *DC, const wxPoint &MousePos) override
Handle the double click in the footprint editor.
BOARD_ITEM * ModeditLocateAndDisplay(int aHotKeyCode=0)
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:258
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Definition: base_screen.h:214
bool OnHotkeyRotateItem(int aIdCommand)
EDA_HOTKEY * GetHotKeyDescription(int aCommand) const override
>
This file is part of the common library.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
struct EDA_HOTKEY_CONFIG g_Module_Editor_Hotkeys_Descr[]
bool OnHotkeyDuplicateItem(int aIdCommand)
const wxPoint & GetGridOrigin() const override
Return the absolute coordinates of the origin of the snap grid.
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
bool OnHotkeyMoveItem(int aIdCommand)
Definition of class FOOTPRINT_EDIT_FRAME.
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:185
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
Pcbnew hotkeys.
EDA_HOTKEY * GetDescriptorFromHotkey(int aKey, EDA_HOTKEY **aList)
Function GetDescriptorFromHotkey Return a EDA_HOTKEY * pointer from a key code for OnHotKey() functio...
class MODULE, a footprint
Definition: typeinfo.h:89
void DisplayHotkeyList(EDA_BASE_FRAME *aFrame, struct EDA_HOTKEY_CONFIG *aDescList)
Function DisplayHotkeyList Displays the current hotkey list.
EDA_DRAW_FRAME::OnSelectGrid ID_TB_OPTIONS_SELECT_UNIT_INCH
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:284
Definition: common.h:160
EDA_HOTKEY * common_Hotkey_List[]
bool PostCommandMenuEvent(int evt_type)
Function PostCommandMenuEvent.
bool OnHotKey(wxDC *aDC, int aHotKey, const wxPoint &aPosition, EDA_ITEM *aItem=NULL) override
Handle hot key events.
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
bool OnHotkeyEditItem(int aIdCommand)
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:123
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:59
static bool SetGridOrigin(KIGFX::VIEW *aView, PCB_BASE_FRAME *aFrame, BOARD_ITEM *originViewItem, const VECTOR2D &aPoint)
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
EDA_HOTKEY * module_edit_Hotkey_List[]
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
#define UR_TRANSIENT
indicates the item is owned by the undo/redo stack
Definition: base_struct.h:142
BLOCK_COMMAND_T GetCommand() const
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:928
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
BOARD_ITEM * PrepareItemForHotkey(bool failIfCurrentlyEdited)
BOARD_ITEM * GetCurItem()
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
void OnLeftClick(wxDC *DC, const wxPoint &MousePos) override
int m_IdMenuEvent
Definition: hotkeys_basic.h:68
EDA_HOTKEY * GetDescriptorFromCommand(int aCommand, EDA_HOTKEY **aList)
Function GetDescriptorFromCommand Returns a EDA_HOTKEY* pointer from a hot key identifier.
bool OnHotkeyDeleteItem(int aIdCommand)