KiCad PCB EDA Suite
toolbars_footprint_editor.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) 2015 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@verizon.net>
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 <fctsys.h>
24 #include <tool/actions.h>
25 #include <pcbnew.h>
26 #include <class_board.h>
27 #include <footprint_edit_frame.h>
28 #include <dialog_helpers.h>
29 #include <pcbnew_id.h>
30 #include <bitmaps.h>
31 #include <tool/action_toolbar.h>
32 #include <tools/pcb_actions.h>
33 #include <pcb_layer_box_selector.h>
34 
36 {
37  // Note:
38  // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
39  // all wxAuiToolBarItems.
40  // However the wxAuiToolBarItems are not the owners of controls managed by
41  // them ( m_zoomSelectBox and m_gridSelectBox ), and therefore do not delete them
42  // So we do not recreate them after clearing the tools.
43 
44  if( m_mainToolBar )
45  m_mainToolBar->Clear();
46  else
47  m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
48  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
49 
50  wxString msg;
51 
52  // Set up toolbar
54 #ifdef KICAD_SCRIPTING
56 #endif
57 
58  if( IsCurrentFPFromBoard() )
60  else
62 
65 
69 
70  m_mainToolBar->AddSeparator();
76 
80 
82  m_mainToolBar->AddTool( ID_MODEDIT_LOAD_MODULE_FROM_BOARD, wxEmptyString,
83  KiScaledBitmap( load_module_board_xpm, this ),
84  _( "Load footprint from current board" ) );
85 
86  m_mainToolBar->AddTool( ID_ADD_FOOTPRINT_TO_BOARD, wxEmptyString,
87  KiScaledBitmap( export_xpm, this ),
88  _( "Insert footprint into current board" ) );
89 
90 #if 0 // Currently there is no check footprint function defined, so do not show this tool
92  m_mainToolBar->AddTool( ID_MODEDIT_CHECK, wxEmptyString,
93  KiScaledBitmap( module_check_xpm, this ),
94  _( "Check footprint" ) );
95 #endif
96 
98 
99  // Grid selection choice box.
100  if( m_gridSelectBox == nullptr )
102  wxDefaultPosition, wxDefaultSize, 0, NULL );
103 
105  m_mainToolBar->AddControl( m_gridSelectBox );
106 
108 
109  // Zoom selection choice box.
110  if( m_zoomSelectBox == nullptr )
112  wxDefaultPosition, wxDefaultSize, 0, NULL );
113 
115  m_mainToolBar->AddControl( m_zoomSelectBox );
116 
118 
119  // Layer selection choice box.
120  if( m_selLayerBox == nullptr )
121  {
123  m_selLayerBox->SetBoardFrame( this );
124 
125  // Some layers cannot be seclect (they are shown in the layer manager
126  // only to set the color and visibility, but not for selection)
127  // Disable them in layer box
130  }
131 
132  ReCreateLayerBox( false );
133  m_mainToolBar->AddControl( m_selLayerBox );
134 
135  // after adding the buttons to the toolbar, must call Realize() to reflect the changes
136  m_mainToolBar->Realize();
137 }
138 
139 
141 {
142  if( m_drawToolBar )
143  m_drawToolBar->Clear();
144  else
145  m_drawToolBar = new ACTION_TOOLBAR( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize,
146  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
147 
149 
159 
164 
165  m_drawToolBar->Realize();
166 }
167 
168 
170 {
171  if( m_optionsToolBar )
172  m_optionsToolBar->Clear();
173  else
174  m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
175  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
176 
182 
183  m_optionsToolBar->AddSeparator();
187 
188  m_optionsToolBar->AddSeparator();
190 
191  m_optionsToolBar->Realize();
192 }
193 
194 
195 void FOOTPRINT_EDIT_FRAME::ReCreateLayerBox( bool aForceResizeToolbar )
196 {
197  if( m_selLayerBox == NULL || m_mainToolBar == NULL )
198  return;
199 
200  m_selLayerBox->SetToolTip( _( "+/- to switch" ) );
202 
203  if( aForceResizeToolbar )
204  {
205  // the layer box can have its size changed
206  // Update the aui manager, to take in account the new size
207  m_auimgr.Update();
208  }
209 }
210 
211 
212 void FOOTPRINT_EDIT_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent )
213 {
215 }
216 
217 
219 {
220 #define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, IsCurrentTool( tool ) )
221 
222  auto& opts = GetDisplayOptions();
223 
224  if( IsCurrentFPFromBoard() )
226  else
228 
229  m_mainToolBar->Toggle( ACTIONS::undo, GetScreen() && GetScreen()->GetUndoCommandCount() > 0 );
230  m_mainToolBar->Toggle( ACTIONS::redo, GetScreen() && GetScreen()->GetRedoCommandCount() > 0 );
233  m_mainToolBar->Refresh();
234 
239  m_optionsToolBar->Toggle( PCB_ACTIONS::padDisplayMode, !opts.m_DisplayPadFill );
240  m_optionsToolBar->Toggle( PCB_ACTIONS::moduleEdgeOutlines, !opts.m_DisplayModEdgeFill );
241  m_optionsToolBar->Toggle( ACTIONS::highContrastMode, opts.m_ContrastModeDisplay );
243  m_optionsToolBar->Refresh();
244 
257  m_drawToolBar->Refresh();
258 }
static TOOL_ACTION drawLine
Definition: pcb_actions.h:153
static TOOL_ACTION saveToBoard
Definition: pcb_actions.h:347
Class ACTION_TOOLBAR.
static TOOL_ACTION footprintProperties
Definition: pcb_actions.h:358
void ReCreateHToolbar() override
Create the main horizontal toolbar for the footprint editor.
static TOOL_ACTION zoomInCenter
Definition: actions.h:90
void SyncToolbars() override
Update the toolbars (mostly settings/check buttons/checkboxes) with the current controller state.
static LSET ForbiddenFootprintLayers()
Function ForbiddenFootprintLayers Layers which are not allowed within footprint definitions.
Definition: lset.cpp:789
static TOOL_ACTION drawArc
Definition: pcb_actions.h:156
ACTION_TOOLBAR * m_optionsToolBar
void SetNotAllowedLayerSet(LSET aMask)
static const bool TOGGLE
static TOOL_ACTION zoomTool
Definition: actions.h:95
static TOOL_ACTION drawZoneKeepout
Definition: pcb_actions.h:161
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:93
static TOOL_ACTION drawPolygon
Definition: pcb_actions.h:154
static TOOL_ACTION placePad
Activation of the drawing tool (placing a PAD)
Definition: pcb_actions.h:362
Class to display a pcb layer list in a wxBitmapComboBox.
wxAuiManager m_auimgr
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
ACTION_TOOLBAR * m_mainToolBar
static TOOL_ACTION print
Definition: actions.h:60
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
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Function GetDisplayOptions returns the display options current in use Display options are relative to...
static TOOL_ACTION setAnchor
Definition: pcb_actions.h:167
static TOOL_ACTION imperialUnits
Definition: actions.h:136
wxChoice * m_gridSelectBox
static TOOL_ACTION placeText
Definition: pcb_actions.h:157
static TOOL_ACTION zoomOutCenter
Definition: actions.h:91
static TOOL_ACTION createFootprint
Definition: pcb_actions.h:343
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
static TOOL_ACTION measureTool
Definition: actions.h:144
static TOOL_ACTION toggleFootprintTree
Definition: pcb_actions.h:336
bool IsGridVisible() const override
static TOOL_ACTION toggleGrid
Definition: actions.h:132
Definition: common.h:134
wxChoice * m_zoomSelectBox
static TOOL_ACTION togglePolarCoords
Definition: actions.h:139
Helper dialog and control classes.
#define TOGGLE_TOOL(toolbar, tool)
int SetLayerSelection(LAYER_NUM layer)
#define _(s)
PCB_LAYER_BOX_SELECTOR * m_selLayerBox
static TOOL_ACTION moduleEdgeOutlines
Display module edges as outlines.
Definition: pcb_actions.h:374
void UpdateGridSelectBox()
static TOOL_ACTION padDisplayMode
Definition: pcb_actions.h:233
static TOOL_ACTION drawCircle
Definition: pcb_actions.h:155
static TOOL_ACTION saveToLibrary
Definition: pcb_actions.h:348
static TOOL_ACTION metricUnits
Definition: actions.h:137
static TOOL_ACTION redo
Definition: actions.h:68
static TOOL_ACTION defaultPadProperties
Definition: pcb_actions.h:359
bool GetShowPolarCoords() const
For those frames that support polar coordinates.
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
static TOOL_ACTION zoomRedraw
Definition: actions.h:87
void Toggle(const TOOL_ACTION &aAction, bool aState)
Applies the default toggle action.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
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
static TOOL_ACTION deleteTool
Definition: actions.h:75
static TOOL_ACTION undo
Definition: actions.h:67
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:98
BOARD * GetBoard() const
static TOOL_ACTION gridSetOrigin
Definition: actions.h:129
void updateZoomSelectBox()
static TOOL_ACTION highContrastMode
Definition: actions.h:99
void OnUpdateLayerSelectBox(wxUpdateUIEvent &aEvent)
static TOOL_ACTION selectionTool
Definition: actions.h:143
static TOOL_ACTION newFootprint
Definition: pcb_actions.h:340
void ReCreateLayerBox(bool aForceResizeToolbar=true)
Re create the layer Box by clearing the old list, and building le new one, from the new layers names ...
ACTION_TOOLBAR * m_drawToolBar