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 
46  if( !menuBar )
47  menuBar = new wxMenuBar();
48 
49  // Delete all existing menus so they can be rebuilt.
50  // This allows language changes of the menu text on the fly.
51  menuBar->Freeze();
52 
53  while( menuBar->GetMenuCount() )
54  delete menuBar->Remove( 0 );
55 
56  // Recreate all menus:
57 
58  // Menu File:
59  wxMenu* fileMenu = new wxMenu;
60 
61  // Load Gerber files
62  AddMenuItem( fileMenu,
63  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
69  AddMenuItem( fileMenu,
71  _( "Load &EXCELLON Drill File" ),
72  _( "Load excellon drill file" ),
73  KiBitmap( gerbview_drill_file_xpm ) );
74 
75  // Load Zip archive files
76  AddMenuItem( fileMenu,
78  _( "Load &Zip Archive File" ),
79  _( "Load a zipped archive (Gerber and drill) file" ),
80  KiBitmap( zip_xpm ) );
81 
82  // Recent gerber files
83  static wxMenu* openRecentGbrMenu;
84 
85  // Add this menu to list menu managed by m_fileHistory
86  // (the file history will be updated when adding/removing files in history
87  if( openRecentGbrMenu )
88  Kiface().GetFileHistory().RemoveMenu( openRecentGbrMenu );
89 
90  openRecentGbrMenu = new wxMenu();
91 
92  Kiface().GetFileHistory().UseMenu( openRecentGbrMenu );
93  Kiface().GetFileHistory().AddFilesToMenu();
94 
95  AddMenuItem( fileMenu, openRecentGbrMenu,
96  wxID_ANY,
97  _( "Open &Recent Gerber File" ),
98  _( "Open a recent opened Gerber file" ),
99  KiBitmap( recent_xpm ) );
100 
101  // Recent drill files
102  static wxMenu* openRecentDrlMenu;
103 
104  if( openRecentDrlMenu )
105  m_drillFileHistory.RemoveMenu( openRecentDrlMenu );
106 
107  openRecentDrlMenu = new wxMenu();
108  m_drillFileHistory.UseMenu( openRecentDrlMenu );
109  m_drillFileHistory.AddFilesToMenu( );
110  AddMenuItem( fileMenu, openRecentDrlMenu,
111  wxID_ANY,
112  _( "Open Recent Dri&ll File" ),
113  _( "Open a recent opened drill file" ),
114  KiBitmap( recent_xpm ) );
115 
116  // Recent drill files
117  static wxMenu* openRecentZipArchiveMenu;
118 
119  if( openRecentZipArchiveMenu )
120  m_zipFileHistory.RemoveMenu( openRecentZipArchiveMenu );
121 
122  openRecentZipArchiveMenu = new wxMenu();
123  m_zipFileHistory.UseMenu( openRecentZipArchiveMenu );
124  m_zipFileHistory.AddFilesToMenu( );
125  AddMenuItem( fileMenu, openRecentZipArchiveMenu,
126  wxID_ANY,
127  _( "Open Recent Zip &Archive File" ),
128  _( "Open a recent opened zip archive file" ),
129  KiBitmap( recent_xpm ) );
130 
131  // Separator
132  fileMenu->AppendSeparator();
133 
134  // Clear all
135  AddMenuItem( fileMenu,
137  _( "Clear &All" ),
138  _( "Clear all layers. All data will be deleted" ),
139  KiBitmap( gerbview_clear_layers_xpm ) );
140 
141  // Separator
142  fileMenu->AppendSeparator();
143 
144  // Export to Pcbnew
145  AddMenuItem( fileMenu,
147  _( "E&xport to Pcbnew" ),
148  _( "Export data in Pcbnew format" ),
149  KiBitmap( export_xpm ) );
150 
151  // Separator
152  fileMenu->AppendSeparator();
153 
154  // Print
155  AddMenuItem( fileMenu,
156  wxID_PRINT,
157  _( "&Print" ),
158  _( "Print gerber" ),
159  KiBitmap( print_button_xpm ) );
160 
161  // Separator
162  fileMenu->AppendSeparator();
163 
164  // Exit
165  AddMenuItem( fileMenu,
166  wxID_EXIT,
167  _( "&Close" ),
168  _( "Close GerbView" ),
169  KiBitmap( exit_xpm ) );
170 
171  // Menu for configuration and preferences
172  wxMenu* configMenu = new wxMenu;
173 
174  // Hide layer manager
175  AddMenuItem( configMenu,
177  _( "Hide &Layers Manager" ),
179  _( "Hide &Layers Manager" ) : _("Show &Layers Manager" ),
180  KiBitmap( layers_manager_xpm ) );
181 
182  // Options (Preferences on WXMAC)
183 
184 #ifdef __WXMAC__
185  configMenu->Append(wxID_PREFERENCES);
186 #else
187  AddMenuItem( configMenu,
188  wxID_PREFERENCES,
189  _( "&Options" ),
190  _( "Set options to draw items" ),
191  KiBitmap( preference_xpm ) );
192 #endif // __WXMAC__
193 
194  // Language submenu
195  Pgm().AddMenuLanguageList( configMenu );
196 
197  // Icons options submenu
198  AddMenuIconsOptions( configMenu );
199 
200  // Hotkey submenu
201  AddHotkeyConfigMenu( configMenu );
202 
203  // Menu miscellaneous
204  wxMenu* miscellaneousMenu = new wxMenu;
205 
206  // List dcodes
207  AddMenuItem( miscellaneousMenu,
209  _( "&List DCodes" ),
210  _( "List D-codes defined in Gerber files" ),
211  KiBitmap( show_dcodenumber_xpm ) );
212 
213  // Show source
214  AddMenuItem( miscellaneousMenu,
216  _( "&Show Source" ),
217  _( "Show source file for the current layer" ),
218  KiBitmap( tools_xpm ) );
219 
220  // Separator
221  miscellaneousMenu->AppendSeparator();
222 
223  // Erase graphic layer
224  AddMenuItem( miscellaneousMenu,
226  _( "&Clear Current Layer" ),
227  _( "Erase the graphic layer currently selected" ),
228  KiBitmap( delete_sheet_xpm ) );
229 
230  // Separator
231  miscellaneousMenu->AppendSeparator();
232 
233  // Text editor (usefull to browse source files)
234  AddMenuItem( miscellaneousMenu,
236  _( "&Text Editor" ),
237  _( "Select your preferred text editor" ),
238  KiBitmap( editor_xpm ) );
239 
240  // Help menu
241  wxMenu* helpMenu = new wxMenu;
242 
243  AddMenuItem( helpMenu,
244  wxID_HELP,
245  _( "Gerbview &Manual" ),
246  _( "Open the GerbView Manual" ),
247  KiBitmap( online_help_xpm ) );
248 
249  AddMenuItem( helpMenu,
251  _( "&List Hotkeys" ),
252  _( "Displays the current hotkeys list and corresponding commands" ),
253  KiBitmap( hotkeys_xpm ) );
254 
255  // Separator
256  helpMenu->AppendSeparator();
257 
258  // Get involved with KiCad
260  _( "Get &Involved" ),
261  _( "Contribute to KiCad (opens a web browser)" ),
262  KiBitmap( info_xpm ) );
263 
264  helpMenu->AppendSeparator();
265 
266  // About Kicad
267  AddMenuItem( helpMenu,
268  wxID_ABOUT,
269  _( "&About Kicad" ),
270  _( "About KiCad" ),
271  KiBitmap( about_xpm ) );
272 
273  // Append menus to the menubar
274  menuBar->Append( fileMenu, _( "&File" ) );
275  menuBar->Append( configMenu, _( "&Preferences" ) );
276  menuBar->Append( miscellaneousMenu, _( "&Miscellaneous" ) );
277  menuBar->Append( helpMenu, _( "&Help" ) );
278 
279  menuBar->Thaw();
280 
281  // Associate the menu bar with the frame, if no previous menubar
282  if( GetMenuBar() == NULL )
283  SetMenuBar( menuBar );
284  else
285  menuBar->Refresh();
286 }
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_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:671
see class PGM_BASE
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
bool m_show_layer_manager_tools
void ReCreateMenuBar() override
Function ReCreateMenuBar Creates recreates the menu bar.