KiCad PCB EDA Suite
gerbview/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) 1992-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
29 #include <fctsys.h>
30 #include <common.h>
31 #include <gerbview_id.h>
32 
33 #include <gerbview.h>
34 #include <gerbview_frame.h>
35 #include <class_drawpanel.h>
36 #include <gerbview_layer_widget.h>
37 #include <hotkeys.h>
38 
39 
40 /* How to add a new hotkey:
41  * add a new id in the enum hotkey_id_command like MY_NEW_ID_FUNCTION.
42  * add a new EDA_HOTKEY entry like:
43  * static EDA_HOTKEY HkMyNewEntry(wxT("Command Label"), MY_NEW_ID_FUNCTION, default key value);
44  * "Command Label" is the name used in hotkey list display, and the identifier in the
45  * hotkey list file MY_NEW_ID_FUNCTION is an equivalent id function used in the switch
46  * in OnHotKey() function. default key value is the default hotkey for this command.
47  * Can be overrided by the user hotkey list file add the HkMyNewEntry pointer in the
48  * s_board_edit_Hotkey_List list ( or/and the s_module_edit_Hotkey_List list) Add the
49  * new code in the switch in OnHotKey() function. when the variable PopupOn is true,
50  * an item is currently edited. This can be usefull if the new function cannot be
51  * executed while an item is currently being edited
52  * ( For example, one cannot start a new wire when a component is moving.)
53  *
54  * Note: If an hotkey is a special key, be sure the corresponding wxWidget keycode (WXK_XXXX)
55  * is handled in the hotkey_name_descr s_Hotkey_Name_List list (see hotkeys_basic.cpp)
56  * and see this list for some ascii keys (space ...)
57  */
58 
59 // local variables
60 // Hotkey list:
61 static EDA_HOTKEY HkZoomAuto( _HKI( "Zoom Auto" ), HK_ZOOM_AUTO, WXK_HOME );
62 static EDA_HOTKEY HkZoomCenter( _HKI( "Zoom Center" ), HK_ZOOM_CENTER, WXK_F4 );
63 static EDA_HOTKEY HkZoomRedraw( _HKI( "Zoom Redraw" ), HK_ZOOM_REDRAW, WXK_F3 );
64 static EDA_HOTKEY HkZoomOut( _HKI( "Zoom Out" ), HK_ZOOM_OUT, WXK_F2 );
65 static EDA_HOTKEY HkZoomIn( _HKI( "Zoom In" ), HK_ZOOM_IN, WXK_F1 );
66 static EDA_HOTKEY HkZoomSelection( _HKI( "Zoom to Selection" ),
67  HK_ZOOM_SELECTION, GR_KB_CTRL + WXK_F5 );
68 static EDA_HOTKEY HkPreferences( _HKI( "Preferences" ),
69  HK_PREFERENCES, GR_KB_CTRL + ',', (int) wxID_PREFERENCES );
70 static EDA_HOTKEY HkHelp( _HKI( "List Hotkeys" ), HK_HELP, GR_KB_CTRL + WXK_F1 );
71 static EDA_HOTKEY HkSwitchUnits( _HKI( "Switch Units" ), HK_SWITCH_UNITS, 'U' );
72 static EDA_HOTKEY HkResetLocalCoord( _HKI( "Reset Local Coordinates" ),
73  HK_RESET_LOCAL_COORD, ' ' );
74 static EDA_HOTKEY HkSwitchHighContrastMode( _HKI( "Toggle High Contrast Mode" ),
76 
77 static EDA_HOTKEY HkLinesDisplayMode( _HKI( "Gbr Lines Display Mode" ),
79 static EDA_HOTKEY HkFlashedDisplayMode( _HKI( "Gbr Flashed Display Mode" ),
81 static EDA_HOTKEY HkPolygonDisplayMode( _HKI( "Gbr Polygons Display Mode" ),
83 static EDA_HOTKEY HkNegativeObjDisplayMode( _HKI( "Gbr Negative Obj Display Mode" ),
85 static EDA_HOTKEY HkDCodesDisplayMode( _HKI( "DCodes Display Mode" ),
87 
88 static EDA_HOTKEY HkSwitch2NextCopperLayer( _HKI( "Switch to Next Layer" ),
90 static EDA_HOTKEY HkSwitch2PreviousCopperLayer( _HKI( "Switch to Previous Layer" ),
92 
93 static EDA_HOTKEY HkCanvasDefault( _HKI( "Switch to Legacy Toolset" ),
95 #ifdef __WXMAC__
96  GR_KB_ALT +
97 #endif
98  WXK_F9 );
99 static EDA_HOTKEY HkCanvasOpenGL( _HKI( "Switch to Modern Toolset with hardware-accelerated graphics (recommended)" ),
101 #ifdef __WXMAC__
102  GR_KB_ALT +
103 #endif
104  WXK_F11 );
105 static EDA_HOTKEY HkCanvasCairo( _HKI( "Switch to Modern Toolset with software graphics (fall-back)" ),
107 #ifdef __WXMAC__
108  GR_KB_ALT +
109 #endif
110  WXK_F12 );
111 
112 static EDA_HOTKEY HkMeasureTool( _HKI( "Measure Distance (Modern Toolset only)" ),
114 
115 // List of common hotkey descriptors
127  &HkCanvasCairo,
128  &HkMeasureTool,
129  NULL
130 };
131 
132 
133 // list of sections and corresponding hotkey list for GerbView (used to create an hotkey
134 // config file)
135 static wxString gerbviewSectionTag( wxT( "[gerbview]" ) );
136 static wxString gerbviewSectionTitle( _HKI( "Gerbview Hotkeys" ) );
137 
139 {
141  { NULL, NULL, NULL }
142 };
143 
144 
146 {
147  EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, gerbviewHotkeyList );
148 
149  return HK_Descr;
150 }
151 
152 
153 bool GERBVIEW_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem )
154 {
155  #define CHANGE( x ) ( x ) = not (x )
156 
157  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
158  cmd.SetEventObject( this );
159 
160  /* Convert lower to upper case (the usual toupper function has problem with non ascii
161  * codes like function keys */
162  if( (aHotkeyCode >= 'a') && (aHotkeyCode <= 'z') )
163  aHotkeyCode += 'A' - 'a';
164 
165  EDA_HOTKEY * HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, gerbviewHotkeyList );
166 
167  if( HK_Descr == NULL )
168  return false;
169 
170  switch( HK_Descr->m_Idcommand )
171  {
172  default:
173  case HK_NOT_FOUND:
174  return false;
175 
176  case HK_HELP: // Display Current hotkey list
178  break;
179 
180  case HK_PREFERENCES:
181  cmd.SetId( wxID_PREFERENCES );
182  GetEventHandler()->ProcessEvent( cmd );
183  break;
184 
185  case HK_ZOOM_IN:
186  cmd.SetId( ID_KEY_ZOOM_IN );
187  GetEventHandler()->ProcessEvent( cmd );
188  break;
189 
190  case HK_ZOOM_OUT:
191  cmd.SetId( ID_KEY_ZOOM_OUT );
192  GetEventHandler()->ProcessEvent( cmd );
193  break;
194 
195  case HK_ZOOM_REDRAW:
196  cmd.SetId( ID_ZOOM_REDRAW );
197  GetEventHandler()->ProcessEvent( cmd );
198  break;
199 
200  case HK_ZOOM_CENTER:
201  cmd.SetId( ID_POPUP_ZOOM_CENTER );
202  GetEventHandler()->ProcessEvent( cmd );
203  break;
204 
205  case HK_ZOOM_SELECTION:
206  //cmd.SetId( ID_ZOOM_SELECTION );
207  //GetEventHandler()->ProcessEvent( cmd );
208  break;
209 
210  case HK_ZOOM_AUTO:
211  cmd.SetId( ID_ZOOM_PAGE );
212  GetEventHandler()->ProcessEvent( cmd );
213  break;
214 
215  case HK_RESET_LOCAL_COORD: // Reset the relative coord
217  break;
218 
219  case HK_SWITCH_UNITS:
220  cmd.SetId( (GetUserUnits() == INCHES) ?
222  GetEventHandler()->ProcessEvent( cmd );
223  break;
224 
227  m_canvas->Refresh();
228  break;
229 
232  m_canvas->Refresh( true );
233  break;
234 
237  m_canvas->Refresh();
238  break;
239 
242  m_canvas->Refresh();
243  break;
244 
247  m_canvas->Refresh();
248  break;
249 
252  m_canvas->Refresh();
253  break;
254 
256  if( GetActiveLayer() > 0 )
257  {
258  SetActiveLayer( GetActiveLayer() - 1, true );
259  m_canvas->Refresh();
260  }
261  break;
262 
265  {
266  SetActiveLayer( GetActiveLayer() + 1, true );
267  m_canvas->Refresh();
268  }
269  break;
270 
271  case HK_CANVAS_CAIRO:
272  cmd.SetId( ID_MENU_CANVAS_CAIRO );
273  GetEventHandler()->ProcessEvent( cmd );
274  break;
275 
276  case HK_CANVAS_OPENGL:
277  cmd.SetId( ID_MENU_CANVAS_OPENGL );
278  GetEventHandler()->ProcessEvent( cmd );
279  break;
280 
281  case HK_CANVAS_LEGACY:
282  cmd.SetId( ID_MENU_CANVAS_LEGACY );
283  GetEventHandler()->ProcessEvent( cmd );
284  break;
285  }
286 
287  return true;
288 }
#define GR_KB_ALT
static EDA_HOTKEY HkSwitch2NextCopperLayer(_HKI("Switch to Next Layer"), HK_SWITCH_LAYER_TO_NEXT, '+')
static wxString gerbviewSectionTitle(_HKI("Gerbview Hotkeys"))
static EDA_HOTKEY HkZoomRedraw(_HKI("Zoom Redraw"), HK_ZOOM_REDRAW, WXK_F3)
bool m_DisplayPolygonsFill
Option to draw polygons (filled/sketch)
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:94
static EDA_HOTKEY HkCanvasOpenGL(_HKI("Switch to Modern Toolset with hardware-accelerated graphics (recommended)"), HK_CANVAS_OPENGL, WXK_F11)
void SetActiveLayer(int aLayer, bool doLayerWidgetUpdate=true)
Function SetActiveLayer will change the currently active layer to aLayer and also update the GERBER_L...
#define GR_KB_CTRL
bool m_HighContrastMode
High contrast mode (dim un-highlighted objects)
struct EDA_HOTKEY_CONFIG GerbviewHotkeysDescr[]
static EDA_HOTKEY HkZoomCenter(_HKI("Zoom Center"), HK_ZOOM_CENTER, WXK_F4)
static EDA_HOTKEY HkFlashedDisplayMode(_HKI("Gbr Flashed Display Mode"), HK_GBR_FLASHED_DISPLAY_MODE, 'F')
int GetActiveLayer()
Function SetActiveLayer returns the active layer.
EDA_HOTKEY * gerbviewHotkeyList[]
static EDA_HOTKEY HkHelp(_HKI("List Hotkeys"), HK_HELP, GR_KB_CTRL+WXK_F1)
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:185
#define CHANGE(x)
bool m_DisplayLinesFill
Option to draw line items (filled/sketch)
static EDA_HOTKEY HkDCodesDisplayMode(_HKI("DCodes Display Mode"), HK_GBR_DCODE_DISPLAY_ONOFF, 'D')
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 HkZoomOut(_HKI("Zoom Out"), HK_ZOOM_OUT, WXK_F2)
static EDA_HOTKEY HkZoomSelection(_HKI("Zoom to Selection"), HK_ZOOM_SELECTION, GR_KB_CTRL+WXK_F5)
#define GERBER_DRAWLAYERS_COUNT
static EDA_HOTKEY HkNegativeObjDisplayMode(_HKI("Gbr Negative Obj Display Mode"), HK_GBR_NEGATIVE_DISPLAY_ONOFF, 'N')
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:289
Definition: common.h:158
GBR_DISPLAY_OPTIONS m_DisplayOptions
bool m_DisplayFlashedItemsFill
Option to draw flashed items (filled/sketch)
bool IsElementVisible(int aLayerID) const
Function IsElementVisible tests whether a given element category is visible.
static EDA_HOTKEY HkZoomAuto(_HKI("Zoom Auto"), HK_ZOOM_AUTO, WXK_HOME)
EDA_HOTKEY * GetHotKeyDescription(int aCommand) const override
static EDA_HOTKEY HkPolygonDisplayMode(_HKI("Gbr Polygons Display Mode"), HK_GBR_POLYGON_DISPLAY_MODE, 'P')
static EDA_HOTKEY HkPreferences(_HKI("Preferences"), HK_PREFERENCES, GR_KB_CTRL+',',(int) wxID_PREFERENCES)
static EDA_HOTKEY HkZoomIn(_HKI("Zoom In"), HK_ZOOM_IN, WXK_F1)
static EDA_HOTKEY HkSwitch2PreviousCopperLayer(_HKI("Switch to Previous Layer"), HK_SWITCH_LAYER_TO_PREVIOUS, '-')
static EDA_HOTKEY HkSwitchUnits(_HKI("Switch Units"), HK_SWITCH_UNITS, 'U')
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:128
static EDA_HOTKEY HkResetLocalCoord(_HKI("Reset Local Coordinates"), HK_RESET_LOCAL_COORD, ' ')
#define GR_KB_SHIFTCTRL
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:59
static EDA_HOTKEY HkMeasureTool(_HKI("Measure Distance (Modern Toolset only)"), HK_MEASURE_TOOL, 'M'+GR_KB_SHIFTCTRL)
static EDA_HOTKEY HkLinesDisplayMode(_HKI("Gbr Lines Display Mode"), HK_GBR_LINES_DISPLAY_MODE, 'L')
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:157
The common library.
static EDA_HOTKEY HkCanvasDefault(_HKI("Switch to Legacy Toolset"), HK_CANVAS_LEGACY, WXK_F9)
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
static wxString gerbviewSectionTag(wxT("[gerbview]"))
#define _HKI(x)
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
Definition: draw_frame.h:408
void SetElementVisibility(int aLayerID, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
bool OnHotKey(wxDC *aDC, int aHotkeyCode, const wxPoint &aPosition, EDA_ITEM *aItem=NULL) override
Function OnHotKey.
static EDA_HOTKEY HkSwitchHighContrastMode(_HKI("Toggle High Contrast Mode"), HK_SWITCH_HIGHCONTRAST_MODE, 'H'+GR_KB_CTRL)
EDA_HOTKEY * GetDescriptorFromCommand(int aCommand, EDA_HOTKEY **aList)
Function GetDescriptorFromCommand Returns a EDA_HOTKEY* pointer from a hot key identifier.
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
static EDA_HOTKEY HkCanvasCairo(_HKI("Switch to Modern Toolset with software graphics (fall-back)"), HK_CANVAS_CAIRO, WXK_F12)