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 (wxArrayString const &aFilters, bool aZeroFilters)
 Filter by footprint filter list. More...
 
void SetDefaultFootprint (wxString const &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

KIWAYm_kiway
 
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 40 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 34 of file footprint_select_widget.cpp.

36  :
37  wxPanel( aParent ),
38  m_kiway( nullptr ),
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 65 of file footprint_select_widget.h.

66  {
67  }

Member Function Documentation

◆ ClearFilters()

void FOOTPRINT_SELECT_WIDGET::ClearFilters ( )

Clear all filters.

Does not update the list.

Definition at line 92 of file footprint_select_widget.cpp.

93 {
95  m_default_footprint.Clear();
96  m_zero_filter = false;
97 }
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 163 of file footprint_select_widget.cpp.

164 {
165  return m_fp_sel_ctrl->Enable( aEnable );
166 }

References m_fp_sel_ctrl.

Referenced by DIALOG_CHOOSE_SYMBOL::PopulateFootprintSelector().

◆ FilterByFootprintFilters()

void FOOTPRINT_SELECT_WIDGET::FilterByFootprintFilters ( wxArrayString const &  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 106 of file footprint_select_widget.cpp.

108 {
109  m_zero_filter = ( aZeroFilters && aFilters.size() == 0 );
111 }
void FilterByFootprintFilters(wxArrayString const &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 100 of file footprint_select_widget.cpp.

101 {
102  m_fp_filter.FilterByPinCount( aPinCount );
103 }
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  m_kiway = &aKiway;
59 
60  try
61  {
64  }
65  catch( ... )
66  {
67  // no footprint libraries available
68  }
69 
70  if( m_update )
71  UpdateList();
72 }
void SetList(FOOTPRINT_LIST &aList)
Set the list to filter.
bool UpdateList()
Update the contents of the list to match the filters.
static FOOTPRINT_LIST * GetInstance(KIWAY &aKiway)
Factory function to return a FOOTPRINT_LIST via Kiway.

References FOOTPRINT_LIST::GetInstance(), m_fp_filter, m_fp_list, m_kiway, m_update, FOOTPRINT_FILTER::SetList(), and UpdateList().

Referenced by DIALOG_CHOOSE_SYMBOL::OnInitDialog().

◆ OnComboBox()

void FOOTPRINT_SELECT_WIDGET::OnComboBox ( wxCommandEvent &  aEvent)
private

Definition at line 75 of file footprint_select_widget.cpp.

76 {
77  wxCommandEvent evt( EVT_FOOTPRINT_SELECTED );
78  int sel = m_fp_sel_ctrl->GetSelection();
79 
80  if( sel == wxNOT_FOUND )
81  return;
82 
83  wxStringClientData* clientdata =
84  static_cast<wxStringClientData*>( m_fp_sel_ctrl->GetClientObject( sel ) );
85  wxASSERT( clientdata );
86 
87  evt.SetString( clientdata->GetData() );
88  wxPostEvent( this, evt );
89 }

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 157 of file footprint_select_widget.cpp.

158 {
159  m_fp_sel_ctrl->SetSelection( 0 );
160 }

References m_fp_sel_ctrl.

Referenced by UpdateList().

◆ SetDefaultFootprint()

void FOOTPRINT_SELECT_WIDGET::SetDefaultFootprint ( wxString const &  aFp)

Set the default footprint for a part.

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

Definition at line 114 of file footprint_select_widget.cpp.

115 {
116  m_default_footprint = aFp;
117 }

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 120 of file footprint_select_widget.cpp.

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

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 133 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 135 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_kiway

KIWAY* FOOTPRINT_SELECT_WIDGET::m_kiway
private

Definition at line 127 of file footprint_select_widget.h.

Referenced by Load().

◆ m_max_items

int FOOTPRINT_SELECT_WIDGET::m_max_items
private

Definition at line 132 of file footprint_select_widget.h.

Referenced by UpdateList().

◆ m_sizer

wxSizer* FOOTPRINT_SELECT_WIDGET::m_sizer
private

Definition at line 129 of file footprint_select_widget.h.

Referenced by FOOTPRINT_SELECT_WIDGET().

◆ m_update

bool FOOTPRINT_SELECT_WIDGET::m_update
private

Definition at line 131 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: