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.

158 lines
5.9 KiB

16 years ago
16 years ago
16 years ago
  1. /***************/
  2. /* hotkeys.cpp */
  3. /***************/
  4. #include "fctsys.h"
  5. #include "common.h"
  6. #include "kicad_device_context.h"
  7. #include "gerbview.h"
  8. #include "class_drawpanel.h"
  9. #include "hotkeys.h"
  10. /* How to add a new hotkey:
  11. * add a new id in the enum hotkey_id_commnand like MY_NEW_ID_FUNCTION.
  12. * add a new Ki_HotkeyInfo entry like:
  13. * static Ki_HotkeyInfo HkMyNewEntry(wxT("Command Label"), MY_NEW_ID_FUNCTION, default key value);
  14. * "Command Label" is the name used in hotkey list display, and the identifier in the hotkey list file
  15. * MY_NEW_ID_FUNCTION is an equivalent id function used in the switch in OnHotKey() function.
  16. * default key value is the default hotkey for this command. Can be overrided by the user hotkey list file
  17. * add the HkMyNewEntry pointer in the s_board_edit_Hotkey_List list ( or/and the s_module_edit_Hotkey_List list)
  18. * Add the new code in the switch in OnHotKey() function.
  19. * when the variable PopupOn is true, an item is currently edited.
  20. * This can be usefull if the new function cannot be executed while an item is currently being edited
  21. * ( For example, one cannot start a new wire when a component is moving.)
  22. *
  23. * Note: If an hotkey is a special key, be sure the corresponding wxWidget keycode (WXK_XXXX)
  24. * is handled in the hotkey_name_descr s_Hotkey_Name_List list (see hotkeys_basic.cpp)
  25. * and see this list for some ascii keys (space ...)
  26. */
  27. /* local variables */
  28. /* Hotkey list: */
  29. static Ki_HotkeyInfo HkResetLocalCoord( wxT( "Reset local coord." ), HK_RESET_LOCAL_COORD, ' ' );
  30. static Ki_HotkeyInfo HkZoomAuto( wxT( "Zoom Auto" ), HK_ZOOM_AUTO, WXK_HOME );
  31. static Ki_HotkeyInfo HkZoomCenter( wxT( "Zoom Center" ), HK_ZOOM_CENTER, WXK_F4 );
  32. static Ki_HotkeyInfo HkZoomRedraw( wxT( "Zoom Redraw" ), HK_ZOOM_REDRAW, WXK_F3 );
  33. static Ki_HotkeyInfo HkZoomOut( wxT( "Zoom Out" ), HK_ZOOM_OUT, WXK_F2 );
  34. static Ki_HotkeyInfo HkZoomIn( wxT( "Zoom In" ), HK_ZOOM_IN, WXK_F1 );
  35. static Ki_HotkeyInfo HkHelp( wxT( "Help: this message" ), HK_HELP, '?' );
  36. static Ki_HotkeyInfo HkSwitchUnits( wxT( "Switch Units" ), HK_SWITCH_UNITS, 'U' );
  37. static Ki_HotkeyInfo HkTrackDisplayMode( wxT(
  38. "Track Display Mode" ),
  39. HK_SWITCH_GBR_ITEMS_DISPLAY_MODE, 'F' );
  40. static Ki_HotkeyInfo HkSwitch2NextCopperLayer( wxT(
  41. "Switch to Next Layer" ),
  42. HK_SWITCH_LAYER_TO_NEXT, '+' );
  43. static Ki_HotkeyInfo HkSwitch2PreviousCopperLayer( wxT(
  44. "Switch to Previous Layer" ),
  45. HK_SWITCH_LAYER_TO_PREVIOUS, '-' );
  46. // List of common hotkey descriptors
  47. Ki_HotkeyInfo* s_Gerbview_Hotkey_List[] = {
  48. &HkHelp,
  49. &HkZoomIn, &HkZoomOut, &HkZoomRedraw, &HkZoomCenter,
  50. &HkZoomAuto, &HkSwitchUnits, &HkResetLocalCoord,
  51. &HkTrackDisplayMode,
  52. &HkSwitch2NextCopperLayer,
  53. &HkSwitch2PreviousCopperLayer,
  54. NULL
  55. };
  56. // list of sections and corresponding hotkey list for pcbnew (used to create an hotkey config file)
  57. struct Ki_HotkeyInfoSectionDescriptor s_Gerbview_Hokeys_Descr[] =
  58. {
  59. { &g_CommonSectionTag, s_Gerbview_Hotkey_List, NULL },
  60. { NULL, NULL, NULL }
  61. };
  62. /***********************************************************/
  63. void GERBVIEW_FRAME::OnHotKey( wxDC* DC, int hotkey, EDA_ITEM* DrawStruct )
  64. /***********************************************************/
  65. /* Hot keys. Some commands are relatives to the item under the mouse cursor
  66. * Commands are case insensitive
  67. * @param DC = current device context
  68. * @param hotkey = hotkey code (ascii or wxWidget code for special keys)
  69. * @param DrawStruct = NULL or pointer on a EDA_ITEM under the mouse cursor
  70. */
  71. {
  72. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  73. cmd.SetEventObject( this );
  74. /* Convert lower to upper case (the usual toupper function has problem with non ascii codes like function keys */
  75. if( (hotkey >= 'a') && (hotkey <= 'z') )
  76. hotkey += 'A' - 'a';
  77. Ki_HotkeyInfo * HK_Descr = GetDescriptorFromHotkey( hotkey, s_Gerbview_Hotkey_List );
  78. if( HK_Descr == NULL ) return;
  79. switch( HK_Descr->m_Idcommand )
  80. {
  81. default:
  82. case HK_NOT_FOUND:
  83. return;
  84. case HK_HELP: // Display Current hotkey list
  85. DisplayHotkeyList( this, s_Gerbview_Hokeys_Descr );
  86. break;
  87. case HK_ZOOM_IN:
  88. cmd.SetId( ID_POPUP_ZOOM_IN );
  89. GetEventHandler()->ProcessEvent( cmd );
  90. break;
  91. case HK_ZOOM_OUT:
  92. cmd.SetId( ID_POPUP_ZOOM_OUT );
  93. GetEventHandler()->ProcessEvent( cmd );
  94. break;
  95. case HK_ZOOM_REDRAW:
  96. cmd.SetId( ID_ZOOM_REDRAW );
  97. GetEventHandler()->ProcessEvent( cmd );
  98. break;
  99. case HK_ZOOM_CENTER:
  100. cmd.SetId( ID_POPUP_ZOOM_CENTER );
  101. GetEventHandler()->ProcessEvent( cmd );
  102. break;
  103. case HK_ZOOM_AUTO:
  104. cmd.SetId( ID_ZOOM_PAGE );
  105. GetEventHandler()->ProcessEvent( cmd );
  106. break;
  107. case HK_RESET_LOCAL_COORD: /*Reset the relative coord */
  108. GetScreen()->m_O_Curseur = GetScreen()->GetCrossHairPosition();
  109. break;
  110. case HK_SWITCH_UNITS:
  111. g_UserUnit = (g_UserUnit == INCHES ) ? MILLIMETRES : INCHES;
  112. break;
  113. case HK_SWITCH_GBR_ITEMS_DISPLAY_MODE:
  114. DisplayOpt.DisplayPcbTrackFill ^= 1; DisplayOpt.DisplayPcbTrackFill &= 1;
  115. DrawPanel->Refresh();
  116. break;
  117. case HK_SWITCH_LAYER_TO_PREVIOUS:
  118. if( getActiveLayer() > 0 )
  119. {
  120. setActiveLayer( getActiveLayer() - 1 );
  121. DrawPanel->Refresh();
  122. }
  123. break;
  124. case HK_SWITCH_LAYER_TO_NEXT:
  125. if( getActiveLayer() < 31 )
  126. {
  127. setActiveLayer( getActiveLayer() + 1 );
  128. DrawPanel->Refresh();
  129. }
  130. break;
  131. }
  132. }