KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <tool/action_manager.h>
32#include <tool/action_menu.h>
33#include <tool/actions.h>
34#include <tool/tool_manager.h>
37#include <widgets/wx_menubar.h>
38
39
41{
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 WX_MENUBAR* menuBar = new WX_MENUBAR();
47
48 //-- File menu -------------------------------------------------------
49 //
50 ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
51 static ACTION_MENU* openRecentGbrMenu;
52 static ACTION_MENU* openRecentDrlMenu;
53 static ACTION_MENU* openRecentJobMenu;
54 static ACTION_MENU* openRecentZipMenu;
55
56 FILE_HISTORY& recentGbrFiles = GetFileHistory();
57
58#define FileHistoryCond( x ) ACTION_CONDITIONS().Enable( FILE_HISTORY::FileHistoryNotEmpty( x ) )
59
60
61 // Create the gerber file menu if it does not exist. Adding a file to/from the history
62 // will automatically refresh the menu.
63 if( !openRecentGbrMenu )
64 {
65 openRecentGbrMenu = new ACTION_MENU( false, selTool );
66 openRecentGbrMenu->SetIcon( BITMAPS::recent );
67
68 recentGbrFiles.SetClearText( _( "Clear Recent Gerber Files" ) );
69 recentGbrFiles.UseMenu( openRecentGbrMenu );
70 recentGbrFiles.AddFilesToMenu();
71 }
72
73 // Ensure the title is up to date after changing language
74 openRecentGbrMenu->SetTitle( _( "Open Recent Gerber File" ) );
75 recentGbrFiles.UpdateClearText( openRecentGbrMenu, _( "Clear Recent Gerber Files" ) );
76
79 wxMenuItem* gbrItem = fileMenu->Add( openRecentGbrMenu->Clone() );
80 RegisterUIUpdateHandler( gbrItem->GetId(), FileHistoryCond( recentGbrFiles) );
81
82
83 // Create the drill file menu if it does not exist. Adding a file to/from the history
84 // will automatically refresh the menu.
85 if( !openRecentDrlMenu )
86 {
87 openRecentDrlMenu = new ACTION_MENU( false, selTool );
88 openRecentDrlMenu->SetTitle( _( "Open Recent Drill File" ) );
89 openRecentDrlMenu->SetIcon( BITMAPS::recent );
90
91 m_drillFileHistory.UseMenu( openRecentDrlMenu );
92 m_drillFileHistory.SetClearText( _( "Clear Recent Drill Files" ) );
94 }
95
96 // Ensure the title is up to date after changing language
97 openRecentGbrMenu->SetTitle( _( "Open Recent Gerber File" ) );
98 m_drillFileHistory.UpdateClearText( openRecentDrlMenu, _( "Clear Recent Drill Files" ) );
99
101 wxMenuItem* drillItem = fileMenu->Add( openRecentDrlMenu->Clone() );
103
104
105 // Create the job file menu if it does not exist. Adding a file to/from the history
106 // will automatically refresh the menu.
107 if( !openRecentJobMenu )
108 {
109 openRecentJobMenu = new ACTION_MENU( false, selTool );
110 openRecentJobMenu->SetIcon( BITMAPS::recent );
111
112 m_jobFileHistory.SetClearText( _( "Clear Recent Job Files" ) );
113 m_jobFileHistory.UseMenu( openRecentJobMenu );
115 }
116
117 // Ensure the title is up to date after changing language
118 openRecentJobMenu->SetTitle( _( "Open Recent Job File" ) );
119 m_jobFileHistory.UpdateClearText( openRecentJobMenu, _( "Clear Recent Job Files" ) );
120
122 wxMenuItem* jobItem = fileMenu->Add( openRecentJobMenu->Clone() );
124
125
126 // Create the zip file menu if it does not exist. Adding a file to/from the history
127 // will automatically refresh the menu.
128 if( !openRecentZipMenu )
129 {
130 openRecentZipMenu = new ACTION_MENU( false, selTool );
131 openRecentZipMenu->SetIcon( BITMAPS::recent );
132
133 m_zipFileHistory.UseMenu( openRecentZipMenu );
134 m_zipFileHistory.SetClearText( _( "Clear Recent Zip Files" ) );
136 }
137
138 // Ensure the title is up to date after changing language
139 openRecentZipMenu->SetTitle( _( "Open Recent Zip File" ) );
140 m_zipFileHistory.UpdateClearText( openRecentZipMenu, _( "Clear Recent Zip Files" ) );
141
143 wxMenuItem* zipItem = fileMenu->Add( openRecentZipMenu->Clone() );
145
146#undef FileHistoryCond
147
148 fileMenu->AppendSeparator();
151
152 fileMenu->AppendSeparator();
154
155 fileMenu->AppendSeparator();
156 fileMenu->Add( ACTIONS::print );
157
158 fileMenu->AppendSeparator();
159 fileMenu->AddQuitOrClose( &Kiface(), _( "Gerber Viewer" ) );
160
161
162 //-- View menu -------------------------------------------------------
163 //
164 ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
165
166 viewMenu->Add( ACTIONS::zoomInCenter );
167 viewMenu->Add( ACTIONS::zoomOutCenter );
168 viewMenu->Add( ACTIONS::zoomFitScreen );
169 viewMenu->Add( ACTIONS::zoomTool );
170 viewMenu->Add( ACTIONS::zoomRedraw );
171
172 viewMenu->AppendSeparator();
175
176#ifdef __APPLE__
177 // Add a separator only on macOS because the OS adds menu items to the view menu after ours
178 viewMenu->AppendSeparator();
179#endif
180
181 // Units submenu
182 ACTION_MENU* unitsSubMenu = new ACTION_MENU( false, selTool );
183
184 unitsSubMenu->SetTitle( _( "&Units" ) );
185 unitsSubMenu->SetIcon( BITMAPS::unit_mm );
187 unitsSubMenu->Add( ACTIONS::milsUnits, ACTION_MENU::CHECK );
189
190 viewMenu->Add( unitsSubMenu );
191
192 viewMenu->AppendSeparator();
202
203 viewMenu->AppendSeparator();
205
206 //-- Tools menu -------------------------------------------------------
207 //
208 ACTION_MENU* toolsMenu = new ACTION_MENU( false, selTool );
209
210 toolsMenu->Add( GERBVIEW_ACTIONS::showDCodes );
211 toolsMenu->Add( GERBVIEW_ACTIONS::showSource );
212
213 toolsMenu->Add( ACTIONS::measureTool );
214
215 toolsMenu->AppendSeparator();
216 toolsMenu->Add( GERBVIEW_ACTIONS::clearLayer );
217
218
219 //-- Preferences menu -----------------------------------------------
220 //
221 ACTION_MENU* preferencesMenu = new ACTION_MENU( false, selTool );
222
223 preferencesMenu->Add( ACTIONS::openPreferences );
224
225 preferencesMenu->AppendSeparator();
226 AddMenuLanguageList( preferencesMenu, selTool );
227
228
229 //-- Menubar -------------------------------------------------------------
230 //
231 menuBar->Append( fileMenu, _( "&File" ) );
232 menuBar->Append( viewMenu, _( "&View" ) );
233 menuBar->Append( toolsMenu, _( "&Tools" ) );
234 menuBar->Append( preferencesMenu, _( "&Preferences" ) );
235 AddStandardHelpMenu( menuBar );
236
237 // Associate the menu bar with the frame, if no previous menubar
238 SetMenuBar( menuBar );
239 delete oldMenuBar;
240}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static TOOL_ACTION toggleGrid
Definition: actions.h:172
static TOOL_ACTION zoomRedraw
Definition: actions.h:114
static TOOL_ACTION millimetersUnits
Definition: actions.h:180
static TOOL_ACTION zoomOutCenter
Definition: actions.h:118
static TOOL_ACTION togglePolarCoords
Definition: actions.h:183
static TOOL_ACTION milsUnits
Definition: actions.h:179
static TOOL_ACTION openPreferences
Definition: actions.h:211
static TOOL_ACTION inchesUnits
Definition: actions.h:178
static TOOL_ACTION highContrastMode
Definition: actions.h:133
static TOOL_ACTION measureTool
Definition: actions.h:188
static TOOL_ACTION zoomFitScreen
Definition: actions.h:124
static TOOL_ACTION zoomTool
Definition: actions.h:127
static TOOL_ACTION print
Definition: actions.h:57
static TOOL_ACTION zoomInCenter
Definition: actions.h:117
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:201
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:92
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition: action_menu.cpp:78
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
void AddMenuLanguageList(ACTION_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
void SetMenuBar(wxMenuBar *menu_bar) override
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:167
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition: wx_menubar.h:47
#define _(s)
#define FileHistoryCond(x)