KiCad PCB EDA Suite
FOOTPRINTS_LISTBOX Class Reference

#include <listboxes.h>

Inheritance diagram for FOOTPRINTS_LISTBOX:
ITEMS_LISTBOX_BASE

Public Types

enum  FP_FILTER_T : int { UNFILTERED_FP_LIST = 0, FILTERING_BY_COMPONENT_FP_FILTERS = 0x0001, FILTERING_BY_PIN_COUNT = 0x0002, FILTERING_BY_LIBRARY = 0x0004 }
 Filter setting constants. More...
 

Public Member Functions

 FOOTPRINTS_LISTBOX (CVPCB_MAINFRAME *parent, wxWindowID id)
 
 ~FOOTPRINTS_LISTBOX ()
 
int GetCount ()
 
void SetSelection (int index, bool State=true)
 
void SetSelectedFootprint (const LIB_ID &aFPID)
 
void SetString (unsigned linecount, const wxString &text)
 
void AppendLine (const wxString &text)
 
void SetFootprints (FOOTPRINT_LIST &aList, const wxString &aLibName, COMPONENT *aComponent, const wxString &aFootPrintFilterPattern, int aFilterType)
 Populate the wxListCtrl with the footprints from aList that meet the filter criteria defined by aFilterType. More...
 
wxString GetSelectedFootprint ()
 
wxString OnGetItemText (long item, long column) const override
 This overloaded function MUST be provided for the wxLC_VIRTUAL mode because real data is not handled by ITEMS_LISTBOX_BASE. More...
 
void OnLeftClick (wxListEvent &event)
 
void OnLeftDClick (wxListEvent &event)
 
void OnChar (wxKeyEvent &event)
 
 DECLARE_EVENT_TABLE ()
 
int GetSelection ()
 
void DeselectAll ()
 Remove all selection in lists which can have more than one item selected. More...
 
virtual CVPCB_MAINFRAMEGetParent () const
 
void UpdateWidth (int aLine=-1)
 Update the width of the column based on its contents. More...
 

Private Attributes

wxArrayString m_footprintList
 

Detailed Description

Definition at line 84 of file listboxes.h.

Member Enumeration Documentation

◆ FP_FILTER_T

Filter setting constants.

The filter type is a bitwise OR of these flags, and only footprints matching all selected filter types are shown.

Enumerator
UNFILTERED_FP_LIST 
FILTERING_BY_COMPONENT_FP_FILTERS 
FILTERING_BY_PIN_COUNT 
FILTERING_BY_LIBRARY 

Definition at line 91 of file listboxes.h.

Constructor & Destructor Documentation

◆ FOOTPRINTS_LISTBOX()

FOOTPRINTS_LISTBOX::FOOTPRINTS_LISTBOX ( CVPCB_MAINFRAME parent,
wxWindowID  id 
)

Definition at line 36 of file footprints_listbox.cpp.

36  :
37  ITEMS_LISTBOX_BASE( parent, id, wxDefaultPosition, wxDefaultSize, wxLC_SINGLE_SEL|wxNO_BORDER )
38 {
39 }
ITEMS_LISTBOX_BASE(CVPCB_MAINFRAME *aParent, wxWindowID aId, const wxPoint &aLocation=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=0)

◆ ~FOOTPRINTS_LISTBOX()

FOOTPRINTS_LISTBOX::~FOOTPRINTS_LISTBOX ( )

Definition at line 42 of file footprints_listbox.cpp.

43 {
44 }

Member Function Documentation

◆ AppendLine()

void FOOTPRINTS_LISTBOX::AppendLine ( const wxString &  text)

Definition at line 84 of file footprints_listbox.cpp.

85 {
86  m_footprintList.Add( text );
87  int lines = m_footprintList.Count();
88  SetItemCount( lines );
89  UpdateWidth( lines - 1 );
90 }
void UpdateWidth(int aLine=-1)
Update the width of the column based on its contents.
wxArrayString m_footprintList
Definition: listboxes.h:138

References m_footprintList, text, and ITEMS_LISTBOX_BASE::UpdateWidth().

◆ DECLARE_EVENT_TABLE()

FOOTPRINTS_LISTBOX::DECLARE_EVENT_TABLE ( )

◆ DeselectAll()

void ITEMS_LISTBOX_BASE::DeselectAll ( )
inherited

Remove all selection in lists which can have more than one item selected.

Definition at line 94 of file listbox_base.cpp.

95 {
96  for( int i = 0; i < GetItemCount(); i++ )
97  Select( i, false );
98 }

Referenced by SetFootprints(), and CVPCB_MAINFRAME::SetSelectedComponent().

◆ GetCount()

int FOOTPRINTS_LISTBOX::GetCount ( )

Definition at line 47 of file footprints_listbox.cpp.

48 {
49  return m_footprintList.Count();
50 }
wxArrayString m_footprintList
Definition: listboxes.h:138

References m_footprintList.

Referenced by CVPCB_MAINFRAME::DisplayStatus(), CVPCB_MAINFRAME::refreshAfterSymbolSearch(), SetSelectedFootprint(), and SetSelection().

◆ GetParent()

CVPCB_MAINFRAME * ITEMS_LISTBOX_BASE::GetParent ( void  ) const
virtualinherited

Definition at line 101 of file listbox_base.cpp.

102 {
103  return (CVPCB_MAINFRAME*) wxListView::GetParent();
104 }
The CvPcb application main window.

Referenced by OnLeftDClick(), SYMBOLS_LISTBOX::OnSelectComponent(), and LIBRARY_LISTBOX::OnSelectLibrary().

◆ GetSelectedFootprint()

wxString FOOTPRINTS_LISTBOX::GetSelectedFootprint ( )

Definition at line 67 of file footprints_listbox.cpp.

68 {
69  wxString footprintName;
70  int ii = GetFirstSelected();
71 
72  if( ii >= 0 )
73  {
74  wxString msg = m_footprintList[ii];
75  msg.Trim( true );
76  msg.Trim( false );
77  footprintName = msg.AfterFirst( wxChar( ' ' ) );
78  }
79 
80  return footprintName;
81 }
wxArrayString m_footprintList
Definition: listboxes.h:138

References m_footprintList.

Referenced by CVPCB_MAINFRAME::GetSelectedFootprint().

◆ GetSelection()

int ITEMS_LISTBOX_BASE::GetSelection ( )
inherited
Returns
the index of the selected item in lists allowing only one item selected and the index of the first selected item in lists allowing many selection

Definition at line 88 of file listbox_base.cpp.

89 {
90  return GetFirstSelected();
91 }

Referenced by CVPCB_MAINFRAME::GetSelectedComponent(), CVPCB_MAINFRAME::OnSelectComponent(), CVPCB_MAINFRAME::refreshAfterSymbolSearch(), CVPCB_MAINFRAME::SendMessageToEESCHEMA(), SetFootprints(), and LIBRARY_LISTBOX::SetLibraryList().

◆ OnChar()

void FOOTPRINTS_LISTBOX::OnChar ( wxKeyEvent &  event)

Definition at line 228 of file footprints_listbox.cpp.

229 {
230  wxLogTrace( kicadTraceKeyEvent, wxT( "FOOTPRINTS_LISTBOX::OnChar %s" ), dump( event ) );
231 
232  int key = event.GetKeyCode();
233 
234  switch( key )
235  {
236  case WXK_HOME:
237  case WXK_END:
238  case WXK_UP:
239  case WXK_DOWN:
240  case WXK_PAGEUP:
241  case WXK_PAGEDOWN:
242  event.Skip();
243  return;
244 
245  default:
246  break;
247  }
248 
249  // Search for an item name starting by the key code:
250  key = toupper( key );
251 
252  for( unsigned ii = 0; ii < m_footprintList.GetCount(); ii++ )
253  {
254  wxString text = m_footprintList.Item( ii );
255 
256  // Search for the start char of the footprint name. Skip the line number.
257  text.Trim( false ); // Remove leading spaces in line
258  unsigned jj = 0;
259 
260  for( ; jj < text.Len(); jj++ )
261  {
262  // skip line number
263  if( text[jj] == ' ' )
264  break;
265  }
266 
267  for( ; jj < text.Len(); jj++ )
268  { // skip blanks
269  if( text[jj] != ' ' )
270  break;
271  }
272 
273  int start_char = toupper( text[jj] );
274 
275  if( key == start_char )
276  {
277  SetSelection( ii, true ); // Ensure visible
278  break;
279  }
280  }
281 
282  event.Skip();
283 }
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxArrayString m_footprintList
Definition: listboxes.h:138
void SetSelection(int index, bool State=true)
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.

References dump(), kicadTraceKeyEvent, m_footprintList, SetSelection(), and text.

◆ OnGetItemText()

wxString FOOTPRINTS_LISTBOX::OnGetItemText ( long  item,
long  column 
) const
override

This overloaded function MUST be provided for the wxLC_VIRTUAL mode because real data is not handled by ITEMS_LISTBOX_BASE.

Definition at line 93 of file footprints_listbox.cpp.

94 {
95  if( item < 0 || item >= (long)m_footprintList.GetCount() )
96  return wxEmptyString;
97 
98  return m_footprintList.Item( item );
99 }
wxArrayString m_footprintList
Definition: listboxes.h:138

References m_footprintList.

Referenced by CVPCB_MAINFRAME::refreshAfterSymbolSearch().

◆ OnLeftClick()

void FOOTPRINTS_LISTBOX::OnLeftClick ( wxListEvent &  event)

Definition at line 200 of file footprints_listbox.cpp.

201 {
202  if( m_footprintList.IsEmpty() )
203  return;
204 
205  // On some plateforms (OSX) the focus is lost when the viewers (fp and 3D viewers)
206  // are opened and refreshed when a new footprint is selected.
207  // If the listbox has the focus before selecting a new footprint, it will be forced
208  // after selection.
209  bool hasFocus = HasFocus();
210 
211  // If the footprint view window is displayed, update the footprint.
212  if( GetParent()->GetFootprintViewerFrame() )
214 
216 
217  if( hasFocus )
218  SetFocus();
219 }
static TOOL_ACTION showFootprintViewer
Open the footprint viewer.
Definition: cvpcb_actions.h:49
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
wxArrayString m_footprintList
Definition: listboxes.h:138
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
void DisplayStatus()
Update the information displayed on the status bar at bottom of the main frame.
virtual CVPCB_MAINFRAME * GetParent() const

References CVPCB_ACTIONS::showFootprintViewer.

◆ OnLeftDClick()

void FOOTPRINTS_LISTBOX::OnLeftDClick ( wxListEvent &  event)

Definition at line 222 of file footprints_listbox.cpp.

223 {
225 }
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
static TOOL_ACTION associate
Definition: cvpcb_actions.h:62
virtual CVPCB_MAINFRAME * GetParent() const

References CVPCB_ACTIONS::associate, ITEMS_LISTBOX_BASE::GetParent(), TOOLS_HOLDER::GetToolManager(), and TOOL_MANAGER::RunAction().

◆ SetFootprints()

void FOOTPRINTS_LISTBOX::SetFootprints ( FOOTPRINT_LIST aList,
const wxString &  aLibName,
COMPONENT aComponent,
const wxString &  aFootPrintFilterPattern,
int  aFilterType 
)

Populate the wxListCtrl with the footprints from aList that meet the filter criteria defined by aFilterType.

Parameters
aListis a FOOTPRINT_LIST item containing the footprints.
aLibNameis wxString containing the name of the selected library. Can be wxEmptyString.
aComponentis the COMPONENT used by the filtering criteria. Can be NULL.
aFootPrintFilterPatternis the filter used to filter list by names.
aFilterTypedefines the criteria to filter aList.

Definition at line 133 of file footprints_listbox.cpp.

137 {
138  wxArrayString newList;
139  wxString msg;
140  wxString oldSelection;
141 
142  FOOTPRINT_FILTER filter( aList );
143 
144  if( aFilterType & FILTERING_BY_COMPONENT_FP_FILTERS && aComponent )
145  filter.FilterByFootprintFilters( aComponent->GetFootprintFilters() );
146 
147  if( aFilterType & FILTERING_BY_PIN_COUNT && aComponent )
148  filter.FilterByPinCount( aComponent->GetPinCount() );
149 
150  if( aFilterType & FILTERING_BY_LIBRARY )
151  filter.FilterByLibrary( aLibName );
152 
153  if( !aFootPrintFilterPattern.IsEmpty() )
154  filter.FilterByTextPattern( aFootPrintFilterPattern );
155 
156  if( GetSelection() >= 0 && GetSelection() < (int)m_footprintList.GetCount() )
157  oldSelection = m_footprintList[ GetSelection() ];
158 
159  for( auto& i: filter )
160  {
161  msg.Printf( wxT( "%3d %s:%s" ),
162  int( newList.GetCount() + 1 ),
163  i.GetLibNickname(),
164  i.GetFootprintName() );
165  newList.Add( msg );
166  }
167 
168  if( newList == m_footprintList )
169  return;
170 
171  m_footprintList = newList;
172 
173  int selection = m_footprintList.Index( oldSelection );
174 
175  if( selection == wxNOT_FOUND )
176  selection = 0;
177 
178  DeselectAll();
179  wxSafeYield();
180  wxWindowUpdateLocker freeze( this );
181  DeleteAllItems();
182 
183  if( m_footprintList.GetCount() )
184  {
185  SetItemCount( m_footprintList.GetCount() );
186  SetSelection( selection, true );
187  RefreshItems( 0L, m_footprintList.GetCount()-1 );
188  UpdateWidth();
189  }
190 }
void DeselectAll()
Remove all selection in lists which can have more than one item selected.
void UpdateWidth(int aLine=-1)
Update the width of the column based on its contents.
wxArrayString m_footprintList
Definition: listboxes.h:138
Footprint display filter.
void SetSelection(int index, bool State=true)
int GetPinCount() const
Definition: pcb_netlist.h:146
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:143

References ITEMS_LISTBOX_BASE::DeselectAll(), filter, FILTERING_BY_COMPONENT_FP_FILTERS, FILTERING_BY_LIBRARY, FILTERING_BY_PIN_COUNT, COMPONENT::GetFootprintFilters(), COMPONENT::GetPinCount(), ITEMS_LISTBOX_BASE::GetSelection(), m_footprintList, SetSelection(), and ITEMS_LISTBOX_BASE::UpdateWidth().

Referenced by CVPCB_MAINFRAME::BuildFootprintsListBox(), and CVPCB_MAINFRAME::OnSelectComponent().

◆ SetSelectedFootprint()

void FOOTPRINTS_LISTBOX::SetSelectedFootprint ( const LIB_ID aFPID)

Definition at line 116 of file footprints_listbox.cpp.

117 {
118  wxString id = aFPID.Format().wx_str();
119 
120  for( int i = 0; i < GetCount(); ++i )
121  {
122  wxString candidate = m_footprintList.Item( i ).substr( 4 );
123 
124  if( candidate.CmpNoCase( id ) == 0 )
125  {
126  SetSelection( i, true );
127  return;
128  }
129  }
130 }
wxArrayString m_footprintList
Definition: listboxes.h:138
UTF8 Format() const
Definition: lib_id.cpp:116
void SetSelection(int index, bool State=true)
wxString wx_str() const
Definition: utf8.cpp:46

References LIB_ID::Format(), GetCount(), m_footprintList, SetSelection(), and UTF8::wx_str().

Referenced by CVPCB_MAINFRAME::OnSelectComponent().

◆ SetSelection()

void FOOTPRINTS_LISTBOX::SetSelection ( int  index,
bool  State = true 
)

Definition at line 102 of file footprints_listbox.cpp.

103 {
104  if( index >= GetCount() )
105  index = GetCount() - 1;
106 
107  if( (index >= 0) && (GetCount() > 0) )
108  {
109  Select( index, State );
110  EnsureVisible( index );
111  Refresh();
112  }
113 }
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...

References GetCount(), and Refresh().

Referenced by OnChar(), CVPCB_MAINFRAME::OnSelectComponent(), CVPCB_MAINFRAME::refreshAfterSymbolSearch(), SetFootprints(), and SetSelectedFootprint().

◆ SetString()

void FOOTPRINTS_LISTBOX::SetString ( unsigned  linecount,
const wxString &  text 
)

Definition at line 53 of file footprints_listbox.cpp.

54 {
55  unsigned count = m_footprintList.Count();
56  if( count > 0 )
57  {
58  if( linecount >= count )
59  linecount = count - 1;
60 
61  m_footprintList[linecount] = text;
62  }
63  UpdateWidth( linecount );
64 }
void UpdateWidth(int aLine=-1)
Update the width of the column based on its contents.
wxArrayString m_footprintList
Definition: listboxes.h:138

References m_footprintList, text, and ITEMS_LISTBOX_BASE::UpdateWidth().

◆ UpdateWidth()

void ITEMS_LISTBOX_BASE::UpdateWidth ( int  aLine = -1)
inherited

Update the width of the column based on its contents.

Parameters
aLineis the line to calculate the width from. If positive, the width will only be increased if needed. If negative, we start from scratch and all lines are considered, i.e., the column may be shrunk.

Definition at line 49 of file listbox_base.cpp.

50 {
51  // Less than zero: recalculate width of all items.
52  if( aLine < 0 )
53  {
54  columnWidth = 0;
55  for( int ii = 0; ii < GetItemCount(); ii++ )
56  {
57  UpdateLineWidth( (unsigned)ii );
58  }
59  }
60 
61  // Zero or above: update from a single line.
62  else
63  {
64  if( aLine < GetItemCount() )
65  UpdateLineWidth( (unsigned)aLine );
66  }
67 }
void UpdateLineWidth(unsigned aLine)
Calculate the width of the given line, and increase the column width if needed.

References ITEMS_LISTBOX_BASE::columnWidth, and ITEMS_LISTBOX_BASE::UpdateLineWidth().

Referenced by AppendLine(), LIBRARY_LISTBOX::AppendLine(), SYMBOLS_LISTBOX::AppendLine(), CVPCB_MAINFRAME::BuildSymbolsListBox(), SetFootprints(), LIBRARY_LISTBOX::SetLibraryList(), SetString(), LIBRARY_LISTBOX::SetString(), and SYMBOLS_LISTBOX::SetString().

Member Data Documentation

◆ m_footprintList

wxArrayString FOOTPRINTS_LISTBOX::m_footprintList
private

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