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 DeselectAll();
168 wxSafeYield();
169 wxWindowUpdateLocker freeze( this );
170 DeleteAllItems();
171
172 if( m_footprintList.GetCount() )
173 {
174 SetItemCount( m_footprintList.GetCount() );
175 SetSelection( selection, true );
176 RefreshItems( 0L, m_footprintList.GetCount() - 1 );
177 UpdateWidth();
178 }
179}
180
181
182BEGIN_EVENT_TABLE( FOOTPRINTS_LISTBOX, ITEMS_LISTBOX_BASE )
186END_EVENT_TABLE()
187
188
189void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event )
190{
191 if( m_isClosing )
192 return;
193
194 GetParent()->RefreshFootprintViewer();
195}
196
197
198void FOOTPRINTS_LISTBOX::OnLeftDClick( wxListEvent& event )
199{
200 if( m_isClosing )
201 return;
202
204}
205
206
207void FOOTPRINTS_LISTBOX::OnChar( wxKeyEvent& event )
208{
209 if( m_isClosing )
210 return;
211
212 wxLogTrace( kicadTraceKeyEvent, wxS( "FOOTPRINTS_LISTBOX::OnChar %s" ), dump( event ) );
213
214 int key = event.GetKeyCode();
215
216 switch( key )
217 {
218 case WXK_HOME:
219 case WXK_END:
220 case WXK_UP:
221 case WXK_DOWN:
222 case WXK_PAGEUP:
223 case WXK_PAGEDOWN:
224 event.Skip();
225 return;
226
227 default:
228 break;
229 }
230
231 // Search for an item name starting by the key code:
232 key = toupper( key );
233
234 for( unsigned ii = 0; ii < m_footprintList.GetCount(); ii++ )
235 {
236 wxString text = m_footprintList.Item( ii );
237
238 // Search for the start char of the footprint name. Skip the line number.
239 text.Trim( false ); // Remove leading spaces in line
240 unsigned jj = 0;
241
242 for( ; jj < text.Len(); jj++ )
243 {
244 // skip line number
245 if( text[jj] == ' ' )
246 break;
247 }
248
249 for( ; jj < text.Len(); jj++ )
250 {
251 // skip blanks
252 if( text[jj] != ' ' )
253 break;
254 }
255
256 int start_char = toupper( text[jj] );
257
258 if( key == start_char )
259 {
260 SetSelection( ii, true ); // Ensure visible
261 break;
262 }
263 }
264
265 event.Skip();
266}
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:115
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.