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 <pcb_base_edit_frame.h>
28#include <tool/tool_manager.h>
29#include <tools/pcb_actions.h>
31#include <pcbnew_settings.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>
40#include <tools/pcb_actions.h>
45#include <collectors.h>
46
47
49 FRAME_T aFrameType, const wxString& aTitle,
50 const wxPoint& aPos, const wxSize& aSize, long aStyle,
51 const wxString& aFrameName ) :
52 PCB_BASE_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ),
53 m_undoRedoBlocked( false ),
54 m_selectionFilterPanel( nullptr ),
55 m_appearancePanel( nullptr ),
56 m_propertiesPanel( nullptr ),
57 m_tabbedPanel( nullptr )
58{
59 Bind( wxEVT_IDLE,
60 [this]( wxIdleEvent& aEvent )
61 {
62 // Handle cursor adjustments. While we can get motion and key events through
63 // wxWidgets, we can't get modifier-key-up events.
64 if( m_toolManager )
65 {
67
68 if( selTool )
69 selTool->OnIdle( aEvent );
70 }
71 } );
72}
73
74
76{
77 GetCanvas()->GetView()->Clear();
78}
79
80
82{
84 wxFileName projectName( Prj().GetProjectFullName() );
85
86 if( mgr->IsProjectOpen() && wxFileName::IsDirWritable( projectName.GetPath() )
87 && projectName.Exists() )
88 {
89 GFootprintList.WriteCacheToFile( Prj().GetProjectPath() + wxT( "fp-info-cache" ) );
90 }
91
92 // Close the project if we are standalone, so it gets cleaned up properly
93 if( mgr->IsProjectOpen() && Kiface().IsSingle() )
94 mgr->UnloadProject( &Prj(), false );
95}
96
97
98bool PCB_BASE_EDIT_FRAME::TryBefore( wxEvent& aEvent )
99{
100 static bool s_presetSwitcherShown = false;
101 static bool s_viewportSwitcherShown = false;
102
103#ifdef __WXMAC__
104 wxKeyCode presetSwitchKey = WXK_RAW_CONTROL;
105 wxKeyCode viewSwitchKey = WXK_ALT;
106#else
107 wxKeyCode presetSwitchKey = WXK_RAW_CONTROL;
108 wxKeyCode viewSwitchKey = WXK_WINDOWS_LEFT;
109#endif
110
111 if( aEvent.GetEventType() != wxEVT_CHAR && aEvent.GetEventType() != wxEVT_CHAR_HOOK )
112 return PCB_BASE_FRAME::TryBefore( aEvent );
113
114 if( !s_presetSwitcherShown && wxGetKeyState( presetSwitchKey ) && wxGetKeyState( WXK_TAB ) )
115 {
116 if( m_appearancePanel && this->IsActive() )
117 {
118 const wxArrayString& mru = m_appearancePanel->GetLayerPresetsMRU();
119
120 if( mru.size() > 0 )
121 {
122 EDA_VIEW_SWITCHER switcher( this, mru, presetSwitchKey );
123
124 s_presetSwitcherShown = true;
125 switcher.ShowModal();
126 s_presetSwitcherShown = false;
127
128 int idx = switcher.GetSelection();
129
130 if( idx >= 0 && idx < (int) mru.size() )
132
133 return true;
134 }
135 }
136 }
137 else if( !s_viewportSwitcherShown && wxGetKeyState( viewSwitchKey ) && wxGetKeyState( WXK_TAB ) )
138 {
139 if( m_appearancePanel && this->IsActive() )
140 {
141 const wxArrayString& mru = m_appearancePanel->GetViewportsMRU();
142
143 if( mru.size() > 0 )
144 {
145 EDA_VIEW_SWITCHER switcher( this, mru, viewSwitchKey );
146
147 s_viewportSwitcherShown = true;
148 switcher.ShowModal();
149 s_viewportSwitcherShown = false;
150
151 int idx = switcher.GetSelection();
152
153 if( idx >= 0 && idx < (int) mru.size() )
154 m_appearancePanel->ApplyViewport( mru[idx] );
155
156 return true;
157 }
158 }
159 }
160
161 return PCB_BASE_FRAME::TryBefore( aEvent );
162}
163
164
166{
167 // Return a default angle (90 degrees) used for rotate operations.
168 return ANGLE_90;
169}
170
171
173{
175
177}
178
179
181{
182 bool new_board = ( aBoard != m_pcb );
183
184 if( new_board )
185 {
186 if( m_toolManager )
188
189 GetCanvas()->GetView()->Clear();
191 }
192
193 PCB_BASE_FRAME::SetBoard( aBoard, aReporter );
194
196
197 if( new_board )
198 {
200 bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard, &bds );
201 }
202
203 // update the tool manager with the new board and its view.
204 if( m_toolManager )
205 {
206 GetCanvas()->DisplayBoard( aBoard, aReporter );
207
209 m_toolManager->SetEnvironment( aBoard, GetCanvas()->GetView(),
210 GetCanvas()->GetViewControls(), config(), this );
211
212 if( new_board )
214 }
215}
216
217
219{
221
222 if( BOARD* board = GetBoard() )
223 {
224 EDA_UNITS units = GetUserUnits();
225 KIGFX::VIEW* view = GetCanvas()->GetView();
226 bool selectedItemModified = false;
227
228 INSPECTOR_FUNC inspector =
229 [units, view, &selectedItemModified]( EDA_ITEM* aItem, void* aTestData )
230 {
231 PCB_DIMENSION_BASE* dimension = static_cast<PCB_DIMENSION_BASE*>( aItem );
232
233 if( dimension->GetUnitsMode() == DIM_UNITS_MODE::AUTOMATIC )
234 {
235 dimension->SetUnits( units );
236 dimension->Update();
237
238 if( dimension->IsSelected() )
239 selectedItemModified = true;
240
241 view->Update( dimension );
242 }
243
245 };
246
247 board->Visit( inspector, nullptr, { PCB_DIM_ALIGNED_T,
257
258 if( selectedItemModified )
260 }
261
264}
265
266
268{
270
271 // Update the grid checkbox in the layer widget
274}
275
276
278{
280 m_appearancePanel->SetObjectVisible( aLayer, aVisible );
281}
282
283
285{
286 return Pgm().GetSettingsManager().GetColorSettings( GetPcbNewSettings()->m_ColorTheme );
287}
288
289
291{
292 if( !GetBoard() )
293 return wxEmptyString;
294
295 wxFileName fn = GetBoard()->GetFileName();
296 fn.SetExt( DesignRulesFileExtension );
297 return Prj().AbsolutePath( fn.GetFullName() );
298}
299
300
301void PCB_BASE_EDIT_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
302{
304
305 // The text in the collapsible pane headers need to be updated
308}
309
310
312{
313 if( !m_propertiesPanel || !m_propertiesPanel->IsShownOnScreen() )
314 return;
315
317}
318
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 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:617
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.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
bool IsSelected() const
Definition: eda_item.h:107
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:210
void WriteCacheToFile(const wxString &aFilePath) override
void SetGridOrigin(const VECTOR2D &aGridOrigin)
Set the origin point for the grid.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:69
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1574
void Clear()
Remove all items from the view.
Definition: view.cpp:1096
void InitPreview()
Definition: view.cpp:1611
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:267
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.
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
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
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
Abstract dimension API.
Definition: pcb_dimension.h:96
void Update()
Update the dimension's cached text and geometry.
void SetUnits(EDA_UNITS aUnits)
DIM_UNITS_MODE GetUnitsMode() 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:304
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).
EDA_UNITS GetUserUnits() const
static constexpr EDA_ANGLE & ANGLE_90
Definition: eda_angle.h:414
std::function< INSPECT_RESULT(EDA_ITEM *aItem, void *aTestData) > INSPECTOR_FUNC
Used to inspect and possibly collect the (search) results of iterating over a list or tree of KICAD_T...
Definition: eda_item.h:75
EDA_UNITS
Definition: eda_units.h:43
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
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
@ PCB_FP_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:95
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:110
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:107
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:108
@ PCB_FP_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:97
@ PCB_FP_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:99
@ PCB_FP_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:96
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:106
@ PCB_FP_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:98
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:109
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617
Definition of file extensions used in Kicad.