1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
|
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2010-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file hotkeys_module_editor.cpp
*/
#include <fctsys.h>
#include <pcbnew.h>
#include <wxPcbStruct.h>
#include <module_editor_frame.h>
#include <pcbnew_id.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <class_board_design_settings.h>
#include <hotkeys.h>
/* How to add a new hotkey:
* See hotkeys.cpp
*/
EDA_HOTKEY* FOOTPRINT_EDIT_FRAME::GetHotKeyDescription( int aCommand ) const
{
EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, common_Hotkey_List );
if( HK_Descr == NULL )
HK_Descr = GetDescriptorFromCommand( aCommand, module_edit_Hotkey_List );
return HK_Descr;
}
bool FOOTPRINT_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
EDA_ITEM* aItem )
{
if( aHotKey == 0 )
return false;
bool blockActive = GetScreen()->m_BlockLocate.GetCommand() != BLOCK_IDLE;
BOARD_ITEM* item = GetCurItem();
bool ItemFree = (item == 0) || (item->GetFlags() == 0);
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
cmd.SetEventObject( this );
/* Convert lower to upper case (the usual toupper function has problem with non ascii
* codes like function keys */
if( (aHotKey >= 'a') && (aHotKey <= 'z') )
aHotKey += 'A' - 'a';
EDA_HOTKEY* HK_Descr = GetDescriptorFromHotkey( aHotKey, common_Hotkey_List );
if( HK_Descr == NULL )
HK_Descr = GetDescriptorFromHotkey( aHotKey, module_edit_Hotkey_List );
if( HK_Descr == NULL )
return false;
switch( HK_Descr->m_Idcommand )
{
default:
case HK_NOT_FOUND:
return false;
case HK_HELP: // Display Current hotkey list
DisplayHotkeyList( this, g_Module_Editor_Hokeys_Descr );
break;
case HK_RESET_LOCAL_COORD: // set local (relative) coordinate origin
GetScreen()->m_O_Curseur = GetCrossHairPosition();
break;
case HK_LEFT_CLICK:
OnLeftClick( aDC, aPosition );
break;
case HK_LEFT_DCLICK: // Simulate a double left click: generate 2 events
OnLeftClick( aDC, aPosition );
OnLeftDClick( aDC, aPosition );
break;
case HK_SET_GRID_ORIGIN:
SetGridOrigin( GetCrossHairPosition() );
m_canvas->Refresh();
break;
case HK_RESET_GRID_ORIGIN:
SetGridOrigin( wxPoint(0,0) );
m_canvas->Refresh();
break;
case HK_SWITCH_UNITS:
cmd.SetId( (g_UserUnit == INCHES) ?
ID_TB_OPTIONS_SELECT_UNIT_MM : ID_TB_OPTIONS_SELECT_UNIT_INCH );
GetEventHandler()->ProcessEvent( cmd );
break;
case HK_ZOOM_IN:
cmd.SetId( ID_POPUP_ZOOM_IN );
GetEventHandler()->ProcessEvent( cmd );
break;
case HK_ZOOM_OUT:
cmd.SetId( ID_POPUP_ZOOM_OUT );
GetEventHandler()->ProcessEvent( cmd );
break;
case HK_ZOOM_REDRAW:
cmd.SetId( ID_ZOOM_REDRAW );
GetEventHandler()->ProcessEvent( cmd );
break;
case HK_ZOOM_CENTER:
cmd.SetId( ID_POPUP_ZOOM_CENTER );
GetEventHandler()->ProcessEvent( cmd );
break;
case HK_UNDO:
case HK_REDO:
if( ItemFree && !blockActive )
{
wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, HK_Descr->m_IdMenuEvent );
wxPostEvent( this, event );
}
break;
case HK_ZOOM_AUTO:
cmd.SetId( ID_ZOOM_PAGE );
GetEventHandler()->ProcessEvent( cmd );
break;
case HK_EDIT_ITEM:
OnHotkeyEditItem( HK_EDIT_ITEM );
break;
case HK_DELETE:
OnHotkeyDeleteItem( HK_DELETE );
break;
case HK_MOVE_ITEM:
OnHotkeyMoveItem( HK_MOVE_ITEM );
break;
case HK_MOVE_ITEM_EXACT:
if( blockActive )
{
cmd.SetId( ID_POPUP_MOVE_BLOCK_EXACT );
GetEventHandler()->ProcessEvent( cmd );
}
else
{
OnHotkeyMoveItemExact();
}
break;
case HK_ROTATE_ITEM:
OnHotkeyRotateItem( HK_ROTATE_ITEM );
break;
case HK_DUPLICATE_ITEM:
case HK_DUPLICATE_ITEM_AND_INCREMENT:
OnHotkeyDuplicateItem( HK_Descr->m_Idcommand );
break;
case HK_CREATE_ARRAY:
PostCommandMenuEvent( ID_POPUP_PCB_CREATE_ARRAY );
}
return true;
}
BOARD_ITEM* FOOTPRINT_EDIT_FRAME::PrepareItemForHotkey( bool aFailIfCurrentlyEdited )
{
BOARD_ITEM* item = GetCurItem();
bool itemCurrentlyEdited = item && item->GetFlags();
bool blockActive = GetScreen()->m_BlockLocate.GetCommand() != BLOCK_IDLE;
if( aFailIfCurrentlyEdited )
{
if( itemCurrentlyEdited || blockActive )
return NULL;
item = ModeditLocateAndDisplay();
}
else
{
if( blockActive )
return NULL;
if( !itemCurrentlyEdited )
item = ModeditLocateAndDisplay();
}
// set item if we can, but don't clear if not
if( item )
SetCurItem( item );
return item;
}
bool FOOTPRINT_EDIT_FRAME::OnHotkeyEditItem( int aIdCommand )
{
BOARD_ITEM* item = PrepareItemForHotkey( true );
if( item == NULL )
return false;
int evt_type = 0; // Used to post a wxCommandEvent on demand
switch( item->Type() )
{
case PCB_MODULE_T:
if( aIdCommand == HK_EDIT_ITEM )
evt_type = ID_POPUP_PCB_EDIT_MODULE_PRMS;
break;
case PCB_PAD_T:
if( aIdCommand == HK_EDIT_ITEM )
evt_type = ID_POPUP_PCB_EDIT_PAD;
break;
case PCB_MODULE_TEXT_T:
if( aIdCommand == HK_EDIT_ITEM )
evt_type = ID_POPUP_PCB_EDIT_TEXTMODULE;
break;
case PCB_MODULE_EDGE_T:
if( aIdCommand == HK_EDIT_ITEM )
evt_type = ID_POPUP_MODEDIT_EDIT_BODY_ITEM;
break;
default:
break;
}
return PostCommandMenuEvent( evt_type );
}
bool FOOTPRINT_EDIT_FRAME::OnHotkeyDeleteItem( int aIdCommand )
{
BOARD_ITEM* item = PrepareItemForHotkey( true );
if( item == NULL )
return false;
int evt_type = 0; // Used to post a wxCommandEvent on demand
switch( item->Type() )
{
case PCB_PAD_T:
if( aIdCommand == HK_DELETE )
evt_type = ID_POPUP_PCB_DELETE_PAD;
break;
case PCB_MODULE_TEXT_T:
if( aIdCommand == HK_DELETE )
evt_type = ID_POPUP_PCB_DELETE_TEXTMODULE;
break;
case PCB_MODULE_EDGE_T:
if( aIdCommand == HK_DELETE )
evt_type = ID_POPUP_PCB_DELETE_EDGE;
break;
default:
break;
}
return PostCommandMenuEvent( evt_type );
}
bool FOOTPRINT_EDIT_FRAME::OnHotkeyMoveItem( int aIdCommand )
{
BOARD_ITEM* item = PrepareItemForHotkey( true );
if( item == NULL )
return false;
int evt_type = 0; // Used to post a wxCommandEvent on demand
switch( item->Type() )
{
case PCB_PAD_T:
if( aIdCommand == HK_MOVE_ITEM )
evt_type = ID_POPUP_PCB_MOVE_PAD_REQUEST;
break;
case PCB_MODULE_TEXT_T:
if( aIdCommand == HK_MOVE_ITEM )
evt_type = ID_POPUP_PCB_MOVE_TEXTMODULE_REQUEST;
break;
case PCB_MODULE_EDGE_T:
if( aIdCommand == HK_MOVE_ITEM )
evt_type = ID_POPUP_PCB_MOVE_EDGE;
break;
default:
break;
}
return PostCommandMenuEvent( evt_type );
}
bool FOOTPRINT_EDIT_FRAME::OnHotkeyMoveItemExact()
{
BOARD_ITEM* item = PrepareItemForHotkey( false );
if( item == NULL )
return false;
int evt_type = 0; // Used to post a wxCommandEvent on demand
switch( item->Type() )
{
case PCB_PAD_T:
case PCB_MODULE_EDGE_T:
case PCB_MODULE_TEXT_T:
evt_type = ID_POPUP_PCB_MOVE_EXACT;
break;
default:
break;
}
return PostCommandMenuEvent( evt_type );
}
bool FOOTPRINT_EDIT_FRAME::OnHotkeyDuplicateItem( int aIdCommand )
{
BOARD_ITEM* item = PrepareItemForHotkey( true );
if( item == NULL )
return false;
int evt_type = 0; // Used to post a wxCommandEvent on demand
switch( item->Type() )
{
case PCB_PAD_T:
case PCB_MODULE_EDGE_T:
case PCB_MODULE_TEXT_T:
if( aIdCommand == HK_DUPLICATE_ITEM )
evt_type = ID_POPUP_PCB_DUPLICATE_ITEM;
else
evt_type = ID_POPUP_PCB_DUPLICATE_ITEM_AND_INCREMENT;
break;
default:
break;
}
return PostCommandMenuEvent( evt_type );
}
bool FOOTPRINT_EDIT_FRAME::OnHotkeyRotateItem( int aIdCommand )
{
BOARD_ITEM* item = PrepareItemForHotkey( false );
if( item == NULL )
return false;
int evt_type = 0; // Used to post a wxCommandEvent on demand
switch( item->Type() )
{
case PCB_MODULE_TEXT_T:
if( aIdCommand == HK_ROTATE_ITEM ) // Rotation
evt_type = ID_POPUP_PCB_ROTATE_TEXTMODULE;
break;
default:
break;
}
return PostCommandMenuEvent( evt_type );
}
|