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>
32#include <board.h>
33#include <project_pcb.h>
35#include <pgm_base.h>
40
41
43 const LIB_ID& aPreselect,
44 const wxArrayString& aFootprintHistoryList ) :
45 DIALOG_SHIM( aParent, wxID_ANY, _( "Choose Footprint" ), wxDefaultPosition, wxDefaultSize,
46 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
47 m_boardAdapter(),
48 m_currentCamera( m_trackBallCamera ),
49 m_trackBallCamera( 2 * RANGE_SCALE_3D )
50{
51 m_parent = aParent;
52 m_showFpMode = true;
53
54 wxBoxSizer* m_SizerTop = new wxBoxSizer( wxVERTICAL );
55 m_chooserPanel = new PANEL_FOOTPRINT_CHOOSER( aParent, this, aFootprintHistoryList,
56 // Filter
57 []( LIB_TREE_NODE& aNode ) -> bool
58 {
59 return true;
60 },
61 // Accept handler
62 [this]()
63 {
64 EndModal( wxID_OK );
65 },
66 // Escape handler
67 [this]()
68 {
69 EndModal( wxID_CANCEL );
70 } );
71
72 m_SizerTop->Add( m_chooserPanel, 1, wxEXPAND, 5 );
74
75 viewerFpPanel->Show( m_showFpMode );
76
78
80
81 wxBoxSizer* bSizerBottom;
82 bSizerBottom = new wxBoxSizer( wxHORIZONTAL );
83
84 bSizerBottom->Add( 0, 0, 1, 0, 5 ); // Add spacer to right-align buttons
85
86 BITMAP_BUTTON* separator = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap );
87 separator->SetIsSeparator();
88 bSizerBottom->Add( separator, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
89
90 m_grButton3DView = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap );
92 m_grButton3DView->SetBitmap( KiBitmapBundle( BITMAPS::shape_3d ) );
94 bSizerBottom->Add( m_grButton3DView, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
95
96 m_grButtonFpView = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap );
98 m_grButtonFpView->SetBitmap( KiBitmapBundle( BITMAPS::module ) );
100 bSizerBottom->Add( m_grButtonFpView, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
101
102 separator = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap );
103 separator->SetIsSeparator();
104 bSizerBottom->Add( separator, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
105
106 if( aPreselect.IsValid() )
107 m_chooserPanel->SetPreselect( aPreselect );
108
109 SetTitle( GetTitle() + wxString::Format( _( " (%d items loaded)" ),
111
112 wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
113 wxButton* okButton = new wxButton( this, wxID_OK );
114 wxButton* cancelButton = new wxButton( this, wxID_CANCEL );
115 sdbSizer->AddButton( okButton );
116 sdbSizer->AddButton( cancelButton );
117 sdbSizer->Realize();
118
119 bSizerBottom->Add( 20, 0, 0, 0, 5 ); // Add spacer
120 bSizerBottom->Add( sdbSizer, 0, wxEXPAND | wxALL, 5 );
121
122 m_SizerTop->Add( bSizerBottom, 0, wxEXPAND, 5 );
123 SetSizer( m_SizerTop );
124
127
129 Layout();
130
131 // Connect Events
132 m_grButton3DView->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
133 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::on3DviewReq ),
134 NULL, this );
135 m_grButtonFpView->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
136 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpViewReq ),
137 NULL, this );
138
139 this->Connect( FP_SELECTION_EVENT, // custom event fired by a PANEL_FOOTPRINT_CHOOSER
140 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpChanged ), NULL, this );
141}
142
143
145{
146 // Disconnect Events
147 m_grButton3DView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
148 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::on3DviewReq ), NULL, this );
149 m_grButtonFpView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
150 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpViewReq ), NULL, this );
151
152 this->Disconnect( FP_SELECTION_EVENT,
153 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpChanged ), NULL, this );
154}
155
156
158{
159 // Create the dummy board used by the 3D canvas
160 m_dummyBoard = new BOARD();
161 m_dummyBoard->SetProject( &m_parent->Prj(), true );
162
163 // This board will only be used to hold a footprint for viewing
164 m_dummyBoard->SetBoardUse( BOARD_USE::FPHOLDER );
165
168 m_boardAdapter.m_IsPreviewer = true; // Force display 3D models, regardless the 3D viewer options
170 m_boardAdapter.m_Cfg = cfg;
171
172 // Build the 3D canvas
173
175 OGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE::AA_8X ),
178
179 m_chooserPanel->m_RightPanelSizer->Add( m_preview3DCanvas, 1, wxEXPAND, 5 );
180 m_chooserPanel->m_RightPanel->Layout();
181
184 dummy_bds.SetBoardThickness( parent_bds.GetBoardThickness() );
187 dummy_board_stackup.RemoveAll();
188 dummy_board_stackup.BuildDefaultStackupList( &dummy_bds, 2 );
189}
190
191
192
194{
196}
197
198
199void DIALOG_FOOTPRINT_CHOOSER::onFpChanged( wxCommandEvent& event )
200{
201 if( m_showFpMode ) // the 3D viewer is not activated
202 return;
203
204 on3DviewReq( event );
205}
206
207
208void DIALOG_FOOTPRINT_CHOOSER::on3DviewReq( wxCommandEvent& event )
209{
210 m_showFpMode = false;
211
214
216 viewFpPanel->Show( m_showFpMode );
219
222
225 m_chooserPanel->m_RightPanel->Layout();
226 m_chooserPanel->m_RightPanel->Refresh();
227}
228
229
230void DIALOG_FOOTPRINT_CHOOSER::onFpViewReq( wxCommandEvent& event )
231{
232 m_showFpMode = true;
233
236
238 viewFpPanel->Show( m_showFpMode );
240 m_chooserPanel->m_RightPanel->Layout();
241 m_chooserPanel->m_RightPanel->Refresh();
242}
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
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:282
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: board.cpp:882
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition: board.h:294
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
Definition: board.cpp:186
void DeleteAllFootprints()
Remove all footprints from the deque and free the memory associated with them.
Definition: board.cpp:1277
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:794
LIB_ID GetSelectedLibId() const
To be called after this dialog returns from ShowModal().
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 ReloadRequest(BOARD *aBoard=nullptr, S3D_CACHE *aCachePointer=nullptr)
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:2004
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:985
static LSET BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:992
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 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)
Declaration of the cogl_att_list class.
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE