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.

900 lines
31 KiB

11 years ago
11 years ago
11 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 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-2011 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 2004-2016 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. /**
  26. * @file eeschema/hotkeys.cpp
  27. */
  28. #include <fctsys.h>
  29. #include <eeschema_id.h>
  30. #include <hotkeys.h>
  31. #include <schframe.h>
  32. #include <class_drawpanel.h>
  33. #include <general.h>
  34. #include <libeditframe.h>
  35. #include <viewlib_frame.h>
  36. #include <class_libentry.h>
  37. #include <sch_junction.h>
  38. #include <sch_line.h>
  39. #include <sch_component.h>
  40. #include <sch_sheet.h>
  41. #include <dialogs/dialog_schematic_find.h>
  42. // Remark: the hotkey message info is used as keyword in hotkey config files and
  43. // as comments in help windows, therefore translated only when displayed
  44. // they are marked _HKI to be extracted by translation tools
  45. // See hotkeys_basic.h for more info
  46. /* How to add a new hotkey:
  47. * add a new id in the enum hotkey_id_command like MY_NEW_ID_FUNCTION (see
  48. * hotkeys.h).
  49. * add a new EDA_HOTKEY entry like:
  50. * static EDA_HOTKEY HkMyNewEntry(_HKI("Command Label"), MY_NEW_ID_FUNCTION,
  51. * default key value);
  52. * _HKI("Command Label") is the name used in hotkey list display, and the
  53. * identifier in the hotkey list file
  54. * MY_NEW_ID_FUNCTION is an equivalent id function used in the switch in
  55. * OnHotKey() function.
  56. * default key value is the default hotkey for this command. Can be overridden
  57. * by the user hotkey list file
  58. * add the HkMyNewEntry pointer in the schematic_Hotkey_List list or the
  59. * libEdit_Hotkey_List list or common_Hotkey_List if the same command is
  60. * added both in Eeschema and libedit)
  61. * Add the new code in the switch in OnHotKey() function.
  62. * when the variable itemInEdit is true, an item is currently edited.
  63. * This can be useful if the new function cannot be executed while an item is
  64. * currently being edited
  65. * ( For example, one cannot start a new wire when a component is moving.)
  66. *
  67. * Note: If an hotkey is a special key be sure the corresponding wxWidget
  68. * keycode (WXK_XXXX) is handled in the hotkey_name_descr
  69. * s_Hotkey_Name_List list (see hotkeys_basic.cpp) and see this list
  70. * for some ascii keys (space ...)
  71. *
  72. * Key modifier are: GR_KB_CTRL GR_KB_ALT
  73. */
  74. // Common commands
  75. // Fit on Screen
  76. #if !defined( __WXMAC__ )
  77. static EDA_HOTKEY HkZoomAuto( _HKI( "Fit on Screen" ), HK_ZOOM_AUTO, WXK_HOME, ID_ZOOM_PAGE );
  78. #else
  79. static EDA_HOTKEY HkZoomAuto( _HKI( "Zoom Auto" ), HK_ZOOM_AUTO, GR_KB_CTRL + '0',
  80. ID_ZOOM_PAGE );
  81. #endif
  82. static EDA_HOTKEY HkZoomCenter( _HKI( "Zoom Center" ), HK_ZOOM_CENTER, WXK_F4,
  83. ID_POPUP_ZOOM_CENTER );
  84. // Refresh Screen
  85. #if !defined( __WXMAC__ )
  86. static EDA_HOTKEY HkZoomRedraw( _HKI( "Zoom Redraw" ), HK_ZOOM_REDRAW, WXK_F3, ID_ZOOM_REDRAW );
  87. #else
  88. static EDA_HOTKEY HkZoomRedraw( _HKI( "Zoom Redraw" ), HK_ZOOM_REDRAW, GR_KB_CTRL + 'R',
  89. ID_ZOOM_REDRAW );
  90. #endif
  91. // Zoom In
  92. #if !defined( __WXMAC__ )
  93. static EDA_HOTKEY HkZoomIn( _HKI( "Zoom In" ), HK_ZOOM_IN, WXK_F1, ID_POPUP_ZOOM_IN );
  94. #else
  95. static EDA_HOTKEY HkZoomIn( _HKI( "Zoom In" ), HK_ZOOM_IN, GR_KB_CTRL + '+', ID_POPUP_ZOOM_IN );
  96. #endif
  97. // Zoom Out
  98. #if !defined( __WXMAC__ )
  99. static EDA_HOTKEY HkZoomOut( _HKI( "Zoom Out" ), HK_ZOOM_OUT, WXK_F2, ID_POPUP_ZOOM_OUT );
  100. #else
  101. static EDA_HOTKEY HkZoomOut( _HKI( "Zoom Out" ), HK_ZOOM_OUT, GR_KB_CTRL + '-', ID_POPUP_ZOOM_OUT );
  102. #endif
  103. static EDA_HOTKEY HkHelp( _HKI( "Help (this window)" ), HK_HELP, '?' );
  104. static EDA_HOTKEY HkResetLocalCoord( _HKI( "Reset Local Coordinates" ), HK_RESET_LOCAL_COORD, ' ' );
  105. static EDA_HOTKEY HkLeaveSheet( _HKI( "Leave Sheet" ), HK_LEAVE_SHEET, GR_KB_ALT + WXK_BACK,
  106. ID_POPUP_SCH_LEAVE_SHEET );
  107. // Undo
  108. static EDA_HOTKEY HkUndo( _HKI( "Undo" ), HK_UNDO, GR_KB_CTRL + 'Z', (int) wxID_UNDO );
  109. // Redo
  110. #if !defined( __WXMAC__ )
  111. static EDA_HOTKEY HkRedo( _HKI( "Redo" ), HK_REDO, GR_KB_CTRL + 'Y', (int) wxID_REDO );
  112. #else
  113. static EDA_HOTKEY HkRedo( _HKI( "Redo" ), HK_REDO, GR_KB_SHIFT + GR_KB_CTRL + 'Z',
  114. (int) wxID_REDO );
  115. #endif
  116. // mouse click command:
  117. static EDA_HOTKEY HkMouseLeftClick( _HKI( "Mouse Left Click" ), HK_LEFT_CLICK, WXK_RETURN, 0 );
  118. static EDA_HOTKEY HkMouseLeftDClick( _HKI( "Mouse Left Double Click" ), HK_LEFT_DCLICK, WXK_END, 0 );
  119. // Schematic editor
  120. static EDA_HOTKEY HkBeginWire( _HKI( "Begin Wire" ), HK_BEGIN_WIRE, 'W', ID_WIRE_BUTT );
  121. static EDA_HOTKEY HkBeginBus( _HKI( "Begin Bus" ), HK_BEGIN_BUS, 'B', ID_BUS_BUTT );
  122. static EDA_HOTKEY HkEndLineWireBus( _HKI( "End Line Wire Bus" ), HK_END_CURR_LINEWIREBUS, 'K',
  123. ID_POPUP_END_LINE );
  124. static EDA_HOTKEY HkAddLabel( _HKI( "Add Label" ), HK_ADD_LABEL, 'L', ID_LABEL_BUTT );
  125. static EDA_HOTKEY HkAddHierarchicalLabel( _HKI( "Add Hierarchical Label" ), HK_ADD_HLABEL, 'H',
  126. ID_HIERLABEL_BUTT );
  127. static EDA_HOTKEY HkAddGlobalLabel( _HKI( "Add Global Label" ), HK_ADD_GLABEL, GR_KB_CTRL + 'H',
  128. ID_GLABEL_BUTT );
  129. static EDA_HOTKEY HkAddJunction( _HKI( "Add Junction" ), HK_ADD_JUNCTION, 'J', ID_JUNCTION_BUTT );
  130. static EDA_HOTKEY HkAddComponent( _HKI( "Add Component" ), HK_ADD_NEW_COMPONENT, 'A',
  131. ID_SCH_PLACE_COMPONENT );
  132. static EDA_HOTKEY HkAddPower( _HKI( "Add Power" ), HK_ADD_NEW_POWER, 'P',
  133. ID_PLACE_POWER_BUTT );
  134. static EDA_HOTKEY HkAddNoConn( _HKI( "Add No Connect Flag" ), HK_ADD_NOCONN_FLAG, 'Q',
  135. ID_NOCONN_BUTT );
  136. static EDA_HOTKEY HkAddHierSheet( _HKI( "Add Sheet" ), HK_ADD_HIER_SHEET, 'S',
  137. ID_SHEET_SYMBOL_BUTT );
  138. static EDA_HOTKEY HkAddBusEntry( _HKI( "Add Bus Entry" ), HK_ADD_BUS_ENTRY, '/',
  139. ID_BUSTOBUS_ENTRY_BUTT );
  140. static EDA_HOTKEY HkAddWireEntry( _HKI( "Add Wire Entry" ), HK_ADD_WIRE_ENTRY, 'Z',
  141. ID_WIRETOBUS_ENTRY_BUTT );
  142. static EDA_HOTKEY HkAddGraphicPolyLine( _HKI( "Add Graphic PolyLine" ), HK_ADD_GRAPHIC_POLYLINE,
  143. 'I', ID_LINE_COMMENT_BUTT );
  144. static EDA_HOTKEY HkAddGraphicText( _HKI( "Add Graphic Text" ), HK_ADD_GRAPHIC_TEXT, 'T',
  145. ID_TEXT_COMMENT_BUTT );
  146. static EDA_HOTKEY HkMirrorY( _HKI( "Mirror Y" ), HK_MIRROR_Y, 'Y',
  147. ID_SCH_MIRROR_Y );
  148. static EDA_HOTKEY HkMirrorX( _HKI( "Mirror X" ), HK_MIRROR_X, 'X',
  149. ID_SCH_MIRROR_X );
  150. static EDA_HOTKEY HkOrientNormalComponent( _HKI( "Orient Normal Component" ),
  151. HK_ORIENT_NORMAL_COMPONENT, 'N', ID_SCH_ORIENT_NORMAL );
  152. static EDA_HOTKEY HkRotate( _HKI( "Rotate Item" ), HK_ROTATE, 'R', ID_SCH_ROTATE_CLOCKWISE );
  153. static EDA_HOTKEY HkEdit( _HKI( "Edit Item" ), HK_EDIT, 'E', ID_SCH_EDIT_ITEM );
  154. static EDA_HOTKEY HkEditComponentValue( _HKI( "Edit Component Value" ),
  155. HK_EDIT_COMPONENT_VALUE, 'V',
  156. ID_SCH_EDIT_COMPONENT_VALUE );
  157. static EDA_HOTKEY HkEditComponentReference( _HKI( "Edit Component Reference" ),
  158. HK_EDIT_COMPONENT_REFERENCE, 'U',
  159. ID_SCH_EDIT_COMPONENT_REFERENCE );
  160. static EDA_HOTKEY HkEditComponentFootprint( _HKI( "Edit Component Footprint" ),
  161. HK_EDIT_COMPONENT_FOOTPRINT, 'F',
  162. ID_SCH_EDIT_COMPONENT_FOOTPRINT );
  163. static EDA_HOTKEY HkEditComponentWithLibedit( _HKI( "Edit with Component Editor" ),
  164. HK_EDIT_COMPONENT_WITH_LIBEDIT,
  165. 'E' + GR_KB_CTRL,
  166. ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP );
  167. static EDA_HOTKEY HkMove( _HKI( "Move Schematic Item" ),
  168. HK_MOVE_COMPONENT_OR_ITEM, 'M',
  169. ID_SCH_MOVE_ITEM );
  170. static EDA_HOTKEY HkCopyComponentOrText( _HKI( "Copy Component or Label" ),
  171. HK_COPY_COMPONENT_OR_LABEL, 'C',
  172. ID_POPUP_SCH_COPY_ITEM );
  173. static EDA_HOTKEY HkDrag( _HKI( "Drag Item" ), HK_DRAG, 'G', ID_SCH_DRAG_ITEM );
  174. static EDA_HOTKEY HkSaveBlock( _HKI( "Save Block" ), HK_SAVE_BLOCK, 'C' + GR_KB_CTRL, wxID_COPY );
  175. static EDA_HOTKEY HkMove2Drag( _HKI( "Move Block -> Drag Block" ),
  176. HK_MOVEBLOCK_TO_DRAGBLOCK, '\t', ID_POPUP_DRAG_BLOCK );
  177. static EDA_HOTKEY HkInsert( _HKI( "Repeat Last Item" ), HK_REPEAT_LAST, WXK_INSERT );
  178. static EDA_HOTKEY HkDelete( _HKI( "Delete Item" ), HK_DELETE, WXK_DELETE );
  179. static EDA_HOTKEY HkDeleteNode( _HKI( "Delete Node" ), HK_DELETE_NODE, WXK_BACK,
  180. ID_POPUP_SCH_DELETE_NODE );
  181. static EDA_HOTKEY HkFindItem( _HKI( "Find Item" ), HK_FIND_ITEM, 'F' + GR_KB_CTRL, ID_FIND_ITEMS );
  182. static EDA_HOTKEY HkFindNextItem( _HKI( "Find Next Item" ), HK_FIND_NEXT_ITEM, WXK_F5,
  183. wxEVT_COMMAND_FIND );
  184. static EDA_HOTKEY HkFindReplace( _HKI( "Find and Replace" ), HK_FIND_REPLACE,
  185. 'F' + GR_KB_CTRL + GR_KB_ALT, wxID_REPLACE );
  186. static EDA_HOTKEY HkFindNextDrcMarker( _HKI( "Find Next DRC Marker" ), HK_FIND_NEXT_DRC_MARKER,
  187. WXK_F5 + GR_KB_SHIFT, EVT_COMMAND_FIND_DRC_MARKER );
  188. static EDA_HOTKEY HkZoomSelection( _HKI( "Zoom to Selection" ), HK_ZOOM_SELECTION, '@', ID_ZOOM_SELECTION );
  189. // Special keys for library editor:
  190. static EDA_HOTKEY HkCreatePin( _HKI( "Create Pin" ), HK_LIBEDIT_CREATE_PIN, 'P' );
  191. static EDA_HOTKEY HkInsertPin( _HKI( "Repeat Pin" ), HK_REPEAT_LAST, WXK_INSERT );
  192. static EDA_HOTKEY HkMoveLibItem( _HKI( "Move Library Item" ), HK_LIBEDIT_MOVE_GRAPHIC_ITEM, 'M' );
  193. // Load/save files
  194. static EDA_HOTKEY HkSaveLib( _HKI( "Save Library" ), HK_SAVE_LIB, 'S' + GR_KB_CTRL );
  195. static EDA_HOTKEY HkSaveSchematic( _HKI( "Save Schematic" ), HK_SAVE_SCH, 'S' + GR_KB_CTRL );
  196. static EDA_HOTKEY HkLoadSchematic( _HKI( "Load Schematic" ), HK_LOAD_SCH, 'L' + GR_KB_CTRL );
  197. // Autoplace fields
  198. static EDA_HOTKEY HkAutoplaceFields( _HKI( "Autoplace Fields" ), HK_AUTOPLACE_FIELDS, 'O',
  199. ID_AUTOPLACE_FIELDS );
  200. static EDA_HOTKEY HkUpdatePcbFromSch( _HKI( "Update PCB from Schematics" ), HK_UPDATE_PCB_FROM_SCH, WXK_F8 );
  201. // Higtlight connection
  202. static EDA_HOTKEY HkHighlightConnection( _HKI( "Highlight Connection" ), ID_HOTKEY_HIGHLIGHT, 'X' + GR_KB_CTRL );
  203. // List of common hotkey descriptors
  204. static EDA_HOTKEY* common_Hotkey_List[] =
  205. {
  206. &HkHelp,
  207. &HkZoomIn,
  208. &HkZoomOut,
  209. &HkZoomRedraw,
  210. &HkZoomCenter,
  211. &HkZoomAuto,
  212. &HkZoomSelection,
  213. &HkResetLocalCoord,
  214. &HkEdit,
  215. &HkDelete,
  216. &HkRotate,
  217. &HkDrag,
  218. &HkUndo,
  219. &HkRedo,
  220. &HkMouseLeftClick,
  221. &HkMouseLeftDClick,
  222. NULL
  223. };
  224. // List of common hotkey descriptors, for the library vierwer
  225. static EDA_HOTKEY* common_basic_Hotkey_List[] =
  226. {
  227. &HkHelp,
  228. &HkZoomIn,
  229. &HkZoomOut,
  230. &HkZoomRedraw,
  231. &HkZoomCenter,
  232. &HkZoomAuto,
  233. &HkResetLocalCoord,
  234. &HkMouseLeftClick,
  235. &HkMouseLeftDClick,
  236. NULL
  237. };
  238. // List of hotkey descriptors for schematic
  239. static EDA_HOTKEY* schematic_Hotkey_List[] =
  240. {
  241. &HkSaveSchematic,
  242. &HkLoadSchematic,
  243. &HkFindItem,
  244. &HkFindNextItem,
  245. &HkFindNextDrcMarker,
  246. &HkFindReplace,
  247. &HkInsert,
  248. &HkMove2Drag,
  249. &HkSaveBlock,
  250. &HkMove,
  251. &HkCopyComponentOrText,
  252. &HkAddComponent,
  253. &HkAddPower,
  254. &HkMirrorX,
  255. &HkMirrorY,
  256. &HkOrientNormalComponent,
  257. &HkEditComponentValue,
  258. &HkEditComponentReference,
  259. &HkEditComponentFootprint,
  260. &HkEditComponentWithLibedit,
  261. &HkBeginWire,
  262. &HkBeginBus,
  263. &HkEndLineWireBus,
  264. &HkAddLabel,
  265. &HkAddHierarchicalLabel,
  266. &HkAddGlobalLabel,
  267. &HkAddJunction,
  268. &HkAddNoConn,
  269. &HkAddHierSheet,
  270. &HkAddWireEntry,
  271. &HkAddBusEntry,
  272. &HkAddGraphicPolyLine,
  273. &HkAddGraphicText,
  274. &HkUpdatePcbFromSch,
  275. &HkAutoplaceFields,
  276. &HkLeaveSheet,
  277. &HkDeleteNode,
  278. &HkHighlightConnection,
  279. NULL
  280. };
  281. // List of hotkey descriptors for library editor
  282. static EDA_HOTKEY* libEdit_Hotkey_List[] =
  283. {
  284. &HkSaveLib,
  285. &HkCreatePin,
  286. &HkInsertPin,
  287. &HkMoveLibItem,
  288. &HkMirrorX,
  289. &HkMirrorY,
  290. NULL
  291. };
  292. // List of hotkey descriptors for library viewer (currently empty
  293. static EDA_HOTKEY* viewlib_Hotkey_List[] =
  294. {
  295. NULL
  296. };
  297. // Keyword Identifiers (tags) in key code configuration file (section names)
  298. // (.m_SectionTag member of a EDA_HOTKEY_CONFIG)
  299. static wxString schematicSectionTag( wxT( "[eeschema]" ) );
  300. static wxString libEditSectionTag( wxT( "[libedit]" ) );
  301. // Titles for hotkey editor and hotkey display
  302. static wxString commonSectionTitle( _HKI( "Common" ) );
  303. static wxString schematicSectionTitle( _HKI( "Schematic Editor" ) );
  304. static wxString libEditSectionTitle( _HKI( "Library Editor" ) );
  305. // list of sections and corresponding hotkey list for Eeschema (used to create
  306. // an hotkey config file)
  307. struct EDA_HOTKEY_CONFIG g_Eeschema_Hokeys_Descr[] =
  308. {
  309. { &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle },
  310. { &schematicSectionTag, schematic_Hotkey_List, &schematicSectionTitle },
  311. { &libEditSectionTag, libEdit_Hotkey_List, &libEditSectionTitle },
  312. { NULL, NULL, NULL }
  313. };
  314. // list of sections and corresponding hotkey list for the schematic editor
  315. // (used to list current hotkeys)
  316. struct EDA_HOTKEY_CONFIG g_Schematic_Hokeys_Descr[] =
  317. {
  318. { &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle },
  319. { &schematicSectionTag, schematic_Hotkey_List, &schematicSectionTitle },
  320. { NULL, NULL, NULL }
  321. };
  322. // list of sections and corresponding hotkey list for the component editor
  323. // (used to list current hotkeys)
  324. struct EDA_HOTKEY_CONFIG g_Libedit_Hokeys_Descr[] =
  325. {
  326. { &g_CommonSectionTag, common_Hotkey_List, &commonSectionTitle },
  327. { &libEditSectionTag, libEdit_Hotkey_List, &libEditSectionTitle },
  328. { NULL, NULL, NULL }
  329. };
  330. // list of sections and corresponding hotkey list for the component browser
  331. // (used to list current hotkeys)
  332. struct EDA_HOTKEY_CONFIG g_Viewlib_Hokeys_Descr[] =
  333. {
  334. { &g_CommonSectionTag, common_basic_Hotkey_List, &commonSectionTitle },
  335. { NULL, NULL, NULL }
  336. };
  337. EDA_HOTKEY* SCH_EDIT_FRAME::GetHotKeyDescription( int aCommand ) const
  338. {
  339. EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, common_Hotkey_List );
  340. if( HK_Descr == NULL )
  341. HK_Descr = GetDescriptorFromCommand( aCommand, schematic_Hotkey_List );
  342. return HK_Descr;
  343. }
  344. /*
  345. * Hot keys. Some commands are relative to the item under the mouse cursor
  346. * Commands are case insensitive
  347. */
  348. bool SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem )
  349. {
  350. if( aHotKey == 0 )
  351. return false;
  352. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  353. SCH_SCREEN* screen = GetScreen();
  354. // itemInEdit == false means no item currently edited. We can ask for editing a new item
  355. bool itemInEdit = screen->GetCurItem() && screen->GetCurItem()->GetFlags();
  356. // blocInProgress == false means no block in progress.
  357. // Because a drag command uses a drag block, false means also no drag in progress
  358. // If false, we can ask for editing a new item
  359. bool blocInProgress = screen->m_BlockLocate.GetState() != STATE_NO_BLOCK;
  360. // notBusy == true means no item currently edited and no other command in progress
  361. // We can change active tool and ask for editing a new item
  362. bool notBusy = (!itemInEdit) && (!blocInProgress);
  363. /* Convert lower to upper case (the usual toupper function has problem
  364. * with non ascii codes like function keys */
  365. if( (aHotKey >= 'a') && (aHotKey <= 'z') )
  366. aHotKey += 'A' - 'a';
  367. // Search command from key :
  368. EDA_HOTKEY* hotKey = GetDescriptorFromHotkey( aHotKey, common_Hotkey_List );
  369. if( hotKey == NULL )
  370. hotKey = GetDescriptorFromHotkey( aHotKey, schematic_Hotkey_List );
  371. if( hotKey == NULL )
  372. return false;
  373. switch( hotKey->m_Idcommand )
  374. {
  375. default:
  376. case HK_NOT_FOUND:
  377. return false;
  378. case HK_HELP: // Display Current hotkey list
  379. DisplayHotkeyList( this, g_Schematic_Hokeys_Descr );
  380. break;
  381. case HK_RESET_LOCAL_COORD: // Reset the relative coord
  382. GetScreen()->m_O_Curseur = GetCrossHairPosition();
  383. break;
  384. case ID_HOTKEY_HIGHLIGHT:
  385. if( notBusy )
  386. HighlightConnectionAtPosition( GetCrossHairPosition() );
  387. break;
  388. case HK_LEFT_CLICK:
  389. case HK_LEFT_DCLICK: // Simulate a double left click: generate 2 events
  390. if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE )
  391. {
  392. GetCanvas()->SetAutoPanRequest( false );
  393. HandleBlockPlace( aDC );
  394. }
  395. else if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK )
  396. {
  397. OnLeftClick( aDC, aPosition );
  398. if( hotKey->m_Idcommand == HK_LEFT_DCLICK )
  399. OnLeftDClick( aDC, aPosition );
  400. }
  401. break;
  402. case HK_ZOOM_IN:
  403. case HK_ZOOM_OUT:
  404. case HK_ZOOM_REDRAW:
  405. case HK_ZOOM_CENTER:
  406. case HK_ZOOM_AUTO:
  407. case HK_ZOOM_SELECTION:
  408. case HK_MOVEBLOCK_TO_DRAGBLOCK: // Switch to drag mode, when block moving
  409. case HK_SAVE_BLOCK: // Copy block to paste buffer.
  410. cmd.SetId( hotKey->m_IdMenuEvent );
  411. GetEventHandler()->ProcessEvent( cmd );
  412. break;
  413. case HK_DELETE:
  414. if( notBusy )
  415. DeleteItemAtCrossHair( aDC );
  416. break;
  417. case HK_REPEAT_LAST:
  418. if( notBusy )
  419. RepeatDrawItem( aDC );
  420. break;
  421. case HK_END_CURR_LINEWIREBUS:
  422. // this key terminates a new line/bus/wire in progress
  423. if( aItem && aItem->IsNew() &&
  424. aItem->Type() == SCH_LINE_T )
  425. {
  426. cmd.SetId( hotKey->m_IdMenuEvent );
  427. GetEventHandler()->ProcessEvent( cmd );
  428. }
  429. break;
  430. case HK_UNDO: // Hot keys that map to command IDs that cannot be called
  431. case HK_REDO: // while busy performing another command.
  432. case HK_FIND_ITEM:
  433. case HK_FIND_REPLACE:
  434. case HK_DELETE_NODE:
  435. case HK_LEAVE_SHEET:
  436. if( notBusy )
  437. {
  438. cmd.SetId( hotKey->m_IdMenuEvent );
  439. GetEventHandler()->ProcessEvent( cmd );
  440. }
  441. break;
  442. case HK_FIND_NEXT_ITEM:
  443. case HK_FIND_NEXT_DRC_MARKER:
  444. if( notBusy )
  445. {
  446. wxFindDialogEvent event( hotKey->m_IdMenuEvent, GetId() );
  447. event.SetEventObject( this );
  448. event.SetFlags( m_findReplaceData->GetFlags() );
  449. event.SetFindString( m_findReplaceData->GetFindString() );
  450. GetEventHandler()->ProcessEvent( event );
  451. }
  452. break;
  453. case HK_ADD_NEW_COMPONENT: // Add component
  454. case HK_ADD_NEW_POWER: // Add power component
  455. case HK_ADD_LABEL:
  456. case HK_ADD_HLABEL:
  457. case HK_ADD_GLABEL:
  458. case HK_ADD_JUNCTION:
  459. case HK_ADD_WIRE_ENTRY:
  460. case HK_ADD_BUS_ENTRY:
  461. case HK_ADD_HIER_SHEET:
  462. case HK_ADD_GRAPHIC_TEXT:
  463. case HK_ADD_GRAPHIC_POLYLINE:
  464. case HK_ADD_NOCONN_FLAG: // Add a no connected flag
  465. case HK_BEGIN_BUS:
  466. case HK_BEGIN_WIRE:
  467. if( notBusy )
  468. {
  469. EDA_HOTKEY_CLIENT_DATA data( aPosition );
  470. cmd.SetInt( aHotKey );
  471. cmd.SetClientObject( &data );
  472. cmd.SetId( hotKey->m_IdMenuEvent );
  473. GetEventHandler()->ProcessEvent( cmd );
  474. }
  475. else if( aItem && aItem->IsNew() )
  476. {
  477. // If the item is a bus or a wire, a begin command is not possible.
  478. if( (GetToolId() == ID_BUS_BUTT) && (aItem->Type() == SCH_LINE_T) )
  479. {
  480. SCH_LINE* segment = (SCH_LINE*) aItem;
  481. if( segment->GetLayer() != LAYER_BUS )
  482. break;
  483. // Bus in progress:
  484. OnLeftClick( aDC, aPosition );
  485. }
  486. else if( (GetToolId() == ID_WIRE_BUTT ) && (aItem->Type() == SCH_LINE_T) )
  487. {
  488. SCH_LINE* segment = (SCH_LINE*) aItem;
  489. if( segment->GetLayer() != LAYER_WIRE )
  490. break;
  491. // Wire in progress:
  492. OnLeftClick( aDC, aPosition );
  493. }
  494. }
  495. break;
  496. case HK_COPY_COMPONENT_OR_LABEL: // Duplicate component or text/label
  497. if( itemInEdit )
  498. break;
  499. if( aItem == NULL )
  500. {
  501. aItem = LocateAndShowItem( aPosition, SCH_COLLECTOR::MovableItems );
  502. if( aItem == NULL )
  503. break;
  504. }
  505. cmd.SetId( hotKey->m_IdMenuEvent );
  506. wxPostEvent( this, cmd );
  507. break;
  508. case HK_DRAG: // Start drag
  509. case HK_MOVE_COMPONENT_OR_ITEM: // Start move schematic item.
  510. if( ! notBusy )
  511. break;
  512. // Fall through
  513. case HK_EDIT:
  514. // Edit schematic item. Do not allow sheet edition when mowing
  515. // Because a sheet edition can be complex.
  516. if( itemInEdit && screen->GetCurItem()->Type() == SCH_SHEET_T )
  517. break;
  518. // Fall through
  519. case HK_EDIT_COMPONENT_VALUE: // Edit component value field.
  520. case HK_EDIT_COMPONENT_REFERENCE: // Edit component value reference.
  521. case HK_EDIT_COMPONENT_FOOTPRINT: // Edit component footprint field.
  522. case HK_MIRROR_Y: // Mirror Y
  523. case HK_MIRROR_X: // Mirror X
  524. case HK_ORIENT_NORMAL_COMPONENT: // Orient 0, no mirror (Component)
  525. case HK_ROTATE: // Rotate schematic item.
  526. case HK_EDIT_COMPONENT_WITH_LIBEDIT: // Call Libedit and load the current component
  527. case HK_AUTOPLACE_FIELDS: // Autoplace all fields around component
  528. {
  529. // force a new item search on hot keys at current position,
  530. // if there is no currently edited item,
  531. // to avoid using a previously selected item
  532. if( ! itemInEdit )
  533. screen->SetCurItem( NULL );
  534. EDA_HOTKEY_CLIENT_DATA data( aPosition );
  535. cmd.SetInt( hotKey->m_Idcommand );
  536. cmd.SetClientObject( &data );
  537. cmd.SetId( hotKey->m_IdMenuEvent );
  538. GetEventHandler()->ProcessEvent( cmd );
  539. }
  540. break;
  541. }
  542. // Hot key handled.
  543. return true;
  544. }
  545. EDA_HOTKEY* LIB_EDIT_FRAME::GetHotKeyDescription( int aCommand ) const
  546. {
  547. EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, common_Hotkey_List );
  548. if( HK_Descr == NULL )
  549. HK_Descr = GetDescriptorFromCommand( aCommand, libEdit_Hotkey_List );
  550. return HK_Descr;
  551. }
  552. bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem )
  553. {
  554. if( aHotKey == 0 )
  555. return false;
  556. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  557. cmd.SetEventObject( this );
  558. bool itemInEdit = m_drawItem && m_drawItem->InEditMode();
  559. /* Convert lower to upper case (the usual toupper function has problem
  560. * with non ascii codes like function keys */
  561. if( (aHotKey >= 'a') && (aHotKey <= 'z') )
  562. aHotKey += 'A' - 'a';
  563. EDA_HOTKEY* hotKey = GetDescriptorFromHotkey( aHotKey, common_Hotkey_List );
  564. if( hotKey == NULL )
  565. hotKey = GetDescriptorFromHotkey( aHotKey, libEdit_Hotkey_List );
  566. if( hotKey == NULL )
  567. return false;
  568. switch( hotKey->m_Idcommand )
  569. {
  570. default:
  571. case HK_NOT_FOUND:
  572. return false;
  573. case HK_HELP: // Display Current hotkey list
  574. DisplayHotkeyList( this, g_Libedit_Hokeys_Descr );
  575. break;
  576. case HK_RESET_LOCAL_COORD: // Reset the relative coord
  577. GetScreen()->m_O_Curseur = GetCrossHairPosition();
  578. break;
  579. case HK_LEFT_CLICK:
  580. OnLeftClick( aDC, aPosition );
  581. break;
  582. case HK_LEFT_DCLICK: // Simulate a double left click: generate 2 events
  583. OnLeftClick( aDC, aPosition );
  584. OnLeftDClick( aDC, aPosition );
  585. break;
  586. case HK_ZOOM_IN:
  587. case HK_ZOOM_OUT:
  588. case HK_ZOOM_REDRAW:
  589. case HK_ZOOM_CENTER:
  590. case HK_ZOOM_AUTO:
  591. cmd.SetId( hotKey->m_IdMenuEvent );
  592. GetEventHandler()->ProcessEvent( cmd );
  593. break;
  594. case HK_UNDO:
  595. case HK_REDO:
  596. if( !itemInEdit )
  597. {
  598. cmd.SetId( hotKey->m_IdMenuEvent );
  599. GetEventHandler()->ProcessEvent( cmd );
  600. }
  601. break;
  602. case HK_REPEAT_LAST:
  603. if( ! itemInEdit )
  604. {
  605. if( m_lastDrawItem && !m_lastDrawItem->InEditMode() &&
  606. ( m_lastDrawItem->Type() == LIB_PIN_T ) )
  607. RepeatPinItem( aDC, (LIB_PIN*) m_lastDrawItem );
  608. }
  609. break;
  610. case HK_EDIT:
  611. if( ! itemInEdit )
  612. m_drawItem = LocateItemUsingCursor( aPosition );
  613. if( m_drawItem )
  614. {
  615. switch( m_drawItem->Type() )
  616. {
  617. case LIB_PIN_T:
  618. cmd.SetId( ID_LIBEDIT_EDIT_PIN );
  619. GetEventHandler()->ProcessEvent( cmd );
  620. break;
  621. case LIB_ARC_T:
  622. case LIB_CIRCLE_T:
  623. case LIB_RECTANGLE_T:
  624. case LIB_POLYLINE_T:
  625. case LIB_TEXT_T:
  626. cmd.SetId( ID_POPUP_LIBEDIT_BODY_EDIT_ITEM );
  627. GetEventHandler()->ProcessEvent( cmd );
  628. break;
  629. case LIB_FIELD_T:
  630. cmd.SetId( ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM );
  631. GetEventHandler()->ProcessEvent( cmd );
  632. break;
  633. default:
  634. break;
  635. }
  636. }
  637. break;
  638. case HK_ROTATE:
  639. if( ! itemInEdit )
  640. m_drawItem = LocateItemUsingCursor( aPosition );
  641. if( m_drawItem )
  642. {
  643. cmd.SetId( ID_LIBEDIT_ROTATE_ITEM );
  644. GetEventHandler()->ProcessEvent( cmd );
  645. }
  646. break;
  647. case HK_LIBEDIT_CREATE_PIN:
  648. if( ! itemInEdit )
  649. {
  650. SetToolID( ID_LIBEDIT_PIN_BUTT, wxCURSOR_PENCIL, _( "Add Pin" ) );
  651. OnLeftClick( aDC, aPosition );
  652. }
  653. break;
  654. case HK_DELETE:
  655. if( !itemInEdit )
  656. m_drawItem = LocateItemUsingCursor( aPosition );
  657. if( m_drawItem && !m_drawItem->InEditMode() )
  658. {
  659. cmd.SetId( ID_POPUP_LIBEDIT_DELETE_ITEM );
  660. Process_Special_Functions( cmd );
  661. }
  662. break;
  663. case HK_LIBEDIT_MOVE_GRAPHIC_ITEM:
  664. if( !itemInEdit )
  665. {
  666. m_drawItem = LocateItemUsingCursor( aPosition );
  667. if( m_drawItem )
  668. {
  669. cmd.SetId( ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST );
  670. Process_Special_Functions( cmd );
  671. }
  672. }
  673. break;
  674. case HK_DRAG:
  675. if( !itemInEdit )
  676. {
  677. m_drawItem = LocateItemUsingCursor( aPosition );
  678. if( m_drawItem && !m_drawItem->InEditMode() )
  679. {
  680. cmd.SetId( ID_POPUP_LIBEDIT_MODIFY_ITEM );
  681. Process_Special_Functions( cmd );
  682. }
  683. }
  684. break;
  685. case HK_MIRROR_Y: // Mirror Y
  686. m_drawItem = LocateItemUsingCursor( aPosition );
  687. cmd.SetId( ID_LIBEDIT_MIRROR_Y );
  688. GetEventHandler()->ProcessEvent( cmd );
  689. break;
  690. case HK_MIRROR_X: // Mirror X
  691. m_drawItem = LocateItemUsingCursor( aPosition );
  692. cmd.SetId( ID_LIBEDIT_MIRROR_X );
  693. GetEventHandler()->ProcessEvent( cmd );
  694. break;
  695. }
  696. // Hot key handled.
  697. return true;
  698. }
  699. EDA_HOTKEY* LIB_VIEW_FRAME::GetHotKeyDescription( int aCommand ) const
  700. {
  701. EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, common_Hotkey_List );
  702. if( HK_Descr == NULL )
  703. HK_Descr = GetDescriptorFromCommand( aCommand, viewlib_Hotkey_List );
  704. return HK_Descr;
  705. }
  706. bool LIB_VIEW_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
  707. EDA_ITEM* aItem )
  708. {
  709. if( aHotKey == 0 )
  710. return false;
  711. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  712. cmd.SetEventObject( this );
  713. /* Convert lower to upper case (the usual toupper function has problem with non ascii
  714. * codes like function keys */
  715. if( (aHotKey >= 'a') && (aHotKey <= 'z') )
  716. aHotKey += 'A' - 'a';
  717. EDA_HOTKEY* HK_Descr = GetDescriptorFromHotkey( aHotKey, common_basic_Hotkey_List );
  718. if( HK_Descr == NULL )
  719. HK_Descr = GetDescriptorFromHotkey( aHotKey, viewlib_Hotkey_List );
  720. if( HK_Descr == NULL )
  721. return false;
  722. switch( HK_Descr->m_Idcommand )
  723. {
  724. default:
  725. case HK_NOT_FOUND:
  726. return false;
  727. case HK_HELP: // Display Current hotkey list
  728. DisplayHotkeyList( this, g_Viewlib_Hokeys_Descr );
  729. break;
  730. case HK_RESET_LOCAL_COORD: // set local (relative) coordinate origin
  731. GetScreen()->m_O_Curseur = GetCrossHairPosition();
  732. break;
  733. case HK_LEFT_CLICK:
  734. OnLeftClick( aDC, aPosition );
  735. break;
  736. case HK_LEFT_DCLICK: // Simulate a double left click: generate 2 events
  737. OnLeftClick( aDC, aPosition );
  738. OnLeftDClick( aDC, aPosition );
  739. break;
  740. case HK_ZOOM_IN:
  741. cmd.SetId( ID_POPUP_ZOOM_IN );
  742. GetEventHandler()->ProcessEvent( cmd );
  743. break;
  744. case HK_ZOOM_OUT:
  745. cmd.SetId( ID_POPUP_ZOOM_OUT );
  746. GetEventHandler()->ProcessEvent( cmd );
  747. break;
  748. case HK_ZOOM_REDRAW:
  749. cmd.SetId( ID_ZOOM_REDRAW );
  750. GetEventHandler()->ProcessEvent( cmd );
  751. break;
  752. case HK_ZOOM_CENTER:
  753. cmd.SetId( ID_POPUP_ZOOM_CENTER );
  754. GetEventHandler()->ProcessEvent( cmd );
  755. break;
  756. case HK_ZOOM_AUTO:
  757. cmd.SetId( ID_ZOOM_PAGE );
  758. GetEventHandler()->ProcessEvent( cmd );
  759. break;
  760. }
  761. return true;
  762. }