KiCad PCB EDA Suite
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 (C) 2020-2022 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>
29#include <tool/tool_manager.h>
30#include <tools/pcb_actions.h>
32#include <pgm_base.h>
33#include <board.h>
35#include <pcb_dimension.h>
36#include <footprint_info_impl.h>
37#include <project.h>
44#include <collectors.h>
45
46
48 FRAME_T aFrameType, const wxString& aTitle,
49 const wxPoint& aPos, const wxSize& aSize, long aStyle,
50 const wxString& aFrameName ) :
51 PCB_BASE_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ),
52 m_undoRedoBlocked( false ),
53 m_selectionFilterPanel( nullptr ),
54 m_appearancePanel( nullptr ),
55 m_propertiesPanel( nullptr ),
56 m_tabbedPanel( nullptr )
57{
59
60 Bind( wxEVT_IDLE,
61 [this]( wxIdleEvent& aEvent )
62 {
63 // Handle cursor adjustments. While we can get motion and key events through
64 // wxWidgets, we can't get modifier-key-up events.
65 if( m_toolManager )
66 {
68
69 if( selTool )
70 selTool->OnIdle( aEvent );
71 }
72
74 {
77 }
78 } );
79}
80
81
83{
84 GetCanvas()->GetView()->Clear();
85}
86
87
89{
91 wxFileName projectName( Prj().GetProjectFullName() );
92
93 if( mgr->IsProjectOpen() && wxFileName::IsDirWritable( projectName.GetPath() )
94 && projectName.Exists() )
95 {
96 GFootprintList.WriteCacheToFile( Prj().GetProjectPath() + wxT( "fp-info-cache" ) );
97 }
98
99 // Close the project if we are standalone, so it gets cleaned up properly
100 if( mgr->IsProjectOpen() && Kiface().IsSingle() )
101 mgr->UnloadProject( &Prj(), false );
102}
103
104
105bool PCB_BASE_EDIT_FRAME::TryBefore( wxEvent& aEvent )
106{
107 static bool s_presetSwitcherShown = false;
108 static bool s_viewportSwitcherShown = false;
109
110 // wxWidgets generates no key events for the tab key when the ctrl key is held down. One
111 // way around this is to look at all events and inspect the keyboard state of the tab key.
112 // However, this runs into issues on some linux VMs where querying the keyboard state is
113 // very slow. Fortunately we only use ctrl-tab on Mac, so we implement this lovely hack:
114#ifdef __WXMAC__
115 if( wxGetKeyState( WXK_TAB ) )
116#else
117 if( ( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
118 && static_cast<wxKeyEvent&>( aEvent ).GetKeyCode() == WXK_TAB )
119#endif
120 {
121 if( !s_presetSwitcherShown && wxGetKeyState( PRESET_SWITCH_KEY ) )
122 {
123 if( m_appearancePanel && this->IsActive() )
124 {
125 const wxArrayString& mru = m_appearancePanel->GetLayerPresetsMRU();
126
127 if( mru.size() > 0 )
128 {
129 EDA_VIEW_SWITCHER switcher( this, mru, PRESET_SWITCH_KEY );
130
131 s_presetSwitcherShown = true;
132 switcher.ShowModal();
133 s_presetSwitcherShown = false;
134
135 int idx = switcher.GetSelection();
136
137 if( idx >= 0 && idx < (int) mru.size() )
139
140 return true;
141 }
142 }
143 }
144 else if( !s_viewportSwitcherShown && wxGetKeyState( VIEWPORT_SWITCH_KEY ) )
145 {
146 if( m_appearancePanel && this->IsActive() )
147 {
148 const wxArrayString& mru = m_appearancePanel->GetViewportsMRU();
149
150 if( mru.size() > 0 )
151 {
152 EDA_VIEW_SWITCHER switcher( this, mru, VIEWPORT_SWITCH_KEY );
153
154 s_viewportSwitcherShown = true;
155 switcher.ShowModal();
156 s_viewportSwitcherShown = false;
157
158 int idx = switcher.GetSelection();
159
160 if( idx >= 0 && idx < (int) mru.size() )
161 m_appearancePanel->ApplyViewport( mru[idx] );
162
163 return true;
164 }
165 }
166 }
167 }
168
169 return PCB_BASE_FRAME::TryBefore( aEvent );
170}
171
172
174{
175 // Return a default angle (90 degrees) used for rotate operations.
176 return ANGLE_90;
177}
178
179
181{
183
185}
186
187
189{
190 bool new_board = ( aBoard != m_pcb );
191
192 if( new_board )
193 {
194 if( m_toolManager )
196
197 GetCanvas()->GetView()->Clear();
199 }
200
201 PCB_BASE_FRAME::SetBoard( aBoard, aReporter );
202
204
205 if( new_board )
206 {
208 bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard, &bds );
209 }
210
211 // update the tool manager with the new board and its view.
212 if( m_toolManager )
213 {
214 GetCanvas()->DisplayBoard( aBoard, aReporter );
215
217 m_toolManager->SetEnvironment( aBoard, GetCanvas()->GetView(),
218 GetCanvas()->GetViewControls(), config(), this );
219
220 if( new_board )
222 }
223}
224
225
227{
229
230 if( BOARD* board = GetBoard() )
231 {
232 bool selectedItemsModified = false;
233
234 UpdateUserUnits( board, &selectedItemsModified );
235
236 if( selectedItemsModified )
238 }
239
242}
243
244
246{
248
249 // Update the grid checkbox in the layer widget
252}
253
254
256{
258 m_appearancePanel->SetObjectVisible( aLayer, aVisible );
259}
260
261
263{
264 return Pgm().GetSettingsManager().GetColorSettings( GetPcbNewSettings()->m_ColorTheme );
265}
266
267
269{
270 if( !GetBoard() )
271 return wxEmptyString;
272
273 wxFileName fn = GetBoard()->GetFileName();
274 fn.SetExt( DesignRulesFileExtension );
275 return Prj().AbsolutePath( fn.GetFullName() );
276}
277
278
279void PCB_BASE_EDIT_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
280{
282
283 // The text in the collapsible pane headers need to be updated
286}
287
288
290{
292}
293
294
296{
297 if( !m_propertiesPanel || !m_propertiesPanel->IsShownOnScreen() )
298 return;
299
301}
302
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
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()
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
const wxString & GetFileName() const
Definition: board.h:302
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:686
Color settings are a bit different than most of the settings objects in that there can be more than o...
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
SETTINGS_MANAGER * GetSettingsManager() const
virtual void ReCreateAuxiliaryToolbar()
virtual void SetGridVisibility(bool aVisible)
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:213
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:1099
void InitPreview()
Definition: view.cpp:1628
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:274
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
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.
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 handleActivateEvent(wxActivateEvent &aEvent) override
Handle a window activation event.
PROPERTIES_PANEL * m_propertiesPanel
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.
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
void UpdateUserUnits(BOARD_ITEM *aItem, bool *aSelectedItemsModified=nullptr)
Update any references within aItem (or its descendants) to the user units.
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
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.
The selection tool: currently supports:
void OnIdle(wxIdleEvent &aEvent)
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:305
virtual void UpdateData()=0
bool IsProjectOpen() const
Helper for checking if we have a project open TODO: This should be deprecated along with Prj() once w...
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:170
@ MODEL_RELOAD
Model changes (required full reload)
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).
static constexpr EDA_ANGLE & ANGLE_90
Definition: eda_angle.h:425
#define VIEWPORT_SWITCH_KEY
#define PRESET_SWITCH_KEY
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: cvpcb.cpp:140
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:33
const std::string DesignRulesFileExtension
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition: layer_ids.h:190
@ LAYER_GRID
Definition: layer_ids.h:205
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition: gtk/ui.cpp:31
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617
Definition of file extensions used in Kicad.