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  // Reload all
149  AddMenuItem( fileMenu,
151  _( "Reload All Layers" ),
152  _( "Reload all layers. All data will be reloaded" ),
153  KiBitmap( reload2_xpm ) );
154 
155  // Separator
156  fileMenu->AppendSeparator();
157 
158  // Export to Pcbnew
159  AddMenuItem( fileMenu,
161  _( "E&xport to Pcbnew..." ),
162  _( "Export data in Pcbnew format" ),
163  KiBitmap( export_xpm ) );
164 
165  // Separator
166  fileMenu->AppendSeparator();
167 
168  // Print
169  AddMenuItem( fileMenu, wxID_PRINT,
170  _( "&Print..." ), _( "Print layers" ),
171  KiBitmap( print_button_xpm ) );
172 
173  // Separator
174  fileMenu->AppendSeparator();
175 
176  // Exit
177  AddMenuItem( fileMenu, wxID_EXIT,
178  _( "&Close" ), _( "Close GerbView" ),
179  KiBitmap( exit_xpm ) );
180 
181  //--------- View menu ----------------
182  wxMenu* viewMenu = new wxMenu;
183 
184  // Hide layer manager
186  _( "Show &Layers Manager" ), _( "Show or hide the layer manager" ),
187  KiBitmap( layers_manager_xpm ), wxITEM_CHECK );
188 
189  viewMenu->AppendSeparator();
190 
191  /* Important Note for ZOOM IN and ZOOM OUT commands from menubar:
192  * we cannot add hotkey info here, because the hotkey HK_ZOOM_IN and HK_ZOOM_OUT
193  * events(default = WXK_F1 and WXK_F2) are *NOT* equivalent to this menu command:
194  * zoom in and out from hotkeys are equivalent to the pop up menu zoom
195  * From here, zooming is made around the screen center
196  * From hotkeys, zooming is made around the mouse cursor position
197  * (obviously not possible from the toolbar or menubar command)
198  *
199  * in other words HK_ZOOM_IN and HK_ZOOM_OUT *are NOT* accelerators
200  * for Zoom in and Zoom out sub menus
201  */
202  text = AddHotkeyName( _( "Zoom &In" ), GerbviewHokeysDescr,
204  AddMenuItem( viewMenu, ID_ZOOM_IN, text, _( "Zoom in" ), KiBitmap( zoom_in_xpm ) );
205 
206  text = AddHotkeyName( _( "Zoom &Out" ), GerbviewHokeysDescr,
208  AddMenuItem( viewMenu, ID_ZOOM_OUT, text, _( "Zoom out" ), KiBitmap( zoom_out_xpm ) );
209 
210  text = AddHotkeyName( _( "Zoom to &Fit" ), GerbviewHokeysDescr, HK_ZOOM_AUTO );
211  AddMenuItem( viewMenu, ID_ZOOM_PAGE, text, _( "Zoom to fit" ),
212  KiBitmap( zoom_fit_in_page_xpm ) );
213 
214  text = AddHotkeyName( _( "Zoom to Selection" ), GerbviewHokeysDescr, HK_ZOOM_SELECTION );
215  AddMenuItem( viewMenu, ID_ZOOM_SELECTION, text, KiBitmap( zoom_area_xpm ), wxITEM_CHECK );
216 
217  text = AddHotkeyName( _( "&Redraw" ), GerbviewHokeysDescr, HK_ZOOM_REDRAW );
218  AddMenuItem( viewMenu, ID_ZOOM_REDRAW, text,
219  _( "Refresh screen" ), KiBitmap( zoom_redraw_xpm ) );
220 
221  viewMenu->AppendSeparator();
222 
224  _( "Show &Grid" ), wxEmptyString,
225  KiBitmap( grid_xpm ), wxITEM_CHECK );
226 
228  _( "Display &Polar Coordinates" ), wxEmptyString,
229  KiBitmap( polar_coord_xpm ), wxITEM_CHECK );
230 
231  // Units submenu
232  wxMenu* unitsSubMenu = new wxMenu;
234  _( "&Imperial" ), _( "Use imperial units" ),
235  KiBitmap( unit_inch_xpm ), wxITEM_RADIO );
236 
238  _( "&Metric" ), _( "Use metric units" ),
239  KiBitmap( unit_mm_xpm ), wxITEM_RADIO );
240 
241  AddMenuItem( viewMenu, unitsSubMenu,
242  -1, _( "&Units" ),
243  _( "Select which units are displayed" ),
244  KiBitmap( unit_mm_xpm ) );
245 
246  viewMenu->AppendSeparator();
247 
249  _( "Sketch F&lashed Items" ),_( "Show flashed items in outline mode" ),
250  KiBitmap( pad_sketch_xpm ), wxITEM_CHECK );
251 
253  _( "Sketch &Lines" ),_( "Show lines in outline mode" ),
254  KiBitmap( showtrack_xpm ), wxITEM_CHECK );
255 
257  _( "Sketch Pol&ygons" ),_( "Show polygons in outline mode" ),
258  KiBitmap( opt_show_polygon_xpm ), wxITEM_CHECK );
259 
261  _( "Show &DCodes" ), _( "Show or hide DCodes" ),
262  KiBitmap( show_dcodenumber_xpm ), wxITEM_CHECK );
263 
265  _( "Show &Negative Objects" ), _( "Show negative objects in ghost color" ),
266  KiBitmap( gerbview_show_negative_objects_xpm ), wxITEM_CHECK );
267 
268  if( IsGalCanvasActive() )
269  {
271  _( "Show in Differential Mode" ), _( "Show layers in differential mode" ),
272  KiBitmap( gbr_select_mode2_xpm ), wxITEM_CHECK );
273 
275  _( "Show in High Contrast" ), _( "Show in high contrast mode" ),
276  KiBitmap( contrast_mode_xpm ), wxITEM_CHECK );
277  }
278  else
279  {
281  _( "Show Normal Mode" ), _( "Show layers in normal mode" ),
282  KiBitmap( gbr_select_mode0_xpm ), wxITEM_RADIO );
284  _( "Show Stacked Mode" ), _( "Show layers in stacked mode" ),
285  KiBitmap( gbr_select_mode1_xpm ), wxITEM_RADIO );
287  _( "Show Transparency Mode" ), _( "Show layers in transparency mode" ),
288  KiBitmap( gbr_select_mode2_xpm ), wxITEM_RADIO );
289  }
290 
291  // Menu for configuration and preferences
292  wxMenu* configMenu = new wxMenu;
293 
294  // Options (Preferences on WXMAC)
295  AddMenuItem( configMenu, wxID_PREFERENCES,
296  _( "&Preferences..." ),
297  wxEmptyString,
298  KiBitmap( preference_xpm ) );
299 
300  // Canvas selection
301  configMenu->AppendSeparator();
302 
303  text = AddHotkeyName( _( "Legacy Tool&set" ), GerbviewHokeysDescr, HK_CANVAS_LEGACY );
304  AddMenuItem( configMenu, ID_MENU_CANVAS_LEGACY,
305  text, _( "Use Legacy Toolset (not all features will be available)" ),
306  KiBitmap( tools_xpm ), wxITEM_RADIO );
307 
308  text = AddHotkeyName( _( "Modern Toolset (&Accelerated)" ), GerbviewHokeysDescr, HK_CANVAS_OPENGL );
309  AddMenuItem( configMenu, ID_MENU_CANVAS_OPENGL, text,
310  _( "Use Modern Toolset with hardware-accelerated graphics (recommended)" ),
311  KiBitmap( tools_xpm ), wxITEM_RADIO );
312 
313  text = AddHotkeyName( _( "Modern Toolset (Fallba&ck)" ), GerbviewHokeysDescr, HK_CANVAS_CAIRO );
314  AddMenuItem( configMenu, ID_MENU_CANVAS_CAIRO, text,
315  _( "Use Modern Toolset with software graphics (fall-back)" ),
316  KiBitmap( tools_xpm ), wxITEM_RADIO );
317 
318  configMenu->AppendSeparator();
319 
320  // Language submenu
321  Pgm().AddMenuLanguageList( configMenu );
322 
323  // Menu miscellaneous
324  wxMenu* miscellaneousMenu = new wxMenu;
325 
326  // List dcodes
327  AddMenuItem( miscellaneousMenu, ID_GERBVIEW_SHOW_LIST_DCODES, _( "&List DCodes..." ),
328  _( "List D-codes defined in Gerber files" ),
329  KiBitmap( show_dcodenumber_xpm ) );
330 
331  // Show source
332  AddMenuItem( miscellaneousMenu, ID_GERBVIEW_SHOW_SOURCE, _( "&Show Source..." ),
333  _( "Show source file for the current layer" ),
334  KiBitmap( tools_xpm ) );
335 
336  miscellaneousMenu->AppendSeparator();
337 
338  // Erase graphic layer
339  AddMenuItem( miscellaneousMenu, ID_GERBVIEW_ERASE_CURR_LAYER, _( "&Clear Current Layer..." ),
340  _( "Clear the graphic layer currently selected" ),
341  KiBitmap( delete_sheet_xpm ) );
342 
343  // Help menu
344  wxMenu* helpMenu = new wxMenu;
345 
346  AddMenuItem( helpMenu, wxID_HELP, _( "Gerbview &Manual" ),
347  _( "Open the GerbView Manual" ),
348  KiBitmap( online_help_xpm ) );
349 
350  text = AddHotkeyName( _( "&List Hotkeys..." ), GerbviewHokeysDescr, HK_HELP );
352  _( "Displays the current hotkeys list and corresponding commands" ),
353  KiBitmap( hotkeys_xpm ) );
354 
355  // Separator
356  helpMenu->AppendSeparator();
357 
358  // Get involved with KiCad
359  AddMenuItem( helpMenu, ID_HELP_GET_INVOLVED, _( "Get &Involved" ),
360  _( "Contribute to KiCad (opens a web browser)" ),
361  KiBitmap( info_xpm ) );
362 
363  helpMenu->AppendSeparator();
364 
365  // About Kicad
366  AddMenuItem( helpMenu, wxID_ABOUT, _( "&About KiCad" ), KiBitmap( about_xpm ) );
367 
368  // Append menus to the menubar
369  menuBar->Append( fileMenu, _( "&File" ) );
370  menuBar->Append( viewMenu, _( "&View" ) );
371  menuBar->Append( miscellaneousMenu, _( "&Tools" ) );
372  menuBar->Append( configMenu, _( "&Preferences" ) );
373  menuBar->Append( helpMenu, _( "&Help" ) );
374 
375  // Associate the menu bar with the frame, if no previous menubar
376  SetMenuBar( menuBar );
377  delete oldMenuBar;
378 }
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
FILE_HISTORY m_jobFileHistory
Definition: id.h:241
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
FILE_HISTORY m_zipFileHistory
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
GERBVIEW_FRAME::OnZipFileHistory GERBVIEW_FRAME::OnSelectActiveLayer GERBVIEW_FRAME::OnToggleShowLayerManager GERBVIEW_FRAME::OnSelectHighlightChoice GERBVIEW_FRAME::OnUpdateShowLayerManager ID_TB_OPTIONS_SHOW_GBR_MODE_2
EDA_DRAW_FRAME::OnSelectGrid ID_TB_OPTIONS_SELECT_UNIT_INCH
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:921
FILE_HISTORY m_drillFileHistory
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
FILE_HISTORY & GetFileHistory()
Definition: kiface_i.h:123
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:800
void ReCreateMenuBar() override
Function ReCreateMenuBar Creates recreates the menu bar.