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 || item->GetEditFlags() == 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_PREFERENCES:
92  cmd.SetId( wxID_PREFERENCES );
93  GetEventHandler()->ProcessEvent( cmd );
94  break;
95 
96  case HK_RESET_LOCAL_COORD: // set local (relative) coordinate origin
98  break;
99 
100  case HK_LEFT_CLICK:
101  OnLeftClick( aDC, aPosition );
102  break;
103 
104  case HK_LEFT_DCLICK: // Simulate a double left click: generate 2 events
105  OnLeftClick( aDC, aPosition );
106  OnLeftDClick( aDC, aPosition );
107  break;
108 
109  case HK_SET_GRID_ORIGIN:
110  PCBNEW_CONTROL::SetGridOrigin( GetGalCanvas()->GetView(), this,
113  m_canvas->Refresh();
114  break;
115 
117  PCBNEW_CONTROL::SetGridOrigin( GetGalCanvas()->GetView(), this,
119  wxPoint( 0, 0 ) );
120  m_canvas->Refresh();
121  break;
122 
123  case HK_SWITCH_UNITS:
126  GetEventHandler()->ProcessEvent( cmd );
127  break;
128 
129  case HK_ZOOM_IN:
130  cmd.SetId( ID_KEY_ZOOM_IN );
131  GetEventHandler()->ProcessEvent( cmd );
132  break;
133 
134  case HK_ZOOM_OUT:
135  cmd.SetId( ID_KEY_ZOOM_OUT );
136  GetEventHandler()->ProcessEvent( cmd );
137  break;
138 
139  case HK_ZOOM_REDRAW:
140  cmd.SetId( ID_ZOOM_REDRAW );
141  GetEventHandler()->ProcessEvent( cmd );
142  break;
143 
144  case HK_ZOOM_CENTER:
145  cmd.SetId( ID_POPUP_ZOOM_CENTER );
146  GetEventHandler()->ProcessEvent( cmd );
147  break;
148 
149  case HK_ZOOM_SELECTION:
150  cmd.SetId( ID_ZOOM_SELECTION );
151  GetEventHandler()->ProcessEvent( cmd );
152  break;
153 
154  case HK_UNDO:
155  case HK_REDO:
156  if( ItemFree && !blockActive )
157  {
158  wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, HK_Descr->m_IdMenuEvent );
159  wxPostEvent( this, event );
160  }
161  break;
162 
163  case HK_ZOOM_AUTO:
164  cmd.SetId( ID_ZOOM_PAGE );
165  GetEventHandler()->ProcessEvent( cmd );
166  break;
167 
168  case HK_EDIT_ITEM:
170  break;
171 
172  case HK_DELETE:
174  break;
175 
176  case HK_MOVE_ITEM:
178  break;
179 
180  case HK_MOVE_ITEM_EXACT:
181  if( blockActive )
182  {
183  cmd.SetId( ID_POPUP_MOVE_BLOCK_EXACT );
184  GetEventHandler()->ProcessEvent( cmd );
185  }
186  else
187  {
189  }
190  break;
191 
192  case HK_ROTATE_ITEM:
194  break;
195 
196  case HK_DUPLICATE:
198  OnHotkeyDuplicateItem( HK_Descr->m_Idcommand );
199  break;
200 
201  case HK_CREATE_ARRAY:
203  }
204 
205  return true;
206 }
207 
208 
210 {
211  BOARD_ITEM* item = GetCurItem();
212  bool itemCurrentlyEdited = item && item->GetEditFlags();
213  bool blockActive = GetScreen()->m_BlockLocate.GetCommand() != BLOCK_IDLE;
214 
215  if( aFailIfCurrentlyEdited )
216  {
217  if( itemCurrentlyEdited || blockActive )
218  return NULL;
219 
220  item = ModeditLocateAndDisplay();
221  }
222  else
223  {
224  if( blockActive )
225  return NULL;
226 
227  if( !itemCurrentlyEdited )
228  item = ModeditLocateAndDisplay();
229  }
230 
231  // set item if we can, but don't clear if not
232  if( item )
233  SetCurItem( item );
234 
235  return item;
236 }
237 
238 
240 {
241  BOARD_ITEM* item = PrepareItemForHotkey( true );
242 
243  if( item == NULL )
244  return false;
245 
246  int evt_type = 0; // Used to post a wxCommandEvent on demand
247 
248  switch( item->Type() )
249  {
250  case PCB_MODULE_T:
251  if( aIdCommand == HK_EDIT_ITEM )
253 
254  break;
255 
256  case PCB_PAD_T:
257  if( aIdCommand == HK_EDIT_ITEM )
258  evt_type = ID_POPUP_PCB_EDIT_PAD;
259 
260  break;
261 
262  case PCB_MODULE_TEXT_T:
263  if( aIdCommand == HK_EDIT_ITEM )
264  evt_type = ID_POPUP_PCB_EDIT_TEXTMODULE;
265 
266  break;
267 
268  case PCB_MODULE_EDGE_T:
269  if( aIdCommand == HK_EDIT_ITEM )
271 
272  break;
273 
274  default:
275  break;
276  }
277 
278  return PostCommandMenuEvent( evt_type );
279 }
280 
281 
283 {
284  BOARD_ITEM* item = PrepareItemForHotkey( true );
285 
286  if( item == NULL )
287  return false;
288 
289  int evt_type = 0; // Used to post a wxCommandEvent on demand
290 
291  switch( item->Type() )
292  {
293  case PCB_PAD_T:
294  if( aIdCommand == HK_DELETE )
295  evt_type = ID_POPUP_PCB_DELETE_PAD;
296 
297  break;
298 
299  case PCB_MODULE_TEXT_T:
300  if( aIdCommand == HK_DELETE )
302 
303  break;
304 
305  case PCB_MODULE_EDGE_T:
306  if( aIdCommand == HK_DELETE )
307  evt_type = ID_POPUP_PCB_DELETE_EDGE;
308 
309  break;
310 
311  default:
312  break;
313  }
314 
315  return PostCommandMenuEvent( evt_type );
316 }
317 
318 
320 {
321  BOARD_ITEM* item = PrepareItemForHotkey( true );
322 
323  if( item == NULL )
324  return false;
325 
326  int evt_type = 0; // Used to post a wxCommandEvent on demand
327 
328  switch( item->Type() )
329  {
330  case PCB_PAD_T:
331  if( aIdCommand == HK_MOVE_ITEM )
333 
334  break;
335 
336  case PCB_MODULE_TEXT_T:
337  if( aIdCommand == HK_MOVE_ITEM )
339 
340  break;
341 
342  case PCB_MODULE_EDGE_T:
343  if( aIdCommand == HK_MOVE_ITEM )
344  evt_type = ID_POPUP_PCB_MOVE_EDGE;
345 
346  break;
347 
348  default:
349  break;
350  }
351 
352  return PostCommandMenuEvent( evt_type );
353 }
354 
355 
357 {
358  BOARD_ITEM* item = PrepareItemForHotkey( false );
359 
360  if( item == NULL )
361  return false;
362 
363  int evt_type = 0; // Used to post a wxCommandEvent on demand
364 
365  switch( item->Type() )
366  {
367  case PCB_PAD_T:
368  case PCB_MODULE_EDGE_T:
369  case PCB_MODULE_TEXT_T:
370  evt_type = ID_POPUP_PCB_MOVE_EXACT;
371  break;
372  default:
373  break;
374  }
375 
376  return PostCommandMenuEvent( evt_type );
377 }
378 
379 
381 {
382  BOARD_ITEM* item = PrepareItemForHotkey( true );
383 
384  if( item == NULL )
385  return false;
386 
387  int evt_type = 0; // Used to post a wxCommandEvent on demand
388 
389  switch( item->Type() )
390  {
391  case PCB_PAD_T:
392  case PCB_MODULE_EDGE_T:
393  case PCB_MODULE_TEXT_T:
394  if( aIdCommand == HK_DUPLICATE )
395  evt_type = ID_POPUP_PCB_DUPLICATE_ITEM;
396  else
398 
399  break;
400 
401  default:
402  break;
403  }
404 
405  return PostCommandMenuEvent( evt_type );
406 }
407 
408 
410 {
411  BOARD_ITEM* item = PrepareItemForHotkey( false );
412 
413  if( item == NULL )
414  return false;
415 
416  int evt_type = 0; // Used to post a wxCommandEvent on demand
417 
418  switch( item->Type() )
419  {
420  case PCB_MODULE_TEXT_T:
421  if( aIdCommand == HK_ROTATE_ITEM ) // Rotation
423 
424  break;
425 
426  default:
427  break;
428  }
429 
430  return PostCommandMenuEvent( evt_type );
431 }
void OnLeftDClick(wxDC *DC, const wxPoint &MousePos) override
Handle the double click in the footprint editor.
BOARD_ITEM * ModeditLocateAndDisplay(int aHotKeyCode=0)
BLOCK_COMMAND_T GetCommand() const
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[]
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:931
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)
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.
STATUS_FLAGS GetEditFlags() const
Definition: base_struct.h:263
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:289
Definition: common.h:158
EDA_HOTKEY * common_Hotkey_List[]
bool PostCommandMenuEvent(int evt_type)
Post a menu event to the frame, which can be used to trigger actions bound to menu items.
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:128
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:157
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:141
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
BOARD_ITEM * PrepareItemForHotkey(bool failIfCurrentlyEdited)
BOARD_ITEM * GetCurItem()
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)
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204