KiCad PCB EDA Suite
menubar_libedit.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) 2007 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 2009 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <menus_helpers.h>
27 #include <pgm_base.h>
28 #include <tool/conditional_menu.h>
29 #include <tool/tool_manager.h>
30 #include <tools/ee_actions.h>
32 #include <lib_manager.h>
33 #include "lib_edit_frame.h"
34 
35 
37 {
39  // wxWidgets handles the Mac Application menu behind the scenes, but that means
40  // we always have to start from scratch with a new wxMenuBar.
41  wxMenuBar* oldMenuBar = GetMenuBar();
42  wxMenuBar* menuBar = new wxMenuBar();
43 
44  auto modifiedDocumentCondition = [ this ] ( const SELECTION& sel ) {
45  LIB_ID libId = getTargetLibId();
46  const wxString& libName = libId.GetLibNickname();
47  const wxString& partName = libId.GetLibItemName();
48  bool readOnly = libName.IsEmpty() || m_libMgr->IsLibraryReadOnly( libName );
49 
50  if( partName.IsEmpty() )
51  return ( !readOnly && m_libMgr->IsLibraryModified( libName ) );
52  else
53  return ( !readOnly && m_libMgr->IsPartModified( partName, libName ) );
54  };
55 
56  //-- File menu -----------------------------------------------
57  //
58  CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool );
59 
63 
64  fileMenu->AddSeparator();
65  fileMenu->AddItem( ACTIONS::save, modifiedDocumentCondition );
68  fileMenu->AddItem( ACTIONS::revert, modifiedDocumentCondition );
69 
70  fileMenu->AddSeparator();
72 
73  // Export submenu
74  ACTION_MENU* submenuExport = new ACTION_MENU( false );
75  submenuExport->SetTool( selTool );
76  submenuExport->SetTitle( _( "Export" ) );
77  submenuExport->SetIcon( export_xpm );
78  submenuExport->Add( EE_ACTIONS::exportSymbol );
79  submenuExport->Add( EE_ACTIONS::exportSymbolView );
80  submenuExport->Add( EE_ACTIONS::exportSymbolAsSVG );
81  fileMenu->AddMenu( submenuExport, EE_CONDITIONS::ShowAlways );
82 
83  fileMenu->AddSeparator();
84  fileMenu->AddClose( _( "Library Editor" ) );
85 
86  fileMenu->Resolve();
87 
88  //-- Edit menu -----------------------------------------------
89  //
90  CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, selTool );
91 
92  auto enableUndoCondition = [ this ] ( const SELECTION& sel ) {
93  return m_my_part && GetScreen() && GetScreen()->GetUndoCommandCount() != 0;
94  };
95  auto enableRedoCondition = [ this ] ( const SELECTION& sel ) {
96  return m_my_part && GetScreen() && GetScreen()->GetRedoCommandCount() != 0;
97  };
98  auto havePartCondition = [ this ] ( const SELECTION& sel ) {
99  return m_my_part != nullptr;
100  };
101 
102  editMenu->AddItem( ACTIONS::undo, enableUndoCondition );
103  editMenu->AddItem( ACTIONS::redo, enableRedoCondition );
104 
105  editMenu->AddSeparator();
111 
112  editMenu->AddSeparator();
113  editMenu->AddItem( EE_ACTIONS::symbolProperties, havePartCondition );
114  editMenu->AddItem( EE_ACTIONS::pinTable, havePartCondition );
115 
116  editMenu->Resolve();
117 
118  //-- View menu -----------------------------------------------
119  //
120  CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool );
121 
122  auto gridShownCondition = [ this ] ( const SELECTION& aSel ) {
123  return IsGridVisible();
124  };
125  auto imperialUnitsCondition = [this]( const SELECTION& aSel ) {
126  return GetUserUnits() == EDA_UNITS::INCHES;
127  };
128  auto metricUnitsCondition = [this]( const SELECTION& aSel ) {
130  };
131  auto fullCrosshairCondition = [ this ] ( const SELECTION& aSel ) {
133  };
134  auto compTreeShownCondition = [ this ] ( const SELECTION& aSel ) {
135  return IsSearchTreeShown();
136  };
137 
139 
140  viewMenu->AddSeparator();
146 
147  viewMenu->AddSeparator();
148  viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition );
150 
151  // Units submenu
152  CONDITIONAL_MENU* unitsSubMenu = new CONDITIONAL_MENU( false, selTool );
153  unitsSubMenu->SetTitle( _( "&Units" ) );
154  unitsSubMenu->SetIcon( unit_mm_xpm );
155  unitsSubMenu->AddCheckItem( ACTIONS::imperialUnits, imperialUnitsCondition );
156  unitsSubMenu->AddCheckItem( ACTIONS::metricUnits, metricUnitsCondition );
157  viewMenu->AddMenu( unitsSubMenu );
158 
159  viewMenu->AddCheckItem( ACTIONS::toggleCursorStyle, fullCrosshairCondition );
160 
161  viewMenu->AddSeparator();
162  viewMenu->AddCheckItem( EE_ACTIONS::showComponentTree, compTreeShownCondition );
163 
164  viewMenu->Resolve();
165 
166  //-- Place menu -----------------------------------------------
167  //
168  auto enableIsEditableCondition = [ this ] ( const SELECTION& aSel ) {
169  return m_my_part && m_my_part->IsRoot();
170  };
171 
172  CONDITIONAL_MENU* placeMenu = new CONDITIONAL_MENU( false, selTool );
173 
174  placeMenu->AddItem( EE_ACTIONS::placeSymbolPin, enableIsEditableCondition );
175  placeMenu->AddItem( EE_ACTIONS::placeSymbolText, enableIsEditableCondition );
176  placeMenu->AddItem( EE_ACTIONS::drawSymbolRectangle, enableIsEditableCondition );
177  placeMenu->AddItem( EE_ACTIONS::drawSymbolCircle, enableIsEditableCondition );
178  placeMenu->AddItem( EE_ACTIONS::drawSymbolArc, enableIsEditableCondition );
179  placeMenu->AddItem( EE_ACTIONS::drawSymbolLines, enableIsEditableCondition );
180 
181  placeMenu->Resolve();
182 
183  //-- Inspect menu -----------------------------------------------
184  //
185  CONDITIONAL_MENU* inspectMenu = new CONDITIONAL_MENU( false, selTool );
186 
187  auto datasheetAvailableCondition = [ this ] ( const SELECTION& aSel ) {
188  return GetCurPart() != nullptr;
189  };
190 
191  inspectMenu->AddItem( EE_ACTIONS::showDatasheet, datasheetAvailableCondition );
193 
194  inspectMenu->Resolve();
195 
196  //-- Preferences menu -----------------------------------------------
197  //
198  CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, selTool );
199 
200  auto acceleratedGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
202  };
203  auto standardGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
205  };
206 
209  prefsMenu->AddItem( wxID_PREFERENCES,
210  _( "Preferences...\tCTRL+," ),
211  _( "Show preferences for all open tools" ),
213 
214  prefsMenu->AddSeparator();
215  AddMenuLanguageList( prefsMenu, selTool );
216 
217  prefsMenu->AddSeparator();
218  prefsMenu->AddCheckItem( ACTIONS::acceleratedGraphics, acceleratedGraphicsCondition );
219  prefsMenu->AddCheckItem( ACTIONS::standardGraphics, standardGraphicsCondition );
220 
221  prefsMenu->Resolve();
222 
223  //-- Menubar -------------------------------------------------------------
224  //
225  menuBar->Append( fileMenu, _( "&File" ) );
226  menuBar->Append( editMenu, _( "&Edit" ) );
227  menuBar->Append( viewMenu, _( "&View" ) );
228  menuBar->Append( placeMenu, _( "&Place" ) );
229  menuBar->Append( inspectMenu, _( "&Inspect" ) );
230  menuBar->Append( prefsMenu, _( "P&references" ) );
231  AddStandardHelpMenu( menuBar );
232 
233  SetMenuBar( menuBar );
234  delete oldMenuBar;
235 }
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()
static TOOL_ACTION pinTable
Definition: ee_actions.h:149
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
Function Add() Adds a wxWidgets-style entry to the menu.
static TOOL_ACTION showDatasheet
Inspection and Editing.
Definition: ee_actions.h:143
static TOOL_ACTION placeSymbolText
Definition: ee_actions.h:105
static TOOL_ACTION drawSymbolLines
Definition: ee_actions.h:109
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
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 runERC
Definition: ee_actions.h:144
ACTION_MENU.
Definition: action_menu.h:43
static TOOL_ACTION doDelete
Definition: actions.h:74
static TOOL_ACTION zoomTool
Definition: actions.h:95
virtual bool IsGridVisible() const
int GetUndoCommandCount() const
Definition: base_screen.h:201
LIB_MANAGER * m_libMgr
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
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()
LIB_PART * GetCurPart()
Return the current part being edited or NULL if none selected.
static TOOL_ACTION showComponentTree
Definition: ee_actions.h:191
static SELECTION_CONDITION Idle
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
static TOOL_ACTION imperialUnits
Definition: actions.h:139
static bool NotEmpty(const SELECTION &aSelection)
Function NotEmpty Tests if there are any items selected.
LIB_PART * m_my_part
static TOOL_ACTION zoomOutCenter
Definition: actions.h:91
static TOOL_ACTION saveCopyAs
Definition: actions.h:56
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
static TOOL_ACTION drawSymbolRectangle
Definition: ee_actions.h:106
static TOOL_ACTION copy
Definition: actions.h:70
static TOOL_ACTION placeSymbolPin
Definition: ee_actions.h:104
void ReCreateMenuBar() override
Recreates the menu bar.
static TOOL_ACTION toggleGrid
Definition: actions.h:135
bool IsPartModified(const wxString &aAlias, const wxString &aLibrary) const
Returns true if part has unsaved modifications.
static TOOL_ACTION save
Definition: actions.h:54
static TOOL_ACTION symbolProperties
Definition: ee_actions.h:148
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
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 cut
Definition: actions.h:69
static TOOL_ACTION drawSymbolCircle
Definition: ee_actions.h:107
static TOOL_ACTION addLibrary
Definition: actions.h:52
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
static TOOL_ACTION importSymbol
Definition: ee_actions.h:172
static TOOL_ACTION newLibrary
Definition: actions.h:51
void Resolve()
Function Resolve()
static TOOL_ACTION exportSymbolView
Definition: ee_actions.h:194
const BITMAP_OPAQUE unit_mm_xpm[1]
Definition: unit_mm.cpp:28
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
static TOOL_ACTION newSymbol
Definition: ee_actions.h:165
static TOOL_ACTION exportSymbol
Definition: ee_actions.h:173
static TOOL_ACTION metricUnits
Definition: actions.h:140
static TOOL_ACTION redo
Definition: actions.h:68
void AddClose(wxString aAppname="")
Function AddClose()
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:86
see class PGM_BASE
void AddMenuLanguageList(CONDITIONAL_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION zoomRedraw
Definition: actions.h:87
static TOOL_ACTION acceleratedGraphics
Definition: actions.h:158
LIB_ID getTargetLibId() const
Returns either the part selected in the component tree, if context menu is active or the currently mo...
static TOOL_ACTION drawSymbolArc
Definition: ee_actions.h:108
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
bool IsLibraryModified(const wxString &aLibrary) const
Returns true if library has unsaved modifications.
static TOOL_ACTION gridProperties
Definition: actions.h:136
static TOOL_ACTION undo
Definition: actions.h:67
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 saveAll
Definition: actions.h:57
TOOL_MANAGER * m_toolManager
static TOOL_ACTION showSymbolBrowser
Definition: actions.h:152
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
static TOOL_ACTION exportSymbolAsSVG
Definition: ee_actions.h:195
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 IsLibraryReadOnly(const wxString &aLibrary) const
Returns true if the library is stored in a read-only file.
static TOOL_ACTION duplicate
Definition: actions.h:73
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
static TOOL_ACTION revert
Definition: actions.h:58