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 
32 #include "footprint_edit_frame.h"
33 
34 #include <advanced_config.h>
35 #include <menus_helpers.h>
36 #include <pgm_base.h>
37 
38 #include "help_common_strings.h"
39 #include "hotkeys.h"
40 #include "pcbnew.h"
41 #include "pcbnew_id.h"
42 
43 
45 {
46  // wxWidgets handles the Mac Application menu behind the scenes, but that means
47  // we always have to start from scratch with a new wxMenuBar.
48  wxMenuBar* oldMenuBar = GetMenuBar();
49  wxMenuBar* menuBar = new wxMenuBar();
50  wxString text;
51 
52  // Recreate all menus:
53 
54  // Menu File:
55  wxMenu* fileMenu = new wxMenu;
56 
57  AddMenuItem( fileMenu,
59  _( "New Library..." ),
60  _( "Creates an empty library" ),
61  KiBitmap( new_library_xpm ) );
62 
63  AddMenuItem( fileMenu,
65  _( "Add Library..." ),
66  _( "Adds a previously created library" ),
67  KiBitmap( add_library_xpm ) );
68 
69  text = AddHotkeyName( _( "&New Footprint..." ), m_hotkeysDescrList, HK_NEW );
71  text, _( "Create a new footprint" ),
72  KiBitmap( new_footprint_xpm ) );
73 
74 #ifdef KICAD_SCRIPTING
76  _( "&Create Footprint..." ),
77  _( "Create a new footprint using the footprint wizard" ),
78  KiBitmap( module_wizard_xpm ) );
79 #endif
80 
81  fileMenu->AppendSeparator();
82 
83  text = AddHotkeyName( _( "&Save" ), m_hotkeysDescrList, HK_SAVE );
84  AddMenuItem( fileMenu, ID_MODEDIT_SAVE, text,
85  _( "Save changes" ),
86  KiBitmap( save_xpm ) );
87 
89  _( "Save &As..." ),
90  _( "Save a copy to a new name and/or location" ),
91  KiBitmap( save_as_xpm ) );
92 
94  _( "&Revert" ),
95  _( "Throw away changes" ),
96  KiBitmap( undo_xpm ) );
97 
98  fileMenu->AppendSeparator();
99 
101  _( "Import Footprint from &KiCad File..." ),
102  _( "Import a footprint from an existing footprint file" ),
103  KiBitmap( import_module_xpm ) );
104 
106  _( "Import Outlines from &DXF or SVG File..." ),
107  _( "Import 2D Drawing DXF or SVG file to Footprint Editor on Drawings layer" ),
108  KiBitmap( import_xpm ) );
109 
111  _( "&Export Footprint..." ),
112  _( "Export current footprint to a file" ),
113  KiBitmap( export_module_xpm ) );
114 
115  fileMenu->AppendSeparator();
116 
117  // Print
118  text = AddHotkeyName( _( "&Print..." ), m_hotkeysDescrList, HK_PRINT );
119  AddMenuItem( fileMenu, wxID_PRINT, text,
120  _( "Print current footprint" ),
121  KiBitmap( print_button_xpm ) );
122 
123  fileMenu->AppendSeparator();
124 
125  AddMenuItem( fileMenu,
127  _( "Export View as PN&G..." ),
128  _( "Create a PNG file from the current view" ),
129  KiBitmap( plot_xpm ) );
130 
131  fileMenu->AppendSeparator();
132 
133  // Close editor
134  AddMenuItem( fileMenu, wxID_EXIT,
135  _( "&Exit" ),
136  _( "Close footprint editor" ),
137  KiBitmap( exit_xpm ) );
138 
139  //----- Edit menu ------------------
140  wxMenu* editMenu = new wxMenu;
141 
142  // Undo
143  text = AddHotkeyName( _( "&Undo" ), m_hotkeysDescrList, HK_UNDO );
144  AddMenuItem( editMenu, wxID_UNDO,
145  text, _( "Undo last action" ),
146  KiBitmap( undo_xpm ) );
147 
148  // Redo
149  text = AddHotkeyName( _( "&Redo" ), m_hotkeysDescrList, HK_REDO );
150  AddMenuItem( editMenu, wxID_REDO,
151  text, _( "Redo last action" ),
152  KiBitmap( redo_xpm ) );
153 
154  // Separator
155  editMenu->AppendSeparator();
156 
157  if( IsGalCanvasActive() )
158  {
159  text = AddHotkeyName( _( "Cu&t" ), m_hotkeysDescrList, HK_EDIT_CUT );
160  AddMenuItem( editMenu, ID_EDIT_CUT, text,
161  _( "Cuts the selected item(s) to the Clipboard" ), KiBitmap( cut_xpm ) );
162  text = AddHotkeyName( _( "&Copy" ), m_hotkeysDescrList, HK_EDIT_COPY );
163  AddMenuItem( editMenu, ID_EDIT_COPY, text,
164  _( "Copies the selected item(s) to the Clipboard" ), KiBitmap( copy_xpm ) );
165  text = AddHotkeyName( _( "&Paste" ), m_hotkeysDescrList, HK_EDIT_PASTE );
166  AddMenuItem( editMenu, ID_EDIT_PASTE, text,
167  _( "Pastes item(s) from the Clipboard" ), KiBitmap( paste_xpm ) );
168 
169  editMenu->AppendSeparator();
170  }
171 
172  // Properties
174  _( "&Footprint Properties..." ),
175  _( "Edit footprint properties" ),
176  KiBitmap( module_options_xpm ) );
177 
179  _( "Default Pad Properties..." ),
180  _( "Edit default pad properties" ),
181  KiBitmap( options_pad_xpm ) );
182 
183  editMenu->AppendSeparator();
184 
186  _( "&Delete Footprint from Library" ),
187  _( "Delete the current footprint" ),
188  KiBitmap( delete_xpm ) );
189 
190  //--------- View menu ----------------
191  wxMenu* viewMenu = new wxMenu;
192 
194  _( "&Library Browser" ),
195  _( "Open the Library Browser" ),
196  KiBitmap( modview_icon_xpm ) );
197 
198  text = AddHotkeyName( _( "&3D Viewer" ), m_hotkeysDescrList, HK_3D_VIEWER );
200  text, _( "Show footprint in 3D viewer" ),
201  KiBitmap( three_d_xpm ) );
202 
203  viewMenu->AppendSeparator();
204 
205  /* Important Note for ZOOM IN and ZOOM OUT commands from menubar:
206  * we cannot add hotkey info here, because the hotkey HK_ZOOM_IN and HK_ZOOM_OUT
207  * events(default = WXK_F1 and WXK_F2) are *NOT* equivalent to this menu command:
208  * zoom in and out from hotkeys are equivalent to the pop up menu zoom
209  * From here, zooming is made around the screen center
210  * From hotkeys, zooming is made around the mouse cursor position
211  * (obviously not possible from the toolbar or menubar command)
212  *
213  * in other words HK_ZOOM_IN and HK_ZOOM_OUT *are NOT* accelerators
214  * for Zoom in and Zoom out sub menus
215  */
216  text = AddHotkeyName( _( "Zoom &In" ), m_hotkeysDescrList,
218  AddMenuItem( viewMenu, ID_ZOOM_IN, text, HELP_ZOOM_IN, KiBitmap( zoom_in_xpm ) );
219 
220  text = AddHotkeyName( _( "Zoom &Out" ), m_hotkeysDescrList,
222  AddMenuItem( viewMenu, ID_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) );
223 
224  text = AddHotkeyName( _( "&Zoom to Fit" ), m_hotkeysDescrList,
225  HK_ZOOM_AUTO );
226  AddMenuItem( viewMenu, ID_ZOOM_PAGE, text, _( "Zoom to fit footprint" ),
227  KiBitmap( zoom_fit_in_page_xpm ) );
228 
229  text = AddHotkeyName( _( "Zoom to Selection" ), m_hotkeysDescrList, HK_ZOOM_SELECTION );
230 
231  AddMenuItem( viewMenu, ID_ZOOM_SELECTION, text, KiBitmap( zoom_area_xpm ), wxITEM_CHECK );
232 
233  text = AddHotkeyName( _( "&Redraw" ), m_hotkeysDescrList, HK_ZOOM_REDRAW );
234  AddMenuItem( viewMenu, ID_ZOOM_REDRAW, text,
235  HELP_ZOOM_REDRAW, KiBitmap( zoom_redraw_xpm ) );
236 
237  viewMenu->AppendSeparator();
238 
240  _( "Show &Grid" ), wxEmptyString,
241  KiBitmap( grid_xpm ), wxITEM_CHECK );
242 
244  _( "Grid &Settings..." ),_( "Adjust custom user-defined grid dimensions" ),
245  KiBitmap( grid_xpm ) );
246 
248  _( "Display &Polar Coordinates" ), wxEmptyString,
249  KiBitmap( polar_coord_xpm ), wxITEM_CHECK );
250 
251  // Units submenu
252  wxMenu* unitsSubMenu = new wxMenu;
254  _( "&Imperial" ), _( "Use imperial units" ),
255  KiBitmap( unit_inch_xpm ), wxITEM_RADIO );
256 
258  _( "&Metric" ), _( "Use metric units" ),
259  KiBitmap( unit_mm_xpm ), wxITEM_RADIO );
260 
261  AddMenuItem( viewMenu, unitsSubMenu,
262  -1, _( "&Units" ),
263  _( "Select which units are displayed" ),
264  KiBitmap( unit_mm_xpm ) );
265 
266 #ifndef __APPLE__
268  _( "Full Window Crosshair" ),
269  _( "Change cursor shape" ),
270  KiBitmap( cursor_shape_xpm ), wxITEM_CHECK );
271 #else
273  _( "Full Window Crosshair" ),
274  _( "Change cursor shape (not supported in Legacy Toolset)" ),
275  KiBitmap( cursor_shape_xpm ), wxITEM_CHECK );
276 #endif
277 
278  viewMenu->AppendSeparator();
279 
280  // Drawing Mode Submenu
281  wxMenu* drawingModeSubMenu = new wxMenu;
282 
283  AddMenuItem( drawingModeSubMenu, ID_TB_OPTIONS_SHOW_PADS_SKETCH,
284  _( "Sketch &Pads" ), _( "Show pads in outline mode" ),
285  KiBitmap( pad_sketch_xpm ), wxITEM_CHECK );
286 
288  _( "Sketch Footprint &Edges" ), _( "Show footprint edges in outline mode" ),
289  KiBitmap( show_mod_edge_xpm ), wxITEM_CHECK );
291  _( "Sketch Footprint Te&xt" ), _( "Show footprint text in outline mode" ),
292  KiBitmap( text_sketch_xpm ), wxITEM_CHECK );
293 
294  AddMenuItem( viewMenu, drawingModeSubMenu,
295  -1, _( "&Drawing Mode" ),
296  _( "Select how items are displayed" ),
297  KiBitmap( add_zone_xpm ) );
298 
299  // Contrast Mode Submenu
300  wxMenu* contrastModeSubMenu = new wxMenu;
301 
302  text = AddHotkeyName( _( "&High Contrast Mode" ), m_hotkeysDescrList,
304  AddMenuItem( contrastModeSubMenu, ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE, text,
305  _( "Use high contrast display mode" ),
306  KiBitmap( contrast_mode_xpm ), wxITEM_CHECK );
307 
308  contrastModeSubMenu->AppendSeparator();
309 
310  text = AddHotkeyName( _( "&Decrease Layer Opacity" ), g_Pcbnew_Editor_Hotkeys_Descr,
312  AddMenuItem( contrastModeSubMenu, ID_DEC_LAYER_ALPHA,
313  text, _( "Make the current layer more transparent" ),
314  KiBitmap( contrast_mode_xpm ) );
315 
316  text = AddHotkeyName( _( "&Increase Layer Opacity" ), g_Pcbnew_Editor_Hotkeys_Descr,
318  AddMenuItem( contrastModeSubMenu, ID_INC_LAYER_ALPHA,
319  text, _( "Make the current layer less transparent" ),
320  KiBitmap( contrast_mode_xpm ) );
321 
322  AddMenuItem( viewMenu, contrastModeSubMenu,
323  -1, _( "&Contrast Mode" ),
324  _( "Select how items are displayed" ),
325  KiBitmap( contrast_mode_xpm ) );
326 
327  // Separator
328  viewMenu->AppendSeparator();
329 
330  AddMenuItem( viewMenu,
332  _( "&Search Tree" ),
333  _( "Toggles the search tree visibility" ),
334  KiBitmap( search_tree_xpm ), wxITEM_CHECK );
335 
336 
337  //-------- Place menu --------------------
338  wxMenu* placeMenu = new wxMenu;
339 
340  // Pad
341  AddMenuItem( placeMenu, ID_MODEDIT_PAD_TOOL,
342  _( "&Pad" ), _( "Add pad" ),
343  KiBitmap( pad_xpm ) );
344 
345  placeMenu->AppendSeparator();
346 
347  // Text
348  text = AddHotkeyName( _( "&Text" ), m_hotkeysDescrList, HK_ADD_TEXT );
349  AddMenuItem( placeMenu, ID_MODEDIT_TEXT_TOOL,
350  text, _( "Add graphic text" ),
351  KiBitmap( text_xpm ) );
352 
353  // Arc
354  text = AddHotkeyName( _( "&Arc" ), m_hotkeysDescrList, HK_ADD_ARC );
355  AddMenuItem( placeMenu, ID_MODEDIT_ARC_TOOL,
356  text, _( "Add graphic arc" ),
357  KiBitmap( add_arc_xpm ) );
358 
359  // Circle
360  text = AddHotkeyName( _( "&Circle" ), m_hotkeysDescrList, HK_ADD_CIRCLE );
362  text, _( "Add graphic circle" ),
363  KiBitmap( add_circle_xpm ) );
364 
365  // Line
366  text = AddHotkeyName( _( "&Line" ), m_hotkeysDescrList, HK_ADD_LINE );
367  AddMenuItem( placeMenu, ID_MODEDIT_LINE_TOOL,
368  text, _( "Add graphic line" ),
369  KiBitmap( add_graphical_segments_xpm ) );
370 
371  // Polygon
372  text = AddHotkeyName( _( "&Polygon" ), m_hotkeysDescrList, HK_ADD_POLYGON );
374  text, _( "Add graphic polygon" ),
375  KiBitmap( add_graphical_polygon_xpm ) );
376 
377  placeMenu->AppendSeparator();
378 
379  // Anchor
380  text = AddHotkeyName( _( "A&nchor" ), m_hotkeysDescrList, HK_ADD_ANCHOR );
382  text, _( "Place footprint reference anchor" ),
383  KiBitmap( anchor_xpm ) );
384 
385  // Origin
387  _( "&Grid Origin" ),
388  _( "Set grid origin point" ),
389  KiBitmap( grid_select_axis_xpm ) );
390 
391 
392  //----- Inspect menu ---------------------
393  wxMenu* inspectMenu = new wxMenu;
394 
395  text = AddHotkeyName( _( "&Measure" ), m_hotkeysDescrList, HK_MEASURE_TOOL );
397  text, _( "Measure distance" ),
398  KiBitmap( measurement_xpm ) );
399 
400  //----- Tools menu ---------------------
401  wxMenu* toolsMenu = new wxMenu;
402 
404  _( "&Load Footprint from PCB..." ),
405  _( "Load a footprint from the current board into the editor" ),
406  KiBitmap( load_module_board_xpm ) );
407 
409  _( "&Insert Footprint on PCB" ),
410  _( "Insert footprint onto current board" ),
411  KiBitmap( insert_module_board_xpm ) );
412 
413 
414  //----- Preferences menu -----------------
415  wxMenu* prefs_menu = new wxMenu;
416 
417  // Path configuration edit dialog.
418  AddMenuItem( prefs_menu,
420  _( "&Configure Paths..." ),
421  _( "Edit path configuration environment variables" ),
422  KiBitmap( path_xpm ) );
423 
424  AddMenuItem( prefs_menu, ID_PCB_LIB_TABLE_EDIT,
425  _( "Manage &Footprint Libraries..." ), _( "Configure footprint library table" ),
426  KiBitmap( library_table_xpm ) );
427 
428  // Settings
429  AddMenuItem( prefs_menu, wxID_PREFERENCES,
430  _( "&Preferences..." ), _( "Show preferences for all open tools" ),
431  KiBitmap( preference_xpm ) );
432 
433  prefs_menu->AppendSeparator();
434 
435  if( ADVANCED_CFG::GetCfg().AllowLegacyCanvas() )
436  {
437  text = AddHotkeyName( _( "Legacy Tool&set" ), m_hotkeysDescrList, HK_CANVAS_LEGACY );
438  AddMenuItem( prefs_menu, ID_MENU_CANVAS_LEGACY, text,
439  _( "Use Legacy Toolset (not all features will be available)" ),
440  KiBitmap( tools_xpm ), wxITEM_RADIO );
441  }
442 
443  text = AddHotkeyName( _( "Modern Toolset (&Accelerated)" ), m_hotkeysDescrList, HK_CANVAS_OPENGL );
444  AddMenuItem( prefs_menu, ID_MENU_CANVAS_OPENGL, text,
445  _( "Use Modern Toolset with hardware-accelerated graphics (recommended)" ),
446  KiBitmap( tools_xpm ), wxITEM_RADIO );
447 
448  text = AddHotkeyName( _( "Modern Toolset (&Fallback)" ), m_hotkeysDescrList, HK_CANVAS_CAIRO );
449  AddMenuItem( prefs_menu, ID_MENU_CANVAS_CAIRO, text,
450  _( "Use Modern Toolset with software graphics (fall-back)" ),
451  KiBitmap( tools_xpm ), wxITEM_RADIO );
452 
453  prefs_menu->AppendSeparator();
454 
455  // Language submenu
456  Pgm().AddMenuLanguageList( prefs_menu );
457 
458  //----- Help menu --------------------
459  wxMenu* helpMenu = new wxMenu;
460 
461  // Contents
462  AddMenuItem( helpMenu, wxID_HELP,
463  _( "Pcbnew &Manual" ),
464  _( "Open the Pcbnew Manual" ),
465  KiBitmap( online_help_xpm ) );
466 
467  AddMenuItem( helpMenu, wxID_INDEX,
468  _( "&Getting Started in KiCad" ),
469  _( "Open the \"Getting Started in KiCad\" guide for beginners" ),
470  KiBitmap( help_xpm ) );
471 
472  text = AddHotkeyName( _( "&List Hotkeys..." ), m_hotkeysDescrList, HK_HELP );
474  text,
475  _( "Displays current hotkeys table and corresponding commands" ),
476  KiBitmap( hotkeys_xpm ) );
477 
478  helpMenu->AppendSeparator();
479 
481  _( "Get &Involved" ),
482  _( "Contribute to KiCad (opens a web browser)" ),
483  KiBitmap( info_xpm ) );
484 
485  // About Pcbnew
486  helpMenu->AppendSeparator();
487  AddMenuItem( helpMenu, wxID_ABOUT, _( "&About KiCad" ), KiBitmap( about_xpm ) );
488 
489  // Append menus to the menubar
490  menuBar->Append( fileMenu, _( "&File" ) );
491  menuBar->Append( editMenu, _( "&Edit" ) );
492  menuBar->Append( viewMenu, _( "&View" ) );
493  menuBar->Append( placeMenu, _( "&Place" ) );
494  menuBar->Append( inspectMenu, _( "&Inspect" ) );
495  menuBar->Append( toolsMenu, _( "&Tools" ) );
496  menuBar->Append( prefs_menu, _( "P&references" ) );
497  menuBar->Append( helpMenu, _( "&Help" ) );
498 
499  SetMenuBar( menuBar );
500  delete oldMenuBar;
501 }
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:918
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
static const ADVANCED_CFG & GetCfg()
Get the singleton instance&#39;s config, which is shared by all consumers of advanced config...
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:807
static const char * text_xpm[]
strings common to toolbars and menubar