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 <stambaughw@gmail.com>
6  * Copyright (C) 1992-2020 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 <filehistory.h>
28 #include <kiface_i.h>
29 #include <menus_helpers.h>
30 #include <pgm_base.h>
31 #include <schematic.h>
32 #include <tool/action_menu.h>
33 #include <tool/tool_manager.h>
35 #include <tools/ee_actions.h>
36 #include "eeschema_id.h"
37 #include "sch_edit_frame.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* openRecentMenu;
53 
54  if( Kiface().IsSingle() ) // When not under a project mgr
55  {
56  FILE_HISTORY& fileHistory = GetFileHistory();
57 
58  // Add this menu to the list of menus managed by the file history
59  // (the file history will be updated when adding/removing files in history)
60  if( !openRecentMenu )
61  {
62  openRecentMenu = new ACTION_MENU( false );
63  openRecentMenu->SetTool( selTool );
64  openRecentMenu->SetTitle( _( "Open Recent" ) );
65  openRecentMenu->SetIcon( recent_xpm );
66 
67  fileHistory.UseMenu( openRecentMenu );
68  fileHistory.AddFilesToMenu( openRecentMenu );
69  }
70 
71  fileMenu->Add( ACTIONS::doNew );
72  fileMenu->Add( ACTIONS::open );
73 
74  wxMenuItem* item = fileMenu->Add( openRecentMenu );
75 
76  // Add the file menu condition here since it needs the item ID for the submenu
77  ACTION_CONDITIONS cond;
78  cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
79  RegisterUIUpdateHandler( item->GetId(), cond );
80  fileMenu->AppendSeparator();
81  }
82 
83  fileMenu->Add( ACTIONS::save );
84  fileMenu->Add( ACTIONS::saveAs );
85 
86  fileMenu->AppendSeparator();
87 
88  fileMenu->Add( _( "Append Schematic Sheet Content..." ),
89  _( "Append schematic sheet content from another project to the current sheet" ),
92 
93  fileMenu->AppendSeparator();
94 
95  // Import submenu
96  ACTION_MENU* submenuImport = new ACTION_MENU( false );
97  submenuImport->SetTool( selTool );
98  submenuImport->SetTitle( _( "Import" ) );
99  submenuImport->SetIcon( import_xpm );
100  submenuImport->Add( _( "Import Non KiCad Schematic..." ),
101  _( "Replace current schematic sheet with one imported from another application" ),
104 
105  submenuImport->Add( EE_ACTIONS::importFPAssignments );
106  fileMenu->Add( submenuImport );
107 
108 
109  // Export submenu
110  ACTION_MENU* submenuExport = new ACTION_MENU( false );
111  submenuExport->SetTool( selTool );
112  submenuExport->SetTitle( _( "Export" ) );
113  submenuExport->SetIcon( export_xpm );
114  submenuExport->Add( EE_ACTIONS::drawSheetOnClipboard );
115  submenuExport->Add( EE_ACTIONS::exportNetlist );
116  fileMenu->Add( submenuExport );
117 
118  fileMenu->AppendSeparator();
119  fileMenu->Add( EE_ACTIONS::schematicSetup );
120 
121  fileMenu->AppendSeparator();
122  fileMenu->Add( ACTIONS::pageSettings );
123  fileMenu->Add( ACTIONS::print );
124  fileMenu->Add( ACTIONS::plot );
125 
126  fileMenu->AppendSeparator();
127  fileMenu->AddQuitOrClose( &Kiface(), _( "Eeschema" ) );
128 
129 
130  //-- Edit menu -----------------------------------------------------------
131  //
132  ACTION_MENU* editMenu = new ACTION_MENU( false, selTool );
133 
134  editMenu->Add( ACTIONS::undo );
135  editMenu->Add( ACTIONS::redo );
136 
137  editMenu->AppendSeparator();
138  editMenu->Add( ACTIONS::cut );
139  editMenu->Add( ACTIONS::copy );
140  editMenu->Add( ACTIONS::paste );
141  editMenu->Add( ACTIONS::pasteSpecial );
142  editMenu->Add( ACTIONS::doDelete );
143  editMenu->Add( ACTIONS::duplicate );
144 
145  editMenu->AppendSeparator();
146  editMenu->Add( ACTIONS::selectAll );
147 
148  editMenu->AppendSeparator();
149  editMenu->Add( ACTIONS::find );
150  editMenu->Add( ACTIONS::findAndReplace );
151 
152  editMenu->AppendSeparator();
153  editMenu->Add( ACTIONS::deleteTool );
155  editMenu->Add( EE_ACTIONS::changeSymbols );
156  editMenu->Add( EE_ACTIONS::editPageNumber );
157 
158  //-- View menu -----------------------------------------------------------
159  //
160  ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
161 
162  viewMenu->Add( ACTIONS::showSymbolBrowser );
163  viewMenu->Add( EE_ACTIONS::navigateHierarchy );
164  viewMenu->Add( EE_ACTIONS::leaveSheet );
165 
166  viewMenu->AppendSeparator();
167  viewMenu->Add( ACTIONS::zoomInCenter );
168  viewMenu->Add( ACTIONS::zoomOutCenter );
169  viewMenu->Add( ACTIONS::zoomFitScreen );
170  viewMenu->Add( ACTIONS::zoomFitObjects );
171  viewMenu->Add( ACTIONS::zoomTool );
172  viewMenu->Add( ACTIONS::zoomRedraw );
173 
174  viewMenu->AppendSeparator();
176  viewMenu->Add( ACTIONS::gridProperties );
177 
178  // Units submenu
179  ACTION_MENU* unitsSubMenu = new ACTION_MENU( false, selTool );
180  unitsSubMenu->SetTitle( _( "&Units" ) );
181  unitsSubMenu->SetIcon( unit_mm_xpm );
182  unitsSubMenu->Add( ACTIONS::inchesUnits, ACTION_MENU::CHECK );
183  unitsSubMenu->Add( ACTIONS::milsUnits, ACTION_MENU::CHECK );
185  viewMenu->Add( unitsSubMenu );
186 
188 
189  viewMenu->AppendSeparator();
191 
192 #ifdef __APPLE__
193  viewMenu->AppendSeparator();
194 #endif
195 
196  //-- Place menu -----------------------------------------------------------
197  //
198  ACTION_MENU* placeMenu = new ACTION_MENU( false, selTool );
199 
200  placeMenu->Add( EE_ACTIONS::placeSymbol );
201  placeMenu->Add( EE_ACTIONS::placePower );
202  placeMenu->Add( EE_ACTIONS::drawWire );
203  placeMenu->Add( EE_ACTIONS::drawBus );
204  placeMenu->Add( EE_ACTIONS::placeBusWireEntry );
205  placeMenu->Add( EE_ACTIONS::placeNoConnect );
206  placeMenu->Add( EE_ACTIONS::placeJunction );
207  placeMenu->Add( EE_ACTIONS::placeLabel );
208  placeMenu->Add( EE_ACTIONS::placeGlobalLabel );
209 
210  placeMenu->AppendSeparator();
211  placeMenu->Add( EE_ACTIONS::placeHierLabel );
212  placeMenu->Add( EE_ACTIONS::drawSheet );
213  placeMenu->Add( EE_ACTIONS::importSheetPin );
214 
215  placeMenu->AppendSeparator();
216  placeMenu->Add( EE_ACTIONS::drawLines );
217  placeMenu->Add( EE_ACTIONS::placeSchematicText );
218  placeMenu->Add( EE_ACTIONS::placeImage );
219 
220 
221  //-- Inspect menu -----------------------------------------------
222  //
223  ACTION_MENU* inspectMenu = new ACTION_MENU( false, selTool );
224 
225  inspectMenu->Add( EE_ACTIONS::runERC );
226 #ifdef KICAD_SPICE
227  inspectMenu->Add( EE_ACTIONS::runSimulation );
228 #endif
229 
230 
231  //-- Tools menu -----------------------------------------------
232  //
233  ACTION_MENU* toolsMenu = new ACTION_MENU( false, selTool );
234 
235  toolsMenu->Add( ACTIONS::updatePcbFromSchematic );
236  toolsMenu->Add( ACTIONS::updateSchematicFromPcb );
237  toolsMenu->Add( EE_ACTIONS::showPcbNew );
238 
239  toolsMenu->AppendSeparator();
240  toolsMenu->Add( ACTIONS::showSymbolEditor );
241  toolsMenu->Add( EE_ACTIONS::updateSymbols );
242  toolsMenu->Add( EE_ACTIONS::rescueSymbols );
243  toolsMenu->Add( EE_ACTIONS::remapSymbols );
244 
245  toolsMenu->AppendSeparator();
246  toolsMenu->Add( EE_ACTIONS::editSymbolFields );
248 
249  toolsMenu->AppendSeparator();
250  toolsMenu->Add( EE_ACTIONS::annotate );
251  toolsMenu->Add( EE_ACTIONS::showBusManager );
252 
253  toolsMenu->AppendSeparator();
254  toolsMenu->Add( EE_ACTIONS::assignFootprints );
255  toolsMenu->Add( EE_ACTIONS::generateBOM );
256 
257 
258  //-- Preferences menu -----------------------------------------------
259  //
260  ACTION_MENU* prefsMenu = new ACTION_MENU( false, selTool );
261 
262  prefsMenu->Add( ACTIONS::configurePaths );
263  prefsMenu->Add( ACTIONS::showSymbolLibTable );
264  prefsMenu->Add( _( "Preferences...\tCTRL+," ),
265  _( "Show preferences for all open tools" ),
266  wxID_PREFERENCES,
267  preference_xpm );
268 
269  prefsMenu->AppendSeparator();
270  AddMenuLanguageList( prefsMenu, selTool );
271 
272 #ifndef __WXMAC__
273  prefsMenu->AppendSeparator();
276 #endif
277 
278 
279  //-- Menubar -------------------------------------------------------------
280  //
281  menuBar->Append( fileMenu, _( "&File" ) );
282  menuBar->Append( editMenu, _( "&Edit" ) );
283  menuBar->Append( viewMenu, _( "&View" ) );
284  menuBar->Append( placeMenu, _( "&Place" ) );
285  menuBar->Append( inspectMenu, _( "&Inspect" ) );
286  menuBar->Append( toolsMenu, _( "&Tools" ) );
287  menuBar->Append( prefsMenu, _( "P&references" ) );
288  AddStandardHelpMenu( menuBar );
289 
290  SetMenuBar( menuBar );
291  delete oldMenuBar;
292 }
293 
294 
static TOOL_ACTION editPageNumber
Definition: ee_actions.h:155
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 rescueSymbols
Definition: ee_actions.h:157
static TOOL_ACTION findAndReplace
Definition: actions.h:80
static TOOL_ACTION exportNetlist
Definition: ee_actions.h:164
static TOOL_ACTION navigateHierarchy
Definition: ee_actions.h:185
static TOOL_ACTION assignFootprints
Definition: ee_actions.h:151
static TOOL_ACTION zoomInCenter
Definition: actions.h:91
static TOOL_ACTION pageSettings
Definition: actions.h:59
static TOOL_ACTION runERC
Definition: ee_actions.h:141
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:43
static TOOL_ACTION doDelete
Definition: actions.h:75
static TOOL_ACTION zoomTool
Definition: actions.h:97
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 remapSymbols
Definition: ee_actions.h:158
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 showSymbolLibTable
Definition: actions.h:173
static TOOL_ACTION standardGraphics
Definition: actions.h:164
static TOOL_ACTION updatePcbFromSchematic
Definition: actions.h:161
static TOOL_ACTION placeBusWireEntry
Definition: ee_actions.h:84
static TOOL_ACTION updateSymbols
Definition: ee_actions.h:148
static TOOL_ACTION zoomFitObjects
Definition: actions.h:95
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 find
Definition: actions.h:79
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.
ACTION_CONDITIONS & Enable(const SELECTION_CONDITION &aCondition)
static TOOL_ACTION leaveSheet
Definition: ee_actions.h:184
static TOOL_ACTION runSimulation
Definition: ee_actions.h:209
static TOOL_ACTION annotate
Definition: ee_actions.h:142
static TOOL_ACTION drawSheet
Definition: ee_actions.h:88
static TOOL_ACTION showPcbNew
Definition: ee_actions.h:162
static TOOL_ACTION copy
Definition: actions.h:70
static TOOL_ACTION showBusManager
Definition: ee_actions.h:153
static TOOL_ACTION updateSchematicFromPcb
Definition: actions.h:162
static TOOL_ACTION editSymbolFields
Definition: ee_actions.h:143
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:138
static TOOL_ACTION open
Definition: actions.h:53
static TOOL_ACTION inchesUnits
Definition: actions.h:142
static TOOL_ACTION save
Definition: actions.h:54
static TOOL_ACTION placeSchematicText
Definition: ee_actions.h:91
static TOOL_ACTION doNew
Definition: actions.h:47
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.
const BITMAP_OPAQUE export_xpm[1]
Definition: export.cpp:71
static TOOL_ACTION placeImage
Definition: ee_actions.h:93
const BITMAP_OPAQUE import_xpm[1]
Definition: import.cpp:68
static TOOL_ACTION cut
Definition: actions.h:69
static TOOL_ACTION plot
Definition: actions.h:61
static TOOL_ACTION importSheetPin
Definition: ee_actions.h:90
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:190
static TOOL_ACTION milsUnits
Definition: actions.h:143
const BITMAP_OPAQUE unit_mm_xpm[1]
Definition: unit_mm.cpp:26
static TOOL_ACTION drawBus
Definition: ee_actions.h:80
static TOOL_ACTION pasteSpecial
Definition: actions.h:72
const BITMAP_OPAQUE import_document_xpm[1]
static TOOL_ACTION placeLabel
Definition: ee_actions.h:85
static TOOL_ACTION redo
Definition: actions.h:68
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.
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:158
static TOOL_ACTION saveAs
Definition: actions.h:55
static TOOL_ACTION toggleHiddenPins
Definition: ee_actions.h:193
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 importFPAssignments
Definition: ee_actions.h:163
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
static TOOL_ACTION acceleratedGraphics
Definition: actions.h:163
static TOOL_ACTION placeNoConnect
Definition: ee_actions.h:82
static TOOL_ACTION changeSymbols
Definition: ee_actions.h:147
static TOOL_ACTION drawSheetOnClipboard
Definition: ee_actions.h:204
static TOOL_ACTION gridProperties
Definition: actions.h:139
static TOOL_ACTION deleteTool
Definition: actions.h:76
static TOOL_ACTION undo
Definition: actions.h:67
static TOOL_ACTION generateBOM
Definition: ee_actions.h:165
static TOOL_ACTION drawLines
Definition: ee_actions.h:92
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:100
static TOOL_ACTION schematicSetup
Definition: ee_actions.h:154
static TOOL_ACTION showSymbolBrowser
Definition: actions.h:157
static TOOL_ACTION placeGlobalLabel
Definition: ee_actions.h:86
static TOOL_ACTION editSymbolLibraryLinks
Definition: ee_actions.h:144
const BITMAP_OPAQUE preference_xpm[1]
Definition: preference.cpp:53
static TOOL_ACTION configurePaths
Definition: actions.h:172
static TOOL_ACTION selectAll
Definition: actions.h:73
static TOOL_ACTION paste
Definition: actions.h:71
static TOOL_ACTION duplicate
Definition: actions.h:74
const BITMAP_OPAQUE add_document_xpm[1]