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 {
136 int pc = aComponent->GetPinCount();
137 wxLogTrace( "CVPCB_PINCOUNT",
138 wxT( "FOOTPRINTS_LISTBOX::SetFootprints: ref='%s' pinCount filter=%d" ),
139 aComponent->GetReference(), pc );
140 filter.FilterByPinCount( pc );
141 }
142
143 if( aFilterType & FILTERING_BY_LIBRARY )
144 filter.FilterByLibrary( aLibName );
145
146 if( !aFootPrintFilterPattern.IsEmpty() )
147 filter.FilterByTextPattern( aFootPrintFilterPattern );
148
149 if( GetSelection() >= 0 && GetSelection() < (int)m_footprintList.GetCount() )
150 oldSelection = m_footprintList[ GetSelection() ];
151
152 for( const FOOTPRINT_INFO& i : filter )
153 {
154 msg.Printf( wxS( "%3d %s:%s" ),
155 int( newList.GetCount() + 1 ),
156 i.GetLibNickname(),
157 i.GetFootprintName() );
158 newList.Add( msg );
159 }
160
161 if( newList == m_footprintList )
162 return;
163
164 m_footprintList = newList;
165
166 int selection = m_footprintList.Index( oldSelection );
167
168 if( selection == wxNOT_FOUND )
169 selection = 0;
170
171 DeselectAll();
172 wxSafeYield();
173 wxWindowUpdateLocker freeze( this );
174 DeleteAllItems();
175
176 if( m_footprintList.GetCount() )
177 {
178 SetItemCount( m_footprintList.GetCount() );
179 SetSelection( selection, true );
180 RefreshItems( 0L, m_footprintList.GetCount() - 1 );
181 UpdateWidth();
182 }
183}
184
185
186BEGIN_EVENT_TABLE( FOOTPRINTS_LISTBOX, ITEMS_LISTBOX_BASE )
190END_EVENT_TABLE()
191
192
193void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event )
194{
195 if( m_isClosing )
196 return;
197
198 GetParent()->RefreshFootprintViewer();
199}
200
201
202void FOOTPRINTS_LISTBOX::OnLeftDClick( wxListEvent& event )
203{
204 if( m_isClosing )
205 return;
206
208}
209
210
211void FOOTPRINTS_LISTBOX::OnChar( wxKeyEvent& event )
212{
213 if( m_isClosing )
214 return;
215
216 wxLogTrace( kicadTraceKeyEvent, wxS( "FOOTPRINTS_LISTBOX::OnChar %s" ), dump( event ) );
217
218 int key = event.GetKeyCode();
219
220 switch( key )
221 {
222 case WXK_HOME:
223 case WXK_END:
224 case WXK_UP:
225 case WXK_DOWN:
226 case WXK_PAGEUP:
227 case WXK_PAGEDOWN:
228 event.Skip();
229 return;
230
231 default:
232 break;
233 }
234
235 // Search for an item name starting by the key code:
236 key = toupper( key );
237
238 for( unsigned ii = 0; ii < m_footprintList.GetCount(); ii++ )
239 {
240 wxString text = m_footprintList.Item( ii );
241
242 // Search for the start char of the footprint name. Skip the line number.
243 text.Trim( false ); // Remove leading spaces in line
244 unsigned jj = 0;
245
246 for( ; jj < text.Len(); jj++ )
247 {
248 // skip line number
249 if( text[jj] == ' ' )
250 break;
251 }
252
253 for( ; jj < text.Len(); jj++ )
254 {
255 // skip blanks
256 if( text[jj] != ' ' )
257 break;
258 }
259
260 int start_char = toupper( text[jj] );
261
262 if( key == start_char )
263 {
264 SetSelection( ii, true ); // Ensure visible
265 break;
266 }
267 }
268
269 event.Skip();
270}
Store all of the related footprint information found in a netlist.
const wxString & GetReference() const
int GetPinCount() 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: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.
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:49
UTF8 Format() const
Definition lib_id.cpp:119
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: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.