KiCad PCB EDA Suite
Loading...
Searching...
No Matches
footprint_wizard_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) 2012-2015 Miguel Angel Ajo Pelayo <[email protected]>
5 * Copyright (C) 2012-2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
6 * Copyright (C) 2008 Wayne Stambaugh <[email protected]>
7 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
24
25#include <wx/listbox.h>
26#include <wx/numformatter.h>
27#include <wx/statline.h>
28#include <wx/textctrl.h>
29#include <wx/tokenzr.h>
30#include <wx/wupdlock.h>
31
32#include <json_common.h>
33
34#include <kiface_base.h>
35#include <pcb_draw_panel_gal.h>
36#include <pcb_edit_frame.h>
39#include <widgets/msgpanel.h>
40#include <bitmaps.h>
41#include <board.h>
43#include <footprint.h>
46#include <pcbnew_id.h>
49
50#include <nlohmann/json.hpp>
51#include <wx/wupdlock.h>
52#include <pgm_base.h>
55#include <tool/tool_manager.h>
57#include <tool/action_toolbar.h>
58#include <tool/common_tools.h>
59#include <tool/common_control.h>
61#include <tools/pcb_control.h>
62#include <tools/pcb_actions.h>
65
66
68
69 // Window events
72
73 // Toolbar events
76
77END_EVENT_TABLE()
78
79
80// Note: our FOOTPRINT_WIZARD_FRAME is always modal.
81
83 FRAME_T aFrameType ) :
84 PCB_BASE_EDIT_FRAME( aKiway, aParent, aFrameType, _( "Footprint Wizard" ),
85 wxDefaultPosition, wxDefaultSize,
86 aParent ? KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT
87 : KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP,
89 m_wizardListShown( false )
90{
91 wxASSERT( aFrameType == FRAME_FOOTPRINT_WIZARD );
92
93 // This frame is always show modal:
94 SetModal( true );
95
96 // Give an icon
97 wxIcon icon;
98 icon.CopyFromBitmap( KiBitmap( BITMAPS::module_wizard ) );
99 SetIcon( icon );
100
101 m_currentWizard = nullptr;
102 m_builtFootprint = nullptr;
103 m_wizardManager = std::make_unique<FOOTPRINT_WIZARD_MANAGER>();
104
105 // Create the GAL canvas.
106 // Must be created before calling LoadSettings() that needs a valid GAL canvas
107 PCB_DRAW_PANEL_GAL* gal_drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
110 SetCanvas( gal_drawPanel );
111
112 SetBoard( new BOARD() );
113
114 // Ensure all layers and items are visible:
115 GetBoard()->SetVisibleAlls();
117 GetScreen()->m_Center = true; // Center coordinate origins on screen.
118
119 LoadSettings( config() );
120
121 SetSize( m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
122
123 // Set some display options here, because the FOOTPRINT_WIZARD_FRAME
124 // does not have a config menu to do that:
125
126 // the footprint wizard frame has no config menu. so use some settings
127 // from the caller, or force some options:
128 PCB_BASE_FRAME* caller = dynamic_cast<PCB_BASE_FRAME*>( aParent );
129
130 if( caller )
131 SetUserUnits( caller->GetUserUnits() );
132
133 // In viewer, the default net clearance is not known (it depends on the actual board).
134 // So we do not show the default clearance, by setting it to 0
135 // The footprint or pad specific clearance will be shown
136 GetBoard()->GetDesignSettings().m_NetSettings->GetDefaultNetclass()->SetClearance( 0 );
137
138 // Create the manager and dispatcher & route draw panel events to the dispatcher
140 m_toolManager->SetEnvironment( GetBoard(), gal_drawPanel->GetView(),
141 gal_drawPanel->GetViewControls(), config(), this );
142 m_actions = new PCB_ACTIONS();
144 gal_drawPanel->SetEventDispatcher( m_toolDispatcher );
145
146 m_toolManager->RegisterTool( new PCB_CONTROL );
147 m_toolManager->RegisterTool( new PCB_SELECTION_TOOL ); // for std context menus (zoom & grid)
148 m_toolManager->RegisterTool( new COMMON_TOOLS );
149 m_toolManager->RegisterTool( new COMMON_CONTROL );
150 m_toolManager->RegisterTool( new FOOTPRINT_WIZARD_TOOLS );
151 m_toolManager->InitTools();
152
153 // Run the control tool, it is supposed to be always active
154 m_toolManager->InvokeTool( "common.InteractiveSelection" );
155
156 // Create the toolbars
160
161 // Create the parameters panel
163
165
166 // Create the build message box
167 m_buildMessageBox = new wxTextCtrl( this, wxID_ANY, wxEmptyString,
168 wxDefaultPosition, wxDefaultSize,
169 wxTE_MULTILINE | wxTE_READONLY | wxNO_BORDER );
170
172
173 m_auimgr.SetManagedWindow( this );
174
175 m_auimgr.AddPane( m_tbTopMain, EDA_PANE().HToolbar().Name( "TopMainToolbar" ).Top().Layer(6) );
176 m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6)
177 .BestSize( -1, m_msgFrameHeight ) );
178
179 m_auimgr.AddPane( m_parametersPanel, EDA_PANE().Palette().Name( "Params" ).Left().Position(0)
180 .Caption( _( "Parameters" ) ).MinSize( 200, 320 ) );
181 m_auimgr.AddPane( m_buildMessageBox, EDA_PANE().Palette().Name( "Output" ).Left().Position(1)
182 .CaptionVisible( false ).MinSize( 120, -1 ) );
183
184 m_auimgr.AddPane( GetCanvas(), wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
185
186 auto& galOpts = GetGalDisplayOptions();
187 galOpts.SetCursorMode( KIGFX::CROSS_HAIR_MODE::FULLSCREEN_CROSS );
188 galOpts.m_forceDisplayCursor = true;
189 galOpts.m_axesEnabled = true;
190
191 // Switch to the canvas type set in config
194
195 updateView();
196
198 GetToolManager()->PostAction( ACTIONS::zoomFitScreen );
199
200 // Do not Run a dialog here: on some Window Managers, it creates issues.
201 // Reason: the FOOTPRINT_WIZARD_FRAME is run as modal;
202 // It means the call to FOOTPRINT_WIZARD_FRAME::ShowModal will change the
203 // Event Loop Manager, and stop the one created by the dialog.
204 // It does not happen on all W.M., perhaps due to the way the order events are called
205 // See the call in onActivate instead
206}
207
208
210{
212 // Be sure any event cannot be fired after frame deletion:
213 GetCanvas()->SetEvtHandlerEnabled( false );
214
215 // Be sure a active tool (if exists) is deactivated:
216 if( m_toolManager )
217 m_toolManager->DeactivateTool();
218
219 if( EDA_3D_VIEWER_FRAME* our3DViewer = GetOur3DViewerFrame() )
220 our3DViewer->Destroy();
221
222 // Now this frame can be deleted
223}
224
225
227{
228 SaveSettings( config() );
229
230 if( IsModal() )
231 {
232 // Only dismiss a modal frame once, so that the return values set by
233 // the prior DismissModal() are not bashed for ShowModal().
234 if( !IsDismissed() )
235 DismissModal( false );
236 }
237}
238
239
241{
242 DismissModal( true );
243 Close();
244}
245
246
247void FOOTPRINT_WIZARD_FRAME::OnSize( wxSizeEvent& SizeEv )
248{
249 if( m_auimgr.GetManagedWindow() )
250 m_auimgr.Update();
251
252 SizeEv.Skip();
253}
254
255
257{
259 return ::GetColorSettings( cfg ? cfg->m_ColorTheme : DEFAULT_THEME );
260}
261
262
271
272
274{
275 BOARD_ITEM* footprint = GetBoard()->GetFirstFootprint();
276
277 if( footprint )
278 {
279 std::vector<MSG_PANEL_ITEM> items;
280
281 footprint->GetMsgPanelInfo( this, items );
282 SetMsgPanel( items );
283 }
284 else
285 {
287 }
288}
289
290
292{
293 if( !m_parametersPanel )
294 return;
295
296 m_parametersPanel->RebuildParameters( GetMyWizard() );
297
300 GetCanvas()->Refresh();
301}
302
303
305{
306 PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
307 wxCHECK( cfg, /*void*/ );
308
310
312 m_viewerAuiState = std::make_unique<nlohmann::json>( cfg->m_FootprintViewer.aui_state );
313}
314
315
317{
318 PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
319 wxCHECK( cfg, /*void*/ );
320
322
323#if wxCHECK_VERSION( 3, 3, 0 )
324 {
325 WX_AUI_JSON_SERIALIZER serializer( m_auimgr );
326 nlohmann::json state = serializer.Serialize();
327
328 if( state.is_null() || state.empty() )
329 cfg->m_FootprintViewer.aui_state = nlohmann::json();
330 else
331 cfg->m_FootprintViewer.aui_state = state;
332
333 cfg->m_FootprintViewer.perspective.clear();
334 }
335#else
336 cfg->m_FootprintViewer.perspective = m_auimgr.SavePerspective().ToStdString();
337 cfg->m_FootprintViewer.aui_state = nlohmann::json();
338#endif
339}
340
341
343{
344 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg ) )
345 return &cfg->m_FootprintWizard;
346
347 wxFAIL_MSG( wxT( "FOOTPRINT_CHOOSER not running with PCBNEW_SETTINGS" ) );
348 return &aCfg->m_Window; // non-null fail-safe
349}
350
351
352void FOOTPRINT_WIZARD_FRAME::OnActivate( wxActivateEvent& event )
353{
354 // Ensure we do not have old selection:
355 if( !event.GetActive() )
356 return;
357
358 if( !m_wizardListShown )
359 {
360 m_wizardListShown = true;
361 wxPostEvent( this, wxCommandEvent( wxEVT_TOOL, ID_FOOTPRINT_WIZARD_SELECT_WIZARD ) );
362 }
363
364 // TODO(JE) re-evaluate below
365#if 0
366 // Currently, we do not have a way to see if a Python wizard has changed,
367 // therefore the lists of parameters and option has to be rebuilt
368 // This code could be enabled when this way exists
369 bool footprintWizardsChanged = false;
370
371 if( footprintWizardsChanged )
372 {
373 // If we are here, the library list has changed, rebuild it
376 }
377#endif
378}
379
380
381void FOOTPRINT_WIZARD_FRAME::Update3DView( bool aMarkDirty, bool aRefresh, const wxString* aTitle )
382{
383 wxString wizardName = m_currentWizard ? m_currentWizard->Info().meta.name : _( "no wizard selected" );
384 wxString frm3Dtitle;
385 frm3Dtitle.Printf( _( "3D Viewer [%s]" ), wizardName );
386 PCB_BASE_FRAME::Update3DView( aMarkDirty, aRefresh, &frm3Dtitle );
387}
388
389
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition bitmap.cpp:100
static TOOL_ACTION zoomFitScreen
Definition actions.h:138
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
WINDOW_SETTINGS m_Window
wxString m_ColorTheme
Active color theme name.
Abstract interface for BOARD_ITEMs capable of storing other items inside.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:85
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:713
Color settings are a bit different than most of the settings objects in that there can be more than o...
Handle actions that are shared between different applications.
Handles action that are shared between different applications.
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
TOOLBAR_SETTINGS * m_toolbarSettings
wxAuiManager m_auimgr
virtual void RecreateToolbars()
ACTION_TOOLBAR * m_tbTopMain
virtual void ClearMsgPanel()
Clear all messages from the message panel.
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
GAL_DISPLAY_OPTIONS_IMPL & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
virtual void resolveCanvasType()
Determine the canvas type to load (with prompt if required) and initializes m_canvasType.
EDA_MSG_PANEL * m_messagePanel
void SetCanvas(EDA_DRAW_PANEL_GAL *aPanel)
virtual void SetScreen(BASE_SCREEN *aScreen)
virtual void ReCreateHToolbar()
void StopDrawing()
Prevent the GAL canvas from further drawing until it is recreated or StartDrawing() is called.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Return a pointer to the KIGFX::VIEW_CONTROLS instance used in the panel.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
@ GAL_TYPE_MODERN
RHI implementation, Vulkan or Metal on macOS.
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
virtual void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition eda_item.h:296
Specialization of the wxAuiPaneInfo class for KiCad panels.
BOARD_ITEM_CONTAINER * GetModel() const override
std::unique_ptr< FOOTPRINT_WIZARD_MANAGER > m_wizardManager
void OnSize(wxSizeEvent &event) override
Recalculate the size of toolbars and display panel when the frame size changes.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void ReCreateParameterList()
Create the list of parameters for the current page.
void DisplayWizardInfos()
Show all the details about the current wizard.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Helper to retrieve the current color settings.
void SelectCurrentWizard(wxCommandEvent &aDummy)
bool m_wizardListShown
A show-once flag for the wizard list.
void updateView()
Rebuild the GAL view (reint tool manager, colors and drawings) must be run after any footprint change...
void Update3DView(bool aMarkDirty, bool aRefresh, const wxString *aTitle=nullptr) override
Update the 3D view, if the viewer is opened by this frame.
FOOTPRINT_WIZARD * m_currentWizard
FOOTPRINT_WIZARD * GetMyWizard()
Reloads the wizard by name.
FOOTPRINT_WIZARD_FRAME(KIWAY *aKiway, wxWindow *parent, FRAME_T aFrameType)
void UpdateMsgPanel() override
Redraw the message panel.
std::unique_ptr< nlohmann::json > m_viewerAuiState
wxString m_auiPerspective
Encoded string describing the AUI layout.
FOOTPRINT_WIZARD_PROPERTIES_PANEL * m_parametersPanel
Panel for the parameter grid.
void ExportSelectedFootprint(wxCommandEvent &aEvent)
Will let the caller exit from the wait loop, and get the built footprint.
WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg) override
Return a pointer to the window settings for this frame.
void OnActivate(wxActivateEvent &event)
Called when the frame frame is activate to reload the libraries and component lists that can be chang...
Tool useful for viewing footprints.
void SetModal(bool aIsModal)
void DismissModal(bool aRetVal, const wxString &aResult=wxEmptyString)
bool IsModal() const override
Return true if the frame is shown in our modal mode and false if the frame is shown as an usual frame...
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:348
WINDOW_SETTINGS m_FootprintViewer
Gather all the actions that are shared by tools.
Definition pcb_actions.h:51
Common, abstract interface for edit frames.
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 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)
void ActivateGalCanvas() override
Use to start up the GAL drawing canvas.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
const VECTOR2I GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
PCB_BASE_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName)
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
BOARD * GetBoard() const
FOOTPRINT_EDITOR_SETTINGS * GetFootprintEditorSettings() const
EDA_3D_VIEWER_FRAME * GetOur3DViewerFrame()
virtual void Update3DView(bool aMarkDirty, bool aRefresh, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
Handle actions that are shared between different frames in PcbNew.
Definition pcb_control.h:47
void UpdateColors()
Update the color settings in the painter and GAL.
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the KIGFX::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.
The selection tool: currently supports:
TOOL_MANAGER * m_toolManager
TOOL_DISPATCHER * m_toolDispatcher
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
ACTIONS * m_actions
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition tool_base.h:76
Master controller class:
EDA_UNITS GetUserUnits() const
void SetUserUnits(EDA_UNITS aUnits)
nlohmann::json Serialize() const
#define _(s)
Declaration of the eda_3d_viewer class.
#define KICAD_DEFAULT_DRAWFRAME_STYLE
#define FOOTPRINT_WIZARD_FRAME_NAME
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition frame_type.h:29
@ FRAME_FOOTPRINT_WIZARD
Definition frame_type.h:42
@ F_Cu
Definition layer_ids.h:60
Message panel definition file.
@ ID_FOOTPRINT_WIZARD_DONE
Definition pcbnew_id.h:91
@ ID_FOOTPRINT_WIZARD_SELECT_WIZARD
Definition pcbnew_id.h:94
see class PGM_BASE
#define DEFAULT_THEME
T * GetToolbarSettings(const wxString &aFilename)
Store the common settings that are saved and loaded for each window / frame.
nlohmann::json aui_state
wxString perspective