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  wxString msg;
43 
44  if( m_mainToolBar )
45  m_mainToolBar->Clear();
46  else
47  m_mainToolBar = new wxAuiToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
48  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
49 
50  // Set up toolbar
51  m_mainToolBar->AddTool( ID_MODVIEW_SELECT_PART, wxEmptyString,
52  KiScaledBitmap( load_module_lib_xpm, this ),
53  _( "Select footprint to browse" ) );
54 
56 
57  m_mainToolBar->AddTool( ID_MODVIEW_OPTIONS, wxEmptyString,
58  KiScaledBitmap( config_xpm, this ),
59  _( "Display options" ) );
60 
61  m_mainToolBar->AddSeparator();
62 
63  m_mainToolBar->AddTool( ID_MODVIEW_PREVIOUS, wxEmptyString,
64  KiScaledBitmap( lib_previous_xpm, this ),
65  _( "Display previous footprint" ) );
66 
67  m_mainToolBar->AddTool( ID_MODVIEW_NEXT, wxEmptyString,
68  KiScaledBitmap( lib_next_xpm, this ),
69  _( "Display next footprint" ) );
70 
72 
73  msg = AddHotkeyName( _( "Redraw view" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_REDRAW );
74  m_mainToolBar->AddTool( ID_VIEWER_ZOOM_REDRAW, wxEmptyString,
75  KiScaledBitmap( zoom_redraw_xpm, this ), msg );
76 
78  m_mainToolBar->AddTool( ID_VIEWER_ZOOM_IN, wxEmptyString,
79  KiScaledBitmap( zoom_in_xpm, this ), msg );
80 
82  m_mainToolBar->AddTool( ID_VIEWER_ZOOM_OUT, wxEmptyString,
83  KiScaledBitmap( zoom_out_xpm, this ), msg );
84 
85  msg = AddHotkeyName( _( "Zoom to fit" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_AUTO );
86  m_mainToolBar->AddTool( ID_VIEWER_ZOOM_PAGE, wxEmptyString,
87  KiScaledBitmap( zoom_fit_in_page_xpm, this ), msg );
88 
90 
91  m_mainToolBar->AddTool( ID_MODVIEW_SHOW_3D_VIEW, wxEmptyString,
92  KiScaledBitmap( three_d_xpm, this ),
93  _( "Show footprint in 3D viewer" ) );
94 
95  if( IsModal() )
96  {
97  m_mainToolBar->AddTool( ID_MODVIEW_EXPORT_TO_BOARD, wxEmptyString,
98  KiScaledBitmap( export_footprint_names_xpm, this ),
99  _( "Insert footprint in board" ) );
100  }
101 
103 
104  // Grid selection choice box.
106  wxDefaultPosition, wxDefaultSize, 0, NULL );
108  m_mainToolBar->AddControl( m_gridSelectBox );
109 
111 
112  // Zoom selection choice box.
114  wxDefaultPosition, wxDefaultSize, 0, NULL );
116  m_mainToolBar->AddControl( m_zoomSelectBox );
117 
118  // after adding the buttons to the toolbar, must call Realize() to
119  // reflect the changes
120  m_mainToolBar->Realize();
121  m_mainToolBar->Refresh();
122 }
123 
124 
126 {
127 }
128 
129 
130 // Virtual function
132 {
133  // wxWidgets handles the Mac Application menu behind the scenes, but that means
134  // we always have to start from scratch with a new wxMenuBar.
135  wxMenuBar* oldMenuBar = GetMenuBar();
136  wxMenuBar* menuBar = new wxMenuBar();
137  wxString text;
138 
139  // Recreate all menus:
140 
141  // Menu File:
142  wxMenu* fileMenu = new wxMenu;
143 
144  // Close viewer
145  AddMenuItem( fileMenu, wxID_EXIT,
146  _( "Cl&ose" ),
147  _( "Close footprint viewer" ),
148  KiBitmap( exit_xpm ) );
149 
150  // View menu
151  wxMenu* viewMenu = new wxMenu;
152 
153  text = AddHotkeyName( _( "Zoom &In" ), g_Module_Viewer_Hotkeys_Descr,
155  AddMenuItem( viewMenu, ID_VIEWER_ZOOM_IN, text, HELP_ZOOM_IN, KiBitmap( zoom_in_xpm ) );
156 
157  text = AddHotkeyName( _( "Zoom &Out" ), g_Module_Viewer_Hotkeys_Descr,
159  AddMenuItem( viewMenu, ID_VIEWER_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) );
160 
161  text = AddHotkeyName( _( "&Fit on Screen" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_AUTO );
162  AddMenuItem( viewMenu, ID_VIEWER_ZOOM_PAGE, text, _( "Zoom to fit footprint" ),
163  KiBitmap( zoom_fit_in_page_xpm ) );
164 
166  AddMenuItem( viewMenu, ID_VIEWER_ZOOM_REDRAW, text,
167  HELP_ZOOM_REDRAW, KiBitmap( zoom_redraw_xpm ) );
168 
169  viewMenu->AppendSeparator();
170 
171  // 3D view
172  text = AddHotkeyName( _( "3&D Viewer" ), g_Module_Viewer_Hotkeys_Descr, HK_3D_VIEWER );
173  AddMenuItem( viewMenu, ID_MODVIEW_SHOW_3D_VIEW, text, _( "Show footprint in 3D viewer" ),
174  KiBitmap( three_d_xpm ) );
175 
176  // Menu Help:
177  wxMenu* helpMenu = new wxMenu;
178 
179  // Contents
180  AddMenuItem( helpMenu, wxID_HELP,
181  _( "Pcbnew &Manual" ),
182  _( "Open the Pcbnew manual" ),
183  KiBitmap( online_help_xpm ) );
184 
185  AddMenuItem( helpMenu, wxID_INDEX,
186  _( "&Getting Started in KiCad" ),
187  _( "Open the \"Getting Started in KiCad\" guide for beginners" ),
188  KiBitmap( help_xpm ) );
189 
190  // About Pcbnew
191  helpMenu->AppendSeparator();
192  AddMenuItem( helpMenu, wxID_ABOUT,
193  _( "&About Pcbnew" ),
194  _( "About Pcbnew PCB designer" ),
195  KiBitmap( info_xpm ) );
196 
197  // Append menus to the menubar
198  menuBar->Append( fileMenu, _( "&File" ) );
199 
200  menuBar->Append( viewMenu, _( "&View" ) );
201  menuBar->Append( helpMenu, _( "&Help" ) );
202 
203  SetMenuBar( menuBar );
204  delete oldMenuBar;
205 }
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:148
#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:149
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