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 <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 NULL, this );
134 m_grButtonFpView->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
135 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpViewReq ),
136 NULL, this );
137
138 this->Connect( FP_SELECTION_EVENT, // custom event fired by a PANEL_FOOTPRINT_CHOOSER
139 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpChanged ), NULL, this );
140}
141
142
144{
145 // Disconnect Events
146 m_grButton3DView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
147 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::on3DviewReq ), NULL, this );
148 m_grButtonFpView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
149 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpViewReq ), NULL, this );
150
151 this->Disconnect( FP_SELECTION_EVENT,
152 wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpChanged ), NULL, this );
153}
154
155
157{
158 // Create the dummy board used by the 3D canvas
159 m_dummyBoard = new BOARD();
160 m_dummyBoard->SetProject( &m_parent->Prj(), true );
161
162 // This board will only be used to hold a footprint for viewing
163 m_dummyBoard->SetBoardUse( BOARD_USE::FPHOLDER );
164
167 m_boardAdapter.m_IsPreviewer = true; // Force display 3D models, regardless the 3D viewer options
169 m_boardAdapter.m_Cfg = cfg;
170
171 // Build the 3D canvas
172
174 OGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE::AA_8X ),
177
178 m_chooserPanel->m_RightPanelSizer->Add( m_preview3DCanvas, 1, wxEXPAND, 5 );
179 m_chooserPanel->m_RightPanel->Layout();
180
183 dummy_bds.SetBoardThickness( parent_bds.GetBoardThickness() );
186 dummy_board_stackup.RemoveAll();
187 dummy_board_stackup.BuildDefaultStackupList( &dummy_bds, 2 );
188}
189
190
191
193{
195}
196
197
198void DIALOG_FOOTPRINT_CHOOSER::onFpChanged( wxCommandEvent& event )
199{
200 if( m_showFpMode ) // the 3D viewer is not activated
201 return;
202
203 on3DviewReq( event );
204}
205
206
207void DIALOG_FOOTPRINT_CHOOSER::on3DviewReq( wxCommandEvent& event )
208{
209 m_showFpMode = false;
210
213
215 viewFpPanel->Show( m_showFpMode );
218
221
224 m_chooserPanel->m_RightPanel->Layout();
225 m_chooserPanel->m_RightPanel->Refresh();
226}
227
228
229void DIALOG_FOOTPRINT_CHOOSER::onFpViewReq( wxCommandEvent& event )
230{
231 m_showFpMode = true;
232
235
237 viewFpPanel->Show( m_showFpMode );
239 m_chooserPanel->m_RightPanel->Layout();
240 m_chooserPanel->m_RightPanel->Refresh();
241}
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:190
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:797
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:84
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:98
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:1986
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