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-2017 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 
31 #include <menus_helpers.h>
32 #include <pgm_base.h>
33 
34 #include "eeschema_id.h"
35 #include "general.h"
36 #include "help_common_strings.h"
37 #include "hotkeys.h"
38 #include "libeditframe.h"
39 
40 
45 {
46  // Create and try to get the current menubar
47  wxString text;
48  wxMenuBar* menuBar = GetMenuBar();
49 
50  if( !menuBar )
51  menuBar = new wxMenuBar();
52 
53  // Delete all existing menus so they can be rebuilt.
54  // This allows language changes of the menu text on the fly.
55  menuBar->Freeze();
56 
57  while( menuBar->GetMenuCount() )
58  delete menuBar->Remove( 0 );
59 
60  // Recreate all menus:
61 
62  // Menu File:
63  wxMenu* fileMenu = new wxMenu;
64 
65  // Creating/loading libraries
66  AddMenuItem( fileMenu,
68  _( "&Create New Library" ),
69  _( "Creates an empty library" ),
70  KiBitmap( new_library_xpm ) );
71 
72  AddMenuItem( fileMenu,
74  _( "&Add Existing Library" ),
75  _( "Adds a previously created library" ),
76  KiBitmap( add_library_xpm ) );
77 
78  // Separator
79  fileMenu->AppendSeparator();
80 
81  // Save library variants
82  text = AddHotkeyName( _( "&Save Library" ), g_Libedit_Hokeys_Descr, HK_SAVE_LIB );
83  AddMenuItem( fileMenu,
85  _( "Save the current active library" ),
86  KiBitmap( save_library_xpm ) );
87 
88  AddMenuItem( fileMenu,
90  _( "&Save Library As.." ),
91  _( "Save the current library to a new file" ),
92  KiBitmap( save_as_xpm ) );
93 
94  AddMenuItem( fileMenu,
96  _( "&Save All Libraries" ),
97  _( "Save all library changes" ),
98  KiBitmap( save_xpm ) );
99 
100  // Separator
101  fileMenu->AppendSeparator();
102 
103  // Export as png file
104  AddMenuItem( fileMenu,
106  _( "Create &PNG File from Screen..." ),
107  _( "Create a PNG file from the part displayed on screen" ),
108  KiBitmap( plot_xpm ) );
109 
110  // Export as SVG file
111  AddMenuItem( fileMenu,
113  _( "Create S&VG File..." ),
114  _( "Create a SVG file from the current loaded part" ),
115  KiBitmap( plot_svg_xpm ) );
116 
117  // Separator
118  fileMenu->AppendSeparator();
119 
120  // Quit
121  AddMenuItem( fileMenu,
122  wxID_EXIT,
123  _( "&Quit" ),
124  _( "Quit Library Editor" ),
125  KiBitmap( exit_xpm ) );
126 
127  // Edit menu
128  wxMenu* editMenu = new wxMenu;
129 
130  // Undo
131  text = AddHotkeyName( _( "&Undo" ), g_Libedit_Hokeys_Descr, HK_UNDO );
132 
133  AddMenuItem( editMenu,
134  wxID_UNDO,
135  text,
136  _( "Undo last edit" ),
137  KiBitmap( undo_xpm ) );
138 
139  // Redo
140  text = AddHotkeyName( _( "&Redo" ), g_Libedit_Hokeys_Descr, HK_REDO );
141  AddMenuItem( editMenu,
142  wxID_REDO,
143  text,
144  _( "Redo the last undo command" ),
145  KiBitmap( redo_xpm ) );
146 
147  // Menu View:
148  wxMenu* viewMenu = new wxMenu;
149 
163  // Zoom in
164  text = _( "Zoom &In" );
165  AddMenuItem( viewMenu, ID_ZOOM_IN, text, HELP_ZOOM_IN, KiBitmap( zoom_in_xpm ) );
166 
167  // Zoom out
168  text = _( "Zoom &Out" );
169  AddMenuItem( viewMenu, ID_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) );
170 
171  // Fit on screen
172  text = AddHotkeyName( _( "&Fit on Screen" ), g_Libedit_Hokeys_Descr, HK_ZOOM_AUTO );
173  AddMenuItem( viewMenu, ID_ZOOM_PAGE, text, HELP_ZOOM_FIT, KiBitmap( zoom_fit_in_page_xpm ) );
174 
175  // Redraw
176  text = AddHotkeyName( _( "&Redraw" ), g_Libedit_Hokeys_Descr, HK_ZOOM_REDRAW );
177  AddMenuItem( viewMenu, ID_ZOOM_REDRAW, text, HELP_ZOOM_REDRAW, KiBitmap( zoom_redraw_xpm ) );
178 
179  // Separator
180  viewMenu->AppendSeparator();
181 
182  AddMenuItem( viewMenu,
184  _( "&Search tree" ),
185  _( "Toggles the search tree visibility" ),
186  KiBitmap( search_tree_xpm ) );
187 
188  // Menu Part:
189  wxMenu* partMenu = new wxMenu;
190 
191  AddMenuItem( partMenu,
193  _( "Create &New" ),
194  _( "Create a new empty part" ),
195  KiBitmap( new_component_xpm ) );
196 
197  text = AddHotkeyName( _( "&Save Part" ), g_Libedit_Hokeys_Descr, HK_SAVE_PART );
198  AddMenuItem( partMenu,
200  text,
201  _( "Saves the current part to the library" ),
202  KiBitmap( save_part_xpm ) );
203 
204  partMenu->AppendSeparator();
205 
206  AddMenuItem( partMenu,
208  _( "&Import" ),
209  _( "Import a part to the current library" ),
210  KiBitmap( import_part_xpm ) );
211 
212  AddMenuItem( partMenu,
214  _( "&Export" ),
215  _( "Export the current part" ),
216  KiBitmap( export_part_xpm ) );
217 
218  partMenu->AppendSeparator();
219 
220  AddMenuItem( partMenu,
222  _( "&Properties" ),
223  _( "Edit part properties" ),
224  KiBitmap( part_properties_xpm ) );
225 
226  AddMenuItem( partMenu,
228  _( "&Fields" ),
229  _( "Edit field properties" ),
230  KiBitmap( edit_text_xpm ) );
231 
232  partMenu->AppendSeparator();
233 
234  AddMenuItem( partMenu,
236  _( "Pi&n Table" ),
237  _( "Show pin table" ),
238  KiBitmap( pin_table_xpm ) );
239 
240  AddMenuItem( partMenu,
242  _( "ERC" ),
243  _( "Check duplicate and off grid pins" ),
244  KiBitmap( erc_xpm ) );
245 
246  // Menu Place:
247  wxMenu* placeMenu = new wxMenu;
248 
249  // Pin
250  AddMenuItem( placeMenu,
252  _( "&Pin" ),
253  HELP_ADD_PIN,
254  KiBitmap( pin_xpm ) );
255 
256  // Graphic text
257  AddMenuItem( placeMenu,
259  _( "Graphic &Text" ),
261  KiBitmap( text_xpm ) );
262 
263  // Graphic rectangle
264  AddMenuItem( placeMenu,
266  _( "&Rectangle" ),
268  KiBitmap( add_rectangle_xpm ) );
269 
270  // Graphic Circle
271  AddMenuItem( placeMenu,
273  _( "&Circle" ),
275  KiBitmap( add_circle_xpm ) );
276 
277  // Graphic Arc
278  AddMenuItem( placeMenu,
280  _( "&Arc" ),
282  KiBitmap( add_arc_xpm ) );
283 
284  // Graphic Line or Polygon
285  AddMenuItem( placeMenu,
287  _( "&Line or Polygon" ),
289  KiBitmap( add_polygon_xpm ) );
290 
291  // Menu Preferences:
292  wxMenu* preferencesMenu = new wxMenu;
293 
294  // Library list
295  AddMenuItem( preferencesMenu,
297  _( "Manage Symbol Libraries" ),
298  _( "Edit the global and project symbol library tables." ),
299  KiBitmap( library_table_xpm ) );
300 
301  // Default values and options
302  AddMenuItem( preferencesMenu,
303  wxID_PREFERENCES,
304  _( "General &Options" ),
305  _( "Set Part Editor default values and options" ),
306  KiBitmap( preference_xpm ) );
307 
308  // Language submenu
309  Pgm().AddMenuLanguageList( preferencesMenu );
310 
311  // Hotkey submenu
312  AddHotkeyConfigMenu( preferencesMenu );
313 
314  // Menu Help:
315  wxMenu* helpMenu = new wxMenu;
316 
317  // Contents
318  AddMenuItem( helpMenu,
319  wxID_HELP,
320  _( "Eeschema &Manual" ),
321  _( "Open the Eeschema Manual" ),
322  KiBitmap( online_help_xpm ) );
323 
324  AddMenuItem( helpMenu,
325  wxID_INDEX,
326  _( "&Getting Started in KiCad" ),
327  _( "Open the \"Getting Started in KiCad\" guide for beginners" ),
328  KiBitmap( help_xpm ) );
329 
330  AddMenuItem( helpMenu,
332  _( "&List Hotkeys" ),
333  _( "Displays the current hotkeys list and corresponding commands" ),
334  KiBitmap( hotkeys_xpm ) );
335 
336  helpMenu->AppendSeparator();
338  _( "Get &Involved" ),
339  _( "Contribute to KiCad (opens a web browser)" ),
340  KiBitmap( info_xpm ) );
341 
342  // About Eeschema
343  helpMenu->AppendSeparator();
344 
345  AddMenuItem( helpMenu,
346  wxID_ABOUT,
347  _( "&About KiCad" ),
348  _( "About KiCad" ),
349  KiBitmap( about_xpm ) );
350 
351  // Create the menubar and append all submenus
352  menuBar->Append( fileMenu, _( "&File" ) );
353  menuBar->Append( editMenu, _( "&Edit" ) );
354  menuBar->Append( viewMenu, _( "&View" ) );
355  menuBar->Append( partMenu, _( "&Part" ) );
356  menuBar->Append( placeMenu, _( "&Place" ) );
357  menuBar->Append( preferencesMenu, _( "P&references" ) );
358  menuBar->Append( helpMenu, _( "&Help" ) );
359 
360  menuBar->Thaw();
361 
362  // Associate the menu bar with the frame, if no previous menubar
363  if( GetMenuBar() == NULL )
364  SetMenuBar( menuBar );
365  else
366  menuBar->Refresh();
367 }
#define HELP_ADD_BODYRECT
#define HELP_ADD_BODYCIRCLE
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:55
#define HELP_ZOOM_FIT
Definition: id.h:232
struct EDA_HOTKEY_CONFIG g_Libedit_Hokeys_Descr[]
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
#define HELP_ZOOM_OUT
#define HELP_ZOOM_REDRAW
#define HELP_ADD_BODYPOLYGON
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
void ReCreateMenuBar() override
(Re)Create the menubar for the part editor frame
strings common to toolbars and menubar
#define HELP_ADD_BODYTEXT
void AddHotkeyConfigMenu(wxMenu *aMenu)
#define HELP_ADD_BODYARC
wxString AddHotkeyName(const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType)
Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value) ...
see class PGM_BASE
#define HELP_ADD_PIN
#define HELP_ZOOM_IN
VTBL_ENTRY void AddMenuLanguageList(wxMenu *MasterMenu)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
Definition: pgm_base.cpp:824
static const char * text_xpm[]
Definition of class LIB_EDIT_FRAME.