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