KiCad PCB EDA Suite
SYMBOLS_LISTBOX Class Reference

#include <listboxes.h>

Inheritance diagram for SYMBOLS_LISTBOX:
ITEMS_LISTBOX_BASE

Public Member Functions

 SYMBOLS_LISTBOX (CVPCB_MAINFRAME *parent, wxWindowID id)
 
 ~SYMBOLS_LISTBOX ()
 
void Clear ()
 
int GetCount ()
 
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...
 
wxListItemAttr * OnGetItemAttr (long item) const override
 
void SetSelection (int index, bool State=true)
 
void SetString (unsigned linecount, const wxString &text)
 
void AppendLine (const wxString &text)
 
void AppendWarning (int index)
 
void RemoveWarning (int index)
 
void OnChar (wxKeyEvent &event)
 Called on a key press. More...
 
void OnSelectComponent (wxListEvent &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...
 

Public Attributes

wxArrayString m_SymbolList
 

Private Member Functions

void UpdateLineWidth (unsigned aLine, wxClientDC &dc)
 Calculate the width of the given line, and increase the column width if needed. More...
 

Private Attributes

std::vector< long > m_symbolWarning
 
std::unique_ptr< wxListItemAttr > m_warningAttr
 
int columnWidth
 

Detailed Description

Definition at line 181 of file listboxes.h.

Constructor & Destructor Documentation

◆ SYMBOLS_LISTBOX()

SYMBOLS_LISTBOX::SYMBOLS_LISTBOX ( CVPCB_MAINFRAME parent,
wxWindowID  id 
)

Definition at line 36 of file symbols_listbox.cpp.

36 :
37 ITEMS_LISTBOX_BASE( parent, id ),
38 m_warningAttr( std::make_unique<wxListItemAttr>() )
39{
40 m_warningAttr->SetBackgroundColour( *wxYELLOW );
41}
ITEMS_LISTBOX_BASE(CVPCB_MAINFRAME *aParent, wxWindowID aId, const wxPoint &aLocation=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=0)
std::unique_ptr< wxListItemAttr > m_warningAttr
Definition: listboxes.h:231

References m_warningAttr.

◆ ~SYMBOLS_LISTBOX()

SYMBOLS_LISTBOX::~SYMBOLS_LISTBOX ( )

Definition at line 44 of file symbols_listbox.cpp.

45{
46}

Member Function Documentation

◆ AppendLine()

void SYMBOLS_LISTBOX::AppendLine ( const wxString &  text)

Definition at line 81 of file symbols_listbox.cpp.

82{
83 m_SymbolList.Add( text );
84 int lines = m_SymbolList.Count();
85 SetItemCount( lines );
86 UpdateWidth( lines - 1 );
87}
void UpdateWidth(int aLine=-1)
Update the width of the column based on its contents.
wxArrayString m_SymbolList
Definition: listboxes.h:227

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

Referenced by CVPCB_MAINFRAME::readNetListAndFpFiles().

◆ AppendWarning()

void SYMBOLS_LISTBOX::AppendWarning ( int  index)

Definition at line 90 of file symbols_listbox.cpp.

91{
92 if( !std::count( m_symbolWarning.begin(), m_symbolWarning.end(), index ) )
93 {
94 m_symbolWarning.emplace_back( index );
95 }
96}
std::vector< long > m_symbolWarning
Definition: listboxes.h:230

References m_symbolWarning.

Referenced by CVPCB_MAINFRAME::AssociateFootprint(), CVPCB_MAINFRAME::BuildSymbolsListBox(), and CVPCB_MAINFRAME::readNetListAndFpFiles().

◆ Clear()

void SYMBOLS_LISTBOX::Clear ( )

Definition at line 55 of file symbols_listbox.cpp.

56{
57 m_SymbolList.Clear();
58 SetItemCount( 0 );
59}

References Clear().

Referenced by Clear(), and CVPCB_MAINFRAME::readNetListAndFpFiles().

◆ DECLARE_EVENT_TABLE()

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

105{
106 for( int i = GetFirstSelected(); i >= 0; i = GetNextSelected(i))
107 {
108 Select( i, false );
109 }
110}

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

◆ GetCount()

int SYMBOLS_LISTBOX::GetCount ( )

◆ GetParent()

CVPCB_MAINFRAME * ITEMS_LISTBOX_BASE::GetParent ( void  ) const
virtualinherited

Definition at line 113 of file listbox_base.cpp.

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

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

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

99{
100 return GetFirstSelected();
101}

Referenced by CVPCB_MAINFRAME::GetSelectedComponent(), CVPCB_MAINFRAME::OnSelectComponent(), CVPCB_MAINFRAME::onTextFilterChangedTimer(), CVPCB_MAINFRAME::refreshAfterSymbolSearch(), CVPCB_MAINFRAME::SendComponentSelectionToSch(), and FOOTPRINTS_LISTBOX::SetFootprints().

◆ OnChar()

void SYMBOLS_LISTBOX::OnChar ( wxKeyEvent &  event)

Called on a key press.

Call default handler for some special keys, and for "ASCII" keys, select the first component that the name starts by the letter.

This is the default behavior of a listbox, but because we use virtual lists, the listbox does not know anything to what is displayed, we must handle this behavior here. Furthermore the reference of components is not at the beginning of displayed lines (the first word is the line number).

Definition at line 142 of file symbols_listbox.cpp.

143{
144 wxLogTrace( kicadTraceKeyEvent, "SYMBOLS_LISTBOX::OnChar %s", dump( event ) );
145
146 int key = event.GetKeyCode();
147
148 switch( key )
149 {
150 case WXK_HOME:
151 case WXK_END:
152 case WXK_UP:
153 case WXK_DOWN:
154 case WXK_PAGEUP:
155 case WXK_PAGEDOWN:
156 event.Skip();
157 return;
158
159
160 default:
161 break;
162 }
163
164 // Search for an item name starting by the key code:
165 key = toupper( key );
166
167 for( unsigned ii = 0; ii < m_SymbolList.GetCount(); ii++ )
168 {
169 wxString text = m_SymbolList.Item( ii );
170
171 // Search for the start char of the footprint name. Skip the line number.
172 text.Trim( false ); // Remove leading spaces in line
173 unsigned jj = 0;
174
175 for( ; jj < text.Len(); jj++ )
176 { // skip line number
177 if( text[jj] == ' ' )
178 break;
179 }
180
181 for( ; jj < text.Len(); jj++ )
182 { // skip blanks
183 if( text[jj] != ' ' )
184 break;
185 }
186
187 int start_char = toupper( text[jj] );
188
189 if( key == start_char )
190 {
191 SetSelection( (int) ii, true ); // Ensure visible
192 break;
193 }
194 }
195
196 event.Skip();
197}
void SetSelection(int index, bool State=true)
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.

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

◆ OnGetItemAttr()

wxListItemAttr * SYMBOLS_LISTBOX::OnGetItemAttr ( long  item) const
override

Definition at line 115 of file symbols_listbox.cpp.

116{
117 if( std::count( m_symbolWarning.begin(), m_symbolWarning.end(), item ) )
118 {
119 return m_warningAttr.get();
120 }
121 return nullptr;
122}

References m_symbolWarning, and m_warningAttr.

◆ OnGetItemText()

wxString SYMBOLS_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 109 of file symbols_listbox.cpp.

110{
111 return m_SymbolList.Item( item );
112}

References m_SymbolList.

◆ OnSelectComponent()

void SYMBOLS_LISTBOX::OnSelectComponent ( wxListEvent &  event)

Definition at line 200 of file symbols_listbox.cpp.

201{
202 SetFocus();
203 GetParent()->OnSelectComponent( event );
204}
void OnSelectComponent(wxListEvent &event)
Called when clicking on a component in component list window:
virtual CVPCB_MAINFRAME * GetParent() const

References ITEMS_LISTBOX_BASE::GetParent(), and CVPCB_MAINFRAME::OnSelectComponent().

◆ RemoveWarning()

void SYMBOLS_LISTBOX::RemoveWarning ( int  index)

Definition at line 99 of file symbols_listbox.cpp.

100{
101 if( auto const found{ std::find( m_symbolWarning.begin(), m_symbolWarning.end(), index ) };
102 found != m_symbolWarning.end() )
103 {
104 m_symbolWarning.erase( found );
105 }
106}

References m_symbolWarning.

Referenced by CVPCB_MAINFRAME::AssociateFootprint().

◆ SetSelection()

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

Definition at line 125 of file symbols_listbox.cpp.

126{
127 if( index >= GetCount() )
128 index = GetCount() - 1;
129
130 if( (index >= 0) && (GetCount() > 0) )
131 {
132 Select( index, State );
133 EnsureVisible( index );
134
135#ifdef __WXMAC__
136 Update();
137#endif
138 }
139}

References GetCount().

Referenced by CVPCB_MAINFRAME::BuildSymbolsListBox(), OnChar(), CVPCB_MAINFRAME::readNetListAndFpFiles(), and CVPCB_MAINFRAME::SetSelectedComponent().

◆ SetString()

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

Definition at line 68 of file symbols_listbox.cpp.

69{
70 if( linecount >= m_SymbolList.Count() )
71 linecount = m_SymbolList.Count() - 1;
72
73 if( m_SymbolList.Count() > 0 )
74 {
75 m_SymbolList[linecount] = text;
76 UpdateWidth( linecount );
77 }
78}

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

Referenced by CVPCB_MAINFRAME::AssociateFootprint().

◆ UpdateLineWidth()

void ITEMS_LISTBOX_BASE::UpdateLineWidth ( unsigned  aLine,
wxClientDC &  dc 
)
privateinherited

Calculate the width of the given line, and increase the column width if needed.

This is effectively the wxListCtrl code for autosizing. NB. it relies on the caller checking the given line number is valid.

Definition at line 73 of file listbox_base.cpp.

74{
75 wxCoord w;
76 int newWidth = 10; // Value of AUTOSIZE_COL_MARGIN from wxWidgets source.
77 wxString str;
78
79 dc.SetFont( GetFont() );
80
81 if( IsVirtual() )
82 str = OnGetItemText( aLine, 0 );
83 else
84 str = GetItemText( aLine, 0 );
85 str += " ";
86
87 dc.GetTextExtent( str, &w, nullptr );
88 newWidth += w;
89
90 if( newWidth > columnWidth )
91 {
92 columnWidth = newWidth;
93 SetColumnWidth( 0, columnWidth );
94 }
95}

References ITEMS_LISTBOX_BASE::columnWidth.

Referenced by 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 wxClientDC dc( this );
52 int itemCount = GetItemCount();
53
54 // Less than zero: recalculate width of all items.
55 if( aLine < 0 )
56 {
57 columnWidth = 0;
58 for( int ii = 0; ii < itemCount; ii++ )
59 {
60 UpdateLineWidth( (unsigned)ii, dc );
61 }
62 }
63
64 // Zero or above: update from a single line.
65 else
66 {
67 if( aLine < itemCount )
68 UpdateLineWidth( (unsigned)aLine, dc );
69 }
70}
void UpdateLineWidth(unsigned aLine, wxClientDC &dc)
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 FOOTPRINTS_LISTBOX::AppendLine(), AppendLine(), CVPCB_MAINFRAME::BuildSymbolsListBox(), LIBRARY_LISTBOX::Finish(), FOOTPRINTS_LISTBOX::SetFootprints(), FOOTPRINTS_LISTBOX::SetString(), LIBRARY_LISTBOX::SetString(), and SetString().

Member Data Documentation

◆ columnWidth

int ITEMS_LISTBOX_BASE::columnWidth
privateinherited

◆ m_SymbolList

wxArrayString SYMBOLS_LISTBOX::m_SymbolList

◆ m_symbolWarning

std::vector<long> SYMBOLS_LISTBOX::m_symbolWarning
private

Definition at line 230 of file listboxes.h.

Referenced by AppendWarning(), OnGetItemAttr(), and RemoveWarning().

◆ m_warningAttr

std::unique_ptr<wxListItemAttr> SYMBOLS_LISTBOX::m_warningAttr
private

Definition at line 231 of file listboxes.h.

Referenced by OnGetItemAttr(), and SYMBOLS_LISTBOX().


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