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-2018 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 "lib_edit_frame.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  _( "&New Library..." ),
69  _( "Creates an empty library" ),
70  KiBitmap( new_library_xpm ) );
71 
72  AddMenuItem( fileMenu,
74  _( "&Add Library..." ),
75  _( "Adds a previously created library" ),
76  KiBitmap( add_library_xpm ) );
77 
78  // Separator
79  fileMenu->AppendSeparator();
80 
81  // Save library variants
82  AddMenuItem( fileMenu,
84  _( "&Save Library" ),
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  text = AddHotkeyName( _( "Save All &Libraries" ), g_Libedit_Hokeys_Descr, HK_SAVE_ALL_LIBS );
95  AddMenuItem( fileMenu, ID_LIBEDIT_SAVE_ALL_LIBS, text, _( "Save all library changes" ),
96  KiBitmap( save_xpm ) );
97 
98  // Separator
99  fileMenu->AppendSeparator();
100 
101  // Export as png file
102  AddMenuItem( fileMenu,
104  _( "Export Current View as &PNG..." ),
105  _( "Create a PNG file from the current view" ),
106  KiBitmap( plot_xpm ) );
107 
108  // Export as SVG file
109  AddMenuItem( fileMenu,
111  _( "Create S&VG File..." ),
112  _( "Create a SVG file from the current symbol" ),
113  KiBitmap( plot_svg_xpm ) );
114 
115  // Separator
116  fileMenu->AppendSeparator();
117 
118  // Quit
119  AddMenuItem( fileMenu,
120  wxID_EXIT,
121  _( "&Quit" ),
122  _( "Quit Library Editor" ),
123  KiBitmap( exit_xpm ) );
124 
125  // Edit menu
126  wxMenu* editMenu = new wxMenu;
127 
128  // Undo
129  text = AddHotkeyName( _( "&Undo" ), g_Libedit_Hokeys_Descr, HK_UNDO );
130 
131  AddMenuItem( editMenu,
132  wxID_UNDO,
133  text,
134  _( "Undo last edit" ),
135  KiBitmap( undo_xpm ) );
136 
137  // Redo
138  text = AddHotkeyName( _( "&Redo" ), g_Libedit_Hokeys_Descr, HK_REDO );
139  AddMenuItem( editMenu,
140  wxID_REDO,
141  text,
142  _( "Redo the last undo command" ),
143  KiBitmap( redo_xpm ) );
144 
145  // Menu View:
146  wxMenu* viewMenu = new wxMenu;
147 
161  // Zoom in
162  text = _( "Zoom &In" );
163  AddMenuItem( viewMenu, ID_ZOOM_IN, text, HELP_ZOOM_IN, KiBitmap( zoom_in_xpm ) );
164 
165  // Zoom out
166  text = _( "Zoom &Out" );
167  AddMenuItem( viewMenu, ID_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) );
168 
169  // Fit on screen
170  text = AddHotkeyName( _( "&Fit on Screen" ), g_Libedit_Hokeys_Descr, HK_ZOOM_AUTO );
171  AddMenuItem( viewMenu, ID_ZOOM_PAGE, text, HELP_ZOOM_FIT, KiBitmap( zoom_fit_in_page_xpm ) );
172 
173  // Redraw
174  text = AddHotkeyName( _( "&Redraw" ), g_Libedit_Hokeys_Descr, HK_ZOOM_REDRAW );
175  AddMenuItem( viewMenu, ID_ZOOM_REDRAW, text, HELP_ZOOM_REDRAW, KiBitmap( zoom_redraw_xpm ) );
176 
177  // Separator
178  viewMenu->AppendSeparator();
179 
180  AddMenuItem( viewMenu,
182  _( "&Search Tree" ),
183  _( "Toggles the search tree visibility" ),
184  KiBitmap( search_tree_xpm ) );
185 
186  // Menu Part:
187  wxMenu* partMenu = new wxMenu;
188 
189  AddMenuItem( partMenu,
191  _( "&New Symbol..." ),
192  _( "Create a new empty symbol" ),
193  KiBitmap( new_component_xpm ) );
194 
195  AddMenuItem( partMenu,
197  _( "&Save Symbol" ),
198  _( "Saves the current symbol to the library" ),
199  KiBitmap( save_part_xpm ) );
200 
201  partMenu->AppendSeparator();
202 
203  AddMenuItem( partMenu,
205  _( "&Import Symbol..." ),
206  _( "Import a symbol to the current library" ),
207  KiBitmap( import_part_xpm ) );
208 
209  AddMenuItem( partMenu,
211  _( "&Export Symbol..." ),
212  _( "Export the current symbol" ),
213  KiBitmap( export_part_xpm ) );
214 
215  partMenu->AppendSeparator();
216 
217  AddMenuItem( partMenu,
219  _( "&Properties..." ),
220  _( "Edit symbol properties" ),
221  KiBitmap( part_properties_xpm ) );
222 
223  AddMenuItem( partMenu,
225  _( "&Fields..." ),
226  _( "Edit field properties" ),
227  KiBitmap( edit_text_xpm ) );
228 
229  partMenu->AppendSeparator();
230 
231  AddMenuItem( partMenu,
233  _( "Pi&n Table..." ),
234  _( "Show pin table" ),
235  KiBitmap( pin_table_xpm ) );
236 
237  AddMenuItem( partMenu,
239  _( "Electrical Rules Checker" ),
240  _( "Check duplicate and off grid pins" ),
241  KiBitmap( erc_xpm ) );
242 
243  // Menu Place:
244  wxMenu* placeMenu = new wxMenu;
245 
246  // Pin
247  AddMenuItem( placeMenu,
249  _( "&Pin" ),
250  HELP_ADD_PIN,
251  KiBitmap( pin_xpm ) );
252 
253  // Graphic text
254  AddMenuItem( placeMenu,
256  _( "Graphic &Text" ),
258  KiBitmap( text_xpm ) );
259 
260  // Graphic rectangle
261  AddMenuItem( placeMenu,
263  _( "&Rectangle" ),
265  KiBitmap( add_rectangle_xpm ) );
266 
267  // Graphic Circle
268  AddMenuItem( placeMenu,
270  _( "&Circle" ),
272  KiBitmap( add_circle_xpm ) );
273 
274  // Graphic Arc
275  AddMenuItem( placeMenu,
277  _( "&Arc" ),
279  KiBitmap( add_arc_xpm ) );
280 
281  // Graphic Line or Polygon
282  AddMenuItem( placeMenu,
284  _( "&Line or Polygon" ),
286  KiBitmap( add_polygon_xpm ) );
287 
288  // Menu Preferences:
289  wxMenu* preferencesMenu = new wxMenu;
290 
291  // Library list
292  AddMenuItem( preferencesMenu,
294  _( "Manage Symbol Libraries..." ),
295  _( "Edit the global and project symbol library tables." ),
296  KiBitmap( library_table_xpm ) );
297 
298  // Default values and options
299  AddMenuItem( preferencesMenu,
300  wxID_PREFERENCES,
301  _( "General &Options..." ),
302  _( "Set Symbol Editor default values and options" ),
303  KiBitmap( preference_xpm ) );
304 
305  // Language submenu
306  Pgm().AddMenuLanguageList( preferencesMenu );
307 
308  // Hotkey submenu
309  AddHotkeyConfigMenu( preferencesMenu );
310 
311  // Menu Help:
312  wxMenu* helpMenu = new wxMenu;
313 
314  // Contents
315  AddMenuItem( helpMenu,
316  wxID_HELP,
317  _( "Eeschema &Manual" ),
318  _( "Open the Eeschema Manual" ),
319  KiBitmap( online_help_xpm ) );
320 
321  AddMenuItem( helpMenu,
322  wxID_INDEX,
323  _( "&Getting Started in KiCad" ),
324  _( "Open the \"Getting Started in KiCad\" guide for beginners" ),
325  KiBitmap( help_xpm ) );
326 
327  text = AddHotkeyName( _( "&List Hotkeys..." ), g_Eeschema_Hokeys_Descr, HK_HELP );
328  AddMenuItem( helpMenu,
330  text,
331  _( "Displays the current hotkeys list and corresponding commands" ),
332  KiBitmap( hotkeys_xpm ) );
333 
334  helpMenu->AppendSeparator();
336  _( "Get &Involved" ),
337  _( "Contribute to KiCad (opens a web browser)" ),
338  KiBitmap( info_xpm ) );
339 
340  // About Eeschema
341  helpMenu->AppendSeparator();
342 
343  AddMenuItem( helpMenu,
344  wxID_ABOUT,
345  _( "&About KiCad" ),
346  _( "About KiCad" ),
347  KiBitmap( about_xpm ) );
348 
349  // Create the menubar and append all submenus
350  menuBar->Append( fileMenu, _( "&File" ) );
351  menuBar->Append( editMenu, _( "&Edit" ) );
352  menuBar->Append( viewMenu, _( "&View" ) );
353  menuBar->Append( partMenu, _( "&Symbol" ) );
354  menuBar->Append( placeMenu, _( "&Place" ) );
355  menuBar->Append( preferencesMenu, _( "P&references" ) );
356  menuBar->Append( helpMenu, _( "&Help" ) );
357 
358  menuBar->Thaw();
359 
360  // Associate the menu bar with the frame, if no previous menubar
361  if( GetMenuBar() == NULL )
362  SetMenuBar( menuBar );
363  else
364  menuBar->Refresh();
365 }
#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:174
#define HELP_ZOOM_FIT
Definition: id.h:241
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:78
void ReCreateMenuBar() override
(Re)Create the menubar for the part editor frame
strings common to toolbars and menubar
struct EDA_HOTKEY_CONFIG g_Eeschema_Hokeys_Descr[]
#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
Definition of class LIB_EDIT_FRAME.
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[]