KiCad PCB EDA Suite
toolbars_footprint_viewer.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) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2012 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 modify it
10  * under the terms of the GNU General Public License as published by the
11  * Free Software Foundation, either version 3 of the License, or (at your
12  * option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include <dialog_helpers.h>
24 #include <macros.h>
25 #include <menus_helpers.h>
26 #include <tool/actions.h>
27 #include "help_common_strings.h"
28 #include "hotkeys.h"
29 #include "footprint_viewer_frame.h"
30 #include "pcbnew.h"
31 #include "pcbnew_id.h"
32 
33 
35 {
36  // Note:
37  // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
38  // all wxAuiToolBarItems.
39  // However the wxAuiToolBarItems are not the owners of controls managed by
40  // them ( m_zoomSelectBox and m_gridSelectBox ), and therefore do not delete them
41  // So we do not recreate them after clearing the tools.
42 
43  wxString msg;
44 
45  if( m_mainToolBar )
46  m_mainToolBar->Clear();
47  else
48  m_mainToolBar = new ACTION_TOOLBAR( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
49  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
50 
51  // Set up toolbar
52  m_mainToolBar->AddTool( ID_MODVIEW_SELECT_PART, wxEmptyString,
53  KiScaledBitmap( load_module_lib_xpm, this ),
54  _( "Select footprint to browse" ) );
55 
57  m_mainToolBar->AddTool( ID_MODVIEW_OPTIONS, wxEmptyString,
58  KiScaledBitmap( config_xpm, this ),
59  _( "Display options" ) );
60 
61  m_mainToolBar->AddSeparator();
62  m_mainToolBar->AddTool( ID_MODVIEW_PREVIOUS, wxEmptyString,
63  KiScaledBitmap( lib_previous_xpm, this ),
64  _( "Display previous footprint" ) );
65  m_mainToolBar->AddTool( ID_MODVIEW_NEXT, wxEmptyString,
66  KiScaledBitmap( lib_next_xpm, this ),
67  _( "Display next footprint" ) );
68 
69  m_mainToolBar->AddSeparator();
74 
76  m_mainToolBar->AddTool( ID_MODVIEW_SHOW_3D_VIEW, wxEmptyString,
77  KiScaledBitmap( three_d_xpm, this ),
78  _( "Show footprint in 3D viewer" ) );
79  m_mainToolBar->AddTool( ID_ADD_FOOTPRINT_TO_BOARD, wxEmptyString,
80  KiScaledBitmap( export_xpm, this ),
81  _( "Insert footprint in board" ) );
82 
84 
85  // Grid selection choice box.
86  if( m_gridSelectBox == nullptr )
88  wxDefaultPosition, wxDefaultSize, 0, NULL );
89 
91  m_mainToolBar->AddControl( m_gridSelectBox );
92 
94 
95  // Zoom selection choice box.
96  if( m_zoomSelectBox == nullptr )
98  wxDefaultPosition, wxDefaultSize, 0, NULL );
99 
101  m_mainToolBar->AddControl( m_zoomSelectBox );
102 
103  // after adding the buttons to the toolbar, must call Realize() to
104  // reflect the changes
105  m_mainToolBar->Realize();
106  m_mainToolBar->Refresh();
107 }
108 
109 
111 {
112 }
113 
114 
115 // Virtual function
117 {
118  // wxWidgets handles the Mac Application menu behind the scenes, but that means
119  // we always have to start from scratch with a new wxMenuBar.
120  wxMenuBar* oldMenuBar = GetMenuBar();
121  wxMenuBar* menuBar = new wxMenuBar();
122  wxString text;
123 
124  // Recreate all menus:
125 
126  // Menu File:
127  wxMenu* fileMenu = new wxMenu;
128 
129  // Close viewer
130  AddMenuItem( fileMenu, wxID_EXIT,
131  _( "Cl&ose" ),
132  _( "Close footprint viewer" ),
133  KiBitmap( exit_xpm ) );
134 
135  // View menu
136  wxMenu* viewMenu = new wxMenu;
137 
138  text = AddHotkeyName( _( "Zoom &In" ), g_Module_Viewer_Hotkeys_Descr,
140  AddMenuItem( viewMenu, ID_VIEWER_ZOOM_IN, text, HELP_ZOOM_IN, KiBitmap( zoom_in_xpm ) );
141 
142  text = AddHotkeyName( _( "Zoom &Out" ), g_Module_Viewer_Hotkeys_Descr,
144  AddMenuItem( viewMenu, ID_VIEWER_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) );
145 
146  text = AddHotkeyName( _( "&Fit on Screen" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_AUTO );
147  AddMenuItem( viewMenu, ID_VIEWER_ZOOM_PAGE, text, _( "Zoom to fit footprint" ),
148  KiBitmap( zoom_fit_in_page_xpm ) );
149 
151  AddMenuItem( viewMenu, ID_VIEWER_ZOOM_REDRAW, text,
152  HELP_ZOOM_REDRAW, KiBitmap( zoom_redraw_xpm ) );
153 
154  viewMenu->AppendSeparator();
155 
156  // 3D view
157  text = AddHotkeyName( _( "3&D Viewer" ), g_Module_Viewer_Hotkeys_Descr, HK_3D_VIEWER );
158  AddMenuItem( viewMenu, ID_MODVIEW_SHOW_3D_VIEW, text, _( "Show footprint in 3D viewer" ),
159  KiBitmap( three_d_xpm ) );
160 
161  // Menu Help:
162  wxMenu* helpMenu = new wxMenu;
163 
164  // Contents
165  AddMenuItem( helpMenu, wxID_HELP,
166  _( "Pcbnew &Manual" ),
167  _( "Open the Pcbnew manual" ),
168  KiBitmap( online_help_xpm ) );
169 
170  AddMenuItem( helpMenu, wxID_INDEX,
171  _( "&Getting Started in KiCad" ),
172  _( "Open the \"Getting Started in KiCad\" guide for beginners" ),
173  KiBitmap( help_xpm ) );
174 
175  // About Pcbnew
176  helpMenu->AppendSeparator();
177  AddMenuItem( helpMenu, wxID_ABOUT,
178  _( "&About Pcbnew" ),
179  _( "About Pcbnew PCB designer" ),
180  KiBitmap( info_xpm ) );
181 
182  // Append menus to the menubar
183  menuBar->Append( fileMenu, _( "&File" ) );
184 
185  menuBar->Append( viewMenu, _( "&View" ) );
186  menuBar->Append( helpMenu, _( "&Help" ) );
187 
188  SetMenuBar( menuBar );
189  delete oldMenuBar;
190 }
struct EDA_HOTKEY_CONFIG g_Module_Viewer_Hotkeys_Descr[]
Class ACTION_TOOLBAR.
static TOOL_ACTION zoomInCenter
Definition: actions.h:60
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
void Add(const TOOL_ACTION &aAction, bool aIsToggleEntry=false)
Function Add() Adds a TOOL_ACTION-based button to the toolbar.
static TOOL_ACTION zoomFitScreen
Definition: actions.h:63
ACTION_TOOLBAR * m_mainToolBar
Definition: draw_frame.h:156
wxBitmap KiScaledBitmap(BITMAP_DEF aBitmap, EDA_BASE_FRAME *aWindow)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:116
wxChoice * m_gridSelectBox
Definition: draw_frame.h:153
static TOOL_ACTION zoomOutCenter
Definition: actions.h:61
#define HELP_ZOOM_OUT
Pcbnew hotkeys.
This file contains miscellaneous commonly used macros and functions.
#define HELP_ZOOM_REDRAW
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
wxChoice * m_zoomSelectBox
Definition: draw_frame.h:154
Helper dialog and control classes.
void UpdateGridSelectBox()
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)
void ReCreateMenuBar() override
Recreates the menu bar.
#define HELP_ZOOM_IN
static TOOL_ACTION zoomRedraw
Definition: actions.h:57
void KiScaledSeparator(wxAuiToolBar *aToolbar, EDA_BASE_FRAME *aWindow)
Add a separator to the given toolbar scaled the same way as KiScaledBitmap.
Definition: bitmap.cpp:167
static constexpr int KICAD_AUI_TB_STYLE
Default style flags used for wxAUI toolbars
void updateZoomSelectBox()
strings common to toolbars and menubar