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 <[email protected]>
6 * Copyright (C) 1992-2022 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
26#include "gerbview_frame.h"
27
28#include <bitmaps.h>
29#include "gerbview_id.h"
30#include <kiface_base.h>
31#include <menus_helpers.h>
32#include <tool/action_manager.h>
33#include <tool/action_menu.h>
34#include <tool/actions.h>
35#include <tool/tool_manager.h>
38#include <widgets/wx_menubar.h>
39
40
42{
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 WX_MENUBAR* menuBar = new WX_MENUBAR();
48
49 //-- File menu -------------------------------------------------------
50 //
51 ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
52 static ACTION_MENU* openRecentGbrMenu;
53 static ACTION_MENU* openRecentDrlMenu;
54 static ACTION_MENU* openRecentJobMenu;
55 static ACTION_MENU* openRecentZipMenu;
56
57 FILE_HISTORY& recentGbrFiles = GetFileHistory();
58
59#define FileHistoryCond( x ) ACTION_CONDITIONS().Enable( FILE_HISTORY::FileHistoryNotEmpty( x ) )
60
61
62 // Create the gerber file menu if it does not exist. Adding a file to/from the history
63 // will automatically refresh the menu.
64 if( !openRecentGbrMenu )
65 {
66 openRecentGbrMenu = new ACTION_MENU( false, selTool );
67 openRecentGbrMenu->SetIcon( BITMAPS::recent );
68
69 recentGbrFiles.SetClearText( _( "Clear Recent Gerber Files" ) );
70 recentGbrFiles.UseMenu( openRecentGbrMenu );
71 recentGbrFiles.AddFilesToMenu();
72 }
73
74 // Ensure the title is up to date after changing language
75 openRecentGbrMenu->SetTitle( _( "Open Recent Gerber File" ) );
76 recentGbrFiles.UpdateClearText( openRecentGbrMenu, _( "Clear Recent Gerber Files" ) );
77
80 wxMenuItem* gbrItem = fileMenu->Add( openRecentGbrMenu->Clone() );
81 RegisterUIUpdateHandler( gbrItem->GetId(), FileHistoryCond( recentGbrFiles) );
82
83
84 // Create the drill file menu if it does not exist. Adding a file to/from the history
85 // will automatically refresh the menu.
86 if( !openRecentDrlMenu )
87 {
88 openRecentDrlMenu = new ACTION_MENU( false, selTool );
89 openRecentDrlMenu->SetTitle( _( "Open Recent Drill File" ) );
90 openRecentDrlMenu->SetIcon( BITMAPS::recent );
91
92 m_drillFileHistory.UseMenu( openRecentDrlMenu );
93 m_drillFileHistory.SetClearText( _( "Clear Recent Drill Files" ) );
95 }
96
97 // Ensure the title is up to date after changing language
98 openRecentGbrMenu->SetTitle( _( "Open Recent Gerber File" ) );
99 m_drillFileHistory.UpdateClearText( openRecentDrlMenu, _( "Clear Recent Drill Files" ) );
100
102 wxMenuItem* drillItem = fileMenu->Add( openRecentDrlMenu->Clone() );
104
105
106 // Create the job file menu if it does not exist. Adding a file to/from the history
107 // will automatically refresh the menu.
108 if( !openRecentJobMenu )
109 {
110 openRecentJobMenu = new ACTION_MENU( false, selTool );
111 openRecentJobMenu->SetIcon( BITMAPS::recent );
112
113 m_jobFileHistory.SetClearText( _( "Clear Recent Job Files" ) );
114 m_jobFileHistory.UseMenu( openRecentJobMenu );
116 }
117
118 // Ensure the title is up to date after changing language
119 openRecentJobMenu->SetTitle( _( "Open Recent Job File" ) );
120 m_jobFileHistory.UpdateClearText( openRecentJobMenu, _( "Clear Recent Job Files" ) );
121
123 wxMenuItem* jobItem = fileMenu->Add( openRecentJobMenu->Clone() );
125
126
127 // Create the zip file menu if it does not exist. Adding a file to/from the history
128 // will automatically refresh the menu.
129 if( !openRecentZipMenu )
130 {
131 openRecentZipMenu = new ACTION_MENU( false, selTool );
132 openRecentZipMenu->SetIcon( BITMAPS::recent );
133
134 m_zipFileHistory.UseMenu( openRecentZipMenu );
135 m_zipFileHistory.SetClearText( _( "Clear Recent Zip Files" ) );
137 }
138
139 // Ensure the title is up to date after changing language
140 openRecentZipMenu->SetTitle( _( "Open Recent Zip File" ) );
141 m_zipFileHistory.UpdateClearText( openRecentZipMenu, _( "Clear Recent Zip Files" ) );
142
144 wxMenuItem* zipItem = fileMenu->Add( openRecentZipMenu->Clone() );
146
147#undef FileHistoryCond
148
149 fileMenu->AppendSeparator();
152
153 fileMenu->AppendSeparator();
155
156 fileMenu->AppendSeparator();
157 fileMenu->Add( ACTIONS::print );
158
159 fileMenu->AppendSeparator();
160 fileMenu->AddQuitOrClose( &Kiface(), _( "Gerber Viewer" ) );
161
162
163 //-- View menu -------------------------------------------------------
164 //
165 ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
166
167 viewMenu->Add( ACTIONS::zoomInCenter );
168 viewMenu->Add( ACTIONS::zoomOutCenter );
169 viewMenu->Add( ACTIONS::zoomFitScreen );
170 viewMenu->Add( ACTIONS::zoomTool );
171 viewMenu->Add( ACTIONS::zoomRedraw );
172
173 viewMenu->AppendSeparator();
176
177#ifdef __APPLE__
178 // Add a separator only on macOS because the OS adds menu items to the view menu after ours
179 viewMenu->AppendSeparator();
180#endif
181
182 // Units submenu
183 ACTION_MENU* unitsSubMenu = new ACTION_MENU( false, selTool );
184
185 unitsSubMenu->SetTitle( _( "&Units" ) );
186 unitsSubMenu->SetIcon( BITMAPS::unit_mm );
188 unitsSubMenu->Add( ACTIONS::milsUnits, ACTION_MENU::CHECK );
190
191 viewMenu->Add( unitsSubMenu );
192
193 viewMenu->AppendSeparator();
203
204 viewMenu->AppendSeparator();
206
207 //-- Tools menu -------------------------------------------------------
208 //
209 ACTION_MENU* toolsMenu = new ACTION_MENU( false, selTool );
210
211 toolsMenu->Add( GERBVIEW_ACTIONS::showDCodes );
212 toolsMenu->Add( GERBVIEW_ACTIONS::showSource );
213
214 toolsMenu->Add( ACTIONS::measureTool );
215
216 toolsMenu->AppendSeparator();
217 toolsMenu->Add( GERBVIEW_ACTIONS::clearLayer );
218
219
220 //-- Preferences menu -----------------------------------------------
221 //
222 ACTION_MENU* preferencesMenu = new ACTION_MENU( false, selTool );
223
224 // We can't use ACTIONS::showPreferences yet because wxWidgets moves this on
225 // Mac, and it needs the wxID_PREFERENCES id to find it.
226 preferencesMenu->Add( _( "Preferences..." ) + wxT( "\tCtrl+," ),
227 _( "Show preferences for all open tools" ),
228 wxID_PREFERENCES,
230
231 preferencesMenu->AppendSeparator();
232 AddMenuLanguageList( preferencesMenu, selTool );
233
234
235 //-- Menubar -------------------------------------------------------------
236 //
237 menuBar->Append( fileMenu, _( "&File" ) );
238 menuBar->Append( viewMenu, _( "&View" ) );
239 menuBar->Append( toolsMenu, _( "&Tools" ) );
240 menuBar->Append( preferencesMenu, _( "&Preferences" ) );
241 AddStandardHelpMenu( menuBar );
242
243 // Associate the menu bar with the frame, if no previous menubar
244 SetMenuBar( menuBar );
245 delete oldMenuBar;
246}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static TOOL_ACTION toggleGrid
Definition: actions.h:143
static TOOL_ACTION zoomRedraw
Definition: actions.h:92
static TOOL_ACTION millimetersUnits
Definition: actions.h:149
static TOOL_ACTION zoomOutCenter
Definition: actions.h:96
static TOOL_ACTION togglePolarCoords
Definition: actions.h:152
static TOOL_ACTION milsUnits
Definition: actions.h:148
static TOOL_ACTION inchesUnits
Definition: actions.h:147
static TOOL_ACTION highContrastMode
Definition: actions.h:105
static TOOL_ACTION measureTool
Definition: actions.h:157
static TOOL_ACTION zoomFitScreen
Definition: actions.h:98
static TOOL_ACTION zoomTool
Definition: actions.h:101
static TOOL_ACTION print
Definition: actions.h:57
static TOOL_ACTION zoomInCenter
Definition: actions.h:95
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
void AddQuitOrClose(KIFACE_BASE *aKiface, wxString aAppname="")
Add either a standard Quit or Close item to the menu.
static constexpr bool CHECK
Definition: action_menu.h:189
ACTION_MENU * Clone() const
Create a deep, recursive copy of this ACTION_MENU.
void SetTitle(const wxString &aTitle) override
Set title for the menu.
Definition: action_menu.cpp:87
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition: action_menu.cpp:73
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
FILE_HISTORY & GetFileHistory()
Get the frame's main file history.
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: file_history.h:43
void SetClearText(wxString aClearText)
Set the text displayed on the menu item that clears the entire menu.
Definition: file_history.h:123
void UpdateClearText(wxMenu *aMenu, wxString aClearText)
Update the text displayed on the menu item that clears the entire menu.
void AddFilesToMenu() override
Add the files to all registered menus.
Definition: file_history.h:98
static TOOL_ACTION dcodeDisplay
static TOOL_ACTION negativeObjectDisplay
static TOOL_ACTION flashedDisplayOutlines
static TOOL_ACTION exportToPcbnew
static TOOL_ACTION showDCodes
static TOOL_ACTION toggleXORMode
static TOOL_ACTION toggleLayerManager
static TOOL_ACTION openGerber
static TOOL_ACTION toggleDiffMode
static TOOL_ACTION clearAllLayers
static TOOL_ACTION flipGerberView
static TOOL_ACTION openAutodetected
static TOOL_ACTION reloadAllLayers
static TOOL_ACTION linesDisplayOutlines
static TOOL_ACTION openDrillFile
static TOOL_ACTION polygonsDisplayOutlines
static TOOL_ACTION openZipFile
static TOOL_ACTION showSource
static TOOL_ACTION openJobFile
static TOOL_ACTION clearLayer
FILE_HISTORY m_jobFileHistory
FILE_HISTORY m_zipFileHistory
FILE_HISTORY m_drillFileHistory
void doReCreateMenuBar() override
Selection tool for GerbView, based on the one in Pcbnew.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:170
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition: wx_menubar.h:46
#define _(s)
#define FileHistoryCond(x)
void AddMenuLanguageList(ACTION_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
Macros and inline functions to create menus items in menubars or popup menus.