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 a footprint from library" ),
90  KiBitmap( module_xpm ) );
91 
92  // from current Board
94  _( "Load Footprint From &Current Board" ),
95  _( "Load a footprint from the 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 a new library and save current footprint into 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 a 2D Drawing DXF file to Pcbnew on the 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  // Properties
179  _( "Edit &Properties" ),
180  _( "Edit footprint properties" ),
181  KiBitmap( module_options_xpm ) );
182 
183  // Dimensions submenu
184  wxMenu* dimensions_Submenu = new wxMenu;
185 
186  // User grid size
187  AddMenuItem( dimensions_Submenu, ID_PCB_USER_GRID_SETUP,
188  _( "&User Grid Size" ), _( "Adjust user grid" ),
189  KiBitmap( grid_xpm ) );
190 
191  // Sizes and Widths
192  AddMenuItem( dimensions_Submenu, ID_PCB_DRAWINGS_WIDTHS_SETUP,
193  _( "&Size and Width" ),
194  _( "Adjust width for texts and drawings" ),
195  KiBitmap( options_text_xpm ) );
196 
197  // Pad settings
198  AddMenuItem( dimensions_Submenu, ID_MODEDIT_PAD_SETTINGS,
199  _( "&Pad Setting" ), _( "Edit settings for new pads" ),
200  KiBitmap( pad_dimensions_xpm ) );
201 
202  //--------- View menu ----------------
203  wxMenu* viewMenu = new wxMenu;
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( _( "&Fit on Screen" ), m_hotkeysDescrList,
225  HK_ZOOM_AUTO );
226  AddMenuItem( viewMenu, ID_ZOOM_PAGE, text, HELP_ZOOM_FIT,
227  KiBitmap( zoom_fit_in_page_xpm ) );
228 
229  text = AddHotkeyName( _( "&Redraw" ), m_hotkeysDescrList, HK_ZOOM_REDRAW );
230  AddMenuItem( viewMenu, ID_ZOOM_REDRAW, text,
231  HELP_ZOOM_REDRAW, KiBitmap( zoom_redraw_xpm ) );
232 
233  viewMenu->AppendSeparator();
234 
235  // 3D view
236  text = AddHotkeyName( _( "&3D Viewer" ), m_hotkeysDescrList, HK_3D_VIEWER );
237  AddMenuItem( viewMenu, ID_MENU_PCB_SHOW_3D_FRAME, text, _( "Show footprint in 3D viewer" ),
238  KiBitmap( three_d_xpm ) );
239 
240  // Add canvas selection
241  viewMenu->AppendSeparator();
242 
243  text = AddHotkeyName( _( "Legacy Canva&s" ), m_hotkeysDescrList,
245 
246  viewMenu->Append(
247  new wxMenuItem( viewMenu, ID_MENU_CANVAS_LEGACY,
248  text, _( "Switch the canvas implementation to Legacy" ),
249  wxITEM_RADIO ) );
250 
251  text = AddHotkeyName( _( "Open&GL Canvas" ), m_hotkeysDescrList,
253 
254  viewMenu->Append(
255  new wxMenuItem( viewMenu, ID_MENU_CANVAS_OPENGL,
256  text, _( "Switch the canvas implementation to OpenGL" ),
257  wxITEM_RADIO ) );
258 
259  text = AddHotkeyName( _( "&Cairo Canvas" ), m_hotkeysDescrList,
260  HK_CANVAS_CAIRO );
261 
262  viewMenu->Append(
263  new wxMenuItem( viewMenu, ID_MENU_CANVAS_CAIRO,
264  text, _( "Switch the canvas implementation to Cairo" ),
265  wxITEM_RADIO ) );
266 
267  //-------- Place menu --------------------
268  wxMenu* placeMenu = new wxMenu;
269 
270  // Pad
271  AddMenuItem( placeMenu, ID_MODEDIT_PAD_TOOL,
272  _( "&Pad" ), _( "Add pad" ),
273  KiBitmap( pad_xpm ) );
274 
275  placeMenu->AppendSeparator();
276 
277  // Circle
279  _( "&Circle" ), _( "Add graphic circle" ),
280  KiBitmap( add_circle_xpm ) );
281 
282  // Line or Polygon
283  AddMenuItem( placeMenu, ID_MODEDIT_LINE_TOOL,
284  _( "&Line or Polygon" ),
285  _( "Add graphic line or polygon" ),
286  KiBitmap( add_polygon_xpm ) );
287 
288  // Arc
289  AddMenuItem( placeMenu, ID_MODEDIT_ARC_TOOL,
290  _( "&Arc" ), _( "Add graphic arc" ),
291  KiBitmap( add_arc_xpm ) );
292 
293  // Text
294  AddMenuItem( placeMenu, ID_MODEDIT_TEXT_TOOL,
295  _( "&Text" ), _( "Add graphic text" ),
296  KiBitmap( add_text_xpm ) );
297 
298  placeMenu->AppendSeparator();
299 
300  // Anchor
302  _( "A&nchor" ),
303  _( "Place footprint reference anchor" ),
304  KiBitmap( anchor_xpm ) );
305 
306 
307  //----- Preferences menu -----------------
308  wxMenu* prefs_menu = new wxMenu;
309 
310  AddMenuItem( prefs_menu, ID_PCB_LIB_WIZARD,
311  _( "&Footprint Libraries Wizard" ), _( "Add footprint libraries with wizard" ),
312  KiBitmap( wizard_add_fplib_small_xpm ) );
313 
314  AddMenuItem( prefs_menu, ID_PCB_LIB_TABLE_EDIT,
315  _( "Footprint Li&braries Manager" ), _( "Configure footprint libraries" ),
316  KiBitmap( library_table_xpm ) );
317 
318  // Path configuration edit dialog.
319  AddMenuItem( prefs_menu,
321  _( "Configure Pa&ths" ),
322  _( "Edit path configuration environment variables" ),
323  KiBitmap( editor_xpm ) );
324 
325  // Settings
326  AddMenuItem( prefs_menu, wxID_PREFERENCES,
327  _( "&Settings" ), _( "Change the footprint editor settings." ),
328  KiBitmap( preference_xpm ) );
329 
331  _( "&Display" ),
332  _( "Change footprint editor display settings" ),
333  KiBitmap( display_options_xpm ) );
334 
335  // Language submenu
336  Pgm().AddMenuLanguageList( prefs_menu );
337 
338  // Hotkey submenu
339  AddHotkeyConfigMenu( prefs_menu );
340 
341  //----- Help menu --------------------
342  wxMenu* helpMenu = new wxMenu;
343 
344  // Contents
345  AddMenuItem( helpMenu, wxID_HELP,
346  _( "Pcbnew &Manual" ),
347  _( "Open the Pcbnew Manual" ),
348  KiBitmap( online_help_xpm ) );
349 
350  AddMenuItem( helpMenu, wxID_INDEX,
351  _( "&Getting Started in KiCad" ),
352  _( "Open the \"Getting Started in KiCad\" guide for beginners" ),
353  KiBitmap( help_xpm ) );
354 
356  _( "&List Hotkeys" ),
357  _( "Displays the current hotkeys list and corresponding commands" ),
358  KiBitmap( hotkeys_xpm ) );
359 
360  helpMenu->AppendSeparator();
361 
363  _( "Get &Involved" ),
364  _( "Contribute to KiCad (opens a web browser)" ),
365  KiBitmap( info_xpm ) );
366 
367  // About Pcbnew
368  helpMenu->AppendSeparator();
369  AddMenuItem( helpMenu, wxID_ABOUT,
370  _( "&About KiCad" ),
371  _( "About KiCad" ),
372  KiBitmap( info_xpm ) );
373 
374  // Append menus to the menubar
375  menuBar->Append( fileMenu, _( "&File" ) );
376  menuBar->Append( editMenu, _( "&Edit" ) );
377  menuBar->Append( viewMenu, _( "&View" ) );
378  menuBar->Append( placeMenu, _( "&Place" ) );
379  menuBar->Append( prefs_menu, _( "P&references" ) );
380  menuBar->Append( dimensions_Submenu, _( "Di&mensions" ) );
381  menuBar->Append( helpMenu, _( "&Help" ) );
382 
383  menuBar->Thaw();
384 
385  // Associate the menu bar with the frame, if no previous menubar
386  if( GetMenuBar() == NULL )
387  SetMenuBar( menuBar );
388  else
389  menuBar->Refresh();
390 }
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:76
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:816
strings common to toolbars and menubar