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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <footprint_filter.h>
22#include <tool/tool_manager.h>
23#include <trace_helpers.h>
24#include <wx/log.h>
25#include <wx/wupdlock.h>
26
27#include <cvpcb_id.h>
28#include <cvpcb_mainframe.h>
29#include <tools/cvpcb_actions.h>
30
32 ITEMS_LISTBOX_BASE( parent, id, wxDefaultPosition, wxDefaultSize, wxLC_SINGLE_SEL | wxNO_BORDER )
33{
34}
35
36
38{
39 return (int) m_footprintList.Count();
40}
41
42
43void FOOTPRINTS_LISTBOX::SetString( unsigned linecount, const wxString& text )
44{
45 unsigned count = m_footprintList.Count();
46
47 if( count > 0 )
48 {
49 if( linecount >= count )
50 linecount = count - 1;
51
52 m_footprintList[linecount] = text;
53 }
54
55 UpdateWidth( linecount );
56}
57
58
60{
61 wxString footprintName;
62 int ii = GetFirstSelected();
63
64 if( ii >= 0 && ii < (int)m_footprintList.size() )
65 {
66 wxString msg = m_footprintList[ii];
67 msg.Trim( true );
68 msg.Trim( false );
69 footprintName = msg.AfterFirst( wxChar( ' ' ) );
70 }
71
72 return footprintName;
73}
74
75
76wxString FOOTPRINTS_LISTBOX::OnGetItemText( long item, long column ) const
77{
78 if( item < 0 || item >= (long)m_footprintList.GetCount() )
79 return wxEmptyString;
80
81 return m_footprintList.Item( item );
82}
83
84
85void FOOTPRINTS_LISTBOX::SetSelection( int aIndex, bool aState )
86{
87 if( aIndex >= GetCount() )
88 aIndex = GetCount() - 1;
89
90 if( aIndex >= 0 && GetCount() > 0)
91 {
92 Select( aIndex, aState );
93 EnsureVisible( aIndex );
94 Refresh();
95 }
96}
97
98
100{
101 wxString id = aFPID.Format().wx_str();
102
103 for( int i = 0; i < GetCount(); ++i )
104 {
105 wxString candidate = m_footprintList.Item( i ).substr( 4 );
106
107 if( candidate.CmpNoCase( id ) == 0 )
108 {
109 SetSelection( i, true );
110 return;
111 }
112 }
113}
114
115
116void FOOTPRINTS_LISTBOX::SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName,
117 COMPONENT* aComponent,
118 const wxString &aFootPrintFilterPattern,
119 int aFilterType )
120{
121 wxArrayString newList;
122 wxString msg;
123 wxString oldSelection;
124
125 FOOTPRINT_FILTER filter( aList );
126
127 if( aFilterType & FILTERING_BY_COMPONENT_FP_FILTERS && aComponent )
128 filter.FilterByFootprintFilters( aComponent->GetFootprintFilters() );
129
130 if( aFilterType & FILTERING_BY_PIN_COUNT && aComponent )
131 {
132 int pc = aComponent->GetPinCount();
133 wxLogTrace( "CVPCB_PINCOUNT",
134 wxT( "FOOTPRINTS_LISTBOX::SetFootprints: ref='%s' pinCount filter=%d" ),
135 aComponent->GetReference(), pc );
136 filter.FilterByPinCount( pc );
137 }
138
139 if( aFilterType & FILTERING_BY_LIBRARY )
140 filter.FilterByLibrary( aLibName );
141
142 if( !aFootPrintFilterPattern.IsEmpty() )
143 filter.FilterByTextPattern( aFootPrintFilterPattern );
144
145 if( GetSelection() >= 0 && GetSelection() < (int)m_footprintList.GetCount() )
146 oldSelection = m_footprintList[ GetSelection() ];
147
148 for( const FOOTPRINT_INFO& i : filter )
149 {
150 msg.Printf( wxS( "%3d %s:%s" ),
151 int( newList.GetCount() + 1 ),
152 i.GetLibNickname(),
153 i.GetFootprintName() );
154 newList.Add( msg );
155 }
156
157 if( newList == m_footprintList )
158 return;
159
160 m_footprintList = newList;
161
162 int selection = m_footprintList.Index( oldSelection );
163
164 if( selection == wxNOT_FOUND )
165 selection = 0;
166
167 // Do NOT call wxSafeYield() here. It disables all top-level windows while it runs, which
168 // greys out the search control and drops keystrokes mid-filter. The update locker and
169 // virtual-list refresh below keep the list consistent without a yield.
170 DeselectAll();
171 wxWindowUpdateLocker freeze( this );
172 DeleteAllItems();
173
174 if( m_footprintList.GetCount() )
175 {
176 SetItemCount( m_footprintList.GetCount() );
177 SetSelection( selection, true );
178 RefreshItems( 0L, m_footprintList.GetCount() - 1 );
179 UpdateWidth();
180 }
181}
182
183
184BEGIN_EVENT_TABLE( FOOTPRINTS_LISTBOX, ITEMS_LISTBOX_BASE )
188END_EVENT_TABLE()
189
190
191void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event )
192{
193 if( m_isClosing )
194 return;
195
196 GetParent()->RefreshFootprintViewer();
197}
198
199
200void FOOTPRINTS_LISTBOX::OnLeftDClick( wxListEvent& event )
201{
202 if( m_isClosing )
203 return;
204
206}
207
208
209void FOOTPRINTS_LISTBOX::OnChar( wxKeyEvent& event )
210{
211 if( m_isClosing )
212 return;
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 {
253 // skip blanks
254 if( text[jj] != ' ' )
255 break;
256 }
257
258 int start_char = toupper( text[jj] );
259
260 if( key == start_char )
261 {
262 SetSelection( ii, true ); // Ensure visible
263 break;
264 }
265 }
266
267 event.Skip();
268}
Store all of the related component information found in a netlist.
const wxString & GetReference() const
const wxArrayString & GetFootprintFilters() const
static TOOL_ACTION associate
The CvPcb application main window.
FOOTPRINTS_LISTBOX(CVPCB_MAINFRAME *parent, wxWindowID id)
wxArrayString m_footprintList
Definition listboxes.h:140
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:97
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:39
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.
ITEMS_LISTBOX_BASE(CVPCB_MAINFRAME *aParent, wxWindowID aId, const wxPoint &aLocation=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=0)
virtual CVPCB_MAINFRAME * GetParent() const
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
UTF8 Format() const
Definition lib_id.cpp:132
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
wxString wx_str() const
Definition utf8.cpp:41
@ ID_CVPCB_FOOTPRINT_LIST
Definition cvpcb_id.h:28
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxLogTrace helper definitions.