KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2024 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 <tools/cvpcb_actions.h>
34
36 ITEMS_LISTBOX_BASE( parent, id, wxDefaultPosition, wxDefaultSize,
37 wxLC_SINGLE_SEL | wxNO_BORDER )
38{
39}
40
41
43{
44 return (int) m_footprintList.Count();
45}
46
47
48void FOOTPRINTS_LISTBOX::SetString( unsigned linecount, const wxString& text )
49{
50 unsigned count = m_footprintList.Count();
51
52 if( count > 0 )
53 {
54 if( linecount >= count )
55 linecount = count - 1;
56
57 m_footprintList[linecount] = text;
58 }
59
60 UpdateWidth( linecount );
61}
62
63
65{
66 wxString footprintName;
67 int ii = GetFirstSelected();
68
69 if( ii >= 0 )
70 {
71 wxString msg = m_footprintList[ii];
72 msg.Trim( true );
73 msg.Trim( false );
74 footprintName = msg.AfterFirst( wxChar( ' ' ) );
75 }
76
77 return footprintName;
78}
79
80
81wxString FOOTPRINTS_LISTBOX::OnGetItemText( long item, long column ) const
82{
83 if( item < 0 || item >= (long)m_footprintList.GetCount() )
84 return wxEmptyString;
85
86 return m_footprintList.Item( item );
87}
88
89
90void FOOTPRINTS_LISTBOX::SetSelection( int aIndex, bool aState )
91{
92 if( aIndex >= GetCount() )
93 aIndex = GetCount() - 1;
94
95 if( aIndex >= 0 && GetCount() > 0)
96 {
97 Select( aIndex, aState );
98 EnsureVisible( aIndex );
99 Refresh();
100 }
101}
102
103
105{
106 wxString id = aFPID.Format().wx_str();
107
108 for( int i = 0; i < GetCount(); ++i )
109 {
110 wxString candidate = m_footprintList.Item( i ).substr( 4 );
111
112 if( candidate.CmpNoCase( id ) == 0 )
113 {
114 SetSelection( i, true );
115 return;
116 }
117 }
118}
119
120
121void FOOTPRINTS_LISTBOX::SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName,
122 COMPONENT* aComponent,
123 const wxString &aFootPrintFilterPattern,
124 int aFilterType )
125{
126 wxArrayString newList;
127 wxString msg;
128 wxString oldSelection;
129
130 FOOTPRINT_FILTER filter( aList );
131
132 if( aFilterType & FILTERING_BY_COMPONENT_FP_FILTERS && aComponent )
133 filter.FilterByFootprintFilters( aComponent->GetFootprintFilters() );
134
135 if( aFilterType & FILTERING_BY_PIN_COUNT && aComponent )
136 filter.FilterByPinCount( aComponent->GetPinCount() );
137
138 if( aFilterType & FILTERING_BY_LIBRARY )
139 filter.FilterByLibrary( aLibName );
140
141 if( !aFootPrintFilterPattern.IsEmpty() )
142 filter.FilterByTextPattern( aFootPrintFilterPattern );
143
144 if( GetSelection() >= 0 && GetSelection() < (int)m_footprintList.GetCount() )
145 oldSelection = m_footprintList[ GetSelection() ];
146
147 for( const FOOTPRINT_INFO& i : filter )
148 {
149 msg.Printf( wxS( "%3d %s:%s" ),
150 int( newList.GetCount() + 1 ),
151 i.GetLibNickname(),
152 i.GetFootprintName() );
153 newList.Add( msg );
154 }
155
156 if( newList == m_footprintList )
157 return;
158
159 m_footprintList = newList;
160
161 int selection = m_footprintList.Index( oldSelection );
162
163 if( selection == wxNOT_FOUND )
164 selection = 0;
165
166 DeselectAll();
167 wxSafeYield();
168 wxWindowUpdateLocker freeze( this );
169 DeleteAllItems();
170
171 if( m_footprintList.GetCount() )
172 {
173 SetItemCount( m_footprintList.GetCount() );
174 SetSelection( selection, true );
175 RefreshItems( 0L, m_footprintList.GetCount()-1 );
176 UpdateWidth();
177 }
178}
179
180
181BEGIN_EVENT_TABLE( FOOTPRINTS_LISTBOX, ITEMS_LISTBOX_BASE )
185END_EVENT_TABLE()
186
187
188void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event )
189{
190 GetParent()->RefreshFootprintViewer();
191}
192
193
194void FOOTPRINTS_LISTBOX::OnLeftDClick( wxListEvent& event )
195{
197}
198
199
200void FOOTPRINTS_LISTBOX::OnChar( wxKeyEvent& event )
201{
202 wxLogTrace( kicadTraceKeyEvent, wxS( "FOOTPRINTS_LISTBOX::OnChar %s" ), dump( event ) );
203
204 int key = event.GetKeyCode();
205
206 switch( key )
207 {
208 case WXK_HOME:
209 case WXK_END:
210 case WXK_UP:
211 case WXK_DOWN:
212 case WXK_PAGEUP:
213 case WXK_PAGEDOWN:
214 event.Skip();
215 return;
216
217 default:
218 break;
219 }
220
221 // Search for an item name starting by the key code:
222 key = toupper( key );
223
224 for( unsigned ii = 0; ii < m_footprintList.GetCount(); ii++ )
225 {
226 wxString text = m_footprintList.Item( ii );
227
228 // Search for the start char of the footprint name. Skip the line number.
229 text.Trim( false ); // Remove leading spaces in line
230 unsigned jj = 0;
231
232 for( ; jj < text.Len(); jj++ )
233 {
234 // skip line number
235 if( text[jj] == ' ' )
236 break;
237 }
238
239 for( ; jj < text.Len(); jj++ )
240 {
241 // skip blanks
242 if( text[jj] != ' ' )
243 break;
244 }
245
246 int start_char = toupper( text[jj] );
247
248 if( key == start_char )
249 {
250 SetSelection( ii, true ); // Ensure visible
251 break;
252 }
253 }
254
255 event.Skip();
256}
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:86
int GetPinCount() const
Definition: pcb_netlist.h:158
const wxArrayString & GetFootprintFilters() const
Definition: pcb_netlist.h:155
static TOOL_ACTION associate
Definition: cvpcb_actions.h:62
The CvPcb application main window.
FOOTPRINTS_LISTBOX(CVPCB_MAINFRAME *parent, wxWindowID id)
wxArrayString m_footprintList
Definition: listboxes.h:138
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:118
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
wxString wx_str() const
Definition: utf8.cpp:45
@ 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.