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-2021 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 <filehistory.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->SetTitle( _( "Open Recent" ) );
66  openRecentMenu->SetIcon( BITMAPS::recent );
67 
68  fileHistory.UseMenu( openRecentMenu );
69  fileHistory.AddFilesToMenu( openRecentMenu );
70  }
71 
72  fileMenu->Add( ACTIONS::doNew );
73  fileMenu->Add( ACTIONS::open );
74 
75  wxMenuItem* item = fileMenu->Add( openRecentMenu );
76 
77  // Add the file menu condition here since it needs the item ID for the submenu
78  ACTION_CONDITIONS cond;
79  cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
80  RegisterUIUpdateHandler( item->GetId(), cond );
81  fileMenu->AppendSeparator();
82  }
83 
84  fileMenu->Add( ACTIONS::save );
85 
86  if( Kiface().IsSingle() )
87  fileMenu->Add( ACTIONS::saveAs );
88  else
90 
91  fileMenu->AppendSeparator();
92 
93  fileMenu->Add( _( "Insert Schematic Sheet Content..." ),
94  _( "Append schematic sheet content from another project to the current sheet" ),
97 
98  fileMenu->AppendSeparator();
99 
100  // Import submenu
101  ACTION_MENU* submenuImport = new ACTION_MENU( false, selTool );
102  submenuImport->SetTitle( _( "Import" ) );
103  submenuImport->SetIcon( BITMAPS::import );
104  submenuImport->Add( _( "Non-KiCad Schematic..." ),
105  _( "Replace current schematic sheet with one imported from another application" ),
108 
109  submenuImport->Add( EE_ACTIONS::importFPAssignments, ACTION_MENU::NORMAL, _( "Footprint Assignments..." ) );
110  fileMenu->Add( submenuImport );
111 
112 
113  // Export submenu
114  ACTION_MENU* submenuExport = new ACTION_MENU( false, selTool );
115  submenuExport->SetTitle( _( "Export" ) );
116  submenuExport->SetIcon( BITMAPS::export_file );
117  submenuExport->Add( EE_ACTIONS::drawSheetOnClipboard, ACTION_MENU::NORMAL, _( "Drawing to Clipboard" ) );
118  submenuExport->Add( EE_ACTIONS::exportNetlist, ACTION_MENU::NORMAL, _( "Netlist..." ) );
119  fileMenu->Add( submenuExport );
120 
121  fileMenu->AppendSeparator();
122  fileMenu->Add( EE_ACTIONS::schematicSetup );
123 
124  fileMenu->AppendSeparator();
125  fileMenu->Add( ACTIONS::pageSettings );
126  fileMenu->Add( ACTIONS::print );
127  fileMenu->Add( ACTIONS::plot );
128 
129  fileMenu->AppendSeparator();
130  fileMenu->AddQuitOrClose( &Kiface(), _( "Schematic Editor" ) );
131 
132 
133  //-- Edit menu -----------------------------------------------------------
134  //
135  ACTION_MENU* editMenu = new ACTION_MENU( false, selTool );
136 
137  editMenu->Add( ACTIONS::undo );
138  editMenu->Add( ACTIONS::redo );
139 
140  editMenu->AppendSeparator();
141  editMenu->Add( ACTIONS::cut );
142  editMenu->Add( ACTIONS::copy );
143  editMenu->Add( ACTIONS::paste );
144  editMenu->Add( ACTIONS::pasteSpecial );
145  editMenu->Add( ACTIONS::doDelete );
146 
147  editMenu->AppendSeparator();
148  editMenu->Add( ACTIONS::selectAll );
149 
150  editMenu->AppendSeparator();
151  editMenu->Add( ACTIONS::find );
152  editMenu->Add( ACTIONS::findAndReplace );
153 
154  editMenu->AppendSeparator();
155  editMenu->Add( ACTIONS::deleteTool );
157  editMenu->Add( EE_ACTIONS::changeSymbols );
158  editMenu->Add( EE_ACTIONS::editPageNumber );
159 
160  //-- View menu -----------------------------------------------------------
161  //
162  ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
163 
164  viewMenu->Add( ACTIONS::showSymbolBrowser );
165  viewMenu->Add( EE_ACTIONS::navigateHierarchy );
166  viewMenu->Add( EE_ACTIONS::leaveSheet );
167 
168  viewMenu->AppendSeparator();
169  viewMenu->Add( ACTIONS::zoomInCenter );
170  viewMenu->Add( ACTIONS::zoomOutCenter );
171  viewMenu->Add( ACTIONS::zoomFitScreen );
172  viewMenu->Add( ACTIONS::zoomFitObjects );
173  viewMenu->Add( ACTIONS::zoomTool );
174  viewMenu->Add( ACTIONS::zoomRedraw );
175 
176  viewMenu->AppendSeparator();
178  viewMenu->Add( ACTIONS::gridProperties );
179 
180  // Units submenu
181  ACTION_MENU* unitsSubMenu = new ACTION_MENU( false, selTool );
182  unitsSubMenu->SetTitle( _( "&Units" ) );
183  unitsSubMenu->SetIcon( BITMAPS::unit_mm );
184  unitsSubMenu->Add( ACTIONS::inchesUnits, ACTION_MENU::CHECK );
185  unitsSubMenu->Add( ACTIONS::milsUnits, ACTION_MENU::CHECK );
187  viewMenu->Add( unitsSubMenu );
188 
190 
191  viewMenu->AppendSeparator();
193 
194 #ifdef __APPLE__
195  viewMenu->AppendSeparator();
196 #endif
197 
198  //-- Place menu -----------------------------------------------------------
199  //
200  ACTION_MENU* placeMenu = new ACTION_MENU( false, selTool );
201 
202  placeMenu->Add( EE_ACTIONS::placeSymbol );
203  placeMenu->Add( EE_ACTIONS::placePower );
204  placeMenu->Add( EE_ACTIONS::drawWire );
205  placeMenu->Add( EE_ACTIONS::drawBus );
206  placeMenu->Add( EE_ACTIONS::placeBusWireEntry );
207  placeMenu->Add( EE_ACTIONS::placeNoConnect );
208  placeMenu->Add( EE_ACTIONS::placeJunction );
209  placeMenu->Add( EE_ACTIONS::placeLabel );
210  placeMenu->Add( EE_ACTIONS::placeGlobalLabel );
211 
212  placeMenu->AppendSeparator();
213  placeMenu->Add( EE_ACTIONS::placeHierLabel );
214  placeMenu->Add( EE_ACTIONS::drawSheet );
215  placeMenu->Add( EE_ACTIONS::importSheetPin );
216 
217  placeMenu->AppendSeparator();
218  placeMenu->Add( EE_ACTIONS::drawLines );
219  placeMenu->Add( EE_ACTIONS::placeSchematicText );
220  placeMenu->Add( EE_ACTIONS::placeImage );
221 
222 
223  //-- Inspect menu -----------------------------------------------
224  //
225  ACTION_MENU* inspectMenu = new ACTION_MENU( false, selTool );
226 
227  inspectMenu->Add( EE_ACTIONS::runERC );
228  inspectMenu->Add( ACTIONS::prevMarker );
229  inspectMenu->Add( ACTIONS::nextMarker );
230  inspectMenu->Add( ACTIONS::excludeMarker );
231 
232 #ifdef KICAD_SPICE
233  inspectMenu->AppendSeparator();
234  inspectMenu->Add( EE_ACTIONS::runSimulation );
235 #endif
236 
237 
238  //-- Tools menu -----------------------------------------------
239  //
240  ACTION_MENU* toolsMenu = new ACTION_MENU( false, selTool );
241 
242  wxMenuItem* update = toolsMenu->Add( ACTIONS::updatePcbFromSchematic );
243  update->Enable( !Kiface().IsSingle() );
244  update = toolsMenu->Add( ACTIONS::updateSchematicFromPcb );
245  update->Enable( !Kiface().IsSingle() );
246 
247  toolsMenu->Add( EE_ACTIONS::showPcbNew );
248 
249  toolsMenu->AppendSeparator();
250  toolsMenu->Add( ACTIONS::showSymbolEditor );
251  toolsMenu->Add( EE_ACTIONS::updateSymbols );
252 
253  toolsMenu->AppendSeparator();
254  toolsMenu->Add( EE_ACTIONS::rescueSymbols );
255  toolsMenu->Add( EE_ACTIONS::remapSymbols );
256 
257  if( ADVANCED_CFG::GetCfg().m_ShowRepairSchematic )
258  toolsMenu->Add( EE_ACTIONS::repairSchematic );
259 
260  toolsMenu->AppendSeparator();
261  toolsMenu->Add( EE_ACTIONS::editSymbolFields );
263 
264  toolsMenu->AppendSeparator();
265  toolsMenu->Add( EE_ACTIONS::annotate );
266  toolsMenu->Add( EE_ACTIONS::showBusManager );
267 
268  toolsMenu->AppendSeparator();
269  toolsMenu->Add( EE_ACTIONS::assignFootprints );
270  toolsMenu->Add( EE_ACTIONS::generateBOM );
271 
272 
273  //-- Preferences menu -----------------------------------------------
274  //
275  ACTION_MENU* prefsMenu = new ACTION_MENU( false, selTool );
276 
277  prefsMenu->Add( ACTIONS::configurePaths );
278  prefsMenu->Add( ACTIONS::showSymbolLibTable );
279 
280  // We can't use ACTIONS::showPreferences yet because wxWidgets moves this on
281  // Mac, and it needs the wxID_PREFERENCES id to find it.
282  prefsMenu->Add( _( "Preferences..." ) + "\tCtrl+,",
283  _( "Show preferences for all open tools" ),
284  wxID_PREFERENCES,
286 
287  prefsMenu->AppendSeparator();
288  AddMenuLanguageList( prefsMenu, selTool );
289 
290 
291  //-- Menubar -------------------------------------------------------------
292  //
293  menuBar->Append( fileMenu, _( "&File" ) );
294  menuBar->Append( editMenu, _( "&Edit" ) );
295  menuBar->Append( viewMenu, _( "&View" ) );
296  menuBar->Append( placeMenu, _( "&Place" ) );
297  menuBar->Append( inspectMenu, _( "&Inspect" ) );
298  menuBar->Append( toolsMenu, _( "&Tools" ) );
299  menuBar->Append( prefsMenu, _( "P&references" ) );
300  AddStandardHelpMenu( menuBar );
301 
302  SetMenuBar( menuBar );
303  delete oldMenuBar;
304 }
305 
306 
static TOOL_ACTION editPageNumber
Definition: ee_actions.h:154
void AddFilesToMenu() override
Add the files to all registered menus.
Definition: filehistory.h:98
static TOOL_ACTION rescueSymbols
Definition: ee_actions.h:157
static TOOL_ACTION findAndReplace
Definition: actions.h:77
static TOOL_ACTION exportNetlist
Definition: ee_actions.h:165
static TOOL_ACTION navigateHierarchy
Definition: ee_actions.h:186
static TOOL_ACTION assignFootprints
Definition: ee_actions.h:150
static TOOL_ACTION zoomInCenter
Definition: actions.h:93
static TOOL_ACTION pageSettings
Definition: actions.h:56
static TOOL_ACTION runERC
Definition: ee_actions.h:140
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
static TOOL_ACTION doDelete
Definition: actions.h:72
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 zoomTool
Definition: actions.h:99
void ReCreateMenuBar() override
Recreates the menu bar.
static TOOL_ACTION placeHierLabel
Definition: ee_actions.h:87
static TOOL_ACTION placeJunction
Definition: ee_actions.h:83
static TOOL_ACTION nextMarker
Definition: actions.h:86
static TOOL_ACTION remapSymbols
Definition: ee_actions.h:158
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 showSymbolLibTable
Definition: actions.h:175
static TOOL_ACTION updatePcbFromSchematic
Definition: actions.h:163
static TOOL_ACTION placeBusWireEntry
Definition: ee_actions.h:84
static TOOL_ACTION updateSymbols
Definition: ee_actions.h:147
static constexpr bool NORMAL
Definition: action_menu.h:182
static TOOL_ACTION zoomFitObjects
Definition: actions.h:97
static TOOL_ACTION print
Definition: actions.h:57
static TOOL_ACTION excludeMarker
Definition: actions.h:87
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 find
Definition: actions.h:76
static TOOL_ACTION saveCurrSheetCopyAs
Definition: ee_actions.h:42
static TOOL_ACTION zoomOutCenter
Definition: actions.h:94
ACTION_CONDITIONS & Enable(const SELECTION_CONDITION &aCondition)
static TOOL_ACTION leaveSheet
Definition: ee_actions.h:185
static TOOL_ACTION runSimulation
Definition: ee_actions.h:214
static TOOL_ACTION annotate
Definition: ee_actions.h:141
static TOOL_ACTION drawSheet
Definition: ee_actions.h:88
static TOOL_ACTION showPcbNew
Definition: ee_actions.h:163
static TOOL_ACTION copy
Definition: actions.h:67
static TOOL_ACTION showBusManager
Definition: ee_actions.h:152
static TOOL_ACTION updateSchematicFromPcb
Definition: actions.h:164
static TOOL_ACTION editSymbolFields
Definition: ee_actions.h:142
static TOOL_ACTION placePower
Definition: ee_actions.h:78
static TOOL_ACTION drawWire
Definition: ee_actions.h:79
static TOOL_ACTION toggleGrid
Definition: actions.h:140
static TOOL_ACTION open
Definition: actions.h:50
static TOOL_ACTION inchesUnits
Definition: actions.h:144
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION placeSchematicText
Definition: ee_actions.h:90
static TOOL_ACTION doNew
Definition: actions.h:44
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
static TOOL_ACTION placeImage
Definition: ee_actions.h:92
static TOOL_ACTION cut
Definition: actions.h:66
#define _(s)
static TOOL_ACTION plot
Definition: actions.h:58
static TOOL_ACTION importSheetPin
Definition: ee_actions.h:89
static TOOL_ACTION placeSymbol
Definition: ee_actions.h:77
void AddMenuLanguageList(ACTION_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
static TOOL_ACTION editTextAndGraphics
Definition: ee_actions.h:192
static TOOL_ACTION milsUnits
Definition: actions.h:145
static TOOL_ACTION drawBus
Definition: ee_actions.h:80
static TOOL_ACTION prevMarker
Definition: actions.h:85
static TOOL_ACTION pasteSpecial
Definition: actions.h:69
static TOOL_ACTION placeLabel
Definition: ee_actions.h:85
static TOOL_ACTION redo
Definition: actions.h:65
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 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...
static TOOL_ACTION showSymbolEditor
Definition: actions.h:160
static TOOL_ACTION saveAs
Definition: actions.h:52
static TOOL_ACTION toggleHiddenPins
Definition: ee_actions.h:195
static TOOL_ACTION zoomRedraw
Definition: actions.h:90
static TOOL_ACTION importFPAssignments
Definition: ee_actions.h:164
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
static TOOL_ACTION placeNoConnect
Definition: ee_actions.h:82
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
static TOOL_ACTION changeSymbols
Definition: ee_actions.h:146
static TOOL_ACTION drawSheetOnClipboard
Definition: ee_actions.h:207
static TOOL_ACTION repairSchematic
Definition: ee_actions.h:211
static TOOL_ACTION gridProperties
Definition: actions.h:141
static TOOL_ACTION deleteTool
Definition: actions.h:73
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
static TOOL_ACTION undo
Definition: actions.h:64
static TOOL_ACTION generateBOM
Definition: ee_actions.h:166
static TOOL_ACTION drawLines
Definition: ee_actions.h:91
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:102
static TOOL_ACTION schematicSetup
Definition: ee_actions.h:153
static TOOL_ACTION showSymbolBrowser
Definition: actions.h:159
void AddQuitOrClose(KIFACE_BASE *aKiface, wxString aAppname="")
Add either a standard Quit or Close item to the menu.
static TOOL_ACTION placeGlobalLabel
Definition: ee_actions.h:86
static TOOL_ACTION editSymbolLibraryLinks
Definition: ee_actions.h:143
static TOOL_ACTION configurePaths
Definition: actions.h:174
static TOOL_ACTION selectAll
Definition: actions.h:70
static TOOL_ACTION paste
Definition: actions.h:68