KiCad PCB EDA Suite
pagelayout_editor/hotkeys.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) 2013 CERN
5  * Copyright (C) 2016-2018 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
30 #include <fctsys.h>
31 #include <common.h>
32 #include <kicad_device_context.h>
33 #include <id.h>
34 
35 #include <class_drawpanel.h>
36 #include <pl_editor_frame.h>
37 #include <design_tree_frame.h>
38 #include <worksheet_dataitem.h>
39 #include <hotkeys.h>
40 #include <pl_editor_id.h>
41 
42 
43 // Remark: the hotkey message info is used as keyword in hotkey config files and
44 // as comments in help windows, therefore translated only when displayed
45 // they are marked _HKI to be extracted by translation tools
46 // See hotkeys_basic.h for more info
47 
48 
49 /* How to add a new hotkey:
50  * add a new id in the enum hotkey_id_commnand like MY_NEW_ID_FUNCTION.
51  * add a new EDA_HOTKEY entry like:
52  * static EDA_HOTKEY HkMyNewEntry(_HKI("Command Label"), MY_NEW_ID_FUNCTION, default key value);
53  * 'Command Label' is the name used in hotkey list display, and the identifier in the
54  * hotkey list file
55  * 'MY_NEW_ID_FUNCTION' is the id event function used in the switch in OnHotKey() function.
56  * 'Default key value' is the default hotkey for this command.
57  * Can be overrided by the user hotkey list
58  * Add the 'HkMyNewEntry' pointer in the s_PlEditor_Hotkey_List list
59  * Add the new code in the switch in OnHotKey() function.
60  *
61  * Note: If an hotkey is a special key, be sure the corresponding wxWidget keycode (WXK_XXXX)
62  * is handled in the hotkey_name_descr s_Hotkey_Name_List list (see hotkeys_basic.cpp)
63  * and see this list for some ascii keys (space ...)
64  */
65 
66 // Hotkey list:
67 
68 // mouse click command:
69 static EDA_HOTKEY HkMouseLeftClick( _HKI( "Mouse Left Click" ), HK_LEFT_CLICK, WXK_RETURN, 0 );
70 static EDA_HOTKEY HkMouseLeftDClick( _HKI( "Mouse Left Double Click" ), HK_LEFT_DCLICK,
71  WXK_END, 0 );
72 
73 static EDA_HOTKEY HkResetLocalCoord( _HKI( "Reset Local Coordinates" ),
74  HK_RESET_LOCAL_COORD, ' ' );
75 static EDA_HOTKEY HkZoomAuto( _HKI( "Zoom Auto" ), HK_ZOOM_AUTO, WXK_HOME, ID_ZOOM_PAGE );
76 static EDA_HOTKEY HkZoomCenter( _HKI( "Zoom Center" ), HK_ZOOM_CENTER, WXK_F4,
78 static EDA_HOTKEY HkZoomRedraw( _HKI( "Zoom Redraw" ), HK_ZOOM_REDRAW, WXK_F3, ID_ZOOM_REDRAW );
79 static EDA_HOTKEY HkZoomOut( _HKI( "Zoom Out" ), HK_ZOOM_OUT, WXK_F2, ID_KEY_ZOOM_OUT );
80 static EDA_HOTKEY HkZoomIn( _HKI( "Zoom In" ), HK_ZOOM_IN, WXK_F1, ID_KEY_ZOOM_IN );
81 static EDA_HOTKEY HkZoomSelection( _HKI( "Zoom to Selection" ), HK_ZOOM_SELECTION,
82  GR_KB_CTRL + WXK_F5, ID_ZOOM_SELECTION );
83 static EDA_HOTKEY HkHelp( _HKI( "Help (this window)" ), HK_HELP, GR_KB_CTRL + WXK_F1 );
84 static EDA_HOTKEY HkMoveItem( _HKI( "Move Item" ), HK_MOVE_ITEM, 'M', ID_POPUP_ITEM_MOVE );
85 static EDA_HOTKEY HkPlaceItem( _HKI( "Place Item" ), HK_PLACE_ITEM, 'P', ID_POPUP_ITEM_PLACE );
86 static EDA_HOTKEY HkMoveStartPoint( _HKI( "Move Start Point" ), HK_MOVE_START_POINT, 'S',
88 static EDA_HOTKEY HkMoveEndPoint( _HKI( "Move End Point" ), HK_MOVE_END_POINT, 'E',
90 static EDA_HOTKEY HkDeleteItem( _HKI( "Delete Item" ), HK_DELETE_ITEM, WXK_DELETE,
92 
93 // Common: hotkeys_basic.h
94 static EDA_HOTKEY HkUndo( _HKI( "Undo" ), HK_UNDO, GR_KB_CTRL + 'Z', (int) wxID_UNDO );
95 static EDA_HOTKEY HkRedo( _HKI( "Redo" ), HK_REDO, GR_KB_CTRL + 'Y', (int) wxID_REDO );
96 static EDA_HOTKEY HkNew( _HKI( "New" ), HK_NEW, GR_KB_CTRL + 'N', (int) wxID_NEW );
97 static EDA_HOTKEY HkOpen( _HKI( "Open" ), HK_OPEN, GR_KB_CTRL + 'O', (int) wxID_OPEN );
98 static EDA_HOTKEY HkSave( _HKI( "Save" ), HK_SAVE, GR_KB_CTRL + 'S', (int) wxID_SAVE );
99 static EDA_HOTKEY HkSaveAs( _HKI( "Save As" ), HK_SAVEAS, GR_KB_CTRL + GR_KB_SHIFT + 'S',
100  (int) wxID_SAVEAS );
101 static EDA_HOTKEY HkPrint( _HKI( "Print" ), HK_PRINT, GR_KB_CTRL + 'P', (int) wxID_PRINT );
102 
103 // List of common hotkey descriptors
105 {
107  &HkUndo, &HkRedo,
110  &HkHelp,
113  NULL
114 };
115 
117 {
120  &HkPlaceItem,
121  &HkDeleteItem,
122  NULL
123 };
124 
125 // Titles for hotkey editor and hotkey display
126 static wxString commonSectionTitle( _HKI( "Common" ) );
127 
128 // list of sections and corresponding hotkey list for Pl_Editor
129 // (used to create an hotkey config file)
130 static wxString s_PlEditorSectionTag( wxT( "[pl_editor]" ) );
131 static wxString s_PlEditorSectionTitle( _HKI( "Page Layout Editor" ) );
132 
134 {
135  { &g_CommonSectionTag, s_Common_Hotkey_List, &commonSectionTitle },
136  { &s_PlEditorSectionTag, s_PlEditor_Hotkey_List, &s_PlEditorSectionTitle },
137  { NULL, NULL, NULL }
138 };
139 
140 
142 {
143  EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, s_Common_Hotkey_List );
144 
145  if( HK_Descr == NULL )
146  HK_Descr = GetDescriptorFromCommand( aCommand, s_PlEditor_Hotkey_List );
147 
148  return HK_Descr;
149 }
150 
151 
152 bool PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode,
153  const wxPoint& aPosition, EDA_ITEM* aItem )
154 {
155  bool busy = GetScreen()->GetCurItem() != NULL;
156  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
157  cmd.SetEventObject( this );
158 
159  /* Convert lower to upper case (the usual toupper function has problem with non ascii
160  * codes like function keys */
161  if( (aHotkeyCode >= 'a') && (aHotkeyCode <= 'z') )
162  aHotkeyCode += 'A' - 'a';
163 
164  EDA_HOTKEY * HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, s_PlEditor_Hotkey_List );
165 
166  if( HK_Descr == NULL )
167  HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, s_Common_Hotkey_List );
168 
169  if( HK_Descr == NULL )
170  return false;
171 
172  WORKSHEET_DATAITEM* item;
173 
174  switch( HK_Descr->m_Idcommand )
175  {
176  case HK_NOT_FOUND:
177  return false;
178 
179  case HK_LEFT_CLICK:
180  OnLeftClick( aDC, aPosition );
181  break;
182 
183  case HK_LEFT_DCLICK: // Simulate a double left click: generate 2 events
184  OnLeftClick( aDC, aPosition );
185  OnLeftDClick( aDC, aPosition );
186  break;
187 
188  case HK_NEW:
189  cmd.SetId( wxID_NEW );
190  GetEventHandler()->ProcessEvent( cmd );
191  break;
192 
193  case HK_OPEN:
194  cmd.SetId( wxID_OPEN );
195  GetEventHandler()->ProcessEvent( cmd );
196  break;
197 
198  case HK_SAVE:
199  cmd.SetId( wxID_SAVE );
200  GetEventHandler()->ProcessEvent( cmd );
201  break;
202 
203  case HK_SAVEAS:
204  cmd.SetId( wxID_SAVEAS );
205  GetEventHandler()->ProcessEvent( cmd );
206  break;
207 
208  case HK_PRINT:
209  cmd.SetId( wxID_PRINT );
210  GetEventHandler()->ProcessEvent( cmd );
211  break;
212 
213  case HK_UNDO:
214  case HK_REDO:
215  if( busy )
216  break;
217  cmd.SetId( HK_Descr->m_IdMenuEvent );
218  GetEventHandler()->ProcessEvent( cmd );
219  break;
220 
221  case HK_ZOOM_IN:
222  cmd.SetId( ID_POPUP_ZOOM_IN );
223  GetEventHandler()->ProcessEvent( cmd );
224  break;
225 
226  case HK_ZOOM_OUT:
227  cmd.SetId( ID_POPUP_ZOOM_OUT );
228  GetEventHandler()->ProcessEvent( cmd );
229  break;
230 
231  case HK_ZOOM_REDRAW:
232  cmd.SetId( ID_ZOOM_REDRAW );
233  GetEventHandler()->ProcessEvent( cmd );
234  break;
235 
236  case HK_ZOOM_CENTER:
237  cmd.SetId( ID_POPUP_ZOOM_CENTER );
238  GetEventHandler()->ProcessEvent( cmd );
239  break;
240 
241  case HK_ZOOM_AUTO:
242  cmd.SetId( ID_ZOOM_PAGE );
243  GetEventHandler()->ProcessEvent( cmd );
244  break;
245 
246  case HK_ZOOM_SELECTION:
247  cmd.SetId( ID_ZOOM_SELECTION );
248  GetEventHandler()->ProcessEvent( cmd );
249  break;
250 
251  case HK_RESET_LOCAL_COORD: // Reset the relative coord
253  break;
254 
255  case HK_HELP: // Display Current hotkey list
256  DisplayHotkeyList( this, PlEditorHokeysDescr );
257  break;
258 
259  case HK_SET_GRID_ORIGIN:
261  break;
262 
263  case HK_MOVE_ITEM:
264  case HK_MOVE_START_POINT:
265  case HK_MOVE_END_POINT:
266  case HK_DELETE_ITEM:
267  if( busy )
268  break;
269 
270  if( (item = Locate( aDC, aPosition ) ) == NULL )
271  break;
272 
273  // Only rect and lines have a end point.
274  if( HK_Descr->m_Idcommand == HK_MOVE_END_POINT && !item->HasEndPoint() )
275  break;
276 
278  m_treePagelayout->SelectCell( item );
279 
280  cmd.SetId( HK_Descr->m_IdMenuEvent );
281  GetEventHandler()->ProcessEvent( cmd );
282  break;
283 
284  case HK_PLACE_ITEM:
285  if( busy )
286  {
287  cmd.SetId( HK_Descr->m_IdMenuEvent );
288  GetEventHandler()->ProcessEvent( cmd );
289  }
290  break;
291 
292  default:
293  wxMessageBox( wxT( "Unknown hotkey" ) );
294  return false;
295  }
296 
297  return true;
298 }
static EDA_HOTKEY HkMouseLeftDClick(_HKI("Mouse Left Double Click"), HK_LEFT_DCLICK, WXK_END, 0)
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:94
WORKSHEET_DATAITEM * GetCurItem() const
Function GetCurItem returns the currently selected WORKSHEET_DATAITEM, overriding BASE_SCREEN::GetCur...
bool OnHotKey(wxDC *aDC, int aHotkeyCode, const wxPoint &aPosition, EDA_ITEM *aItem=NULL) override
Function OnHotKey.
virtual bool HasEndPoint()
static EDA_HOTKEY HkPrint(_HKI("Print"), HK_PRINT, GR_KB_CTRL+ 'P',(int) wxID_PRINT)
static EDA_HOTKEY HkZoomIn(_HKI("Zoom In"), HK_ZOOM_IN, WXK_F1, ID_KEY_ZOOM_IN)
static EDA_HOTKEY HkSaveAs(_HKI("Save As"), HK_SAVEAS, GR_KB_CTRL+GR_KB_SHIFT+ 'S',(int) wxID_SAVEAS)
static EDA_HOTKEY HkMouseLeftClick(_HKI("Mouse Left Click"), HK_LEFT_CLICK, WXK_RETURN, 0)
static wxString s_PlEditorSectionTitle(_HKI("Page Layout Editor"))
#define GR_KB_CTRL
static wxString s_PlEditorSectionTag(wxT("[pl_editor]"))
void SelectCell(WORKSHEET_DATAITEM *aItem)
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:185
EDA_HOTKEY * GetHotKeyDescription(int aCommand) const override
>
static EDA_HOTKEY HkResetLocalCoord(_HKI("Reset Local Coordinates"), HK_RESET_LOCAL_COORD, ' ')
EDA_HOTKEY * GetDescriptorFromHotkey(int aKey, EDA_HOTKEY **aList)
Function GetDescriptorFromHotkey Return a EDA_HOTKEY * pointer from a key code for OnHotKey() functio...
void DisplayHotkeyList(EDA_BASE_FRAME *aFrame, struct EDA_HOTKEY_CONFIG *aDescList)
Function DisplayHotkeyList Displays the current hotkey list.
static EDA_HOTKEY HkOpen(_HKI("Open"), HK_OPEN, GR_KB_CTRL+ 'O',(int) wxID_OPEN)
a helper to handle the real device context used in KiCad
static EDA_HOTKEY HkMoveStartPoint(_HKI("Move Start Point"), HK_MOVE_START_POINT, 'S', ID_POPUP_ITEM_MOVE_START_POINT)
static wxString commonSectionTitle(_HKI("Common"))
void OnLeftDClick(wxDC *aDC, const wxPoint &aMousePos) override
EDA_HOTKEY * s_Common_Hotkey_List[]
static EDA_HOTKEY HkMoveItem(_HKI("Move Item"), HK_MOVE_ITEM, 'M', ID_POPUP_ITEM_MOVE)
static EDA_HOTKEY HkSave(_HKI("Save"), HK_SAVE, GR_KB_CTRL+ 'S',(int) wxID_SAVE)
description of graphic items and texts to build a title block
PL_EDITOR_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
static EDA_HOTKEY HkPlaceItem(_HKI("Place Item"), HK_PLACE_ITEM, 'P', ID_POPUP_ITEM_PLACE)
WORKSHEET_DATAITEM * Locate(wxDC *aDC, const wxPoint &aPosition)
Function Locate.
#define GR_KB_SHIFT
EDA_HOTKEY * s_PlEditor_Hotkey_List[]
static EDA_HOTKEY HkNew(_HKI("New"), HK_NEW, GR_KB_CTRL+ 'N',(int) wxID_NEW)
void OnLeftClick(wxDC *aDC, const wxPoint &aMousePos) override
static EDA_HOTKEY HkZoomAuto(_HKI("Zoom Auto"), HK_ZOOM_AUTO, WXK_HOME, ID_ZOOM_PAGE)
static EDA_HOTKEY HkZoomRedraw(_HKI("Zoom Redraw"), HK_ZOOM_REDRAW, WXK_F3, ID_ZOOM_REDRAW)
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:59
static EDA_HOTKEY HkMoveEndPoint(_HKI("Move End Point"), HK_MOVE_END_POINT, 'E', ID_POPUP_ITEM_MOVE_END_POINT)
static EDA_HOTKEY HkZoomCenter(_HKI("Zoom Center"), HK_ZOOM_CENTER, WXK_F4, ID_POPUP_ZOOM_CENTER)
void SetGridOrigin(const wxPoint &aPoint) override
static EDA_HOTKEY HkUndo(_HKI("Undo"), HK_UNDO, GR_KB_CTRL+ 'Z',(int) wxID_UNDO)
static EDA_HOTKEY HkRedo(_HKI("Redo"), HK_REDO, GR_KB_CTRL+ 'Y',(int) wxID_REDO)
static EDA_HOTKEY HkZoomOut(_HKI("Zoom Out"), HK_ZOOM_OUT, WXK_F2, ID_KEY_ZOOM_OUT)
struct EDA_HOTKEY_CONFIG PlEditorHokeysDescr[]
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
The common library.
wxString g_CommonSectionTag
static EDA_HOTKEY HkDeleteItem(_HKI("Delete Item"), HK_DELETE_ITEM, WXK_DELETE, ID_POPUP_ITEM_DELETE)
#define _HKI(x)
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
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.
static EDA_HOTKEY HkZoomSelection(_HKI("Zoom to Selection"), HK_ZOOM_SELECTION, GR_KB_CTRL+WXK_F5, ID_ZOOM_SELECTION)
WORKSHEET_DATAITEM * GetPageLayoutSelectedItem() const
DESIGN_TREE_FRAME * m_treePagelayout
static EDA_HOTKEY HkHelp(_HKI("Help (this window)"), HK_HELP, GR_KB_CTRL+WXK_F1)