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_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>
36 #include <tools/gerbview_actions.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->SetTitle( _( "Open Recent Gerber File" ) );
68  openRecentGbrMenu->SetIcon( BITMAPS::recent );
69 
70  recentGbrFiles.UseMenu( openRecentGbrMenu );
71  recentGbrFiles.SetClearText( _( "Clear Recent Gerber Files" ) );
72  recentGbrFiles.AddFilesToMenu();
73  }
74 
75  fileMenu->Add( GERBVIEW_ACTIONS::openGerber );
76  wxMenuItem* gbrItem = fileMenu->Add( openRecentGbrMenu );
77  RegisterUIUpdateHandler( gbrItem->GetId(), FileHistoryCond( recentGbrFiles) );
78 
79 
80  // Create the drill file menu if it does not exist. Adding a file to/from the history
81  // will automatically refresh the menu.
82  if( !openRecentDrlMenu )
83  {
84  openRecentDrlMenu = new ACTION_MENU( false, selTool );
85  openRecentDrlMenu->SetTitle( _( "Open Recent Drill File" ) );
86  openRecentDrlMenu->SetIcon( BITMAPS::recent );
87 
88  m_drillFileHistory.UseMenu( openRecentDrlMenu );
89  m_drillFileHistory.SetClearText( _( "Clear Recent Drill Files" ) );
91  }
92 
94  wxMenuItem* drillItem = fileMenu->Add( openRecentDrlMenu );
96 
97 
98  // Create the job file menu if it does not exist. Adding a file to/from the history
99  // will automatically refresh the menu.
100  if( !openRecentJobMenu )
101  {
102  openRecentJobMenu = new ACTION_MENU( false, selTool );
103  openRecentJobMenu->SetTitle( _( "Open Recent Job File" ) );
104  openRecentJobMenu->SetIcon( BITMAPS::recent );
105 
106  m_jobFileHistory.UseMenu( openRecentJobMenu );
107  m_jobFileHistory.SetClearText( _( "Clear Recent Job Files" ) );
109  }
110 
111  fileMenu->Add( GERBVIEW_ACTIONS::openJobFile );
112  wxMenuItem* jobItem = fileMenu->Add( openRecentJobMenu );
114 
115 
116  // Create the zip file menu if it does not exist. Adding a file to/from the history
117  // will automatically refresh the menu.
118  if( !openRecentZipMenu )
119  {
120  openRecentZipMenu = new ACTION_MENU( false, selTool );
121  openRecentZipMenu->SetTitle( _( "Open Recent Zip File" ) );
122  openRecentZipMenu->SetIcon( BITMAPS::recent );
123 
124  m_zipFileHistory.UseMenu( openRecentZipMenu );
125  m_zipFileHistory.SetClearText( _( "Clear Recent Zip Files" ) );
127  }
128 
129  fileMenu->Add( GERBVIEW_ACTIONS::openZipFile );
130  wxMenuItem* zipItem = fileMenu->Add( openRecentZipMenu );
132 
133 #undef FileHistoryCond
134 
135  fileMenu->AppendSeparator();
138 
139  fileMenu->AppendSeparator();
141 
142  fileMenu->AppendSeparator();
143  fileMenu->Add( ACTIONS::print );
144 
145  fileMenu->AppendSeparator();
146  fileMenu->AddQuitOrClose( &Kiface(), _( "Gerber Viewer" ) );
147 
148 
149  //-- View menu -------------------------------------------------------
150  //
151  ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
152 
154 
155  viewMenu->AppendSeparator();
156  viewMenu->Add( ACTIONS::zoomInCenter );
157  viewMenu->Add( ACTIONS::zoomOutCenter );
158  viewMenu->Add( ACTIONS::zoomFitScreen );
159  viewMenu->Add( ACTIONS::zoomTool );
160  viewMenu->Add( ACTIONS::zoomRedraw );
161 
162  viewMenu->AppendSeparator();
165 
166 #ifdef __APPLE__
167  // Add a separator only on macOS because the OS adds menu items to the view menu after ours
168  viewMenu->AppendSeparator();
169 #endif
170 
171  // Units submenu
172  ACTION_MENU* unitsSubMenu = new ACTION_MENU( false, selTool );
173 
174  unitsSubMenu->SetTitle( _( "&Units" ) );
175  unitsSubMenu->SetIcon( BITMAPS::unit_mm );
176  unitsSubMenu->Add( ACTIONS::inchesUnits, ACTION_MENU::CHECK );
177  unitsSubMenu->Add( ACTIONS::milsUnits, ACTION_MENU::CHECK );
179 
180  viewMenu->Add( unitsSubMenu );
181 
182  viewMenu->AppendSeparator();
191 
192 
193  //-- Tools menu -------------------------------------------------------
194  //
195  ACTION_MENU* toolsMenu = new ACTION_MENU( false, selTool );
196 
197  toolsMenu->Add( GERBVIEW_ACTIONS::showDCodes );
198  toolsMenu->Add( GERBVIEW_ACTIONS::showSource );
199 
200  toolsMenu->Add( ACTIONS::measureTool );
201 
202  toolsMenu->AppendSeparator();
203  toolsMenu->Add( GERBVIEW_ACTIONS::clearLayer );
204 
205 
206  //-- Preferences menu -----------------------------------------------
207  //
208  ACTION_MENU* preferencesMenu = new ACTION_MENU( false, selTool );
209 
210  // We can't use ACTIONS::showPreferences yet because wxWidgets moves this on
211  // Mac, and it needs the wxID_PREFERENCES id to find it.
212  preferencesMenu->Add( _( "Preferences..." ) + "\tCtrl+,",
213  _( "Show preferences for all open tools" ),
214  wxID_PREFERENCES,
216 
217  preferencesMenu->AppendSeparator();
218  AddMenuLanguageList( preferencesMenu, selTool );
219 
220 
221  //-- Menubar -------------------------------------------------------------
222  //
223  menuBar->Append( fileMenu, _( "&File" ) );
224  menuBar->Append( viewMenu, _( "&View" ) );
225  menuBar->Append( toolsMenu, _( "&Tools" ) );
226  menuBar->Append( preferencesMenu, _( "&Preferences" ) );
227  AddStandardHelpMenu( menuBar );
228 
229  // Associate the menu bar with the frame, if no previous menubar
230  SetMenuBar( menuBar );
231  delete oldMenuBar;
232 }
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:93
static TOOL_ACTION openGerber
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition: action_menu.cpp:73
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static TOOL_ACTION showSource
static TOOL_ACTION zoomTool
Definition: actions.h:99
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:96
static TOOL_ACTION millimetersUnits
Definition: actions.h:146
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:57
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:94
static TOOL_ACTION toggleDiffMode
FILE_HISTORY m_zipFileHistory
static TOOL_ACTION measureTool
Definition: actions.h:154
static TOOL_ACTION flipGerberView
static TOOL_ACTION toggleGrid
Definition: actions.h:140
static TOOL_ACTION inchesUnits
Definition: actions.h:144
static TOOL_ACTION linesDisplayOutlines
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
static TOOL_ACTION togglePolarCoords
Definition: actions.h:149
static TOOL_ACTION openJobFile
#define FileHistoryCond(x)
#define _(s)
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:145
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:183
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:158
void SetTitle(const wxString &aTitle) override
Set title for the menu.
Definition: action_menu.cpp:87
FILE_HISTORY & GetFileHistory()
Get the frame's main file history.
static TOOL_ACTION zoomRedraw
Definition: actions.h:90
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.
void AddQuitOrClose(KIFACE_BASE *aKiface, wxString aAppname="")
Add either a standard Quit or Close item to the menu.
static TOOL_ACTION showDCodes
static TOOL_ACTION highContrastMode
Definition: actions.h:103
static TOOL_ACTION reloadAllLayers
static TOOL_ACTION openZipFile