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-2019 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 #include "gerbview_frame.h"
26 
27 #include "gerbview_id.h"
28 #include <kiface_i.h>
29 #include <menus_helpers.h>
30 #include <pgm_base.h>
31 #include <tool/action_menu.h>
32 #include <tool/actions.h>
33 #include <tool/tool_manager.h>
34 #include <tools/gerbview_actions.h>
36 #include <widgets/wx_menubar.h>
37 
38 
40 {
42  // wxWidgets handles the Mac Application menu behind the scenes, but that means
43  // we always have to start from scratch with a new wxMenuBar.
44  wxMenuBar* oldMenuBar = GetMenuBar();
45  WX_MENUBAR* menuBar = new WX_MENUBAR();
46 
47  //-- File menu -------------------------------------------------------
48  //
49  ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
50  static ACTION_MENU* openRecentGbrMenu;
51  static ACTION_MENU* openRecentDrlMenu;
52  static ACTION_MENU* openRecentJobMenu;
53  static ACTION_MENU* openRecentZipMenu;
54 
55  FILE_HISTORY& recentGbrFiles = GetFileHistory();
56 
57 #define FileHistoryCond( x ) ACTION_CONDITIONS().Enable( FILE_HISTORY::FileHistoryNotEmpty( x ) )
58 
59 
60  // Create the gerber file menu if it does not exist. Adding a file to/from the history
61  // will automatically refresh the menu.
62  if( !openRecentGbrMenu )
63  {
64  openRecentGbrMenu = new ACTION_MENU( false );
65  openRecentGbrMenu->SetTool( selTool );
66  openRecentGbrMenu->SetTitle( _( "Open Recent Gerber File" ) );
67  openRecentGbrMenu->SetIcon( recent_xpm );
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 );
84  openRecentDrlMenu->SetTool( selTool );
85  openRecentDrlMenu->SetTitle( _( "Open Recent Drill File" ) );
86  openRecentDrlMenu->SetIcon( recent_xpm );
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 );
103  openRecentJobMenu->SetTool( selTool );
104  openRecentJobMenu->SetTitle( _( "Open Recent Job File" ) );
105  openRecentJobMenu->SetIcon( recent_xpm );
106 
107  m_jobFileHistory.UseMenu( openRecentJobMenu );
108  m_jobFileHistory.SetClearText( _( "Clear Recent Job Files" ) );
110  }
111 
112  fileMenu->Add( GERBVIEW_ACTIONS::openJobFile );
113  wxMenuItem* jobItem = fileMenu->Add( openRecentJobMenu );
115 
116 
117  // Create the zip file menu if it does not exist. Adding a file to/from the history
118  // will automatically refresh the menu.
119  if( !openRecentZipMenu )
120  {
121  openRecentZipMenu = new ACTION_MENU( false );
122  openRecentZipMenu->SetTool( selTool );
123  openRecentZipMenu->SetTitle( _( "Open Recent Zip File" ) );
124  openRecentZipMenu->SetIcon( recent_xpm );
125 
126  m_zipFileHistory.UseMenu( openRecentZipMenu );
127  m_zipFileHistory.SetClearText( _( "Clear Recent Zip Files" ) );
129  }
130 
131  fileMenu->Add( GERBVIEW_ACTIONS::openZipFile );
132  wxMenuItem* zipItem = fileMenu->Add( openRecentZipMenu );
134 
135 #undef FileHistoryCond
136 
137  fileMenu->AppendSeparator();
140 
141  fileMenu->AppendSeparator();
143 
144  fileMenu->AppendSeparator();
145  fileMenu->Add( ACTIONS::print );
146 
147  fileMenu->AppendSeparator();
148  fileMenu->AddQuitOrClose( &Kiface(), _( "GerbView" ) );
149 
150 
151  //-- View menu -------------------------------------------------------
152  //
153  ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
154 
156 
157  viewMenu->AppendSeparator();
158  viewMenu->Add( ACTIONS::zoomInCenter );
159  viewMenu->Add( ACTIONS::zoomOutCenter );
160  viewMenu->Add( ACTIONS::zoomFitScreen );
161  viewMenu->Add( ACTIONS::zoomTool );
162  viewMenu->Add( ACTIONS::zoomRedraw );
163 
164  viewMenu->AppendSeparator();
167 
168 #ifdef __APPLE__
169  // Add a separator only on macOS because the OS adds menu items to the view menu after ours
170  viewMenu->AppendSeparator();
171 #endif
172 
173  // Units submenu
174  ACTION_MENU* unitsSubMenu = new ACTION_MENU( false, selTool );
175 
176  unitsSubMenu->SetTitle( _( "&Units" ) );
177  unitsSubMenu->SetIcon( unit_mm_xpm );
178  unitsSubMenu->Add( ACTIONS::inchesUnits, ACTION_MENU::CHECK );
179  unitsSubMenu->Add( ACTIONS::milsUnits, ACTION_MENU::CHECK );
181 
182  viewMenu->Add( unitsSubMenu );
183 
184  viewMenu->AppendSeparator();
193 
194 
195  //-- Tools menu -------------------------------------------------------
196  //
197  ACTION_MENU* toolsMenu = new ACTION_MENU( false, selTool );
198 
199  toolsMenu->Add( GERBVIEW_ACTIONS::showDCodes );
200  toolsMenu->Add( GERBVIEW_ACTIONS::showSource );
201 
202  toolsMenu->Add( ACTIONS::measureTool );
203 
204  toolsMenu->AppendSeparator();
205  toolsMenu->Add( GERBVIEW_ACTIONS::clearLayer );
206 
207 
208  //-- Preferences menu -----------------------------------------------
209  //
210  ACTION_MENU* preferencesMenu = new ACTION_MENU( false, selTool );
211 
212  preferencesMenu->Add( _( "Preferences...\tCTRL+," ),
213  _( "Show preferences for all open tools" ),
214  wxID_PREFERENCES,
215  preference_xpm );
216 
217  preferencesMenu->AppendSeparator();
218  AddMenuLanguageList( preferencesMenu, selTool );
219 
220 #ifndef __WXMAC__
221  preferencesMenu->AppendSeparator();
223  preferencesMenu->Add( ACTIONS::standardGraphics, ACTION_MENU::CHECK );
224 #endif
225 
226 
227  //-- Menubar -------------------------------------------------------------
228  //
229  menuBar->Append( fileMenu, _( "&File" ) );
230  menuBar->Append( viewMenu, _( "&View" ) );
231  menuBar->Append( toolsMenu, _( "&Tools" ) );
232  menuBar->Append( preferencesMenu, _( "&Preferences" ) );
233  AddStandardHelpMenu( menuBar );
234 
235  // Associate the menu bar with the frame, if no previous menubar
236  SetMenuBar( menuBar );
237  delete oldMenuBar;
238 }
void AddFilesToMenu() override
Add the files to all registered menus.
Definition: filehistory.h:98
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
Adds a wxWidgets-style entry to the menu.
static TOOL_ACTION openDrillFile
static TOOL_ACTION zoomInCenter
Definition: actions.h:91
static TOOL_ACTION openGerber
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:43
static TOOL_ACTION showSource
static TOOL_ACTION zoomTool
Definition: actions.h:97
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:94
static TOOL_ACTION millimetersUnits
Definition: actions.h:144
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
static TOOL_ACTION standardGraphics
Definition: actions.h:164
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:92
const BITMAP_OPAQUE recent_xpm[1]
Definition: recent.cpp:68
void SetTool(TOOL_INTERACTIVE *aTool)
Sets a tool that is the creator of the menu.
static TOOL_ACTION toggleDiffMode
FILE_HISTORY m_zipFileHistory
static TOOL_ACTION measureTool
Definition: actions.h:152
static TOOL_ACTION flipGerberView
static TOOL_ACTION toggleGrid
Definition: actions.h:138
static TOOL_ACTION inchesUnits
Definition: actions.h:142
static TOOL_ACTION linesDisplayOutlines
void SetIcon(const BITMAP_OPAQUE *aIcon)
Assigns an icon for the entry.
Definition: action_menu.cpp:71
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:147
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:143
const BITMAP_OPAQUE unit_mm_xpm[1]
Definition: unit_mm.cpp:26
static TOOL_ACTION flashedDisplayOutlines
static TOOL_ACTION clearLayer
GERBVIEW_SELECTION_TOOL.
static constexpr bool CHECK
Definition: action_menu.h:162
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
void SetTitle(const wxString &aTitle) override
Sets title for the menu.
Definition: action_menu.cpp:89
see class PGM_BASE
FILE_HISTORY & GetFileHistory()
Get the frame's main file history.
void AddQuitOrClose(KIFACE_I *aKiface, wxString aAppname="")
Adds either a standard Quit or Close item to the menu.
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION zoomRedraw
Definition: actions.h:88
static TOOL_ACTION polygonsDisplayOutlines
static TOOL_ACTION acceleratedGraphics
Definition: actions.h:163
void ReCreateMenuBar() override
Recreates the menu bar.
const BITMAP_OPAQUE preference_xpm[1]
Definition: preference.cpp:53
static TOOL_ACTION showDCodes
static TOOL_ACTION highContrastMode
Definition: actions.h:101
static TOOL_ACTION reloadAllLayers
static TOOL_ACTION openZipFile