KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_footprint_chooser.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) 2023 CERN
5 * Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
26#include <wx/sizer.h>
27#include <wx/button.h>
28#include <pcb_base_frame.h>
31#include <board.h>
32#include <project_pcb.h>
34#include <pgm_base.h>
39
40
42 const LIB_ID& aPreselect,
43 const wxArrayString& aFootprintHistoryList ) :
44 DIALOG_SHIM( aParent, wxID_ANY, _( "Choose Footprint" ), wxDefaultPosition, wxDefaultSize,
45 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
46 m_boardAdapter(),
47 m_currentCamera( m_trackBallCamera ),
48 m_trackBallCamera( 2 * RANGE_SCALE_3D )
49{
50 m_parent = aParent;
51 m_showFpMode = true;
52
53 // This is also the main sizer:
54 wxBoxSizer* m_SizerTop = new wxBoxSizer( wxVERTICAL );
55
56 m_chooserPanel = new PANEL_FOOTPRINT_CHOOSER( aParent, this, aFootprintHistoryList,
57 // Filter
58 []( LIB_TREE_NODE& aNode ) -> bool
59 {
60 return true;
61 },
62 // Accept handler
63 [this]()
64 {
65 EndQuasiModal( wxID_OK );
66 },
67 // Escape handler
68 [this]()
69 {
70 EndQuasiModal( wxID_CANCEL );
71 } );
72
73 m_SizerTop->Add( m_chooserPanel, 1, wxEXPAND | wxRIGHT, 5 );
75
76 viewerFpPanel->Show( m_showFpMode );
77
79
81
82 // bSizerBottom shows all buttons to the bottom of window
83 wxBoxSizer* bSizerBottom;
84 bSizerBottom = new wxBoxSizer( wxHORIZONTAL );
85
86 bSizerBottom->Add( 0, 0, 1, 0, 5 ); // Add spacer to right-align buttons
87
88 BITMAP_BUTTON* separator = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap );
89 separator->SetIsSeparator();
90 bSizerBottom->Add( separator, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
91
92 m_grButton3DView = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap );
94 m_grButton3DView->SetBitmap( KiBitmapBundle( BITMAPS::shape_3d ) );
96 bSizerBottom->Add( m_grButton3DView, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
97
98 m_grButtonFpView = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap );
100 m_grButtonFpView->SetBitmap( KiBitmapBundle( BITMAPS::module ) );
102 bSizerBottom->Add( m_grButtonFpView, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
103
104 separator = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap );
105 separator->SetIsSeparator();
106 bSizerBottom->Add( separator, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
107
108 if( aPreselect.IsValid() )
109 m_chooserPanel->SetPreselect( aPreselect );
110
111 SetTitle( GetTitle() + wxString::Format( _( " (%d items loaded)" ),
113
114 wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
115 wxButton* okButton = new wxButton( this, wxID_OK );
116 wxButton* cancelButton = new wxButton( this, wxID_CANCEL );
117 sdbSizer->AddButton( okButton );
118 sdbSizer->AddButton( cancelButton );
119 sdbSizer->Realize();
120
121 bSizerBottom->Add( 20, 0, 0, 0, 5 ); // Add spacer
122 bSizerBottom->Add( sdbSizer, 0, wxEXPAND | wxALL, 5 );
123
124 m_SizerTop->Add( bSizerBottom, 0, wxEXPAND, 5 );
125 SetSizer( m_SizerTop );
126
129
131 // Ensure a reasonable min size that shows all widgets in this dialog
132 SetMinSize( wxSize( 400, 300 ) );
133 Layout();
134
135 // Connect Events
136 m_grButton3DView->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
137 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::on3DviewReq ),
138 nullptr, this );
139 m_grButtonFpView->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
140 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpViewReq ),
141 nullptr, this );
142
143 Connect( FP_SELECTION_EVENT, wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpChanged ),
144 nullptr, this );
145}
146
147
149{
152
153 // Disconnect Events
154 m_grButton3DView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
155 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::on3DviewReq ),
156 nullptr, this );
157 m_grButtonFpView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
158 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpViewReq ),
159 nullptr, this );
160
161 Disconnect( FP_SELECTION_EVENT, wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpChanged ),
162 nullptr, this );
163}
164
165
167{
168 // Create the dummy board used by the 3D canvas
169 m_dummyBoard = new BOARD();
170 m_dummyBoard->SetProject( &m_parent->Prj(), true );
171
172 // This board will only be used to hold a footprint for viewing
173 m_dummyBoard->SetBoardUse( BOARD_USE::FPHOLDER );
174
177 m_boardAdapter.m_IsPreviewer = true; // Force display 3D models, regardless the 3D viewer options
178
179 // Build the 3D canvas
180
182 OGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE::AA_8X ),
185
186 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
187
188 // TODO(JE) use all control options
190
193
194 if( cfg )
195 {
196 // Save the 3D viewer render settings, to restore it after closing the preview
198
199 m_boardAdapter.m_Cfg = cfg;
200
204
205 // Ensure the board body is always shown, and do not use the settings of the 3D viewer
206 cfg->m_Render.show_copper_top = true;
207 cfg->m_Render.show_copper_bottom = true;
208 cfg->m_Render.show_soldermask_top = true;
210 cfg->m_Render.show_solderpaste = true;
211 cfg->m_Render.show_zones = true;
212 cfg->m_Render.show_board_body = true;
214 }
215
216 m_chooserPanel->m_RightPanelSizer->Add( m_preview3DCanvas, 1, wxEXPAND, 5 );
217 m_chooserPanel->m_RightPanel->Layout();
218
221 dummy_bds.SetBoardThickness( parent_bds.GetBoardThickness() );
224 dummy_board_stackup.RemoveAll();
225 dummy_board_stackup.BuildDefaultStackupList( &dummy_bds, 2 );
226}
227
228
229
231{
233}
234
235
236void DIALOG_FOOTPRINT_CHOOSER::onFpChanged( wxCommandEvent& event )
237{
238 m_chooserPanel->GetViewerPanel()->Refresh();
239
240 if( m_showFpMode ) // the 3D viewer is not activated
241 return;
242
243 on3DviewReq( event );
244}
245
246
247void DIALOG_FOOTPRINT_CHOOSER::on3DviewReq( wxCommandEvent& event )
248{
249 m_showFpMode = false;
250
253
255 viewFpPanel->Show( m_showFpMode );
258
261
264 m_chooserPanel->m_RightPanel->Layout();
265 m_chooserPanel->m_RightPanel->Refresh();
266}
267
268
269void DIALOG_FOOTPRINT_CHOOSER::onFpViewReq( wxCommandEvent& event )
270{
271 m_showFpMode = true;
272
275
277 viewFpPanel->Show( m_showFpMode );
279 m_chooserPanel->m_RightPanel->Layout();
280 m_chooserPanel->m_RightPanel->Refresh();
281}
282
283
285{
286 wxLogDebug( wxS( "Entering DIALOG_FOOTPRINT_CHOOSER::TearDownQuasiModal()" ) );
287
288 if( m_chooserPanel )
289 {
291
292 if( viewerWidget )
293 {
294 FOOTPRINT_PREVIEW_PANEL_BASE* previewPanel = viewerWidget->GetPreviewPanel();
295
296 FOOTPRINT_PREVIEW_PANEL* fpPreviewPanel =
297 static_cast<FOOTPRINT_PREVIEW_PANEL*>( previewPanel );
298
299 if( fpPreviewPanel )
300 {
301 wxLogDebug( wxS( "Stopping footprint preview panel drawing." ) );
302 fpPreviewPanel->StopDrawing();
303 }
304 }
305 }
306
308 {
309 // Work around assertion firing when we try to LockCtx on a hidden 3D canvas during dtor
310 wxCloseEvent dummy;
311 m_preview3DCanvas->Show();
313 }
314}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
#define RANGE_SCALE_3D
This defines the range that all coord will have to be rendered.
Definition: board_adapter.h:66
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:42
void SetIsRadioButton()
void Check(bool aCheck=true)
Check the control.
void SetIsSeparator()
Render button as a toolbar separator.
void SetBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is enabled.
bool m_IsPreviewer
true if we're in a 3D preview panel, false for the standard 3D viewer
void SetBoard(BOARD *aBoard) noexcept
Set current board to be rendered.
EDA_3D_VIEWER_SETTINGS * m_Cfg
bool m_MousewheelPanning
Container for design settings for a BOARD object.
void SetEnabledLayers(LSET aMask)
Change the bit-mask of enabled layers to aMask.
int GetBoardThickness() const
The full thickness of the board including copper and masks.
BOARD_STACKUP & GetStackupDescriptor()
void SetBoardThickness(int aThickness)
Manage layers needed to make a physical board.
void RemoveAll()
Delete all items in list and clear the list.
void BuildDefaultStackupList(const BOARD_DESIGN_SETTINGS *aSettings, int aActiveCopperLayersCount=0)
Create a default stackup, according to the current BOARD_DESIGN_SETTINGS settings.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: board.cpp:1003
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition: board.h:302
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
Definition: board.cpp:197
void DeleteAllFootprints()
Remove all footprints from the deque and free the memory associated with them.
Definition: board.cpp:1399
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:895
virtual void TearDownQuasiModal() override
Override this method to perform dialog tear down actions not suitable for object dtor.
LIB_ID GetSelectedLibId() const
To be called after this dialog returns from ShowModal().
EDA_3D_VIEWER_SETTINGS::RENDER_SETTINGS m_initialRender
The 3d viewer Render initial settings (must be saved and restored)
void onFpChanged(wxCommandEvent &event)
DIALOG_FOOTPRINT_CHOOSER(PCB_BASE_FRAME *aParent, const LIB_ID &aPreselect, const wxArrayString &aFootprintHistoryList)
void on3DviewReq(wxCommandEvent &event)
PANEL_FOOTPRINT_CHOOSER * m_chooserPanel
void onFpViewReq(wxCommandEvent &event)
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition: dialog_shim.h:88
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:102
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void EndQuasiModal(int retCode)
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:51
void SetProjectionMode(int aMode)
void SetAnimationEnabled(bool aEnable)
Enable or disable camera animation when switching to a pre-defined view.
void ReloadRequest(BOARD *aBoard=nullptr, S3D_CACHE *aCachePointer=nullptr)
void OnCloseWindow(wxCloseEvent &event)
void SetMovingSpeedMultiplier(int aMultiplier)
Set the camera animation moving speed multiplier option.
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
void StopDrawing()
Prevent the GAL canvas from further drawing until it is recreated or StartDrawing() is called.
Base class for the actual viewer panel.
Panel that renders a single footprint via Cairo GAL, meant to be exported through Kiface.
FOOTPRINT_PREVIEW_PANEL_BASE * GetPreviewPanel()
EDA_ITEM * Clone() const override
Invoke a function on all children.
Definition: footprint.cpp:2075
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
bool IsValid() const
Check if this LID_ID is valid.
Definition: lib_id.h:172
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
static LSET FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
Definition: lset.cpp:782
static LSET BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:789
static const wxGLAttributes GetAttributesList(ANTIALIASING_MODE aAntiAliasingMode, bool aAlpha=false)
Get a list of attributes to pass to wxGLCanvas.
wxWindow * GetFocusTarget() const
FOOTPRINT_PREVIEW_WIDGET * GetViewerPanel() const
void SetPreselect(const LIB_ID &aPreselect)
LIB_ID GetSelectedLibId() const
To be called after this dialog returns from ShowModal().
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:679
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
static S3D_CACHE * Get3DCacheManager(PROJECT *aProject, bool updateProjDir=false)
Return a pointer to an instance of the 3D cache manager.
Definition: project_pcb.cpp:77
T * GetAppSettings(const wxString &aFilename)
Returns a handle to the a given settings by type If the settings have already been loaded,...
#define _(s)
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE
std::vector< FAB_LAYER_COLOR > dummy