KiCad PCB EDA Suite
footprints_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) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <footprint_filter.h>
26#include <tool/tool_manager.h>
27#include <trace_helpers.h>
28#include <wx/log.h>
29#include <wx/wupdlock.h>
30
31#include <cvpcb_id.h>
32#include <cvpcb_mainframe.h>
33#include <listboxes.h>
34#include <tools/cvpcb_actions.h>
35
37 ITEMS_LISTBOX_BASE( parent, id, wxDefaultPosition, wxDefaultSize, wxLC_SINGLE_SEL|wxNO_BORDER )
38{
39}
40
41
43{
44}
45
46
48{
49 return m_footprintList.Count();
50}
51
52
53void FOOTPRINTS_LISTBOX::SetString( unsigned linecount, const wxString& text )
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}
65
66
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}
82
83
84void FOOTPRINTS_LISTBOX::AppendLine( const wxString& text )
85{
86 m_footprintList.Add( text );
87 int lines = m_footprintList.Count();
88 SetItemCount( lines );
89 UpdateWidth( lines - 1 );
90}
91
92
93wxString FOOTPRINTS_LISTBOX::OnGetItemText( long item, long column ) const
94{
95 if( item < 0 || item >= (long)m_footprintList.GetCount() )
96 return wxEmptyString;
97
98 return m_footprintList.Item( item );
99}
100
101
102void FOOTPRINTS_LISTBOX::SetSelection( int aIndex, bool aState )
103{
104 if( aIndex >= GetCount() )
105 aIndex = GetCount() - 1;
106
107 if(( aIndex >= 0) && ( GetCount() > 0) )
108 {
109 Select( aIndex, aState );
110 EnsureVisible( aIndex );
111 Refresh();
112 }
113}
114
115
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}
131
132
133void FOOTPRINTS_LISTBOX::SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName,
134 COMPONENT* aComponent,
135 const wxString &aFootPrintFilterPattern,
136 int aFilterType )
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( const FOOTPRINT_INFO& i : filter )
160 {
161 msg.Printf( wxS( "%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}
191
192
193BEGIN_EVENT_TABLE( FOOTPRINTS_LISTBOX, ITEMS_LISTBOX_BASE )
197END_EVENT_TABLE()
198
199
200void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event )
201{
202 GetParent()->RefreshFootprintViewer();
203}
204
205
206void FOOTPRINTS_LISTBOX::OnLeftDClick( wxListEvent& event )
207{
209}
210
211
212void FOOTPRINTS_LISTBOX::OnChar( wxKeyEvent& event )
213{
214 wxLogTrace( kicadTraceKeyEvent, wxS( "FOOTPRINTS_LISTBOX::OnChar %s" ), dump( event ) );
215
216 int key = event.GetKeyCode();
217
218 switch( key )
219 {
220 case WXK_HOME:
221 case WXK_END:
222 case WXK_UP:
223 case WXK_DOWN:
224 case WXK_PAGEUP:
225 case WXK_PAGEDOWN:
226 event.Skip();
227 return;
228
229 default:
230 break;
231 }
232
233 // Search for an item name starting by the key code:
234 key = toupper( key );
235
236 for( unsigned ii = 0; ii < m_footprintList.GetCount(); ii++ )
237 {
238 wxString text = m_footprintList.Item( ii );
239
240 // Search for the start char of the footprint name. Skip the line number.
241 text.Trim( false ); // Remove leading spaces in line
242 unsigned jj = 0;
243
244 for( ; jj < text.Len(); jj++ )
245 {
246 // skip line number
247 if( text[jj] == ' ' )
248 break;
249 }
250
251 for( ; jj < text.Len(); jj++ )
252 { // skip blanks
253 if( text[jj] != ' ' )
254 break;
255 }
256
257 int start_char = toupper( text[jj] );
258
259 if( key == start_char )
260 {
261 SetSelection( ii, true ); // Ensure visible
262 break;
263 }
264 }
265
266 event.Skip();
267}
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:85
int GetPinCount() const
Definition: pcb_netlist.h:151
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:148
static TOOL_ACTION associate
Definition: cvpcb_actions.h:62
The CvPcb application main window.
FOOTPRINTS_LISTBOX(CVPCB_MAINFRAME *parent, wxWindowID id)
void AppendLine(const wxString &text)
wxArrayString m_footprintList
Definition: listboxes.h:139
void OnLeftClick(wxListEvent &event)
void OnLeftDClick(wxListEvent &event)
void SetSelectedFootprint(const LIB_ID &aFPID)
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 aFilt...
@ FILTERING_BY_COMPONENT_FP_FILTERS
Definition: listboxes.h:95
void SetString(unsigned linecount, const wxString &text)
void OnChar(wxKeyEvent &event)
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 ...
void SetSelection(int aIndex, bool aState=true)
Footprint display filter.
Holds a list of FOOTPRINT_INFO objects, along with a list of IO_ERRORs or PARSE_ERRORs that were thro...
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.
void DeselectAll()
Remove all selection in lists which can have more than one item selected.
virtual CVPCB_MAINFRAME * GetParent() const
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
UTF8 Format() const
Definition: lib_id.cpp:117
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
wxString wx_str() const
Definition: utf8.cpp:46
@ ID_CVPCB_FOOTPRINT_LIST
Definition: cvpcb_id.h:32
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.