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>
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->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 
78  fileMenu->Add( GERBVIEW_ACTIONS::openGerber );
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 
121  fileMenu->Add( GERBVIEW_ACTIONS::openJobFile );
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 
142  fileMenu->Add( GERBVIEW_ACTIONS::openZipFile );
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 
167 
168  viewMenu->AppendSeparator();
169  viewMenu->Add( ACTIONS::zoomInCenter );
170  viewMenu->Add( ACTIONS::zoomOutCenter );
171  viewMenu->Add( ACTIONS::zoomFitScreen );
172  viewMenu->Add( ACTIONS::zoomTool );
173  viewMenu->Add( ACTIONS::zoomRedraw );
174 
175  viewMenu->AppendSeparator();
178 
179 #ifdef __APPLE__
180  // Add a separator only on macOS because the OS adds menu items to the view menu after ours
181  viewMenu->AppendSeparator();
182 #endif
183 
184  // Units submenu
185  ACTION_MENU* unitsSubMenu = new ACTION_MENU( false, selTool );
186 
187  unitsSubMenu->SetTitle( _( "&Units" ) );
188  unitsSubMenu->SetIcon( BITMAPS::unit_mm );
189  unitsSubMenu->Add( ACTIONS::inchesUnits, ACTION_MENU::CHECK );
190  unitsSubMenu->Add( ACTIONS::milsUnits, ACTION_MENU::CHECK );
192 
193  viewMenu->Add( unitsSubMenu );
194 
195  viewMenu->AppendSeparator();
204 
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  // We can't use ACTIONS::showPreferences yet because wxWidgets moves this on
224  // Mac, and it needs the wxID_PREFERENCES id to find it.
225  preferencesMenu->Add( _( "Preferences..." ) + wxT( "\tCtrl+," ),
226  _( "Show preferences for all open tools" ),
227  wxID_PREFERENCES,
229 
230  preferencesMenu->AppendSeparator();
231  AddMenuLanguageList( preferencesMenu, selTool );
232 
233 
234  //-- Menubar -------------------------------------------------------------
235  //
236  menuBar->Append( fileMenu, _( "&File" ) );
237  menuBar->Append( viewMenu, _( "&View" ) );
238  menuBar->Append( toolsMenu, _( "&Tools" ) );
239  menuBar->Append( preferencesMenu, _( "&Preferences" ) );
240  AddStandardHelpMenu( menuBar );
241 
242  // Associate the menu bar with the frame, if no previous menubar
243  SetMenuBar( menuBar );
244  delete oldMenuBar;
245 }
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
void UpdateClearText(wxMenu *aMenu, wxString aClearText)
Update the text displayed on the menu item that clears the entire menu.
#define FileHistoryCond(x)
#define _(s)
ACTION_MENU * Clone() const
Create a deep, recursive copy of this ACTION_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...
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:189
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