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.

547 lines
19 KiB

18 years ago
16 years ago
15 years ago
15 years ago
15 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2007 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2009-2011 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2011 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/menubar.cpp
  27. * @brief (Re)Create the main menubar for the schematic frame
  28. */
  29. #ifdef __GNUG__
  30. #pragma implementation
  31. #endif
  32. #include <fctsys.h>
  33. #include <appl_wxstruct.h>
  34. #include <wxEeschemaStruct.h>
  35. #include <general.h>
  36. //#include <protos.h>
  37. #include <eeschema_id.h>
  38. #include <hotkeys.h>
  39. #include <menus_helpers.h>
  40. #include <help_common_strings.h>
  41. /**
  42. * @brief (Re)Create the menubar for the schematic frame
  43. */
  44. void SCH_EDIT_FRAME::ReCreateMenuBar()
  45. {
  46. // Create and try to get the current menubar
  47. wxString text;
  48. wxMenuBar* menuBar = GetMenuBar();
  49. if( !menuBar )
  50. menuBar = new wxMenuBar();
  51. // Delete all existing menus so they can be rebuilt.
  52. // This allows language changes of the menu text on the fly.
  53. menuBar->Freeze();
  54. while( menuBar->GetMenuCount() )
  55. delete menuBar->Remove( 0 );
  56. // Recreate all menus:
  57. // Menu File:
  58. wxMenu* fileMenu = new wxMenu;
  59. // New
  60. AddMenuItem( fileMenu,
  61. ID_NEW_PROJECT,
  62. _( "&New" ),
  63. _( "New schematic project" ),
  64. KiBitmap( new_xpm ) );
  65. // Open
  66. text = AddHotkeyName( _( "&Open" ), s_Schematic_Hokeys_Descr, HK_LOAD_SCH );
  67. AddMenuItem( fileMenu,
  68. ID_LOAD_PROJECT, text,
  69. _( "Open an existing schematic project" ),
  70. KiBitmap( open_document_xpm ) );
  71. // Open Recent submenu
  72. static wxMenu* openRecentMenu;
  73. // Add this menu to list menu managed by m_fileHistory
  74. // (the file history will be updated when adding/removing files in history
  75. if( openRecentMenu )
  76. wxGetApp().GetFileHistory().RemoveMenu( openRecentMenu );
  77. openRecentMenu = new wxMenu();
  78. wxGetApp().GetFileHistory().UseMenu( openRecentMenu );
  79. wxGetApp().GetFileHistory().AddFilesToMenu( openRecentMenu );
  80. AddMenuItem( fileMenu, openRecentMenu,
  81. wxID_ANY, _( "Open &Recent" ),
  82. _( "Open a recent opened schematic project" ),
  83. KiBitmap( open_project_xpm ) );
  84. // Separator
  85. fileMenu->AppendSeparator();
  86. // Save schematic project
  87. text = AddHotkeyName( _( "&Save Whole Schematic Project" ),
  88. s_Schematic_Hokeys_Descr, HK_SAVE_SCH );
  89. AddMenuItem( fileMenu,
  90. ID_SAVE_PROJECT, text,
  91. _( "Save all sheets in the schematic project" ),
  92. KiBitmap( save_project_xpm ) );
  93. // Save current sheet
  94. AddMenuItem( fileMenu,
  95. ID_UPDATE_ONE_SHEET,
  96. _( "Save &Current Sheet Only" ),
  97. _( "Save only current schematic sheet" ),
  98. KiBitmap( save_xpm ) );
  99. // Save current sheet as
  100. AddMenuItem( fileMenu,
  101. ID_SAVE_ONE_SHEET_UNDER_NEW_NAME,
  102. _( "Save Current Sheet &As" ),
  103. _( "Save current schematic sheet as..." ),
  104. KiBitmap( save_as_xpm ) );
  105. // Separator
  106. fileMenu->AppendSeparator();
  107. // Page settings
  108. AddMenuItem( fileMenu,
  109. ID_SHEET_SET,
  110. _( "Pa&ge Settings" ),
  111. _( "Settigns for page size and information" ),
  112. KiBitmap( sheetset_xpm ) );
  113. // Print
  114. AddMenuItem( fileMenu,
  115. wxID_PRINT,
  116. _( "Pri&nt" ),
  117. _( "Print schematic" ),
  118. KiBitmap( print_button_xpm ) );
  119. // Plot submenu
  120. wxMenu* choice_plot_fmt = new wxMenu;
  121. AddMenuItem( choice_plot_fmt, ID_GEN_PLOT_SCHEMATIC,
  122. _( "&Plot" ),
  123. _( "Plot schematic sheet in PostScript, PDF, SVG, DXF or HPGL format" ),
  124. KiBitmap( plot_xpm ) );
  125. // Plot to Clipboard (Windows only)
  126. #ifdef __WINDOWS__
  127. AddMenuItem( choice_plot_fmt, ID_GEN_COPY_SHEET_TO_CLIPBOARD,
  128. _( "Plot to &Clipboard" ),
  129. _( "Export drawings to clipboard" ),
  130. KiBitmap( copy_button_xpm ) );
  131. #endif // __WINDOWS__
  132. // Plot submenu
  133. AddMenuItem( fileMenu, choice_plot_fmt,
  134. ID_GEN_PLOT, _( "&Plot" ),
  135. _( "Plot schematic sheet in HPGL, PostScript or SVG format" ),
  136. KiBitmap( plot_xpm ) );
  137. // Separator
  138. fileMenu->AppendSeparator();
  139. // Quit
  140. AddMenuItem( fileMenu,
  141. wxID_EXIT,
  142. _( "&Quit" ),
  143. _( "Quit Eeschema" ),
  144. KiBitmap( exit_xpm ) );
  145. // Menu Edit:
  146. wxMenu* editMenu = new wxMenu;
  147. // Undo
  148. text = AddHotkeyName( _( "&Undo" ), s_Schematic_Hokeys_Descr, HK_UNDO );
  149. AddMenuItem( editMenu, wxID_UNDO, text, HELP_UNDO, KiBitmap( undo_xpm ) );
  150. // Redo
  151. text = AddHotkeyName( _( "&Redo" ), s_Schematic_Hokeys_Descr, HK_REDO );
  152. AddMenuItem( editMenu, wxID_REDO, text, HELP_REDO, KiBitmap( redo_xpm ) );
  153. // Delete
  154. editMenu->AppendSeparator();
  155. AddMenuItem( editMenu, ID_SCHEMATIC_DELETE_ITEM_BUTT,
  156. _( "&Delete" ), HELP_DELETE_ITEMS,
  157. KiBitmap( delete_xpm ) );
  158. // Find
  159. editMenu->AppendSeparator();
  160. text = AddHotkeyName( _( "&Find" ), s_Schematic_Hokeys_Descr, HK_FIND_ITEM );
  161. AddMenuItem( editMenu, ID_FIND_ITEMS, text, HELP_FIND, KiBitmap( find_xpm ) );
  162. // Find/Replace
  163. AddMenuItem( editMenu, wxID_REPLACE, _( "Find and Re&place\tCtrl+Shift+F" ), HELP_REPLACE,
  164. KiBitmap( find_replace_xpm ) );
  165. // Backannotate
  166. editMenu->AppendSeparator();
  167. AddMenuItem( editMenu,
  168. ID_BACKANNO_ITEMS,
  169. _( "&Backannotate" ),
  170. _( "Back annotate the footprint fields" ),
  171. KiBitmap( import_footprint_names_xpm ) );
  172. // Menu View:
  173. wxMenu* viewMenu = new wxMenu;
  174. /**
  175. * Important Note for ZOOM IN and ZOOM OUT commands from menubar:
  176. * we cannot add hotkey shortcut here, because the hotkey HK_ZOOM_IN and HK_ZOOM_OUT
  177. * events(default = WXK_F1 and WXK_F2) are *NOT* equivalent to this menu command:
  178. * zoom in and out from hotkeys are equivalent to the pop up menu zoom
  179. * From here, zooming is made around the screen center
  180. * From hotkeys, zooming is made around the mouse cursor position
  181. * (obviously not possible from the toolbar or menubar command)
  182. *
  183. * in others words HK_ZOOM_IN and HK_ZOOM_OUT *are NOT* accelerators
  184. * for Zoom in and Zoom out sub menus
  185. * SO WE ADD THE NAME OF THE CORRESPONDING HOTKEY AS A COMMENT, NOT AS A SHORTCUT
  186. * using in AddHotkeyName call the option "false" (not a shortcut)
  187. */
  188. // Zoom in
  189. text = AddHotkeyName( _( "Zoom &In" ), s_Schematic_Hokeys_Descr,
  190. HK_ZOOM_IN, IS_ACCELERATOR ); // add an accelerator, not a shortcut
  191. AddMenuItem( viewMenu, ID_ZOOM_IN, text, HELP_ZOOM_IN, KiBitmap( zoom_in_xpm ) );
  192. // Zoom out
  193. text = AddHotkeyName( _( "Zoom &Out" ), s_Schematic_Hokeys_Descr,
  194. HK_ZOOM_OUT, IS_ACCELERATOR ); // add accelerator, not a shortcut
  195. AddMenuItem( viewMenu, ID_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) );
  196. // Fit on screen
  197. text = AddHotkeyName( _( "&Fit on Screen" ), s_Schematic_Hokeys_Descr, HK_ZOOM_AUTO );
  198. AddMenuItem( viewMenu, ID_ZOOM_PAGE, text, HELP_ZOOM_FIT, KiBitmap( zoom_fit_in_page_xpm ) );
  199. // Separator
  200. viewMenu->AppendSeparator();
  201. // Hierarchy
  202. AddMenuItem( viewMenu,
  203. ID_HIERARCHY,
  204. _( "&Hierarchy" ),
  205. _( "Navigate schematic hierarchy" ),
  206. KiBitmap( hierarchy_nav_xpm ) );
  207. // Redraw
  208. text = AddHotkeyName( _( "&Redraw" ), s_Schematic_Hokeys_Descr, HK_ZOOM_REDRAW );
  209. AddMenuItem( viewMenu, ID_ZOOM_REDRAW, text, HELP_ZOOM_REDRAW, KiBitmap( zoom_redraw_xpm ) );
  210. // Menu place:
  211. // @todo unify IDs
  212. wxMenu* placeMenu = new wxMenu;
  213. // Component
  214. text = AddHotkeyName( _( "&Component" ), s_Schematic_Hokeys_Descr,
  215. HK_ADD_NEW_COMPONENT, IS_ACCELERATOR ); // add an accelerator, not a shortcut
  216. AddMenuItem( placeMenu, ID_SCH_PLACE_COMPONENT, text,
  217. HELP_PLACE_COMPONENTS,
  218. KiBitmap( add_component_xpm ) );
  219. // Power port
  220. text = AddHotkeyName( _( "&Power Port" ), s_Schematic_Hokeys_Descr,
  221. HK_ADD_NEW_POWER, IS_ACCELERATOR ); // add an accelerator, not a shortcut
  222. AddMenuItem( placeMenu, ID_PLACE_POWER_BUTT, text,
  223. HELP_PLACE_POWERPORT,
  224. KiBitmap( add_power_xpm ) );
  225. // Wire
  226. text = AddHotkeyName( _( "&Wire" ), s_Schematic_Hokeys_Descr,
  227. HK_BEGIN_WIRE, IS_ACCELERATOR ); // add an accelerator, not a shortcut
  228. AddMenuItem( placeMenu, ID_WIRE_BUTT, text,
  229. HELP_PLACE_WIRE,
  230. KiBitmap( add_line_xpm ) );
  231. // Bus
  232. text = AddHotkeyName( _( "&Bus" ), s_Schematic_Hokeys_Descr,
  233. HK_BEGIN_BUS, IS_ACCELERATOR ); // add an accelerator, not a shortcut
  234. AddMenuItem( placeMenu, ID_BUS_BUTT, text,
  235. HELP_PLACE_BUS,
  236. KiBitmap( add_bus_xpm ) );
  237. // Wire to Bus entry
  238. text = AddHotkeyName( _( "Wire to Bus &Entry" ), s_Schematic_Hokeys_Descr,
  239. HK_ADD_WIRE_ENTRY, IS_ACCELERATOR ); // add an accelerator, not a shortcut
  240. AddMenuItem( placeMenu, ID_WIRETOBUS_ENTRY_BUTT, text,
  241. HELP_PLACE_WIRE2BUS_ENTRY,
  242. KiBitmap( add_line2bus_xpm ) );
  243. // Bus to Bus entry
  244. text = AddHotkeyName( _( "Bus &to Bus Entry" ), s_Schematic_Hokeys_Descr,
  245. HK_ADD_BUS_ENTRY, IS_ACCELERATOR ); // add an accelerator, not a shortcut
  246. AddMenuItem( placeMenu, ID_BUSTOBUS_ENTRY_BUTT, text,
  247. HELP_PLACE_BUS2BUS_ENTRY,
  248. KiBitmap( add_bus2bus_xpm ) );
  249. // No Connect Flag
  250. text = AddHotkeyName( _( "&No Connect Flag" ), s_Schematic_Hokeys_Descr,
  251. HK_ADD_NOCONN_FLAG, IS_ACCELERATOR ); // add an accelerator, not a shortcut
  252. AddMenuItem( placeMenu, ID_NOCONN_BUTT, text, HELP_PLACE_NC_FLAG, KiBitmap( noconn_xpm ) );
  253. // Net name
  254. text = AddHotkeyName( _( "&Label" ), s_Schematic_Hokeys_Descr,
  255. HK_ADD_LABEL, IS_ACCELERATOR ); // add an accelerator, not a shortcut
  256. AddMenuItem( placeMenu, ID_LABEL_BUTT, text,
  257. HELP_PLACE_NETLABEL,
  258. KiBitmap( add_line_label_xpm ) );
  259. // Global label
  260. text = AddHotkeyName( _( "Gl&obal Label" ), s_Schematic_Hokeys_Descr,
  261. HK_ADD_GLABEL, IS_ACCELERATOR ); // add an accelerator, not a shortcut
  262. AddMenuItem( placeMenu, ID_GLABEL_BUTT, text,
  263. HELP_PLACE_GLOBALLABEL,
  264. KiBitmap( add_glabel_xpm ) );
  265. // Junction
  266. text = AddHotkeyName( _( "&Junction" ), s_Schematic_Hokeys_Descr,
  267. HK_ADD_JUNCTION, IS_ACCELERATOR ); // add an accelerator, not a shortcut
  268. AddMenuItem( placeMenu, ID_JUNCTION_BUTT, text,
  269. HELP_PLACE_JUNCTION,
  270. KiBitmap( add_junction_xpm ) );
  271. // Separator
  272. placeMenu->AppendSeparator();
  273. // Hierarchical label
  274. text = AddHotkeyName( _( "&Hierarchical Label" ), s_Schematic_Hokeys_Descr,
  275. HK_ADD_HLABEL, IS_ACCELERATOR ); // add an accelerator, not a shortcut
  276. AddMenuItem( placeMenu, ID_HIERLABEL_BUTT,
  277. text, HELP_PLACE_HIER_LABEL,
  278. KiBitmap( add_hierarchical_label_xpm ) );
  279. // Hierarchical sheet
  280. text = AddHotkeyName( _( "H&ierarchical &Sheet" ), s_Schematic_Hokeys_Descr,
  281. HK_ADD_HIER_SHEET, IS_ACCELERATOR ); // add an accelerator, not a shortcut
  282. AddMenuItem( placeMenu, ID_SHEET_SYMBOL_BUTT, text,
  283. HELP_PLACE_SHEET,
  284. KiBitmap( add_hierarchical_subsheet_xpm ) );
  285. // Import hierarchical sheet
  286. AddMenuItem( placeMenu,
  287. ID_IMPORT_HLABEL_BUTT,
  288. _( "I&mport Hierarchical Label" ),
  289. HELP_IMPORT_SHEETPIN,
  290. KiBitmap( import_hierarchical_label_xpm ) );
  291. // Add hierarchical Pin to Sheet
  292. AddMenuItem( placeMenu,
  293. ID_SHEET_PIN_BUTT,
  294. _( "Hierarchical Pi&n to Sheet" ),
  295. HELP_PLACE_SHEETPIN,
  296. KiBitmap( add_hierar_pin_xpm ) );
  297. // Separator
  298. placeMenu->AppendSeparator();
  299. // Graphic line or polygon
  300. text = AddHotkeyName( _( "Graphic Polyline" ), s_Schematic_Hokeys_Descr,
  301. HK_ADD_GRAPHIC_POLYLINE, IS_ACCELERATOR ); // add an accelerator, not a shortcut
  302. AddMenuItem( placeMenu, ID_LINE_COMMENT_BUTT, text,
  303. HELP_PLACE_GRAPHICLINES,
  304. KiBitmap( add_dashed_line_xpm ) );
  305. // Graphic text
  306. text = AddHotkeyName( _( "Graphic Text" ), s_Schematic_Hokeys_Descr,
  307. HK_ADD_GRAPHIC_TEXT, IS_ACCELERATOR ); // add an accelerator, not a shortcut
  308. AddMenuItem( placeMenu, ID_TEXT_COMMENT_BUTT, text,
  309. HELP_PLACE_GRAPHICTEXTS,
  310. KiBitmap( add_text_xpm ) );
  311. // Graphic image
  312. AddMenuItem( placeMenu, ID_ADD_IMAGE_BUTT, _( "Image" ),
  313. HELP_PLACE_GRAPHICIMAGES,
  314. KiBitmap( image_xpm ) );
  315. // Menu Preferences:
  316. wxMenu* preferencesMenu = new wxMenu;
  317. // Library
  318. AddMenuItem( preferencesMenu,
  319. ID_CONFIG_REQ,
  320. _( "&Library" ),
  321. _( "Library preferences" ),
  322. KiBitmap( library_xpm ) );
  323. // Colors
  324. AddMenuItem( preferencesMenu,
  325. ID_COLORS_SETUP,
  326. _( "&Colors" ),
  327. _( "Color preferences" ),
  328. KiBitmap( palette_xpm ) );
  329. // Options (Preferences on WXMAC)
  330. #ifdef __WXMAC__
  331. preferencesMenu->Append( wxID_PREFERENCES );
  332. #else
  333. AddMenuItem( preferencesMenu,
  334. wxID_PREFERENCES,
  335. _( "&Options" ),
  336. _( "Eeschema preferences" ),
  337. KiBitmap( preference_xpm ) );
  338. #endif // __WXMAC__
  339. // Language submenu
  340. wxGetApp().AddMenuLanguageList( preferencesMenu );
  341. // Hotkey submenu
  342. AddHotkeyConfigMenu( preferencesMenu );
  343. // Separator
  344. preferencesMenu->AppendSeparator();
  345. // Save preferences
  346. AddMenuItem( preferencesMenu,
  347. ID_CONFIG_SAVE,
  348. _( "&Save Preferences" ),
  349. _( "Save application preferences" ),
  350. KiBitmap( save_setup_xpm ) );
  351. // Read preferences
  352. AddMenuItem( preferencesMenu,
  353. ID_CONFIG_READ,
  354. _( "&Read Preferences" ),
  355. _( "Read application preferences" ),
  356. KiBitmap( read_setup_xpm ) );
  357. // Menu Tools:
  358. wxMenu* toolsMenu = new wxMenu;
  359. // Library editor
  360. AddMenuItem( toolsMenu,
  361. ID_TO_LIBRARY,
  362. _( "Library &Editor" ), HELP_RUN_LIB_EDITOR,
  363. KiBitmap( libedit_xpm ) );
  364. // Library viewer
  365. AddMenuItem( toolsMenu,
  366. ID_TO_LIBVIEW,
  367. _( "Library &Browser" ), HELP_RUN_LIB_VIEWER,
  368. KiBitmap( library_browse_xpm ) );
  369. // Separator
  370. toolsMenu->AppendSeparator();
  371. // Annotate
  372. AddMenuItem( toolsMenu,
  373. ID_GET_ANNOTATE,
  374. _( "&Annotate" ), HELP_ANNOTATE,
  375. KiBitmap( annotate_xpm ) );
  376. // ERC
  377. AddMenuItem( toolsMenu,
  378. ID_GET_ERC,
  379. _( "ER&C" ),
  380. _( "Perform electrical rule check" ),
  381. KiBitmap( erc_xpm ) );
  382. // Generate netlist
  383. AddMenuItem( toolsMenu,
  384. ID_GET_NETLIST,
  385. _( "Generate &Netlist" ),
  386. _( "Generate the component netlist" ),
  387. KiBitmap( netlist_xpm ) );
  388. // Generate bill of materials
  389. AddMenuItem( toolsMenu,
  390. ID_GET_TOOLS,
  391. _( "Generate Bill of &Materials" ),
  392. HELP_GENERATE_BOM,
  393. KiBitmap( bom_xpm ) );
  394. // Separator
  395. toolsMenu->AppendSeparator();
  396. //Run CvPcb
  397. AddMenuItem( toolsMenu,
  398. ID_TO_CVPCB,
  399. _( "A&ssign Component Footprints" ),
  400. _( "Run CvPcb" ),
  401. KiBitmap( cvpcb_xpm ) );
  402. // Run Pcbnew
  403. AddMenuItem( toolsMenu,
  404. ID_TO_PCB,
  405. _( "&Layout Printed Circuit Board" ),
  406. _( "Run Pcbnew" ),
  407. KiBitmap( pcbnew_xpm ) );
  408. AddMenuItem( toolsMenu, ID_BACKANNO_ITEMS,
  409. _( "Import Footprint Selection" ),
  410. HELP_IMPORT_FOOTPRINTS,
  411. KiBitmap( import_footprint_names_xpm ) );
  412. // Help Menu:
  413. wxMenu* helpMenu = new wxMenu;
  414. // Version info
  415. AddHelpVersionInfoMenuEntry( helpMenu );
  416. // Contents
  417. AddMenuItem( helpMenu,
  418. wxID_HELP,
  419. _( "&Contents" ),
  420. _( "Open the Eeschema handbook" ),
  421. KiBitmap( online_help_xpm ) );
  422. AddMenuItem( helpMenu,
  423. wxID_INDEX,
  424. _( "&Getting Started in KiCad" ),
  425. _( "Open the \"Getting Started in KiCad\" guide for beginners" ),
  426. KiBitmap( help_xpm ) );
  427. // About Eeschema
  428. helpMenu->AppendSeparator();
  429. AddMenuItem( helpMenu,
  430. wxID_ABOUT,
  431. _( "&About Eeschema" ),
  432. _( "About Eeschema schematic designer" ),
  433. KiBitmap( info_xpm ) );
  434. // Create the menubar and append all submenus
  435. menuBar->Append( fileMenu, _( "&File" ) );
  436. menuBar->Append( editMenu, _( "&Edit" ) );
  437. menuBar->Append( viewMenu, _( "&View" ) );
  438. menuBar->Append( placeMenu, _( "&Place" ) );
  439. menuBar->Append( preferencesMenu, _( "P&references" ) );
  440. menuBar->Append( toolsMenu, _( "&Tools" ) );
  441. menuBar->Append( helpMenu, _( "&Help" ) );
  442. menuBar->Thaw();
  443. // Associate the menu bar with the frame, if no previous menubar
  444. if( GetMenuBar() == NULL )
  445. SetMenuBar( menuBar );
  446. else
  447. menuBar->Refresh();
  448. }