KiCad PCB EDA Suite
menubar_footprint_editor.cpp
Go to the documentation of this file.
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) 2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
7  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
8 *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
33 #include <menus_helpers.h>
34 #include <pgm_base.h>
35 
36 #include "help_common_strings.h"
37 #include "hotkeys.h"
38 #include "footprint_edit_frame.h"
39 #include "pcbnew.h"
40 #include "pcbnew_id.h"
41 
42 
44 {
45  // wxWidgets handles the Mac Application menu behind the scenes, but that means
46  // we always have to start from scratch with a new wxMenuBar.
47  wxMenuBar* oldMenuBar = GetMenuBar();
48  wxMenuBar* menuBar = new wxMenuBar();
49  wxString text;
50 
51  // Recreate all menus:
52 
53  // Menu File:
54  wxMenu* fileMenu = new wxMenu;
55 
56  AddMenuItem( fileMenu,
58  _( "New Library..." ),
59  _( "Creates an empty library" ),
60  KiBitmap( new_library_xpm ) );
61 
62  AddMenuItem( fileMenu,
64  _( "Add Library..." ),
65  _( "Adds a previously created library" ),
66  KiBitmap( add_library_xpm ) );
67 
68  text = AddHotkeyName( _( "&New Footprint..." ), m_hotkeysDescrList, HK_NEW );
70  text, _( "Create a new footprint" ),
71  KiBitmap( new_footprint_xpm ) );
72 
73 #ifdef KICAD_SCRIPTING
75  _( "&Create Footprint..." ),
76  _( "Create a new footprint using the footprint wizard" ),
77  KiBitmap( module_wizard_xpm ) );
78 #endif
79 
80  fileMenu->AppendSeparator();
81 
82  text = AddHotkeyName( _( "&Save" ), m_hotkeysDescrList, HK_SAVE );
83  AddMenuItem( fileMenu, ID_MODEDIT_SAVE, text,
84  _( "Save changes" ),
85  KiBitmap( save_xpm ) );
86 
88  _( "Save &As..." ),
89  _( "Save a copy to a new name and/or location" ),
90  KiBitmap( save_as_xpm ) );
91 
93  _( "&Revert" ),
94  _( "Throw away changes" ),
95  KiBitmap( undo_xpm ) );
96 
97  fileMenu->AppendSeparator();
98 
100  _( "Import Footprint from &KiCad File..." ),
101  _( "Import a footprint from an existing footprint file" ),
102  KiBitmap( import_module_xpm ) );
103 
105  _( "Import Outlines from &DXF File..." ),
106  _( "Import 2D Drawing DXF file to Footprint Editor on Drawings layer" ),
107  KiBitmap( import_xpm ) );
108 
110  _( "&Export Footprint..." ),
111  _( "Export current footprint to a file" ),
112  KiBitmap( export_module_xpm ) );
113 
114  fileMenu->AppendSeparator();
115 
116  // Print
117  text = AddHotkeyName( _( "&Print..." ), m_hotkeysDescrList, HK_PRINT );
118  AddMenuItem( fileMenu, wxID_PRINT, text,
119  _( "Print current footprint" ),
120  KiBitmap( print_button_xpm ) );
121 
122  fileMenu->AppendSeparator();
123 
124  AddMenuItem( fileMenu,
126  _( "Export View as PN&G..." ),
127  _( "Create a PNG file from the current view" ),
128  KiBitmap( plot_xpm ) );
129 
130  fileMenu->AppendSeparator();
131 
132  // Close editor
133  AddMenuItem( fileMenu, wxID_EXIT,
134  _( "&Exit" ),
135  _( "Close footprint editor" ),
136  KiBitmap( exit_xpm ) );
137 
138  //----- Edit menu ------------------
139  wxMenu* editMenu = new wxMenu;
140 
141  // Undo
142  text = AddHotkeyName( _( "&Undo" ), m_hotkeysDescrList, HK_UNDO );
143  AddMenuItem( editMenu, wxID_UNDO,
144  text, _( "Undo last action" ),
145  KiBitmap( undo_xpm ) );
146 
147  // Redo
148  text = AddHotkeyName( _( "&Redo" ), m_hotkeysDescrList, HK_REDO );
149  AddMenuItem( editMenu, wxID_REDO,
150  text, _( "Redo last action" ),
151  KiBitmap( redo_xpm ) );
152 
153  // Separator
154  editMenu->AppendSeparator();
155 
156  if( IsGalCanvasActive() )
157  {
158  text = AddHotkeyName( _( "Cu&t" ), m_hotkeysDescrList, HK_EDIT_CUT );
159  AddMenuItem( editMenu, ID_EDIT_CUT, text,
160  _( "Cuts the selected item(s) to the Clipboard" ), KiBitmap( cut_xpm ) );
161  text = AddHotkeyName( _( "&Copy" ), m_hotkeysDescrList, HK_EDIT_COPY );
162  AddMenuItem( editMenu, ID_EDIT_COPY, text,
163  _( "Copies the selected item(s) to the Clipboard" ), KiBitmap( copy_xpm ) );
164  text = AddHotkeyName( _( "&Paste" ), m_hotkeysDescrList, HK_EDIT_PASTE );
165  AddMenuItem( editMenu, ID_EDIT_PASTE, text,
166  _( "Pastes item(s) from the Clipboard" ), KiBitmap( paste_xpm ) );
167 
168  editMenu->AppendSeparator();
169  }
170 
171  // Properties
173  _( "&Footprint Properties..." ),
174  _( "Edit footprint properties" ),
175  KiBitmap( module_options_xpm ) );
176 
178  _( "Default Pad Properties..." ),
179  _( "Edit default pad properties" ),
180  KiBitmap( options_pad_xpm ) );
181 
182  editMenu->AppendSeparator();
183 
185  _( "&Delete Footprint from Library" ),
186  _( "Delete the current footprint" ),
187  KiBitmap( delete_xpm ) );
188 
189  //--------- View menu ----------------
190  wxMenu* viewMenu = new wxMenu;
191 
193  _( "&Library Browser" ),
194  _( "Open the Library Browser" ),
195  KiBitmap( modview_icon_xpm ) );
196 
197  text = AddHotkeyName( _( "&3D Viewer" ), m_hotkeysDescrList, HK_3D_VIEWER );
199  text, _( "Show footprint in 3D viewer" ),
200  KiBitmap( three_d_xpm ) );
201 
202  viewMenu->AppendSeparator();
203 
204  /* Important Note for ZOOM IN and ZOOM OUT commands from menubar:
205  * we cannot add hotkey info here, because the hotkey HK_ZOOM_IN and HK_ZOOM_OUT
206  * events(default = WXK_F1 and WXK_F2) are *NOT* equivalent to this menu command:
207  * zoom in and out from hotkeys are equivalent to the pop up menu zoom
208  * From here, zooming is made around the screen center
209  * From hotkeys, zooming is made around the mouse cursor position
210  * (obviously not possible from the toolbar or menubar command)
211  *
212  * in other words HK_ZOOM_IN and HK_ZOOM_OUT *are NOT* accelerators
213  * for Zoom in and Zoom out sub menus
214  */
215  text = AddHotkeyName( _( "Zoom &In" ), m_hotkeysDescrList,
217  AddMenuItem( viewMenu, ID_ZOOM_IN, text, HELP_ZOOM_IN, KiBitmap( zoom_in_xpm ) );
218 
219  text = AddHotkeyName( _( "Zoom &Out" ), m_hotkeysDescrList,
221  AddMenuItem( viewMenu, ID_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) );
222 
223  text = AddHotkeyName( _( "&Zoom to Fit" ), m_hotkeysDescrList,
224  HK_ZOOM_AUTO );
225  AddMenuItem( viewMenu, ID_ZOOM_PAGE, text, _( "Zoom to fit footprint" ),
226  KiBitmap( zoom_fit_in_page_xpm ) );
227 
228  text = AddHotkeyName( _( "Zoom to Selection" ), m_hotkeysDescrList, HK_ZOOM_SELECTION );
229 
230  AddMenuItem( viewMenu, ID_ZOOM_SELECTION, text, KiBitmap( zoom_area_xpm ), wxITEM_CHECK );
231 
232  text = AddHotkeyName( _( "&Redraw" ), m_hotkeysDescrList, HK_ZOOM_REDRAW );
233  AddMenuItem( viewMenu, ID_ZOOM_REDRAW, text,
234  HELP_ZOOM_REDRAW, KiBitmap( zoom_redraw_xpm ) );
235 
236  viewMenu->AppendSeparator();
237 
239  _( "Show &Grid" ), wxEmptyString,
240  KiBitmap( grid_xpm ), wxITEM_CHECK );
241 
243  _( "Grid &Settings..." ),_( "Adjust custom user-defined grid dimensions" ),
244  KiBitmap( grid_xpm ) );
245 
247  _( "Display &Polar Coordinates" ), wxEmptyString,
248  KiBitmap( polar_coord_xpm ), wxITEM_CHECK );
249 
250  // Units submenu
251  wxMenu* unitsSubMenu = new wxMenu;
253  _( "&Imperial" ), _( "Use imperial units" ),
254  KiBitmap( unit_inch_xpm ), wxITEM_RADIO );
255 
257  _( "&Metric" ), _( "Use metric units" ),
258  KiBitmap( unit_mm_xpm ), wxITEM_RADIO );
259 
260  AddMenuItem( viewMenu, unitsSubMenu,
261  -1, _( "&Units" ),
262  _( "Select which units are displayed" ),
263  KiBitmap( unit_mm_xpm ) );
264 
265 #ifndef __APPLE__
267  _( "Full Window Crosshair" ),
268  _( "Change cursor shape" ),
269  KiBitmap( cursor_shape_xpm ), wxITEM_CHECK );
270 #else
272  _( "Full Window Crosshair" ),
273  _( "Change cursor shape (not supported in Legacy Toolset)" ),
274  KiBitmap( cursor_shape_xpm ), wxITEM_CHECK );
275 #endif
276 
277  viewMenu->AppendSeparator();
278 
279  // Drawing Mode Submenu
280  wxMenu* drawingModeSubMenu = new wxMenu;
281 
282  AddMenuItem( drawingModeSubMenu, ID_TB_OPTIONS_SHOW_PADS_SKETCH,
283  _( "Sketch &Pads" ), _( "Show pads in outline mode" ),
284  KiBitmap( pad_sketch_xpm ), wxITEM_CHECK );
285 
287  _( "Sketch Footprint &Edges" ), _( "Show footprint edges in outline mode" ),
288  KiBitmap( show_mod_edge_xpm ), wxITEM_CHECK );
290  _( "Sketch Footprint Te&xt" ), _( "Show footprint text in outline mode" ),
291  KiBitmap( text_sketch_xpm ), wxITEM_CHECK );
292 
293  AddMenuItem( viewMenu, drawingModeSubMenu,
294  -1, _( "&Drawing Mode" ),
295  _( "Select how items are displayed" ),
296  KiBitmap( add_zone_xpm ) );
297 
298  // Contrast Mode Submenu
299  wxMenu* contrastModeSubMenu = new wxMenu;
300 
301  text = AddHotkeyName( _( "&High Contrast Mode" ), m_hotkeysDescrList,
303  AddMenuItem( contrastModeSubMenu, ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE, text,
304  _( "Use high contrast display mode" ),
305  KiBitmap( contrast_mode_xpm ), wxITEM_CHECK );
306 
307  contrastModeSubMenu->AppendSeparator();
308 
309  text = AddHotkeyName( _( "&Decrease Layer Opacity" ), g_Pcbnew_Editor_Hotkeys_Descr,
311  AddMenuItem( contrastModeSubMenu, ID_DEC_LAYER_ALPHA,
312  text, _( "Make the current layer more transparent" ),
313  KiBitmap( contrast_mode_xpm ) );
314 
315  text = AddHotkeyName( _( "&Increase Layer Opacity" ), g_Pcbnew_Editor_Hotkeys_Descr,
317  AddMenuItem( contrastModeSubMenu, ID_INC_LAYER_ALPHA,
318  text, _( "Make the current layer less transparent" ),
319  KiBitmap( contrast_mode_xpm ) );
320 
321  AddMenuItem( viewMenu, contrastModeSubMenu,
322  -1, _( "&Contrast Mode" ),
323  _( "Select how items are displayed" ),
324  KiBitmap( contrast_mode_xpm ) );
325 
326  // Separator
327  viewMenu->AppendSeparator();
328 
329  AddMenuItem( viewMenu,
331  _( "&Search Tree" ),
332  _( "Toggles the search tree visibility" ),
333  KiBitmap( search_tree_xpm ), wxITEM_CHECK );
334 
335 
336  //-------- Place menu --------------------
337  wxMenu* placeMenu = new wxMenu;
338 
339  // Pad
340  AddMenuItem( placeMenu, ID_MODEDIT_PAD_TOOL,
341  _( "&Pad" ), _( "Add pad" ),
342  KiBitmap( pad_xpm ) );
343 
344  placeMenu->AppendSeparator();
345 
346  // Text
347  text = AddHotkeyName( _( "&Text" ), m_hotkeysDescrList, HK_ADD_TEXT );
348  AddMenuItem( placeMenu, ID_MODEDIT_TEXT_TOOL,
349  text, _( "Add graphic text" ),
350  KiBitmap( text_xpm ) );
351 
352  // Arc
353  text = AddHotkeyName( _( "&Arc" ), m_hotkeysDescrList, HK_ADD_ARC );
354  AddMenuItem( placeMenu, ID_MODEDIT_ARC_TOOL,
355  text, _( "Add graphic arc" ),
356  KiBitmap( add_arc_xpm ) );
357 
358  // Circle
359  text = AddHotkeyName( _( "&Circle" ), m_hotkeysDescrList, HK_ADD_CIRCLE );
361  text, _( "Add graphic circle" ),
362  KiBitmap( add_circle_xpm ) );
363 
364  // Line
365  text = AddHotkeyName( _( "&Line" ), m_hotkeysDescrList, HK_ADD_LINE );
366  AddMenuItem( placeMenu, ID_MODEDIT_LINE_TOOL,
367  text, _( "Add graphic line" ),
368  KiBitmap( add_graphical_segments_xpm ) );
369 
370  // Polygon
371  text = AddHotkeyName( _( "&Polygon" ), m_hotkeysDescrList, HK_ADD_POLYGON );
373  text, _( "Add graphic polygon" ),
374  KiBitmap( add_graphical_polygon_xpm ) );
375 
376  placeMenu->AppendSeparator();
377 
378  // Anchor
379  text = AddHotkeyName( _( "A&nchor" ), m_hotkeysDescrList, HK_ADD_ANCHOR );
381  text, _( "Place footprint reference anchor" ),
382  KiBitmap( anchor_xpm ) );
383 
384  // Origin
386  _( "&Grid Origin" ),
387  _( "Set grid origin point" ),
388  KiBitmap( grid_select_axis_xpm ) );
389 
390 
391  //----- Inspect menu ---------------------
392  wxMenu* inspectMenu = new wxMenu;
393 
394  text = AddHotkeyName( _( "&Measure" ), m_hotkeysDescrList, HK_MEASURE_TOOL );
396  text, _( "Measure distance" ),
397  KiBitmap( measurement_xpm ) );
398 
399  //----- Tools menu ---------------------
400  wxMenu* toolsMenu = new wxMenu;
401 
403  _( "&Load Footprint from PCB..." ),
404  _( "Load a footprint from the current board into the editor" ),
405  KiBitmap( load_module_board_xpm ) );
406 
408  _( "&Insert Footprint on PCB" ),
409  _( "Insert footprint onto current board" ),
410  KiBitmap( insert_module_board_xpm ) );
411 
412 
413  //----- Preferences menu -----------------
414  wxMenu* prefs_menu = new wxMenu;
415 
416  // Path configuration edit dialog.
417  AddMenuItem( prefs_menu,
419  _( "&Configure Paths..." ),
420  _( "Edit path configuration environment variables" ),
421  KiBitmap( path_xpm ) );
422 
423  AddMenuItem( prefs_menu, ID_PCB_LIB_TABLE_EDIT,
424  _( "Manage &Footprint Libraries..." ), _( "Configure footprint library table" ),
425  KiBitmap( library_table_xpm ) );
426 
427  // Settings
428  AddMenuItem( prefs_menu, wxID_PREFERENCES,
429  _( "&Preferences..." ), _( "Show preferences for all open tools" ),
430  KiBitmap( preference_xpm ) );
431 
432  prefs_menu->AppendSeparator();
433 
434  text = AddHotkeyName( _( "Legacy Tool&set" ), m_hotkeysDescrList, HK_CANVAS_LEGACY );
435  AddMenuItem( prefs_menu, ID_MENU_CANVAS_LEGACY, text,
436  _( "Use Legacy Toolset (not all features will be available)" ),
437  KiBitmap( tools_xpm ), wxITEM_RADIO );
438 
439  text = AddHotkeyName( _( "Modern Toolset (&Accelerated)" ), m_hotkeysDescrList, HK_CANVAS_OPENGL );
440  AddMenuItem( prefs_menu, ID_MENU_CANVAS_OPENGL, text,
441  _( "Use Modern Toolset with hardware-accelerated graphics (recommended)" ),
442  KiBitmap( tools_xpm ), wxITEM_RADIO );
443 
444  text = AddHotkeyName( _( "Modern Toolset (&Fallback)" ), m_hotkeysDescrList, HK_CANVAS_CAIRO );
445  AddMenuItem( prefs_menu, ID_MENU_CANVAS_CAIRO, text,
446  _( "Use Modern Toolset with software graphics (fall-back)" ),
447  KiBitmap( tools_xpm ), wxITEM_RADIO );
448 
449  prefs_menu->AppendSeparator();
450 
451  // Language submenu
452  Pgm().AddMenuLanguageList( prefs_menu );
453 
454  //----- Help menu --------------------
455  wxMenu* helpMenu = new wxMenu;
456 
457  // Contents
458  AddMenuItem( helpMenu, wxID_HELP,
459  _( "Pcbnew &Manual" ),
460  _( "Open the Pcbnew Manual" ),
461  KiBitmap( online_help_xpm ) );
462 
463  AddMenuItem( helpMenu, wxID_INDEX,
464  _( "&Getting Started in KiCad" ),
465  _( "Open the \"Getting Started in KiCad\" guide for beginners" ),
466  KiBitmap( help_xpm ) );
467 
468  text = AddHotkeyName( _( "&List Hotkeys..." ), m_hotkeysDescrList, HK_HELP );
470  text,
471  _( "Displays current hotkeys table and corresponding commands" ),
472  KiBitmap( hotkeys_xpm ) );
473 
474  helpMenu->AppendSeparator();
475 
477  _( "Get &Involved" ),
478  _( "Contribute to KiCad (opens a web browser)" ),
479  KiBitmap( info_xpm ) );
480 
481  // About Pcbnew
482  helpMenu->AppendSeparator();
483  AddMenuItem( helpMenu, wxID_ABOUT, _( "&About KiCad" ), KiBitmap( about_xpm ) );
484 
485  // Append menus to the menubar
486  menuBar->Append( fileMenu, _( "&File" ) );
487  menuBar->Append( editMenu, _( "&Edit" ) );
488  menuBar->Append( viewMenu, _( "&View" ) );
489  menuBar->Append( placeMenu, _( "&Place" ) );
490  menuBar->Append( inspectMenu, _( "&Inspect" ) );
491  menuBar->Append( toolsMenu, _( "&Tools" ) );
492  menuBar->Append( prefs_menu, _( "P&references" ) );
493  menuBar->Append( helpMenu, _( "&Help" ) );
494 
495  SetMenuBar( menuBar );
496  delete oldMenuBar;
497 }
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:223
Definition: id.h:241
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
struct EDA_HOTKEY_CONFIG g_Pcbnew_Editor_Hotkeys_Descr[]
Definition of class FOOTPRINT_EDIT_FRAME.
#define HELP_ZOOM_OUT
Pcbnew hotkeys.
#define HELP_ZOOM_REDRAW
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
void ReCreateMenuBar() override
(Re)Create the menubar for the module editor frame
EDA_DRAW_FRAME::OnSelectGrid ID_TB_OPTIONS_SELECT_UNIT_INCH
EDA_HOTKEY_CONFIG * m_hotkeysDescrList
Definition: draw_frame.h:105
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:914
ID_MODEDIT_MEASUREMENT_TOOL
wxString AddHotkeyName(const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType)
Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value) ...
see class PGM_BASE
#define HELP_ZOOM_IN
VTBL_ENTRY void AddMenuLanguageList(wxMenu *MasterMenu)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
Definition: pgm_base.cpp:800
static const char * text_xpm[]
strings common to toolbars and menubar