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-2010 <Jean-Pierre Charras>
5  * Copyright (C) 1992-2016 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 <id.h>
32 
33 #include <gerbview.h>
34 #include <gerbview_frame.h>
35 #include <class_drawpanel.h>
36 #include <hotkeys.h>
37 
38 
39 /* How to add a new hotkey:
40  * add a new id in the enum hotkey_id_commnand like MY_NEW_ID_FUNCTION.
41  * add a new EDA_HOTKEY entry like:
42  * static EDA_HOTKEY HkMyNewEntry(wxT("Command Label"), MY_NEW_ID_FUNCTION, default key value);
43  * "Command Label" is the name used in hotkey list display, and the identifier in the
44  * hotkey list file MY_NEW_ID_FUNCTION is an equivalent id function used in the switch
45  * in OnHotKey() function. default key value is the default hotkey for this command.
46  * Can be overrided by the user hotkey list file add the HkMyNewEntry pointer in the
47  * s_board_edit_Hotkey_List list ( or/and the s_module_edit_Hotkey_List list) Add the
48  * new code in the switch in OnHotKey() function. when the variable PopupOn is true,
49  * an item is currently edited. This can be usefull if the new function cannot be
50  * executed while an item is currently being edited
51  * ( For example, one cannot start a new wire when a component is moving.)
52  *
53  * Note: If an hotkey is a special key, be sure the corresponding wxWidget keycode (WXK_XXXX)
54  * is handled in the hotkey_name_descr s_Hotkey_Name_List list (see hotkeys_basic.cpp)
55  * and see this list for some ascii keys (space ...)
56  */
57 
58 // local variables
59 // Hotkey list:
60 static EDA_HOTKEY HkZoomAuto( _HKI( "Zoom Auto" ), HK_ZOOM_AUTO, WXK_HOME );
61 static EDA_HOTKEY HkZoomCenter( _HKI( "Zoom Center" ), HK_ZOOM_CENTER, WXK_F4 );
62 static EDA_HOTKEY HkZoomRedraw( _HKI( "Zoom Redraw" ), HK_ZOOM_REDRAW, WXK_F3 );
63 static EDA_HOTKEY HkZoomOut( _HKI( "Zoom Out" ), HK_ZOOM_OUT, WXK_F2 );
64 static EDA_HOTKEY HkZoomIn( _HKI( "Zoom In" ), HK_ZOOM_IN, WXK_F1 );
65 static EDA_HOTKEY HkZoomSelection( _HKI( "Zoom to Selection" ), HK_ZOOM_SELECTION, '@', ID_ZOOM_SELECTION );
66 static EDA_HOTKEY HkHelp( _HKI( "Help (this window)" ), HK_HELP, '?' );
67 static EDA_HOTKEY HkSwitchUnits( _HKI( "Switch Units" ), HK_SWITCH_UNITS, 'U' );
68 static EDA_HOTKEY HkResetLocalCoord( _HKI( "Reset Local Coordinates" ), HK_RESET_LOCAL_COORD, ' ' );
69 
70 static EDA_HOTKEY HkLinesDisplayMode( _HKI( "Gbr Lines Display Mode" ), HK_GBR_LINES_DISPLAY_MODE, 'L' );
71 static EDA_HOTKEY HkFlashedDisplayMode( _HKI( "Gbr Flashed Display Mode" ), HK_GBR_FLASHED_DISPLAY_MODE, 'F' );
72 static EDA_HOTKEY HkPolygonDisplayMode( _HKI( "Gbr Polygons Display Mode" ), HK_GBR_POLYGON_DISPLAY_MODE, 'P' );
73 static EDA_HOTKEY HkNegativeObjDisplayMode( _HKI( "Gbr Negative Obj Display Mode" ), HK_GBR_NEGATIVE_DISPLAY_ONOFF, 'N' );
74 static EDA_HOTKEY HkDCodesDisplayMode( _HKI( "DCodes Display Mode" ), HK_GBR_DCODE_DISPLAY_ONOFF, 'D' );
75 
76 static EDA_HOTKEY HkSwitch2NextCopperLayer( _HKI( "Switch to Next Layer" ), HK_SWITCH_LAYER_TO_NEXT, '+' );
77 static EDA_HOTKEY HkSwitch2PreviousCopperLayer( _HKI( "Switch to Previous Layer" ), HK_SWITCH_LAYER_TO_PREVIOUS, '-' );
78 
79 // List of common hotkey descriptors
81  &HkHelp,
88  NULL
89 };
90 
91 
92 // list of sections and corresponding hotkey list for GerbView (used to create an hotkey
93 // config file)
94 static wxString gerbviewSectionTag( wxT( "[gerbview]" ) );
95 static wxString gerbviewSectionTitle( _HKI( "Gerbview Hotkeys" ) );
96 
98 {
100  { NULL, NULL, NULL }
101 };
102 
103 
105 {
106  EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, gerbviewHotkeyList );
107 
108  return HK_Descr;
109 }
110 
111 
112 bool GERBVIEW_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem )
113 {
114  #define CHANGE( x ) ( x ) = not (x )
115 
116  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
117  cmd.SetEventObject( this );
118 
119  /* Convert lower to upper case (the usual toupper function has problem with non ascii
120  * codes like function keys */
121  if( (aHotkeyCode >= 'a') && (aHotkeyCode <= 'z') )
122  aHotkeyCode += 'A' - 'a';
123 
124  EDA_HOTKEY * HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, gerbviewHotkeyList );
125 
126  if( HK_Descr == NULL )
127  return false;
128 
129  switch( HK_Descr->m_Idcommand )
130  {
131  default:
132  case HK_NOT_FOUND:
133  return false;
134 
135  case HK_HELP: // Display Current hotkey list
136  DisplayHotkeyList( this, GerbviewHokeysDescr );
137  break;
138 
139  case HK_ZOOM_IN:
140  cmd.SetId( ID_POPUP_ZOOM_IN );
141  GetEventHandler()->ProcessEvent( cmd );
142  break;
143 
144  case HK_ZOOM_OUT:
145  cmd.SetId( ID_POPUP_ZOOM_OUT );
146  GetEventHandler()->ProcessEvent( cmd );
147  break;
148 
149  case HK_ZOOM_REDRAW:
150  cmd.SetId( ID_ZOOM_REDRAW );
151  GetEventHandler()->ProcessEvent( cmd );
152  break;
153 
154  case HK_ZOOM_CENTER:
155  cmd.SetId( ID_POPUP_ZOOM_CENTER );
156  GetEventHandler()->ProcessEvent( cmd );
157  break;
158 
159  case HK_ZOOM_AUTO:
160  cmd.SetId( ID_ZOOM_PAGE );
161  GetEventHandler()->ProcessEvent( cmd );
162  break;
163 
164  case HK_RESET_LOCAL_COORD: // Reset the relative coord
166  break;
167 
168  case HK_SWITCH_UNITS:
170  break;
171 
174  m_canvas->Refresh();
175  break;
176 
179  m_canvas->Refresh( true );
180  break;
181 
184  m_canvas->Refresh();
185  break;
186 
189  m_canvas->Refresh();
190  break;
191 
194  m_canvas->Refresh();
195  break;
196 
198  if( getActiveLayer() > 0 )
199  {
201  m_canvas->Refresh();
202  }
203  break;
204 
206  if( getActiveLayer() < 31 )
207  {
209  m_canvas->Refresh();
210  }
211  break;
212  }
213 
214  return true;
215 }
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
Definition: draw_panel.cpp:326
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')
EDA_HOTKEY * gerbviewHotkeyList[]
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
#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:309
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)
static EDA_HOTKEY HkSwitch2PreviousCopperLayer(_HKI("Switch to Previous Layer"), HK_SWITCH_LAYER_TO_PREVIOUS, '-')
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 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:92
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 HkZoomSelection(_HKI("Zoom to Selection"), HK_ZOOM_SELECTION, '@', ID_ZOOM_SELECTION)
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.
int getActiveLayer()
Function getActiveLayer returns the active layer.
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:151
The common library.
static EDA_HOTKEY HkHelp(_HKI("Help (this window)"), HK_HELP, '?')
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.