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 The 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, see <https://www.gnu.org/licenses/>.
20 */
21
22#include "gerbview_frame.h"
23
24#include <bitmaps.h>
25#include "gerbview_id.h"
26#include <kiface_base.h>
27#include <tool/action_manager.h>
28#include <tool/action_menu.h>
29#include <tool/actions.h>
30#include <tool/tool_manager.h>
33#include <widgets/wx_menubar.h>
34
35
37{
39 // wxWidgets handles the Mac Application menu behind the scenes, but that means
40 // we always have to start from scratch with a new wxMenuBar.
41 wxMenuBar* oldMenuBar = GetMenuBar();
42 WX_MENUBAR* menuBar = new WX_MENUBAR();
43
44 //-- File menu -------------------------------------------------------
45 //
46 ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
47 static ACTION_MENU* openRecentGbrMenu;
48 static ACTION_MENU* openRecentDrlMenu;
49 static ACTION_MENU* openRecentJobMenu;
50 static ACTION_MENU* openRecentZipMenu;
51
52 FILE_HISTORY& recentGbrFiles = GetFileHistory();
53
54#define FileHistoryCond( x ) ACTION_CONDITIONS().Enable( FILE_HISTORY::FileHistoryNotEmpty( x ) )
55
56
57 // Create the gerber file menu if it does not exist. Adding a file to/from the history
58 // will automatically refresh the menu.
59 if( !openRecentGbrMenu )
60 {
61 openRecentGbrMenu = new ACTION_MENU( false, selTool );
62 openRecentGbrMenu->SetIcon( BITMAPS::recent );
63
64 recentGbrFiles.SetClearText( _( "Clear Recent Gerber Files" ) );
65 recentGbrFiles.UseMenu( openRecentGbrMenu );
66 recentGbrFiles.AddFilesToMenu();
67 }
68
69 // Ensure the title is up to date after changing language
70 openRecentGbrMenu->SetTitle( _( "Open Recent Gerber File" ) );
71 recentGbrFiles.UpdateClearText( openRecentGbrMenu, _( "Clear Recent Gerber Files" ) );
72
75 wxMenuItem* gbrItem = fileMenu->Add( openRecentGbrMenu->Clone() );
76 RegisterUIUpdateHandler( gbrItem->GetId(), FileHistoryCond( recentGbrFiles) );
77
78
79 // Create the drill file menu if it does not exist. Adding a file to/from the history
80 // will automatically refresh the menu.
81 if( !openRecentDrlMenu )
82 {
83 openRecentDrlMenu = new ACTION_MENU( false, selTool );
84 openRecentDrlMenu->SetTitle( _( "Open Recent Drill File" ) );
85 openRecentDrlMenu->SetIcon( BITMAPS::recent );
86
87 m_drillFileHistory.UseMenu( openRecentDrlMenu );
88 m_drillFileHistory.SetClearText( _( "Clear Recent Drill Files" ) );
89 m_drillFileHistory.AddFilesToMenu();
90 }
91
92 // Ensure the title is up to date after changing language
93 openRecentGbrMenu->SetTitle( _( "Open Recent Gerber File" ) );
94 m_drillFileHistory.UpdateClearText( openRecentDrlMenu, _( "Clear Recent Drill Files" ) );
95
97 wxMenuItem* drillItem = fileMenu->Add( openRecentDrlMenu->Clone() );
99
100
101 // Create the job file menu if it does not exist. Adding a file to/from the history
102 // will automatically refresh the menu.
103 if( !openRecentJobMenu )
104 {
105 openRecentJobMenu = new ACTION_MENU( false, selTool );
106 openRecentJobMenu->SetIcon( BITMAPS::recent );
107
108 m_jobFileHistory.SetClearText( _( "Clear Recent Job Files" ) );
109 m_jobFileHistory.UseMenu( openRecentJobMenu );
110 m_jobFileHistory.AddFilesToMenu();
111 }
112
113 // Ensure the title is up to date after changing language
114 openRecentJobMenu->SetTitle( _( "Open Recent Job File" ) );
115 m_jobFileHistory.UpdateClearText( openRecentJobMenu, _( "Clear Recent Job Files" ) );
116
118 wxMenuItem* jobItem = fileMenu->Add( openRecentJobMenu->Clone() );
120
121
122 // Create the zip file menu if it does not exist. Adding a file to/from the history
123 // will automatically refresh the menu.
124 if( !openRecentZipMenu )
125 {
126 openRecentZipMenu = new ACTION_MENU( false, selTool );
127 openRecentZipMenu->SetIcon( BITMAPS::recent );
128
129 m_zipFileHistory.UseMenu( openRecentZipMenu );
130 m_zipFileHistory.SetClearText( _( "Clear Recent Zip Files" ) );
131 m_zipFileHistory.AddFilesToMenu();
132 }
133
134 // Ensure the title is up to date after changing language
135 openRecentZipMenu->SetTitle( _( "Open Recent Zip File" ) );
136 m_zipFileHistory.UpdateClearText( openRecentZipMenu, _( "Clear Recent Zip Files" ) );
137
139 wxMenuItem* zipItem = fileMenu->Add( openRecentZipMenu->Clone() );
141
142#undef FileHistoryCond
143
144 fileMenu->AppendSeparator();
147
148 fileMenu->AppendSeparator();
150
151 fileMenu->AppendSeparator();
152 fileMenu->Add( ACTIONS::print );
153
154 fileMenu->AppendSeparator();
155 fileMenu->AddQuitOrClose( &Kiface(), _( "Gerber Viewer" ) );
156
157
158 //-- View menu -------------------------------------------------------
159 //
160 ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
161
162 viewMenu->Add( ACTIONS::zoomInCenter );
163 viewMenu->Add( ACTIONS::zoomOutCenter );
164 viewMenu->Add( ACTIONS::zoomFitScreen );
165 viewMenu->Add( ACTIONS::zoomTool );
166 viewMenu->Add( ACTIONS::zoomRedraw );
167
168 viewMenu->AppendSeparator();
171
172#ifdef __APPLE__
173 // Add a separator only on macOS because the OS adds menu items to the view menu after ours
174 viewMenu->AppendSeparator();
175#endif
176
177 // Units submenu
178 ACTION_MENU* unitsSubMenu = new ACTION_MENU( false, selTool );
179
180 unitsSubMenu->SetTitle( _( "&Units" ) );
181 unitsSubMenu->SetIcon( BITMAPS::unit_mm );
183 unitsSubMenu->Add( ACTIONS::milsUnits, ACTION_MENU::CHECK );
185
186 viewMenu->Add( unitsSubMenu );
187
188 viewMenu->AppendSeparator();
198
199 viewMenu->AppendSeparator();
201
202 //-- Tools menu -------------------------------------------------------
203 //
204 ACTION_MENU* toolsMenu = new ACTION_MENU( false, selTool );
205
206 toolsMenu->Add( GERBVIEW_ACTIONS::showDCodes );
207 toolsMenu->Add( GERBVIEW_ACTIONS::showSource );
208
209 toolsMenu->Add( ACTIONS::measureTool );
210
211 toolsMenu->AppendSeparator();
212 toolsMenu->Add( GERBVIEW_ACTIONS::clearLayer );
213
214
215 //-- Preferences menu -----------------------------------------------
216 //
217 ACTION_MENU* preferencesMenu = new ACTION_MENU( false, selTool );
218
219 preferencesMenu->Add( ACTIONS::openPreferences );
220
221 preferencesMenu->AppendSeparator();
222 AddMenuLanguageList( preferencesMenu, selTool );
223
224
225 //-- Menubar -------------------------------------------------------------
226 //
227 menuBar->Append( fileMenu, _( "&File" ) );
228 menuBar->Append( viewMenu, _( "&View" ) );
229 menuBar->Append( toolsMenu, _( "&Tools" ) );
230 menuBar->Append( preferencesMenu, _( "&Preferences" ) );
231 AddStandardHelpMenu( menuBar );
232
233 // Associate the menu bar with the frame, if no previous menubar
234 SetMenuBar( menuBar );
235 delete oldMenuBar;
236}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static TOOL_ACTION toggleGrid
Definition actions.h:194
static TOOL_ACTION zoomRedraw
Definition actions.h:128
static TOOL_ACTION millimetersUnits
Definition actions.h:202
static TOOL_ACTION zoomOutCenter
Definition actions.h:132
static TOOL_ACTION togglePolarCoords
Definition actions.h:205
static TOOL_ACTION milsUnits
Definition actions.h:201
static TOOL_ACTION openPreferences
Definition actions.h:276
static TOOL_ACTION inchesUnits
Definition actions.h:200
static TOOL_ACTION highContrastMode
Definition actions.h:151
static TOOL_ACTION measureTool
Definition actions.h:248
static TOOL_ACTION zoomFitScreen
Definition actions.h:138
static TOOL_ACTION zoomTool
Definition actions.h:142
static TOOL_ACTION print
Definition actions.h:60
static TOOL_ACTION zoomInCenter
Definition actions.h:131
Define the structure of a menu based on ACTIONs.
Definition action_menu.h:43
void AddQuitOrClose(KIFACE_BASE *aKiface, wxString aAppname="")
Add either a standard Quit or Close item to the menu.
static constexpr bool CHECK
ACTION_MENU * Clone() const
Create a deep, recursive copy of this ACTION_MENU.
void SetTitle(const wxString &aTitle) override
Set title for the menu.
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
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)
Create a menu list for language choice, and add it as submenu to MasterMenu.
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)
Add 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...
void SetClearText(wxString aClearText)
Set the text displayed on the menu item that clears the entire menu.
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.
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 clearAllLayers
static TOOL_ACTION flipGerberView
static TOOL_ACTION openAutodetected
static TOOL_ACTION reloadAllLayers
static TOOL_ACTION toggleForceOpacityMode
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
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition wx_menubar.h:43
#define _(s)
#define FileHistoryCond(x)