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, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
28
29#include <wx/listbox.h>
30#include <wx/numformatter.h>
31#include <wx/statline.h>
32#include <wx/tokenzr.h>
33#include <wx/wupdlock.h>
34
35#include <json_common.h>
36
37#include <kiface_base.h>
38#include <pcb_draw_panel_gal.h>
39#include <pcb_edit_frame.h>
42#include <widgets/msgpanel.h>
43#include <bitmaps.h>
44#include <board.h>
46#include <footprint.h>
49#include <pcbnew_id.h>
52
53#include <nlohmann/json.hpp>
54#include <wx/wupdlock.h>
55#include <pgm_base.h>
58#include <tool/tool_manager.h>
60#include <tool/action_toolbar.h>
61#include <tool/common_tools.h>
62#include <tool/common_control.h>
64#include <tools/pcb_control.h>
65#include <tools/pcb_actions.h>
68
69
71
72 // Window events
75
76 // Toolbar events
79
80END_EVENT_TABLE()
81
82
83// Note: our FOOTPRINT_WIZARD_FRAME is always modal.
84
86 FRAME_T aFrameType ) :
87 PCB_BASE_EDIT_FRAME( aKiway, aParent, aFrameType, _( "Footprint Wizard" ),
88 wxDefaultPosition, wxDefaultSize,
89 aParent ? KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT
90 : KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP,
92 m_wizardListShown( false )
93{
94 wxASSERT( aFrameType == FRAME_FOOTPRINT_WIZARD );
95
96 // This frame is always show modal:
97 SetModal( true );
98
99 // Give an icon
100 wxIcon icon;
101 icon.CopyFromBitmap( KiBitmap( BITMAPS::module_wizard ) );
102 SetIcon( icon );
103
104 m_currentWizard = nullptr;
105 m_wizardManager = std::make_unique<FOOTPRINT_WIZARD_MANAGER>();
106
107 // Create the GAL canvas.
108 // Must be created before calling LoadSettings() that needs a valid GAL canvas
109 PCB_DRAW_PANEL_GAL* gal_drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ),
113 SetCanvas( gal_drawPanel );
114
115 SetBoard( new BOARD() );
116
117 // Ensure all layers and items are visible:
118 GetBoard()->SetVisibleAlls();
120 GetScreen()->m_Center = true; // Center coordinate origins on screen.
121
122 LoadSettings( config() );
123
124 SetSize( m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
125
126 // Set some display options here, because the FOOTPRINT_WIZARD_FRAME
127 // does not have a config menu to do that:
128
129 // the footprint wizard frame has no config menu. so use some settings
130 // from the caller, or force some options:
131 PCB_BASE_FRAME* caller = dynamic_cast<PCB_BASE_FRAME*>( aParent );
132
133 if( caller )
134 SetUserUnits( caller->GetUserUnits() );
135
136 // In viewer, the default net clearance is not known (it depends on the actual board).
137 // So we do not show the default clearance, by setting it to 0
138 // The footprint or pad specific clearance will be shown
139 GetBoard()->GetDesignSettings().m_NetSettings->GetDefaultNetclass()->SetClearance( 0 );
140
141 // Create the manager and dispatcher & route draw panel events to the dispatcher
143 m_toolManager->SetEnvironment( GetBoard(), gal_drawPanel->GetView(),
144 gal_drawPanel->GetViewControls(), config(), this );
145 m_actions = new PCB_ACTIONS();
147 gal_drawPanel->SetEventDispatcher( m_toolDispatcher );
148
149 m_toolManager->RegisterTool( new PCB_CONTROL );
150 m_toolManager->RegisterTool( new PCB_SELECTION_TOOL ); // for std context menus (zoom & grid)
151 m_toolManager->RegisterTool( new COMMON_TOOLS );
152 m_toolManager->RegisterTool( new COMMON_CONTROL );
153 m_toolManager->RegisterTool( new FOOTPRINT_WIZARD_TOOLS );
154 m_toolManager->InitTools();
155
156 // Run the control tool, it is supposed to be always active
157 m_toolManager->InvokeTool( "common.InteractiveSelection" );
158
159 // Create the toolbars
163
164 // Create the parameters panel
166
168
169 // Create the build message box
170 m_buildMessageBox = new wxTextCtrl( this, wxID_ANY, wxEmptyString,
171 wxDefaultPosition, wxDefaultSize,
172 wxTE_MULTILINE | wxTE_READONLY | wxNO_BORDER );
173
175
176 m_auimgr.SetManagedWindow( this );
177
178 m_auimgr.AddPane( m_tbTopMain, EDA_PANE().HToolbar().Name( "TopMainToolbar" ).Top().Layer(6) );
179 m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6)
180 .BestSize( -1, m_msgFrameHeight ) );
181
182 m_auimgr.AddPane( m_parametersPanel, EDA_PANE().Palette().Name( "Params" ).Left().Position(0)
183 .Caption( _( "Parameters" ) ).MinSize( 200, 320 ) );
184 m_auimgr.AddPane( m_buildMessageBox, EDA_PANE().Palette().Name( "Output" ).Left().Position(1)
185 .CaptionVisible( false ).MinSize( 120, -1 ) );
186
187 m_auimgr.AddPane( GetCanvas(), wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
188
189 auto& galOpts = GetGalDisplayOptions();
190 galOpts.SetCursorMode( KIGFX::CROSS_HAIR_MODE::FULLSCREEN_CROSS );
191 galOpts.m_forceDisplayCursor = true;
192 galOpts.m_axesEnabled = true;
193
194 // Switch to the canvas type set in config
196 GetCanvas()->SwitchBackend( m_canvasType );
198
199 updateView();
200
202 GetToolManager()->PostAction( ACTIONS::zoomFitScreen );
203
204 // Do not Run a dialog here: on some Window Managers, it creates issues.
205 // Reason: the FOOTPRINT_WIZARD_FRAME is run as modal;
206 // It means the call to FOOTPRINT_WIZARD_FRAME::ShowModal will change the
207 // Event Loop Manager, and stop the one created by the dialog.
208 // It does not happen on all W.M., perhaps due to the way the order events are called
209 // See the call in onActivate instead
210}
211
212
214{
216 // Be sure any event cannot be fired after frame deletion:
217 GetCanvas()->SetEvtHandlerEnabled( false );
218
219 // Be sure a active tool (if exists) is deactivated:
220 if( m_toolManager )
221 m_toolManager->DeactivateTool();
222
223 EDA_3D_VIEWER_FRAME* draw3DFrame = Get3DViewerFrame();
224
225 if( draw3DFrame )
226 draw3DFrame->Destroy();
227
228 // Now this frame can be deleted
229}
230
231
233{
234 SaveSettings( config() );
235
236 if( IsModal() )
237 {
238 // Only dismiss a modal frame once, so that the return values set by
239 // the prior DismissModal() are not bashed for ShowModal().
240 if( !IsDismissed() )
241 DismissModal( false );
242 }
243}
244
245
247{
248 DismissModal( true );
249 Close();
250}
251
252
253void FOOTPRINT_WIZARD_FRAME::OnSize( wxSizeEvent& SizeEv )
254{
255 if( m_auimgr.GetManagedWindow() )
256 m_auimgr.Update();
257
258 SizeEv.Skip();
259}
260
261
263{
265 return ::GetColorSettings( cfg ? cfg->m_ColorTheme : DEFAULT_THEME );
266}
267
268
277
278
280{
281 BOARD_ITEM* footprint = GetBoard()->GetFirstFootprint();
282
283 if( footprint )
284 {
285 std::vector<MSG_PANEL_ITEM> items;
286
287 footprint->GetMsgPanelInfo( this, items );
288 SetMsgPanel( items );
289 }
290 else
291 {
293 }
294}
295
296
298{
299 if( !m_parametersPanel )
300 return;
301
302 m_parametersPanel->RebuildParameters( GetMyWizard() );
303
306 GetCanvas()->Refresh();
307}
308
309
311{
312 PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
313 wxCHECK( cfg, /*void*/ );
314
316
318 m_viewerAuiState = std::make_unique<nlohmann::json>( cfg->m_FootprintViewer.aui_state );
319}
320
321
323{
324 PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
325 wxCHECK( cfg, /*void*/ );
326
328
329#if wxCHECK_VERSION( 3, 3, 0 )
330 {
331 WX_AUI_JSON_SERIALIZER serializer( m_auimgr );
332 nlohmann::json state = serializer.Serialize();
333
334 if( state.is_null() || state.empty() )
335 cfg->m_FootprintViewer.aui_state = nlohmann::json();
336 else
337 cfg->m_FootprintViewer.aui_state = state;
338
339 cfg->m_FootprintViewer.perspective.clear();
340 }
341#else
342 cfg->m_FootprintViewer.perspective = m_auimgr.SavePerspective().ToStdString();
343 cfg->m_FootprintViewer.aui_state = nlohmann::json();
344#endif
345}
346
347
349{
350 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg ) )
351 return &cfg->m_FootprintWizard;
352
353 wxFAIL_MSG( wxT( "FOOTPRINT_CHOOSER not running with PCBNEW_SETTINGS" ) );
354 return &aCfg->m_Window; // non-null fail-safe
355}
356
357
358void FOOTPRINT_WIZARD_FRAME::OnActivate( wxActivateEvent& event )
359{
360 // Ensure we do not have old selection:
361 if( !event.GetActive() )
362 return;
363
364 if( !m_wizardListShown )
365 {
366 m_wizardListShown = true;
367 wxPostEvent( this, wxCommandEvent( wxEVT_TOOL, ID_FOOTPRINT_WIZARD_SELECT_WIZARD ) );
368 }
369
370 // TODO(JE) re-evaluate below
371#if 0
372 // Currently, we do not have a way to see if a Python wizard has changed,
373 // therefore the lists of parameters and option has to be rebuilt
374 // This code could be enabled when this way exists
375 bool footprintWizardsChanged = false;
376
377 if( footprintWizardsChanged )
378 {
379 // If we are here, the library list has changed, rebuild it
382 }
383#endif
384}
385
386
387void FOOTPRINT_WIZARD_FRAME::Update3DView( bool aMarkDirty, bool aRefresh, const wxString* aTitle )
388{
389 wxString wizardName = m_currentWizard ? m_currentWizard->Info().meta.name : _( "no wizard selected" );
390 wxString frm3Dtitle;
391 frm3Dtitle.Printf( _( "3D Viewer [%s]" ), wizardName );
392 PCB_BASE_FRAME::Update3DView( aMarkDirty, aRefresh, &frm3Dtitle );
393}
394
395
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:104
static TOOL_ACTION zoomFitScreen
Definition actions.h:142
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:84
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:524
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:227
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:315
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
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:47
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:80
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:33
@ FRAME_FOOTPRINT_WIZARD
Definition frame_type.h:46
@ F_Cu
Definition layer_ids.h:64
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