KiCad PCB EDA Suite
Loading...
Searching...
No Matches
library_listbox.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <trace_helpers.h>
25
26#include <cvpcb_mainframe.h>
27#include <cvpcb_id.h>
28#include <wx/log.h>
30
31
32/***************************************/
33/* ListBox handling the library list */
34/***************************************/
35
37 ITEMS_LISTBOX_BASE( parent, id, wxDefaultPosition, wxDefaultSize, wxLC_SINGLE_SEL )
38{
39}
40
41
43{
44 return (int) m_libraryList.Count();
45}
46
47
48void LIBRARY_LISTBOX::SetString( unsigned linecount, const wxString& text )
49{
50 unsigned count = m_libraryList.Count();
51
52 if( count > 0 )
53 {
54 if( linecount >= count )
55 linecount = count - 1;
56
57 m_libraryList[linecount] = text;
58 UpdateWidth( linecount );
59 }
60}
61
62
64{
65 wxString libName;
66 int ii = GetFirstSelected();
67
68 if( ii >= 0 )
69 {
70 libName = m_libraryList[ii];
71 libName.Trim( false );
72
73 if( libName.StartsWith( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() ) )
74 libName = libName.substr( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol().length() );
75 }
76
77 return libName;
78}
79
80
81void LIBRARY_LISTBOX::AppendLine( const wxString& text )
82{
83 m_libraryList.Add( wxT( " " ) + text );
84 int lines = m_libraryList.Count();
85 SetItemCount( lines );
86}
87
88
89wxString LIBRARY_LISTBOX::OnGetItemText( long item, long column ) const
90{
91 return m_libraryList.Item( item );
92}
93
94
95void LIBRARY_LISTBOX::SetSelection( int index, bool State )
96{
97 if( index >= GetCount() )
98 index = GetCount() - 1;
99
100 if( (index >= 0) && (GetCount() > 0) )
101 {
102#ifndef __WXMAC__
103 Select( index, State );
104#endif
105 EnsureVisible( index );
106#ifdef __WXMAC__
107 Refresh();
108#endif
109 }
110}
111
112
114{
115 if( m_libraryList.Count() )
116 {
117 RefreshItems( 0L, m_libraryList.Count()-1 );
118 UpdateWidth();
119 }
120}
121
122
124{
125 m_libraryList.clear();
126}
127
128
129BEGIN_EVENT_TABLE( LIBRARY_LISTBOX, ITEMS_LISTBOX_BASE )
130 EVT_CHAR( LIBRARY_LISTBOX::OnChar )
132END_EVENT_TABLE()
133
134
135void LIBRARY_LISTBOX::OnChar( wxKeyEvent& event )
136{
137 wxLogTrace( kicadTraceKeyEvent, wxS( "LIBRARY_LISTBOX::OnChar %s" ), dump( event ) );
138
139 int key = event.GetKeyCode();
140
141 switch( key )
142 {
143 case WXK_HOME:
144 case WXK_END:
145 case WXK_UP:
146 case WXK_DOWN:
147 case WXK_PAGEUP:
148 case WXK_PAGEDOWN:
149 event.Skip();
150 return;
151
152 default:
153 break;
154 }
155
156 // Search for an item name starting by the key code:
157 key = toupper(key);
158
159 for( unsigned ii = 0; ii < m_libraryList.GetCount(); ii++ )
160 {
161 wxString text = m_libraryList.Item( ii );
162
163 // Search for the start char of the footprint name. Skip the line number.
164 text.Trim( false ); // Remove leading spaces in line
165 unsigned jj = 0;
166
167 for( ; jj < text.Len(); jj++ )
168 {
169 // skip line number
170 if( text[jj] == ' ' )
171 break;
172 }
173
174 for( ; jj < text.Len(); jj++ )
175 {
176 // skip blanks
177 if( text[jj] != ' ' )
178 break;
179 }
180
181 int start_char = toupper( text[jj] );
182
183 if( key == start_char )
184 {
185 SetSelection( ii, true ); // Ensure visible
186 break;
187 }
188 }
189
190 event.Skip();
191}
192
193
194void LIBRARY_LISTBOX::OnSelectLibrary( wxListEvent& event )
195{
196 // Apply the filter
199
200 SetFocus();
201 GetParent()->OnSelectComponent( event );
202}
The CvPcb application main window.
@ FILTER_ENABLE
Turn on the filter.
void SetFootprintFilter(FOOTPRINTS_LISTBOX::FP_FILTER_T aFilter, CVPCB_MAINFRAME::CVPCB_FILTER_ACTION aAction)
Set a filter criteria to either on/off or toggle the criteria.
void OnSelectComponent(wxListEvent &event)
Called when clicking on a component in component list window:
Base class to display symbol and footprint lists.
Definition: listboxes.h:43
void UpdateWidth(int aLine=-1)
Update the width of the column based on its contents.
virtual CVPCB_MAINFRAME * GetParent() const
void SetString(unsigned linecount, const wxString &text)
wxArrayString m_libraryList
Definition: listboxes.h:176
wxString OnGetItemText(long item, long column) const override
void OnChar(wxKeyEvent &event)
Called on a key press.
void OnSelectLibrary(wxListEvent &event)
void AppendLine(const wxString &text)
LIBRARY_LISTBOX(CVPCB_MAINFRAME *parent, wxWindowID id)
void SetSelection(int index, bool State=true)
wxString GetSelectedLibrary()
static const wxString GetPinningSymbol()
@ ID_CVPCB_LIBRARY_LIST
Definition: cvpcb_id.h:33
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxLogTrace helper definitions.