2013-04-25 12:29:35 -04:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-01-06 08:36:08 +01:00
|
|
|
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2024-05-15 10:32:40 +01:00
|
|
|
* Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-04-25 12:29:35 -04:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2019-07-18 23:47:01 +02:00
|
|
|
#include <footprint_filter.h>
|
|
|
|
#include <tool/tool_manager.h>
|
2019-08-09 00:11:59 +02:00
|
|
|
#include <trace_helpers.h>
|
2021-06-03 08:11:15 -04:00
|
|
|
#include <wx/log.h>
|
2017-03-22 20:59:25 -04:00
|
|
|
#include <wx/wupdlock.h>
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2019-07-18 23:47:01 +02:00
|
|
|
#include <cvpcb_id.h>
|
2012-01-22 22:33:36 -06:00
|
|
|
#include <cvpcb_mainframe.h>
|
2019-07-18 23:47:01 +02:00
|
|
|
#include <tools/cvpcb_actions.h>
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2020-01-11 21:14:09 +00:00
|
|
|
FOOTPRINTS_LISTBOX::FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id ) :
|
2024-05-15 10:32:40 +01:00
|
|
|
ITEMS_LISTBOX_BASE( parent, id, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxLC_SINGLE_SEL | wxNO_BORDER )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int FOOTPRINTS_LISTBOX::GetCount()
|
|
|
|
{
|
2024-05-15 10:32:40 +01:00
|
|
|
return (int) m_footprintList.Count();
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINTS_LISTBOX::SetString( unsigned linecount, const wxString& text )
|
|
|
|
{
|
2014-07-30 22:04:34 -05:00
|
|
|
unsigned count = m_footprintList.Count();
|
2024-05-15 10:32:40 +01:00
|
|
|
|
2014-07-30 22:04:34 -05:00
|
|
|
if( count > 0 )
|
|
|
|
{
|
|
|
|
if( linecount >= count )
|
|
|
|
linecount = count - 1;
|
2020-01-11 21:14:09 +00:00
|
|
|
|
2013-06-06 11:37:48 -04:00
|
|
|
m_footprintList[linecount] = text;
|
2014-07-30 22:04:34 -05:00
|
|
|
}
|
2024-05-15 10:32:40 +01:00
|
|
|
|
2014-11-12 11:46:40 +01:00
|
|
|
UpdateWidth( linecount );
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString FOOTPRINTS_LISTBOX::GetSelectedFootprint()
|
|
|
|
{
|
2012-03-16 22:01:53 -05:00
|
|
|
wxString footprintName;
|
2009-08-20 11:44:06 +00:00
|
|
|
int ii = GetFirstSelected();
|
|
|
|
|
|
|
|
if( ii >= 0 )
|
|
|
|
{
|
2013-06-06 11:37:48 -04:00
|
|
|
wxString msg = m_footprintList[ii];
|
2010-11-07 21:06:07 +01:00
|
|
|
msg.Trim( true );
|
|
|
|
msg.Trim( false );
|
2012-03-16 22:01:53 -05:00
|
|
|
footprintName = msg.AfterFirst( wxChar( ' ' ) );
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
2012-03-16 22:01:53 -05:00
|
|
|
return footprintName;
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString FOOTPRINTS_LISTBOX::OnGetItemText( long item, long column ) const
|
|
|
|
{
|
2013-06-06 11:37:48 -04:00
|
|
|
if( item < 0 || item >= (long)m_footprintList.GetCount() )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
return m_footprintList.Item( item );
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-25 13:29:18 +01:00
|
|
|
void FOOTPRINTS_LISTBOX::SetSelection( int aIndex, bool aState )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2022-07-25 13:29:18 +01:00
|
|
|
if( aIndex >= GetCount() )
|
|
|
|
aIndex = GetCount() - 1;
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2024-05-15 10:32:40 +01:00
|
|
|
if( aIndex >= 0 && GetCount() > 0)
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2022-07-25 13:29:18 +01:00
|
|
|
Select( aIndex, aState );
|
|
|
|
EnsureVisible( aIndex );
|
2009-08-20 11:44:06 +00:00
|
|
|
Refresh();
|
2018-09-22 16:20:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINTS_LISTBOX::SetSelectedFootprint( const LIB_ID& aFPID )
|
|
|
|
{
|
2020-01-11 21:14:09 +00:00
|
|
|
wxString id = aFPID.Format().wx_str();
|
2018-09-22 16:20:45 +01:00
|
|
|
|
2018-09-16 15:47:19 +02:00
|
|
|
for( int i = 0; i < GetCount(); ++i )
|
2018-09-22 16:20:45 +01:00
|
|
|
{
|
|
|
|
wxString candidate = m_footprintList.Item( i ).substr( 4 );
|
|
|
|
|
|
|
|
if( candidate.CmpNoCase( id ) == 0 )
|
|
|
|
{
|
|
|
|
SetSelection( i, true );
|
|
|
|
return;
|
|
|
|
}
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-06 11:37:48 -04:00
|
|
|
void FOOTPRINTS_LISTBOX::SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName,
|
2016-02-25 14:57:59 +01:00
|
|
|
COMPONENT* aComponent,
|
|
|
|
const wxString &aFootPrintFilterPattern,
|
|
|
|
int aFilterType )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2013-06-06 11:37:48 -04:00
|
|
|
wxArrayString newList;
|
|
|
|
wxString msg;
|
|
|
|
wxString oldSelection;
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2017-03-22 20:59:25 -04:00
|
|
|
FOOTPRINT_FILTER filter( aList );
|
|
|
|
|
2019-09-03 19:28:54 +01:00
|
|
|
if( aFilterType & FILTERING_BY_COMPONENT_FP_FILTERS && aComponent )
|
2017-03-22 20:59:25 -04:00
|
|
|
filter.FilterByFootprintFilters( aComponent->GetFootprintFilters() );
|
|
|
|
|
2017-03-26 18:48:14 -04:00
|
|
|
if( aFilterType & FILTERING_BY_PIN_COUNT && aComponent )
|
2018-03-26 19:55:59 +01:00
|
|
|
filter.FilterByPinCount( aComponent->GetPinCount() );
|
2017-03-22 20:59:25 -04:00
|
|
|
|
|
|
|
if( aFilterType & FILTERING_BY_LIBRARY )
|
|
|
|
filter.FilterByLibrary( aLibName );
|
|
|
|
|
2020-07-09 14:21:28 +01:00
|
|
|
if( !aFootPrintFilterPattern.IsEmpty() )
|
2019-09-03 19:28:54 +01:00
|
|
|
filter.FilterByTextPattern( aFootPrintFilterPattern );
|
2016-02-25 14:57:59 +01:00
|
|
|
|
2013-06-06 11:37:48 -04:00
|
|
|
if( GetSelection() >= 0 && GetSelection() < (int)m_footprintList.GetCount() )
|
|
|
|
oldSelection = m_footprintList[ GetSelection() ];
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2022-07-25 13:29:18 +01:00
|
|
|
for( const FOOTPRINT_INFO& i : filter )
|
2011-02-22 18:59:46 +01:00
|
|
|
{
|
2023-01-16 23:14:38 -05:00
|
|
|
msg.Printf( wxS( "%3d %s:%s" ),
|
2020-01-11 21:14:09 +00:00
|
|
|
int( newList.GetCount() + 1 ),
|
|
|
|
i.GetLibNickname(),
|
|
|
|
i.GetFootprintName() );
|
2013-06-06 11:37:48 -04:00
|
|
|
newList.Add( msg );
|
2012-03-15 14:20:22 -04:00
|
|
|
}
|
|
|
|
|
2013-06-06 11:37:48 -04:00
|
|
|
if( newList == m_footprintList )
|
|
|
|
return;
|
2013-05-31 13:33:46 -04:00
|
|
|
|
2013-06-06 11:37:48 -04:00
|
|
|
m_footprintList = newList;
|
2013-04-25 12:29:35 -04:00
|
|
|
|
2013-06-06 11:37:48 -04:00
|
|
|
int selection = m_footprintList.Index( oldSelection );
|
2013-05-31 13:33:46 -04:00
|
|
|
|
2013-06-06 11:37:48 -04:00
|
|
|
if( selection == wxNOT_FOUND )
|
|
|
|
selection = 0;
|
2013-05-31 13:33:46 -04:00
|
|
|
|
2021-06-22 22:24:33 +01:00
|
|
|
DeselectAll();
|
2021-08-06 13:33:14 +02:00
|
|
|
wxSafeYield();
|
2017-03-22 20:59:25 -04:00
|
|
|
wxWindowUpdateLocker freeze( this );
|
2013-06-06 11:37:48 -04:00
|
|
|
DeleteAllItems();
|
2013-09-14 16:33:22 -04:00
|
|
|
|
|
|
|
if( m_footprintList.GetCount() )
|
|
|
|
{
|
|
|
|
SetItemCount( m_footprintList.GetCount() );
|
|
|
|
SetSelection( selection, true );
|
|
|
|
RefreshItems( 0L, m_footprintList.GetCount()-1 );
|
2014-11-12 11:46:40 +01:00
|
|
|
UpdateWidth();
|
2013-09-14 16:33:22 -04:00
|
|
|
}
|
2013-05-31 13:33:46 -04:00
|
|
|
}
|
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE( FOOTPRINTS_LISTBOX, ITEMS_LISTBOX_BASE )
|
2013-04-25 12:29:35 -04:00
|
|
|
EVT_CHAR( FOOTPRINTS_LISTBOX::OnChar )
|
2013-06-06 11:37:48 -04:00
|
|
|
EVT_LIST_ITEM_SELECTED( ID_CVPCB_FOOTPRINT_LIST, FOOTPRINTS_LISTBOX::OnLeftClick )
|
|
|
|
EVT_LIST_ITEM_ACTIVATED( ID_CVPCB_FOOTPRINT_LIST, FOOTPRINTS_LISTBOX::OnLeftDClick )
|
2009-08-20 11:44:06 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event )
|
|
|
|
{
|
2022-07-25 13:29:18 +01:00
|
|
|
GetParent()->RefreshFootprintViewer();
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINTS_LISTBOX::OnLeftDClick( wxListEvent& event )
|
|
|
|
{
|
2023-06-26 23:16:51 +01:00
|
|
|
GetParent()->GetToolManager()->RunAction( CVPCB_ACTIONS::associate );
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINTS_LISTBOX::OnChar( wxKeyEvent& event )
|
|
|
|
{
|
2023-01-16 23:14:38 -05:00
|
|
|
wxLogTrace( kicadTraceKeyEvent, wxS( "FOOTPRINTS_LISTBOX::OnChar %s" ), dump( event ) );
|
2019-08-09 00:11:59 +02:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
int key = event.GetKeyCode();
|
2013-04-25 12:29:35 -04:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
switch( key )
|
|
|
|
{
|
2013-06-06 11:37:48 -04:00
|
|
|
case WXK_HOME:
|
|
|
|
case WXK_END:
|
|
|
|
case WXK_UP:
|
|
|
|
case WXK_DOWN:
|
|
|
|
case WXK_PAGEUP:
|
|
|
|
case WXK_PAGEDOWN:
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
2013-04-25 12:29:35 -04:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
// Search for an item name starting by the key code:
|
2013-06-06 11:37:48 -04:00
|
|
|
key = toupper( key );
|
2013-04-25 12:29:35 -04:00
|
|
|
|
2013-06-06 11:37:48 -04:00
|
|
|
for( unsigned ii = 0; ii < m_footprintList.GetCount(); ii++ )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2013-06-06 11:37:48 -04:00
|
|
|
wxString text = m_footprintList.Item( ii );
|
2013-04-25 12:29:35 -04:00
|
|
|
|
2013-06-06 11:37:48 -04:00
|
|
|
// Search for the start char of the footprint name. Skip the line number.
|
|
|
|
text.Trim( false ); // Remove leading spaces in line
|
2009-08-20 11:44:06 +00:00
|
|
|
unsigned jj = 0;
|
2013-04-25 12:29:35 -04:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
for( ; jj < text.Len(); jj++ )
|
2012-03-16 22:01:53 -05:00
|
|
|
{
|
|
|
|
// skip line number
|
2009-08-20 11:44:06 +00:00
|
|
|
if( text[jj] == ' ' )
|
|
|
|
break;
|
|
|
|
}
|
2012-03-16 22:01:53 -05:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
for( ; jj < text.Len(); jj++ )
|
2024-05-15 10:32:40 +01:00
|
|
|
{
|
|
|
|
// skip blanks
|
2009-08-20 11:44:06 +00:00
|
|
|
if( text[jj] != ' ' )
|
|
|
|
break;
|
|
|
|
}
|
2012-03-16 22:01:53 -05:00
|
|
|
|
|
|
|
int start_char = toupper( text[jj] );
|
2013-04-25 12:29:35 -04:00
|
|
|
|
2012-03-16 22:01:53 -05:00
|
|
|
if( key == start_char )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
|
|
|
SetSelection( ii, true ); // Ensure visible
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-10-14 09:18:48 -04:00
|
|
|
|
|
|
|
event.Skip();
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|