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 // Undo Redo
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 
95 // List of common hotkey descriptors
97 {
98  &HkHelp,
101  &HkUndo, &HkRedo,
104  NULL
105 };
106 
108 {
111  &HkPlaceItem,
112  &HkDeleteItem,
113  NULL
114 };
115 
116 // Titles for hotkey editor and hotkey display
117 static wxString commonSectionTitle( _HKI( "Common" ) );
118 
119 // list of sections and corresponding hotkey list for Pl_Editor
120 // (used to create an hotkey config file)
121 static wxString s_PlEditorSectionTag( wxT( "[pl_editor]" ) );
122 static wxString s_PlEditorSectionTitle( _HKI( "Page Layout Editor" ) );
123 
125 {
128  { NULL, NULL, NULL }
129 };
130 
131 
133 {
134  EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, s_Common_Hotkey_List );
135 
136  if( HK_Descr == NULL )
137  HK_Descr = GetDescriptorFromCommand( aCommand, s_PlEditor_Hotkey_List );
138 
139  return HK_Descr;
140 }
141 
142 
143 bool PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode,
144  const wxPoint& aPosition, EDA_ITEM* aItem )
145 {
146  bool busy = GetScreen()->GetCurItem() != NULL;
147  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
148  cmd.SetEventObject( this );
149 
150  /* Convert lower to upper case (the usual toupper function has problem with non ascii
151  * codes like function keys */
152  if( (aHotkeyCode >= 'a') && (aHotkeyCode <= 'z') )
153  aHotkeyCode += 'A' - 'a';
154 
155  EDA_HOTKEY * HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, s_PlEditor_Hotkey_List );
156 
157  if( HK_Descr == NULL )
158  HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, s_Common_Hotkey_List );
159 
160  if( HK_Descr == NULL )
161  return false;
162 
163  WORKSHEET_DATAITEM* item;
164 
165  switch( HK_Descr->m_Idcommand )
166  {
167  case HK_NOT_FOUND:
168  return false;
169 
170  case HK_LEFT_CLICK:
171  OnLeftClick( aDC, aPosition );
172  break;
173 
174  case HK_LEFT_DCLICK: // Simulate a double left click: generate 2 events
175  OnLeftClick( aDC, aPosition );
176  OnLeftDClick( aDC, aPosition );
177  break;
178 
179  case HK_HELP: // Display Current hotkey list
180  DisplayHotkeyList( this, PlEditorHokeysDescr );
181  break;
182 
183  case HK_UNDO:
184  case HK_REDO:
185  if( busy )
186  break;
187  cmd.SetId( HK_Descr->m_IdMenuEvent );
188  GetEventHandler()->ProcessEvent( cmd );
189  break;
190 
191  case HK_ZOOM_IN:
192  cmd.SetId( ID_POPUP_ZOOM_IN );
193  GetEventHandler()->ProcessEvent( cmd );
194  break;
195 
196  case HK_ZOOM_OUT:
197  cmd.SetId( ID_POPUP_ZOOM_OUT );
198  GetEventHandler()->ProcessEvent( cmd );
199  break;
200 
201  case HK_ZOOM_REDRAW:
202  cmd.SetId( ID_ZOOM_REDRAW );
203  GetEventHandler()->ProcessEvent( cmd );
204  break;
205 
206  case HK_ZOOM_CENTER:
207  cmd.SetId( ID_POPUP_ZOOM_CENTER );
208  GetEventHandler()->ProcessEvent( cmd );
209  break;
210 
211  case HK_ZOOM_AUTO:
212  cmd.SetId( ID_ZOOM_PAGE );
213  GetEventHandler()->ProcessEvent( cmd );
214  break;
215 
216  case HK_ZOOM_SELECTION:
217  cmd.SetId( ID_ZOOM_SELECTION );
218  GetEventHandler()->ProcessEvent( cmd );
219  break;
220 
221  case HK_RESET_LOCAL_COORD: // Reset the relative coord
223  break;
224 
225  case HK_SET_GRID_ORIGIN:
227  break;
228 
229  case HK_MOVE_ITEM:
230  case HK_MOVE_START_POINT:
231  case HK_MOVE_END_POINT:
232  case HK_DELETE_ITEM:
233  if( busy )
234  break;
235 
236  if( (item = Locate( aPosition )) == NULL )
237  break;
238 
239  // Only rect and lines have a end point.
240  if( HK_Descr->m_Idcommand == HK_MOVE_END_POINT && !item->HasEndPoint() )
241  break;
242 
244  m_treePagelayout->SelectCell( item );
245 
246  cmd.SetId( HK_Descr->m_IdMenuEvent );
247  GetEventHandler()->ProcessEvent( cmd );
248  break;
249 
250  case HK_PLACE_ITEM:
251  if( busy )
252  {
253  cmd.SetId( HK_Descr->m_IdMenuEvent );
254  GetEventHandler()->ProcessEvent( cmd );
255  }
256  break;
257 
258  default:
259  wxMessageBox( wxT( "Unknown hotkey" ) );
260  return false;
261  }
262 
263  return true;
264 }
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 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.
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)
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)
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:151
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:65
#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