KiCad PCB EDA Suite
gerbview/menubar.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) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2009 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 1992-2018 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 
32 #include <kiface_i.h>
33 #include <pgm_base.h>
34 
35 #include "gerbview_frame.h"
36 #include "gerbview_id.h"
37 #include "hotkeys.h"
38 #include <menus_helpers.h>
39 
40 
42 {
43  // wxWidgets handles the Mac Application menu behind the scenes, but that means
44  // we always have to start from scratch with a new wxMenuBar.
45  wxMenuBar* oldMenuBar = GetMenuBar();
46  wxMenuBar* menuBar = new wxMenuBar();
47  wxString text;
48 
49  // Recreate all menus:
50 
51  // Menu File:
52  wxMenu* fileMenu = new wxMenu;
53 
54  // Open Gerber file(s)
55  AddMenuItem( fileMenu, wxID_FILE,
56  _( "Open &Gerber File(s)..." ),
57  _( "Open Gerber file(s) on the current layer. Previous data will be deleted" ),
58  KiBitmap( load_gerber_xpm ) );
59 
60  // Open Excellon drill file(s)
62  _( "Open &Excellon Drill File(s)..." ),
63  _( "Open Excellon drill file(s) on the current layer. Previous data will be deleted" ),
64  KiBitmap( gerbview_drill_file_xpm ) );
65 
66  // Open Gerber job files
68  _( "Open Gerber &Job File..." ),
69  _( "Open a Gerber job file, and it's associated gerber files depending on the job" ),
70  KiBitmap( gerber_job_file_xpm ) );
71 
72  // Open Zip archive files
74  _( "Open &Zip Archive File..." ),
75  _( "Open a zipped archive (Gerber and Drill) file" ),
76  KiBitmap( zip_xpm ) );
77 
78  // Recent gerber files
79  static wxMenu* openRecentGbrMenu;
80 
81  // Add this menu to list menu managed by m_fileHistory
82  // (the file history will be updated when adding/removing files in history
83  if( openRecentGbrMenu )
84  Kiface().GetFileHistory().RemoveMenu( openRecentGbrMenu );
85 
86  openRecentGbrMenu = new wxMenu();
87 
88  Kiface().GetFileHistory().UseMenu( openRecentGbrMenu );
89  Kiface().GetFileHistory().AddFilesToMenu();
90 
91  AddMenuItem( fileMenu, openRecentGbrMenu, wxID_ANY,
92  _( "Open &Recent Gerber File" ),
93  _( "Open a recently opened Gerber file" ),
94  KiBitmap( recent_xpm ) );
95 
96  // Recent drill files
97  static wxMenu* openRecentDrlMenu;
98 
99  if( openRecentDrlMenu )
100  m_drillFileHistory.RemoveMenu( openRecentDrlMenu );
101 
102  openRecentDrlMenu = new wxMenu();
103  m_drillFileHistory.UseMenu( openRecentDrlMenu );
104  m_drillFileHistory.AddFilesToMenu( );
105  AddMenuItem( fileMenu, openRecentDrlMenu, wxID_ANY,
106  _( "Open Recent Excellon Dri&ll File" ),
107  _( "Open a recently opened Excellon drill file" ),
108  KiBitmap( recent_xpm ) );
109 
110  // Recent job files
111  static wxMenu* openRecentJobFilesMenu;
112 
113  if( openRecentJobFilesMenu )
114  m_jobFileHistory.RemoveMenu( openRecentJobFilesMenu );
115 
116  openRecentJobFilesMenu = new wxMenu();
117  m_jobFileHistory.UseMenu( openRecentJobFilesMenu );
118  m_jobFileHistory.AddFilesToMenu( );
119  AddMenuItem( fileMenu, openRecentJobFilesMenu, wxID_ANY,
120  _( "Open Recent Gerber &Job File" ),
121  _( "Open a recently opened gerber job file" ),
122  KiBitmap( recent_xpm ) );
123 
124  // Recent Zip archive
125  static wxMenu* openRecentZipArchiveMenu;
126 
127  if( openRecentZipArchiveMenu )
128  m_zipFileHistory.RemoveMenu( openRecentZipArchiveMenu );
129 
130  openRecentZipArchiveMenu = new wxMenu();
131  m_zipFileHistory.UseMenu( openRecentZipArchiveMenu );
132  m_zipFileHistory.AddFilesToMenu( );
133  AddMenuItem( fileMenu, openRecentZipArchiveMenu, wxID_ANY,
134  _( "Open Recent Zip &Archive File" ),
135  _( "Open a recently opened zip archive file" ),
136  KiBitmap( recent_xpm ) );
137 
138  // Separator
139  fileMenu->AppendSeparator();
140 
141  // Clear all
142  AddMenuItem( fileMenu,
144  _( "Clear &All Layers" ),
145  _( "Clear all layers. All data will be deleted" ),
146  KiBitmap( delete_gerber_xpm ) );
147 
148  // Separator
149  fileMenu->AppendSeparator();
150 
151  // Export to Pcbnew
152  AddMenuItem( fileMenu,
154  _( "E&xport to Pcbnew..." ),
155  _( "Export data in Pcbnew format" ),
156  KiBitmap( export_xpm ) );
157 
158  // Separator
159  fileMenu->AppendSeparator();
160 
161  // Print
162  AddMenuItem( fileMenu, wxID_PRINT,
163  _( "&Print..." ), _( "Print layers" ),
164  KiBitmap( print_button_xpm ) );
165 
166  // Separator
167  fileMenu->AppendSeparator();
168 
169  // Exit
170  AddMenuItem( fileMenu, wxID_EXIT,
171  _( "&Close" ), _( "Close GerbView" ),
172  KiBitmap( exit_xpm ) );
173 
174  //--------- View menu ----------------
175  wxMenu* viewMenu = new wxMenu;
176 
177  // Hide layer manager
179  _( "Show &Layers Manager" ), _( "Show or hide the layer manager" ),
180  KiBitmap( layers_manager_xpm ), wxITEM_CHECK );
181 
182  viewMenu->AppendSeparator();
183 
184  /* Important Note for ZOOM IN and ZOOM OUT commands from menubar:
185  * we cannot add hotkey info here, because the hotkey HK_ZOOM_IN and HK_ZOOM_OUT
186  * events(default = WXK_F1 and WXK_F2) are *NOT* equivalent to this menu command:
187  * zoom in and out from hotkeys are equivalent to the pop up menu zoom
188  * From here, zooming is made around the screen center
189  * From hotkeys, zooming is made around the mouse cursor position
190  * (obviously not possible from the toolbar or menubar command)
191  *
192  * in other words HK_ZOOM_IN and HK_ZOOM_OUT *are NOT* accelerators
193  * for Zoom in and Zoom out sub menus
194  */
195  text = AddHotkeyName( _( "Zoom &In" ), GerbviewHokeysDescr,
197  AddMenuItem( viewMenu, ID_ZOOM_IN, text, _( "Zoom in" ), KiBitmap( zoom_in_xpm ) );
198 
199  text = AddHotkeyName( _( "Zoom &Out" ), GerbviewHokeysDescr,
201  AddMenuItem( viewMenu, ID_ZOOM_OUT, text, _( "Zoom out" ), KiBitmap( zoom_out_xpm ) );
202 
203  text = AddHotkeyName( _( "Zoom to &Fit" ), GerbviewHokeysDescr, HK_ZOOM_AUTO );
204  AddMenuItem( viewMenu, ID_ZOOM_PAGE, text, _( "Zoom to fit" ),
205  KiBitmap( zoom_fit_in_page_xpm ) );
206 
207  text = AddHotkeyName( _( "Zoom to Selection" ), GerbviewHokeysDescr, HK_ZOOM_SELECTION );
208  AddMenuItem( viewMenu, ID_ZOOM_SELECTION, text, KiBitmap( zoom_area_xpm ), wxITEM_CHECK );
209 
210  text = AddHotkeyName( _( "&Redraw" ), GerbviewHokeysDescr, HK_ZOOM_REDRAW );
211  AddMenuItem( viewMenu, ID_ZOOM_REDRAW, text,
212  _( "Refresh screen" ), KiBitmap( zoom_redraw_xpm ) );
213 
214  viewMenu->AppendSeparator();
215 
217  _( "Show &Grid" ), wxEmptyString,
218  KiBitmap( grid_xpm ), wxITEM_CHECK );
219 
221  _( "Display &Polar Coordinates" ), wxEmptyString,
222  KiBitmap( polar_coord_xpm ), wxITEM_CHECK );
223 
224  // Units submenu
225  wxMenu* unitsSubMenu = new wxMenu;
227  _( "&Imperial" ), _( "Use imperial units" ),
228  KiBitmap( unit_inch_xpm ), wxITEM_RADIO );
229 
231  _( "&Metric" ), _( "Use metric units" ),
232  KiBitmap( unit_mm_xpm ), wxITEM_RADIO );
233 
234  AddMenuItem( viewMenu, unitsSubMenu,
235  -1, _( "&Units" ),
236  _( "Select which units are displayed" ),
237  KiBitmap( unit_mm_xpm ) );
238 
239  viewMenu->AppendSeparator();
240 
242  _( "Sketch F&lashed Items" ),_( "Show flashed items in outline mode" ),
243  KiBitmap( pad_sketch_xpm ), wxITEM_CHECK );
244 
246  _( "Sketch &Lines" ),_( "Show lines in outline mode" ),
247  KiBitmap( showtrack_xpm ), wxITEM_CHECK );
248 
250  _( "Sketch Pol&ygons" ),_( "Show polygons in outline mode" ),
251  KiBitmap( opt_show_polygon_xpm ), wxITEM_CHECK );
252 
254  _( "Show &DCodes" ), _( "Show or hide DCodes" ),
255  KiBitmap( show_dcodenumber_xpm ), wxITEM_CHECK );
256 
258  _( "Show &Negative Objects" ), _( "Show negative objects in ghost color" ),
259  KiBitmap( gerbview_show_negative_objects_xpm ), wxITEM_CHECK );
260 
261  if( IsGalCanvasActive() )
262  {
264  _( "Show in Differential Mode" ), _( "Show layers in differential mode" ),
265  KiBitmap( gbr_select_mode2_xpm ), wxITEM_CHECK );
266 
268  _( "Show in High Contrast" ), _( "Show in high contrast mode" ),
269  KiBitmap( contrast_mode_xpm ), wxITEM_CHECK );
270  }
271  else
272  {
274  _( "Show Normal Mode" ), _( "Show layers in normal mode" ),
275  KiBitmap( gbr_select_mode0_xpm ), wxITEM_RADIO );
277  _( "Show Stacked Mode" ), _( "Show layers in stacked mode" ),
278  KiBitmap( gbr_select_mode1_xpm ), wxITEM_RADIO );
280  _( "Show Transparency Mode" ), _( "Show layers in transparency mode" ),
281  KiBitmap( gbr_select_mode2_xpm ), wxITEM_RADIO );
282  }
283 
284  // Menu for configuration and preferences
285  wxMenu* configMenu = new wxMenu;
286 
287  // Options (Preferences on WXMAC)
288 #ifdef __WXMAC__
289  configMenu->Append(wxID_PREFERENCES);
290 #else
291  AddMenuItem( configMenu, wxID_PREFERENCES,
292  _( "&Options" ),
293  _( "Set options to draw items" ),
294  KiBitmap( preference_xpm ) );
295 #endif // __WXMAC__
296 
297  // Language submenu
298  Pgm().AddMenuLanguageList( configMenu );
299 
300  // Icons options submenu
301  AddMenuIconsOptions( configMenu );
302 
303  // Hotkey submenu
304  AddHotkeyConfigMenu( configMenu );
305 
306  // Canvas selection
307  configMenu->AppendSeparator();
308 
309  text = AddHotkeyName( _( "Legacy Tool&set" ), GerbviewHokeysDescr,
311  AddMenuItem( configMenu, ID_MENU_CANVAS_LEGACY,
312  text, _( "Use Legacy Toolset (not all features will be available)" ),
313  KiBitmap( tools_xpm ), wxITEM_RADIO );
314 
315  text = AddHotkeyName( _( "Modern Toolset (&Accelerated)" ), GerbviewHokeysDescr,
317  AddMenuItem( configMenu, ID_MENU_CANVAS_OPENGL, text,
318  _( "Use Modern Toolset with hardware-accelerated graphics (recommended)" ),
319  KiBitmap( tools_xpm ), wxITEM_RADIO );
320 
321  text = AddHotkeyName( _( "Modern Toolset (Fallba&ck)" ), GerbviewHokeysDescr,
322  HK_CANVAS_CAIRO );
323  AddMenuItem( configMenu, ID_MENU_CANVAS_CAIRO, text,
324  _( "Use Modern Toolset with software graphics (fall-back)" ),
325  KiBitmap( tools_xpm ), wxITEM_RADIO );
326 
327  // Menu miscellaneous
328  wxMenu* miscellaneousMenu = new wxMenu;
329 
330  // List dcodes
331  AddMenuItem( miscellaneousMenu, ID_GERBVIEW_SHOW_LIST_DCODES,
332  _( "&List DCodes" ),
333  _( "List D-codes defined in Gerber files" ),
334  KiBitmap( show_dcodenumber_xpm ) );
335 
336  // Show source
337  AddMenuItem( miscellaneousMenu, ID_GERBVIEW_SHOW_SOURCE,
338  _( "&Show Source" ),
339  _( "Show source file for the current layer" ),
340  KiBitmap( tools_xpm ) );
341 
342  // Separator
343  miscellaneousMenu->AppendSeparator();
344 
345  // Erase graphic layer
346  AddMenuItem( miscellaneousMenu, ID_GERBVIEW_ERASE_CURR_LAYER,
347  _( "&Clear Current Layer" ),
348  _( "Clear the graphic layer currently selected" ),
349  KiBitmap( delete_sheet_xpm ) );
350 
351  // Separator
352  miscellaneousMenu->AppendSeparator();
353 
354  // Text editor (usefull to browse source files)
356  _( "Set &Text Editor..." ),
357  _( "Select your preferred text editor" ),
358  KiBitmap( editor_xpm ) );
359 
360  // Help menu
361  wxMenu* helpMenu = new wxMenu;
362 
363  AddMenuItem( helpMenu, wxID_HELP,
364  _( "Gerbview &Manual" ),
365  _( "Open the GerbView Manual" ),
366  KiBitmap( online_help_xpm ) );
367 
368  text = AddHotkeyName( _( "&List Hotkeys..." ), GerbviewHokeysDescr, HK_HELP );
370  text,
371  _( "Displays the current hotkeys list and corresponding commands" ),
372  KiBitmap( hotkeys_xpm ) );
373 
374  // Separator
375  helpMenu->AppendSeparator();
376 
377  // Get involved with KiCad
379  _( "Get &Involved" ),
380  _( "Contribute to KiCad (opens a web browser)" ),
381  KiBitmap( info_xpm ) );
382 
383  helpMenu->AppendSeparator();
384 
385  // About Kicad
386  AddMenuItem( helpMenu, wxID_ABOUT,
387  _( "&About KiCad" ), _( "About KiCad" ),
388  KiBitmap( about_xpm ) );
389 
390  // Append menus to the menubar
391  menuBar->Append( fileMenu, _( "&File" ) );
392  menuBar->Append( viewMenu, _( "&View" ) );
393  menuBar->Append( configMenu, _( "&Preferences" ) );
394  menuBar->Append( miscellaneousMenu, _( "&Miscellaneous" ) );
395  menuBar->Append( helpMenu, _( "&Help" ) );
396 
397  // Associate the menu bar with the frame, if no previous menubar
398  SetMenuBar( menuBar );
399  delete oldMenuBar;
400 }
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:174
GERBVIEW_FRAME::OnZipFileHistory GERBVIEW_FRAME::Process_Config GERBVIEW_FRAME::OnSelectActiveLayer GERBVIEW_FRAME::OnToggleShowLayerManager GERBVIEW_FRAME::OnSelectHighlightChoice GERBVIEW_FRAME::OnUpdateShowLayerManager ID_TB_OPTIONS_SHOW_GBR_MODE_2
Definition: id.h:242
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
wxFileHistory m_drillFileHistory
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
EDA_DRAW_FRAME::OnSelectGrid ID_TB_OPTIONS_SELECT_UNIT_INCH
Definition: draw_frame.cpp:123
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
wxFileHistory & GetFileHistory()
Definition: kiface_i.h:123
wxFileHistory m_jobFileHistory
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:887
wxFileHistory m_zipFileHistory
void AddHotkeyConfigMenu(wxMenu *aMenu)
void AddMenuIconsOptions(wxMenu *MasterMenu)
Function AddMenuIconsOptions creates a menu list for icons in menu and icon sizes choice...
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
struct EDA_HOTKEY_CONFIG GerbviewHokeysDescr[]
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:831
void ReCreateMenuBar() override
Function ReCreateMenuBar Creates recreates the menu bar.