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-2013 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2017 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  // Create and try to get the current menubar
44  wxMenuBar* menuBar = GetMenuBar();
45  wxString text;
46 
47  if( !menuBar )
48  menuBar = new wxMenuBar();
49 
50  // Delete all existing menus so they can be rebuilt.
51  // This allows language changes of the menu text on the fly.
52  menuBar->Freeze();
53 
54  while( menuBar->GetMenuCount() )
55  delete menuBar->Remove( 0 );
56 
57  // Recreate all menus:
58 
59  // Menu File:
60  wxMenu* fileMenu = new wxMenu;
61 
62  // Load Gerber files
63  AddMenuItem( fileMenu, wxID_FILE,
64  _( "Load &Gerber File" ),
65  _( "Load a new Gerber file on the current layer. Previous data will be deleted" ),
66  KiBitmap( gerber_file_xpm ) );
67 
68  // Load Excellon drill files
70  _( "Load &EXCELLON Drill File" ),
71  _( "Load excellon drill file" ),
72  KiBitmap( gerbview_drill_file_xpm ) );
73 
74  // Load Gerber job files
76  _( "Load Gerber &Job File" ),
77  _( "Load a Gerber job file, and load gerber files depending on the job" ),
78  KiBitmap( gerber_job_file_xpm ) );
79 
80  // Load Zip archive files
82  _( "Load &Zip Archive File" ),
83  _( "Load a zipped archive (Gerber and drill) file" ),
84  KiBitmap( zip_xpm ) );
85 
86  // Recent gerber files
87  static wxMenu* openRecentGbrMenu;
88 
89  // Add this menu to list menu managed by m_fileHistory
90  // (the file history will be updated when adding/removing files in history
91  if( openRecentGbrMenu )
92  Kiface().GetFileHistory().RemoveMenu( openRecentGbrMenu );
93 
94  openRecentGbrMenu = new wxMenu();
95 
96  Kiface().GetFileHistory().UseMenu( openRecentGbrMenu );
97  Kiface().GetFileHistory().AddFilesToMenu();
98 
99  AddMenuItem( fileMenu, openRecentGbrMenu, wxID_ANY,
100  _( "Open &Recent Gerber File" ),
101  _( "Open a recent opened Gerber file" ),
102  KiBitmap( recent_xpm ) );
103 
104  // Recent drill files
105  static wxMenu* openRecentDrlMenu;
106 
107  if( openRecentDrlMenu )
108  m_drillFileHistory.RemoveMenu( openRecentDrlMenu );
109 
110  openRecentDrlMenu = new wxMenu();
111  m_drillFileHistory.UseMenu( openRecentDrlMenu );
112  m_drillFileHistory.AddFilesToMenu( );
113  AddMenuItem( fileMenu, openRecentDrlMenu, wxID_ANY,
114  _( "Open Recent Dri&ll File" ),
115  _( "Open a recent opened drill file" ),
116  KiBitmap( recent_xpm ) );
117 
118  // Recent drill files
119  static wxMenu* openRecentZipArchiveMenu;
120 
121  if( openRecentZipArchiveMenu )
122  m_zipFileHistory.RemoveMenu( openRecentZipArchiveMenu );
123 
124  openRecentZipArchiveMenu = new wxMenu();
125  m_zipFileHistory.UseMenu( openRecentZipArchiveMenu );
126  m_zipFileHistory.AddFilesToMenu( );
127  AddMenuItem( fileMenu, openRecentZipArchiveMenu, wxID_ANY,
128  _( "Open Recent Zip &Archive File" ),
129  _( "Open a recent opened zip archive file" ),
130  KiBitmap( recent_xpm ) );
131 
132  // Recent job files
133  static wxMenu* openRecentJobFilesMenu;
134 
135  if( openRecentJobFilesMenu )
136  m_jobFileHistory.RemoveMenu( openRecentJobFilesMenu );
137 
138  openRecentJobFilesMenu = new wxMenu();
139  m_jobFileHistory.UseMenu( openRecentJobFilesMenu );
140  m_jobFileHistory.AddFilesToMenu( );
141  AddMenuItem( fileMenu, openRecentJobFilesMenu, wxID_ANY,
142  _( "Open Recent &Job File" ),
143  _( "Open a recent opened gerber job file" ),
144  KiBitmap( recent_xpm ) );
145 
146  // Separator
147  fileMenu->AppendSeparator();
148 
149  // Clear all
150  AddMenuItem( fileMenu,
152  _( "Clear &All" ),
153  _( "Clear all layers. All data will be deleted" ),
154  KiBitmap( gerbview_clear_layers_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 gerber" ),
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  // Menu for configuration and preferences
183  wxMenu* configMenu = new wxMenu;
184 
185  // Hide layer manager
187  _( "Hide &Layers Manager" ),
189  _( "Hide &Layers Manager" ) : _("Show &Layers Manager" ),
190  KiBitmap( layers_manager_xpm ) );
191 
192  // Options (Preferences on WXMAC)
193 #ifdef __WXMAC__
194  configMenu->Append(wxID_PREFERENCES);
195 #else
196  AddMenuItem( configMenu, wxID_PREFERENCES,
197  _( "&Options" ),
198  _( "Set options to draw items" ),
199  KiBitmap( preference_xpm ) );
200 #endif // __WXMAC__
201 
202  // Language submenu
203  Pgm().AddMenuLanguageList( configMenu );
204 
205  // Icons options submenu
206  AddMenuIconsOptions( configMenu );
207 
208  // Hotkey submenu
209  AddHotkeyConfigMenu( configMenu );
210 
211  // Canvas selection
212  configMenu->AppendSeparator();
213 
214  text = AddHotkeyName( _( "Legacy Canva&s" ), GerbviewHokeysDescr,
216 
217  configMenu->Append(
218  new wxMenuItem( configMenu, ID_MENU_CANVAS_LEGACY,
219  text, _( "Switch the canvas implementation to Legacy" ),
220  wxITEM_RADIO ) );
221 
222  text = AddHotkeyName( _( "Open&GL Canvas" ), GerbviewHokeysDescr,
224 
225  configMenu->Append(
226  new wxMenuItem( configMenu, ID_MENU_CANVAS_OPENGL,
227  text, _( "Switch the canvas implementation to OpenGL" ),
228  wxITEM_RADIO ) );
229 
230  text = AddHotkeyName( _( "&Cairo Canvas" ), GerbviewHokeysDescr,
231  HK_CANVAS_CAIRO );
232 
233  configMenu->Append(
234  new wxMenuItem( configMenu, ID_MENU_CANVAS_CAIRO,
235  text, _( "Switch the canvas implementation to Cairo" ),
236  wxITEM_RADIO ) );
237 
238  // Menu miscellaneous
239  wxMenu* miscellaneousMenu = new wxMenu;
240 
241  // List dcodes
242  AddMenuItem( miscellaneousMenu, ID_GERBVIEW_SHOW_LIST_DCODES,
243  _( "&List DCodes" ),
244  _( "List D-codes defined in Gerber files" ),
245  KiBitmap( show_dcodenumber_xpm ) );
246 
247  // Show source
248  AddMenuItem( miscellaneousMenu, ID_GERBVIEW_SHOW_SOURCE,
249  _( "&Show Source" ),
250  _( "Show source file for the current layer" ),
251  KiBitmap( tools_xpm ) );
252 
253  // Separator
254  miscellaneousMenu->AppendSeparator();
255 
256  // Erase graphic layer
257  AddMenuItem( miscellaneousMenu, ID_GERBVIEW_ERASE_CURR_LAYER,
258  _( "&Clear Current Layer" ),
259  _( "Erase the graphic layer currently selected" ),
260  KiBitmap( delete_sheet_xpm ) );
261 
262  // Separator
263  miscellaneousMenu->AppendSeparator();
264 
265  // Text editor (usefull to browse source files)
267  _( "&Text Editor" ),
268  _( "Select your preferred text editor" ),
269  KiBitmap( editor_xpm ) );
270 
271  // Help menu
272  wxMenu* helpMenu = new wxMenu;
273 
274  AddMenuItem( helpMenu, wxID_HELP,
275  _( "Gerbview &Manual" ),
276  _( "Open the GerbView Manual" ),
277  KiBitmap( online_help_xpm ) );
278 
280  _( "&List Hotkeys" ),
281  _( "Displays the current hotkeys list and corresponding commands" ),
282  KiBitmap( hotkeys_xpm ) );
283 
284  // Separator
285  helpMenu->AppendSeparator();
286 
287  // Get involved with KiCad
289  _( "Get &Involved" ),
290  _( "Contribute to KiCad (opens a web browser)" ),
291  KiBitmap( info_xpm ) );
292 
293  helpMenu->AppendSeparator();
294 
295  // About Kicad
296  AddMenuItem( helpMenu, wxID_ABOUT,
297  _( "&About Kicad" ), _( "About KiCad" ),
298  KiBitmap( about_xpm ) );
299 
300  // Append menus to the menubar
301  menuBar->Append( fileMenu, _( "&File" ) );
302  menuBar->Append( configMenu, _( "&Preferences" ) );
303  menuBar->Append( miscellaneousMenu, _( "&Miscellaneous" ) );
304  menuBar->Append( helpMenu, _( "&Help" ) );
305 
306  menuBar->Thaw();
307 
308  // Associate the menu bar with the frame, if no previous menubar
309  if( GetMenuBar() == NULL )
310  SetMenuBar( menuBar );
311  else
312  menuBar->Refresh();
313 }
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
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
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
wxFileHistory & GetFileHistory()
Definition: kiface_i.h:123
wxFileHistory m_jobFileHistory
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...
Definition: basicframe.cpp:692
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:824
bool m_show_layer_manager_tools
void ReCreateMenuBar() override
Function ReCreateMenuBar Creates recreates the menu bar.