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/tokenzr.h>
29#include <wx/wupdlock.h>
30
31#include <json_common.h>
32
33#include <kiface_base.h>
34#include <pcb_draw_panel_gal.h>
35#include <pcb_edit_frame.h>
38#include <widgets/msgpanel.h>
39#include <bitmaps.h>
40#include <board.h>
42#include <footprint.h>
45#include <pcbnew_id.h>
48
49#include <nlohmann/json.hpp>
50#include <wx/wupdlock.h>
51#include <pgm_base.h>
54#include <tool/tool_manager.h>
56#include <tool/action_toolbar.h>
57#include <tool/common_tools.h>
58#include <tool/common_control.h>
60#include <tools/pcb_control.h>
61#include <tools/pcb_actions.h>
64
65
67
68 // Window events
71
72 // Toolbar events
75
76END_EVENT_TABLE()
77
78
79// Note: our FOOTPRINT_WIZARD_FRAME is always modal.
80
82 FRAME_T aFrameType ) :
83 PCB_BASE_EDIT_FRAME( aKiway, aParent, aFrameType, _( "Footprint Wizard" ),
84 wxDefaultPosition, wxDefaultSize,
85 aParent ? KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT
86 : KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP,
88 m_wizardListShown( false )
89{
90 wxASSERT( aFrameType == FRAME_FOOTPRINT_WIZARD );
91
92 // This frame is always show modal:
93 SetModal( true );
94
95 // Give an icon
96 wxIcon icon;
97 icon.CopyFromBitmap( KiBitmap( BITMAPS::module_wizard ) );
98 SetIcon( icon );
99
100 m_currentWizard = nullptr;
101 m_wizardManager = std::make_unique<FOOTPRINT_WIZARD_MANAGER>();
102
103 // Create the GAL canvas.
104 // Must be created before calling LoadSettings() that needs a valid GAL canvas
105 PCB_DRAW_PANEL_GAL* gal_drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ),
109 SetCanvas( gal_drawPanel );
110
111 SetBoard( new BOARD() );
112
113 // Ensure all layers and items are visible:
114 GetBoard()->SetVisibleAlls();
116 GetScreen()->m_Center = true; // Center coordinate origins on screen.
117
118 LoadSettings( config() );
119
120 SetSize( m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
121
122 // Set some display options here, because the FOOTPRINT_WIZARD_FRAME
123 // does not have a config menu to do that:
124
125 // the footprint wizard frame has no config menu. so use some settings
126 // from the caller, or force some options:
127 PCB_BASE_FRAME* caller = dynamic_cast<PCB_BASE_FRAME*>( aParent );
128
129 if( caller )
130 SetUserUnits( caller->GetUserUnits() );
131
132 // In viewer, the default net clearance is not known (it depends on the actual board).
133 // So we do not show the default clearance, by setting it to 0
134 // The footprint or pad specific clearance will be shown
135 GetBoard()->GetDesignSettings().m_NetSettings->GetDefaultNetclass()->SetClearance( 0 );
136
137 // Create the manager and dispatcher & route draw panel events to the dispatcher
139 m_toolManager->SetEnvironment( GetBoard(), gal_drawPanel->GetView(),
140 gal_drawPanel->GetViewControls(), config(), this );
141 m_actions = new PCB_ACTIONS();
143 gal_drawPanel->SetEventDispatcher( m_toolDispatcher );
144
145 m_toolManager->RegisterTool( new PCB_CONTROL );
146 m_toolManager->RegisterTool( new PCB_SELECTION_TOOL ); // for std context menus (zoom & grid)
147 m_toolManager->RegisterTool( new COMMON_TOOLS );
148 m_toolManager->RegisterTool( new COMMON_CONTROL );
149 m_toolManager->RegisterTool( new FOOTPRINT_WIZARD_TOOLS );
150 m_toolManager->InitTools();
151
152 // Run the control tool, it is supposed to be always active
153 m_toolManager->InvokeTool( "common.InteractiveSelection" );
154
155 // Create the toolbars
159
160 // Create the parameters panel
162
164
165 // Create the build message box
166 m_buildMessageBox = new wxTextCtrl( this, wxID_ANY, wxEmptyString,
167 wxDefaultPosition, wxDefaultSize,
168 wxTE_MULTILINE | wxTE_READONLY | wxNO_BORDER );
169
171
172 m_auimgr.SetManagedWindow( this );
173
174 m_auimgr.AddPane( m_tbTopMain, EDA_PANE().HToolbar().Name( "TopMainToolbar" ).Top().Layer(6) );
175 m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6)
176 .BestSize( -1, m_msgFrameHeight ) );
177
178 m_auimgr.AddPane( m_parametersPanel, EDA_PANE().Palette().Name( "Params" ).Left().Position(0)
179 .Caption( _( "Parameters" ) ).MinSize( 200, 320 ) );
180 m_auimgr.AddPane( m_buildMessageBox, EDA_PANE().Palette().Name( "Output" ).Left().Position(1)
181 .CaptionVisible( false ).MinSize( 120, -1 ) );
182
183 m_auimgr.AddPane( GetCanvas(), wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
184
185 auto& galOpts = GetGalDisplayOptions();
186 galOpts.SetCursorMode( KIGFX::CROSS_HAIR_MODE::FULLSCREEN_CROSS );
187 galOpts.m_forceDisplayCursor = true;
188 galOpts.m_axesEnabled = true;
189
190 // Switch to the canvas type set in config
192 GetCanvas()->SwitchBackend( m_canvasType );
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 EDA_3D_VIEWER_FRAME* draw3DFrame = Get3DViewerFrame();
220
221 if( draw3DFrame )
222 draw3DFrame->Destroy();
223
224 // Now this frame can be deleted
225}
226
227
229{
230 SaveSettings( config() );
231
232 if( IsModal() )
233 {
234 // Only dismiss a modal frame once, so that the return values set by
235 // the prior DismissModal() are not bashed for ShowModal().
236 if( !IsDismissed() )
237 DismissModal( false );
238 }
239}
240
241
243{
244 DismissModal( true );
245 Close();
246}
247
248
249void FOOTPRINT_WIZARD_FRAME::OnSize( wxSizeEvent& SizeEv )
250{
251 if( m_auimgr.GetManagedWindow() )
252 m_auimgr.Update();
253
254 SizeEv.Skip();
255}
256
257
259{
261 return ::GetColorSettings( cfg ? cfg->m_ColorTheme : DEFAULT_THEME );
262}
263
264
273
274
276{
277 BOARD_ITEM* footprint = GetBoard()->GetFirstFootprint();
278
279 if( footprint )
280 {
281 std::vector<MSG_PANEL_ITEM> items;
282
283 footprint->GetMsgPanelInfo( this, items );
284 SetMsgPanel( items );
285 }
286 else
287 {
289 }
290}
291
292
294{
295 if( !m_parametersPanel )
296 return;
297
298 m_parametersPanel->RebuildParameters( GetMyWizard() );
299
302 GetCanvas()->Refresh();
303}
304
305
307{
308 PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
309 wxCHECK( cfg, /*void*/ );
310
312
314 m_viewerAuiState = std::make_unique<nlohmann::json>( cfg->m_FootprintViewer.aui_state );
315}
316
317
319{
320 PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
321 wxCHECK( cfg, /*void*/ );
322
324
325#if wxCHECK_VERSION( 3, 3, 0 )
326 {
327 WX_AUI_JSON_SERIALIZER serializer( m_auimgr );
328 nlohmann::json state = serializer.Serialize();
329
330 if( state.is_null() || state.empty() )
331 cfg->m_FootprintViewer.aui_state = nlohmann::json();
332 else
333 cfg->m_FootprintViewer.aui_state = state;
334
335 cfg->m_FootprintViewer.perspective.clear();
336 }
337#else
338 cfg->m_FootprintViewer.perspective = m_auimgr.SavePerspective().ToStdString();
339 cfg->m_FootprintViewer.aui_state = nlohmann::json();
340#endif
341}
342
343
345{
346 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg ) )
347 return &cfg->m_FootprintWizard;
348
349 wxFAIL_MSG( wxT( "FOOTPRINT_CHOOSER not running with PCBNEW_SETTINGS" ) );
350 return &aCfg->m_Window; // non-null fail-safe
351}
352
353
354void FOOTPRINT_WIZARD_FRAME::OnActivate( wxActivateEvent& event )
355{
356 // Ensure we do not have old selection:
357 if( !event.GetActive() )
358 return;
359
360 if( !m_wizardListShown )
361 {
362 m_wizardListShown = true;
363 wxPostEvent( this, wxCommandEvent( wxEVT_TOOL, ID_FOOTPRINT_WIZARD_SELECT_WIZARD ) );
364 }
365
366 // TODO(JE) re-evaluate below
367#if 0
368 // Currently, we do not have a way to see if a Python wizard has changed,
369 // therefore the lists of parameters and option has to be rebuilt
370 // This code could be enabled when this way exists
371 bool footprintWizardsChanged = false;
372
373 if( footprintWizardsChanged )
374 {
375 // If we are here, the library list has changed, rebuild it
378 }
379#endif
380}
381
382
383void FOOTPRINT_WIZARD_FRAME::Update3DView( bool aMarkDirty, bool aRefresh, const wxString* aTitle )
384{
385 wxString wizardName = m_currentWizard ? m_currentWizard->Info().meta.name : _( "no wizard selected" );
386 wxString frm3Dtitle;
387 frm3Dtitle.Printf( _( "3D Viewer [%s]" ), wizardName );
388 PCB_BASE_FRAME::Update3DView( aMarkDirty, aRefresh, &frm3Dtitle );
389}
390
391
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:81
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:587
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.
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
The current canvas type.
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()
static constexpr GAL_TYPE GAL_FALLBACK
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 #VIEW_CONTROLS instance used in the panel.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
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:230
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)
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
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:311
WINDOW_SETTINGS m_FootprintViewer
Gather all the actions that are shared by tools.
Definition pcb_actions.h:47
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
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
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 * Get3DViewerFrame()
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:43
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.
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:90
@ ID_FOOTPRINT_WIZARD_SELECT_WIZARD
Definition pcbnew_id.h:93
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