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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
|
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2017 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2017 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 eeschema/hotkeys.cpp
*/
#include <fctsys.h>
#include <eeschema_id.h>
#include <hotkeys.h>
#include <schframe.h>
#include <class_drawpanel.h>
#include <general.h>
#include <libeditframe.h>
#include <viewlib_frame.h>
#include <class_libentry.h>
#include <sch_junction.h>
#include <sch_line.h>
#include <sch_component.h>
#include <sch_sheet.h>
#include <dialogs/dialog_schematic_find.h>
// Remark: the hotkey message info is used as keyword in hotkey config files and
// as comments in help windows, therefore translated only when displayed
// they are marked _HKI to be extracted by translation tools
// See hotkeys_basic.h for more info
/* How to add a new hotkey:
* add a new id in the enum hotkey_id_command like MY_NEW_ID_FUNCTION (see
* hotkeys.h).
* add a new EDA_HOTKEY entry like:
* static EDA_HOTKEY HkMyNewEntry(_HKI("Command Label"), MY_NEW_ID_FUNCTION,
* default key value);
* _HKI("Command Label") is the name used in hotkey list display, and the
* identifier in the hotkey list file
* MY_NEW_ID_FUNCTION is an equivalent id function used in the switch in
* OnHotKey() function.
* default key value is the default hotkey for this command. Can be overridden
* by the user hotkey list file
* add the HkMyNewEntry pointer in the schematic_Hotkey_List list or the
* libEdit_Hotkey_List list or common_Hotkey_List if the same command is
* added both in Eeschema and libedit)
* Add the new code in the switch in OnHotKey() function.
* when the variable itemInEdit is true, an item is currently edited.
* This can be useful if the new function cannot be executed while an item is
* currently being edited
* ( For example, one cannot start a new wire when a component is moving.)
*
* Note: If an hotkey is a special key be sure the corresponding wxWidget
* keycode (WXK_XXXX) is handled in the hotkey_name_descr
* s_Hotkey_Name_List list (see hotkeys_basic.cpp) and see this list
* for some ascii keys (space ...)
*
* Key modifier are: GR_KB_CTRL GR_KB_ALT
*/
// Common commands
// Fit on Screen
#if !defined( __WXMAC__ )
static EDA_HOTKEY HkZoomAuto( _HKI( "Fit on Screen" ), HK_ZOOM_AUTO, WXK_HOME, ID_ZOOM_PAGE );
#else
static EDA_HOTKEY HkZoomAuto( _HKI( "Zoom Auto" ), HK_ZOOM_AUTO, GR_KB_CTRL + '0',
ID_ZOOM_PAGE );
#endif
static EDA_HOTKEY HkZoomCenter( _HKI( "Zoom Center" ), HK_ZOOM_CENTER, WXK_F4,
ID_POPUP_ZOOM_CENTER );
// Refresh Screen
#if !defined( __WXMAC__ )
static EDA_HOTKEY HkZoomRedraw( _HKI( "Zoom Redraw" ), HK_ZOOM_REDRAW, WXK_F3, ID_ZOOM_REDRAW );
#else
static EDA_HOTKEY HkZoomRedraw( _HKI( "Zoom Redraw" ), HK_ZOOM_REDRAW, GR_KB_CTRL + 'R',
ID_ZOOM_REDRAW );
#endif
// Zoom In
#if !defined( __WXMAC__ )
static EDA_HOTKEY HkZoomIn( _HKI( "Zoom In" ), HK_ZOOM_IN, WXK_F1, ID_POPUP_ZOOM_IN );
#else
static EDA_HOTKEY HkZoomIn( _HKI( "Zoom In" ), HK_ZOOM_IN, GR_KB_CTRL + '+', ID_POPUP_ZOOM_IN );
#endif
// Zoom Out
#if !defined( __WXMAC__ )
static EDA_HOTKEY HkZoomOut( _HKI( "Zoom Out" ), HK_ZOOM_OUT, WXK_F2, ID_POPUP_ZOOM_OUT );
#else
static EDA_HOTKEY HkZoomOut( _HKI( "Zoom Out" ), HK_ZOOM_OUT, GR_KB_CTRL + '-', ID_POPUP_ZOOM_OUT );
#endif
static EDA_HOTKEY HkHelp( _HKI( "Help (this window)" ), HK_HELP, '?' );
static EDA_HOTKEY HkResetLocalCoord( _HKI( "Reset Local Coordinates" ), HK_RESET_LOCAL_COORD, ' ' );
static EDA_HOTKEY HkLeaveSheet( _HKI( "Leave Sheet" ), HK_LEAVE_SHEET, GR_KB_ALT + WXK_BACK,
ID_POPUP_SCH_LEAVE_SHEET );
// Undo
static EDA_HOTKEY HkUndo( _HKI( "Undo" ), HK_UNDO, GR_KB_CTRL + 'Z', (int) wxID_UNDO );
// Redo
#if !defined( __WXMAC__ )
static EDA_HOTKEY HkRedo( _HKI( "Redo" ), HK_REDO, GR_KB_CTRL + 'Y', (int) wxID_REDO );
#else
static EDA_HOTKEY HkRedo( _HKI( "Redo" ), HK_REDO, GR_KB_SHIFT + GR_KB_CTRL + 'Z',
(int) wxID_REDO );
#endif
// mouse click command:
static EDA_HOTKEY HkMouseLeftClick( _HKI( "Mouse Left Click" ), HK_LEFT_CLICK, WXK_RETURN, 0 );
static EDA_HOTKEY HkMouseLeftDClick( _HKI( "Mouse Left Double Click" ), HK_LEFT_DCLICK, WXK_END, 0 );
// Schematic editor
static EDA_HOTKEY HkBeginWire( _HKI( "Begin Wire" ), HK_BEGIN_WIRE, 'W', ID_WIRE_BUTT );
static EDA_HOTKEY HkBeginBus( _HKI( "Begin Bus" ), HK_BEGIN_BUS, 'B', ID_BUS_BUTT );
static EDA_HOTKEY HkEndLineWireBus( _HKI( "End Line Wire Bus" ), HK_END_CURR_LINEWIREBUS, 'K',
ID_POPUP_END_LINE );
static EDA_HOTKEY HkAddLabel( _HKI( "Add Label" ), HK_ADD_LABEL, 'L', ID_LABEL_BUTT );
static EDA_HOTKEY HkAddHierarchicalLabel( _HKI( "Add Hierarchical Label" ), HK_ADD_HLABEL, 'H',
ID_HIERLABEL_BUTT );
static EDA_HOTKEY HkAddGlobalLabel( _HKI( "Add Global Label" ), HK_ADD_GLABEL, GR_KB_CTRL + 'H',
ID_GLABEL_BUTT );
static EDA_HOTKEY HkAddJunction( _HKI( "Add Junction" ), HK_ADD_JUNCTION, 'J', ID_JUNCTION_BUTT );
static EDA_HOTKEY HkAddComponent( _HKI( "Add Component" ), HK_ADD_NEW_COMPONENT, 'A',
ID_SCH_PLACE_COMPONENT );
static EDA_HOTKEY HkAddPower( _HKI( "Add Power" ), HK_ADD_NEW_POWER, 'P',
ID_PLACE_POWER_BUTT );
static EDA_HOTKEY HkAddNoConn( _HKI( "Add No Connect Flag" ), HK_ADD_NOCONN_FLAG, 'Q',
ID_NOCONN_BUTT );
static EDA_HOTKEY HkAddHierSheet( _HKI( "Add Sheet" ), HK_ADD_HIER_SHEET, 'S',
ID_SHEET_SYMBOL_BUTT );
static EDA_HOTKEY HkAddBusEntry( _HKI( "Add Bus Entry" ), HK_ADD_BUS_ENTRY, '/',
ID_BUSTOBUS_ENTRY_BUTT );
static EDA_HOTKEY HkAddWireEntry( _HKI( "Add Wire Entry" ), HK_ADD_WIRE_ENTRY, 'Z',
ID_WIRETOBUS_ENTRY_BUTT );
static EDA_HOTKEY HkAddGraphicPolyLine( _HKI( "Add Graphic PolyLine" ), HK_ADD_GRAPHIC_POLYLINE,
'I', ID_LINE_COMMENT_BUTT );
static EDA_HOTKEY HkAddGraphicText( _HKI( "Add Graphic Text" ), HK_ADD_GRAPHIC_TEXT, 'T',
ID_TEXT_COMMENT_BUTT );
static EDA_HOTKEY HkMirrorY( _HKI( "Mirror Y" ), HK_MIRROR_Y, 'Y',
ID_SCH_MIRROR_Y );
static EDA_HOTKEY HkMirrorX( _HKI( "Mirror X" ), HK_MIRROR_X, 'X',
ID_SCH_MIRROR_X );
static EDA_HOTKEY HkOrientNormalComponent( _HKI( "Orient Normal Component" ),
HK_ORIENT_NORMAL_COMPONENT, 'N', ID_SCH_ORIENT_NORMAL );
static EDA_HOTKEY HkRotate( _HKI( "Rotate Item" ), HK_ROTATE, 'R', ID_SCH_ROTATE_CLOCKWISE );
static EDA_HOTKEY HkEdit( _HKI( "Edit Item" ), HK_EDIT, 'E', ID_SCH_EDIT_ITEM );
static EDA_HOTKEY HkEditComponentValue( _HKI( "Edit Component Value" ),
HK_EDIT_COMPONENT_VALUE, 'V',
ID_SCH_EDIT_COMPONENT_VALUE );
static EDA_HOTKEY HkEditComponentReference( _HKI( "Edit Component Reference" ),
HK_EDIT_COMPONENT_REFERENCE, 'U',
ID_SCH_EDIT_COMPONENT_REFERENCE );
static EDA_HOTKEY HkEditComponentFootprint( _HKI( "Edit Component Footprint" ),
HK_EDIT_COMPONENT_FOOTPRINT, 'F',
ID_SCH_EDIT_COMPONENT_FOOTPRINT );
static EDA_HOTKEY HkEditComponentWithLibedit( _HKI( "Edit with Component Editor" ),
HK_EDIT_COMPONENT_WITH_LIBEDIT,
'E' + GR_KB_CTRL,
ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP );
static EDA_HOTKEY HkMove( _HKI( "Move Schematic Item" ),
HK_MOVE_COMPONENT_OR_ITEM, 'M',
ID_SCH_MOVE_ITEM );
static EDA_HOTKEY HkCopyComponentOrText( _HKI( "Copy Component or Label" ),
HK_COPY_COMPONENT_OR_LABEL, 'C',
ID_POPUP_SCH_COPY_ITEM );
static EDA_HOTKEY HkDrag( _HKI( "Drag Item" ), HK_DRAG, 'G', ID_SCH_DRAG_ITEM );
static EDA_HOTKEY HkSaveBlock( _HKI( "Save Block" ), HK_SAVE_BLOCK, 'C' + GR_KB_CTRL, wxID_COPY );
static EDA_HOTKEY HkMove2Drag( _HKI( "Move Block -> Drag Block" ),
HK_MOVEBLOCK_TO_DRAGBLOCK, '\t', ID_POPUP_DRAG_BLOCK );
static EDA_HOTKEY HkInsert( _HKI( "Repeat Last Item" ), HK_REPEAT_LAST, WXK_INSERT );
static EDA_HOTKEY HkDelete( _HKI( "Delete Item" ), HK_DELETE, WXK_DELETE );
static EDA_HOTKEY HkDeleteNode( _HKI( "Delete Node" ), HK_DELETE_NODE, WXK_BACK,
ID_POPUP_SCH_DELETE_NODE );
static EDA_HOTKEY HkFindItem( _HKI( "Find Item" ), HK_FIND_ITEM, 'F' + GR_KB_CTRL, ID_FIND_ITEMS );
static EDA_HOTKEY HkFindNextItem( _HKI( "Find Next Item" ), HK_FIND_NEXT_ITEM, WXK_F5,
wxEVT_COMMAND_FIND );
static EDA_HOTKEY HkFindReplace( _HKI( "Find and Replace" ), HK_FIND_REPLACE,
'F' + GR_KB_CTRL + GR_KB_ALT, wxID_REPLACE );
static EDA_HOTKEY HkFindNextDrcMarker( _HKI( "Find Next DRC Marker" ), HK_FIND_NEXT_DRC_MARKER,
WXK_F5 + GR_KB_SHIFT, EVT_COMMAND_FIND_DRC_MARKER );
// Special keys for library editor:
static EDA_HOTKEY HkCreatePin( _HKI( "Create Pin" ), HK_LIBEDIT_CREATE_PIN, 'P' );
static EDA_HOTKEY HkInsertPin( _HKI( "Repeat Pin" ), HK_REPEAT_LAST, WXK_INSERT );
static EDA_HOTKEY HkMoveLibItem( _HKI( "Move Library Item" ), HK_LIBEDIT_MOVE_GRAPHIC_ITEM, 'M' );
// Load/save files
static EDA_HOTKEY HkSaveLib( _HKI( "Save Library" ), HK_SAVE_LIB, 'S' + GR_KB_CTRL );
static EDA_HOTKEY HkSaveSchematic( _HKI( "Save Schematic" ), HK_SAVE_SCH, 'S' + GR_KB_CTRL );
static EDA_HOTKEY HkLoadSchematic( _HKI( "Load Schematic" ), HK_LOAD_SCH, 'L' + GR_KB_CTRL );
// List of common hotkey descriptors
static EDA_HOTKEY* common_Hotkey_List[] =
{
&HkHelp,
&HkZoomIn,
&HkZoomOut,
&HkZoomRedraw,
&HkZoomCenter,
&HkZoomAuto,
&HkResetLocalCoord,
&HkEdit,
&HkDelete,
&HkRotate,
&HkDrag,
&HkUndo,
&HkRedo,
&HkMouseLeftClick,
&HkMouseLeftDClick,
NULL
};
// List of common hotkey descriptors, for the library vierwer
static EDA_HOTKEY* common_basic_Hotkey_List[] =
{
&HkHelp,
&HkZoomIn,
&HkZoomOut,
&HkZoomRedraw,
&HkZoomCenter,
&HkZoomAuto,
&HkResetLocalCoord,
&HkMouseLeftClick,
&HkMouseLeftDClick,
NULL
};
// List of hotkey descriptors for schematic
static EDA_HOTKEY* schematic_Hotkey_List[] =
{
&HkSaveSchematic,
&HkLoadSchematic,
&HkFindItem,
&HkFindNextItem,
&HkFindNextDrcMarker,
&HkFindReplace,
&HkInsert,
&HkMove2Drag,
&HkSaveBlock,
&HkMove,
&HkCopyComponentOrText,
&HkAddComponent,
&HkAddPower,
&HkMirrorX,
&HkMirrorY,
&HkOrientNormalComponent,
&HkEditComponentValue,
&HkEditComponentReference,
&HkEditComponentFootprint,
&HkEditComponentWithLibedit,
&HkBeginWire,
&HkBeginBus,
&HkEndLineWireBus,
&HkAddLabel,
&HkAddHierarchicalLabel,
&HkAddGlobalLabel,
&HkAddJunction,
&HkAddNoConn,
&HkAddHierSheet,
&HkAddWireEntry,
&HkAddBusEntry,
&HkAddGraphicPolyLine,
&HkAddGraphicText,
&HkLeaveSheet,
&HkDeleteNode,
NULL
};
// List of hotkey descriptors for library editor
static EDA_HOTKEY* libEdit_Hotkey_List[] =
{
&HkSaveLib,
&HkCreatePin,
&HkInsertPin,
&HkMoveLibItem,
NULL
};
// List of hotkey descriptors for library viewer (currently empty
static EDA_HOTKEY* viewlib_Hotkey_List[] =
{
NULL
};
// Keyword Identifiers (tags) in key code configuration file (section names)
// (.m_SectionTag member of a EDA_HOTKEY_CONFIG)
static wxString schematicSectionTag( wxT( "[eeschema]" ) );
static wxString libEditSectionTag( wxT( "[libedit]" ) );
// Titles for hotkey editor and hotkey display
static wxString commonSectionTitle( _HKI( "Common" ) );
static wxString schematicSectionTitle( _HKI( "Schematic Editor" ) );
static wxString libEditSectionTitle( _HKI( "Library Editor" ) );
// list of sections and corresponding hotkey list for Eeschema (used to create
// an hotkey config file)
struct EDA_HOTKEY_CONFIG g_Eeschema_Hokeys_Descr[] =
{
{ &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle },
{ &schematicSectionTag, schematic_Hotkey_List, &schematicSectionTitle },
{ &libEditSectionTag, libEdit_Hotkey_List, &libEditSectionTitle },
{ NULL, NULL, NULL }
};
// list of sections and corresponding hotkey list for the schematic editor
// (used to list current hotkeys)
struct EDA_HOTKEY_CONFIG g_Schematic_Hokeys_Descr[] =
{
{ &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle },
{ &schematicSectionTag, schematic_Hotkey_List, &schematicSectionTitle },
{ NULL, NULL, NULL }
};
// list of sections and corresponding hotkey list for the component editor
// (used to list current hotkeys)
struct EDA_HOTKEY_CONFIG g_Libedit_Hokeys_Descr[] =
{
{ &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle },
{ &libEditSectionTag, libEdit_Hotkey_List, &libEditSectionTitle },
{ NULL, NULL, NULL }
};
// list of sections and corresponding hotkey list for the component browser
// (used to list current hotkeys)
struct EDA_HOTKEY_CONFIG g_Viewlib_Hokeys_Descr[] =
{
{ &g_CommonSectionTag, common_basic_Hotkey_List, &commonSectionTitle },
{ NULL, NULL, NULL }
};
EDA_HOTKEY* SCH_EDIT_FRAME::GetHotKeyDescription( int aCommand ) const
{
EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, common_Hotkey_List );
if( HK_Descr == NULL )
HK_Descr = GetDescriptorFromCommand( aCommand, schematic_Hotkey_List );
return HK_Descr;
}
/*
* Hot keys. Some commands are relative to the item under the mouse cursor
* Commands are case insensitive
*/
bool SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem )
{
if( aHotKey == 0 )
return false;
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
SCH_SCREEN* screen = GetScreen();
// itemInEdit == false means no item currently edited. We can ask for editing a new item
bool itemInEdit = screen->GetCurItem() && screen->GetCurItem()->GetFlags();
// blocInProgress == false means no block in progress.
// Because a drag command uses a drag block, false means also no drag in progress
// If false, we can ask for editing a new item
bool blocInProgress = screen->m_BlockLocate.GetState() != STATE_NO_BLOCK;
// notBusy == true means no item currently edited and no other command in progress
// We can change active tool and ask for editing a new item
bool notBusy = (!itemInEdit) && (!blocInProgress);
/* 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';
// Search command from key :
EDA_HOTKEY* hotKey = GetDescriptorFromHotkey( aHotKey, common_Hotkey_List );
if( hotKey == NULL )
hotKey = GetDescriptorFromHotkey( aHotKey, schematic_Hotkey_List );
if( hotKey == NULL )
return false;
switch( hotKey->m_Idcommand )
{
default:
case HK_NOT_FOUND:
return false;
case HK_HELP: // Display Current hotkey list
DisplayHotkeyList( this, g_Schematic_Hokeys_Descr );
break;
case HK_RESET_LOCAL_COORD: // Reset the relative coord
GetScreen()->m_O_Curseur = GetCrossHairPosition();
break;
case HK_LEFT_CLICK:
case HK_LEFT_DCLICK: // Simulate a double left click: generate 2 events
if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE )
{
GetCanvas()->SetAutoPanRequest( false );
HandleBlockPlace( aDC );
}
else if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK )
{
OnLeftClick( aDC, aPosition );
if( hotKey->m_Idcommand == HK_LEFT_DCLICK )
OnLeftDClick( aDC, aPosition );
}
break;
case HK_ZOOM_IN:
case HK_ZOOM_OUT:
case HK_ZOOM_REDRAW:
case HK_ZOOM_CENTER:
case HK_ZOOM_AUTO:
// case HK_ZOOM_SELECTION:
case HK_MOVEBLOCK_TO_DRAGBLOCK: // Switch to drag mode, when block moving
case HK_SAVE_BLOCK: // Copy block to paste buffer.
cmd.SetId( hotKey->m_IdMenuEvent );
GetEventHandler()->ProcessEvent( cmd );
break;
case HK_DELETE:
if( notBusy )
DeleteItemAtCrossHair( aDC );
break;
case HK_REPEAT_LAST:
if( notBusy )
RepeatDrawItem( aDC );
break;
case HK_END_CURR_LINEWIREBUS:
// this key terminates a new line/bus/wire in progress
if( aItem && aItem->IsNew() &&
aItem->Type() == SCH_LINE_T )
{
cmd.SetId( hotKey->m_IdMenuEvent );
GetEventHandler()->ProcessEvent( cmd );
}
break;
case HK_UNDO: // Hot keys that map to command IDs that cannot be called
case HK_REDO: // while busy performing another command.
case HK_FIND_ITEM:
case HK_FIND_REPLACE:
case HK_DELETE_NODE:
case HK_LEAVE_SHEET:
if( notBusy )
{
cmd.SetId( hotKey->m_IdMenuEvent );
GetEventHandler()->ProcessEvent( cmd );
}
break;
case HK_FIND_NEXT_ITEM:
case HK_FIND_NEXT_DRC_MARKER:
if( notBusy )
{
wxFindDialogEvent event( hotKey->m_IdMenuEvent, GetId() );
event.SetEventObject( this );
event.SetFlags( m_findReplaceData->GetFlags() );
event.SetFindString( m_findReplaceData->GetFindString() );
GetEventHandler()->ProcessEvent( event );
}
break;
case HK_ADD_NEW_COMPONENT: // Add component
case HK_ADD_NEW_POWER: // Add power component
case HK_ADD_LABEL:
case HK_ADD_HLABEL:
case HK_ADD_GLABEL:
case HK_ADD_JUNCTION:
case HK_ADD_WIRE_ENTRY:
case HK_ADD_BUS_ENTRY:
case HK_ADD_HIER_SHEET:
case HK_ADD_GRAPHIC_TEXT:
case HK_ADD_GRAPHIC_POLYLINE:
case HK_ADD_NOCONN_FLAG: // Add a no connected flag
case HK_BEGIN_BUS:
case HK_BEGIN_WIRE:
if( notBusy )
{
EDA_HOTKEY_CLIENT_DATA data( aPosition );
cmd.SetInt( aHotKey );
cmd.SetClientObject( &data );
cmd.SetId( hotKey->m_IdMenuEvent );
GetEventHandler()->ProcessEvent( cmd );
}
else if( aItem && aItem->IsNew() )
{
// If the item is a bus or a wire, a begin command is not possible.
if( (GetToolId() == ID_BUS_BUTT) && (aItem->Type() == SCH_LINE_T) )
{
SCH_LINE* segment = (SCH_LINE*) aItem;
if( segment->GetLayer() != LAYER_BUS )
break;
// Bus in progress:
OnLeftClick( aDC, aPosition );
}
else if( (GetToolId() == ID_WIRE_BUTT ) && (aItem->Type() == SCH_LINE_T) )
{
SCH_LINE* segment = (SCH_LINE*) aItem;
if( segment->GetLayer() != LAYER_WIRE )
break;
// Wire in progress:
OnLeftClick( aDC, aPosition );
}
}
break;
case HK_COPY_COMPONENT_OR_LABEL: // Duplicate component or text/label
if( itemInEdit )
break;
if( aItem == NULL )
{
aItem = LocateAndShowItem( aPosition, SCH_COLLECTOR::MovableItems );
if( aItem == NULL )
break;
}
cmd.SetId( hotKey->m_IdMenuEvent );
wxPostEvent( this, cmd );
break;
case HK_DRAG: // Start drag
case HK_MOVE_COMPONENT_OR_ITEM: // Start move schematic item.
if( ! notBusy )
break;
// Fall through
case HK_EDIT:
// Edit schematic item. Do not allow sheet edition when mowing
// Because a sheet edition can be complex.
if( itemInEdit && screen->GetCurItem()->Type() == SCH_SHEET_T )
break;
// Fall through
case HK_EDIT_COMPONENT_VALUE: // Edit component value field.
case HK_EDIT_COMPONENT_REFERENCE: // Edit component value reference.
case HK_EDIT_COMPONENT_FOOTPRINT: // Edit component footprint field.
case HK_MIRROR_Y: // Mirror Y
case HK_MIRROR_X: // Mirror X
case HK_ORIENT_NORMAL_COMPONENT: // Orient 0, no mirror (Component)
case HK_ROTATE: // Rotate schematic item.
case HK_EDIT_COMPONENT_WITH_LIBEDIT: // Call Libedit and load the current component
{
// force a new item search on hot keys at current position,
// if there is no currently edited item,
// to avoid using a previously selected item
if( ! itemInEdit )
screen->SetCurItem( NULL );
EDA_HOTKEY_CLIENT_DATA data( aPosition );
cmd.SetInt( hotKey->m_Idcommand );
cmd.SetClientObject( &data );
cmd.SetId( hotKey->m_IdMenuEvent );
GetEventHandler()->ProcessEvent( cmd );
}
break;
}
// Hot key handled.
return true;
}
EDA_HOTKEY* LIB_EDIT_FRAME::GetHotKeyDescription( int aCommand ) const
{
EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, common_Hotkey_List );
if( HK_Descr == NULL )
HK_Descr = GetDescriptorFromCommand( aCommand, libEdit_Hotkey_List );
return HK_Descr;
}
bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem )
{
if( aHotKey == 0 )
return false;
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* hotKey = GetDescriptorFromHotkey( aHotKey, common_Hotkey_List );
if( hotKey == NULL )
hotKey = GetDescriptorFromHotkey( aHotKey, libEdit_Hotkey_List );
if( hotKey == NULL )
return false;
bool itemInEdit = m_drawItem && m_drawItem->InEditMode();
bool blocInProgress = GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK;
switch( hotKey->m_Idcommand )
{
default:
case HK_NOT_FOUND:
return false;
case HK_HELP: // Display Current hotkey list
DisplayHotkeyList( this, g_Libedit_Hokeys_Descr );
break;
case HK_RESET_LOCAL_COORD: // Reset the relative coord
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_ZOOM_IN:
case HK_ZOOM_OUT:
case HK_ZOOM_REDRAW:
case HK_ZOOM_CENTER:
case HK_ZOOM_AUTO:
cmd.SetId( hotKey->m_IdMenuEvent );
GetEventHandler()->ProcessEvent( cmd );
break;
case HK_UNDO:
case HK_REDO:
if( !itemInEdit )
{
cmd.SetId( hotKey->m_IdMenuEvent );
GetEventHandler()->ProcessEvent( cmd );
}
break;
case HK_REPEAT_LAST:
if( ! itemInEdit )
{
if( m_lastDrawItem && !m_lastDrawItem->InEditMode() &&
( m_lastDrawItem->Type() == LIB_PIN_T ) )
RepeatPinItem( aDC, (LIB_PIN*) m_lastDrawItem );
}
break;
case HK_EDIT:
if( !itemInEdit )
m_drawItem = LocateItemUsingCursor( aPosition );
if( m_drawItem )
{
switch( m_drawItem->Type() )
{
case LIB_PIN_T:
cmd.SetId( ID_LIBEDIT_EDIT_PIN );
GetEventHandler()->ProcessEvent( cmd );
break;
case LIB_ARC_T:
case LIB_CIRCLE_T:
case LIB_RECTANGLE_T:
case LIB_POLYLINE_T:
case LIB_TEXT_T:
cmd.SetId( ID_POPUP_LIBEDIT_BODY_EDIT_ITEM );
GetEventHandler()->ProcessEvent( cmd );
break;
case LIB_FIELD_T:
cmd.SetId( ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM );
GetEventHandler()->ProcessEvent( cmd );
break;
default:
break;
}
}
break;
case HK_ROTATE:
if( blocInProgress )
{
GetScreen()->m_BlockLocate.SetCommand( BLOCK_ROTATE );
HandleBlockPlace( aDC );
}
else
{
if( !itemInEdit )
m_drawItem = LocateItemUsingCursor( aPosition );
if( m_drawItem )
{
cmd.SetId( ID_LIBEDIT_ROTATE_ITEM );
GetEventHandler()->ProcessEvent( cmd );
}
}
break;
case HK_LIBEDIT_CREATE_PIN:
if( ! itemInEdit )
{
SetToolID( ID_LIBEDIT_PIN_BUTT, wxCURSOR_PENCIL, _( "Add Pin" ) );
OnLeftClick( aDC, aPosition );
}
break;
case HK_DELETE:
if( !itemInEdit )
m_drawItem = LocateItemUsingCursor( aPosition );
if( m_drawItem && !m_drawItem->InEditMode() )
{
cmd.SetId( ID_POPUP_LIBEDIT_DELETE_ITEM );
Process_Special_Functions( cmd );
}
break;
case HK_LIBEDIT_MOVE_GRAPHIC_ITEM:
if( !itemInEdit )
{
m_drawItem = LocateItemUsingCursor( aPosition );
if( m_drawItem )
{
cmd.SetId( ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST );
Process_Special_Functions( cmd );
}
}
break;
case HK_DRAG:
if( !itemInEdit )
{
m_drawItem = LocateItemUsingCursor( aPosition );
if( m_drawItem && !m_drawItem->InEditMode() )
{
cmd.SetId( ID_POPUP_LIBEDIT_MODIFY_ITEM );
Process_Special_Functions( cmd );
}
}
break;
}
// Hot key handled.
return true;
}
EDA_HOTKEY* LIB_VIEW_FRAME::GetHotKeyDescription( int aCommand ) const
{
EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, common_Hotkey_List );
if( HK_Descr == NULL )
HK_Descr = GetDescriptorFromCommand( aCommand, viewlib_Hotkey_List );
return HK_Descr;
}
bool LIB_VIEW_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem )
{
if( aHotKey == 0 )
return false;
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_basic_Hotkey_List );
if( HK_Descr == NULL )
HK_Descr = GetDescriptorFromHotkey( aHotKey, viewlib_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_Viewlib_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_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_ZOOM_AUTO:
cmd.SetId( ID_ZOOM_PAGE );
GetEventHandler()->ProcessEvent( cmd );
break;
}
return true;
}
|