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-2021 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 
24 #include <macros.h>
25 #include <bitmaps.h>
26 #include <tool/action_toolbar.h>
27 #include <tool/conditional_menu.h>
28 #include <tool/tool_manager.h>
30 #include <tools/pcb_actions.h>
31 #include "footprint_viewer_frame.h"
32 #include "pcbnew_id.h"
33 #include <widgets/wx_menubar.h>
34 #include <wx/choice.h>
35 
36 
38 {
39  // Note:
40  // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
41  // all wxAuiToolBarItems.
42  // However the wxAuiToolBarItems are not the owners of controls managed by
43  // them ( m_zoomSelectBox and m_gridSelectBox ), and therefore do not delete them
44  // So we do not recreate them after clearing the tools.
45 
46  if( m_mainToolBar )
47  {
49  }
50  else
51  {
52  m_mainToolBar = new ACTION_TOOLBAR( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
53  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT |
54  wxAUI_TB_HORIZONTAL );
56  }
57 
58  // Set up toolbar
59  m_mainToolBar->AddTool( ID_MODVIEW_PREVIOUS, wxEmptyString,
61  _( "Display previous footprint" ) );
62  m_mainToolBar->AddTool( ID_MODVIEW_NEXT, wxEmptyString,
64  _( "Display next footprint" ) );
65 
72 
75  m_mainToolBar->AddTool( ID_ADD_FOOTPRINT_TO_BOARD, wxEmptyString,
77  _( "Insert footprint in board" ) );
78 
80 
81  // Grid selection choice box.
82  if( m_gridSelectBox == nullptr )
83  {
84  m_gridSelectBox = new wxChoice( m_mainToolBar, ID_ON_GRID_SELECT, wxDefaultPosition,
85  wxDefaultSize, 0, nullptr );
86  }
87 
89  m_mainToolBar->AddControl( m_gridSelectBox );
90 
92 
93  // Zoom selection choice box.
94  if( m_zoomSelectBox == nullptr )
95  {
96  m_zoomSelectBox = new wxChoice( m_mainToolBar, ID_ON_ZOOM_SELECT, wxDefaultPosition,
97  wxDefaultSize, 0, nullptr );
98  }
99 
101  m_mainToolBar->AddControl( m_zoomSelectBox );
102 
103  // after adding the buttons to the toolbar, must call Realize() to
104  // reflect the changes
106 }
107 
108 
110 {
111  if( m_optionsToolBar )
112  {
114  }
115  else
116  {
117  m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition,
118  wxDefaultSize,
119  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
121  }
122 
125 
133 
139 
141 }
142 
143 
145 {
146  // This toolbar is not currently used
147 }
148 
149 
151 {
153 
154  // wxWidgets handles the Mac Application menu behind the scenes, but that means
155  // we always have to start from scratch with a new wxMenuBar.
156  wxMenuBar* oldMenuBar = GetMenuBar();
157  WX_MENUBAR* menuBar = new WX_MENUBAR();
158 
159 
160  //----- File menu -----------------------------------------------------------
161  //
162  ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
163 
164  fileMenu->AddClose( _( "Footprint Viewer" ) );
165 
166  //----- View menu -----------------------------------------------------------
167  //
168  ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
169 
170  viewMenu->AppendSeparator();
171  viewMenu->Add( ACTIONS::zoomInCenter );
172  viewMenu->Add( ACTIONS::zoomOutCenter );
173  viewMenu->Add( ACTIONS::zoomFitScreen );
174  viewMenu->Add( ACTIONS::zoomRedraw );
175 
176  viewMenu->AppendSeparator();
177  viewMenu->Add( ACTIONS::show3DViewer );
178 
179  //----- Menubar -------------------------------------------------------------
180  //
181  menuBar->Append( fileMenu, _( "&File" ) );
182  menuBar->Append( viewMenu, _( "&View" ) );
183  AddStandardHelpMenu( menuBar );
184 
185  SetMenuBar( menuBar );
186  delete oldMenuBar;
187 }
static TOOL_ACTION show3DViewer
Definition: actions.h:158
Define the structure of a toolbar with buttons that invoke ACTIONs.
static TOOL_ACTION zoomInCenter
Definition: actions.h:93
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
ACTION_TOOLBAR * m_optionsToolBar
static constexpr bool TOGGLE
static TOOL_ACTION zoomTool
Definition: actions.h:99
void AddScaledSeparator(wxWindow *aWindow)
Add a separator that introduces space on either side to not squash the tools when scaled.
void Add(const TOOL_ACTION &aAction, bool aIsToggleEntry=false, bool aIsCancellable=false)
Add a TOOL_ACTION-based button to the toolbar.
static TOOL_ACTION zoomFitScreen
Definition: actions.h:96
static TOOL_ACTION millimetersUnits
Definition: actions.h:146
void SetAuiManager(wxAuiManager *aManager)
Set the AUI manager that this toolbar belongs to.
void UpdateZoomSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
wxAuiManager m_auimgr
ACTION_TOOLBAR * m_mainToolBar
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition: wx_menubar.h:45
wxChoice * m_gridSelectBox
bool KiRealize()
Use this over Realize() to avoid a rendering glitch with fixed orientation toolbars.
static TOOL_ACTION zoomOutCenter
Definition: actions.h:94
This file contains miscellaneous commonly used macros and functions.
void UpdateGridSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
static TOOL_ACTION measureTool
Definition: actions.h:154
static constexpr bool CANCEL
static TOOL_ACTION toggleGrid
Definition: actions.h:140
static TOOL_ACTION showPadNumbers
Definition: pcb_actions.h:248
static TOOL_ACTION inchesUnits
Definition: actions.h:144
wxChoice * m_zoomSelectBox
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
static TOOL_ACTION togglePolarCoords
Definition: actions.h:149
#define _(s)
static TOOL_ACTION milsUnits
Definition: actions.h:145
wxBitmap KiScaledBitmap(BITMAPS aBitmap, wxWindow *aWindow, int aHeight, bool aQuantized)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:148
static TOOL_ACTION padDisplayMode
Definition: pcb_actions.h:241
static TOOL_ACTION graphicsOutlines
Display footprint graphics as outlines.
Definition: pcb_actions.h:391
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:158
void ReCreateMenuBar() override
Recreates the menu bar.
static TOOL_ACTION zoomRedraw
Definition: actions.h:90
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
The selection tool: currently supports:
static constexpr int KICAD_AUI_TB_STYLE
< Default style flags used for wxAUI toolbars.
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:102
static TOOL_ACTION selectionTool
Definition: actions.h:153
static TOOL_ACTION textOutlines
Display texts as lines.
Definition: pcb_actions.h:394
void ClearToolbar()
Clear the toolbar and remove all associated menus.
void AddClose(const wxString &aAppname="")
Add a standard close item to the menu with the accelerator key CTRL-W.