KiCad PCB EDA Suite
menubar_modedit.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@verizon.net>
7  * Copyright (C) 1992-2017 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 #include <wxPcbStruct.h>
36 
37 
38 #include "help_common_strings.h"
39 #include "hotkeys.h"
40 #include "module_editor_frame.h"
41 #include "pcbnew.h"
42 #include "pcbnew_id.h"
43 
44 
46 {
47  // Create and try to get the current menubar
48  wxMenuBar* menuBar = GetMenuBar();
49 
50  if( !menuBar )
51  menuBar = new wxMenuBar();
52 
53  // Delete all existing menus so they can be rebuilt.
54  // This allows language changes of the menu text on the fly.
55  menuBar->Freeze();
56 
57  while( menuBar->GetMenuCount() )
58  delete menuBar->Remove( 0 );
59 
60  // Recreate all menus:
61  wxString text;
62 
63  // Menu File:
64  wxMenu* fileMenu = new wxMenu;
65 
66  // Active library selection
67  AddMenuItem( fileMenu, ID_MODEDIT_SELECT_CURRENT_LIB, _("Set Acti&ve Library"),
68  _( "Select active library" ),
69  KiBitmap( open_library_xpm ) );
70  fileMenu->AppendSeparator();
71 
72  // New module
74  _( "&New Footprint" ), _( "Create new footprint" ),
75  KiBitmap( new_footprint_xpm ) );
76 
77  // Open submenu
78  wxMenu* openSubmenu = new wxMenu;
79 
80  // from File
81  AddMenuItem( openSubmenu, ID_MODEDIT_IMPORT_PART,
82  _( "&Import Footprint From File" ),
83  _( "Import footprint from an existing file" ),
84  KiBitmap( import_module_xpm ) );
85 
86  // from Library
87  AddMenuItem( openSubmenu, ID_MODEDIT_LOAD_MODULE,
88  _( "Load Footprint From Current Li&brary" ),
89  _( "Open footprint from library" ),
90  KiBitmap( module_xpm ) );
91 
92  // from current Board
94  _( "Load Footprint From &Current Board" ),
95  _( "Load footprint from current board" ),
96  KiBitmap( load_module_board_xpm ) );
97 
98  /* Append openSubmenu to fileMenu */
99  AddMenuItem( fileMenu, openSubmenu, -1,
100  _( "&Load Footprint" ),
101  _( "Load footprint" ),
102  KiBitmap( open_document_xpm ) );
103  fileMenu->AppendSeparator();
104 
105  // Save the currently loaded legacy library as an s-expression library.
107  _( "Save &Current Library As..." ),
108  _( "Save entire current library under a new name" ),
109  KiBitmap( copy_library_xpm ) );
110 
111  // Save module
112  text = AddHotkeyName( _( "&Save Footprint in Active Library" ),
114 
115  AddMenuItem( fileMenu, ID_MODEDIT_SAVE_LIBMODULE, text,
116  _( "Save footprint in active library" ),
117  KiBitmap( save_library_xpm ) );
118 
119  // Save module in new lib
121  _( "S&ave Footprint in New Library" ),
122  _( "Create new library and save current footprint in it" ),
123  KiBitmap( new_library_xpm ) );
124 
125  // Export module
127  _( "&Export Footprint" ),
128  _( "Save currently loaded footprint into file" ),
129  KiBitmap( export_module_xpm ) );
130 
131  // Import DXF File
133  _( "&Import DXF File" ),
134  _( "Import 2D Drawing DXF file to Pcbnew on Drawings layer" ),
135  KiBitmap( import_xpm ) );
136 
137  fileMenu->AppendSeparator();
138 
139  // Print
140  AddMenuItem( fileMenu, wxID_PRINT,
141  _( "&Print" ),
142  _( "Print current footprint" ),
143  KiBitmap( plot_xpm ) );
144 
145  // Separator
146  fileMenu->AppendSeparator();
147 
148  // Close editor
149  AddMenuItem( fileMenu, wxID_EXIT,
150  _( "Cl&ose" ),
151  _( "Close footprint editor" ),
152  KiBitmap( exit_xpm ) );
153 
154  //----- Edit menu ------------------
155  wxMenu* editMenu = new wxMenu;
156 
157  // Undo
158  text = AddHotkeyName( _( "&Undo" ), m_hotkeysDescrList, HK_UNDO );
159  AddMenuItem( editMenu, wxID_UNDO,
160  text, _( "Undo last action" ),
161  KiBitmap( undo_xpm ) );
162 
163  // Redo
164  text = AddHotkeyName( _( "&Redo" ), m_hotkeysDescrList, HK_REDO );
165  AddMenuItem( editMenu, wxID_REDO,
166  text, _( "Redo last action" ),
167  KiBitmap( redo_xpm ) );
168 
169  // Delete items
171  _( "&Delete" ), _( "Delete objects with eraser" ),
172  KiBitmap( delete_xpm ) );
173 
174  // Separator
175  editMenu->AppendSeparator();
176 
177  if( IsGalCanvasActive() )
178  {
180  AddMenuItem( editMenu, ID_EDIT_CUT, text, _(
181  "Cuts the selected item(s) to the Clipboard" ), KiBitmap( cut_xpm ) );
183  AddMenuItem( editMenu, ID_EDIT_COPY, text, _(
184  "Copies the selected item(s) to the Clipboard" ), KiBitmap( copy_xpm ) );
185  text = AddHotkeyName( _( "&Paste" ), g_Module_Viewer_Hokeys_Descr, HK_EDIT_PASTE );
186  AddMenuItem( editMenu, ID_EDIT_PASTE, text, _(
187  "Pastes item(s) from the Clipboard" ), KiBitmap( paste_xpm ) );
188  editMenu->AppendSeparator();
189  }
190 
191  // Properties
193  _( "Footprint &Properties" ),
194  _( "Edit footprint properties" ),
195  KiBitmap( module_options_xpm ) );
196 
197  // Dimensions submenu
198  wxMenu* dimensions_Submenu = new wxMenu;
199 
200  // User grid size
201  AddMenuItem( dimensions_Submenu, ID_PCB_USER_GRID_SETUP,
202  _( "Set Custom &User Grid" ), _( "Set custom user grid size" ),
203  KiBitmap( grid_xpm ) );
204 
205  // Sizes and Widths
206  AddMenuItem( dimensions_Submenu, ID_PCB_DRAWINGS_WIDTHS_SETUP,
207  _( "Text &Size and Width" ),
208  _( "Adjust width for text and drawing" ),
209  KiBitmap( text_xpm ) );
210 
211  // Pad settings
212  AddMenuItem( dimensions_Submenu, ID_MODEDIT_PAD_SETTINGS,
213  _( "&Pad Properties" ), _( "Edit settings for new pads" ),
214  KiBitmap( pad_dimensions_xpm ) );
215 
216  //--------- View menu ----------------
217  wxMenu* viewMenu = new wxMenu;
218 
219  /* Important Note for ZOOM IN and ZOOM OUT commands from menubar:
220  * we cannot add hotkey info here, because the hotkey HK_ZOOM_IN and HK_ZOOM_OUT
221  * events(default = WXK_F1 and WXK_F2) are *NOT* equivalent to this menu command:
222  * zoom in and out from hotkeys are equivalent to the pop up menu zoom
223  * From here, zooming is made around the screen center
224  * From hotkeys, zooming is made around the mouse cursor position
225  * (obviously not possible from the toolbar or menubar command)
226  *
227  * in other words HK_ZOOM_IN and HK_ZOOM_OUT *are NOT* accelerators
228  * for Zoom in and Zoom out sub menus
229  */
230  text = AddHotkeyName( _( "Zoom &In" ), m_hotkeysDescrList,
232  AddMenuItem( viewMenu, ID_ZOOM_IN, text, HELP_ZOOM_IN, KiBitmap( zoom_in_xpm ) );
233 
234  text = AddHotkeyName( _( "Zoom &Out" ), m_hotkeysDescrList,
236  AddMenuItem( viewMenu, ID_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) );
237 
238  text = AddHotkeyName( _( "&Fit on Screen" ), m_hotkeysDescrList,
239  HK_ZOOM_AUTO );
240  AddMenuItem( viewMenu, ID_ZOOM_PAGE, text, HELP_ZOOM_FIT,
241  KiBitmap( zoom_fit_in_page_xpm ) );
242 
243  text = AddHotkeyName( _( "&Redraw" ), m_hotkeysDescrList, HK_ZOOM_REDRAW );
244  AddMenuItem( viewMenu, ID_ZOOM_REDRAW, text,
245  HELP_ZOOM_REDRAW, KiBitmap( zoom_redraw_xpm ) );
246 
247  viewMenu->AppendSeparator();
248 
249  // 3D view
250  text = AddHotkeyName( _( "&3D Viewer" ), m_hotkeysDescrList, HK_3D_VIEWER );
251  AddMenuItem( viewMenu, ID_MENU_PCB_SHOW_3D_FRAME, text, _( "Show footprint in 3D viewer" ),
252  KiBitmap( three_d_xpm ) );
253 
254  // Add canvas selection
255  viewMenu->AppendSeparator();
256 
257  text = AddHotkeyName( _( "Legacy Canva&s" ), m_hotkeysDescrList,
259 
260  viewMenu->Append(
261  new wxMenuItem( viewMenu, ID_MENU_CANVAS_LEGACY,
262  text, _( "Switch the canvas implementation to Legacy" ),
263  wxITEM_RADIO ) );
264 
265  text = AddHotkeyName( _( "Open&GL Canvas" ), m_hotkeysDescrList,
267 
268  viewMenu->Append(
269  new wxMenuItem( viewMenu, ID_MENU_CANVAS_OPENGL,
270  text, _( "Switch the canvas implementation to OpenGL" ),
271  wxITEM_RADIO ) );
272 
273  text = AddHotkeyName( _( "&Cairo Canvas" ), m_hotkeysDescrList,
274  HK_CANVAS_CAIRO );
275 
276  viewMenu->Append(
277  new wxMenuItem( viewMenu, ID_MENU_CANVAS_CAIRO,
278  text, _( "Switch the canvas implementation to Cairo" ),
279  wxITEM_RADIO ) );
280 
281  //-------- Place menu --------------------
282  wxMenu* placeMenu = new wxMenu;
283 
284  // Pad
285  AddMenuItem( placeMenu, ID_MODEDIT_PAD_TOOL,
286  _( "&Pad" ), _( "Add pad" ),
287  KiBitmap( pad_xpm ) );
288 
289  placeMenu->AppendSeparator();
290 
291  // Circle
293  _( "&Circle" ), _( "Add graphic circle" ),
294  KiBitmap( add_circle_xpm ) );
295 
296  // Line or Polygon
297  AddMenuItem( placeMenu, ID_MODEDIT_LINE_TOOL,
298  _( "&Line or Polygon" ),
299  _( "Add graphic line or polygon" ),
300  KiBitmap( add_polygon_xpm ) );
301 
302  // Arc
303  AddMenuItem( placeMenu, ID_MODEDIT_ARC_TOOL,
304  _( "&Arc" ), _( "Add graphic arc" ),
305  KiBitmap( add_arc_xpm ) );
306 
307  // Text
308  AddMenuItem( placeMenu, ID_MODEDIT_TEXT_TOOL,
309  _( "&Text" ), _( "Add graphic text" ),
310  KiBitmap( text_xpm ) );
311 
312  placeMenu->AppendSeparator();
313 
314  // Anchor
316  _( "A&nchor" ),
317  _( "Place footprint reference anchor" ),
318  KiBitmap( anchor_xpm ) );
319 
320 
321  //----- Preferences menu -----------------
322  wxMenu* prefs_menu = new wxMenu;
323 
324  AddMenuItem( prefs_menu, ID_PCB_LIB_WIZARD,
325  _( "&Footprint Library Wizard" ), _( "Add footprint libraries with wizard" ),
326  KiBitmap( wizard_add_fplib_small_xpm ) );
327 
328  AddMenuItem( prefs_menu, ID_PCB_LIB_TABLE_EDIT,
329  _( "Footprint Li&brary Table" ), _( "Configure footprint library table" ),
330  KiBitmap( library_table_xpm ) );
331 
332  // Path configuration edit dialog.
333  AddMenuItem( prefs_menu,
335  _( "Configure Pa&ths" ),
336  _( "Edit path configuration environment variables" ),
337  KiBitmap( path_xpm ) );
338 
339  // Settings
340  AddMenuItem( prefs_menu, wxID_PREFERENCES,
341  _( "General &Settings" ), _( "Change footprint editor settings." ),
342  KiBitmap( preference_xpm ) );
343 
345  _( "&Display and Hide" ),
346  _( "Change footprint editor display settings" ),
347  KiBitmap( display_options_xpm ) );
348 
349  // Language submenu
350  Pgm().AddMenuLanguageList( prefs_menu );
351 
352  // Hotkey submenu
353  AddHotkeyConfigMenu( prefs_menu );
354 
355  //----- Help menu --------------------
356  wxMenu* helpMenu = new wxMenu;
357 
358  // Contents
359  AddMenuItem( helpMenu, wxID_HELP,
360  _( "Pcbnew &Manual" ),
361  _( "Open the Pcbnew Manual" ),
362  KiBitmap( online_help_xpm ) );
363 
364  AddMenuItem( helpMenu, wxID_INDEX,
365  _( "&Getting Started in KiCad" ),
366  _( "Open the \"Getting Started in KiCad\" guide for beginners" ),
367  KiBitmap( help_xpm ) );
368 
370  _( "&List Hotkeys" ),
371  _( "Displays current hotkeys table and corresponding commands" ),
372  KiBitmap( hotkeys_xpm ) );
373 
374  helpMenu->AppendSeparator();
375 
377  _( "Get &Involved" ),
378  _( "Contribute to KiCad (open web browser)" ),
379  KiBitmap( info_xpm ) );
380 
381  // About Pcbnew
382  helpMenu->AppendSeparator();
383  AddMenuItem( helpMenu, wxID_ABOUT,
384  _( "&About KiCad" ),
385  _( "About KiCad" ),
386  KiBitmap( about_xpm ) );
387 
388  // Append menus to the menubar
389  menuBar->Append( fileMenu, _( "&File" ) );
390  menuBar->Append( editMenu, _( "&Edit" ) );
391  menuBar->Append( viewMenu, _( "&View" ) );
392  menuBar->Append( placeMenu, _( "&Place" ) );
393  menuBar->Append( prefs_menu, _( "P&references" ) );
394  menuBar->Append( dimensions_Submenu, _( "Di&mensions" ) );
395  menuBar->Append( helpMenu, _( "&Help" ) );
396 
397  menuBar->Thaw();
398 
399  // Associate the menu bar with the frame, if no previous menubar
400  if( GetMenuBar() == NULL )
401  SetMenuBar( menuBar );
402  else
403  menuBar->Refresh();
404 }
Definition of class FOOTPRINT_EDIT_FRAME.
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:55
#define HELP_ZOOM_FIT
Definition: id.h:232
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
#define HELP_ZOOM_OUT
Pcbnew hotkeys.
#define HELP_ZOOM_REDRAW
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
void ReCreateMenuBar() override
(Re)Create the menubar for the module editor frame
EDA_HOTKEY_CONFIG * m_hotkeysDescrList
Definition: draw_frame.h:77
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:862
void AddHotkeyConfigMenu(wxMenu *aMenu)
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:824
static const char * text_xpm[]
strings common to toolbars and menubar
struct EDA_HOTKEY_CONFIG g_Module_Viewer_Hokeys_Descr[]