KiCad PCB EDA Suite
Loading...
Searching...
No Matches
footprint_select_widget.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <eda_draw_frame.h>
21#include <kiway.h>
22#include <kiway_player.h>
23#include <project.h>
24#include <project_pcb.h>
28#include <progress_reporter.h>
29#include <footprint_info_impl.h>
30#include <wx/wupdlock.h>
31
32
33extern FOOTPRINT_LIST_IMPL GFootprintList; // KIFACE scope.
34
35wxDEFINE_EVENT( EVT_FOOTPRINT_SELECTED, wxCommandEvent );
36
38 FOOTPRINT_LIST* aFpList, bool aUpdate,
39 int aMaxItems ) :
40 wxPanel( aParent ),
41 m_update( aUpdate ),
42 m_max_items( aMaxItems ),
43 m_fp_list( aFpList ),
44 m_frame( aFrame )
45{
46 m_zero_filter = true;
47 m_sizer = new wxBoxSizer( wxVERTICAL );
48 m_fp_sel_ctrl = new FOOTPRINT_CHOICE( this, wxID_ANY );
49 m_sizer->Add( m_fp_sel_ctrl, 1, wxEXPAND, 5 );
50
51 SetSizer( m_sizer );
52 Layout();
53 m_sizer->Fit( this );
54
55 m_fp_sel_ctrl->Bind( wxEVT_COMBOBOX, &FOOTPRINT_SELECT_WIDGET::OnComboBox, this );
56}
57
58
60{
62 wxCHECK_MSG( m_fp_list, /* void */, "Failed to get the footprint list from the KiWay" );
63
64 if( m_fp_list->GetCount() == 0 )
65 {
66 WX_PROGRESS_REPORTER progressReporter( m_frame, _( "Load Footprint Libraries" ), 1,
68
69 // If the fp-info-cache is empty (or, more likely, hasn't been created in a new
70 // project yet), load footprints the hard way.
71 FOOTPRINT_LIBRARY_ADAPTER* footprints = aProject.FootprintLibAdapter( aKiway );
72 FOOTPRINT_LIST_IMPL& fpList = static_cast<FOOTPRINT_LIST_IMPL&>( *m_fp_list );
73
74 fpList.ReadFootprintFiles( footprints, nullptr, &progressReporter );
75 }
76
77 m_fp_filter.SetList( *m_fp_list );
78
79 if( m_update )
80 UpdateList();
81}
82
83
84void FOOTPRINT_SELECT_WIDGET::OnComboBox( wxCommandEvent& aEvent )
85{
86 wxCommandEvent evt( EVT_FOOTPRINT_SELECTED );
87 int sel = m_fp_sel_ctrl->GetSelection();
88
89 if( sel == wxNOT_FOUND )
90 return;
91
92 wxStringClientData* clientdata =
93 static_cast<wxStringClientData*>( m_fp_sel_ctrl->GetClientObject( sel ) );
94 wxASSERT( clientdata );
95
96 evt.SetString( clientdata->GetData() );
97 wxPostEvent( this, evt );
98}
99
100
102{
103 m_fp_filter.ClearFilters();
104 m_default_footprint.Clear();
105 m_zero_filter = false;
106}
107
108
110{
111 m_fp_filter.FilterByPinCount( aPinCount );
112}
113
114
115void FOOTPRINT_SELECT_WIDGET::FilterByFootprintFilters( wxArrayString const& aFilters,
116 bool aZeroFilters )
117{
118 m_zero_filter = ( aZeroFilters && aFilters.size() == 0 );
119 m_fp_filter.FilterByFootprintFilters( aFilters );
120}
121
122
124{
126}
127
128
130{
131 int n_items = 0;
132
133 if( !m_fp_list )
134 return false;
135
136 wxWindowUpdateLocker lock( m_fp_sel_ctrl );
137 m_fp_sel_ctrl->Clear();
138
139 // Be careful adding items! "Default" must occupy POS_DEFAULT,
140 // "Other" must occupy POS_OTHER, and the separator must occupy POS_SEPARATOR.
141 m_fp_sel_ctrl->Append( m_default_footprint.IsEmpty() ?
142 _( "No default footprint" ) :
143 wxS( "[" ) + _( "Default" ) + wxS( "] " ) + m_default_footprint,
144 new wxStringClientData( m_default_footprint ) );
145
146 if( !m_zero_filter )
147 {
148 for( FOOTPRINT_INFO& fpinfo : m_fp_filter )
149 {
150 wxString display_name( fpinfo.GetLibNickname() + wxS( ":" ) +
151 fpinfo.GetFootprintName() );
152
153 m_fp_sel_ctrl->Append( display_name, new wxStringClientData( display_name ) );
154 ++n_items;
155
156 if( n_items >= m_max_items )
157 break;
158 }
159 }
160
162 return true;
163}
164
165
167{
168 m_fp_sel_ctrl->SetSelection( 0 );
169}
170
171
173{
174 return m_fp_sel_ctrl->Enable( aEnable );
175}
The base class for create windows for drawing purpose.
Customized combo box for footprint selection.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
bool ReadFootprintFiles(FOOTPRINT_LIBRARY_ADAPTER *aAdapter, const wxString *aNickname=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr) override
Read all the footprints provided by the combination of aTable and aNickname.
Holds a list of FOOTPRINT_INFO objects, along with a list of IO_ERRORs or PARSE_ERRORs that were thro...
static FOOTPRINT_LIST * GetInstance(KIWAY &aKiway)
Factory function to return a FOOTPRINT_LIST via Kiway.
virtual bool Enable(bool aEnable=true) override
Enable or disable the control for input.
void OnComboBox(wxCommandEvent &aEvent)
void FilterByFootprintFilters(const wxArrayString &aFilters, bool aZeroFilters)
Filter by footprint filter list.
void SetDefaultFootprint(const wxString &aFp)
Set the default footprint for a part.
FOOTPRINT_SELECT_WIDGET(EDA_DRAW_FRAME *aFrame, wxWindow *aParent, FOOTPRINT_LIST *aFpList, bool aUpdate=true, int aMaxItems=400)
Construct a footprint selector widget.
void FilterByPinCount(int aPinCount)
Filter by pin count.
void SelectDefault()
Set current selection to the default footprint.
bool UpdateList()
Update the contents of the list to match the filters.
void ClearFilters()
Clear all filters.
void Load(KIWAY &aKiway, PROJECT &aProject)
Start loading.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:292
Container for project specific data.
Definition project.h:65
virtual FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(KIWAY &aKiway)
Fetches the footprint library adapter from the PCB editor instance.
Definition project.cpp:410
Multi-thread safe progress reporter dialog, intended for use of tasks that parallel reporting back of...
#define _(s)
wxDEFINE_EVENT(EVT_FOOTPRINT_SELECTED, wxCommandEvent)
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition cvpcb.cpp:138
#define PR_CAN_ABORT