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( "List Hotkeys" ), 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 static EDA_HOTKEY HkSwitchHighContrastMode( _HKI( "Toggle High Contrast Mode" ),
74 
75 static EDA_HOTKEY HkLinesDisplayMode( _HKI( "Gbr Lines Display Mode" ),
77 static EDA_HOTKEY HkFlashedDisplayMode( _HKI( "Gbr Flashed Display Mode" ),
79 static EDA_HOTKEY HkPolygonDisplayMode( _HKI( "Gbr Polygons Display Mode" ),
81 static EDA_HOTKEY HkNegativeObjDisplayMode( _HKI( "Gbr Negative Obj Display Mode" ),
83 static EDA_HOTKEY HkDCodesDisplayMode( _HKI( "DCodes Display Mode" ),
85 
86 static EDA_HOTKEY HkSwitch2NextCopperLayer( _HKI( "Switch to Next Layer" ),
88 static EDA_HOTKEY HkSwitch2PreviousCopperLayer( _HKI( "Switch to Previous Layer" ),
90 
91 static EDA_HOTKEY HkCanvasDefault( _HKI( "Switch to Legacy Toolset" ),
93 #ifdef __WXMAC__
94  GR_KB_ALT +
95 #endif
96  WXK_F9 );
97 static EDA_HOTKEY HkCanvasOpenGL( _HKI( "Switch to Modern Toolset with hardware-accelerated graphics (recommended)" ),
99 #ifdef __WXMAC__
100  GR_KB_ALT +
101 #endif
102  WXK_F11 );
103 static EDA_HOTKEY HkCanvasCairo( _HKI( "Switch to Modern Toolset with software graphics (fall-back)" ),
105 #ifdef __WXMAC__
106  GR_KB_ALT +
107 #endif
108  WXK_F12 );
109 
110 static EDA_HOTKEY HkMeasureTool( _HKI( "Measure Distance (Modern Toolset only)" ),
112 
113 // List of common hotkey descriptors
115  &HkHelp,
125  &HkCanvasCairo,
126  &HkMeasureTool,
127  NULL
128 };
129 
130 
131 // list of sections and corresponding hotkey list for GerbView (used to create an hotkey
132 // config file)
133 static wxString gerbviewSectionTag( wxT( "[gerbview]" ) );
134 static wxString gerbviewSectionTitle( _HKI( "Gerbview Hotkeys" ) );
135 
137 {
139  { NULL, NULL, NULL }
140 };
141 
142 
144 {
145  EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, gerbviewHotkeyList );
146 
147  return HK_Descr;
148 }
149 
150 
151 bool GERBVIEW_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem )
152 {
153  #define CHANGE( x ) ( x ) = not (x )
154 
155  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
156  cmd.SetEventObject( this );
157 
158  /* Convert lower to upper case (the usual toupper function has problem with non ascii
159  * codes like function keys */
160  if( (aHotkeyCode >= 'a') && (aHotkeyCode <= 'z') )
161  aHotkeyCode += 'A' - 'a';
162 
163  EDA_HOTKEY * HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, gerbviewHotkeyList );
164 
165  if( HK_Descr == NULL )
166  return false;
167 
168  switch( HK_Descr->m_Idcommand )
169  {
170  default:
171  case HK_NOT_FOUND:
172  return false;
173 
174  case HK_HELP: // Display Current hotkey list
176  break;
177 
178  case HK_ZOOM_IN:
179  cmd.SetId( ID_KEY_ZOOM_IN );
180  GetEventHandler()->ProcessEvent( cmd );
181  break;
182 
183  case HK_ZOOM_OUT:
184  cmd.SetId( ID_KEY_ZOOM_OUT );
185  GetEventHandler()->ProcessEvent( cmd );
186  break;
187 
188  case HK_ZOOM_REDRAW:
189  cmd.SetId( ID_ZOOM_REDRAW );
190  GetEventHandler()->ProcessEvent( cmd );
191  break;
192 
193  case HK_ZOOM_CENTER:
194  cmd.SetId( ID_POPUP_ZOOM_CENTER );
195  GetEventHandler()->ProcessEvent( cmd );
196  break;
197 
198  case HK_ZOOM_SELECTION:
199  //cmd.SetId( ID_ZOOM_SELECTION );
200  //GetEventHandler()->ProcessEvent( cmd );
201  break;
202 
203  case HK_ZOOM_AUTO:
204  cmd.SetId( ID_ZOOM_PAGE );
205  GetEventHandler()->ProcessEvent( cmd );
206  break;
207 
208  case HK_RESET_LOCAL_COORD: // Reset the relative coord
210  break;
211 
212  case HK_SWITCH_UNITS:
213  cmd.SetId( (GetUserUnits() == INCHES) ?
215  GetEventHandler()->ProcessEvent( cmd );
216  break;
217 
220  m_canvas->Refresh();
221  break;
222 
225  m_canvas->Refresh( true );
226  break;
227 
230  m_canvas->Refresh();
231  break;
232 
235  m_canvas->Refresh();
236  break;
237 
240  m_canvas->Refresh();
241  break;
242 
245  m_canvas->Refresh();
246  break;
247 
249  if( GetActiveLayer() > 0 )
250  {
251  SetActiveLayer( GetActiveLayer() - 1, true );
252  m_canvas->Refresh();
253  }
254  break;
255 
258  {
259  SetActiveLayer( GetActiveLayer() + 1, true );
260  m_canvas->Refresh();
261  }
262  break;
263 
264  case HK_CANVAS_CAIRO:
265  cmd.SetId( ID_MENU_CANVAS_CAIRO );
266  GetEventHandler()->ProcessEvent( cmd );
267  break;
268 
269  case HK_CANVAS_OPENGL:
270  cmd.SetId( ID_MENU_CANVAS_OPENGL );
271  GetEventHandler()->ProcessEvent( cmd );
272  break;
273 
274  case HK_CANVAS_LEGACY:
275  cmd.SetId( ID_MENU_CANVAS_LEGACY );
276  GetEventHandler()->ProcessEvent( cmd );
277  break;
278  }
279 
280  return true;
281 }
#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)
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)
EDA_DRAW_FRAME::OnSelectGrid ID_TB_OPTIONS_SELECT_UNIT_INCH
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:291
Definition: common.h:161
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 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:126
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)
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:154
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:404
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)