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