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 <tool/conditional_menu.h>
32 #include <tool/tool_manager.h>
34 #include <tools/ee_actions.h>
35 #include "eeschema_id.h"
36 #include "sch_edit_frame.h"
37 
38 extern void AddMenuLanguageList( CONDITIONAL_MENU* aMasterMenu, TOOL_INTERACTIVE* aControlTool );
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  wxMenuBar* menuBar = new wxMenuBar();
48 
49  auto modifiedDocumentCondition = [] ( const SELECTION& sel ) {
50  SCH_SHEET_LIST sheetList( g_RootSheet );
51  return sheetList.IsModified();
52  };
53 
54  //-- File menu -----------------------------------------------------------
55  //
56  CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool );
57  static ACTION_MENU* openRecentMenu;
58 
59  if( Kiface().IsSingle() ) // When not under a project mgr
60  {
61  FILE_HISTORY& fileHistory = Kiface().GetFileHistory();
62 
63  // Add this menu to the list of menus managed by the file history
64  // (the file history will be updated when adding/removing files in history)
65  if( !openRecentMenu )
66  {
67  openRecentMenu = new ACTION_MENU( false );
68  openRecentMenu->SetTool( selTool );
69  openRecentMenu->SetTitle( _( "Open Recent" ) );
70  openRecentMenu->SetIcon( recent_xpm );
71 
72  fileHistory.UseMenu( openRecentMenu );
73  fileHistory.AddFilesToMenu( openRecentMenu );
74  }
75 
78  fileMenu->AddMenu( openRecentMenu, FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
79  fileMenu->AddSeparator();
80  }
81 
82  fileMenu->AddItem( ACTIONS::save, modifiedDocumentCondition );
84 
85  fileMenu->AddSeparator();
86 
87  fileMenu->AddItem( ID_APPEND_PROJECT, _( "Append Schematic Sheet Content..." ),
88  _( "Append schematic sheet content from another project to the current sheet" ),
90 
91  fileMenu->AddItem( ID_IMPORT_NON_KICAD_SCH, _( "Import Non KiCad Schematic..." ),
92  _( "Replace current schematic sheet with one imported from another application" ),
94 
95  fileMenu->AddSeparator();
96 
97  // Import submenu
98  ACTION_MENU* submenuImport = new ACTION_MENU( false );
99  submenuImport->SetTool( selTool );
100  submenuImport->SetTitle( _( "Import" ) );
101  submenuImport->SetIcon( import_xpm );
102  submenuImport->Add( EE_ACTIONS::importFPAssignments );
103  fileMenu->AddMenu( submenuImport, EE_CONDITIONS::ShowAlways );
104 
105 
106  // Export submenu
107  ACTION_MENU* submenuExport = new ACTION_MENU( false );
108  submenuExport->SetTool( selTool );
109  submenuExport->SetTitle( _( "Export" ) );
110  submenuExport->SetIcon( export_xpm );
111  submenuExport->Add( EE_ACTIONS::drawSheetOnClipboard );
112  submenuExport->Add( EE_ACTIONS::exportNetlist );
113  fileMenu->AddMenu( submenuExport, EE_CONDITIONS::ShowAlways );
114 
115  fileMenu->AddSeparator();
117 
118  fileMenu->AddSeparator();
122 
123  fileMenu->AddSeparator();
124  fileMenu->AddQuitOrClose( &Kiface(), _( "Eeschema" ) );
125 
126  fileMenu->Resolve();
127 
128  //-- Edit menu -----------------------------------------------------------
129  //
130  CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, selTool );
131 
132  auto enableUndoCondition = [ this ] ( const SELECTION& sel ) {
133  return GetScreen() && GetScreen()->GetUndoCommandCount() > 0;
134  };
135  auto enableRedoCondition = [ this ] ( const SELECTION& sel ) {
136  return GetScreen() && GetScreen()->GetRedoCommandCount() > 0;
137  };
138 
139  editMenu->AddItem( ACTIONS::undo, enableUndoCondition );
140  editMenu->AddItem( ACTIONS::redo, enableRedoCondition );
141 
142  editMenu->AddSeparator();
149 
150  editMenu->AddSeparator();
153 
154  editMenu->AddSeparator();
158 
159  editMenu->Resolve();
160 
161  //-- View menu -----------------------------------------------------------
162  //
163  CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool );
164 
165  auto belowRootSheetCondition = [] ( const SELECTION& aSel ) {
166  return g_CurrentSheet->Last() != g_RootSheet;
167  };
168  auto gridShownCondition = [ this ] ( const SELECTION& aSel ) {
169  return IsGridVisible();
170  };
171  auto imperialUnitsCondition = [this]( const SELECTION& aSel ) {
172  return GetUserUnits() == EDA_UNITS::INCHES;
173  };
174  auto metricUnitsCondition = [this]( const SELECTION& aSel ) {
176  };
177  auto fullCrosshairCondition = [ this ] ( const SELECTION& aSel ) {
179  };
180  auto hiddenPinsCondition = [ this ] ( const SELECTION& aSel ) {
181  return GetShowAllPins();
182  };
183 
186  viewMenu->AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition );
187 
188  viewMenu->AddSeparator();
194 
195  viewMenu->AddSeparator();
196  viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition );
198 
199  // Units submenu
200  CONDITIONAL_MENU* unitsSubMenu = new CONDITIONAL_MENU( false, selTool );
201  unitsSubMenu->SetTitle( _( "&Units" ) );
202  unitsSubMenu->SetIcon( unit_mm_xpm );
203  unitsSubMenu->AddCheckItem( ACTIONS::imperialUnits, imperialUnitsCondition );
204  unitsSubMenu->AddCheckItem( ACTIONS::metricUnits, metricUnitsCondition );
205  viewMenu->AddMenu( unitsSubMenu );
206 
207  viewMenu->AddCheckItem( ACTIONS::toggleCursorStyle, fullCrosshairCondition );
208 
209  viewMenu->AddSeparator();
210  viewMenu->AddCheckItem( EE_ACTIONS::toggleHiddenPins, hiddenPinsCondition );
211 
212 #ifdef __APPLE__
213  viewMenu->AddSeparator();
214 #endif
215 
216  viewMenu->Resolve();
217 
218  //-- Place menu -----------------------------------------------------------
219  //
220  CONDITIONAL_MENU* placeMenu = new CONDITIONAL_MENU( false, selTool );
221 
231 
232  placeMenu->AddSeparator();
236 
237  placeMenu->AddSeparator();
241 
242  placeMenu->Resolve();
243 
244  //-- Inspect menu -----------------------------------------------
245  //
246  CONDITIONAL_MENU* inspectMenu = new CONDITIONAL_MENU( false, selTool );
247 
249 #ifdef KICAD_SPICE
251 #endif
252 
253  inspectMenu->Resolve();
254 
255  //-- Tools menu -----------------------------------------------
256  //
257  CONDITIONAL_MENU* toolsMenu = new CONDITIONAL_MENU( false, selTool );
258 
259  auto remapSymbolsCondition = [] ( const SELECTION& aSel ) {
260  SCH_SCREENS schematic;
261 
262  // The remapping can only be performed on legacy projects.
263  return schematic.HasNoFullyDefinedLibIds();
264  };
265 
269 
270  toolsMenu->AddSeparator();
272  toolsMenu->AddItem( ID_RESCUE_CACHED, _( "Rescue Symbols..." ),
273  _( "Find old symbols in project and rename/rescue them" ),
275 
276  toolsMenu->AddItem( ID_REMAP_SYMBOLS, _( "Remap Symbols..." ),
277  _( "Remap legacy library symbols to symbol library table" ),
278  rescue_xpm, remapSymbolsCondition );
279 
280  toolsMenu->AddSeparator();
283 
284  toolsMenu->AddSeparator();
287 
288  toolsMenu->AddSeparator();
291 
292  toolsMenu->Resolve();
293 
294  //-- Preferences menu -----------------------------------------------
295  //
296  CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, selTool );
297 
298  auto acceleratedGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
300  };
301  auto standardGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
303  };
304 
307  prefsMenu->AddItem( wxID_PREFERENCES,
308  _( "Preferences...\tCTRL+," ),
309  _( "Show preferences for all open tools" ),
311 
312  prefsMenu->AddSeparator();
313  AddMenuLanguageList( prefsMenu, selTool );
314 
315  prefsMenu->AddSeparator();
316  prefsMenu->AddCheckItem( ACTIONS::acceleratedGraphics, acceleratedGraphicsCondition );
317  prefsMenu->AddCheckItem( ACTIONS::standardGraphics, standardGraphicsCondition );
318 
319  prefsMenu->Resolve();
320 
321  //-- Menubar -------------------------------------------------------------
322  //
323  menuBar->Append( fileMenu, _( "&File" ) );
324  menuBar->Append( editMenu, _( "&Edit" ) );
325  menuBar->Append( viewMenu, _( "&View" ) );
326  menuBar->Append( placeMenu, _( "&Place" ) );
327  menuBar->Append( inspectMenu, _( "&Inspect" ) );
328  menuBar->Append( toolsMenu, _( "&Tools" ) );
329  menuBar->Append( prefsMenu, _( "P&references" ) );
330  AddStandardHelpMenu( menuBar );
331 
332  SetMenuBar( menuBar );
333  delete oldMenuBar;
334 }
335 
336 
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).
SCH_SHEET_LIST.
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 findAndReplace
Definition: actions.h:79
static TOOL_ACTION exportNetlist
Definition: ee_actions.h:159
static TOOL_ACTION navigateHierarchy
Definition: ee_actions.h:178
static TOOL_ACTION assignFootprints
Definition: ee_actions.h:151
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:144
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:43
static TOOL_ACTION doDelete
Definition: actions.h:74
static TOOL_ACTION zoomTool
Definition: actions.h:95
void ReCreateMenuBar() override
Recreates the menu bar.
virtual bool IsGridVisible() const
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:90
int GetUndoCommandCount() const
Definition: base_screen.h:201
static TOOL_ACTION placeJunction
Definition: ee_actions.h:85
static TOOL_ACTION zoomFitScreen
Definition: actions.h:93
static TOOL_ACTION showSymbolLibTable
Definition: actions.h:167
static TOOL_ACTION standardGraphics
Definition: actions.h:159
void AddCheckItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddCheckItem()
static TOOL_ACTION updatePcbFromSchematic
Definition: actions.h:156
static TOOL_ACTION placeBusWireEntry
Definition: ee_actions.h:86
static TOOL_ACTION print
Definition: actions.h:60
static SELECTION_CONDITION Idle
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:139
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:161
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
static TOOL_ACTION annotate
Definition: ee_actions.h:145
static TOOL_ACTION drawSheet
Definition: ee_actions.h:91
static TOOL_ACTION showPcbNew
Definition: ee_actions.h:157
static TOOL_ACTION copy
Definition: actions.h:70
static TOOL_ACTION showBusManager
Definition: ee_actions.h:152
static TOOL_ACTION updateSchematicFromPcb
Definition: actions.h:157
static TOOL_ACTION editSymbolFields
Definition: ee_actions.h:146
static TOOL_ACTION placePower
Definition: ee_actions.h:80
SCH_SHEET_PATH * g_CurrentSheet
With the new connectivity algorithm, many more places than before want to know what the current sheet...
static TOOL_ACTION drawWire
Definition: ee_actions.h:81
static TOOL_ACTION toggleGrid
Definition: actions.h:135
static TOOL_ACTION open
Definition: actions.h:53
static TOOL_ACTION save
Definition: actions.h:54
static TOOL_ACTION placeSchematicText
Definition: ee_actions.h:94
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:68
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:96
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
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:93
static TOOL_ACTION placeSymbol
Definition: ee_actions.h:79
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:82
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
static TOOL_ACTION pasteSpecial
Definition: actions.h:72
static TOOL_ACTION updateFieldsFromLibrary
Definition: ee_actions.h:150
void AddQuitOrClose(KIFACE_I *aKiface, wxString aAppname="")
Functions AddQuitOrClose()
const BITMAP_OPAQUE import_document_xpm[1]
static TOOL_ACTION placeLabel
Definition: ee_actions.h:88
const BITMAP_OPAQUE rescue_xpm[1]
Definition: rescue.cpp:65
static TOOL_ACTION metricUnits
Definition: actions.h:140
static TOOL_ACTION redo
Definition: actions.h:68
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:86
see class PGM_BASE
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:153
static TOOL_ACTION saveAs
Definition: actions.h:55
static TOOL_ACTION toggleHiddenPins
Definition: ee_actions.h:183
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION zoomRedraw
Definition: actions.h:87
static TOOL_ACTION importFPAssignments
Definition: ee_actions.h:158
FILE_HISTORY & GetFileHistory()
Definition: kiface_i.h:125
static TOOL_ACTION acceleratedGraphics
Definition: actions.h:158
static TOOL_ACTION placeNoConnect
Definition: ee_actions.h:84
static TOOL_ACTION drawSheetOnClipboard
Definition: ee_actions.h:193
static TOOL_ACTION gridProperties
Definition: actions.h:136
static TOOL_ACTION deleteTool
Definition: actions.h:75
static TOOL_ACTION undo
Definition: actions.h:67
static TOOL_ACTION generateBOM
Definition: ee_actions.h:160
static TOOL_ACTION drawLines
Definition: ee_actions.h:95
GAL_TYPE GetBackend() const
Function GetBackend Returns the type of backend currently used by GAL canvas.
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:98
TOOL_MANAGER * m_toolManager
SCH_SHEET * g_RootSheet
static TOOL_ACTION schematicSetup
Definition: ee_actions.h:153
static TOOL_ACTION showSymbolBrowser
Definition: actions.h:152
static TOOL_ACTION placeGlobalLabel
Definition: ee_actions.h:89
static TOOL_ACTION editSymbolLibraryLinks
Definition: ee_actions.h:147
const BITMAP_OPAQUE preference_xpm[1]
Definition: preference.cpp:66
static TOOL_ACTION configurePaths
Definition: actions.h:166
int GetRedoCommandCount() const
Definition: base_screen.h:206
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 some frames 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:491
const BITMAP_OPAQUE add_document_xpm[1]