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/action_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  //-- File menu ----------------------------------------------------------
48  //
49  ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
50 
51  fileMenu->Add( ACTIONS::newLibrary );
52  fileMenu->Add( ACTIONS::addLibrary );
53  fileMenu->Add( PCB_ACTIONS::newFootprint );
54 
55 #ifdef KICAD_SCRIPTING
56  fileMenu->Add( PCB_ACTIONS::createFootprint );
57 #endif
58 
59  fileMenu->AppendSeparator();
60 
61  if( IsCurrentFPFromBoard() )
62  fileMenu->Add( PCB_ACTIONS::saveToBoard );
63  else
64  fileMenu->Add( PCB_ACTIONS::saveToLibrary );
65 
66  fileMenu->Add( ACTIONS::saveAs );
67  fileMenu->Add( ACTIONS::revert );
68 
69  fileMenu->AppendSeparator();
70 
71  ACTION_MENU* submenuImport = new ACTION_MENU( false );
72  submenuImport->SetTool( selTool );
73  submenuImport->SetTitle( _( "Import" ) );
74  submenuImport->SetIcon( import_xpm );
75 
76  submenuImport->Add( PCB_ACTIONS::importFootprint );
77  submenuImport->Add( _( "&Import Graphics..." ),
78  _( "Import 2D Drawing file to Footprint Editor on Drawings layer" ),
81 
82  fileMenu->Add( submenuImport );
83 
84  ACTION_MENU* submenuExport = new ACTION_MENU( false, selTool );
85  submenuExport->SetTitle( _( "Export" ) );
86  submenuExport->SetIcon( export_xpm );
87 
88  submenuExport->Add( PCB_ACTIONS::exportFootprint );
89  submenuExport->Add( _( "Export View as &PNG..." ),
90  _( "Create a PNG file from the current view" ),
92  plot_xpm );
93 
94  fileMenu->Add( submenuExport );
95 
96  fileMenu->AppendSeparator();
97  fileMenu->Add( ACTIONS::print );
98 
99  fileMenu->AppendSeparator();
100  fileMenu->AddClose( _( "Footprint Editor" ) );
101 
102 
103  //-- Edit menu -------------------------------------------------------
104  //
105  ACTION_MENU* editMenu = new ACTION_MENU( false, selTool );
106 
107  editMenu->Add( ACTIONS::undo );
108  editMenu->Add( ACTIONS::redo );
109 
110  editMenu->AppendSeparator();
111  editMenu->Add( ACTIONS::cut );
112  editMenu->Add( ACTIONS::copy );
113  editMenu->Add( ACTIONS::paste );
114  editMenu->Add( ACTIONS::doDelete );
115  editMenu->Add( ACTIONS::duplicate );
116 
117  editMenu->AppendSeparator();
118  editMenu->Add( ACTIONS::selectAll );
119 
120  editMenu->AppendSeparator();
123 
124  editMenu->AppendSeparator();
125  editMenu->Add( PCB_ACTIONS::cleanupGraphics );
126 
127 
128  //-- View menu -------------------------------------------------------
129  //
130  ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
131 
132  viewMenu->Add( ACTIONS::showFootprintBrowser );
133  viewMenu->Add( ACTIONS::show3DViewer );
134 
135  viewMenu->AppendSeparator();
136  viewMenu->Add( ACTIONS::zoomInCenter );
137  viewMenu->Add( ACTIONS::zoomOutCenter );
138  viewMenu->Add( ACTIONS::zoomFitScreen );
139  viewMenu->Add( ACTIONS::zoomTool );
140  viewMenu->Add( ACTIONS::zoomRedraw );
141 
142  viewMenu->AppendSeparator();
144  viewMenu->Add( ACTIONS::gridProperties );
146 
147  // Units submenu
148  ACTION_MENU* unitsSubMenu = new ACTION_MENU( false, selTool );
149  unitsSubMenu->SetTitle( _( "&Units" ) );
150  unitsSubMenu->SetIcon( unit_mm_xpm );
151  unitsSubMenu->Add( ACTIONS::inchesUnits, ACTION_MENU::CHECK );
152  unitsSubMenu->Add( ACTIONS::milsUnits, ACTION_MENU::CHECK );
154  viewMenu->Add( unitsSubMenu );
155 
157 
158  viewMenu->AppendSeparator();
159  // Drawing Mode Submenu
160  ACTION_MENU* drawingModeSubMenu = new ACTION_MENU( false, selTool );
161  drawingModeSubMenu->SetTitle( _( "&Drawing Mode" ) );
162  drawingModeSubMenu->SetIcon( add_zone_xpm );
163 
164  drawingModeSubMenu->Add( PCB_ACTIONS::padDisplayMode, ACTION_MENU::CHECK );
165  drawingModeSubMenu->Add( PCB_ACTIONS::graphicsOutlines, ACTION_MENU::CHECK );
166  drawingModeSubMenu->Add( PCB_ACTIONS::textOutlines, ACTION_MENU::CHECK );
167  viewMenu->Add( drawingModeSubMenu );
168 
169  // Contrast Mode Submenu
170  ACTION_MENU* contrastModeSubMenu = new ACTION_MENU( false, selTool );
171  contrastModeSubMenu->SetTitle( _( "&Contrast Mode" ) );
172  contrastModeSubMenu->SetIcon( contrast_mode_xpm );
173 
174  contrastModeSubMenu->Add( ACTIONS::highContrastMode, ACTION_MENU::CHECK );
175  contrastModeSubMenu->Add( PCB_ACTIONS::layerAlphaDec );
176  contrastModeSubMenu->Add( PCB_ACTIONS::layerAlphaInc );
177  viewMenu->Add( contrastModeSubMenu );
178 
179  viewMenu->AppendSeparator();
181 
182 
183  //-- Place menu -------------------------------------------------------
184  //
185  ACTION_MENU* placeMenu = new ACTION_MENU( false, selTool );
186 
187  placeMenu->Add( PCB_ACTIONS::placePad );
188 
189  placeMenu->AppendSeparator();
190  placeMenu->Add( PCB_ACTIONS::placeText );
191  placeMenu->Add( PCB_ACTIONS::drawArc );
192  placeMenu->Add( PCB_ACTIONS::drawRectangle );
193  placeMenu->Add( PCB_ACTIONS::drawCircle );
194  placeMenu->Add( PCB_ACTIONS::drawLine );
195  placeMenu->Add( PCB_ACTIONS::drawPolygon );
196  placeMenu->Add( PCB_ACTIONS::drawRuleArea );
197 
198  placeMenu->AppendSeparator();
199  placeMenu->Add( PCB_ACTIONS::setAnchor );
200  placeMenu->Add( ACTIONS::gridSetOrigin );
201 
202 
203  //-- Inspect menu ------------------------------------------------------
204  //
205  ACTION_MENU* inspectMenu = new ACTION_MENU( false, selTool );
206 
207  inspectMenu->Add( ACTIONS::measureTool );
208 
209 
210  //-- Tools menu --------------------------------------------------------
211  //
212  ACTION_MENU* toolsMenu = new ACTION_MENU( false, selTool );
213 
214  toolsMenu->Add( _( "&Load Footprint from PCB..." ),
215  _( "Load a footprint from the current board into the editor" ),
218 
219  toolsMenu->Add( _( "&Insert Footprint on PCB" ),
220  _( "Insert footprint onto current board" ),
223 
224 
225  //-- Preferences menu -------------------------------------------------
226  //
227  ACTION_MENU* prefsMenu = new ACTION_MENU( false, selTool );
228 
229  prefsMenu->Add( ACTIONS::configurePaths );
230  prefsMenu->Add( ACTIONS::showFootprintLibTable );
231  prefsMenu->Add( _( "Preferences...\tCTRL+," ),
232  _( "Show preferences for all open tools" ),
233  wxID_PREFERENCES,
234  preference_xpm );
235 
236  prefsMenu->AppendSeparator();
237  AddMenuLanguageList( prefsMenu, selTool );
238 
239 #ifndef __WXMAC__
240  prefsMenu->AppendSeparator();
243 #endif
244 
245  //--MenuBar -----------------------------------------------------------
246  //
247  menuBar->Append( fileMenu, _( "&File" ) );
248  menuBar->Append( editMenu, _( "&Edit" ) );
249  menuBar->Append( viewMenu, _( "&View" ) );
250  menuBar->Append( placeMenu, _( "&Place" ) );
251  menuBar->Append( inspectMenu, _( "&Inspect" ) );
252  menuBar->Append( toolsMenu, _( "&Tools" ) );
253  menuBar->Append( prefsMenu, _( "P&references" ) );
254  AddStandardHelpMenu( menuBar );
255 
256  SetMenuBar( menuBar );
257  delete oldMenuBar;
258 }
static TOOL_ACTION drawLine
Definition: pcb_actions.h:145
static TOOL_ACTION show3DViewer
Definition: actions.h:156
static TOOL_ACTION saveToBoard
Definition: pcb_actions.h:357
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
Adds a wxWidgets-style entry to the menu.
static TOOL_ACTION footprintProperties
Definition: pcb_actions.h:368
static TOOL_ACTION zoomInCenter
Definition: actions.h:91
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:43
static TOOL_ACTION doDelete
Definition: actions.h:75
static TOOL_ACTION drawArc
Definition: pcb_actions.h:149
static TOOL_ACTION cleanupGraphics
Definition: pcb_actions.h:317
static TOOL_ACTION layerAlphaDec
Definition: pcb_actions.h:286
static TOOL_ACTION zoomTool
Definition: actions.h:97
SELECTION_TOOL.
static TOOL_ACTION layerAlphaInc
Definition: pcb_actions.h:285
static TOOL_ACTION zoomFitScreen
Definition: actions.h:94
static TOOL_ACTION millimetersUnits
Definition: actions.h:144
static TOOL_ACTION drawPolygon
Definition: pcb_actions.h:146
static TOOL_ACTION standardGraphics
Definition: actions.h:164
static TOOL_ACTION placePad
Activation of the drawing tool (placing a PAD)
Definition: pcb_actions.h:372
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
static TOOL_ACTION setAnchor
Definition: pcb_actions.h:163
static TOOL_ACTION placeText
Definition: pcb_actions.h:150
static TOOL_ACTION zoomOutCenter
Definition: actions.h:92
static TOOL_ACTION createFootprint
Definition: pcb_actions.h:353
void SetTool(TOOL_INTERACTIVE *aTool)
Sets a tool that is the creator of the menu.
static TOOL_ACTION measureTool
Definition: actions.h:152
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:346
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:174
static TOOL_ACTION toggleGrid
Definition: actions.h:138
static TOOL_ACTION exportFootprint
Definition: pcb_actions.h:366
static TOOL_ACTION showFootprintBrowser
Definition: actions.h:159
static TOOL_ACTION inchesUnits
Definition: actions.h:142
void SetIcon(const BITMAP_OPAQUE *aIcon)
Assigns an icon for the entry.
Definition: action_menu.cpp:71
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
const BITMAP_OPAQUE export_xpm[1]
Definition: export.cpp:71
const BITMAP_OPAQUE import_xpm[1]
Definition: import.cpp:68
static TOOL_ACTION togglePolarCoords
Definition: actions.h:147
static TOOL_ACTION cut
Definition: actions.h:69
static TOOL_ACTION drawRectangle
Definition: pcb_actions.h:147
static TOOL_ACTION addLibrary
Definition: actions.h:52
const BITMAP_OPAQUE insert_module_board_xpm[1]
void AddMenuLanguageList(ACTION_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
static TOOL_ACTION newLibrary
Definition: actions.h:51
static TOOL_ACTION milsUnits
Definition: actions.h:143
static TOOL_ACTION importFootprint
Definition: pcb_actions.h:365
const BITMAP_OPAQUE unit_mm_xpm[1]
Definition: unit_mm.cpp:26
static TOOL_ACTION padDisplayMode
Definition: pcb_actions.h:241
static TOOL_ACTION drawCircle
Definition: pcb_actions.h:148
static TOOL_ACTION graphicsOutlines
Display module edges as outlines.
Definition: pcb_actions.h:384
static TOOL_ACTION saveToLibrary
Definition: pcb_actions.h:358
static TOOL_ACTION redo
Definition: actions.h:68
static TOOL_ACTION defaultPadProperties
Definition: pcb_actions.h:369
static constexpr bool CHECK
Definition: action_menu.h:162
const BITMAP_OPAQUE plot_xpm[1]
Definition: plot.cpp:59
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
static TOOL_ACTION drawRuleArea
Definition: pcb_actions.h:157
void SetTitle(const wxString &aTitle) override
Sets title for the menu.
Definition: action_menu.cpp:89
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:88
static TOOL_ACTION acceleratedGraphics
Definition: actions.h:163
static TOOL_ACTION gridProperties
Definition: actions.h:139
const BITMAP_OPAQUE add_zone_xpm[1]
Definition: add_zone.cpp:59
static TOOL_ACTION undo
Definition: actions.h:67
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:100
static TOOL_ACTION gridSetOrigin
Definition: actions.h:135
const BITMAP_OPAQUE preference_xpm[1]
Definition: preference.cpp:53
static TOOL_ACTION configurePaths
Definition: actions.h:172
static TOOL_ACTION highContrastMode
Definition: actions.h:101
static TOOL_ACTION selectAll
Definition: actions.h:73
static TOOL_ACTION paste
Definition: actions.h:71
static TOOL_ACTION duplicate
Definition: actions.h:74
static TOOL_ACTION revert
Definition: actions.h:58
static TOOL_ACTION newFootprint
Definition: pcb_actions.h:350
void AddClose(wxString aAppname="")
Add a standard close item to the menu with the accelerator key CTRL-W.
static TOOL_ACTION textOutlines
Display texts as lines.
Definition: pcb_actions.h:387