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.

273 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 HkLinesDisplayMode( _HKI( "Gbr Lines Display Mode" ),
  67. HK_GBR_LINES_DISPLAY_MODE, 'L' );
  68. static EDA_HOTKEY HkFlashedDisplayMode( _HKI( "Gbr Flashed Display Mode" ),
  69. HK_GBR_FLASHED_DISPLAY_MODE, 'F' );
  70. static EDA_HOTKEY HkPolygonDisplayMode( _HKI( "Gbr Polygons Display Mode" ),
  71. HK_GBR_POLYGON_DISPLAY_MODE, 'P' );
  72. static EDA_HOTKEY HkNegativeObjDisplayMode( _HKI( "Gbr Negative Obj Display Mode" ),
  73. HK_GBR_NEGATIVE_DISPLAY_ONOFF, 'N' );
  74. static EDA_HOTKEY HkDCodesDisplayMode( _HKI( "DCodes Display Mode" ),
  75. HK_GBR_DCODE_DISPLAY_ONOFF, 'D' );
  76. static EDA_HOTKEY HkSwitch2NextCopperLayer( _HKI( "Switch to Next Layer" ),
  77. HK_SWITCH_LAYER_TO_NEXT, '+' );
  78. static EDA_HOTKEY HkSwitch2PreviousCopperLayer( _HKI( "Switch to Previous Layer" ),
  79. HK_SWITCH_LAYER_TO_PREVIOUS, '-' );
  80. static EDA_HOTKEY HkCanvasDefault( _HKI( "Switch to Legacy Toolset" ),
  81. HK_CANVAS_LEGACY,
  82. #ifdef __WXMAC__
  83. GR_KB_ALT +
  84. #endif
  85. WXK_F9 );
  86. static EDA_HOTKEY HkCanvasOpenGL( _HKI( "Switch to Modern Toolset with hardware-accelerated graphics (recommended)" ),
  87. HK_CANVAS_OPENGL,
  88. #ifdef __WXMAC__
  89. GR_KB_ALT +
  90. #endif
  91. WXK_F11 );
  92. static EDA_HOTKEY HkCanvasCairo( _HKI( "Switch to Modern Toolset with software graphics (fall-back)" ),
  93. HK_CANVAS_CAIRO,
  94. #ifdef __WXMAC__
  95. GR_KB_ALT +
  96. #endif
  97. WXK_F12 );
  98. static EDA_HOTKEY HkMeasureTool( _HKI( "Measure Distance (Modern Toolset only)" ),
  99. HK_MEASURE_TOOL, 'M' + GR_KB_SHIFTCTRL );
  100. // List of common hotkey descriptors
  101. EDA_HOTKEY* gerbviewHotkeyList[] = {
  102. &HkHelp,
  103. &HkZoomIn, &HkZoomOut, &HkZoomRedraw, &HkZoomCenter,
  104. &HkZoomAuto, &HkZoomSelection, &HkSwitchUnits, &HkResetLocalCoord,
  105. &HkLinesDisplayMode, &HkFlashedDisplayMode, &HkPolygonDisplayMode,
  106. &HkDCodesDisplayMode, &HkNegativeObjDisplayMode,
  107. &HkSwitch2NextCopperLayer,
  108. &HkSwitch2PreviousCopperLayer,
  109. &HkCanvasDefault,
  110. &HkCanvasOpenGL,
  111. &HkCanvasCairo,
  112. &HkMeasureTool,
  113. NULL
  114. };
  115. // list of sections and corresponding hotkey list for GerbView (used to create an hotkey
  116. // config file)
  117. static wxString gerbviewSectionTag( wxT( "[gerbview]" ) );
  118. static wxString gerbviewSectionTitle( _HKI( "Gerbview Hotkeys" ) );
  119. struct EDA_HOTKEY_CONFIG GerbviewHokeysDescr[] =
  120. {
  121. { &gerbviewSectionTag, gerbviewHotkeyList, &gerbviewSectionTitle },
  122. { NULL, NULL, NULL }
  123. };
  124. EDA_HOTKEY* GERBVIEW_FRAME::GetHotKeyDescription( int aCommand ) const
  125. {
  126. EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, gerbviewHotkeyList );
  127. return HK_Descr;
  128. }
  129. bool GERBVIEW_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem )
  130. {
  131. #define CHANGE( x ) ( x ) = not (x )
  132. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  133. cmd.SetEventObject( this );
  134. /* Convert lower to upper case (the usual toupper function has problem with non ascii
  135. * codes like function keys */
  136. if( (aHotkeyCode >= 'a') && (aHotkeyCode <= 'z') )
  137. aHotkeyCode += 'A' - 'a';
  138. EDA_HOTKEY * HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, gerbviewHotkeyList );
  139. if( HK_Descr == NULL )
  140. return false;
  141. switch( HK_Descr->m_Idcommand )
  142. {
  143. default:
  144. case HK_NOT_FOUND:
  145. return false;
  146. case HK_HELP: // Display Current hotkey list
  147. DisplayHotkeyList( this, GerbviewHokeysDescr );
  148. break;
  149. case HK_ZOOM_IN:
  150. cmd.SetId( ID_KEY_ZOOM_IN );
  151. GetEventHandler()->ProcessEvent( cmd );
  152. break;
  153. case HK_ZOOM_OUT:
  154. cmd.SetId( ID_KEY_ZOOM_OUT );
  155. GetEventHandler()->ProcessEvent( cmd );
  156. break;
  157. case HK_ZOOM_REDRAW:
  158. cmd.SetId( ID_ZOOM_REDRAW );
  159. GetEventHandler()->ProcessEvent( cmd );
  160. break;
  161. case HK_ZOOM_CENTER:
  162. cmd.SetId( ID_POPUP_ZOOM_CENTER );
  163. GetEventHandler()->ProcessEvent( cmd );
  164. break;
  165. case HK_ZOOM_SELECTION:
  166. //cmd.SetId( ID_ZOOM_SELECTION );
  167. //GetEventHandler()->ProcessEvent( cmd );
  168. break;
  169. case HK_ZOOM_AUTO:
  170. cmd.SetId( ID_ZOOM_PAGE );
  171. GetEventHandler()->ProcessEvent( cmd );
  172. break;
  173. case HK_RESET_LOCAL_COORD: // Reset the relative coord
  174. GetScreen()->m_O_Curseur = GetCrossHairPosition();
  175. break;
  176. case HK_SWITCH_UNITS:
  177. cmd.SetId( (GetUserUnits() == INCHES) ?
  178. ID_TB_OPTIONS_SELECT_UNIT_MM : ID_TB_OPTIONS_SELECT_UNIT_INCH );
  179. GetEventHandler()->ProcessEvent( cmd );
  180. break;
  181. case HK_GBR_LINES_DISPLAY_MODE:
  182. CHANGE( m_DisplayOptions.m_DisplayLinesFill );
  183. m_canvas->Refresh();
  184. break;
  185. case HK_GBR_FLASHED_DISPLAY_MODE:
  186. CHANGE( m_DisplayOptions.m_DisplayFlashedItemsFill );
  187. m_canvas->Refresh( true );
  188. break;
  189. case HK_GBR_POLYGON_DISPLAY_MODE:
  190. CHANGE( m_DisplayOptions.m_DisplayPolygonsFill );
  191. m_canvas->Refresh();
  192. break;
  193. case HK_GBR_NEGATIVE_DISPLAY_ONOFF:
  194. SetElementVisibility( LAYER_NEGATIVE_OBJECTS, not IsElementVisible( LAYER_NEGATIVE_OBJECTS ) );
  195. m_canvas->Refresh();
  196. break;
  197. case HK_GBR_DCODE_DISPLAY_ONOFF:
  198. SetElementVisibility( LAYER_DCODES, not IsElementVisible( LAYER_DCODES ) );
  199. m_canvas->Refresh();
  200. break;
  201. case HK_SWITCH_LAYER_TO_PREVIOUS:
  202. if( GetActiveLayer() > 0 )
  203. {
  204. SetActiveLayer( GetActiveLayer() - 1, true );
  205. m_canvas->Refresh();
  206. }
  207. break;
  208. case HK_SWITCH_LAYER_TO_NEXT:
  209. if( GetActiveLayer() < GERBER_DRAWLAYERS_COUNT - 1 )
  210. {
  211. SetActiveLayer( GetActiveLayer() + 1, true );
  212. m_canvas->Refresh();
  213. }
  214. break;
  215. case HK_CANVAS_CAIRO:
  216. cmd.SetId( ID_MENU_CANVAS_CAIRO );
  217. GetEventHandler()->ProcessEvent( cmd );
  218. break;
  219. case HK_CANVAS_OPENGL:
  220. cmd.SetId( ID_MENU_CANVAS_OPENGL );
  221. GetEventHandler()->ProcessEvent( cmd );
  222. break;
  223. case HK_CANVAS_LEGACY:
  224. cmd.SetId( ID_MENU_CANVAS_LEGACY );
  225. GetEventHandler()->ProcessEvent( cmd );
  226. break;
  227. }
  228. return true;
  229. }