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>
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, '@' );
68 static EDA_HOTKEY HkHelp( _HKI( "Help (this window)" ), HK_HELP, '?' );
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 Canvas" ),
91 #ifdef __WXMAC__
92  GR_KB_ALT +
93 #endif
94  WXK_F9 );
95 static EDA_HOTKEY HkCanvasOpenGL( _HKI( "Switch to OpenGL Canvas" ),
97 #ifdef __WXMAC__
98  GR_KB_ALT +
99 #endif
100  WXK_F11 );
101 static EDA_HOTKEY HkCanvasCairo( _HKI( "Switch to Cairo Canvas" ),
103 #ifdef __WXMAC__
104  GR_KB_ALT +
105 #endif
106  WXK_F12 );
107 
108 // List of common hotkey descriptors
110  &HkHelp,
119  &HkCanvasCairo,
120  NULL
121 };
122 
123 
124 // list of sections and corresponding hotkey list for GerbView (used to create an hotkey
125 // config file)
126 static wxString gerbviewSectionTag( wxT( "[gerbview]" ) );
127 static wxString gerbviewSectionTitle( _HKI( "Gerbview Hotkeys" ) );
128 
130 {
132  { NULL, NULL, NULL }
133 };
134 
135 
137 {
138  EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, gerbviewHotkeyList );
139 
140  return HK_Descr;
141 }
142 
143 
144 bool GERBVIEW_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem )
145 {
146  #define CHANGE( x ) ( x ) = not (x )
147 
148  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
149  cmd.SetEventObject( this );
150 
151  /* Convert lower to upper case (the usual toupper function has problem with non ascii
152  * codes like function keys */
153  if( (aHotkeyCode >= 'a') && (aHotkeyCode <= 'z') )
154  aHotkeyCode += 'A' - 'a';
155 
156  EDA_HOTKEY * HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, gerbviewHotkeyList );
157 
158  if( HK_Descr == NULL )
159  return false;
160 
161  switch( HK_Descr->m_Idcommand )
162  {
163  default:
164  case HK_NOT_FOUND:
165  return false;
166 
167  case HK_HELP: // Display Current hotkey list
168  DisplayHotkeyList( this, GerbviewHokeysDescr );
169  break;
170 
171  case HK_ZOOM_IN:
172  cmd.SetId( ID_POPUP_ZOOM_IN );
173  GetEventHandler()->ProcessEvent( cmd );
174  break;
175 
176  case HK_ZOOM_OUT:
177  cmd.SetId( ID_POPUP_ZOOM_OUT );
178  GetEventHandler()->ProcessEvent( cmd );
179  break;
180 
181  case HK_ZOOM_REDRAW:
182  cmd.SetId( ID_ZOOM_REDRAW );
183  GetEventHandler()->ProcessEvent( cmd );
184  break;
185 
186  case HK_ZOOM_CENTER:
187  cmd.SetId( ID_POPUP_ZOOM_CENTER );
188  GetEventHandler()->ProcessEvent( cmd );
189  break;
190 
191  case HK_ZOOM_AUTO:
192  cmd.SetId( ID_ZOOM_PAGE );
193  GetEventHandler()->ProcessEvent( cmd );
194  break;
195 
196  case HK_RESET_LOCAL_COORD: // Reset the relative coord
198  break;
199 
200  case HK_SWITCH_UNITS:
202  break;
203 
206  m_canvas->Refresh();
207  break;
208 
211  m_canvas->Refresh( true );
212  break;
213 
216  m_canvas->Refresh();
217  break;
218 
221  m_canvas->Refresh();
222  break;
223 
226  m_canvas->Refresh();
227  break;
228 
230  if( GetActiveLayer() > 0 )
231  {
234  m_canvas->Refresh();
235  }
236  break;
237 
240  {
243  m_canvas->Refresh();
244  }
245  break;
246 
247  case HK_CANVAS_CAIRO:
248  cmd.SetId( ID_MENU_CANVAS_CAIRO );
249  GetEventHandler()->ProcessEvent( cmd );
250  break;
251 
252  case HK_CANVAS_OPENGL:
253  cmd.SetId( ID_MENU_CANVAS_OPENGL );
254  GetEventHandler()->ProcessEvent( cmd );
255  break;
256 
257  case HK_CANVAS_LEGACY:
258  cmd.SetId( ID_MENU_CANVAS_LEGACY );
259  GetEventHandler()->ProcessEvent( cmd );
260  break;
261  }
262 
263  return true;
264 }
static EDA_HOTKEY HkCanvasDefault(_HKI("Switch to Legacy Canvas"), HK_CANVAS_LEGACY, WXK_F9)
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:325
GERBER_LAYER_WIDGET * m_LayersManager
static EDA_HOTKEY HkCanvasOpenGL(_HKI("Switch to OpenGL Canvas"), 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.
#define GR_KB_ALT
Definition: common.h:64
#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 HkZoomSelection(_HKI("Zoom to Selection"), HK_ZOOM_SELECTION, '@')
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:347
#define GERBER_DRAWLAYERS_COUNT
static EDA_HOTKEY HkNegativeObjDisplayMode(_HKI("Gbr Negative Obj Display Mode"), HK_GBR_NEGATIVE_DISPLAY_ONOFF, 'N')
static EDA_HOTKEY HkCanvasCairo(_HKI("Switch to Cairo Canvas"), HK_CANVAS_CAIRO, WXK_F12)
Definition: common.h:144
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)
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:56
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:93
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
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.
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:165
The common library.
static EDA_HOTKEY HkHelp(_HKI("Help (this window)"), HK_HELP, '?')
static wxString gerbviewSectionTag(wxT("[gerbview]"))
#define _HKI(x)
bool OnLayerSelected()
Function OnLayerSelected ensure the active layer is visible, and other layers not visible when m_alwa...
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.