2013-04-25 16:29:35 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-02-21 18:27:47 +00:00
|
|
|
/**
|
|
|
|
* @file class_footprints_listbox.cpp
|
2013-04-25 16:29:35 +00:00
|
|
|
* class to display the list of available footprints
|
2011-02-21 18:27:47 +00:00
|
|
|
*/
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <macros.h>
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <cvpcb.h>
|
|
|
|
#include <cvpcb_mainframe.h>
|
|
|
|
#include <cvstruct.h>
|
2009-08-20 11:44:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***************************************/
|
|
|
|
/* ListBox handling the footprint list */
|
|
|
|
/***************************************/
|
|
|
|
|
2011-02-05 16:15:48 +00:00
|
|
|
FOOTPRINTS_LISTBOX::FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent,
|
2009-08-20 11:44:06 +00:00
|
|
|
wxWindowID id, const wxPoint& loc,
|
|
|
|
const wxSize& size,
|
|
|
|
int nbitems, wxString choice[] ) :
|
|
|
|
ITEMS_LISTBOX_BASE( parent, id, loc, size )
|
|
|
|
{
|
|
|
|
m_UseFootprintFullList = true;
|
|
|
|
m_ActiveFootprintList = NULL;
|
2010-11-07 20:06:07 +00:00
|
|
|
SetActiveFootprintList( true );
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FOOTPRINTS_LISTBOX::~FOOTPRINTS_LISTBOX()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return number of items
|
|
|
|
*/
|
|
|
|
int FOOTPRINTS_LISTBOX::GetCount()
|
|
|
|
{
|
|
|
|
return m_ActiveFootprintList->Count();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Change an item text
|
|
|
|
*/
|
|
|
|
void FOOTPRINTS_LISTBOX::SetString( unsigned linecount, const wxString& text )
|
|
|
|
{
|
|
|
|
if( linecount >= m_ActiveFootprintList->Count() )
|
|
|
|
linecount = m_ActiveFootprintList->Count() - 1;
|
|
|
|
if( linecount >= 0 )
|
|
|
|
(*m_ActiveFootprintList)[linecount] = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString FOOTPRINTS_LISTBOX::GetSelectedFootprint()
|
|
|
|
{
|
2012-03-17 03:01:53 +00:00
|
|
|
wxString footprintName;
|
2009-08-20 11:44:06 +00:00
|
|
|
int ii = GetFirstSelected();
|
|
|
|
|
|
|
|
if( ii >= 0 )
|
|
|
|
{
|
|
|
|
wxString msg = (*m_ActiveFootprintList)[ii];
|
2010-11-07 20:06:07 +00:00
|
|
|
msg.Trim( true );
|
|
|
|
msg.Trim( false );
|
2012-03-17 03:01:53 +00:00
|
|
|
footprintName = msg.AfterFirst( wxChar( ' ' ) );
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 03:01:53 +00:00
|
|
|
return footprintName;
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINTS_LISTBOX::AppendLine( const wxString& text )
|
|
|
|
{
|
|
|
|
m_ActiveFootprintList->Add( text );
|
|
|
|
SetItemCount( m_ActiveFootprintList->Count() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Overlaid function: MUST be provided in wxLC_VIRTUAL mode
|
|
|
|
* because real data is not handled by ITEMS_LISTBOX_BASE
|
|
|
|
*/
|
|
|
|
wxString FOOTPRINTS_LISTBOX::OnGetItemText( long item, long column ) const
|
|
|
|
{
|
|
|
|
return m_ActiveFootprintList->Item( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable or disable an item
|
|
|
|
*/
|
|
|
|
void FOOTPRINTS_LISTBOX::SetSelection( unsigned index, bool State )
|
|
|
|
{
|
|
|
|
if( (int) index >= GetCount() )
|
|
|
|
index = GetCount() - 1;
|
|
|
|
|
|
|
|
if( (index >= 0) && (GetCount() > 0) )
|
|
|
|
{
|
|
|
|
#ifndef __WXMAC__
|
|
|
|
Select( index, State );
|
|
|
|
#endif
|
|
|
|
EnsureVisible( index );
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
Refresh();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINTS_LISTBOX::SetFootprintFullList( FOOTPRINT_LIST& list )
|
|
|
|
{
|
|
|
|
wxString msg;
|
2012-03-17 03:01:53 +00:00
|
|
|
int oldSelection = GetSelection();
|
2009-08-20 11:44:06 +00:00
|
|
|
|
|
|
|
m_FullFootprintList.Clear();
|
|
|
|
|
2011-02-22 17:59:46 +00:00
|
|
|
for( unsigned ii = 0; ii < list.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
FOOTPRINT_INFO & footprint = list.GetItem(ii);
|
2013-04-14 11:02:19 +00:00
|
|
|
msg.Printf( wxT( "%3zu %s" ), m_FullFootprintList.GetCount() + 1,
|
2011-02-22 17:59:46 +00:00
|
|
|
GetChars(footprint.m_Module) );
|
2009-08-20 11:44:06 +00:00
|
|
|
m_FullFootprintList.Add( msg );
|
|
|
|
}
|
|
|
|
|
2010-11-07 20:06:07 +00:00
|
|
|
SetActiveFootprintList( true );
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2012-03-17 03:01:53 +00:00
|
|
|
if( GetCount() == 0 || oldSelection < 0 || oldSelection >= GetCount() )
|
2010-11-07 20:06:07 +00:00
|
|
|
SetSelection( 0, true );
|
2009-08-20 11:44:06 +00:00
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
void FOOTPRINTS_LISTBOX::SetFootprintFilteredList( COMPONENT* aComponent,
|
2009-08-20 11:44:06 +00:00
|
|
|
FOOTPRINT_LIST& list )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
unsigned jj;
|
|
|
|
int OldSelection = GetSelection();
|
2012-03-17 03:01:53 +00:00
|
|
|
bool hasItem = false;
|
2009-08-20 11:44:06 +00:00
|
|
|
|
|
|
|
m_FilteredFootprintList.Clear();
|
|
|
|
|
2011-02-22 17:59:46 +00:00
|
|
|
for( unsigned ii = 0; ii < list.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
FOOTPRINT_INFO& footprint = list.GetItem(ii);
|
2011-10-14 16:44:15 +00:00
|
|
|
// Search for matching footprints
|
|
|
|
// The search is case insensitive
|
|
|
|
wxString module = footprint.m_Module.Upper();
|
|
|
|
wxString candidate;
|
2013-04-25 16:29:35 +00:00
|
|
|
|
|
|
|
for( jj = 0; jj < aComponent->GetFootprintFilters().GetCount(); jj++ )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
candidate = aComponent->GetFootprintFilters()[jj].Upper();
|
|
|
|
|
2011-10-14 16:44:15 +00:00
|
|
|
if( !module.Matches( candidate ) )
|
2009-08-20 11:44:06 +00:00
|
|
|
continue;
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2013-04-14 11:02:19 +00:00
|
|
|
msg.Printf( wxT( "%3zu %s" ), m_FilteredFootprintList.GetCount() + 1,
|
2013-04-25 16:29:35 +00:00
|
|
|
footprint.m_Module.GetData() );
|
2009-08-20 11:44:06 +00:00
|
|
|
m_FilteredFootprintList.Add( msg );
|
2012-03-17 03:01:53 +00:00
|
|
|
hasItem = true;
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 03:01:53 +00:00
|
|
|
if( hasItem )
|
2010-11-07 20:06:07 +00:00
|
|
|
SetActiveFootprintList( false );
|
2009-08-20 11:44:06 +00:00
|
|
|
else
|
2010-11-07 20:06:07 +00:00
|
|
|
SetActiveFootprintList( true );
|
2009-08-20 11:44:06 +00:00
|
|
|
|
|
|
|
if( ( GetCount() == 0 ) || ( OldSelection >= GetCount() ) )
|
2010-11-07 20:06:07 +00:00
|
|
|
SetSelection( 0, true );
|
2009-08-20 11:44:06 +00:00
|
|
|
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
|
|
|
|
void FOOTPRINTS_LISTBOX::SetFootprintFilteredByPinCount( COMPONENT* aComponent,
|
|
|
|
FOOTPRINT_LIST& list )
|
|
|
|
{
|
2012-03-15 18:20:22 +00:00
|
|
|
wxString msg;
|
2012-03-17 03:01:53 +00:00
|
|
|
int oldSelection = GetSelection();
|
|
|
|
bool hasItem = false;
|
2012-03-15 18:20:22 +00:00
|
|
|
|
|
|
|
m_FilteredFootprintList.Clear();
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < list.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
FOOTPRINT_INFO& footprint = list.GetItem(ii);
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
if( aComponent->GetNetCount() == footprint.m_padCount )
|
2012-03-17 03:01:53 +00:00
|
|
|
{
|
2013-04-14 11:02:19 +00:00
|
|
|
msg.Printf( wxT( "%3zu %s" ), m_FilteredFootprintList.GetCount() + 1,
|
2013-04-25 16:29:35 +00:00
|
|
|
footprint.m_Module.GetData() );
|
2012-03-17 03:01:53 +00:00
|
|
|
m_FilteredFootprintList.Add( msg );
|
|
|
|
hasItem = true;
|
2012-03-15 18:20:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 03:01:53 +00:00
|
|
|
if( hasItem )
|
2012-03-15 18:20:22 +00:00
|
|
|
SetActiveFootprintList( false );
|
|
|
|
else
|
|
|
|
SetActiveFootprintList( true );
|
|
|
|
|
2012-03-17 03:01:53 +00:00
|
|
|
if( ( GetCount() == 0 ) || ( oldSelection >= GetCount() ) )
|
2012-03-15 18:20:22 +00:00
|
|
|
SetSelection( 0, true );
|
|
|
|
|
|
|
|
Refresh();
|
|
|
|
}
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
void FOOTPRINTS_LISTBOX::SetActiveFootprintList( bool FullList, bool Redraw )
|
|
|
|
{
|
|
|
|
bool old_selection = m_UseFootprintFullList;
|
|
|
|
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
|
|
|
|
/* Workaround for a curious bug in wxWidgets:
|
|
|
|
* if we switch from a long list of footprints to a short list (a
|
|
|
|
* filtered footprint list), and if the selected item is near the end
|
|
|
|
* of the long list, the new list is not displayed from the top of
|
|
|
|
* the list box
|
|
|
|
*/
|
|
|
|
if( m_ActiveFootprintList )
|
|
|
|
{
|
|
|
|
bool new_selection;
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
if( FullList )
|
2010-11-07 20:06:07 +00:00
|
|
|
new_selection = true;
|
2009-08-20 11:44:06 +00:00
|
|
|
else
|
2010-11-07 20:06:07 +00:00
|
|
|
new_selection = false;
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
if( new_selection != old_selection )
|
2010-11-07 20:06:07 +00:00
|
|
|
SetSelection( 0, true );
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if( FullList )
|
|
|
|
{
|
2010-11-07 20:06:07 +00:00
|
|
|
m_UseFootprintFullList = true;
|
2009-08-20 11:44:06 +00:00
|
|
|
m_ActiveFootprintList = &m_FullFootprintList;
|
|
|
|
SetItemCount( m_FullFootprintList.GetCount() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-07 20:06:07 +00:00
|
|
|
m_UseFootprintFullList = false;
|
2009-08-20 11:44:06 +00:00
|
|
|
m_ActiveFootprintList = &m_FilteredFootprintList;
|
|
|
|
SetItemCount( m_FilteredFootprintList.GetCount() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Redraw )
|
|
|
|
{
|
2010-11-07 20:06:07 +00:00
|
|
|
if( !m_UseFootprintFullList || ( m_UseFootprintFullList != old_selection ) )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-07 20:06:07 +00:00
|
|
|
GetParent()->DisplayStatus();
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************/
|
|
|
|
/* Event table for the footprint list */
|
|
|
|
/**************************************/
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE( FOOTPRINTS_LISTBOX, ITEMS_LISTBOX_BASE )
|
2013-04-25 16:29:35 +00:00
|
|
|
EVT_SIZE( ITEMS_LISTBOX_BASE::OnSize )
|
|
|
|
EVT_CHAR( FOOTPRINTS_LISTBOX::OnChar )
|
2009-08-20 11:44:06 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event )
|
|
|
|
{
|
2011-02-21 18:27:47 +00:00
|
|
|
FOOTPRINT_INFO* Module;
|
2012-03-17 03:01:53 +00:00
|
|
|
wxString footprintName = GetSelectedFootprint();
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2012-03-17 03:01:53 +00:00
|
|
|
Module = GetParent()->m_footprints.GetModuleInfo( footprintName );
|
2010-11-07 20:06:07 +00:00
|
|
|
wxASSERT(Module);
|
2011-08-04 11:23:19 +00:00
|
|
|
if( GetParent()->m_DisplayFootprintFrame )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2012-05-25 06:58:52 +00:00
|
|
|
// Refresh current selected footprint view:
|
|
|
|
GetParent()->CreateScreenCmp();
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( Module )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg = Module->m_Doc;
|
|
|
|
GetParent()->SetStatusText( msg, 0 );
|
|
|
|
|
|
|
|
msg = wxT( "KeyW: " );
|
|
|
|
msg += Module->m_KeyWord;
|
|
|
|
GetParent()->SetStatusText( msg, 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINTS_LISTBOX::OnLeftDClick( wxListEvent& event )
|
|
|
|
{
|
2012-03-17 03:01:53 +00:00
|
|
|
wxString footprintName = GetSelectedFootprint();
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2012-03-17 03:01:53 +00:00
|
|
|
GetParent()->SetNewPkg( footprintName );
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINTS_LISTBOX::OnChar( wxKeyEvent& event )
|
|
|
|
{
|
|
|
|
int key = event.GetKeyCode();
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
switch( key )
|
|
|
|
{
|
|
|
|
case WXK_LEFT:
|
|
|
|
case WXK_NUMPAD_LEFT:
|
|
|
|
GetParent()->m_ListCmp->SetFocus();
|
|
|
|
return;
|
|
|
|
|
|
|
|
case WXK_HOME:
|
|
|
|
case WXK_END:
|
|
|
|
case WXK_UP:
|
|
|
|
case WXK_DOWN:
|
|
|
|
case WXK_PAGEUP:
|
|
|
|
case WXK_PAGEDOWN:
|
|
|
|
case WXK_RIGHT:
|
|
|
|
case WXK_NUMPAD_RIGHT:
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
// Search for an item name starting by the key code:
|
|
|
|
key = toupper(key);
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
for( unsigned ii = 0; ii < m_ActiveFootprintList->GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
wxString text = m_ActiveFootprintList->Item(ii);
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
/* search for the start char of the footprint name.
|
|
|
|
* we must skip the line number
|
2013-04-25 16:29:35 +00:00
|
|
|
*/
|
2009-08-20 11:44:06 +00:00
|
|
|
text.Trim(false); // Remove leading spaces in line
|
|
|
|
unsigned jj = 0;
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
for( ; jj < text.Len(); jj++ )
|
2012-03-17 03:01:53 +00:00
|
|
|
{
|
|
|
|
// skip line number
|
2009-08-20 11:44:06 +00:00
|
|
|
if( text[jj] == ' ' )
|
|
|
|
break;
|
|
|
|
}
|
2012-03-17 03:01:53 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
for( ; jj < text.Len(); jj++ )
|
|
|
|
{ // skip blanks
|
|
|
|
if( text[jj] != ' ' )
|
|
|
|
break;
|
|
|
|
}
|
2012-03-17 03:01:53 +00:00
|
|
|
|
|
|
|
int start_char = toupper( text[jj] );
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2012-03-17 03:01:53 +00:00
|
|
|
if( key == start_char )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
|
|
|
Focus( ii );
|
|
|
|
SetSelection( ii, true ); // Ensure visible
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|