KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_base_edit_frame.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 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <kiface_base.h>
27#include <kiplatform/ui.h>
28#include <pcb_base_edit_frame.h>
30#include <tool/tool_manager.h>
31#include <tools/pcb_actions.h>
33#include <pgm_base.h>
34#include <board.h>
37#include <pcb_dimension.h>
39#include <footprint.h>
40#include <footprint_info_impl.h>
41#include <layer_pairs.h>
42#include <project.h>
50
51
53 FRAME_T aFrameType, const wxString& aTitle,
54 const wxPoint& aPos, const wxSize& aSize, long aStyle,
55 const wxString& aFrameName ) :
56 PCB_BASE_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ),
57 m_undoRedoBlocked( false ),
58 m_selectionFilterPanel( nullptr ),
59 m_appearancePanel( nullptr ),
60 m_tabbedPanel( nullptr )
61{
62 m_SelLayerBox = nullptr;
64
65 Bind( wxEVT_IDLE,
66 [this]( wxIdleEvent& aEvent )
67 {
68 // Handle cursor adjustments. While we can get motion and key events through
69 // wxWidgets, we can't get modifier-key-up events.
70 if( m_toolManager )
71 {
73
74 if( selTool )
75 selTool->OnIdle( aEvent );
76 }
77
79 {
82 }
83 } );
84}
85
86
88{
89 GetCanvas()->GetView()->Clear();
90}
91
92
94{
96 wxFileName projectName( Prj().GetProjectFullName() );
97
98 if( mgr->IsProjectOpen() && wxFileName::IsDirWritable( projectName.GetPath() )
99 && projectName.Exists() )
100 {
101 GFootprintList.WriteCacheToFile( Prj().GetProjectPath() + wxT( "fp-info-cache" ) );
102 }
103
104 // Close the project if we are standalone, so it gets cleaned up properly
105 if( mgr->IsProjectOpen() && Kiface().IsSingle() )
106 mgr->UnloadProject( &Prj(), false );
107}
108
109
110bool PCB_BASE_EDIT_FRAME::TryBefore( wxEvent& aEvent )
111{
112 static bool s_presetSwitcherShown = false;
113 static bool s_viewportSwitcherShown = false;
114
115 // wxWidgets generates no key events for the tab key when the ctrl key is held down. One
116 // way around this is to look at all events and inspect the keyboard state of the tab key.
117 // However, this runs into issues on some linux VMs where querying the keyboard state is
118 // very slow. Fortunately we only use ctrl-tab on Mac, so we implement this lovely hack:
119#ifdef __WXMAC__
120 if( wxGetKeyState( WXK_TAB ) )
121#else
122 if( ( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
123 && static_cast<wxKeyEvent&>( aEvent ).GetKeyCode() == WXK_TAB )
124#endif
125 {
126 if( !s_presetSwitcherShown && wxGetKeyState( PRESET_SWITCH_KEY ) )
127 {
128 if( m_appearancePanel && this->IsActive() )
129 {
130 const wxArrayString& mru = m_appearancePanel->GetLayerPresetsMRU();
131
132 if( mru.size() > 0 )
133 {
134 EDA_VIEW_SWITCHER switcher( this, mru, PRESET_SWITCH_KEY );
135
136 s_presetSwitcherShown = true;
137 const int switcherDialogRet = switcher.ShowModal();
138 s_presetSwitcherShown = false;
139
140 if( switcherDialogRet == wxID_OK )
141 {
142 int idx = switcher.GetSelection();
143
144 if( idx >= 0 && idx < (int) mru.size() )
146 }
147
148 return true;
149 }
150 }
151 }
152 else if( !s_viewportSwitcherShown && wxGetKeyState( VIEWPORT_SWITCH_KEY ) )
153 {
154 if( m_appearancePanel && this->IsActive() )
155 {
156 const wxArrayString& mru = m_appearancePanel->GetViewportsMRU();
157
158 if( mru.size() > 0 )
159 {
160 EDA_VIEW_SWITCHER switcher( this, mru, VIEWPORT_SWITCH_KEY );
161
162 s_viewportSwitcherShown = true;
163 const int switcherDialogRet = switcher.ShowModal();
164 s_viewportSwitcherShown = false;
165
166 if( switcherDialogRet == wxID_OK )
167 {
168 int idx = switcher.GetSelection();
169
170 if( idx >= 0 && idx < (int) mru.size() )
171 m_appearancePanel->ApplyViewport( mru[idx] );
172 }
173
174 return true;
175 }
176 }
177 }
178 }
179
180 return PCB_BASE_FRAME::TryBefore( aEvent );
181}
182
183
185{
186 // Return a default angle (90 degrees) used for rotate operations.
187 return ANGLE_90;
188}
189
190
192{
194
196}
197
198
200{
201 bool is_new_board = ( aBoard != m_pcb );
202
203 if( is_new_board )
204 {
205 if( m_toolManager )
207
208 GetCanvas()->GetView()->Clear();
210 }
211
212 PCB_BASE_FRAME::SetBoard( aBoard, aReporter );
213
215
216 if( is_new_board )
217 {
219 bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard, &bds );
220 }
221
222 // update the tool manager with the new board and its view.
223 if( m_toolManager )
224 {
225 GetCanvas()->DisplayBoard( aBoard, aReporter );
226
228 m_toolManager->SetEnvironment( aBoard, GetCanvas()->GetView(),
229 GetCanvas()->GetViewControls(), config(), this );
230
231 if( is_new_board )
233 }
234}
235
236
238{
240
241 if( BOARD* board = GetBoard() )
242 {
243 board->UpdateUserUnits( board, GetCanvas()->GetView() );
245 }
246
249}
250
251
253{
255
256 // Update the grid checkbox in the layer widget
259}
260
261
263{
265 m_appearancePanel->SetObjectVisible( aLayer, aVisible );
266}
267
268
270{
271 return Pgm().GetSettingsManager().GetColorSettings( GetPcbNewSettings()->m_ColorTheme );
272}
273
274
276{
277 if( !GetBoard() )
278 return wxEmptyString;
279
280 wxFileName fn = GetBoard()->GetFileName();
282 return Prj().AbsolutePath( fn.GetFullName() );
283}
284
285
286void PCB_BASE_EDIT_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
287{
289
290 // The text in the collapsible pane headers need to be updated
293}
294
295
297{
299
301
302 if( viewer )
303 viewer->OnDarkModeToggle();
304}
305
306
308{
309 if( !m_propertiesPanel )
310 return;
311
312 bool show = !m_propertiesPanel->IsShownOnScreen();
313
314 wxAuiPaneInfo& propertiesPaneInfo = m_auimgr.GetPane( PropertiesPaneName() );
315 propertiesPaneInfo.Show( show );
316
318
319 if( show )
320 {
321 SetAuiPaneSize( m_auimgr, propertiesPaneInfo,
322 settings->m_AuiPanels.properties_panel_width, -1 );
323 }
324 else
325 {
327 m_auimgr.Update();
328 }
329}
330
331
332void PCB_BASE_EDIT_FRAME::GetContextualTextVars( BOARD_ITEM* aSourceItem, const wxString& aCrossRef,
333 wxArrayString* aTokens )
334{
335 BOARD* board = aSourceItem->GetBoard();
336
337 if( !aCrossRef.IsEmpty() )
338 {
339 for( FOOTPRINT* candidate : board->Footprints() )
340 {
341 if( candidate->GetReference() == aCrossRef )
342 {
343 candidate->GetContextualTextVars( aTokens );
344 break;
345 }
346 }
347 }
348 else
349 {
350 board->GetContextualTextVars( aTokens );
351
352 if( FOOTPRINT* footprint = aSourceItem->GetParentFootprint() )
353 footprint->GetContextualTextVars( aTokens );
354 }
355}
356
357
359{
360 // Load the toolbar configuration and base controls
362
363 // Layer selector
364 auto layerSelectorFactory =
365 [this]( ACTION_TOOLBAR* aToolbar )
366 {
367 if( !m_SelLayerBox )
368 {
369 m_SelLayerBox = new PCB_LAYER_BOX_SELECTOR( aToolbar, wxID_ANY );
371 }
372
373 // In the footprint editor, some layers cannot be select (they are shown in the layer
374 // manager only to set the color and visibility, but not for selection)
375 // Disable them in layer box
378
379 m_SelLayerBox->SetToolTip( _( "+/- to switch" ) );
381
382 aToolbar->Add( m_SelLayerBox );
383
384 // UI update handler for the control
385 aToolbar->Bind( wxEVT_UPDATE_UI,
386 [this]( wxUpdateUIEvent& aEvent )
387 {
388 if( m_SelLayerBox->GetCount()
390 {
392 }
393 },
394 m_SelLayerBox->GetId() );
395
396 // Event handler to respond to the user interacting with the control
397 aToolbar->Bind( wxEVT_COMBOBOX,
398 [this]( wxCommandEvent& aEvent )
399 {
401
402 if( GetDisplayOptions().m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL )
403 GetCanvas()->Refresh();
404 },
405 m_SelLayerBox->GetId() );
406 };
407
409}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static ACTION_TOOLBAR_CONTROL layerSelector
Define the structure of a toolbar with buttons that invoke ACTIONs.
void ApplyLayerPreset(const wxString &aPresetName)
const wxArrayString & GetViewportsMRU()
void RefreshCollapsiblePanes()
Function to force a redraw of the collapsible panes in this control.
const wxArrayString & GetLayerPresetsMRU()
Return a list of viewports created by the user.
void OnDarkModeToggle()
Update the widget when the active board layer is changed.
void SetObjectVisible(GAL_LAYER_ID aLayer, bool isVisible=true)
void ApplyViewport(const wxString &aPresetName)
Container for design settings for a BOARD object.
std::shared_ptr< DRC_ENGINE > m_DRCEngine
const VECTOR2I & GetGridOrigin() const
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:47
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:298
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:296
void GetContextualTextVars(wxArrayString *aVars) const
Definition: board.cpp:410
const FOOTPRINTS & Footprints() const
Definition: board.h:337
const wxString & GetFileName() const
Definition: board.h:333
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:948
Color settings are a bit different than most of the settings objects in that there can be more than o...
int ShowModal() override
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
virtual APP_SETTINGS_BASE * config() const
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
SETTINGS_MANAGER * GetSettingsManager() const
void RegisterCustomToolbarControlFactory(const ACTION_TOOLBAR_CONTROL &aControlDesc, const ACTION_TOOLBAR_CONTROL_FACTORY &aControlFactory)
Register a creation factory for toolbar controls that are present in this frame.
virtual void configureToolbars()
wxAuiManager m_auimgr
bool IsType(FRAME_T aType) const
static const wxString PropertiesPaneName()
virtual void ReCreateAuxiliaryToolbar()
virtual void SetGridVisibility(bool aVisible)
PROPERTIES_PANEL * m_propertiesPanel
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
int GetSelection() const
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:303
void WriteCacheToFile(const wxString &aFilePath) override
void SetGridOrigin(const VECTOR2D &aGridOrigin)
Set the origin point for the grid.
void Clear()
Remove all items from the view.
Definition: view.cpp:1131
void InitPreview()
Definition: view.cpp:1710
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:285
int SetLayerSelection(int layer)
static LSET ForbiddenFootprintLayers()
Layers which are not allowed within footprint definitions.
Definition: lset.cpp:704
AUI_PANELS m_AuiPanels
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Helper to retrieve the current color settings.
wxString GetDesignRulesPath()
Return the absolute path to the design rules file for the currently-loaded board.
bool m_darkMode
Panel with Layers and Object Inspector tabs.
void doCloseWindow() override
void SetGridVisibility(bool aVisible) override
Override this function in the PCB_BASE_EDIT_FRAME to refill the layer widget.
virtual EDA_ANGLE GetRotationAngle() const
Return the angle used for rotate operations.
void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
bool TryBefore(wxEvent &aEvent) override
PCB_LAYER_BOX_SELECTOR * m_SelLayerBox
virtual void SetBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr) override
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
void ToggleProperties() override
void configureToolbars() override
PCB_BASE_EDIT_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName)
APPEARANCE_CONTROLS * m_appearancePanel
void SetObjectVisible(GAL_LAYER_ID aLayer, bool aVisible=true)
void GetContextualTextVars(BOARD_ITEM *aSourceItem, const wxString &aCrossRef, wxArrayString *aTokens)
void handleActivateEvent(wxActivateEvent &aEvent) override
Handle a window activation event.
virtual void onDarkModeToggle()
void ActivateGalCanvas() override
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Display options control the way tracks, vias, outlines and other things are shown (for instance solid...
void handleActivateEvent(wxActivateEvent &aEvent) override
Handle a window activation event.
virtual void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
PCBNEW_SETTINGS * GetPcbNewSettings() const
virtual PCB_LAYER_ID GetActiveLayer() const
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual void ActivateGalCanvas() override
Use to start up the GAL drawing canvas.
virtual void SetBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
BOARD * GetBoard() const
EDA_3D_VIEWER_FRAME * Get3DViewerFrame()
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
void UpdateColors()
Update the color settings in the painter and GAL.
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void DisplayBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Add all items from the current board to the VIEW, so they can be displayed by GAL.
void SyncLayersVisibility(const BOARD *aBoard)
Update "visibility" property of each layer of a given BOARD.
Class to display a pcb layer list in a wxBitmapComboBox.
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
void SetNotAllowedLayerSet(LSET aMask)
The selection tool: currently supports:
void OnIdle(wxIdleEvent &aEvent)
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:125
A progress reporter interface for use in multi-threaded environments.
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
Definition: project.cpp:370
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieve a color settings object that applications can read colors from.
bool IsProjectOpen() const
Helper for checking if we have a project open.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Save, unload and unregister the given PROJECT.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:171
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition: tool_base.h:80
void PostEvent(const TOOL_EVENT &aEvent)
Put an event to the event queue to be processed at the end of event processing cycle.
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
#define _(s)
Declaration of the eda_3d_viewer class.
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:403
#define VIEWPORT_SWITCH_KEY
#define PRESET_SWITCH_KEY
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: cvpcb.cpp:156
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:33
@ FRAME_FOOTPRINT_EDITOR
Definition: frame_type.h:43
static const std::string DesignRulesFileExtension
PROJECT & Prj()
Definition: kicad.cpp:597
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition: layer_ids.h:228
@ LAYER_GRID
Definition: layer_ids.h:253
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:722
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition: wxgtk/ui.cpp:48
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:1073
see class PGM_BASE
VECTOR2< double > VECTOR2D
Definition: vector2d.h:694
Definition of file extensions used in Kicad.
void SetAuiPaneSize(wxAuiManager &aManager, wxAuiPaneInfo &aPane, int aWidth, int aHeight)
Sets the size of an AUI pane, working around http://trac.wxwidgets.org/ticket/13180.