KiCad PCB EDA Suite
hotkeys_module_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 <wxPcbStruct.h>
32 #include <module_editor_frame.h>
33 #include <pcbnew_id.h>
34 #include <class_drawpanel.h>
35 #include <confirm.h>
37 
38 #include <hotkeys.h>
39 
40 /* How to add a new hotkey:
41  * See hotkeys.cpp
42  */
43 
45 {
47 
48  if( HK_Descr == NULL )
49  HK_Descr = GetDescriptorFromCommand( aCommand, module_edit_Hotkey_List );
50 
51  return HK_Descr;
52 }
53 
54 
55 bool FOOTPRINT_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
56  EDA_ITEM* aItem )
57 {
58  if( aHotKey == 0 )
59  return false;
60 
61  bool blockActive = GetScreen()->m_BlockLocate.GetCommand() != BLOCK_IDLE;
62  BOARD_ITEM* item = GetCurItem();
63  bool ItemFree = (item == 0) || (item->GetFlags() == 0);
64  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
65  cmd.SetEventObject( this );
66 
67  /* Convert lower to upper case (the usual toupper function has problem with non ascii
68  * codes like function keys */
69  if( (aHotKey >= 'a') && (aHotKey <= 'z') )
70  aHotKey += 'A' - 'a';
71 
73 
74  if( HK_Descr == NULL )
75  HK_Descr = GetDescriptorFromHotkey( aHotKey, module_edit_Hotkey_List );
76 
77  if( HK_Descr == NULL )
78  return false;
79 
80  switch( HK_Descr->m_Idcommand )
81  {
82  default:
83  case HK_NOT_FOUND:
84  return false;
85 
86  case HK_HELP: // Display Current hotkey list
88  break;
89 
90  case HK_RESET_LOCAL_COORD: // set local (relative) coordinate origin
92  break;
93 
94  case HK_LEFT_CLICK:
95  OnLeftClick( aDC, aPosition );
96  break;
97 
98  case HK_LEFT_DCLICK: // Simulate a double left click: generate 2 events
99  OnLeftClick( aDC, aPosition );
100  OnLeftDClick( aDC, aPosition );
101  break;
102 
103  case HK_SET_GRID_ORIGIN:
105  m_canvas->Refresh();
106  break;
107 
109  SetGridOrigin( wxPoint(0,0) );
110  m_canvas->Refresh();
111  break;
112 
113  case HK_SWITCH_UNITS:
114  cmd.SetId( (g_UserUnit == INCHES) ?
116  GetEventHandler()->ProcessEvent( cmd );
117  break;
118 
119  case HK_ZOOM_IN:
120  cmd.SetId( ID_POPUP_ZOOM_IN );
121  GetEventHandler()->ProcessEvent( cmd );
122  break;
123 
124  case HK_ZOOM_OUT:
125  cmd.SetId( ID_POPUP_ZOOM_OUT );
126  GetEventHandler()->ProcessEvent( cmd );
127  break;
128 
129  case HK_ZOOM_REDRAW:
130  cmd.SetId( ID_ZOOM_REDRAW );
131  GetEventHandler()->ProcessEvent( cmd );
132  break;
133 
134  case HK_ZOOM_CENTER:
135  cmd.SetId( ID_POPUP_ZOOM_CENTER );
136  GetEventHandler()->ProcessEvent( cmd );
137  break;
138 
139  case HK_ZOOM_SELECTION:
140  cmd.SetId( ID_ZOOM_SELECTION );
141  GetEventHandler()->ProcessEvent( cmd );
142  break;
143 
144  case HK_UNDO:
145  case HK_REDO:
146  if( ItemFree && !blockActive )
147  {
148  wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, HK_Descr->m_IdMenuEvent );
149  wxPostEvent( this, event );
150  }
151  break;
152 
153  case HK_ZOOM_AUTO:
154  cmd.SetId( ID_ZOOM_PAGE );
155  GetEventHandler()->ProcessEvent( cmd );
156  break;
157 
158  case HK_EDIT_ITEM:
160  break;
161 
162  case HK_DELETE:
164  break;
165 
166  case HK_MOVE_ITEM:
168  break;
169 
170  case HK_MOVE_ITEM_EXACT:
171  if( blockActive )
172  {
173  cmd.SetId( ID_POPUP_MOVE_BLOCK_EXACT );
174  GetEventHandler()->ProcessEvent( cmd );
175  }
176  else
177  {
179  }
180  break;
181 
182  case HK_ROTATE_ITEM:
184  break;
185 
186  case HK_DUPLICATE_ITEM:
188  OnHotkeyDuplicateItem( HK_Descr->m_Idcommand );
189  break;
190 
191  case HK_CREATE_ARRAY:
193  }
194 
195  return true;
196 }
197 
198 
200 {
201  BOARD_ITEM* item = GetCurItem();
202  bool itemCurrentlyEdited = item && item->GetFlags();
203  bool blockActive = GetScreen()->m_BlockLocate.GetCommand() != BLOCK_IDLE;
204 
205  if( aFailIfCurrentlyEdited )
206  {
207  if( itemCurrentlyEdited || blockActive )
208  return NULL;
209 
210  item = ModeditLocateAndDisplay();
211  }
212  else
213  {
214  if( blockActive )
215  return NULL;
216 
217  if( !itemCurrentlyEdited )
218  item = ModeditLocateAndDisplay();
219  }
220 
221  // set item if we can, but don't clear if not
222  if( item )
223  SetCurItem( item );
224 
225  return item;
226 }
227 
228 
230 {
231  BOARD_ITEM* item = PrepareItemForHotkey( true );
232 
233  if( item == NULL )
234  return false;
235 
236  int evt_type = 0; // Used to post a wxCommandEvent on demand
237 
238  switch( item->Type() )
239  {
240  case PCB_MODULE_T:
241  if( aIdCommand == HK_EDIT_ITEM )
243 
244  break;
245 
246  case PCB_PAD_T:
247  if( aIdCommand == HK_EDIT_ITEM )
248  evt_type = ID_POPUP_PCB_EDIT_PAD;
249 
250  break;
251 
252  case PCB_MODULE_TEXT_T:
253  if( aIdCommand == HK_EDIT_ITEM )
254  evt_type = ID_POPUP_PCB_EDIT_TEXTMODULE;
255 
256  break;
257 
258  case PCB_MODULE_EDGE_T:
259  if( aIdCommand == HK_EDIT_ITEM )
261 
262  break;
263 
264  default:
265  break;
266  }
267 
268  return PostCommandMenuEvent( evt_type );
269 }
270 
271 
273 {
274  BOARD_ITEM* item = PrepareItemForHotkey( true );
275 
276  if( item == NULL )
277  return false;
278 
279  int evt_type = 0; // Used to post a wxCommandEvent on demand
280 
281  switch( item->Type() )
282  {
283  case PCB_PAD_T:
284  if( aIdCommand == HK_DELETE )
285  evt_type = ID_POPUP_PCB_DELETE_PAD;
286 
287  break;
288 
289  case PCB_MODULE_TEXT_T:
290  if( aIdCommand == HK_DELETE )
292 
293  break;
294 
295  case PCB_MODULE_EDGE_T:
296  if( aIdCommand == HK_DELETE )
297  evt_type = ID_POPUP_PCB_DELETE_EDGE;
298 
299  break;
300 
301  default:
302  break;
303  }
304 
305  return PostCommandMenuEvent( evt_type );
306 }
307 
308 
310 {
311  BOARD_ITEM* item = PrepareItemForHotkey( true );
312 
313  if( item == NULL )
314  return false;
315 
316  int evt_type = 0; // Used to post a wxCommandEvent on demand
317 
318  switch( item->Type() )
319  {
320  case PCB_PAD_T:
321  if( aIdCommand == HK_MOVE_ITEM )
323 
324  break;
325 
326  case PCB_MODULE_TEXT_T:
327  if( aIdCommand == HK_MOVE_ITEM )
329 
330  break;
331 
332  case PCB_MODULE_EDGE_T:
333  if( aIdCommand == HK_MOVE_ITEM )
334  evt_type = ID_POPUP_PCB_MOVE_EDGE;
335 
336  break;
337 
338  default:
339  break;
340  }
341 
342  return PostCommandMenuEvent( evt_type );
343 }
344 
345 
347 {
348  BOARD_ITEM* item = PrepareItemForHotkey( false );
349 
350  if( item == NULL )
351  return false;
352 
353  int evt_type = 0; // Used to post a wxCommandEvent on demand
354 
355  switch( item->Type() )
356  {
357  case PCB_PAD_T:
358  case PCB_MODULE_EDGE_T:
359  case PCB_MODULE_TEXT_T:
360  evt_type = ID_POPUP_PCB_MOVE_EXACT;
361  break;
362  default:
363  break;
364  }
365 
366  return PostCommandMenuEvent( evt_type );
367 }
368 
369 
371 {
372  BOARD_ITEM* item = PrepareItemForHotkey( true );
373 
374  if( item == NULL )
375  return false;
376 
377  int evt_type = 0; // Used to post a wxCommandEvent on demand
378 
379  switch( item->Type() )
380  {
381  case PCB_PAD_T:
382  case PCB_MODULE_EDGE_T:
383  case PCB_MODULE_TEXT_T:
384  if( aIdCommand == HK_DUPLICATE_ITEM )
385  evt_type = ID_POPUP_PCB_DUPLICATE_ITEM;
386  else
388 
389  break;
390 
391  default:
392  break;
393  }
394 
395  return PostCommandMenuEvent( evt_type );
396 }
397 
398 
400 {
401  BOARD_ITEM* item = PrepareItemForHotkey( false );
402 
403  if( item == NULL )
404  return false;
405 
406  int evt_type = 0; // Used to post a wxCommandEvent on demand
407 
408  switch( item->Type() )
409  {
410  case PCB_MODULE_TEXT_T:
411  if( aIdCommand == HK_ROTATE_ITEM ) // Rotation
413 
414  break;
415 
416  default:
417  break;
418  }
419 
420  return PostCommandMenuEvent( evt_type );
421 }
void OnLeftDClick(wxDC *DC, const wxPoint &MousePos) override
Function OnLeftDClick handles the double click in the footprint editor: If the double clicked item is...
BOARD_ITEM * ModeditLocateAndDisplay(int aHotKeyCode=0)
Definition: modedit.cpp:82
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
Definition of class FOOTPRINT_EDIT_FRAME.
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:269
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
bool OnHotkeyRotateItem(int aIdCommand)
void SetGridOrigin(const wxPoint &aPoint) override
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:325
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...
bool OnHotkeyDuplicateItem(int aIdCommand)
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.
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
Pcbnew hotkeys.
EDA_DRAW_FRAME::OnSelectGrid ID_TB_OPTIONS_SELECT_UNIT_INCH
Definition: draw_frame.cpp:124
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.
Definition: common.h:144
EDA_HOTKEY * common_Hotkey_List[]
bool PostCommandMenuEvent(int evt_type)
Function PostCommandMenuEvent.
Definition: basicframe.cpp:666
bool OnHotKey(wxDC *aDC, int aHotKey, const wxPoint &aPosition, EDA_ITEM *aItem=NULL) override
Function OnHotKey handle hot key events.
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
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:93
struct EDA_HOTKEY_CONFIG g_Module_Editor_Hokeys_Descr[]
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
EDA_HOTKEY * module_edit_Hotkey_List[]
PCB_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
BLOCK_COMMAND_T GetCommand() const
BOARD_ITEM * PrepareItemForHotkey(bool failIfCurrentlyEdited)
BOARD_ITEM * GetCurItem()
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition 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:66
EDA_HOTKEY * GetDescriptorFromCommand(int aCommand, EDA_HOTKEY **aList)
Function GetDescriptorFromCommand Returns a EDA_HOTKEY* pointer from a hot key identifier.
bool OnHotkeyDeleteItem(int aIdCommand)