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_commnand 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 HkHelp( _HKI( "Help (this window)" ), HK_HELP, GR_KB_CTRL + WXK_F1 );
69 static EDA_HOTKEY HkSwitchUnits( _HKI( "Switch Units" ), HK_SWITCH_UNITS, 'U' );
70 static EDA_HOTKEY HkResetLocalCoord( _HKI( "Reset Local Coordinates" ),
71  HK_RESET_LOCAL_COORD, ' ' );
72 
73 static EDA_HOTKEY HkLinesDisplayMode( _HKI( "Gbr Lines Display Mode" ),
75 static EDA_HOTKEY HkFlashedDisplayMode( _HKI( "Gbr Flashed Display Mode" ),
77 static EDA_HOTKEY HkPolygonDisplayMode( _HKI( "Gbr Polygons Display Mode" ),
79 static EDA_HOTKEY HkNegativeObjDisplayMode( _HKI( "Gbr Negative Obj Display Mode" ),
81 static EDA_HOTKEY HkDCodesDisplayMode( _HKI( "DCodes Display Mode" ),
83 
84 static EDA_HOTKEY HkSwitch2NextCopperLayer( _HKI( "Switch to Next Layer" ),
86 static EDA_HOTKEY HkSwitch2PreviousCopperLayer( _HKI( "Switch to Previous Layer" ),
88 
89 static EDA_HOTKEY HkCanvasDefault( _HKI( "Switch to Legacy Toolset" ),
91 #ifdef __WXMAC__
92  GR_KB_ALT +
93 #endif
94  WXK_F9 );
95 static EDA_HOTKEY HkCanvasOpenGL( _HKI( "Switch to Modern Toolset with hardware-accelerated graphics (recommended)" ),
97 #ifdef __WXMAC__
98  GR_KB_ALT +
99 #endif
100  WXK_F11 );
101 static EDA_HOTKEY HkCanvasCairo( _HKI( "Switch to Modern Toolset with software graphics (fall-back)" ),
103 #ifdef __WXMAC__
104  GR_KB_ALT +
105 #endif
106  WXK_F12 );
107 
108 static EDA_HOTKEY HkMeasureTool( _HKI( "Measure Distance (Modern Toolset only)" ),
110 
111 // List of common hotkey descriptors
113  &HkHelp,
122  &HkCanvasCairo,
123  &HkMeasureTool,
124  NULL
125 };
126 
127 
128 // list of sections and corresponding hotkey list for GerbView (used to create an hotkey
129 // config file)
130 static wxString gerbviewSectionTag( wxT( "[gerbview]" ) );
131 static wxString gerbviewSectionTitle( _HKI( "Gerbview Hotkeys" ) );
132 
134 {
135  { &gerbviewSectionTag, gerbviewHotkeyList, &gerbviewSectionTitle },
136  { NULL, NULL, NULL }
137 };
138 
139 
141 {
142  EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, gerbviewHotkeyList );
143 
144  return HK_Descr;
145 }
146 
147 
148 bool GERBVIEW_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem )
149 {
150  #define CHANGE( x ) ( x ) = not (x )
151 
152  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
153  cmd.SetEventObject( this );
154 
155  /* Convert lower to upper case (the usual toupper function has problem with non ascii
156  * codes like function keys */
157  if( (aHotkeyCode >= 'a') && (aHotkeyCode <= 'z') )
158  aHotkeyCode += 'A' - 'a';
159 
160  EDA_HOTKEY * HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, gerbviewHotkeyList );
161 
162  if( HK_Descr == NULL )
163  return false;
164 
165  switch( HK_Descr->m_Idcommand )
166  {
167  default:
168  case HK_NOT_FOUND:
169  return false;
170 
171  case HK_HELP: // Display Current hotkey list
172  DisplayHotkeyList( this, GerbviewHokeysDescr );
173  break;
174 
175  case HK_ZOOM_IN:
176  cmd.SetId( ID_KEY_ZOOM_IN );
177  GetEventHandler()->ProcessEvent( cmd );
178  break;
179 
180  case HK_ZOOM_OUT:
181  cmd.SetId( ID_KEY_ZOOM_OUT );
182  GetEventHandler()->ProcessEvent( cmd );
183  break;
184 
185  case HK_ZOOM_REDRAW:
186  cmd.SetId( ID_ZOOM_REDRAW );
187  GetEventHandler()->ProcessEvent( cmd );
188  break;
189 
190  case HK_ZOOM_CENTER:
191  cmd.SetId( ID_POPUP_ZOOM_CENTER );
192  GetEventHandler()->ProcessEvent( cmd );
193  break;
194 
195  case HK_ZOOM_SELECTION:
196  //cmd.SetId( ID_ZOOM_SELECTION );
197  //GetEventHandler()->ProcessEvent( cmd );
198  break;
199 
200  case HK_ZOOM_AUTO:
201  cmd.SetId( ID_ZOOM_PAGE );
202  GetEventHandler()->ProcessEvent( cmd );
203  break;
204 
205  case HK_RESET_LOCAL_COORD: // Reset the relative coord
207  break;
208 
209  case HK_SWITCH_UNITS:
211  break;
212 
215  m_canvas->Refresh();
216  break;
217 
220  m_canvas->Refresh( true );
221  break;
222 
225  m_canvas->Refresh();
226  break;
227 
230  m_canvas->Refresh();
231  break;
232 
235  m_canvas->Refresh();
236  break;
237 
239  if( GetActiveLayer() > 0 )
240  {
241  SetActiveLayer( GetActiveLayer() - 1, true );
242  m_canvas->Refresh();
243  }
244  break;
245 
248  {
249  SetActiveLayer( GetActiveLayer() + 1, true );
250  m_canvas->Refresh();
251  }
252  break;
253 
254  case HK_CANVAS_CAIRO:
255  cmd.SetId( ID_MENU_CANVAS_CAIRO );
256  GetEventHandler()->ProcessEvent( cmd );
257  break;
258 
259  case HK_CANVAS_OPENGL:
260  cmd.SetId( ID_MENU_CANVAS_OPENGL );
261  GetEventHandler()->ProcessEvent( cmd );
262  break;
263 
264  case HK_CANVAS_LEGACY:
265  cmd.SetId( ID_MENU_CANVAS_LEGACY );
266  GetEventHandler()->ProcessEvent( cmd );
267  break;
268  }
269 
270  return true;
271 }
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:87
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:338
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...
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[]
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:185
#define GR_KB_ALT
Definition: common.h:65
#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)
virtual BASE_SCREEN * GetScreen() const
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: draw_frame.h:361
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')
Definition: common.h:145
GBR_DISPLAY_OPTIONS m_DisplayOptions
bool m_DisplayFlashedItemsFill
Option to draw flashed items (filled/sketch)
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 HkZoomIn(_HKI("Zoom In"), HK_ZOOM_IN, WXK_F1)
#define GR_KB_SHIFTCTRL
Definition: common.h:67
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_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:57
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:98
static EDA_HOTKEY HkResetLocalCoord(_HKI("Reset Local Coordinates"), HK_RESET_LOCAL_COORD, ' ')
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
static EDA_HOTKEY HkHelp(_HKI("Help (this window)"), HK_HELP, GR_KB_CTRL+WXK_F1)
void SetElementVisibility(GERBVIEW_LAYER_ID aItemIdVisible, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
bool IsElementVisible(GERBVIEW_LAYER_ID aItemIdVisible) const
Function IsElementVisible tests whether a given element category is visible.
static EDA_HOTKEY HkMeasureTool(_HKI("Measure Distance (Modern Toolset only)"), HK_MEASURE_TOOL, 'M'+GR_KB_SHIFTCTRL)
struct EDA_HOTKEY_CONFIG GerbviewHokeysDescr[]
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:162
The common library.
static EDA_HOTKEY HkCanvasDefault(_HKI("Switch to Legacy Toolset"), HK_CANVAS_LEGACY, WXK_F9)
#define GR_KB_CTRL
Definition: common.h:64
static wxString gerbviewSectionTag(wxT("[gerbview]"))
#define _HKI(x)
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
bool OnHotKey(wxDC *aDC, int aHotkeyCode, const wxPoint &aPosition, EDA_ITEM *aItem=NULL) override
Function OnHotKey.
EDA_HOTKEY * GetDescriptorFromCommand(int aCommand, EDA_HOTKEY **aList)
Function GetDescriptorFromCommand Returns a EDA_HOTKEY* pointer from a hot key identifier.
static EDA_HOTKEY HkCanvasCairo(_HKI("Switch to Modern Toolset with software graphics (fall-back)"), HK_CANVAS_CAIRO, WXK_F12)