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 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>
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, WXK_END, 0 );
71 
72 static EDA_HOTKEY HkResetLocalCoord( _HKI( "Reset Local Coordinates" ),
73  HK_RESET_LOCAL_COORD, ' ' );
74 static EDA_HOTKEY HkZoomAuto( _HKI( "Zoom Auto" ), HK_ZOOM_AUTO, WXK_HOME, ID_ZOOM_PAGE );
75 static EDA_HOTKEY HkZoomCenter( _HKI( "Zoom Center" ), HK_ZOOM_CENTER, WXK_F4,
77 static EDA_HOTKEY HkZoomRedraw( _HKI( "Zoom Redraw" ), HK_ZOOM_REDRAW, WXK_F3, ID_ZOOM_REDRAW );
78 static EDA_HOTKEY HkZoomOut( _HKI( "Zoom Out" ), HK_ZOOM_OUT, WXK_F2, ID_POPUP_ZOOM_OUT );
79 static EDA_HOTKEY HkZoomIn( _HKI( "Zoom In" ), HK_ZOOM_IN, WXK_F1, ID_POPUP_ZOOM_IN );
80 static EDA_HOTKEY HkZoomSelection( _HKI( "Zoom to Selection" ), HK_ZOOM_SELECTION, '@', ID_ZOOM_SELECTION );
81 static EDA_HOTKEY HkHelp( _HKI( "Help (this window)" ), HK_HELP, '?' );
82 static EDA_HOTKEY HkMoveItem( _HKI( "Move Item" ), HK_MOVE_ITEM, 'M', ID_POPUP_ITEM_MOVE );
83 static EDA_HOTKEY HkPlaceItem( _HKI( "Place Item" ), HK_PLACE_ITEM, 'P', ID_POPUP_ITEM_PLACE );
84 static EDA_HOTKEY HkMoveStartPoint( _HKI( "Move Start Point" ), HK_MOVE_START_POINT, 'S',
86 static EDA_HOTKEY HkMoveEndPoint( _HKI( "Move End Point" ), HK_MOVE_END_POINT, 'E',
88 static EDA_HOTKEY HkDeleteItem( _HKI( "Delete Item" ), HK_DELETE_ITEM, WXK_DELETE,
90 
91 // Common: hotkeys_basic.h
92 static EDA_HOTKEY HkUndo( _HKI( "Undo" ), HK_UNDO, GR_KB_CTRL + 'Z', (int) wxID_UNDO );
93 static EDA_HOTKEY HkRedo( _HKI( "Redo" ), HK_REDO, GR_KB_CTRL + 'Y', (int) wxID_REDO );
94 static EDA_HOTKEY HkNew( _HKI( "New" ), HK_NEW, GR_KB_CTRL + 'N', (int) wxID_NEW );
95 static EDA_HOTKEY HkOpen( _HKI( "Open" ), HK_OPEN, GR_KB_CTRL + 'O', (int) wxID_OPEN );
96 static EDA_HOTKEY HkSave( _HKI( "Save" ), HK_SAVE, GR_KB_CTRL + 'S', (int) wxID_SAVE );
97 static EDA_HOTKEY HkSaveAs( _HKI( "Save As" ), HK_SAVEAS, GR_KB_CTRL + GR_KB_SHIFT + 'S', (int) wxID_SAVEAS );
98 static EDA_HOTKEY HkPrint( _HKI( "Print" ), HK_PRINT, GR_KB_CTRL + 'P', (int) wxID_PRINT );
99 
100 // List of common hotkey descriptors
102 {
104  &HkUndo, &HkRedo,
107  &HkHelp,
110  NULL
111 };
112 
114 {
117  &HkPlaceItem,
118  &HkDeleteItem,
119  NULL
120 };
121 
122 // Titles for hotkey editor and hotkey display
123 static wxString commonSectionTitle( _HKI( "Common" ) );
124 
125 // list of sections and corresponding hotkey list for Pl_Editor
126 // (used to create an hotkey config file)
127 static wxString s_PlEditorSectionTag( wxT( "[pl_editor]" ) );
128 static wxString s_PlEditorSectionTitle( _HKI( "Page Layout Editor" ) );
129 
131 {
134  { NULL, NULL, NULL }
135 };
136 
137 
139 {
140  EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, s_Common_Hotkey_List );
141 
142  if( HK_Descr == NULL )
143  HK_Descr = GetDescriptorFromCommand( aCommand, s_PlEditor_Hotkey_List );
144 
145  return HK_Descr;
146 }
147 
148 
149 bool PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode,
150  const wxPoint& aPosition, EDA_ITEM* aItem )
151 {
152  bool busy = GetScreen()->GetCurItem() != NULL;
153  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
154  cmd.SetEventObject( this );
155 
156  /* Convert lower to upper case (the usual toupper function has problem with non ascii
157  * codes like function keys */
158  if( (aHotkeyCode >= 'a') && (aHotkeyCode <= 'z') )
159  aHotkeyCode += 'A' - 'a';
160 
161  EDA_HOTKEY * HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, s_PlEditor_Hotkey_List );
162 
163  if( HK_Descr == NULL )
164  HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, s_Common_Hotkey_List );
165 
166  if( HK_Descr == NULL )
167  return false;
168 
169  WORKSHEET_DATAITEM* item;
170 
171  switch( HK_Descr->m_Idcommand )
172  {
173  case HK_NOT_FOUND:
174  return false;
175 
176  case HK_LEFT_CLICK:
177  OnLeftClick( aDC, aPosition );
178  break;
179 
180  case HK_LEFT_DCLICK: // Simulate a double left click: generate 2 events
181  OnLeftClick( aDC, aPosition );
182  OnLeftDClick( aDC, aPosition );
183  break;
184 
185  case HK_NEW:
186  cmd.SetId( wxID_NEW );
187  GetEventHandler()->ProcessEvent( cmd );
188  break;
189 
190  case HK_OPEN:
191  cmd.SetId( wxID_OPEN );
192  GetEventHandler()->ProcessEvent( cmd );
193  break;
194 
195  case HK_SAVE:
196  cmd.SetId( wxID_SAVE );
197  GetEventHandler()->ProcessEvent( cmd );
198  break;
199 
200  case HK_SAVEAS:
201  cmd.SetId( wxID_SAVEAS );
202  GetEventHandler()->ProcessEvent( cmd );
203  break;
204 
205  case HK_PRINT:
206  cmd.SetId( wxID_PRINT );
207  GetEventHandler()->ProcessEvent( cmd );
208  break;
209 
210  case HK_UNDO:
211  case HK_REDO:
212  if( busy )
213  break;
214  cmd.SetId( HK_Descr->m_IdMenuEvent );
215  GetEventHandler()->ProcessEvent( cmd );
216  break;
217 
218  case HK_ZOOM_IN:
219  cmd.SetId( ID_POPUP_ZOOM_IN );
220  GetEventHandler()->ProcessEvent( cmd );
221  break;
222 
223  case HK_ZOOM_OUT:
224  cmd.SetId( ID_POPUP_ZOOM_OUT );
225  GetEventHandler()->ProcessEvent( cmd );
226  break;
227 
228  case HK_ZOOM_REDRAW:
229  cmd.SetId( ID_ZOOM_REDRAW );
230  GetEventHandler()->ProcessEvent( cmd );
231  break;
232 
233  case HK_ZOOM_CENTER:
234  cmd.SetId( ID_POPUP_ZOOM_CENTER );
235  GetEventHandler()->ProcessEvent( cmd );
236  break;
237 
238  case HK_ZOOM_AUTO:
239  cmd.SetId( ID_ZOOM_PAGE );
240  GetEventHandler()->ProcessEvent( cmd );
241  break;
242 
243  case HK_ZOOM_SELECTION:
244  cmd.SetId( ID_ZOOM_SELECTION );
245  GetEventHandler()->ProcessEvent( cmd );
246  break;
247 
248  case HK_RESET_LOCAL_COORD: // Reset the relative coord
250  break;
251 
252  case HK_HELP: // Display Current hotkey list
253  DisplayHotkeyList( this, PlEditorHokeysDescr );
254  break;
255 
256  case HK_SET_GRID_ORIGIN:
258  break;
259 
260  case HK_MOVE_ITEM:
261  case HK_MOVE_START_POINT:
262  case HK_MOVE_END_POINT:
263  case HK_DELETE_ITEM:
264  if( busy )
265  break;
266 
267  if( (item = Locate( aPosition )) == NULL )
268  break;
269 
270  // Only rect and lines have a end point.
271  if( HK_Descr->m_Idcommand == HK_MOVE_END_POINT && !item->HasEndPoint() )
272  break;
273 
275  m_treePagelayout->SelectCell( item );
276 
277  cmd.SetId( HK_Descr->m_IdMenuEvent );
278  GetEventHandler()->ProcessEvent( cmd );
279  break;
280 
281  case HK_PLACE_ITEM:
282  if( busy )
283  {
284  cmd.SetId( HK_Descr->m_IdMenuEvent );
285  GetEventHandler()->ProcessEvent( cmd );
286  }
287  break;
288 
289  default:
290  wxMessageBox( wxT( "Unknown hotkey" ) );
291  return false;
292  }
293 
294  return true;
295 }
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:87
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.
static EDA_HOTKEY HkZoomOut(_HKI("Zoom Out"), HK_ZOOM_OUT, WXK_F2, ID_POPUP_ZOOM_OUT)
static EDA_HOTKEY HkPrint(_HKI("Print"), HK_PRINT, GR_KB_CTRL+ 'P',(int) wxID_PRINT)
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"))
description of graphic items and texts to build a title block
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.
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
#define GR_KB_SHIFT
Definition: common.h:66
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)
WORKSHEET_DATAITEM * Locate(const wxPoint &aPosition)
Function Locate.
PL_EDITOR_SCREEN * GetScreen() const override
Function GetScreen returns 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)
EDA_HOTKEY * s_PlEditor_Hotkey_List[]
static EDA_HOTKEY HkZoomIn(_HKI("Zoom In"), HK_ZOOM_IN, WXK_F1, ID_POPUP_ZOOM_IN)
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 HkZoomSelection(_HKI("Zoom to Selection"), HK_ZOOM_SELECTION, '@', ID_ZOOM_SELECTION)
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:57
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)
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:165
The common library.
wxString g_CommonSectionTag
static EDA_HOTKEY HkDeleteItem(_HKI("Delete Item"), HK_DELETE_ITEM, WXK_DELETE, ID_POPUP_ITEM_DELETE)
#define GR_KB_CTRL
Definition: common.h:64
#define _HKI(x)
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
static EDA_HOTKEY HkHelp(_HKI("Help (this window)"), HK_HELP, '?')
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.
WORKSHEET_DATAITEM * GetPageLayoutSelectedItem() const
DESIGN_TREE_FRAME * m_treePagelayout