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,
  FILTERING_BY_TEXT_PATTERN = 0x0008
}
 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)
 Function SetFootprints populates 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
 Function OnGetItemText 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)
 
int GetSelection ()
 
void DeselectAll ()
 Removes all selection in lists which can have more than one item selected. More...
 
virtual CVPCB_MAINFRAMEGetParent () const
 
void UpdateWidth (int aLine=-1)
 

Private Attributes

wxArrayString m_footprintList
 

Detailed Description

Definition at line 83 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 
FILTERING_BY_TEXT_PATTERN 

Definition at line 94 of file listboxes.h.

Constructor & Destructor Documentation

◆ FOOTPRINTS_LISTBOX()

FOOTPRINTS_LISTBOX::FOOTPRINTS_LISTBOX ( CVPCB_MAINFRAME parent,
wxWindowID  id 
)

Definition at line 35 of file footprints_listbox.cpp.

35  :
36  ITEMS_LISTBOX_BASE( parent, id, wxDefaultPosition, wxDefaultSize, wxLC_SINGLE_SEL|wxNO_BORDER )
37 {
38 }
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 41 of file footprints_listbox.cpp.

42 {
43 }

Member Function Documentation

◆ AppendLine()

void FOOTPRINTS_LISTBOX::AppendLine ( const wxString &  text)

Definition at line 83 of file footprints_listbox.cpp.

84 {
85  m_footprintList.Add( text );
86  int lines = m_footprintList.Count();
87  SetItemCount( lines );
88  UpdateWidth( lines - 1 );
89 }
void UpdateWidth(int aLine=-1)
wxArrayString m_footprintList
Definition: listboxes.h:86

References m_footprintList, and ITEMS_LISTBOX_BASE::UpdateWidth().

◆ DeselectAll()

void ITEMS_LISTBOX_BASE::DeselectAll ( )
inherited

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

Definition at line 107 of file listbox_base.cpp.

108 {
109  for( int i = 0; i < GetItemCount(); i++ )
110  Select( i, false );
111 }

Referenced by CVPCB_MAINFRAME::SetSelectedComponent().

◆ GetCount()

int FOOTPRINTS_LISTBOX::GetCount ( )

Definition at line 46 of file footprints_listbox.cpp.

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

References m_footprintList.

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

◆ GetParent()

CVPCB_MAINFRAME * ITEMS_LISTBOX_BASE::GetParent ( void  ) const
virtualinherited

Definition at line 114 of file listbox_base.cpp.

115 {
116  return (CVPCB_MAINFRAME*) wxListView::GetParent();
117 }
The CvPcb application main window.

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

◆ GetSelectedFootprint()

wxString FOOTPRINTS_LISTBOX::GetSelectedFootprint ( )

Definition at line 66 of file footprints_listbox.cpp.

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

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 100 of file listbox_base.cpp.

101 {
102  return GetFirstSelected();
103 }

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

◆ OnChar()

void FOOTPRINTS_LISTBOX::OnChar ( wxKeyEvent &  event)

Definition at line 225 of file footprints_listbox.cpp.

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

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

◆ OnGetItemText()

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

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

Definition at line 92 of file footprints_listbox.cpp.

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

References m_footprintList.

Referenced by CVPCB_MAINFRAME::refreshAfterComponentSearch().

◆ OnLeftClick()

void FOOTPRINTS_LISTBOX::OnLeftClick ( wxListEvent &  event)

Definition at line 197 of file footprints_listbox.cpp.

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

References CVPCB_ACTIONS::showFootprintViewer.

◆ OnLeftDClick()

void FOOTPRINTS_LISTBOX::OnLeftDClick ( wxListEvent &  event)

Definition at line 219 of file footprints_listbox.cpp.

220 {
222 }
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:140
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:74
static TOOL_ACTION associate
Definition: cvpcb_actions.h:64
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 
)

Function SetFootprints populates 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.
aFootPrintFilterPattern= a filter used to filter list by names
aFilterTypedefines the criteria to filter aList.

Definition at line 132 of file footprints_listbox.cpp.

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

References FOOTPRINT_FILTER::FilterByFootprintFilters(), FOOTPRINT_FILTER::FilterByLibrary(), FOOTPRINT_FILTER::FilterByPinCount(), FOOTPRINT_FILTER::FilterByTextPattern(), FILTERING_BY_COMPONENT_FP_FILTERS, FILTERING_BY_LIBRARY, FILTERING_BY_PIN_COUNT, FILTERING_BY_TEXT_PATTERN, COMPONENT::GetFootprintFilters(), COMPONENT::GetPinCount(), ITEMS_LISTBOX_BASE::GetSelection(), m_footprintList, SetSelection(), and ITEMS_LISTBOX_BASE::UpdateWidth().

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

◆ SetSelectedFootprint()

void FOOTPRINTS_LISTBOX::SetSelectedFootprint ( const LIB_ID aFPID)

Definition at line 115 of file footprints_listbox.cpp.

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

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 101 of file footprints_listbox.cpp.

102 {
103  if( index >= GetCount() )
104  index = GetCount() - 1;
105 
106  if( (index >= 0) && (GetCount() > 0) )
107  {
108  Select( index, State );
109  EnsureVisible( index );
110  Refresh();
111  }
112 }
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::refreshAfterComponentSearch(), SetFootprints(), and SetSelectedFootprint().

◆ SetString()

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

Definition at line 52 of file footprints_listbox.cpp.

53 {
54  unsigned count = m_footprintList.Count();
55  if( count > 0 )
56  {
57  if( linecount >= count )
58  linecount = count - 1;
59 
60  m_footprintList[linecount] = text;
61  }
62  UpdateWidth( linecount );
63 }
void UpdateWidth(int aLine=-1)
wxArrayString m_footprintList
Definition: listboxes.h:86

References m_footprintList, and ITEMS_LISTBOX_BASE::UpdateWidth().

◆ UpdateWidth()

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

Definition at line 53 of file listbox_base.cpp.

54 {
55  // Less than zero: recalculate width of all items.
56  if( aLine < 0 )
57  {
58  columnWidth = 0;
59  for( int ii = 0; ii < GetItemCount(); ii++ )
60  {
61  UpdateLineWidth( (unsigned)ii );
62  }
63  }
64 
65  // Zero or above: update from a single line.
66  else
67  {
68  if( aLine < GetItemCount() )
69  UpdateLineWidth( (unsigned)aLine );
70  }
71 }
void UpdateLineWidth(unsigned aLine)

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

Referenced by AppendLine(), LIBRARY_LISTBOX::AppendLine(), COMPONENTS_LISTBOX::AppendLine(), CVPCB_MAINFRAME::BuildCmpListBox(), SetFootprints(), LIBRARY_LISTBOX::SetLibraryList(), SetString(), LIBRARY_LISTBOX::SetString(), and COMPONENTS_LISTBOX::SetString().

Member Data Documentation

◆ m_footprintList

wxArrayString FOOTPRINTS_LISTBOX::m_footprintList
private

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