You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

281 lines
10 KiB

14 years ago
16 years ago
  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. /**
  25. * @file gerbview/hotkeys.cpp
  26. */
  27. #include <fctsys.h>
  28. #include <common.h>
  29. #include <gerbview_id.h>
  30. #include <gerbview.h>
  31. #include <gerbview_frame.h>
  32. #include <class_drawpanel.h>
  33. #include <gerbview_layer_widget.h>
  34. #include <hotkeys.h>
  35. /* How to add a new hotkey:
  36. * add a new id in the enum hotkey_id_commnand like MY_NEW_ID_FUNCTION.
  37. * add a new EDA_HOTKEY entry like:
  38. * static EDA_HOTKEY HkMyNewEntry(wxT("Command Label"), MY_NEW_ID_FUNCTION, default key value);
  39. * "Command Label" is the name used in hotkey list display, and the identifier in the
  40. * hotkey list file MY_NEW_ID_FUNCTION is an equivalent id function used in the switch
  41. * in OnHotKey() function. default key value is the default hotkey for this command.
  42. * Can be overrided by the user hotkey list file add the HkMyNewEntry pointer in the
  43. * s_board_edit_Hotkey_List list ( or/and the s_module_edit_Hotkey_List list) Add the
  44. * new code in the switch in OnHotKey() function. when the variable PopupOn is true,
  45. * an item is currently edited. This can be usefull if the new function cannot be
  46. * executed while an item is currently being edited
  47. * ( For example, one cannot start a new wire when a component is moving.)
  48. *
  49. * Note: If an hotkey is a special key, be sure the corresponding wxWidget keycode (WXK_XXXX)
  50. * is handled in the hotkey_name_descr s_Hotkey_Name_List list (see hotkeys_basic.cpp)
  51. * and see this list for some ascii keys (space ...)
  52. */
  53. // local variables
  54. // Hotkey list:
  55. static EDA_HOTKEY HkZoomAuto( _HKI( "Zoom Auto" ), HK_ZOOM_AUTO, WXK_HOME );
  56. static EDA_HOTKEY HkZoomCenter( _HKI( "Zoom Center" ), HK_ZOOM_CENTER, WXK_F4 );
  57. static EDA_HOTKEY HkZoomRedraw( _HKI( "Zoom Redraw" ), HK_ZOOM_REDRAW, WXK_F3 );
  58. static EDA_HOTKEY HkZoomOut( _HKI( "Zoom Out" ), HK_ZOOM_OUT, WXK_F2 );
  59. static EDA_HOTKEY HkZoomIn( _HKI( "Zoom In" ), HK_ZOOM_IN, WXK_F1 );
  60. static EDA_HOTKEY HkZoomSelection( _HKI( "Zoom to Selection" ),
  61. HK_ZOOM_SELECTION, GR_KB_CTRL + WXK_F5 );
  62. static EDA_HOTKEY HkHelp( _HKI( "List Hotkeys" ), HK_HELP, GR_KB_CTRL + WXK_F1 );
  63. static EDA_HOTKEY HkSwitchUnits( _HKI( "Switch Units" ), HK_SWITCH_UNITS, 'U' );
  64. static EDA_HOTKEY HkResetLocalCoord( _HKI( "Reset Local Coordinates" ),
  65. HK_RESET_LOCAL_COORD, ' ' );
  66. static EDA_HOTKEY HkSwitchHighContrastMode( _HKI( "Toggle High Contrast Mode" ),
  67. HK_SWITCH_HIGHCONTRAST_MODE, 'H' + GR_KB_CTRL );
  68. static EDA_HOTKEY HkLinesDisplayMode( _HKI( "Gbr Lines Display Mode" ),
  69. HK_GBR_LINES_DISPLAY_MODE, 'L' );
  70. static EDA_HOTKEY HkFlashedDisplayMode( _HKI( "Gbr Flashed Display Mode" ),
  71. HK_GBR_FLASHED_DISPLAY_MODE, 'F' );
  72. static EDA_HOTKEY HkPolygonDisplayMode( _HKI( "Gbr Polygons Display Mode" ),
  73. HK_GBR_POLYGON_DISPLAY_MODE, 'P' );
  74. static EDA_HOTKEY HkNegativeObjDisplayMode( _HKI( "Gbr Negative Obj Display Mode" ),
  75. HK_GBR_NEGATIVE_DISPLAY_ONOFF, 'N' );
  76. static EDA_HOTKEY HkDCodesDisplayMode( _HKI( "DCodes Display Mode" ),
  77. HK_GBR_DCODE_DISPLAY_ONOFF, 'D' );
  78. static EDA_HOTKEY HkSwitch2NextCopperLayer( _HKI( "Switch to Next Layer" ),
  79. HK_SWITCH_LAYER_TO_NEXT, '+' );
  80. static EDA_HOTKEY HkSwitch2PreviousCopperLayer( _HKI( "Switch to Previous Layer" ),
  81. HK_SWITCH_LAYER_TO_PREVIOUS, '-' );
  82. static EDA_HOTKEY HkCanvasDefault( _HKI( "Switch to Legacy Toolset" ),
  83. HK_CANVAS_LEGACY,
  84. #ifdef __WXMAC__
  85. GR_KB_ALT +
  86. #endif
  87. WXK_F9 );
  88. static EDA_HOTKEY HkCanvasOpenGL( _HKI( "Switch to Modern Toolset with hardware-accelerated graphics (recommended)" ),
  89. HK_CANVAS_OPENGL,
  90. #ifdef __WXMAC__
  91. GR_KB_ALT +
  92. #endif
  93. WXK_F11 );
  94. static EDA_HOTKEY HkCanvasCairo( _HKI( "Switch to Modern Toolset with software graphics (fall-back)" ),
  95. HK_CANVAS_CAIRO,
  96. #ifdef __WXMAC__
  97. GR_KB_ALT +
  98. #endif
  99. WXK_F12 );
  100. static EDA_HOTKEY HkMeasureTool( _HKI( "Measure Distance (Modern Toolset only)" ),
  101. HK_MEASURE_TOOL, 'M' + GR_KB_SHIFTCTRL );
  102. // List of common hotkey descriptors
  103. EDA_HOTKEY* gerbviewHotkeyList[] = {
  104. &HkHelp,
  105. &HkZoomIn, &HkZoomOut, &HkZoomRedraw, &HkZoomCenter,
  106. &HkZoomAuto, &HkZoomSelection, &HkSwitchUnits, &HkResetLocalCoord,
  107. &HkLinesDisplayMode, &HkFlashedDisplayMode, &HkPolygonDisplayMode,
  108. &HkDCodesDisplayMode, &HkNegativeObjDisplayMode,
  109. &HkSwitchHighContrastMode,
  110. &HkSwitch2NextCopperLayer,
  111. &HkSwitch2PreviousCopperLayer,
  112. &HkCanvasDefault,
  113. &HkCanvasOpenGL,
  114. &HkCanvasCairo,
  115. &HkMeasureTool,
  116. NULL
  117. };
  118. // list of sections and corresponding hotkey list for GerbView (used to create an hotkey
  119. // config file)
  120. static wxString gerbviewSectionTag( wxT( "[gerbview]" ) );
  121. static wxString gerbviewSectionTitle( _HKI( "Gerbview Hotkeys" ) );
  122. struct EDA_HOTKEY_CONFIG GerbviewHokeysDescr[] =
  123. {
  124. { &gerbviewSectionTag, gerbviewHotkeyList, &gerbviewSectionTitle },
  125. { NULL, NULL, NULL }
  126. };
  127. EDA_HOTKEY* GERBVIEW_FRAME::GetHotKeyDescription( int aCommand ) const
  128. {
  129. EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, gerbviewHotkeyList );
  130. return HK_Descr;
  131. }
  132. bool GERBVIEW_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem )
  133. {
  134. #define CHANGE( x ) ( x ) = not (x )
  135. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  136. cmd.SetEventObject( this );
  137. /* Convert lower to upper case (the usual toupper function has problem with non ascii
  138. * codes like function keys */
  139. if( (aHotkeyCode >= 'a') && (aHotkeyCode <= 'z') )
  140. aHotkeyCode += 'A' - 'a';
  141. EDA_HOTKEY * HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, gerbviewHotkeyList );
  142. if( HK_Descr == NULL )
  143. return false;
  144. switch( HK_Descr->m_Idcommand )
  145. {
  146. default:
  147. case HK_NOT_FOUND:
  148. return false;
  149. case HK_HELP: // Display Current hotkey list
  150. DisplayHotkeyList( this, GerbviewHokeysDescr );
  151. break;
  152. case HK_ZOOM_IN:
  153. cmd.SetId( ID_KEY_ZOOM_IN );
  154. GetEventHandler()->ProcessEvent( cmd );
  155. break;
  156. case HK_ZOOM_OUT:
  157. cmd.SetId( ID_KEY_ZOOM_OUT );
  158. GetEventHandler()->ProcessEvent( cmd );
  159. break;
  160. case HK_ZOOM_REDRAW:
  161. cmd.SetId( ID_ZOOM_REDRAW );
  162. GetEventHandler()->ProcessEvent( cmd );
  163. break;
  164. case HK_ZOOM_CENTER:
  165. cmd.SetId( ID_POPUP_ZOOM_CENTER );
  166. GetEventHandler()->ProcessEvent( cmd );
  167. break;
  168. case HK_ZOOM_SELECTION:
  169. //cmd.SetId( ID_ZOOM_SELECTION );
  170. //GetEventHandler()->ProcessEvent( cmd );
  171. break;
  172. case HK_ZOOM_AUTO:
  173. cmd.SetId( ID_ZOOM_PAGE );
  174. GetEventHandler()->ProcessEvent( cmd );
  175. break;
  176. case HK_RESET_LOCAL_COORD: // Reset the relative coord
  177. GetScreen()->m_O_Curseur = GetCrossHairPosition();
  178. break;
  179. case HK_SWITCH_UNITS:
  180. cmd.SetId( (GetUserUnits() == INCHES) ?
  181. ID_TB_OPTIONS_SELECT_UNIT_MM : ID_TB_OPTIONS_SELECT_UNIT_INCH );
  182. GetEventHandler()->ProcessEvent( cmd );
  183. break;
  184. case HK_GBR_LINES_DISPLAY_MODE:
  185. CHANGE( m_DisplayOptions.m_DisplayLinesFill );
  186. m_canvas->Refresh();
  187. break;
  188. case HK_GBR_FLASHED_DISPLAY_MODE:
  189. CHANGE( m_DisplayOptions.m_DisplayFlashedItemsFill );
  190. m_canvas->Refresh( true );
  191. break;
  192. case HK_GBR_POLYGON_DISPLAY_MODE:
  193. CHANGE( m_DisplayOptions.m_DisplayPolygonsFill );
  194. m_canvas->Refresh();
  195. break;
  196. case HK_GBR_NEGATIVE_DISPLAY_ONOFF:
  197. SetElementVisibility( LAYER_NEGATIVE_OBJECTS, not IsElementVisible( LAYER_NEGATIVE_OBJECTS ) );
  198. m_canvas->Refresh();
  199. break;
  200. case HK_GBR_DCODE_DISPLAY_ONOFF:
  201. SetElementVisibility( LAYER_DCODES, not IsElementVisible( LAYER_DCODES ) );
  202. m_canvas->Refresh();
  203. break;
  204. case HK_SWITCH_HIGHCONTRAST_MODE:
  205. CHANGE( m_DisplayOptions.m_HighContrastMode );
  206. m_canvas->Refresh();
  207. break;
  208. case HK_SWITCH_LAYER_TO_PREVIOUS:
  209. if( GetActiveLayer() > 0 )
  210. {
  211. SetActiveLayer( GetActiveLayer() - 1, true );
  212. m_canvas->Refresh();
  213. }
  214. break;
  215. case HK_SWITCH_LAYER_TO_NEXT:
  216. if( GetActiveLayer() < GERBER_DRAWLAYERS_COUNT - 1 )
  217. {
  218. SetActiveLayer( GetActiveLayer() + 1, true );
  219. m_canvas->Refresh();
  220. }
  221. break;
  222. case HK_CANVAS_CAIRO:
  223. cmd.SetId( ID_MENU_CANVAS_CAIRO );
  224. GetEventHandler()->ProcessEvent( cmd );
  225. break;
  226. case HK_CANVAS_OPENGL:
  227. cmd.SetId( ID_MENU_CANVAS_OPENGL );
  228. GetEventHandler()->ProcessEvent( cmd );
  229. break;
  230. case HK_CANVAS_LEGACY:
  231. cmd.SetId( ID_MENU_CANVAS_LEGACY );
  232. GetEventHandler()->ProcessEvent( cmd );
  233. break;
  234. }
  235. return true;
  236. }