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-2019 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/conditional_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 extern void AddMenuLanguageList( CONDITIONAL_MENU* aMasterMenu, TOOL_INTERACTIVE* aControlTool );
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  auto modifiedDocumentCondition = [&]( const SELECTION& sel )
52  {
53  return Schematic().GetSheets().IsModified();
54  };
55 
56  //-- File menu -----------------------------------------------------------
57  //
58  CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool );
59  static ACTION_MENU* openRecentMenu;
60 
61  if( Kiface().IsSingle() ) // When not under a project mgr
62  {
63  FILE_HISTORY& fileHistory = GetFileHistory();
64 
65  // Add this menu to the list of menus managed by the file history
66  // (the file history will be updated when adding/removing files in history)
67  if( !openRecentMenu )
68  {
69  openRecentMenu = new ACTION_MENU( false );
70  openRecentMenu->SetTool( selTool );
71  openRecentMenu->SetTitle( _( "Open Recent" ) );
72  openRecentMenu->SetIcon( recent_xpm );
73 
74  fileHistory.UseMenu( openRecentMenu );
75  fileHistory.AddFilesToMenu( openRecentMenu );
76  }
77 
80  fileMenu->AddMenu( openRecentMenu, FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
81  fileMenu->AddSeparator();
82  }
83 
84  fileMenu->AddItem( ACTIONS::save, modifiedDocumentCondition );
86 
87  fileMenu->AddSeparator();
88 
89  fileMenu->AddItem( ID_APPEND_PROJECT, _( "Append Schematic Sheet Content..." ),
90  _( "Append schematic sheet content from another project to the current sheet" ),
92 
93  fileMenu->AddSeparator();
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" ),
103 
104  submenuImport->Add( EE_ACTIONS::importFPAssignments );
105  fileMenu->AddMenu( submenuImport, EE_CONDITIONS::ShowAlways );
106 
107 
108  // Export submenu
109  ACTION_MENU* submenuExport = new ACTION_MENU( false );
110  submenuExport->SetTool( selTool );
111  submenuExport->SetTitle( _( "Export" ) );
112  submenuExport->SetIcon( export_xpm );
113  submenuExport->Add( EE_ACTIONS::drawSheetOnClipboard );
114  submenuExport->Add( EE_ACTIONS::exportNetlist );
115  fileMenu->AddMenu( submenuExport, EE_CONDITIONS::ShowAlways );
116 
117  fileMenu->AddSeparator();
119 
120  fileMenu->AddSeparator();
124 
125  fileMenu->AddSeparator();
126  fileMenu->AddQuitOrClose( &Kiface(), _( "Eeschema" ) );
127 
128  fileMenu->Resolve();
129 
130  //-- Edit menu -----------------------------------------------------------
131  //
132  CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, selTool );
133 
134  auto enableUndoCondition = [ this ] ( const SELECTION& sel ) {
135  return GetUndoCommandCount() > 0;
136  };
137  auto enableRedoCondition = [ this ] ( const SELECTION& sel ) {
138  return GetRedoCommandCount() > 0;
139  };
140 
141  editMenu->AddItem( ACTIONS::undo, enableUndoCondition );
142  editMenu->AddItem( ACTIONS::redo, enableRedoCondition );
143 
144  editMenu->AddSeparator();
151 
152  editMenu->AddSeparator();
155 
156  editMenu->AddSeparator();
160 
161  editMenu->Resolve();
162 
163  //-- View menu -----------------------------------------------------------
164  //
165  CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool );
166 
167  auto belowRootSheetCondition =
168  [this]( const SELECTION& aSel )
169  {
170  return GetCurrentSheet().Last() != &Schematic().Root();
171  };
172 
173  auto gridShownCondition =
174  [this]( const SELECTION& aSel )
175  {
176  return IsGridVisible();
177  };
178 
179  auto imperialUnitsCondition =
180  [this]( const SELECTION& aSel )
181  {
182  return GetUserUnits() == EDA_UNITS::INCHES;
183  };
184 
185  auto metricUnitsCondition =
186  [this]( const SELECTION& aSel )
187  {
189  };
190 
191  auto fullCrosshairCondition =
192  [this]( const SELECTION& aSel )
193  {
195  };
196  auto hiddenPinsCondition =
197  [this]( const SELECTION& aSel )
198  {
199  return GetShowAllPins();
200  };
201 
204  viewMenu->AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition );
205 
206  viewMenu->AddSeparator();
212 
213  viewMenu->AddSeparator();
214  viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition );
216 
217  // Units submenu
218  CONDITIONAL_MENU* unitsSubMenu = new CONDITIONAL_MENU( false, selTool );
219  unitsSubMenu->SetTitle( _( "&Units" ) );
220  unitsSubMenu->SetIcon( unit_mm_xpm );
221  unitsSubMenu->AddCheckItem( ACTIONS::imperialUnits, imperialUnitsCondition );
222  unitsSubMenu->AddCheckItem( ACTIONS::metricUnits, metricUnitsCondition );
223  viewMenu->AddMenu( unitsSubMenu );
224 
225  viewMenu->AddCheckItem( ACTIONS::toggleCursorStyle, fullCrosshairCondition );
226 
227  viewMenu->AddSeparator();
228  viewMenu->AddCheckItem( EE_ACTIONS::toggleHiddenPins, hiddenPinsCondition );
229 
230 #ifdef __APPLE__
231  viewMenu->AddSeparator();
232 #endif
233 
234  viewMenu->Resolve();
235 
236  //-- Place menu -----------------------------------------------------------
237  //
238  CONDITIONAL_MENU* placeMenu = new CONDITIONAL_MENU( false, selTool );
239 
249 
250  placeMenu->AddSeparator();
254 
255  placeMenu->AddSeparator();
259 
260  placeMenu->Resolve();
261 
262  //-- Inspect menu -----------------------------------------------
263  //
264  CONDITIONAL_MENU* inspectMenu = new CONDITIONAL_MENU( false, selTool );
265 
267 #ifdef KICAD_SPICE
269 #endif
270 
271  inspectMenu->Resolve();
272 
273  //-- Tools menu -----------------------------------------------
274  //
275  CONDITIONAL_MENU* toolsMenu = new CONDITIONAL_MENU( false, selTool );
276 
277  auto remapSymbolsCondition =
278  [&]( const SELECTION& aSel )
279  {
280  SCH_SCREENS schematic( Schematic().Root() );
281 
282  // The remapping can only be performed on legacy projects.
283  return schematic.HasNoFullyDefinedLibIds();
284  };
285 
289 
290  toolsMenu->AddSeparator();
293  toolsMenu->AddItem( EE_ACTIONS::remapSymbols, remapSymbolsCondition );
294 
295  toolsMenu->AddSeparator();
298 
299  toolsMenu->AddSeparator();
302 
303  toolsMenu->AddSeparator();
306 
307  toolsMenu->Resolve();
308 
309  //-- Preferences menu -----------------------------------------------
310  //
311  CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, selTool );
312 
313  auto acceleratedGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
315  };
316  auto standardGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
318  };
319 
322  prefsMenu->AddItem( wxID_PREFERENCES,
323  _( "Preferences...\tCTRL+," ),
324  _( "Show preferences for all open tools" ),
326 
327  prefsMenu->AddSeparator();
328  AddMenuLanguageList( prefsMenu, selTool );
329 
330  prefsMenu->AddSeparator();
331  prefsMenu->AddCheckItem( ACTIONS::acceleratedGraphics, acceleratedGraphicsCondition );
332  prefsMenu->AddCheckItem( ACTIONS::standardGraphics, standardGraphicsCondition );
333 
334  prefsMenu->Resolve();
335 
336  //-- Menubar -------------------------------------------------------------
337  //
338  menuBar->Append( fileMenu, _( "&File" ) );
339  menuBar->Append( editMenu, _( "&Edit" ) );
340  menuBar->Append( viewMenu, _( "&View" ) );
341  menuBar->Append( placeMenu, _( "&Place" ) );
342  menuBar->Append( inspectMenu, _( "&Inspect" ) );
343  menuBar->Append( toolsMenu, _( "&Tools" ) );
344  menuBar->Append( prefsMenu, _( "P&references" ) );
345  AddStandardHelpMenu( menuBar );
346 
347  SetMenuBar( menuBar );
348  delete oldMenuBar;
349 }
350 
351 
void AddFilesToMenu() override
Add the files to all registered menus.
Definition: filehistory.h:98
static bool ShowAlways(const SELECTION &aSelection)
Function ShowAlways The default condition function (always returns true).
void AddMenu(ACTION_MENU *aMenu, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddMenu()
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
Function Add() Adds a wxWidgets-style entry to the menu.
bool IsModified()
Function IsModified checks the entire hierarchy for any modifications.
static TOOL_ACTION rescueSymbols
Definition: ee_actions.h:152
static TOOL_ACTION findAndReplace
Definition: actions.h:79
static TOOL_ACTION exportNetlist
Definition: ee_actions.h:160
static TOOL_ACTION navigateHierarchy
Definition: ee_actions.h:178
static TOOL_ACTION assignFootprints
Definition: ee_actions.h:147
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:92
static TOOL_ACTION zoomInCenter
Definition: actions.h:90
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
static TOOL_ACTION pageSettings
Definition: actions.h:59
static TOOL_ACTION runERC
Definition: ee_actions.h:140
SCH_SHEET * Last() const
Function Last returns a pointer to the last sheet of the list One can see the others sheet as the "pa...
ACTION_MENU.
Definition: action_menu.h:44
static TOOL_ACTION doDelete
Definition: actions.h:74
int GetUndoCommandCount() const
static TOOL_ACTION zoomTool
Definition: actions.h:95
void ReCreateMenuBar() override
Recreates the menu bar.
void AddMenuLanguageList(CONDITIONAL_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
static TOOL_ACTION placeHierLabel
Definition: ee_actions.h:87
static TOOL_ACTION placeJunction
Definition: ee_actions.h:83
int GetRedoCommandCount() const
static TOOL_ACTION remapSymbols
Definition: ee_actions.h:153
static TOOL_ACTION zoomFitScreen
Definition: actions.h:93
static TOOL_ACTION showSymbolLibTable
Definition: actions.h:168
static TOOL_ACTION standardGraphics
Definition: actions.h:160
void AddCheckItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddCheckItem()
static TOOL_ACTION updatePcbFromSchematic
Definition: actions.h:157
static TOOL_ACTION placeBusWireEntry
Definition: ee_actions.h:84
static TOOL_ACTION print
Definition: actions.h:60
static SELECTION_CONDITION Idle
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:78
static TOOL_ACTION imperialUnits
Definition: actions.h:140
static bool NotEmpty(const SELECTION &aSelection)
Function NotEmpty Tests if there are any items selected.
static TOOL_ACTION zoomOutCenter
Definition: actions.h:91
const BITMAP_OPAQUE recent_xpm[1]
Definition: recent.cpp:68
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
static TOOL_ACTION leaveSheet
Definition: ee_actions.h:177
static TOOL_ACTION runSimulation
Definition: ee_actions.h:201
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:158
static TOOL_ACTION copy
Definition: actions.h:70
static TOOL_ACTION showBusManager
Definition: ee_actions.h:149
static TOOL_ACTION updateSchematicFromPcb
Definition: actions.h:158
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
bool IsGridVisible() const
static TOOL_ACTION toggleGrid
Definition: actions.h:136
static TOOL_ACTION open
Definition: actions.h:53
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
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:70
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:75
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
SCHEMATIC & Schematic() const
static TOOL_ACTION plot
Definition: actions.h:61
bool HasNoFullyDefinedLibIds()
Test all of the schematic symbols to see if all LIB_ID objects library nickname is not set.
static TOOL_ACTION importSheetPin
Definition: ee_actions.h:90
static TOOL_ACTION placeSymbol
Definition: ee_actions.h:77
static TOOL_ACTION editTextAndGraphics
Definition: ee_actions.h:182
void Resolve()
Function Resolve()
const BITMAP_OPAQUE unit_mm_xpm[1]
Definition: unit_mm.cpp:28
static TOOL_ACTION drawBus
Definition: ee_actions.h:80
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
static TOOL_ACTION pasteSpecial
Definition: actions.h:72
static TOOL_ACTION updateFieldsFromLibrary
Definition: ee_actions.h:146
void AddQuitOrClose(KIFACE_I *aKiface, wxString aAppname="")
Functions AddQuitOrClose()
const BITMAP_OPAQUE import_document_xpm[1]
static TOOL_ACTION placeLabel
Definition: ee_actions.h:85
static TOOL_ACTION metricUnits
Definition: actions.h:141
static TOOL_ACTION redo
Definition: actions.h:68
SCH_SHEET & Root() const
Definition: schematic.h:97
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:88
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:154
static TOOL_ACTION saveAs
Definition: actions.h:55
static TOOL_ACTION toggleHiddenPins
Definition: ee_actions.h:185
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION zoomRedraw
Definition: actions.h:87
static TOOL_ACTION importFPAssignments
Definition: ee_actions.h:159
static TOOL_ACTION acceleratedGraphics
Definition: actions.h:159
static TOOL_ACTION placeNoConnect
Definition: ee_actions.h:82
static TOOL_ACTION drawSheetOnClipboard
Definition: ee_actions.h:196
static TOOL_ACTION gridProperties
Definition: actions.h:137
SCH_SHEET_PATH & GetCurrentSheet() const
static TOOL_ACTION deleteTool
Definition: actions.h:75
static TOOL_ACTION undo
Definition: actions.h:67
static TOOL_ACTION generateBOM
Definition: ee_actions.h:161
static TOOL_ACTION drawLines
Definition: ee_actions.h:92
GAL_TYPE GetBackend() const
Function GetBackend Returns the type of backend currently used by GAL canvas.
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:98
static TOOL_ACTION schematicSetup
Definition: ee_actions.h:150
static TOOL_ACTION showSymbolBrowser
Definition: actions.h:153
static TOOL_ACTION placeGlobalLabel
Definition: ee_actions.h:86
static TOOL_ACTION editSymbolLibraryLinks
Definition: ee_actions.h:143
const BITMAP_OPAQUE preference_xpm[1]
Definition: preference.cpp:66
static TOOL_ACTION configurePaths
Definition: actions.h:167
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
bool m_fullscreenCursor
Fullscreen crosshair or small cross
static TOOL_ACTION paste
Definition: actions.h:71
bool GetShowAllPins() const override
Allow edit frame to show/hide hidden pins.
static TOOL_ACTION duplicate
Definition: actions.h:73
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:528
const BITMAP_OPAQUE add_document_xpm[1]