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 <stambaughw@gmail.com>
6  * Copyright (C) 1992-2021 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_i.h>
31 #include <menus_helpers.h>
32 #include <tool/action_menu.h>
33 #include <tool/actions.h>
34 #include <tool/tool_manager.h>
35 #include <tools/gerbview_actions.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->SetTitle( _( "Open Recent Gerber File" ) );
67  openRecentGbrMenu->SetIcon( BITMAPS::recent );
68 
69  recentGbrFiles.UseMenu( openRecentGbrMenu );
70  recentGbrFiles.SetClearText( _( "Clear Recent Gerber Files" ) );
71  recentGbrFiles.AddFilesToMenu();
72  }
73 
74  fileMenu->Add( GERBVIEW_ACTIONS::openGerber );
75  wxMenuItem* gbrItem = fileMenu->Add( openRecentGbrMenu );
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" ) );
90  }
91 
93  wxMenuItem* drillItem = fileMenu->Add( openRecentDrlMenu );
95 
96 
97  // Create the job file menu if it does not exist. Adding a file to/from the history
98  // will automatically refresh the menu.
99  if( !openRecentJobMenu )
100  {
101  openRecentJobMenu = new ACTION_MENU( false, selTool );
102  openRecentJobMenu->SetTitle( _( "Open Recent Job File" ) );
103  openRecentJobMenu->SetIcon( BITMAPS::recent );
104 
105  m_jobFileHistory.UseMenu( openRecentJobMenu );
106  m_jobFileHistory.SetClearText( _( "Clear Recent Job Files" ) );
108  }
109 
110  fileMenu->Add( GERBVIEW_ACTIONS::openJobFile );
111  wxMenuItem* jobItem = fileMenu->Add( openRecentJobMenu );
113 
114 
115  // Create the zip file menu if it does not exist. Adding a file to/from the history
116  // will automatically refresh the menu.
117  if( !openRecentZipMenu )
118  {
119  openRecentZipMenu = new ACTION_MENU( false, selTool );
120  openRecentZipMenu->SetTitle( _( "Open Recent Zip File" ) );
121  openRecentZipMenu->SetIcon( BITMAPS::recent );
122 
123  m_zipFileHistory.UseMenu( openRecentZipMenu );
124  m_zipFileHistory.SetClearText( _( "Clear Recent Zip Files" ) );
126  }
127 
128  fileMenu->Add( GERBVIEW_ACTIONS::openZipFile );
129  wxMenuItem* zipItem = fileMenu->Add( openRecentZipMenu );
131 
132 #undef FileHistoryCond
133 
134  fileMenu->AppendSeparator();
137 
138  fileMenu->AppendSeparator();
140 
141  fileMenu->AppendSeparator();
142  fileMenu->Add( ACTIONS::print );
143 
144  fileMenu->AppendSeparator();
145  fileMenu->AddQuitOrClose( &Kiface(), _( "Gerber Viewer" ) );
146 
147 
148  //-- View menu -------------------------------------------------------
149  //
150  ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
151 
153 
154  viewMenu->AppendSeparator();
155  viewMenu->Add( ACTIONS::zoomInCenter );
156  viewMenu->Add( ACTIONS::zoomOutCenter );
157  viewMenu->Add( ACTIONS::zoomFitScreen );
158  viewMenu->Add( ACTIONS::zoomTool );
159  viewMenu->Add( ACTIONS::zoomRedraw );
160 
161  viewMenu->AppendSeparator();
164 
165 #ifdef __APPLE__
166  // Add a separator only on macOS because the OS adds menu items to the view menu after ours
167  viewMenu->AppendSeparator();
168 #endif
169 
170  // Units submenu
171  ACTION_MENU* unitsSubMenu = new ACTION_MENU( false, selTool );
172 
173  unitsSubMenu->SetTitle( _( "&Units" ) );
174  unitsSubMenu->SetIcon( BITMAPS::unit_mm );
175  unitsSubMenu->Add( ACTIONS::inchesUnits, ACTION_MENU::CHECK );
176  unitsSubMenu->Add( ACTIONS::milsUnits, ACTION_MENU::CHECK );
178 
179  viewMenu->Add( unitsSubMenu );
180 
181  viewMenu->AppendSeparator();
190 
191 
192  //-- Tools menu -------------------------------------------------------
193  //
194  ACTION_MENU* toolsMenu = new ACTION_MENU( false, selTool );
195 
196  toolsMenu->Add( GERBVIEW_ACTIONS::showDCodes );
197  toolsMenu->Add( GERBVIEW_ACTIONS::showSource );
198 
199  toolsMenu->Add( ACTIONS::measureTool );
200 
201  toolsMenu->AppendSeparator();
202  toolsMenu->Add( GERBVIEW_ACTIONS::clearLayer );
203 
204 
205  //-- Preferences menu -----------------------------------------------
206  //
207  ACTION_MENU* preferencesMenu = new ACTION_MENU( false, selTool );
208 
209  preferencesMenu->Add( _( "Preferences..." ) + "\tCtrl+,",
210  _( "Show preferences for all open tools" ),
211  wxID_PREFERENCES,
213 
214  preferencesMenu->AppendSeparator();
215  AddMenuLanguageList( preferencesMenu, selTool );
216 
217 
218  //-- Menubar -------------------------------------------------------------
219  //
220  menuBar->Append( fileMenu, _( "&File" ) );
221  menuBar->Append( viewMenu, _( "&View" ) );
222  menuBar->Append( toolsMenu, _( "&Tools" ) );
223  menuBar->Append( preferencesMenu, _( "&Preferences" ) );
224  AddStandardHelpMenu( menuBar );
225 
226  // Associate the menu bar with the frame, if no previous menubar
227  SetMenuBar( menuBar );
228  delete oldMenuBar;
229 }
void AddFilesToMenu() override
Add the files to all registered menus.
Definition: filehistory.h:98
static TOOL_ACTION openDrillFile
static TOOL_ACTION zoomInCenter
Definition: actions.h:96
static TOOL_ACTION openGerber
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:47
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition: action_menu.cpp:72
static TOOL_ACTION showSource
static TOOL_ACTION zoomTool
Definition: actions.h:102
FILE_HISTORY m_jobFileHistory
void SetClearText(wxString aClearText)
Set the text displayed on the menu item that clears the entire menu.
Definition: filehistory.h:123
static TOOL_ACTION clearAllLayers
static TOOL_ACTION zoomFitScreen
Definition: actions.h:99
static TOOL_ACTION millimetersUnits
Definition: actions.h:149
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
static TOOL_ACTION exportToPcbnew
static TOOL_ACTION toggleLayerManager
static TOOL_ACTION print
Definition: actions.h:60
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition: wx_menubar.h:45
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: filehistory.h:42
static TOOL_ACTION dcodeDisplay
static TOOL_ACTION negativeObjectDisplay
static TOOL_ACTION zoomOutCenter
Definition: actions.h:97
static TOOL_ACTION toggleDiffMode
FILE_HISTORY m_zipFileHistory
static TOOL_ACTION measureTool
Definition: actions.h:157
static TOOL_ACTION flipGerberView
static TOOL_ACTION toggleGrid
Definition: actions.h:143
static TOOL_ACTION inchesUnits
Definition: actions.h:147
static TOOL_ACTION linesDisplayOutlines
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
static TOOL_ACTION togglePolarCoords
Definition: actions.h:152
static TOOL_ACTION openJobFile
#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...
FILE_HISTORY m_drillFileHistory
static TOOL_ACTION milsUnits
Definition: actions.h:148
static TOOL_ACTION flashedDisplayOutlines
static TOOL_ACTION clearLayer
Selection tool for GerbView, based on the one in Pcbnew.
static constexpr bool CHECK
Definition: action_menu.h:182
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:157
void SetTitle(const wxString &aTitle) override
Set title for the menu.
Definition: action_menu.cpp:90
FILE_HISTORY & GetFileHistory()
Get the frame's main file history.
void AddQuitOrClose(KIFACE_I *aKiface, wxString aAppname="")
Add either a standard Quit or Close item to the menu.
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION zoomRedraw
Definition: actions.h:93
static TOOL_ACTION polygonsDisplayOutlines
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
void ReCreateMenuBar() override
Recreates the menu bar.
static TOOL_ACTION showDCodes
static TOOL_ACTION highContrastMode
Definition: actions.h:106
static TOOL_ACTION reloadAllLayers
static TOOL_ACTION openZipFile