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 wxBoxSizer* m_SizerTop = new wxBoxSizer( wxVERTICAL );
54 m_chooserPanel = new PANEL_FOOTPRINT_CHOOSER( aParent, this, aFootprintHistoryList,
55 // Filter
56 []( LIB_TREE_NODE& aNode ) -> bool
57 {
58 return true;
59 },
60 // Accept handler
61 [this]()
62 {
63 EndModal( wxID_OK );
64 },
65 // Escape handler
66 [this]()
67 {
68 EndModal( wxID_CANCEL );
69 } );
70
71 m_SizerTop->Add( m_chooserPanel, 1, wxEXPAND, 5 );
73
74 viewerFpPanel->Show( m_showFpMode );
75
77
79
80 wxBoxSizer* bSizerBottom;
81 bSizerBottom = new wxBoxSizer( wxHORIZONTAL );
82
83 bSizerBottom->Add( 0, 0, 1, 0, 5 ); // Add spacer to right-align buttons
84
85 BITMAP_BUTTON* separator = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap );
86 separator->SetIsSeparator();
87 bSizerBottom->Add( separator, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
88
89 m_grButton3DView = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap );
91 m_grButton3DView->SetBitmap( KiBitmapBundle( BITMAPS::shape_3d ) );
93 bSizerBottom->Add( m_grButton3DView, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
94
95 m_grButtonFpView = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap );
97 m_grButtonFpView->SetBitmap( KiBitmapBundle( BITMAPS::module ) );
99 bSizerBottom->Add( m_grButtonFpView, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
100
101 separator = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap );
102 separator->SetIsSeparator();
103 bSizerBottom->Add( separator, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
104
105 if( aPreselect.IsValid() )
106 m_chooserPanel->SetPreselect( aPreselect );
107
108 SetTitle( GetTitle() + wxString::Format( _( " (%d items loaded)" ),
110
111 wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
112 wxButton* okButton = new wxButton( this, wxID_OK );
113 wxButton* cancelButton = new wxButton( this, wxID_CANCEL );
114 sdbSizer->AddButton( okButton );
115 sdbSizer->AddButton( cancelButton );
116 sdbSizer->Realize();
117
118 bSizerBottom->Add( 20, 0, 0, 0, 5 ); // Add spacer
119 bSizerBottom->Add( sdbSizer, 0, wxEXPAND | wxALL, 5 );
120
121 m_SizerTop->Add( bSizerBottom, 0, wxEXPAND, 5 );
122 SetSizer( m_SizerTop );
123
126
128 Layout();
129
130 // Connect Events
131 m_grButton3DView->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
132 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::on3DviewReq ),
133 nullptr, this );
134 m_grButtonFpView->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
135 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpViewReq ),
136 nullptr, this );
137
138 Connect( FP_SELECTION_EVENT, wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpChanged ),
139 nullptr, this );
140}
141
142
144{
147
148 // Disconnect Events
149 m_grButton3DView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
150 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::on3DviewReq ),
151 nullptr, this );
152 m_grButtonFpView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
153 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpViewReq ),
154 nullptr, this );
155
156 Disconnect( FP_SELECTION_EVENT, wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpChanged ),
157 nullptr, this );
158}
159
160
162{
163 // Create the dummy board used by the 3D canvas
164 m_dummyBoard = new BOARD();
165 m_dummyBoard->SetProject( &m_parent->Prj(), true );
166
167 // This board will only be used to hold a footprint for viewing
168 m_dummyBoard->SetBoardUse( BOARD_USE::FPHOLDER );
169
172 m_boardAdapter.m_IsPreviewer = true; // Force display 3D models, regardless the 3D viewer options
173
174 // Build the 3D canvas
175
177 OGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE::AA_8X ),
180
181 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
182
183 // TODO(JE) use all control options
185
187
188 if( cfg )
189 {
190 // Save the 3D viewer render settings, to restore it after closing the preview
192
193 m_boardAdapter.m_Cfg = cfg;
194
198
199 // Ensure the board body is always shown, and do not use the settings of the 3D viewer
200 cfg->m_Render.show_copper_top = true;
201 cfg->m_Render.show_copper_bottom = true;
202 cfg->m_Render.show_soldermask_top = true;
204 cfg->m_Render.show_solderpaste = true;
205 cfg->m_Render.show_zones = true;
206 cfg->m_Render.show_board_body = true;
207 }
208
209 m_chooserPanel->m_RightPanelSizer->Add( m_preview3DCanvas, 1, wxEXPAND, 5 );
210 m_chooserPanel->m_RightPanel->Layout();
211
214 dummy_bds.SetBoardThickness( parent_bds.GetBoardThickness() );
217 dummy_board_stackup.RemoveAll();
218 dummy_board_stackup.BuildDefaultStackupList( &dummy_bds, 2 );
219}
220
221
222
224{
226}
227
228
229void DIALOG_FOOTPRINT_CHOOSER::onFpChanged( wxCommandEvent& event )
230{
231 if( m_showFpMode ) // the 3D viewer is not activated
232 return;
233
234 on3DviewReq( event );
235}
236
237
238void DIALOG_FOOTPRINT_CHOOSER::on3DviewReq( wxCommandEvent& event )
239{
240 m_showFpMode = false;
241
244
246 viewFpPanel->Show( m_showFpMode );
249
252
255 m_chooserPanel->m_RightPanel->Layout();
256 m_chooserPanel->m_RightPanel->Refresh();
257}
258
259
260void DIALOG_FOOTPRINT_CHOOSER::onFpViewReq( wxCommandEvent& event )
261{
262 m_showFpMode = true;
263
266
268 viewFpPanel->Show( m_showFpMode );
270 m_chooserPanel->m_RightPanel->Layout();
271 m_chooserPanel->m_RightPanel->Refresh();
272}
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:289
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: board.cpp:982
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition: board.h:301
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
Definition: board.cpp:196
void DeleteAllFootprints()
Remove all footprints from the deque and free the memory associated with them.
Definition: board.cpp:1377
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:874
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={})
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:49
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 SetMovingSpeedMultiplier(int aMultiplier)
Set the camera animation moving speed multiplier option.
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
EDA_ITEM * Clone() const override
Invoke a function on all children.
Definition: footprint.cpp:2032
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:838
static LSET BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:845
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:678
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()
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:1059
see class PGM_BASE