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.

683 lines
24 KiB

11 years ago
11 years ago
11 years ago
16 years ago
16 years ago
16 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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2008 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <fctsys.h>
  26. #include <id.h>
  27. #include <eeschema_id.h>
  28. #include <ee_hotkeys.h>
  29. #include <sch_edit_frame.h>
  30. #include <sch_draw_panel.h>
  31. #include <general.h>
  32. #include <lib_edit_frame.h>
  33. #include <viewlib_frame.h>
  34. #include <class_libentry.h>
  35. #include <sch_junction.h>
  36. #include <sch_line.h>
  37. #include <sch_component.h>
  38. #include <sch_sheet.h>
  39. #include <dialogs/dialog_schematic_find.h>
  40. #include <tool/tool_manager.h>
  41. #include <tools/ee_selection_tool.h>
  42. #include <tools/ee_actions.h>
  43. // Remark: the hotkey message info is used as keyword in hotkey config files and
  44. // as comments in help windows, therefore translated only when displayed
  45. // they are marked _HKI to be extracted by translation tools
  46. // See hotkeys_basic.h for more info
  47. /* How to add a new hotkey:
  48. * add a new id in the enum hotkey_id_command like MY_NEW_ID_FUNCTION (see
  49. * hotkeys.h).
  50. * add a new EDA_HOTKEY entry like:
  51. * static EDA_HOTKEY HkMyNewEntry(_HKI("Command Label"), MY_NEW_ID_FUNCTION,
  52. * default key value);
  53. * _HKI("Command Label") is the name used in hotkey list display, and the
  54. * identifier in the hotkey list file
  55. * MY_NEW_ID_FUNCTION is an equivalent id function used in the switch in
  56. * OnHotKey() function.
  57. * default key value is the default hotkey for this command. Can be overridden
  58. * by the user hotkey list file
  59. * add the HkMyNewEntry pointer in the schematic_Hotkey_List list or the
  60. * libEdit_Hotkey_List list or common_Hotkey_List if the same command is
  61. * added both in Eeschema and libedit)
  62. * Add the new code in the switch in OnHotKey() function.
  63. * when the variable itemInEdit is true, an item is currently edited.
  64. * This can be useful if the new function cannot be executed while an item is
  65. * currently being edited
  66. * ( For example, one cannot start a new wire when a component is moving.)
  67. *
  68. * Note: If an hotkey is a special key be sure the corresponding wxWidget
  69. * keycode (WXK_XXXX) is handled in the hotkey_name_descr
  70. * s_Hotkey_Name_List list (see hotkeys_basic.cpp) and see this list
  71. * for some ascii keys (space ...)
  72. *
  73. * Key modifier are: GR_KB_CTRL GR_KB_ALT
  74. */
  75. // Common commands
  76. // Fit on Screen
  77. #if !defined( __WXMAC__ )
  78. static EDA_HOTKEY HkZoomAuto( _HKI( "Fit on Screen" ), HK_ZOOM_AUTO, WXK_HOME,
  79. ID_ZOOM_PAGE );
  80. #else
  81. static EDA_HOTKEY HkZoomAuto( _HKI( "Zoom Auto" ), HK_ZOOM_AUTO, GR_KB_CTRL + '0',
  82. ID_ZOOM_PAGE );
  83. #endif
  84. static EDA_HOTKEY HkZoomCenter( _HKI( "Zoom Center" ), HK_ZOOM_CENTER, WXK_F4,
  85. ID_POPUP_ZOOM_CENTER );
  86. // Refresh Screen
  87. #if !defined( __WXMAC__ )
  88. static EDA_HOTKEY HkZoomRedraw( _HKI( "Zoom Redraw" ), HK_ZOOM_REDRAW, WXK_F3,
  89. ID_ZOOM_REDRAW );
  90. #else
  91. static EDA_HOTKEY HkZoomRedraw( _HKI( "Zoom Redraw" ), HK_ZOOM_REDRAW, GR_KB_CTRL + 'R',
  92. ID_ZOOM_REDRAW );
  93. #endif
  94. // Zoom In
  95. #if !defined( __WXMAC__ )
  96. static EDA_HOTKEY HkZoomIn( _HKI( "Zoom In" ), HK_ZOOM_IN, WXK_F1,
  97. ID_KEY_ZOOM_IN );
  98. #else
  99. static EDA_HOTKEY HkZoomIn( _HKI( "Zoom In" ), HK_ZOOM_IN, GR_KB_CTRL + '+',
  100. ID_KEY_ZOOM_IN );
  101. #endif
  102. // Zoom Out
  103. #if !defined( __WXMAC__ )
  104. static EDA_HOTKEY HkZoomOut( _HKI( "Zoom Out" ), HK_ZOOM_OUT, WXK_F2,
  105. ID_KEY_ZOOM_OUT );
  106. #else
  107. static EDA_HOTKEY HkZoomOut( _HKI( "Zoom Out" ), HK_ZOOM_OUT, GR_KB_CTRL + '-',
  108. ID_KEY_ZOOM_OUT );
  109. #endif
  110. static EDA_HOTKEY HkHelp( _HKI( "List Hotkeys" ), HK_HELP, GR_KB_CTRL + WXK_F1 );
  111. static EDA_HOTKEY HkPreferences( _HKI( "Preferences" ), HK_PREFERENCES, GR_KB_CTRL + ',',
  112. wxID_PREFERENCES );
  113. static EDA_HOTKEY HkResetLocalCoord( _HKI( "Reset Local Coordinates" ), HK_RESET_LOCAL_COORD, ' ' );
  114. static EDA_HOTKEY HkLeaveSheet( _HKI( "Leave Sheet" ), HK_LEAVE_SHEET, GR_KB_ALT + WXK_BACK,
  115. ID_SCH_LEAVE_SHEET );
  116. // mouse click command:
  117. static EDA_HOTKEY HkMouseLeftClick( _HKI( "Mouse Left Click" ), HK_LEFT_CLICK, WXK_RETURN,
  118. ID_MOUSE_CLICK );
  119. static EDA_HOTKEY HkMouseLeftDClick( _HKI( "Mouse Left Double Click" ), HK_LEFT_DCLICK, WXK_END,
  120. ID_MOUSE_DOUBLECLICK );
  121. // Schematic editor
  122. static EDA_HOTKEY HkBeginWire( _HKI( "Begin Wire" ), HK_BEGIN_WIRE, 'W',
  123. ID_WIRE_BUTT );
  124. static EDA_HOTKEY HkBeginBus( _HKI( "Begin Bus" ), HK_BEGIN_BUS, 'B',
  125. ID_BUS_BUTT );
  126. static EDA_HOTKEY HkEndLineWireBus( _HKI( "End Line Wire Bus" ), HK_END_CURR_LINEWIREBUS, 'K',
  127. ID_SCH_END_LINE_WIRE_OR_BUS );
  128. static EDA_HOTKEY HkAddLabel( _HKI( "Add Label" ), HK_ADD_LABEL, 'L',
  129. ID_LABEL_BUTT );
  130. static EDA_HOTKEY HkAddHierarchicalLabel( _HKI( "Add Hierarchical Label" ), HK_ADD_HLABEL, 'H',
  131. ID_HIERLABEL_BUTT );
  132. static EDA_HOTKEY HkAddGlobalLabel( _HKI( "Add Global Label" ), HK_ADD_GLABEL, GR_KB_CTRL + 'H',
  133. ID_GLOBALLABEL_BUTT );
  134. static EDA_HOTKEY HkAddJunction( _HKI( "Add Junction" ), HK_ADD_JUNCTION, 'J',
  135. ID_JUNCTION_BUTT );
  136. static EDA_HOTKEY HkAddComponent( _HKI( "Add Symbol" ), HK_ADD_NEW_COMPONENT, 'A',
  137. ID_SCH_PLACE_COMPONENT );
  138. static EDA_HOTKEY HkAddPower( _HKI( "Add Power" ), HK_ADD_NEW_POWER, 'P',
  139. ID_PLACE_POWER_BUTT );
  140. static EDA_HOTKEY HkAddNoConn( _HKI( "Add No Connect Flag" ), HK_ADD_NOCONN_FLAG, 'Q',
  141. ID_NOCONN_BUTT );
  142. static EDA_HOTKEY HkAddHierSheet( _HKI( "Add Sheet" ), HK_ADD_HIER_SHEET, 'S',
  143. ID_SHEET_SYMBOL_BUTT );
  144. static EDA_HOTKEY HkAddBusEntry( _HKI( "Add Bus Entry" ), HK_ADD_BUS_ENTRY, '/',
  145. ID_BUSTOBUS_ENTRY_BUTT );
  146. static EDA_HOTKEY HkAddWireEntry( _HKI( "Add Wire Entry" ), HK_ADD_WIRE_ENTRY, 'Z',
  147. ID_WIRETOBUS_ENTRY_BUTT );
  148. static EDA_HOTKEY HkAddGraphicPolyLine( _HKI( "Add Graphic PolyLine" ), HK_ADD_GRAPHIC_POLYLINE, 'I',
  149. ID_LINE_COMMENT_BUTT );
  150. static EDA_HOTKEY HkAddGraphicText( _HKI( "Add Graphic Text" ), HK_ADD_GRAPHIC_TEXT, 'T',
  151. ID_TEXT_COMMENT_BUTT );
  152. static EDA_HOTKEY HkMirrorY( _HKI( "Mirror Y" ), HK_MIRROR_Y, 'Y',
  153. ID_SCH_MIRROR_Y );
  154. static EDA_HOTKEY HkMirrorX( _HKI( "Mirror X" ), HK_MIRROR_X, 'X',
  155. ID_SCH_MIRROR_X );
  156. static EDA_HOTKEY HkRotate( _HKI( "Rotate Item" ), HK_ROTATE, 'R',
  157. ID_SCH_ROTATE_CLOCKWISE );
  158. static EDA_HOTKEY HkEdit( _HKI( "Edit Item" ), HK_EDIT, 'E',
  159. ID_SCH_EDIT_ITEM );
  160. static EDA_HOTKEY HkEditValue( _HKI( "Edit Symbol Value" ), HK_EDIT_COMPONENT_VALUE, 'V',
  161. ID_SCH_EDIT_COMPONENT_VALUE );
  162. static EDA_HOTKEY HkEditReference( _HKI( "Edit Symbol Reference" ), HK_EDIT_COMPONENT_REFERENCE, 'U',
  163. ID_SCH_EDIT_COMPONENT_REFERENCE );
  164. static EDA_HOTKEY HkEditFootprint( _HKI( "Edit Symbol Footprint" ), HK_EDIT_COMPONENT_FOOTPRINT, 'F',
  165. ID_SCH_EDIT_COMPONENT_FOOTPRINT );
  166. static EDA_HOTKEY HkShowDatasheet( _HKI( "Show Symbol Datasheet" ), HK_SHOW_COMPONENT_DATASHEET, 'D',
  167. ID_SCH_DISPLAYDOC_CMP );
  168. static EDA_HOTKEY HkEditWithLibedit( _HKI( "Edit with Symbol Editor" ), HK_EDIT_COMPONENT_WITH_LIBEDIT, 'E' + GR_KB_CTRL,
  169. ID_SCH_CALL_LIBEDIT_AND_LOAD_CMP );
  170. static EDA_HOTKEY HkMove( _HKI( "Move Schematic Item" ), HK_MOVE, 'M',
  171. ID_SCH_MOVE );
  172. static EDA_HOTKEY HkDuplicateItem( _HKI( "Duplicate" ), HK_DUPLICATE, 'D' + GR_KB_CTRL,
  173. ID_SCH_DUPLICATE );
  174. static EDA_HOTKEY HkDrag( _HKI( "Drag Item" ), HK_DRAG, 'G',
  175. ID_SCH_DRAG );
  176. static EDA_HOTKEY HkInsert( _HKI( "Repeat Last Item" ), HK_REPEAT_LAST, WXK_INSERT );
  177. static EDA_HOTKEY HkDelete( _HKI( "Delete Item" ), HK_DELETE, WXK_DELETE );
  178. static EDA_HOTKEY HkFindItem( _HKI( "Find Item" ), HK_FIND_ITEM, 'F' + GR_KB_CTRL,
  179. ID_FIND_ITEMS );
  180. static EDA_HOTKEY HkFindNextItem( _HKI( "Find Next Item" ), HK_FIND_NEXT_ITEM, WXK_F5,
  181. wxEVT_COMMAND_FIND );
  182. static EDA_HOTKEY HkFindReplace( _HKI( "Find and Replace" ), HK_FIND_REPLACE, 'F' + GR_KB_CTRL + GR_KB_ALT,
  183. wxID_REPLACE );
  184. static EDA_HOTKEY HkFindNextMarker( _HKI( "Find Next Marker" ), HK_FIND_NEXT_DRC_MARKER, WXK_F5 + GR_KB_SHIFT,
  185. EVT_COMMAND_FIND_DRC_MARKER );
  186. static EDA_HOTKEY HkZoomSelection( _HKI( "Zoom to Selection" ), HK_ZOOM_SELECTION, GR_KB_CTRL + WXK_F5,
  187. ID_ZOOM_SELECTION );
  188. // Special keys for library editor:
  189. static EDA_HOTKEY HkCreatePin( _HKI( "Create Pin" ), HK_LIBEDIT_CREATE_PIN, 'P',
  190. ID_LIBEDIT_PIN_BUTT );
  191. static EDA_HOTKEY HkInsertPin( _HKI( "Repeat Pin" ), HK_REPEAT_LAST, WXK_INSERT );
  192. static EDA_HOTKEY HkViewDoc( _HKI( "Show Datasheet" ), HK_LIBEDIT_VIEW_DOC, 'D' + GR_KB_ALT,
  193. ID_LIBEDIT_VIEW_DOC );
  194. // Autoplace fields
  195. static EDA_HOTKEY HkAutoplaceFields( _HKI( "Autoplace Fields" ), HK_AUTOPLACE_FIELDS, 'O',
  196. ID_AUTOPLACE_FIELDS );
  197. static EDA_HOTKEY HkUpdatePcbFromSch( _HKI( "Update PCB from Schematic" ), HK_UPDATE_PCB_FROM_SCH, WXK_F8,
  198. ID_UPDATE_PCB_FROM_SCH );
  199. // Selection
  200. static EDA_HOTKEY HkSelectNode( _HKI( "Select Node" ), HK_SELECT_NODE, GR_KB_ALT + '3',
  201. ID_HOTKEY_SELECT_NODE);
  202. static EDA_HOTKEY HkSelectConnection( _HKI( "Select Connection" ), HK_SELECT_CONNECTION, GR_KB_ALT + '4',
  203. ID_HOTKEY_SELECT_CONNECTION );
  204. // Higtlight connection
  205. static EDA_HOTKEY HkHighlightConnection( _HKI( "Highlight Net" ), ID_HOTKEY_HIGHLIGHT, 'B' + GR_KB_CTRL,
  206. ID_HIGHLIGHT_NET );
  207. static EDA_HOTKEY HkUnfoldBus( _HKI( "Unfold from Bus" ), HK_UNFOLD_BUS, 'C',
  208. ID_SCH_UNFOLD_BUS );
  209. // Common: hotkeys_basic.h
  210. static EDA_HOTKEY HkNew( _HKI( "New" ), HK_NEW, GR_KB_CTRL + 'N',
  211. wxID_NEW );
  212. static EDA_HOTKEY HkOpen( _HKI( "Open" ), HK_OPEN, GR_KB_CTRL + 'O',
  213. wxID_OPEN );
  214. static EDA_HOTKEY HkSave( _HKI( "Save" ), HK_SAVE, GR_KB_CTRL + 'S',
  215. wxID_SAVE );
  216. static EDA_HOTKEY HkSaveAs( _HKI( "Save As" ), HK_SAVEAS, GR_KB_SHIFT + GR_KB_CTRL + 'S',
  217. wxID_SAVEAS );
  218. static EDA_HOTKEY HkPrint( _HKI( "Print" ), HK_PRINT, GR_KB_CTRL + 'P',
  219. wxID_PRINT );
  220. static EDA_HOTKEY HkUndo( _HKI( "Undo" ), HK_UNDO, GR_KB_CTRL + 'Z',
  221. wxID_UNDO );
  222. #if !defined( __WXMAC__ )
  223. static EDA_HOTKEY HkRedo( _HKI( "Redo" ), HK_REDO, GR_KB_CTRL + 'Y',
  224. wxID_REDO );
  225. #else
  226. static EDA_HOTKEY HkRedo( _HKI( "Redo" ), HK_REDO, GR_KB_SHIFTCTRL + 'Z',
  227. wxID_REDO );
  228. #endif
  229. static EDA_HOTKEY HkEditCut( _HKI( "Cut" ), HK_EDIT_CUT, GR_KB_CTRL + 'X',
  230. wxID_CUT );
  231. static EDA_HOTKEY HkEditCopy( _HKI( "Copy" ), HK_EDIT_COPY, GR_KB_CTRL + 'C',
  232. wxID_COPY );
  233. static EDA_HOTKEY HkEditPaste( _HKI( "Paste" ), HK_EDIT_PASTE, GR_KB_CTRL + 'V',
  234. wxID_PASTE );
  235. static EDA_HOTKEY HkCanvasOpenGL( _HKI( "Switch to Modern Toolset with hardware-accelerated graphics (recommended)" ),
  236. HK_CANVAS_OPENGL,
  237. #ifdef __WXMAC__
  238. GR_KB_ALT +
  239. #endif
  240. WXK_F11, ID_MENU_CANVAS_OPENGL );
  241. static EDA_HOTKEY HkCanvasCairo( _HKI( "Switch to Modern Toolset with software graphics (fall-back)" ),
  242. HK_CANVAS_CAIRO,
  243. #ifdef __WXMAC__
  244. GR_KB_ALT +
  245. #endif
  246. WXK_F12, ID_MENU_CANVAS_CAIRO );
  247. // List of common hotkey descriptors
  248. static EDA_HOTKEY* common_Hotkey_List[] =
  249. {
  250. &HkNew, &HkOpen, &HkSave, &HkSaveAs, &HkPrint,
  251. &HkUndo, &HkRedo,
  252. &HkEditCut, &HkEditCopy, &HkEditPaste,
  253. &HkHelp,
  254. &HkPreferences,
  255. &HkZoomIn,
  256. &HkZoomOut,
  257. &HkZoomRedraw,
  258. &HkZoomCenter,
  259. &HkZoomAuto,
  260. &HkZoomSelection,
  261. &HkResetLocalCoord,
  262. &HkEdit,
  263. &HkDuplicateItem,
  264. &HkDelete,
  265. &HkRotate,
  266. &HkDrag,
  267. &HkMove,
  268. &HkMirrorX,
  269. &HkMirrorY,
  270. &HkMouseLeftClick,
  271. &HkMouseLeftDClick,
  272. NULL
  273. };
  274. // List of common hotkey descriptors, for the library viewer
  275. static EDA_HOTKEY* common_basic_Hotkey_List[] =
  276. {
  277. &HkHelp,
  278. &HkZoomIn,
  279. &HkZoomOut,
  280. &HkZoomRedraw,
  281. &HkZoomCenter,
  282. &HkZoomAuto,
  283. &HkResetLocalCoord,
  284. &HkEdit,
  285. &HkDuplicateItem,
  286. &HkDelete,
  287. &HkRotate,
  288. &HkMove,
  289. &HkMirrorX,
  290. &HkMirrorY,
  291. &HkMouseLeftClick,
  292. &HkMouseLeftDClick,
  293. NULL
  294. };
  295. // List of hotkey descriptors for schematic
  296. static EDA_HOTKEY* schematic_Hotkey_List[] =
  297. {
  298. &HkFindItem,
  299. &HkFindNextItem,
  300. &HkFindNextMarker,
  301. &HkFindReplace,
  302. &HkInsert,
  303. &HkAddComponent,
  304. &HkAddPower,
  305. &HkEditValue,
  306. &HkEditReference,
  307. &HkEditFootprint,
  308. &HkShowDatasheet,
  309. &HkEditWithLibedit,
  310. &HkSelectNode,
  311. &HkSelectConnection,
  312. &HkBeginWire,
  313. &HkBeginBus,
  314. &HkEndLineWireBus,
  315. &HkAddLabel,
  316. &HkAddHierarchicalLabel,
  317. &HkAddGlobalLabel,
  318. &HkAddJunction,
  319. &HkAddNoConn,
  320. &HkAddHierSheet,
  321. &HkAddWireEntry,
  322. &HkAddBusEntry,
  323. &HkAddGraphicPolyLine,
  324. &HkAddGraphicText,
  325. &HkUpdatePcbFromSch,
  326. &HkAutoplaceFields,
  327. &HkLeaveSheet,
  328. &HkHighlightConnection,
  329. &HkUnfoldBus,
  330. &HkCanvasCairo,
  331. &HkCanvasOpenGL,
  332. NULL
  333. };
  334. // List of hotkey descriptors for library editor
  335. static EDA_HOTKEY* libEdit_Hotkey_List[] =
  336. {
  337. &HkCreatePin,
  338. &HkInsertPin,
  339. &HkViewDoc,
  340. NULL
  341. };
  342. // List of hotkey descriptors for library viewer (currently empty
  343. static EDA_HOTKEY* viewlib_Hotkey_List[] =
  344. {
  345. NULL
  346. };
  347. // Keyword Identifiers (tags) in key code configuration file (section names)
  348. // (.m_SectionTag member of a EDA_HOTKEY_CONFIG)
  349. static wxString schematicSectionTag( wxT( "[eeschema]" ) );
  350. static wxString libEditSectionTag( wxT( "[libedit]" ) );
  351. // Titles for hotkey editor and hotkey display
  352. static wxString commonSectionTitle( _HKI( "Common" ) );
  353. static wxString schematicSectionTitle( _HKI( "Schematic Editor" ) );
  354. static wxString libEditSectionTitle( _HKI( "Library Editor" ) );
  355. // list of sections and corresponding hotkey list for Eeschema (used to create
  356. // an hotkey config file)
  357. struct EDA_HOTKEY_CONFIG g_Eeschema_Hotkeys_Descr[] =
  358. {
  359. { &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle },
  360. { &schematicSectionTag, schematic_Hotkey_List, &schematicSectionTitle },
  361. { &libEditSectionTag, libEdit_Hotkey_List, &libEditSectionTitle },
  362. { NULL, NULL, NULL }
  363. };
  364. // list of sections and corresponding hotkey list for the schematic editor
  365. // (used to list current hotkeys)
  366. struct EDA_HOTKEY_CONFIG g_Schematic_Hotkeys_Descr[] =
  367. {
  368. { &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle },
  369. { &schematicSectionTag, schematic_Hotkey_List, &schematicSectionTitle },
  370. { NULL, NULL, NULL }
  371. };
  372. // list of sections and corresponding hotkey list for the component editor
  373. // (used to list current hotkeys)
  374. struct EDA_HOTKEY_CONFIG g_Libedit_Hotkeys_Descr[] =
  375. {
  376. { &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle },
  377. { &libEditSectionTag, libEdit_Hotkey_List, &libEditSectionTitle },
  378. { NULL, NULL, NULL }
  379. };
  380. // list of sections and corresponding hotkey list for the component browser
  381. // (used to list current hotkeys)
  382. struct EDA_HOTKEY_CONFIG g_Viewlib_Hotkeys_Descr[] =
  383. {
  384. { &g_CommonSectionTag, common_basic_Hotkey_List, &commonSectionTitle },
  385. { NULL, NULL, NULL }
  386. };
  387. EDA_HOTKEY* SCH_EDIT_FRAME::GetHotKeyDescription( int aCommand ) const
  388. {
  389. EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, common_Hotkey_List );
  390. if( HK_Descr == NULL )
  391. HK_Descr = GetDescriptorFromCommand( aCommand, schematic_Hotkey_List );
  392. return HK_Descr;
  393. }
  394. /*
  395. * Hot keys. Commands are case insensitive.
  396. */
  397. bool SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem )
  398. {
  399. if( aHotKey == 0 )
  400. return false;
  401. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  402. EE_SELECTION_TOOL* selTool = GetToolManager()->GetTool<EE_SELECTION_TOOL>();
  403. SELECTION& selection = selTool->GetSelection();
  404. /* Convert lower to upper case (the usual toupper function has problem
  405. * with non ascii codes like function keys */
  406. if( (aHotKey >= 'a') && (aHotKey <= 'z') )
  407. aHotKey += 'A' - 'a';
  408. // Search command from key :
  409. EDA_HOTKEY* hotKey = GetDescriptorFromHotkey( aHotKey, common_Hotkey_List );
  410. if( hotKey == NULL )
  411. hotKey = GetDescriptorFromHotkey( aHotKey, schematic_Hotkey_List );
  412. if( hotKey == NULL )
  413. return false;
  414. switch( hotKey->m_Idcommand )
  415. {
  416. default:
  417. case HK_NOT_FOUND:
  418. return false;
  419. case HK_HELP: // Display Current hotkey list
  420. DisplayHotkeyList( this, g_Schematic_Hotkeys_Descr );
  421. break;
  422. case HK_PREFERENCES:
  423. cmd.SetId( wxID_PREFERENCES );
  424. GetEventHandler()->ProcessEvent( cmd );
  425. break;
  426. case HK_RESET_LOCAL_COORD: // Reset the relative coord
  427. GetScreen()->m_O_Curseur = GetCrossHairPosition();
  428. break;
  429. case HK_UNDO: // Hot keys that map to command IDs that cannot be called
  430. case HK_REDO: // while busy performing another command.
  431. case HK_FIND_ITEM:
  432. case HK_FIND_REPLACE:
  433. if( EE_CONDITIONS::Idle( selection ) )
  434. {
  435. cmd.SetId( hotKey->m_IdMenuEvent );
  436. GetEventHandler()->ProcessEvent( cmd );
  437. }
  438. break;
  439. case HK_FIND_NEXT_ITEM:
  440. case HK_FIND_NEXT_DRC_MARKER:
  441. if( EE_CONDITIONS::Idle( selection ) )
  442. {
  443. wxFindDialogEvent event( hotKey->m_IdMenuEvent, GetId() );
  444. event.SetEventObject( this );
  445. event.SetFlags( m_findReplaceData->GetFlags() );
  446. event.SetFindString( m_findReplaceData->GetFindString() );
  447. GetEventHandler()->ProcessEvent( event );
  448. }
  449. break;
  450. case HK_CANVAS_CAIRO:
  451. case HK_CANVAS_OPENGL:
  452. {
  453. EDA_HOTKEY_CLIENT_DATA data( aPosition );
  454. cmd.SetInt( hotKey->m_Idcommand );
  455. cmd.SetClientObject( &data );
  456. cmd.SetId( hotKey->m_IdMenuEvent );
  457. GetEventHandler()->ProcessEvent( cmd );
  458. }
  459. break;
  460. }
  461. // Hot key handled.
  462. return true;
  463. }
  464. EDA_HOTKEY* LIB_EDIT_FRAME::GetHotKeyDescription( int aCommand ) const
  465. {
  466. EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, common_Hotkey_List );
  467. if( HK_Descr == NULL )
  468. HK_Descr = GetDescriptorFromCommand( aCommand, libEdit_Hotkey_List );
  469. return HK_Descr;
  470. }
  471. bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem )
  472. {
  473. if( aHotKey == 0 )
  474. return false;
  475. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  476. EE_SELECTION_TOOL* selTool = GetToolManager()->GetTool<EE_SELECTION_TOOL>();
  477. SELECTION& selection = selTool->GetSelection();
  478. cmd.SetEventObject( this );
  479. /* Convert lower to upper case (the usual toupper function has problem
  480. * with non ascii codes like function keys */
  481. if( (aHotKey >= 'a') && (aHotKey <= 'z') )
  482. aHotKey += 'A' - 'a';
  483. EDA_HOTKEY* hotKey = GetDescriptorFromHotkey( aHotKey, common_Hotkey_List );
  484. if( hotKey == NULL )
  485. hotKey = GetDescriptorFromHotkey( aHotKey, libEdit_Hotkey_List );
  486. if( hotKey == NULL )
  487. return false;
  488. switch( hotKey->m_Idcommand )
  489. {
  490. default:
  491. case HK_NOT_FOUND:
  492. return false;
  493. case HK_HELP: // Display Current hotkey list
  494. DisplayHotkeyList( this, g_Libedit_Hotkeys_Descr );
  495. break;
  496. case HK_PREFERENCES:
  497. cmd.SetId( wxID_PREFERENCES );
  498. GetEventHandler()->ProcessEvent( cmd );
  499. break;
  500. case HK_RESET_LOCAL_COORD: // Reset the relative coord
  501. GetScreen()->m_O_Curseur = GetCrossHairPosition();
  502. break;
  503. case HK_EDIT_PASTE:
  504. case HK_EDIT_COPY:
  505. case HK_EDIT_CUT:
  506. cmd.SetId( hotKey->m_IdMenuEvent );
  507. GetEventHandler()->ProcessEvent( cmd );
  508. break;
  509. case HK_UNDO:
  510. case HK_REDO:
  511. if( EE_CONDITIONS::Idle( selection ) )
  512. {
  513. cmd.SetId( hotKey->m_IdMenuEvent );
  514. GetEventHandler()->ProcessEvent( cmd );
  515. }
  516. break;
  517. }
  518. // Hot key handled.
  519. return true;
  520. }
  521. EDA_HOTKEY* LIB_VIEW_FRAME::GetHotKeyDescription( int aCommand ) const
  522. {
  523. EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, common_Hotkey_List );
  524. if( HK_Descr == NULL )
  525. HK_Descr = GetDescriptorFromCommand( aCommand, viewlib_Hotkey_List );
  526. return HK_Descr;
  527. }
  528. bool LIB_VIEW_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem )
  529. {
  530. if( aHotKey == 0 )
  531. return false;
  532. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  533. cmd.SetEventObject( this );
  534. /* Convert lower to upper case (the usual toupper function has problem with non ascii
  535. * codes like function keys */
  536. if( (aHotKey >= 'a') && (aHotKey <= 'z') )
  537. aHotKey += 'A' - 'a';
  538. EDA_HOTKEY* HK_Descr = GetDescriptorFromHotkey( aHotKey, common_basic_Hotkey_List );
  539. if( HK_Descr == NULL )
  540. HK_Descr = GetDescriptorFromHotkey( aHotKey, viewlib_Hotkey_List );
  541. if( HK_Descr == NULL )
  542. return false;
  543. switch( HK_Descr->m_Idcommand )
  544. {
  545. default:
  546. case HK_NOT_FOUND:
  547. return false;
  548. case HK_HELP: // Display Current hotkey list
  549. DisplayHotkeyList( this, g_Viewlib_Hotkeys_Descr );
  550. break;
  551. case HK_RESET_LOCAL_COORD: // set local (relative) coordinate origin
  552. GetScreen()->m_O_Curseur = GetCrossHairPosition();
  553. break;
  554. case HK_ZOOM_IN:
  555. cmd.SetId( ID_KEY_ZOOM_IN );
  556. GetEventHandler()->ProcessEvent( cmd );
  557. break;
  558. case HK_ZOOM_OUT:
  559. cmd.SetId( ID_KEY_ZOOM_OUT );
  560. GetEventHandler()->ProcessEvent( cmd );
  561. break;
  562. case HK_ZOOM_REDRAW:
  563. cmd.SetId( ID_ZOOM_REDRAW );
  564. GetEventHandler()->ProcessEvent( cmd );
  565. break;
  566. case HK_ZOOM_CENTER:
  567. cmd.SetId( ID_POPUP_ZOOM_CENTER );
  568. GetEventHandler()->ProcessEvent( cmd );
  569. break;
  570. case HK_ZOOM_AUTO:
  571. cmd.SetId( ID_ZOOM_PAGE );
  572. GetEventHandler()->ProcessEvent( cmd );
  573. break;
  574. case HK_CANVAS_CAIRO:
  575. case HK_CANVAS_OPENGL:
  576. cmd.SetInt( HK_Descr->m_Idcommand );
  577. cmd.SetId( HK_Descr->m_IdMenuEvent );
  578. GetEventHandler()->ProcessEvent( cmd );
  579. }
  580. return true;
  581. }