KiCad PCB EDA Suite
menubar_footprint_editor.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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
7  * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
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 "footprint_edit_frame.h"
28 #include "pcbnew_id.h"
29 #include <menus_helpers.h>
30 #include <tool/actions.h>
31 #include <tool/conditional_menu.h>
32 #include <tool/tool_manager.h>
33 #include <tools/pcb_actions.h>
34 #include <class_board.h>
35 #include <tools/selection_tool.h>
36 #include <widgets/wx_menubar.h>
37 
38 
40 {
42  // wxWidgets handles the Mac Application menu behind the scenes, but that means
43  // we always have to start from scratch with a new wxMenuBar.
44  wxMenuBar* oldMenuBar = GetMenuBar();
45  WX_MENUBAR* menuBar = new WX_MENUBAR();
46 
47  auto modifiedDocumentCondition = [this]( const SELECTION& sel ) {
48  return IsContentModified();
49  };
50  auto haveFootprintCondition = [this]( const SELECTION& aSelection ) {
51  return GetBoard()->GetFirstModule() != nullptr;
52  };
53  auto footprintTargettedCondition = [this]( const SELECTION& aSelection ) {
54  return !GetTargetFPID().GetLibItemName().empty();
55  };
56 
57  //-- File menu ----------------------------------------------------------
58  //
59  CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool );
60 
64 #ifdef KICAD_SCRIPTING
66 #endif
67 
68  fileMenu->AddSeparator();
69  if( IsCurrentFPFromBoard() )
70  fileMenu->AddItem( PCB_ACTIONS::saveToBoard, modifiedDocumentCondition );
71  else
72  fileMenu->AddItem( PCB_ACTIONS::saveToLibrary, modifiedDocumentCondition );
73  fileMenu->AddItem( ACTIONS::saveAs, footprintTargettedCondition );
74  fileMenu->AddItem( ACTIONS::revert, modifiedDocumentCondition );
75 
76  fileMenu->AddSeparator();
77 
78  ACTION_MENU* submenuImport = new ACTION_MENU( false );
79  submenuImport->SetTool( selTool );
80  submenuImport->SetTitle( _( "Import" ) );
81  submenuImport->SetIcon( import_xpm );
82 
83  submenuImport->Add( PCB_ACTIONS::importFootprint );
84  submenuImport->Add( _( "&Import Graphics..." ),
85  _( "Import 2D Drawing file to Footprint Editor on Drawings layer" ),
87 
88  fileMenu->AddMenu( submenuImport, SELECTION_CONDITIONS::ShowAlways );
89 
90  CONDITIONAL_MENU* submenuExport = new CONDITIONAL_MENU( false, selTool );
91  submenuExport->SetTitle( _( "Export" ) );
92  submenuExport->SetIcon( export_xpm );
93 
94  submenuExport->AddItem( PCB_ACTIONS::exportFootprint, haveFootprintCondition );
95  submenuExport->AddItem( ID_MODEDIT_SAVE_PNG, _( "Export View as &PNG..." ),
96  _( "Create a PNG file from the current view" ),
98 
99  fileMenu->AddMenu( submenuExport, SELECTION_CONDITIONS::ShowAlways );
100 
101  fileMenu->AddSeparator();
102  fileMenu->AddItem( ACTIONS::print, haveFootprintCondition );
103 
104  fileMenu->AddSeparator();
105  fileMenu->AddClose( _( "Footprint Editor" ) );
106 
107  fileMenu->Resolve();
108 
109  //-- Edit menu -------------------------------------------------------
110  //
111  CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, selTool );
112 
113  auto enableUndoCondition = [ this ] ( const SELECTION& sel ) {
114  return GetScreen() && GetScreen()->GetUndoCommandCount() > 0;
115  };
116  auto enableRedoCondition = [ this ] ( const SELECTION& sel ) {
117  return GetScreen() && GetScreen()->GetRedoCommandCount() > 0;
118  };
119  auto noActiveToolCondition = [ this ] ( const SELECTION& aSelection ) {
120  return ToolStackIsEmpty();
121  };
122 
123  editMenu->AddItem( ACTIONS::undo, enableUndoCondition );
124  editMenu->AddItem( ACTIONS::redo, enableRedoCondition );
125 
126  editMenu->AddSeparator();
129  editMenu->AddItem( ACTIONS::paste, noActiveToolCondition );
132 
133  editMenu->AddSeparator();
134  editMenu->AddItem( PCB_ACTIONS::footprintProperties, haveFootprintCondition );
136 
137  editMenu->AddSeparator();
138  editMenu->AddItem( PCB_ACTIONS::cleanupGraphics, haveFootprintCondition );
139 
140  editMenu->Resolve();
141 
142  //-- View menu -------------------------------------------------------
143  //
144  CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool );
145 
146  auto gridShownCondition = [ this ] ( const SELECTION& aSel ) {
147  return IsGridVisible();
148  };
149  auto polarCoordsCondition = [ this ] ( const SELECTION& aSel ) {
150  return GetShowPolarCoords();
151  };
152  auto imperialUnitsCondition = [this]( const SELECTION& aSel ) {
153  return GetUserUnits() == EDA_UNITS::INCHES;
154  };
155  auto metricUnitsCondition = [this]( const SELECTION& aSel ) {
157  };
158  auto fullCrosshairCondition = [ this ] ( const SELECTION& aSel ) {
160  };
161  auto sketchPadsCondition = [ this ] ( const SELECTION& aSel ) {
163  };
164  auto sketchGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
166  };
167  auto sketchTextCondition = [ this ] ( const SELECTION& aSel ) {
169  };
170  auto contrastModeCondition = [ this ] ( const SELECTION& aSel ) {
173  };
174  auto searchTreeShownCondition = [ this ] ( const SELECTION& aSel ) {
175  return IsSearchTreeShown();
176  };
177 
180 
181  viewMenu->AddSeparator();
187 
188  viewMenu->AddSeparator();
189  viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition );
191  viewMenu->AddCheckItem( PCB_ACTIONS::togglePolarCoords, polarCoordsCondition );
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  // Drawing Mode Submenu
205  CONDITIONAL_MENU* drawingModeSubMenu = new CONDITIONAL_MENU( false, selTool );
206  drawingModeSubMenu->SetTitle( _( "&Drawing Mode" ) );
207  drawingModeSubMenu->SetIcon( add_zone_xpm );
208 
209  drawingModeSubMenu->AddCheckItem( PCB_ACTIONS::padDisplayMode, sketchPadsCondition );
210  drawingModeSubMenu->AddCheckItem( PCB_ACTIONS::graphicsOutlines, sketchGraphicsCondition );
211  drawingModeSubMenu->AddCheckItem( PCB_ACTIONS::textOutlines, sketchTextCondition );
212  viewMenu->AddMenu( drawingModeSubMenu );
213 
214  // Contrast Mode Submenu
215  CONDITIONAL_MENU* contrastModeSubMenu = new CONDITIONAL_MENU( false, selTool );
216  contrastModeSubMenu->SetTitle( _( "&Contrast Mode" ) );
217  contrastModeSubMenu->SetIcon( contrast_mode_xpm );
218 
219  contrastModeSubMenu->AddCheckItem( ACTIONS::highContrastMode, contrastModeCondition );
222  viewMenu->AddMenu( contrastModeSubMenu );
223 
224  viewMenu->AddSeparator();
225  viewMenu->AddCheckItem( PCB_ACTIONS::toggleFootprintTree, searchTreeShownCondition );
226 
227  viewMenu->Resolve();
228 
229  //-- Place menu -------------------------------------------------------
230  //
231  CONDITIONAL_MENU* placeMenu = new CONDITIONAL_MENU( false, selTool );
232 
233  placeMenu->AddItem( PCB_ACTIONS::placePad, haveFootprintCondition );
234 
235  placeMenu->AddSeparator();
236  placeMenu->AddItem( PCB_ACTIONS::placeText, haveFootprintCondition );
237  placeMenu->AddItem( PCB_ACTIONS::drawArc, haveFootprintCondition );
238  placeMenu->AddItem( PCB_ACTIONS::drawRectangle, haveFootprintCondition );
239  placeMenu->AddItem( PCB_ACTIONS::drawCircle, haveFootprintCondition );
240  placeMenu->AddItem( PCB_ACTIONS::drawLine, haveFootprintCondition );
241  placeMenu->AddItem( PCB_ACTIONS::drawPolygon, haveFootprintCondition );
242  placeMenu->AddItem( PCB_ACTIONS::drawZoneKeepout, haveFootprintCondition );
243 
244  placeMenu->AddSeparator();
245  placeMenu->AddItem( PCB_ACTIONS::setAnchor, haveFootprintCondition );
246  placeMenu->AddItem( ACTIONS::gridSetOrigin, haveFootprintCondition );
247 
248  placeMenu->Resolve();
249 
250  //-- Inspect menu ------------------------------------------------------
251  //
252  CONDITIONAL_MENU* inspectMenu = new CONDITIONAL_MENU( false, selTool );
253 
254  inspectMenu->AddItem( ACTIONS::measureTool, haveFootprintCondition );
255  inspectMenu->Resolve();
256 
257  //-- Tools menu --------------------------------------------------------
258  //
259  wxMenu* toolsMenu = new wxMenu;
260 
262  _( "&Load Footprint from PCB..." ),
263  _( "Load a footprint from the current board into the editor" ),
265 
267  _( "&Insert Footprint on PCB" ),
268  _( "Insert footprint onto current board" ),
270 
271 
272  //-- Preferences menu -------------------------------------------------
273  //
274  CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, selTool );
275 
276  auto acceleratedGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
278  };
279  auto standardGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
281  };
282 
285  prefsMenu->AddItem( wxID_PREFERENCES,
286  _( "Preferences...\tCTRL+," ),
287  _( "Show preferences for all open tools" ),
289 
290  prefsMenu->AddSeparator();
291  AddMenuLanguageList( prefsMenu, selTool );
292 
293  prefsMenu->AddSeparator();
294  prefsMenu->AddCheckItem( ACTIONS::acceleratedGraphics, acceleratedGraphicsCondition );
295  prefsMenu->AddCheckItem( ACTIONS::standardGraphics, standardGraphicsCondition );
296 
297  prefsMenu->Resolve();
298 
299  //--MenuBar -----------------------------------------------------------
300  //
301  menuBar->Append( fileMenu, _( "&File" ) );
302  menuBar->Append( editMenu, _( "&Edit" ) );
303  menuBar->Append( viewMenu, _( "&View" ) );
304  menuBar->Append( placeMenu, _( "&Place" ) );
305  menuBar->Append( inspectMenu, _( "&Inspect" ) );
306  menuBar->Append( toolsMenu, _( "&Tools" ) );
307  menuBar->Append( prefsMenu, _( "P&references" ) );
308  AddStandardHelpMenu( menuBar );
309  menuBar->SetDoubleBuffered( true );
310 
311  SetMenuBar( menuBar );
312  delete oldMenuBar;
313 }
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 drawLine
Definition: pcb_actions.h:140
static TOOL_ACTION show3DViewer
Definition: actions.h:152
static TOOL_ACTION saveToBoard
Definition: pcb_actions.h:343
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
Function Add() Adds a wxWidgets-style entry to the menu.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
static TOOL_ACTION footprintProperties
Definition: pcb_actions.h:354
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.
ACTION_MENU.
Definition: action_menu.h:44
static TOOL_ACTION doDelete
Definition: actions.h:74
static TOOL_ACTION drawArc
Definition: pcb_actions.h:144
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:232
static TOOL_ACTION cleanupGraphics
Definition: pcb_actions.h:303
static TOOL_ACTION layerAlphaDec
Definition: pcb_actions.h:272
static TOOL_ACTION zoomTool
Definition: actions.h:95
SELECTION_TOOL.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
int GetUndoCommandCount() const
Definition: base_screen.h:160
static TOOL_ACTION drawZoneKeepout
Definition: pcb_actions.h:149
static TOOL_ACTION layerAlphaInc
Definition: pcb_actions.h:271
static TOOL_ACTION zoomFitScreen
Definition: actions.h:93
static TOOL_ACTION drawPolygon
Definition: pcb_actions.h:141
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 placePad
Activation of the drawing tool (placing a PAD)
Definition: pcb_actions.h:358
const BITMAP_OPAQUE contrast_mode_xpm[1]
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
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Function GetDisplayOptions Display options control the way tracks, vias, outlines and other things ar...
static TOOL_ACTION setAnchor
Definition: pcb_actions.h:155
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 placeText
Definition: pcb_actions.h:145
static TOOL_ACTION zoomOutCenter
Definition: actions.h:91
static TOOL_ACTION createFootprint
Definition: pcb_actions.h:339
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
bool IsContentModified() override
Get if any footprints or libraries have been modified but not saved.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
static TOOL_ACTION measureTool
Definition: actions.h:148
void ReCreateMenuBar() override
(Re)Create the menubar for the module editor frame
static TOOL_ACTION copy
Definition: actions.h:70
const BITMAP_OPAQUE load_module_board_xpm[1]
static TOOL_ACTION toggleFootprintTree
Definition: pcb_actions.h:332
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:169
bool IsGridVisible() const
static TOOL_ACTION toggleGrid
Definition: actions.h:136
static TOOL_ACTION exportFootprint
Definition: pcb_actions.h:352
static TOOL_ACTION showFootprintBrowser
Definition: actions.h:155
LIB_ID GetTargetFPID() const
Return the LIB_ID of the part selected in the footprint tree, or the loaded part if there is no selec...
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:70
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
const BITMAP_OPAQUE export_xpm[1]
Definition: export.cpp:75
const BITMAP_OPAQUE import_xpm[1]
Definition: import.cpp:68
static TOOL_ACTION togglePolarCoords
Definition: actions.h:143
static TOOL_ACTION cut
Definition: actions.h:69
MODULE * GetFirstModule() const
Gets the first module in the list (used in footprint viewer/editor) or NULL if none.
Definition: class_board.h:330
bool ToolStackIsEmpty()
Definition: tools_holder.h:84
static TOOL_ACTION drawRectangle
Definition: pcb_actions.h:142
static TOOL_ACTION addLibrary
Definition: actions.h:52
HIGH_CONTRAST_MODE m_ContrastModeDisplay
How inactive layers are displayed.
const BITMAP_OPAQUE insert_module_board_xpm[1]
static TOOL_ACTION newLibrary
Definition: actions.h:51
void Resolve()
Function Resolve()
static TOOL_ACTION importFootprint
Definition: pcb_actions.h:351
const BITMAP_OPAQUE unit_mm_xpm[1]
Definition: unit_mm.cpp:28
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
static TOOL_ACTION padDisplayMode
Definition: pcb_actions.h:227
static TOOL_ACTION drawCircle
Definition: pcb_actions.h:143
static TOOL_ACTION graphicsOutlines
Display module edges as outlines.
Definition: pcb_actions.h:370
static TOOL_ACTION saveToLibrary
Definition: pcb_actions.h:344
static TOOL_ACTION metricUnits
Definition: actions.h:141
static TOOL_ACTION redo
Definition: actions.h:68
void AddClose(wxString aAppname="")
Function AddClose()
static TOOL_ACTION defaultPadProperties
Definition: pcb_actions.h:355
const BITMAP_OPAQUE plot_xpm[1]
Definition: plot.cpp:59
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
bool GetShowPolarCoords() const
For those frames that support polar coordinates.
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 saveAs
Definition: actions.h:55
const BITMAP_OPAQUE import_vector_xpm[1]
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION zoomRedraw
Definition: actions.h:87
static TOOL_ACTION acceleratedGraphics
Definition: actions.h:159
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
static TOOL_ACTION gridProperties
Definition: actions.h:137
const BITMAP_OPAQUE add_zone_xpm[1]
Definition: add_zone.cpp:74
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
BOARD * GetBoard() const
static TOOL_ACTION gridSetOrigin
Definition: actions.h:133
const BITMAP_OPAQUE preference_xpm[1]
Definition: preference.cpp:66
static TOOL_ACTION configurePaths
Definition: actions.h:167
static TOOL_ACTION highContrastMode
Definition: actions.h:99
int GetRedoCommandCount() const
Definition: base_screen.h:165
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
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
static TOOL_ACTION newFootprint
Definition: pcb_actions.h:336
bool empty() const
Definition: utf8.h:108
static TOOL_ACTION textOutlines
Display texts as lines.
Definition: pcb_actions.h:373