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_KEYWORD = 0x0001, FILTERING_BY_PIN_COUNT = 0x0002, FILTERING_BY_LIBRARY = 0x0004,
  FILTERING_BY_NAME = 0x0008
}
 Filter setting constants. More...
 

Public Member Functions

 FOOTPRINTS_LISTBOX (CVPCB_MAINFRAME *parent, wxWindowID id, const wxPoint &loc, const wxSize &size)
 
 ~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 87 of file listboxes.h.

Member Enumeration Documentation

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_KEYWORD 
FILTERING_BY_PIN_COUNT 
FILTERING_BY_LIBRARY 
FILTERING_BY_NAME 

Definition at line 98 of file listboxes.h.

Constructor & Destructor Documentation

FOOTPRINTS_LISTBOX::FOOTPRINTS_LISTBOX ( CVPCB_MAINFRAME parent,
wxWindowID  id,
const wxPoint loc,
const wxSize &  size 
)

Definition at line 41 of file footprints_listbox.cpp.

43  :
44  ITEMS_LISTBOX_BASE( parent, id, loc, size, wxLC_SINGLE_SEL | wxNO_BORDER )
45 {
46 }
ITEMS_LISTBOX_BASE(CVPCB_MAINFRAME *aParent, wxWindowID aId, const wxPoint &aLocation, const wxSize &aSize, long aStyle=0)
FOOTPRINTS_LISTBOX::~FOOTPRINTS_LISTBOX ( )

Definition at line 49 of file footprints_listbox.cpp.

50 {
51 }

Member Function Documentation

void FOOTPRINTS_LISTBOX::AppendLine ( const wxString &  text)

Definition at line 90 of file footprints_listbox.cpp.

References m_footprintList, and ITEMS_LISTBOX_BASE::UpdateWidth().

91 {
92  m_footprintList.Add( text );
93  int lines = m_footprintList.Count();
94  SetItemCount( lines );
95  UpdateWidth( lines - 1 );
96 }
void UpdateWidth(int aLine=-1)
wxArrayString m_footprintList
Definition: listboxes.h:90
void ITEMS_LISTBOX_BASE::DeselectAll ( )
inherited

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

Definition at line 111 of file listbox_base.cpp.

References i.

Referenced by CVPCB_MAINFRAME::DelAssociations(), CVPCB_MAINFRAME::ToFirstNA(), and CVPCB_MAINFRAME::ToPreviousNA().

112 {
113  for( int i = 0; i < GetItemCount(); i++ )
114  Select( i, false );
115 }
size_t i
Definition: json11.cpp:597
int FOOTPRINTS_LISTBOX::GetCount ( )

Definition at line 54 of file footprints_listbox.cpp.

References m_footprintList.

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

55 {
56  return m_footprintList.Count();
57 }
wxArrayString m_footprintList
Definition: listboxes.h:90
CVPCB_MAINFRAME * ITEMS_LISTBOX_BASE::GetParent ( ) const
virtualinherited

Definition at line 118 of file listbox_base.cpp.

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

119 {
120  return (CVPCB_MAINFRAME*) wxListView::GetParent();
121 }
The CvPcb application main window.
wxString FOOTPRINTS_LISTBOX::GetSelectedFootprint ( )

Definition at line 73 of file footprints_listbox.cpp.

References m_footprintList.

Referenced by CVPCB_MAINFRAME::GetSelectedFootprint(), and OnLeftDClick().

74 {
75  wxString footprintName;
76  int ii = GetFirstSelected();
77 
78  if( ii >= 0 )
79  {
80  wxString msg = m_footprintList[ii];
81  msg.Trim( true );
82  msg.Trim( false );
83  footprintName = msg.AfterFirst( wxChar( ' ' ) );
84  }
85 
86  return footprintName;
87 }
wxArrayString m_footprintList
Definition: listboxes.h:90
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 104 of file listbox_base.cpp.

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

105 {
106  return GetFirstSelected();
107 }
void FOOTPRINTS_LISTBOX::OnChar ( wxKeyEvent &  event)

Definition at line 235 of file footprints_listbox.cpp.

References CVPCB_MAINFRAME::ChangeFocus(), ITEMS_LISTBOX_BASE::GetParent(), m_footprintList, and SetSelection().

Referenced by SetFootprints().

236 {
237  int key = event.GetKeyCode();
238 
239  switch( key )
240  {
241  case WXK_TAB:
242  case WXK_RIGHT:
243  case WXK_NUMPAD_RIGHT:
244  GetParent()->ChangeFocus( true );
245  return;
246 
247  case WXK_LEFT:
248  case WXK_NUMPAD_LEFT:
249  GetParent()->ChangeFocus( false );
250  return;
251 
252  case WXK_HOME:
253  case WXK_END:
254  case WXK_UP:
255  case WXK_DOWN:
256  case WXK_PAGEUP:
257  case WXK_PAGEDOWN:
258  event.Skip();
259  return;
260 
261  default:
262  break;
263  }
264 
265  // Search for an item name starting by the key code:
266  key = toupper( key );
267 
268  for( unsigned ii = 0; ii < m_footprintList.GetCount(); ii++ )
269  {
270  wxString text = m_footprintList.Item( ii );
271 
272  // Search for the start char of the footprint name. Skip the line number.
273  text.Trim( false ); // Remove leading spaces in line
274  unsigned jj = 0;
275 
276  for( ; jj < text.Len(); jj++ )
277  {
278  // skip line number
279  if( text[jj] == ' ' )
280  break;
281  }
282 
283  for( ; jj < text.Len(); jj++ )
284  { // skip blanks
285  if( text[jj] != ' ' )
286  break;
287  }
288 
289  int start_char = toupper( text[jj] );
290 
291  if( key == start_char )
292  {
293  SetSelection( ii, true ); // Ensure visible
294  break;
295  }
296  }
297 
298  event.Skip();
299 }
void ChangeFocus(bool aMoveRight)
wxArrayString m_footprintList
Definition: listboxes.h:90
void SetSelection(int index, bool State=true)
virtual CVPCB_MAINFRAME * GetParent() const
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 99 of file footprints_listbox.cpp.

References m_footprintList.

Referenced by CVPCB_MAINFRAME::refreshAfterComponentSearch().

100 {
101  if( item < 0 || item >= (long)m_footprintList.GetCount() )
102  return wxEmptyString;
103 
104  return m_footprintList.Item( item );
105 }
wxArrayString m_footprintList
Definition: listboxes.h:90
void FOOTPRINTS_LISTBOX::OnLeftClick ( wxListEvent &  event)

Definition at line 205 of file footprints_listbox.cpp.

References CVPCB_MAINFRAME::CreateScreenCmp(), CVPCB_MAINFRAME::DisplayStatus(), ITEMS_LISTBOX_BASE::GetParent(), and m_footprintList.

Referenced by SetFootprints().

206 {
207  if( m_footprintList.IsEmpty() )
208  return;
209 
210  // On some plateforms (OSX) the focus is lost when the viewers (fp and 3D viewers)
211  // are opened and refreshed when a new footprint is selected.
212  // If the listbox has the focus before selecting a new footprint, it will be forced
213  // after selection.
214  bool hasFocus = HasFocus();
215 
216  // If the footprint view window is displayed, update the footprint.
217  if( GetParent()->GetFootprintViewerFrame() )
219 
221 
222  if( hasFocus )
223  SetFocus();
224 }
void CreateScreenCmp()
Create or Update the frame showing the current highlighted footprint and (if showed) the 3D display f...
wxArrayString m_footprintList
Definition: listboxes.h:90
virtual CVPCB_MAINFRAME * GetParent() const
void DisplayStatus()
Function DisplayStatus updates the information displayed on the status bar at bottom of the main fram...
void FOOTPRINTS_LISTBOX::OnLeftDClick ( wxListEvent &  event)

Definition at line 227 of file footprints_listbox.cpp.

References ITEMS_LISTBOX_BASE::GetParent(), GetSelectedFootprint(), and CVPCB_MAINFRAME::SetNewPkg().

Referenced by SetFootprints().

228 {
229  wxString footprintName = GetSelectedFootprint();
230 
231  GetParent()->SetNewPkg( footprintName );
232 }
void SetNewPkg(const wxString &aFootprintName)
Function SetNewPkg set the footprint name for all selected components in component list and selects t...
virtual CVPCB_MAINFRAME * GetParent() const
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 141 of file footprints_listbox.cpp.

References FOOTPRINT_FILTER::FilterByFootprintFilters(), FOOTPRINT_FILTER::FilterByLibrary(), FOOTPRINT_FILTER::FilterByPattern(), FOOTPRINT_FILTER::FilterByPinCount(), FILTERING_BY_COMPONENT_KEYWORD, FILTERING_BY_LIBRARY, FILTERING_BY_NAME, FILTERING_BY_PIN_COUNT, GetChars(), COMPONENT::GetFootprintFilters(), COMPONENT::GetPinCount(), ITEMS_LISTBOX_BASE::GetSelection(), i, ID_CVPCB_FOOTPRINT_LIST, m_footprintList, OnChar(), OnLeftClick(), OnLeftDClick(), SetSelection(), and ITEMS_LISTBOX_BASE::UpdateWidth().

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

145 {
146  wxArrayString newList;
147  wxString msg;
148  wxString oldSelection;
149 
150  FOOTPRINT_FILTER filter( aList );
151 
152  if( aFilterType & FILTERING_BY_COMPONENT_KEYWORD && aComponent )
153  filter.FilterByFootprintFilters( aComponent->GetFootprintFilters() );
154 
155  if( aFilterType & FILTERING_BY_PIN_COUNT && aComponent )
156  filter.FilterByPinCount( aComponent->GetPinCount() );
157 
158  if( aFilterType & FILTERING_BY_LIBRARY )
159  filter.FilterByLibrary( aLibName );
160 
161  if( aFilterType & FILTERING_BY_NAME )
162  filter.FilterByPattern( aFootPrintFilterPattern );
163 
164  if( GetSelection() >= 0 && GetSelection() < (int)m_footprintList.GetCount() )
165  oldSelection = m_footprintList[ GetSelection() ];
166 
167  for( auto& i: filter )
168  {
169  msg.Printf( "%3d %s:%s", int( newList.GetCount() + 1 ),
170  GetChars( i.GetLibNickname() ),
171  GetChars( i.GetFootprintName() ) );
172  newList.Add( msg );
173  }
174 
175  if( newList == m_footprintList )
176  return;
177 
178  m_footprintList = newList;
179 
180  int selection = m_footprintList.Index( oldSelection );
181 
182  if( selection == wxNOT_FOUND )
183  selection = 0;
184 
185  wxWindowUpdateLocker freeze( this );
186  DeleteAllItems();
187 
188  if( m_footprintList.GetCount() )
189  {
190  SetItemCount( m_footprintList.GetCount() );
191  SetSelection( selection, true );
192  RefreshItems( 0L, m_footprintList.GetCount()-1 );
193  UpdateWidth();
194  }
195 }
int GetPinCount() const
Definition: pcb_netlist.h:184
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:177
void UpdateWidth(int aLine=-1)
wxArrayString m_footprintList
Definition: listboxes.h:90
Footprint display filter.
void SetSelection(int index, bool State=true)
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
size_t i
Definition: json11.cpp:597
void FOOTPRINTS_LISTBOX::SetSelectedFootprint ( const LIB_ID aFPID)

Definition at line 122 of file footprints_listbox.cpp.

References Format(), GetChars(), GetCount(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), i, m_footprintList, and SetSelection().

Referenced by CVPCB_MAINFRAME::OnSelectComponent().

123 {
124  wxString id = wxString::Format( "%s:%s",
125  GetChars( aFPID.GetLibNickname() ),
126  GetChars( aFPID.GetLibItemName() ) );
127 
128  for( int i = 0; i < GetCount(); ++i )
129  {
130  wxString candidate = m_footprintList.Item( i ).substr( 4 );
131 
132  if( candidate.CmpNoCase( id ) == 0 )
133  {
134  SetSelection( i, true );
135  return;
136  }
137  }
138 }
wxArrayString m_footprintList
Definition: listboxes.h:90
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
void SetSelection(int index, bool State=true)
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
size_t i
Definition: json11.cpp:597
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
void FOOTPRINTS_LISTBOX::SetSelection ( int  index,
bool  State = true 
)

Definition at line 108 of file footprints_listbox.cpp.

References GetCount(), and Refresh().

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

109 {
110  if( index >= GetCount() )
111  index = GetCount() - 1;
112 
113  if( (index >= 0) && (GetCount() > 0) )
114  {
115  Select( index, State );
116  EnsureVisible( index );
117  Refresh();
118  }
119 }
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
void FOOTPRINTS_LISTBOX::SetString ( unsigned  linecount,
const wxString &  text 
)

Definition at line 60 of file footprints_listbox.cpp.

References m_footprintList, and ITEMS_LISTBOX_BASE::UpdateWidth().

61 {
62  unsigned count = m_footprintList.Count();
63  if( count > 0 )
64  {
65  if( linecount >= count )
66  linecount = count - 1;
67  m_footprintList[linecount] = text;
68  }
69  UpdateWidth( linecount );
70 }
void UpdateWidth(int aLine=-1)
wxArrayString m_footprintList
Definition: listboxes.h:90
void ITEMS_LISTBOX_BASE::UpdateWidth ( int  aLine = -1)
inherited

Definition at line 57 of file listbox_base.cpp.

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().

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

Member Data Documentation

wxArrayString FOOTPRINTS_LISTBOX::m_footprintList
private

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