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-2019 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 
29 #include <advanced_config.h>
30 #include <menus_helpers.h>
31 #include <pgm_base.h>
32 #include <tool/tool_manager.h>
33 #include <tool/conditional_menu.h>
34 #include <tool/actions.h>
35 #include <tools/selection_tool.h>
36 #include <tools/pcb_actions.h>
37 #include "help_common_strings.h"
38 #include "pcbnew.h"
39 #include "pcbnew_id.h"
40 
41 
43 {
45  // wxWidgets handles the Mac Application menu behind the scenes, but that means
46  // we always have to start from scratch with a new wxMenuBar.
47  wxMenuBar* oldMenuBar = GetMenuBar();
48  wxMenuBar* menuBar = new wxMenuBar();
49 
50  auto modifiedDocumentCondition = [this]( const SELECTION& sel ) {
51  return IsContentModified();
52  };
53  auto haveFootprintCondition = [this]( const SELECTION& aSelection ) {
54  return GetBoard()->GetFirstModule() != nullptr;
55  };
56  auto footprintTargettedCondition = [this]( const SELECTION& aSelection ) {
57  return !GetTargetFPID().GetLibItemName().empty();
58  };
59 
60  //-- File menu ----------------------------------------------------------
61  //
62  CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool );
63 
67 #ifdef KICAD_SCRIPTING
69 #endif
70 
71  fileMenu->AddSeparator();
72  if( IsCurrentFPFromBoard() )
73  fileMenu->AddItem( PCB_ACTIONS::saveToBoard, modifiedDocumentCondition );
74  else
75  fileMenu->AddItem( PCB_ACTIONS::saveToLibrary, modifiedDocumentCondition );
76  fileMenu->AddItem( ACTIONS::saveAs, footprintTargettedCondition );
77  fileMenu->AddItem( ACTIONS::revert, modifiedDocumentCondition );
78 
79  fileMenu->AddSeparator();
80 
81  ACTION_MENU* submenuImport = new ACTION_MENU( false );
82  submenuImport->SetTool( selTool );
83  submenuImport->SetTitle( _( "Import" ) );
84  submenuImport->SetIcon( import_xpm );
85 
86  submenuImport->Add( PCB_ACTIONS::importFootprint );
87  submenuImport->Add( _( "&Import Graphics..." ),
88  _( "Import 2D Drawing file to Footprint Editor on Drawings layer" ),
90 
91  fileMenu->AddMenu( submenuImport, SELECTION_CONDITIONS::ShowAlways );
92 
93  CONDITIONAL_MENU* submenuExport = new CONDITIONAL_MENU( false, selTool );
94  submenuExport->SetTitle( _( "Export" ) );
95  submenuExport->SetIcon( export_xpm );
96 
97  submenuExport->AddItem( PCB_ACTIONS::exportFootprint, haveFootprintCondition );
98  submenuExport->AddItem( ID_MODEDIT_SAVE_PNG, _( "Export View as &PNG..." ),
99  _( "Create a PNG file from the current view" ),
101 
102  fileMenu->AddMenu( submenuExport, SELECTION_CONDITIONS::ShowAlways );
103 
104  fileMenu->AddSeparator();
105  fileMenu->AddItem( ACTIONS::print, haveFootprintCondition );
106 
107  fileMenu->AddSeparator();
108  fileMenu->AddClose( _( "Footprint Editor" ) );
109 
110  fileMenu->Resolve();
111 
112  //-- Edit menu -------------------------------------------------------
113  //
114  CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, selTool );
115 
116  auto enableUndoCondition = [ this ] ( const SELECTION& sel ) {
117  return GetScreen() && GetScreen()->GetUndoCommandCount() > 0;
118  };
119  auto enableRedoCondition = [ this ] ( const SELECTION& sel ) {
120  return GetScreen() && GetScreen()->GetRedoCommandCount() > 0;
121  };
122  auto noActiveToolCondition = [ this ] ( const SELECTION& aSelection ) {
123  return ToolStackIsEmpty();
124  };
125 
126  editMenu->AddItem( ACTIONS::undo, enableUndoCondition );
127  editMenu->AddItem( ACTIONS::redo, enableRedoCondition );
128 
129  editMenu->AddSeparator();
132  editMenu->AddItem( ACTIONS::paste, noActiveToolCondition );
135 
136  editMenu->AddSeparator();
137  editMenu->AddItem( PCB_ACTIONS::footprintProperties, 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 sketchEdgesCondition = [ this ] ( const SELECTION& aSel ) {
166  };
167  auto contrastModeCondition = [ this ] ( const SELECTION& aSel ) {
169  };
170  auto searchTreeShownCondition = [ this ] ( const SELECTION& aSel ) {
171  return IsSearchTreeShown();
172  };
173 
176 
177  viewMenu->AddSeparator();
183 
184  viewMenu->AddSeparator();
185  viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition );
187  viewMenu->AddCheckItem( PCB_ACTIONS::togglePolarCoords, polarCoordsCondition );
188 
189  // Units submenu
190  CONDITIONAL_MENU* unitsSubMenu = new CONDITIONAL_MENU( false, selTool );
191  unitsSubMenu->SetTitle( _( "&Units" ) );
192  unitsSubMenu->SetIcon( unit_mm_xpm );
193  unitsSubMenu->AddCheckItem( ACTIONS::imperialUnits, imperialUnitsCondition );
194  unitsSubMenu->AddCheckItem( ACTIONS::metricUnits, metricUnitsCondition );
195  viewMenu->AddMenu( unitsSubMenu );
196 
197  viewMenu->AddCheckItem( ACTIONS::toggleCursorStyle, fullCrosshairCondition );
198 
199  viewMenu->AddSeparator();
200  // Drawing Mode Submenu
201  CONDITIONAL_MENU* drawingModeSubMenu = new CONDITIONAL_MENU( false, selTool );
202  drawingModeSubMenu->SetTitle( _( "&Drawing Mode" ) );
203  drawingModeSubMenu->SetIcon( add_zone_xpm );
204 
205  drawingModeSubMenu->AddCheckItem( PCB_ACTIONS::padDisplayMode, sketchPadsCondition );
206  drawingModeSubMenu->AddCheckItem( PCB_ACTIONS::moduleEdgeOutlines, sketchEdgesCondition );
207  viewMenu->AddMenu( drawingModeSubMenu );
208 
209  // Contrast Mode Submenu
210  CONDITIONAL_MENU* contrastModeSubMenu = new CONDITIONAL_MENU( false, selTool );
211  contrastModeSubMenu->SetTitle( _( "&Contrast Mode" ) );
212  contrastModeSubMenu->SetIcon( contrast_mode_xpm );
213 
214  contrastModeSubMenu->AddCheckItem( ACTIONS::highContrastMode, contrastModeCondition );
217  viewMenu->AddMenu( contrastModeSubMenu );
218 
219  viewMenu->AddSeparator();
220  viewMenu->AddCheckItem( PCB_ACTIONS::toggleFootprintTree, searchTreeShownCondition );
221 
222  viewMenu->Resolve();
223 
224  //-- Place menu -------------------------------------------------------
225  //
226  CONDITIONAL_MENU* placeMenu = new CONDITIONAL_MENU( false, selTool );
227 
228  placeMenu->AddItem( PCB_ACTIONS::placePad, haveFootprintCondition );
229 
230  placeMenu->AddSeparator();
231  placeMenu->AddItem( PCB_ACTIONS::placeText, haveFootprintCondition );
232  placeMenu->AddItem( PCB_ACTIONS::drawArc, haveFootprintCondition );
233  placeMenu->AddItem( PCB_ACTIONS::drawCircle, haveFootprintCondition );
234  placeMenu->AddItem( PCB_ACTIONS::drawLine, haveFootprintCondition );
235  placeMenu->AddItem( PCB_ACTIONS::drawPolygon, haveFootprintCondition );
236  placeMenu->AddItem( PCB_ACTIONS::drawZoneKeepout, haveFootprintCondition );
237 
238  placeMenu->AddSeparator();
239  placeMenu->AddItem( PCB_ACTIONS::setAnchor, haveFootprintCondition );
240  placeMenu->AddItem( ACTIONS::gridSetOrigin, haveFootprintCondition );
241 
242  placeMenu->Resolve();
243 
244  //-- Inspect menu ------------------------------------------------------
245  //
246  CONDITIONAL_MENU* inspectMenu = new CONDITIONAL_MENU( false, selTool );
247 
248  inspectMenu->AddItem( ACTIONS::measureTool, haveFootprintCondition );
249  inspectMenu->Resolve();
250 
251  //-- Tools menu --------------------------------------------------------
252  //
253  wxMenu* toolsMenu = new wxMenu;
254 
256  _( "&Load Footprint from PCB..." ),
257  _( "Load a footprint from the current board into the editor" ),
259 
261  _( "&Insert Footprint on PCB" ),
262  _( "Insert footprint onto current board" ),
264 
265 
266  //-- Preferences menu -------------------------------------------------
267  //
268  CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, selTool );
269 
270  auto acceleratedGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
272  };
273  auto standardGraphicsCondition = [ this ] ( const SELECTION& aSel ) {
275  };
276 
279  prefsMenu->AddItem( wxID_PREFERENCES,
280  _( "Preferences...\tCTRL+," ),
281  _( "Show preferences for all open tools" ),
283 
284  prefsMenu->AddSeparator();
285  AddMenuLanguageList( prefsMenu, selTool );
286 
287  prefsMenu->AddSeparator();
288  prefsMenu->AddCheckItem( ACTIONS::acceleratedGraphics, acceleratedGraphicsCondition );
289  prefsMenu->AddCheckItem( ACTIONS::standardGraphics, standardGraphicsCondition );
290 
291  prefsMenu->Resolve();
292 
293  //--MenuBar -----------------------------------------------------------
294  //
295  menuBar->Append( fileMenu, _( "&File" ) );
296  menuBar->Append( editMenu, _( "&Edit" ) );
297  menuBar->Append( viewMenu, _( "&View" ) );
298  menuBar->Append( placeMenu, _( "&Place" ) );
299  menuBar->Append( inspectMenu, _( "&Inspect" ) );
300  menuBar->Append( toolsMenu, _( "&Tools" ) );
301  menuBar->Append( prefsMenu, _( "P&references" ) );
302  AddStandardHelpMenu( menuBar );
303 
304  SetMenuBar( menuBar );
305  delete oldMenuBar;
306 }
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:148
static TOOL_ACTION show3DViewer
Definition: actions.h:148
static TOOL_ACTION saveToBoard
Definition: pcb_actions.h:342
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:353
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.
virtual bool IsGridVisible() const override
Function IsGridVisible()
ACTION_MENU.
Definition: action_menu.h:43
static TOOL_ACTION doDelete
Definition: actions.h:74
static TOOL_ACTION drawArc
Definition: pcb_actions.h:151
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:251
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:201
static TOOL_ACTION drawZoneKeepout
Definition: pcb_actions.h:156
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:149
static TOOL_ACTION standardGraphics
Definition: actions.h:155
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:357
const BITMAP_OPAQUE contrast_mode_xpm[1]
static TOOL_ACTION print
Definition: actions.h:60
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Function GetDisplayOptions returns the display options current in use Display options are relative to...
static TOOL_ACTION setAnchor
Definition: pcb_actions.h:162
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 placeText
Definition: pcb_actions.h:152
static TOOL_ACTION zoomOutCenter
Definition: actions.h:91
static TOOL_ACTION createFootprint
Definition: pcb_actions.h:338
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:79
static TOOL_ACTION measureTool
Definition: actions.h:144
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:331
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:164
static TOOL_ACTION toggleGrid
Definition: actions.h:132
static TOOL_ACTION exportFootprint
Definition: pcb_actions.h:351
static TOOL_ACTION showFootprintBrowser
Definition: actions.h:151
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...
strings common to toolbars and menubar
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
const BITMAP_OPAQUE import_xpm[1]
Definition: import.cpp:68
static TOOL_ACTION togglePolarCoords
Definition: actions.h:139
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:275
static TOOL_ACTION addLibrary
Definition: actions.h:52
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:350
const BITMAP_OPAQUE unit_mm_xpm[1]
Definition: unit_mm.cpp:28
static TOOL_ACTION moduleEdgeOutlines
Display module edges as outlines.
Definition: pcb_actions.h:369
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
static TOOL_ACTION padDisplayMode
Definition: pcb_actions.h:228
static TOOL_ACTION drawCircle
Definition: pcb_actions.h:150
static TOOL_ACTION saveToLibrary
Definition: pcb_actions.h:343
static TOOL_ACTION metricUnits
Definition: actions.h:137
static TOOL_ACTION redo
Definition: actions.h:68
void AddClose(wxString aAppname="")
Function AddClose()
static TOOL_ACTION defaultPadProperties
Definition: pcb_actions.h:354
const BITMAP_OPAQUE plot_xpm[1]
Definition: plot.cpp:59
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:86
see class PGM_BASE
bool GetShowPolarCoords() const
For those frames that support polar coordinates.
bool ToolStackIsEmpty()
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:31
static TOOL_ACTION zoomRedraw
Definition: actions.h:87
static TOOL_ACTION acceleratedGraphics
Definition: actions.h:154
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
static TOOL_ACTION gridProperties
Definition: actions.h:133
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
TOOL_MANAGER * m_toolManager
BOARD * GetBoard() const
static TOOL_ACTION gridSetOrigin
Definition: actions.h:129
const BITMAP_OPAQUE preference_xpm[1]
Definition: preference.cpp:66
static TOOL_ACTION configurePaths
Definition: actions.h:162
static TOOL_ACTION highContrastMode
Definition: actions.h:99
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
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:335
bool empty() const
Definition: utf8.h:108