KiCad PCB EDA Suite
tool_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-2018 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 
29 #include <dialog_helpers.h>
30 #include <macros.h>
31 #include <menus_helpers.h>
32 
33 #include "help_common_strings.h"
34 #include "hotkeys.h"
35 #include "footprint_viewer_frame.h"
36 #include "pcbnew.h"
37 #include "pcbnew_id.h"
38 
39 
41 {
42  // Note:
43  // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
44  // all wxAuiToolBarItems.
45  // However the wxAuiToolBarItems are not the owners of controls managed by
46  // them ( m_zoomSelectBox and m_gridSelectBox ), and therefore do not delete them
47  // So we do not recreate them after clearing the tools.
48 
49  wxString msg;
50 
51  if( m_mainToolBar )
52  m_mainToolBar->Clear();
53  else
54  m_mainToolBar = new wxAuiToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
55  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
56 
57  // Set up toolbar
58  m_mainToolBar->AddTool( ID_MODVIEW_SELECT_PART, wxEmptyString,
59  KiScaledBitmap( load_module_lib_xpm, this ),
60  _( "Select footprint to browse" ) );
61 
63 
64  m_mainToolBar->AddTool( ID_MODVIEW_OPTIONS, wxEmptyString,
65  KiScaledBitmap( config_xpm, this ),
66  _( "Display options" ) );
67 
68  m_mainToolBar->AddSeparator();
69 
70  m_mainToolBar->AddTool( ID_MODVIEW_PREVIOUS, wxEmptyString,
71  KiScaledBitmap( lib_previous_xpm, this ),
72  _( "Display previous footprint" ) );
73 
74  m_mainToolBar->AddTool( ID_MODVIEW_NEXT, wxEmptyString,
75  KiScaledBitmap( lib_next_xpm, this ),
76  _( "Display next footprint" ) );
77 
79 
80  msg = AddHotkeyName( _( "Redraw view" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_REDRAW );
81  m_mainToolBar->AddTool( ID_VIEWER_ZOOM_REDRAW, wxEmptyString,
82  KiScaledBitmap( zoom_redraw_xpm, this ), msg );
83 
85  m_mainToolBar->AddTool( ID_VIEWER_ZOOM_IN, wxEmptyString,
86  KiScaledBitmap( zoom_in_xpm, this ), msg );
87 
89  m_mainToolBar->AddTool( ID_VIEWER_ZOOM_OUT, wxEmptyString,
90  KiScaledBitmap( zoom_out_xpm, this ), msg );
91 
92  msg = AddHotkeyName( _( "Zoom to fit" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_AUTO );
93  m_mainToolBar->AddTool( ID_VIEWER_ZOOM_PAGE, wxEmptyString,
94  KiScaledBitmap( zoom_fit_in_page_xpm, this ), msg );
95 
97 
98  m_mainToolBar->AddTool( ID_MODVIEW_SHOW_3D_VIEW, wxEmptyString,
99  KiScaledBitmap( three_d_xpm, this ),
100  _( "Show footprint in 3D viewer" ) );
101 
102  if( IsModal() )
103  {
104  m_mainToolBar->AddTool( ID_MODVIEW_EXPORT_TO_BOARD, wxEmptyString,
105  KiScaledBitmap( export_footprint_names_xpm, this ),
106  _( "Insert footprint in board" ) );
107  }
108 
110 
111  // Grid selection choice box.
112  if( m_gridSelectBox == nullptr )
114  wxDefaultPosition, wxDefaultSize, 0, NULL );
115 
117  m_mainToolBar->AddControl( m_gridSelectBox );
118 
120 
121  // Zoom selection choice box.
122  if( m_zoomSelectBox == nullptr )
124  wxDefaultPosition, wxDefaultSize, 0, NULL );
125 
127  m_mainToolBar->AddControl( m_zoomSelectBox );
128 
129  // after adding the buttons to the toolbar, must call Realize() to
130  // reflect the changes
131  m_mainToolBar->Realize();
132  m_mainToolBar->Refresh();
133 }
134 
135 
137 {
138 }
139 
140 
141 // Virtual function
143 {
144  // wxWidgets handles the Mac Application menu behind the scenes, but that means
145  // we always have to start from scratch with a new wxMenuBar.
146  wxMenuBar* oldMenuBar = GetMenuBar();
147  wxMenuBar* menuBar = new wxMenuBar();
148  wxString text;
149 
150  // Recreate all menus:
151 
152  // Menu File:
153  wxMenu* fileMenu = new wxMenu;
154 
155  // Close viewer
156  AddMenuItem( fileMenu, wxID_EXIT,
157  _( "Cl&ose" ),
158  _( "Close footprint viewer" ),
159  KiBitmap( exit_xpm ) );
160 
161  // View menu
162  wxMenu* viewMenu = new wxMenu;
163 
164  text = AddHotkeyName( _( "Zoom &In" ), g_Module_Viewer_Hotkeys_Descr,
166  AddMenuItem( viewMenu, ID_VIEWER_ZOOM_IN, text, HELP_ZOOM_IN, KiBitmap( zoom_in_xpm ) );
167 
168  text = AddHotkeyName( _( "Zoom &Out" ), g_Module_Viewer_Hotkeys_Descr,
170  AddMenuItem( viewMenu, ID_VIEWER_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) );
171 
172  text = AddHotkeyName( _( "&Fit on Screen" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_AUTO );
173  AddMenuItem( viewMenu, ID_VIEWER_ZOOM_PAGE, text, _( "Zoom to fit footprint" ),
174  KiBitmap( zoom_fit_in_page_xpm ) );
175 
177  AddMenuItem( viewMenu, ID_VIEWER_ZOOM_REDRAW, text,
178  HELP_ZOOM_REDRAW, KiBitmap( zoom_redraw_xpm ) );
179 
180  viewMenu->AppendSeparator();
181 
182  // 3D view
183  text = AddHotkeyName( _( "3&D Viewer" ), g_Module_Viewer_Hotkeys_Descr, HK_3D_VIEWER );
184  AddMenuItem( viewMenu, ID_MODVIEW_SHOW_3D_VIEW, text, _( "Show footprint in 3D viewer" ),
185  KiBitmap( three_d_xpm ) );
186 
187  // Menu Help:
188  wxMenu* helpMenu = new wxMenu;
189 
190  // Contents
191  AddMenuItem( helpMenu, wxID_HELP,
192  _( "Pcbnew &Manual" ),
193  _( "Open the Pcbnew manual" ),
194  KiBitmap( online_help_xpm ) );
195 
196  AddMenuItem( helpMenu, wxID_INDEX,
197  _( "&Getting Started in KiCad" ),
198  _( "Open the \"Getting Started in KiCad\" guide for beginners" ),
199  KiBitmap( help_xpm ) );
200 
201  // About Pcbnew
202  helpMenu->AppendSeparator();
203  AddMenuItem( helpMenu, wxID_ABOUT,
204  _( "&About Pcbnew" ),
205  _( "About Pcbnew PCB designer" ),
206  KiBitmap( info_xpm ) );
207 
208  // Append menus to the menubar
209  menuBar->Append( fileMenu, _( "&File" ) );
210 
211  menuBar->Append( viewMenu, _( "&View" ) );
212  menuBar->Append( helpMenu, _( "&Help" ) );
213 
214  SetMenuBar( menuBar );
215  delete oldMenuBar;
216 }
struct EDA_HOTKEY_CONFIG g_Module_Viewer_Hotkeys_Descr[]
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:223
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:151
#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:152
Helper dialog and control classes.
bool IsModal()
Definition: kiway_player.h:226
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
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
Function ReCreateMenuBar Creates recreates the menu bar.
#define HELP_ZOOM_IN
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
strings common to toolbars and menubar