KiCad PCB EDA Suite
eeschema/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) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2009 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
7 * Copyright (C) 2019 CERN
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#include <bitmaps.h>
28#include <file_history.h>
29#include <kiface_base.h>
30#include <menus_helpers.h>
31#include <schematic.h>
32#include <tool/action_manager.h>
33#include <tool/action_menu.h>
34#include <tool/tool_manager.h>
36#include <tools/ee_actions.h>
37#include "eeschema_id.h"
38#include "sch_edit_frame.h"
39#include <widgets/wx_menubar.h>
40#include <advanced_config.h>
41
42
44{
46 // wxWidgets handles the Mac Application menu behind the scenes, but that means
47 // we always have to start from scratch with a new wxMenuBar.
48 wxMenuBar* oldMenuBar = GetMenuBar();
49 WX_MENUBAR* menuBar = new WX_MENUBAR();
50
51 //-- File menu -----------------------------------------------------------
52 //
53 ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
54 static ACTION_MENU* openRecentMenu;
55
56 if( Kiface().IsSingle() ) // When not under a project mgr
57 {
58 FILE_HISTORY& fileHistory = GetFileHistory();
59
60 // Add this menu to the list of menus managed by the file history
61 // (the file history will be updated when adding/removing files in history)
62 if( !openRecentMenu )
63 {
64 openRecentMenu = new ACTION_MENU( false, selTool );
65 openRecentMenu->SetIcon( BITMAPS::recent );
66
67 fileHistory.UseMenu( openRecentMenu );
68 fileHistory.AddFilesToMenu( openRecentMenu );
69 }
70
71 // Ensure the title is up to date after changing language
72 openRecentMenu->SetTitle( _( "Open Recent" ) );
73 fileHistory.UpdateClearText( openRecentMenu, _( "Clear Recent Files" ) );
74
75 fileMenu->Add( ACTIONS::doNew );
76 fileMenu->Add( ACTIONS::open );
77
78 wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() );
79
80 // Add the file menu condition here since it needs the item ID for the submenu
82 cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
83 RegisterUIUpdateHandler( item->GetId(), cond );
84 fileMenu->AppendSeparator();
85 }
86
87 fileMenu->Add( ACTIONS::save );
88
89 if( Kiface().IsSingle() )
90 fileMenu->Add( ACTIONS::saveAs );
91 else
93
94 fileMenu->Add( ACTIONS::revert );
95
96 fileMenu->AppendSeparator();
97
98 fileMenu->Add( _( "Insert Schematic Sheet Content..." ),
99 _( "Append schematic sheet content from another project to the current sheet" ),
102
103 fileMenu->AppendSeparator();
104
105 // Import submenu
106 ACTION_MENU* submenuImport = new ACTION_MENU( false, selTool );
107 submenuImport->SetTitle( _( "Import" ) );
108 submenuImport->SetIcon( BITMAPS::import );
109 submenuImport->Add( _( "Non-KiCad Schematic..." ),
110 _( "Replace current schematic sheet with one imported from another application" ),
113
114 submenuImport->Add( EE_ACTIONS::importFPAssignments, ACTION_MENU::NORMAL, _( "Footprint Assignments..." ) );
115 fileMenu->Add( submenuImport );
116
117
118 // Export submenu
119 ACTION_MENU* submenuExport = new ACTION_MENU( false, selTool );
120 submenuExport->SetTitle( _( "Export" ) );
121 submenuExport->SetIcon( BITMAPS::export_file );
122 submenuExport->Add( EE_ACTIONS::drawSheetOnClipboard, ACTION_MENU::NORMAL, _( "Drawing to Clipboard" ) );
123 submenuExport->Add( EE_ACTIONS::exportNetlist, ACTION_MENU::NORMAL, _( "Netlist..." ) );
125 _( "Symbols to Library..." ) );
127 _( "Symbols to New Library..." ) );
128 fileMenu->Add( submenuExport );
129
130 fileMenu->AppendSeparator();
131 fileMenu->Add( EE_ACTIONS::schematicSetup );
132
133 fileMenu->AppendSeparator();
134 fileMenu->Add( ACTIONS::pageSettings );
135 fileMenu->Add( ACTIONS::print );
136 fileMenu->Add( ACTIONS::plot );
137
138 fileMenu->AppendSeparator();
139 fileMenu->AddQuitOrClose( &Kiface(), _( "Schematic Editor" ) );
140
141
142 //-- Edit menu -----------------------------------------------------------
143 //
144 ACTION_MENU* editMenu = new ACTION_MENU( false, selTool );
145
146 editMenu->Add( ACTIONS::undo );
147 editMenu->Add( ACTIONS::redo );
148
149 editMenu->AppendSeparator();
150 editMenu->Add( ACTIONS::cut );
151 editMenu->Add( ACTIONS::copy );
152 editMenu->Add( ACTIONS::paste );
153 editMenu->Add( ACTIONS::pasteSpecial );
154 editMenu->Add( ACTIONS::doDelete );
155
156 editMenu->AppendSeparator();
157 editMenu->Add( ACTIONS::selectAll );
158
159 editMenu->AppendSeparator();
160 editMenu->Add( ACTIONS::find );
161 editMenu->Add( ACTIONS::findAndReplace );
162
163 editMenu->AppendSeparator();
164 editMenu->Add( ACTIONS::deleteTool );
166 editMenu->Add( EE_ACTIONS::changeSymbols );
167 editMenu->Add( EE_ACTIONS::editPageNumber );
168
169 //-- View menu -----------------------------------------------------------
170 //
171 ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
172
173 viewMenu->Add( ACTIONS::showSymbolBrowser );
175 viewMenu->Add( EE_ACTIONS::navigateBack );
176 viewMenu->Add( EE_ACTIONS::navigateUp );
177 viewMenu->Add( EE_ACTIONS::navigateForward );
179 viewMenu->Add( EE_ACTIONS::navigateNext );
180
181 viewMenu->AppendSeparator();
182 viewMenu->Add( ACTIONS::zoomInCenter );
183 viewMenu->Add( ACTIONS::zoomOutCenter );
184 viewMenu->Add( ACTIONS::zoomFitScreen );
185 viewMenu->Add( ACTIONS::zoomFitObjects );
186 viewMenu->Add( ACTIONS::zoomTool );
187 viewMenu->Add( ACTIONS::zoomRedraw );
188
189 viewMenu->AppendSeparator();
191 viewMenu->Add( ACTIONS::gridProperties );
192
193 // Units submenu
194 ACTION_MENU* unitsSubMenu = new ACTION_MENU( false, selTool );
195 unitsSubMenu->SetTitle( _( "&Units" ) );
196 unitsSubMenu->SetIcon( BITMAPS::unit_mm );
198 unitsSubMenu->Add( ACTIONS::milsUnits, ACTION_MENU::CHECK );
200 viewMenu->Add( unitsSubMenu );
201
203
204 viewMenu->AppendSeparator();
210
211#ifdef __APPLE__
212 viewMenu->AppendSeparator();
213#endif
214
215 //-- Place menu -----------------------------------------------------------
216 //
217 ACTION_MENU* placeMenu = new ACTION_MENU( false, selTool );
218
219 placeMenu->Add( EE_ACTIONS::placeSymbol );
220 placeMenu->Add( EE_ACTIONS::placePower );
221 placeMenu->Add( EE_ACTIONS::drawWire );
222 placeMenu->Add( EE_ACTIONS::drawBus );
224 placeMenu->Add( EE_ACTIONS::placeNoConnect );
225 placeMenu->Add( EE_ACTIONS::placeJunction );
226 placeMenu->Add( EE_ACTIONS::placeLabel );
227 placeMenu->Add( EE_ACTIONS::placeClassLabel );
228 placeMenu->Add( EE_ACTIONS::placeGlobalLabel );
229
230 placeMenu->AppendSeparator();
231 placeMenu->Add( EE_ACTIONS::placeHierLabel );
232 placeMenu->Add( EE_ACTIONS::drawSheet );
233 placeMenu->Add( EE_ACTIONS::importSheetPin );
234
235 placeMenu->AppendSeparator();
237 placeMenu->Add( EE_ACTIONS::drawTextBox );
238 placeMenu->Add( EE_ACTIONS::drawRectangle );
239 placeMenu->Add( EE_ACTIONS::drawCircle );
240 placeMenu->Add( EE_ACTIONS::drawArc );
241 placeMenu->Add( EE_ACTIONS::drawLines );
242 placeMenu->Add( EE_ACTIONS::placeImage );
243
244
245 //-- Inspect menu -----------------------------------------------
246 //
247 ACTION_MENU* inspectMenu = new ACTION_MENU( false, selTool );
248
249 inspectMenu->Add( EE_ACTIONS::runERC );
250 inspectMenu->Add( ACTIONS::prevMarker );
251 inspectMenu->Add( ACTIONS::nextMarker );
252 inspectMenu->Add( ACTIONS::excludeMarker );
253
254#ifdef KICAD_SPICE
255 inspectMenu->AppendSeparator();
256 inspectMenu->Add( EE_ACTIONS::runSimulation );
257#endif
258
259
260 //-- Tools menu -----------------------------------------------
261 //
262 ACTION_MENU* toolsMenu = new ACTION_MENU( false, selTool );
263
264 wxMenuItem* update = toolsMenu->Add( ACTIONS::updatePcbFromSchematic );
265 update->Enable( !Kiface().IsSingle() );
266
267 toolsMenu->Add( EE_ACTIONS::showPcbNew );
268
269 toolsMenu->AppendSeparator();
270 toolsMenu->Add( ACTIONS::showSymbolEditor );
271 toolsMenu->Add( EE_ACTIONS::updateSymbols );
272
273 toolsMenu->AppendSeparator();
274 toolsMenu->Add( EE_ACTIONS::rescueSymbols );
275 toolsMenu->Add( EE_ACTIONS::remapSymbols );
276
277 if( ADVANCED_CFG::GetCfg().m_ShowRepairSchematic )
278 toolsMenu->Add( EE_ACTIONS::repairSchematic );
279
280 toolsMenu->AppendSeparator();
281 toolsMenu->Add( EE_ACTIONS::editSymbolFields );
283
284 toolsMenu->AppendSeparator();
285 toolsMenu->Add( EE_ACTIONS::annotate );
286
287 toolsMenu->AppendSeparator();
288 toolsMenu->Add( EE_ACTIONS::assignFootprints );
289 toolsMenu->Add( EE_ACTIONS::generateBOM );
290
291 toolsMenu->AppendSeparator();
292 update = toolsMenu->Add( ACTIONS::updateSchematicFromPcb );
293 update->Enable( !Kiface().IsSingle() );
294
295 //-- Preferences menu -----------------------------------------------
296 //
297 ACTION_MENU* prefsMenu = new ACTION_MENU( false, selTool );
298
299 prefsMenu->Add( ACTIONS::configurePaths );
300 prefsMenu->Add( ACTIONS::showSymbolLibTable );
301
302 // We can't use ACTIONS::showPreferences yet because wxWidgets moves this on
303 // Mac, and it needs the wxID_PREFERENCES id to find it.
304 prefsMenu->Add( _( "Preferences..." ) + "\tCtrl+,",
305 _( "Show preferences for all open tools" ),
306 wxID_PREFERENCES,
308
309 prefsMenu->AppendSeparator();
310 AddMenuLanguageList( prefsMenu, selTool );
311
312
313 //-- Menubar -------------------------------------------------------------
314 //
315 menuBar->Append( fileMenu, _( "&File" ) );
316 menuBar->Append( editMenu, _( "&Edit" ) );
317 menuBar->Append( viewMenu, _( "&View" ) );
318 menuBar->Append( placeMenu, _( "&Place" ) );
319 menuBar->Append( inspectMenu, _( "&Inspect" ) );
320 menuBar->Append( toolsMenu, _( "&Tools" ) );
321 menuBar->Append( prefsMenu, _( "P&references" ) );
322 AddStandardHelpMenu( menuBar );
323
324 SetMenuBar( menuBar );
325 delete oldMenuBar;
326}
327
328
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
@ import_document
@ add_document
static TOOL_ACTION gridProperties
Definition: actions.h:144
static TOOL_ACTION updatePcbFromSchematic
Definition: actions.h:167
static TOOL_ACTION toggleGrid
Definition: actions.h:143
static TOOL_ACTION paste
Definition: actions.h:69
static TOOL_ACTION excludeMarker
Definition: actions.h:89
static TOOL_ACTION nextMarker
Definition: actions.h:88
static TOOL_ACTION zoomRedraw
Definition: actions.h:92
static TOOL_ACTION millimetersUnits
Definition: actions.h:149
static TOOL_ACTION revert
Definition: actions.h:55
static TOOL_ACTION zoomOutCenter
Definition: actions.h:96
static TOOL_ACTION saveAs
Definition: actions.h:52
static TOOL_ACTION copy
Definition: actions.h:68
static TOOL_ACTION showSymbolLibTable
Definition: actions.h:180
static TOOL_ACTION showSymbolEditor
Definition: actions.h:164
static TOOL_ACTION showSymbolBrowser
Definition: actions.h:163
static TOOL_ACTION pasteSpecial
Definition: actions.h:70
static TOOL_ACTION findAndReplace
Definition: actions.h:79
static TOOL_ACTION milsUnits
Definition: actions.h:148
static TOOL_ACTION plot
Definition: actions.h:58
static TOOL_ACTION open
Definition: actions.h:50
static TOOL_ACTION pageSettings
Definition: actions.h:56
static TOOL_ACTION undo
Definition: actions.h:65
static TOOL_ACTION prevMarker
Definition: actions.h:87
static TOOL_ACTION inchesUnits
Definition: actions.h:147
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:104
static TOOL_ACTION doDelete
Definition: actions.h:73
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION zoomFitScreen
Definition: actions.h:98
static TOOL_ACTION redo
Definition: actions.h:66
static TOOL_ACTION deleteTool
Definition: actions.h:74
static TOOL_ACTION zoomTool
Definition: actions.h:101
static TOOL_ACTION updateSchematicFromPcb
Definition: actions.h:168
static TOOL_ACTION print
Definition: actions.h:57
static TOOL_ACTION doNew
Definition: actions.h:47
static TOOL_ACTION zoomFitObjects
Definition: actions.h:99
static TOOL_ACTION zoomInCenter
Definition: actions.h:95
static TOOL_ACTION cut
Definition: actions.h:67
static TOOL_ACTION configurePaths
Definition: actions.h:179
static TOOL_ACTION selectAll
Definition: actions.h:71
static TOOL_ACTION find
Definition: actions.h:78
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
void AddQuitOrClose(KIFACE_BASE *aKiface, wxString aAppname="")
Add either a standard Quit or Close item to the menu.
static constexpr bool CHECK
Definition: action_menu.h:189
ACTION_MENU * Clone() const
Create a deep, recursive copy of this ACTION_MENU.
void SetTitle(const wxString &aTitle) override
Set title for the menu.
Definition: action_menu.cpp:87
static constexpr bool NORMAL
Definition: action_menu.h:188
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition: action_menu.cpp:73
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
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)
Adds the standard KiCad help menu to the menubar.
static TOOL_ACTION importFPAssignments
Definition: ee_actions.h:173
static TOOL_ACTION repairSchematic
Definition: ee_actions.h:232
static TOOL_ACTION remapSymbols
Definition: ee_actions.h:167
static TOOL_ACTION runERC
Definition: ee_actions.h:150
static TOOL_ACTION toggleHiddenPins
Definition: ee_actions.h:213
static TOOL_ACTION navigateForward
Definition: ee_actions.h:201
static TOOL_ACTION placeSymbol
Definition: ee_actions.h:79
static TOOL_ACTION navigateBack
Definition: ee_actions.h:202
static TOOL_ACTION toggleERCWarnings
Definition: ee_actions.h:215
static TOOL_ACTION toggleERCExclusions
Definition: ee_actions.h:217
static TOOL_ACTION placeClassLabel
Definition: ee_actions.h:88
static TOOL_ACTION drawWire
Definition: ee_actions.h:81
static TOOL_ACTION drawCircle
Definition: ee_actions.h:96
static TOOL_ACTION drawBus
Definition: ee_actions.h:82
static TOOL_ACTION toggleERCErrors
Definition: ee_actions.h:216
static TOOL_ACTION placePower
Definition: ee_actions.h:80
static TOOL_ACTION drawLines
Definition: ee_actions.h:98
static TOOL_ACTION importSheetPin
Definition: ee_actions.h:92
static TOOL_ACTION exportNetlist
Definition: ee_actions.h:174
static TOOL_ACTION assignFootprints
Definition: ee_actions.h:160
static TOOL_ACTION rescueSymbols
Definition: ee_actions.h:166
static TOOL_ACTION toggleHiddenFields
Definition: ee_actions.h:214
static TOOL_ACTION placeGlobalLabel
Definition: ee_actions.h:89
static TOOL_ACTION exportSymbolsToLibrary
Definition: ee_actions.h:177
static TOOL_ACTION placeHierLabel
Definition: ee_actions.h:90
static TOOL_ACTION drawSheetOnClipboard
Definition: ee_actions.h:228
static TOOL_ACTION editSymbolFields
Definition: ee_actions.h:152
static TOOL_ACTION drawTextBox
Definition: ee_actions.h:94
static TOOL_ACTION editPageNumber
Definition: ee_actions.h:163
static TOOL_ACTION drawRectangle
Definition: ee_actions.h:95
static TOOL_ACTION annotate
Definition: ee_actions.h:151
static TOOL_ACTION placeImage
Definition: ee_actions.h:99
static TOOL_ACTION updateSymbols
Definition: ee_actions.h:157
static TOOL_ACTION showHierarchy
Definition: ee_actions.h:205
static TOOL_ACTION placeSchematicText
Definition: ee_actions.h:93
static TOOL_ACTION changeSymbols
Definition: ee_actions.h:156
static TOOL_ACTION drawArc
Definition: ee_actions.h:97
static TOOL_ACTION drawSheet
Definition: ee_actions.h:91
static TOOL_ACTION runSimulation
Definition: ee_actions.h:244
static TOOL_ACTION navigateNext
Definition: ee_actions.h:204
static TOOL_ACTION navigateUp
Definition: ee_actions.h:200
static TOOL_ACTION editSymbolLibraryLinks
Definition: ee_actions.h:153
static TOOL_ACTION placeLabel
Definition: ee_actions.h:87
static TOOL_ACTION saveCurrSheetCopyAs
Definition: ee_actions.h:42
static TOOL_ACTION editTextAndGraphics
Definition: ee_actions.h:210
static TOOL_ACTION showPcbNew
Definition: ee_actions.h:172
static TOOL_ACTION placeBusWireEntry
Definition: ee_actions.h:86
static TOOL_ACTION placeJunction
Definition: ee_actions.h:85
static TOOL_ACTION generateBOM
Definition: ee_actions.h:175
static TOOL_ACTION navigatePrevious
Definition: ee_actions.h:203
static TOOL_ACTION placeNoConnect
Definition: ee_actions.h:84
static TOOL_ACTION schematicSetup
Definition: ee_actions.h:162
static TOOL_ACTION exportSymbolsToNewLibrary
Definition: ee_actions.h:178
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: file_history.h:43
static SELECTION_CONDITION FileHistoryNotEmpty(const FILE_HISTORY &aHistory)
Create a SELECTION_CONDITION that can be used to enable a menu item when the file history has items i...
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.
Definition: file_history.h:98
void doReCreateMenuBar() override
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:170
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition: wx_menubar.h:46
#define _(s)
@ ID_IMPORT_NON_KICAD_SCH
Definition: eeschema_id.h:63
@ ID_APPEND_PROJECT
Definition: id.h:74
void AddMenuLanguageList(ACTION_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
Macros and inline functions to create menus items in menubars or popup menus.
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
ACTION_CONDITIONS & Enable(const SELECTION_CONDITION &aCondition)