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 FILE_HISTORY_MENU* openRecentMenu;
58 
59  if( Kiface().IsSingle() ) // not when under a project mgr
60  {
61  FILE_HISTORY& fileHistory = Kiface().GetFileHistory();
62 
63  // Create the menu if it does not exist. Adding a file to/from the history
64  // will automatically refresh the menu.
65  if( !openRecentMenu )
66  {
67  openRecentMenu = new FILE_HISTORY_MENU( fileHistory );
68  openRecentMenu->SetTool( selTool );
69  openRecentMenu->SetTitle( _( "Open Recent" ) );
70  openRecentMenu->SetIcon( recent_xpm );
71  }
72 
75  fileMenu->AddMenu( openRecentMenu, FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
76  fileMenu->AddSeparator();
77  }
78 
79  fileMenu->AddItem( ACTIONS::save, modifiedDocumentCondition );
81 
82  fileMenu->AddSeparator();
83 
84  fileMenu->AddItem( ID_APPEND_PROJECT, _( "Append Schematic Sheet Content..." ),
85  _( "Append schematic sheet content from another project to the current sheet" ),
87 
88  fileMenu->AddItem( ID_IMPORT_NON_KICAD_SCH, _( "Import Non KiCad Schematic..." ),
89  _( "Replace current schematic sheet with one imported from another application" ),
91 
92  fileMenu->AddSeparator();
93 
94  // Import submenu
95  ACTION_MENU* submenuImport = new ACTION_MENU( false );
96  submenuImport->SetTool( selTool );
97  submenuImport->SetTitle( _( "Import" ) );
98  submenuImport->SetIcon( import_xpm );
99  submenuImport->Add( EE_ACTIONS::importFPAssignments );
100  fileMenu->AddMenu( submenuImport, EE_CONDITIONS::ShowAlways );
101 
102 
103  // Export submenu
104  ACTION_MENU* submenuExport = new ACTION_MENU( false );
105  submenuExport->SetTool( selTool );
106  submenuExport->SetTitle( _( "Export" ) );
107  submenuExport->SetIcon( export_xpm );
108  submenuExport->Add( EE_ACTIONS::drawSheetOnClipboard );
109  submenuExport->Add( EE_ACTIONS::exportNetlist );
110  fileMenu->AddMenu( submenuExport, EE_CONDITIONS::ShowAlways );
111 
112  fileMenu->AddSeparator();
116 
117  fileMenu->AddSeparator();
118  fileMenu->AddQuitOrClose( &Kiface(), _( "Eeschema" ) );
119 
120  fileMenu->Resolve();
121 
122  //-- Edit menu -----------------------------------------------------------
123  //
124  CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, selTool );
125 
126  auto enableUndoCondition = [ this ] ( const SELECTION& sel ) {
127  return GetScreen() && GetScreen()->GetUndoCommandCount() > 0;
128  };
129  auto enableRedoCondition = [ this ] ( const SELECTION& sel ) {
130  return GetScreen() && GetScreen()->GetRedoCommandCount() > 0;
131  };
132 
133  editMenu->AddItem( ACTIONS::undo, enableUndoCondition );
134  editMenu->AddItem( ACTIONS::redo, enableRedoCondition );
135 
136  editMenu->AddSeparator();
143 
144  editMenu->AddSeparator();
147 
148  editMenu->AddSeparator();
152 
153  editMenu->Resolve();
154 
155  //-- View menu -----------------------------------------------------------
156  //
157  CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool );
158 
159  auto belowRootSheetCondition = [] ( const SELECTION& aSel ) {
160  return g_CurrentSheet->Last() != g_RootSheet;
161  };
162  auto gridShownCondition = [ this ] ( const SELECTION& aSel ) {
163  return IsGridVisible();
164  };
165  auto imperialUnitsCondition = [this]( const SELECTION& aSel ) {
166  return GetUserUnits() == EDA_UNITS::INCHES;
167  };
168  auto metricUnitsCondition = [this]( const SELECTION& aSel ) {
170  };
171  auto fullCrosshairCondition = [ this ] ( const SELECTION& aSel ) {
173  };
174  auto hiddenPinsCondition = [ this ] ( const SELECTION& aSel ) {
175  return GetShowAllPins();
176  };
177 
180  viewMenu->AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition );
181 
182  viewMenu->AddSeparator();
188 
189  viewMenu->AddSeparator();
190  viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition );
192 
193  // Units submenu
194  CONDITIONAL_MENU* unitsSubMenu = new CONDITIONAL_MENU( false, selTool );
195  unitsSubMenu->SetTitle( _( "&Units" ) );
196  unitsSubMenu->SetIcon( unit_mm_xpm );
197  unitsSubMenu->AddCheckItem( ACTIONS::imperialUnits, imperialUnitsCondition );
198  unitsSubMenu->AddCheckItem( ACTIONS::metricUnits, metricUnitsCondition );
199  viewMenu->AddMenu( unitsSubMenu );
200 
201  viewMenu->AddCheckItem( ACTIONS::toggleCursorStyle, fullCrosshairCondition );
202 
203  viewMenu->AddSeparator();
204  viewMenu->AddCheckItem( EE_ACTIONS::toggleHiddenPins, hiddenPinsCondition );
205 
206 #ifdef __APPLE__
207  viewMenu->AddSeparator();
208 #endif
209 
210  viewMenu->Resolve();
211 
212  //-- Place menu -----------------------------------------------------------
213  //
214  CONDITIONAL_MENU* placeMenu = new CONDITIONAL_MENU( false, selTool );
215 
226 
227  placeMenu->AddSeparator();
232 
233  placeMenu->AddSeparator();
237 
238  placeMenu->Resolve();
239 
240  //-- Inspect menu -----------------------------------------------
241  //
242  CONDITIONAL_MENU* inspectMenu = new CONDITIONAL_MENU( false, selTool );
243 
245 #ifdef KICAD_SPICE
247 #endif
248 
249  inspectMenu->Resolve();
250 
251  //-- Tools menu -----------------------------------------------
252  //
253  CONDITIONAL_MENU* toolsMenu = new CONDITIONAL_MENU( false, selTool );
254 
255  auto remapSymbolsCondition = [] ( const SELECTION& aSel ) {
256  SCH_SCREENS schematic;
257 
258  // The remapping can only be performed on legacy projects.
259  return schematic.HasNoFullyDefinedLibIds();
260  };
261 
264 
265  toolsMenu->AddSeparator();
267  toolsMenu->AddItem( ID_RESCUE_CACHED, _( "Rescue Symbols..." ),
268  _( "Find old symbols in project and rename/rescue them" ),
270 
271  toolsMenu->AddItem( ID_REMAP_SYMBOLS, _( "Remap Symbols..." ),
272  _( "Remap legacy library symbols to symbol library table" ),
273  rescue_xpm, remapSymbolsCondition );
274 
275  toolsMenu->AddSeparator();
278 
279  toolsMenu->AddSeparator();
282 
283  toolsMenu->AddSeparator();
286 
287  toolsMenu->Resolve();
288 
289  //-- Preferences menu -----------------------------------------------
290  //
291  CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, selTool );
292 
293  auto acceleratedGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
295  };
296  auto standardGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
298  };
299 
302  prefsMenu->AddItem( wxID_PREFERENCES,
303  _( "Preferences...\tCTRL+," ),
304  _( "Show preferences for all open tools" ),
306 
307  prefsMenu->AddSeparator();
308  AddMenuLanguageList( prefsMenu, selTool );
309 
310  prefsMenu->AddSeparator();
311  prefsMenu->AddCheckItem( ACTIONS::acceleratedGraphics, acceleratedGraphicsCondition );
312  prefsMenu->AddCheckItem( ACTIONS::standardGraphics, standardGraphicsCondition );
313 
314  prefsMenu->Resolve();
315 
316  //-- Menubar -------------------------------------------------------------
317  //
318  menuBar->Append( fileMenu, _( "&File" ) );
319  menuBar->Append( editMenu, _( "&Edit" ) );
320  menuBar->Append( viewMenu, _( "&View" ) );
321  menuBar->Append( placeMenu, _( "&Place" ) );
322  menuBar->Append( inspectMenu, _( "&Inspect" ) );
323  menuBar->Append( toolsMenu, _( "&Tools" ) );
324  menuBar->Append( prefsMenu, _( "P&references" ) );
325  AddStandardHelpMenu( menuBar );
326 
327  SetMenuBar( menuBar );
328  delete oldMenuBar;
329 }
330 
331 
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:152
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:163
static TOOL_ACTION standardGraphics
Definition: actions.h:155
void AddCheckItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddCheckItem()
This class implements a menu container for a file history.
Definition: filehistory.h:86
static TOOL_ACTION placeBusBusEntry
Definition: ee_actions.h:87
static TOOL_ACTION updatePcbFromSchematic
Definition: actions.h:153
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:40
static TOOL_ACTION find
Definition: actions.h:78
static TOOL_ACTION imperialUnits
Definition: actions.h:136
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:146
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:153
static TOOL_ACTION editSymbolFields
Definition: ee_actions.h:147
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 placeSheetPin
Definition: ee_actions.h:92
static TOOL_ACTION toggleGrid
Definition: actions.h:132
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:151
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:137
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...
Definition: filehistory.cpp:73
static TOOL_ACTION showSymbolEditor
Definition: actions.h:150
static TOOL_ACTION saveAs
Definition: actions.h:55
static TOOL_ACTION toggleHiddenPins
Definition: ee_actions.h:183
#define _(s)
Definition: 3d_actions.cpp:31
static TOOL_ACTION zoomRedraw
Definition: actions.h:87
static TOOL_ACTION importFPAssignments
Definition: ee_actions.h:158
FILE_HISTORY & GetFileHistory()
Definition: kiface_i.h:123
static TOOL_ACTION acceleratedGraphics
Definition: actions.h:154
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:133
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 showSymbolBrowser
Definition: actions.h:149
static TOOL_ACTION placeGlobalLabel
Definition: ee_actions.h:89
static TOOL_ACTION editSymbolLibraryLinks
Definition: ee_actions.h:148
const BITMAP_OPAQUE preference_xpm[1]
Definition: preference.cpp:66
static TOOL_ACTION configurePaths
Definition: actions.h:162
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:498
const BITMAP_OPAQUE add_document_xpm[1]