KiCad PCB EDA Suite
FOOTPRINT_SELECT_WIDGET Class Reference

#include <footprint_select_widget.h>

Inheritance diagram for FOOTPRINT_SELECT_WIDGET:

Public Member Functions

 FOOTPRINT_SELECT_WIDGET (EDA_DRAW_FRAME *aFrame, wxWindow *aParent, FOOTPRINT_LIST *aFpList, bool aUpdate=true, int aMaxItems=400)
 Construct a footprint selector widget. More...
 
virtual ~FOOTPRINT_SELECT_WIDGET ()
 
void Load (KIWAY &aKiway, PROJECT &aProject)
 Start loading. More...
 
void ClearFilters ()
 Clear all filters. More...
 
void FilterByPinCount (int aPinCount)
 Filter by pin count. More...
 
void FilterByFootprintFilters (const wxArrayString &aFilters, bool aZeroFilters)
 Filter by footprint filter list. More...
 
void SetDefaultFootprint (const wxString &aFp)
 Set the default footprint for a part. More...
 
bool UpdateList ()
 Update the contents of the list to match the filters. More...
 
void SelectDefault ()
 Set current selection to the default footprint. More...
 
virtual bool Enable (bool aEnable=true) override
 Enable or disable the control for input. More...
 

Private Member Functions

void OnComboBox (wxCommandEvent &aEvent)
 

Private Attributes

FOOTPRINT_CHOICEm_fp_sel_ctrl
 
wxSizer * m_sizer
 
bool m_update
 
int m_max_items
 
wxString m_default_footprint
 
FOOTPRINT_LISTm_fp_list
 
FOOTPRINT_FILTER m_fp_filter
 
bool m_zero_filter
 

Detailed Description

Definition at line 39 of file footprint_select_widget.h.

Constructor & Destructor Documentation

◆ FOOTPRINT_SELECT_WIDGET()

FOOTPRINT_SELECT_WIDGET::FOOTPRINT_SELECT_WIDGET ( EDA_DRAW_FRAME aFrame,
wxWindow *  aParent,
FOOTPRINT_LIST aFpList,
bool  aUpdate = true,
int  aMaxItems = 400 
)

Construct a footprint selector widget.

This requires references to an external footprint loader, and an external unique_ptr-to-FOOTPRINT_LIST. The latter will be populated with a FOOTPRINT_LIST instance the first time Load() is called.

The reason for this is that footprint loading tends to be very expensive, especially when using online libraries. The caller is expected to keep these objects around (e.g. they may be statics on the dialog this FOOTPRINT_SELECT_WIDGET is created in) so footprints do not have to be loaded more than once.

Parameters
aParent- parent window
aFpList- FOOTPRINT_LIST container
aUpdate- whether to call UpdateList() automatically when finished loading
aMaxItems- maximum number of filter items to display, in addition to Default and Other

Definition at line 35 of file footprint_select_widget.cpp.

37 :
38 wxPanel( aParent ),
39 m_update( aUpdate ),
40 m_max_items( aMaxItems ),
41 m_fp_list( aFpList )
42{
43 m_zero_filter = true;
44 m_sizer = new wxBoxSizer( wxVERTICAL );
45 m_fp_sel_ctrl = new FOOTPRINT_CHOICE( this, wxID_ANY );
46 m_sizer->Add( m_fp_sel_ctrl, 1, wxEXPAND, 5 );
47
48 SetSizer( m_sizer );
49 Layout();
50 m_sizer->Fit( this );
51
52 m_fp_sel_ctrl->Bind( wxEVT_COMBOBOX, &FOOTPRINT_SELECT_WIDGET::OnComboBox, this );
53}
Customized combo box for footprint selection.
void OnComboBox(wxCommandEvent &aEvent)

References m_fp_sel_ctrl, m_sizer, m_zero_filter, and OnComboBox().

◆ ~FOOTPRINT_SELECT_WIDGET()

virtual FOOTPRINT_SELECT_WIDGET::~FOOTPRINT_SELECT_WIDGET ( )
inlinevirtual

Definition at line 64 of file footprint_select_widget.h.

65 {
66 }

Member Function Documentation

◆ ClearFilters()

void FOOTPRINT_SELECT_WIDGET::ClearFilters ( )

Clear all filters.

Does not update the list.

Definition at line 99 of file footprint_select_widget.cpp.

100{
102 m_default_footprint.Clear();
103 m_zero_filter = false;
104}
void ClearFilters()
Clear all filter criteria.

References FOOTPRINT_FILTER::ClearFilters(), m_default_footprint, m_fp_filter, and m_zero_filter.

Referenced by DIALOG_CHOOSE_SYMBOL::PopulateFootprintSelector().

◆ Enable()

bool FOOTPRINT_SELECT_WIDGET::Enable ( bool  aEnable = true)
overridevirtual

Enable or disable the control for input.

Definition at line 170 of file footprint_select_widget.cpp.

171{
172 return m_fp_sel_ctrl->Enable( aEnable );
173}

References m_fp_sel_ctrl.

Referenced by DIALOG_CHOOSE_SYMBOL::PopulateFootprintSelector().

◆ FilterByFootprintFilters()

void FOOTPRINT_SELECT_WIDGET::FilterByFootprintFilters ( const wxArrayString &  aFilters,
bool  aZeroFilters 
)

Filter by footprint filter list.

Does not update the list.

Parameters
aFiltersis a wxArrayString of strings used to filter the list of available footprints (can be empty). The final fp list is the list of footprint names matching at least one filtering string. A filtering string is something like sm0402 or DIP*
aZeroFilters- if true, zero filters = zero footprints. If false, zero filters = not filtering.

Definition at line 113 of file footprint_select_widget.cpp.

115{
116 m_zero_filter = ( aZeroFilters && aFilters.size() == 0 );
118}
void FilterByFootprintFilters(const wxArrayString &aFilters)
Set a list of footprint filters to filter by.

References FOOTPRINT_FILTER::FilterByFootprintFilters(), m_fp_filter, and m_zero_filter.

Referenced by DIALOG_CHOOSE_SYMBOL::PopulateFootprintSelector().

◆ FilterByPinCount()

void FOOTPRINT_SELECT_WIDGET::FilterByPinCount ( int  aPinCount)

Filter by pin count.

Does not update the list.

Definition at line 107 of file footprint_select_widget.cpp.

108{
109 m_fp_filter.FilterByPinCount( aPinCount );
110}
void FilterByPinCount(int aPinCount)
Set a pin count to filter by.

References FOOTPRINT_FILTER::FilterByPinCount(), and m_fp_filter.

Referenced by DIALOG_CHOOSE_SYMBOL::PopulateFootprintSelector().

◆ Load()

void FOOTPRINT_SELECT_WIDGET::Load ( KIWAY aKiway,
PROJECT aProject 
)

Start loading.

This function returns immediately; footprints will continue to load in the background.

Parameters
aKiway- active kiway instance. This is cached for use when "Other" is selected.
aProject- current project

Definition at line 56 of file footprint_select_widget.cpp.

57{
58 try
59 {
61
62 if( m_fp_list->GetCount() == 0 )
63 {
64 // If the fp-info-cache is empty (or, more likely, hasn't been created in a new
65 // project yet), load footprints the hard way.
66 FP_LIB_TABLE* fpTable = aProject.PcbFootprintLibs( aKiway );
67 static_cast<FOOTPRINT_LIST_IMPL*>( m_fp_list )->ReadFootprintFiles( fpTable );
68 }
69
71 }
72 catch( ... )
73 {
74 // no footprint libraries available
75 }
76
77 if( m_update )
78 UpdateList();
79}
void SetList(FOOTPRINT_LIST &aList)
Set the list to filter.
unsigned GetCount() const
static FOOTPRINT_LIST * GetInstance(KIWAY &aKiway)
Factory function to return a FOOTPRINT_LIST via Kiway.
bool UpdateList()
Update the contents of the list to match the filters.
virtual FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:277

References FOOTPRINT_LIST::GetCount(), FOOTPRINT_LIST::GetInstance(), m_fp_filter, m_fp_list, m_update, PROJECT::PcbFootprintLibs(), FOOTPRINT_FILTER::SetList(), and UpdateList().

Referenced by DIALOG_CHOOSE_SYMBOL::OnInitDialog().

◆ OnComboBox()

void FOOTPRINT_SELECT_WIDGET::OnComboBox ( wxCommandEvent &  aEvent)
private

Definition at line 82 of file footprint_select_widget.cpp.

83{
84 wxCommandEvent evt( EVT_FOOTPRINT_SELECTED );
85 int sel = m_fp_sel_ctrl->GetSelection();
86
87 if( sel == wxNOT_FOUND )
88 return;
89
90 wxStringClientData* clientdata =
91 static_cast<wxStringClientData*>( m_fp_sel_ctrl->GetClientObject( sel ) );
92 wxASSERT( clientdata );
93
94 evt.SetString( clientdata->GetData() );
95 wxPostEvent( this, evt );
96}

References m_fp_sel_ctrl.

Referenced by FOOTPRINT_SELECT_WIDGET().

◆ SelectDefault()

void FOOTPRINT_SELECT_WIDGET::SelectDefault ( )

Set current selection to the default footprint.

Definition at line 164 of file footprint_select_widget.cpp.

165{
166 m_fp_sel_ctrl->SetSelection( 0 );
167}

References m_fp_sel_ctrl.

Referenced by UpdateList().

◆ SetDefaultFootprint()

void FOOTPRINT_SELECT_WIDGET::SetDefaultFootprint ( const wxString &  aFp)

Set the default footprint for a part.

This will be listed at the top. May be an empty string.

Definition at line 121 of file footprint_select_widget.cpp.

122{
124}

References m_default_footprint.

Referenced by DIALOG_CHOOSE_SYMBOL::PopulateFootprintSelector().

◆ UpdateList()

bool FOOTPRINT_SELECT_WIDGET::UpdateList ( )

Update the contents of the list to match the filters.

Has no effect if the footprint list has not been loaded yet. The "default" footprint will be selected.

Returns
true if the footprint list has been loaded (and the list was updated)

Definition at line 127 of file footprint_select_widget.cpp.

128{
129 int n_items = 0;
130
131 if( !m_fp_list )
132 return false;
133
134 wxWindowUpdateLocker lock( m_fp_sel_ctrl );
135 m_fp_sel_ctrl->Clear();
136
137 // Be careful adding items! "Default" must occupy POS_DEFAULT,
138 // "Other" must occupy POS_OTHER, and the separator must occupy POS_SEPARATOR.
139
140 m_fp_sel_ctrl->Append( m_default_footprint.IsEmpty() ?
141 _( "No default footprint" ) :
142 "[" + _( "Default" ) + "] " + m_default_footprint,
143 new wxStringClientData( m_default_footprint ) );
144
145 if( !m_zero_filter )
146 {
147 for( FOOTPRINT_INFO& fpinfo : m_fp_filter )
148 {
149 wxString display_name( fpinfo.GetLibNickname() + ":" + fpinfo.GetFootprintName() );
150
151 m_fp_sel_ctrl->Append( display_name, new wxStringClientData( display_name ) );
152 ++n_items;
153
154 if( n_items >= m_max_items )
155 break;
156 }
157 }
158
160 return true;
161}
void SelectDefault()
Set current selection to the default footprint.
#define _(s)

References _, m_default_footprint, m_fp_filter, m_fp_list, m_fp_sel_ctrl, m_max_items, m_zero_filter, and SelectDefault().

Referenced by Load(), and DIALOG_CHOOSE_SYMBOL::PopulateFootprintSelector().

Member Data Documentation

◆ m_default_footprint

wxString FOOTPRINT_SELECT_WIDGET::m_default_footprint
private

Definition at line 131 of file footprint_select_widget.h.

Referenced by ClearFilters(), SetDefaultFootprint(), and UpdateList().

◆ m_fp_filter

FOOTPRINT_FILTER FOOTPRINT_SELECT_WIDGET::m_fp_filter
private

◆ m_fp_list

FOOTPRINT_LIST* FOOTPRINT_SELECT_WIDGET::m_fp_list
private

Definition at line 133 of file footprint_select_widget.h.

Referenced by Load(), and UpdateList().

◆ m_fp_sel_ctrl

FOOTPRINT_CHOICE* FOOTPRINT_SELECT_WIDGET::m_fp_sel_ctrl
private

◆ m_max_items

int FOOTPRINT_SELECT_WIDGET::m_max_items
private

Definition at line 130 of file footprint_select_widget.h.

Referenced by UpdateList().

◆ m_sizer

wxSizer* FOOTPRINT_SELECT_WIDGET::m_sizer
private

Definition at line 127 of file footprint_select_widget.h.

Referenced by FOOTPRINT_SELECT_WIDGET().

◆ m_update

bool FOOTPRINT_SELECT_WIDGET::m_update
private

Definition at line 129 of file footprint_select_widget.h.

Referenced by Load().

◆ m_zero_filter

bool FOOTPRINT_SELECT_WIDGET::m_zero_filter
private

The documentation for this class was generated from the following files: