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>
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <pgm_base.h>
|
2013-05-31 17:33:46 +00:00
|
|
|
#include <wildcards_and_files_ext.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>
|
2013-06-06 15:37:48 +00:00
|
|
|
#include <cvpcb_id.h>
|
2009-08-20 11:44:06 +00:00
|
|
|
|
|
|
|
|
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,
|
2013-06-06 15:37:48 +00:00
|
|
|
const wxSize& size ) :
|
2009-08-20 11:44:06 +00:00
|
|
|
ITEMS_LISTBOX_BASE( parent, id, loc, size )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FOOTPRINTS_LISTBOX::~FOOTPRINTS_LISTBOX()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int FOOTPRINTS_LISTBOX::GetCount()
|
|
|
|
{
|
2013-06-06 15:37:48 +00:00
|
|
|
return m_footprintList.Count();
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINTS_LISTBOX::SetString( unsigned linecount, const wxString& text )
|
|
|
|
{
|
2014-07-31 03:04:34 +00:00
|
|
|
unsigned count = m_footprintList.Count();
|
|
|
|
if( count > 0 )
|
|
|
|
{
|
|
|
|
if( linecount >= count )
|
|
|
|
linecount = count - 1;
|
2013-06-06 15:37:48 +00:00
|
|
|
m_footprintList[linecount] = text;
|
2014-07-31 03:04:34 +00:00
|
|
|
}
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2013-06-06 15:37:48 +00:00
|
|
|
wxString msg = m_footprintList[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 )
|
|
|
|
{
|
2013-06-06 15:37:48 +00:00
|
|
|
m_footprintList.Add( text );
|
|
|
|
SetItemCount( m_footprintList.Count() );
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString FOOTPRINTS_LISTBOX::OnGetItemText( long item, long column ) const
|
|
|
|
{
|
2013-06-06 15:37:48 +00:00
|
|
|
if( item < 0 || item >= (long)m_footprintList.GetCount() )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
return m_footprintList.Item( item );
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-04 17:34:23 +00:00
|
|
|
void FOOTPRINTS_LISTBOX::SetSelection( int index, bool State )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2014-06-04 17:34:23 +00:00
|
|
|
if( index >= GetCount() )
|
2009-08-20 11:44:06 +00:00
|
|
|
index = GetCount() - 1;
|
|
|
|
|
|
|
|
if( (index >= 0) && (GetCount() > 0) )
|
|
|
|
{
|
|
|
|
#ifndef __WXMAC__
|
|
|
|
Select( index, State );
|
|
|
|
#endif
|
2013-06-06 15:37:48 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
EnsureVisible( index );
|
2013-06-06 15:37:48 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
Refresh();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-06 15:37:48 +00:00
|
|
|
void FOOTPRINTS_LISTBOX::SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName,
|
|
|
|
COMPONENT* aComponent, int aFilterType )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2013-06-06 15:37:48 +00:00
|
|
|
wxArrayString newList;
|
|
|
|
wxString msg;
|
|
|
|
wxString oldSelection;
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2013-06-06 15:37:48 +00:00
|
|
|
if( GetSelection() >= 0 && GetSelection() < (int)m_footprintList.GetCount() )
|
|
|
|
oldSelection = m_footprintList[ GetSelection() ];
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2013-06-06 15:37:48 +00:00
|
|
|
for( unsigned ii = 0; ii < aList.GetCount(); ii++ )
|
2011-02-22 17:59:46 +00:00
|
|
|
{
|
2013-06-06 15:37:48 +00:00
|
|
|
if( aFilterType == UNFILTERED )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2013-09-14 20:33:22 +00:00
|
|
|
msg.Printf( wxT( "%3zu %s:%s" ), newList.GetCount() + 1,
|
2013-10-31 21:30:57 +00:00
|
|
|
GetChars( aList.GetItem( ii ).GetNickname() ),
|
2013-12-12 16:01:03 +00:00
|
|
|
GetChars( aList.GetItem( ii ).GetFootprintName() ) );
|
2013-06-06 15:37:48 +00:00
|
|
|
newList.Add( msg );
|
|
|
|
continue;
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
2013-06-06 15:37:48 +00:00
|
|
|
if( (aFilterType & BY_LIBRARY) && !aLibName.IsEmpty()
|
2013-06-07 12:15:32 +00:00
|
|
|
&& !aList.GetItem( ii ).InLibrary( aLibName ) )
|
2013-06-06 15:37:48 +00:00
|
|
|
continue;
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2013-12-12 16:01:03 +00:00
|
|
|
if( (aFilterType & BY_COMPONENT) && aComponent
|
|
|
|
&& !aComponent->MatchesFootprintFilters( aList.GetItem( ii ).GetFootprintName() ) )
|
2013-06-06 15:37:48 +00:00
|
|
|
continue;
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2013-12-12 16:01:03 +00:00
|
|
|
if( (aFilterType & BY_PIN_COUNT) && aComponent
|
|
|
|
&& aComponent->GetNetCount() != aList.GetItem( ii ).GetPadCount() )
|
2013-06-06 15:37:48 +00:00
|
|
|
continue;
|
2012-03-15 18:20:22 +00:00
|
|
|
|
2013-09-14 20:33:22 +00:00
|
|
|
msg.Printf( wxT( "%3zu %s:%s" ), newList.GetCount() + 1,
|
2013-10-31 21:30:57 +00:00
|
|
|
GetChars( aList.GetItem( ii ).GetNickname() ),
|
2013-12-12 16:01:03 +00:00
|
|
|
GetChars( aList.GetItem( ii ).GetFootprintName() ) );
|
2013-06-06 15:37:48 +00:00
|
|
|
newList.Add( msg );
|
2012-03-15 18:20:22 +00:00
|
|
|
}
|
|
|
|
|
2013-06-06 15:37:48 +00:00
|
|
|
if( newList == m_footprintList )
|
|
|
|
return;
|
2013-05-31 17:33:46 +00:00
|
|
|
|
2013-06-06 15:37:48 +00:00
|
|
|
m_footprintList = newList;
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2013-06-06 15:37:48 +00:00
|
|
|
int selection = m_footprintList.Index( oldSelection );
|
2013-05-31 17:33:46 +00:00
|
|
|
|
2013-06-06 15:37:48 +00:00
|
|
|
if( selection == wxNOT_FOUND )
|
|
|
|
selection = 0;
|
2013-05-31 17:33:46 +00:00
|
|
|
|
2013-06-06 15:37:48 +00:00
|
|
|
DeleteAllItems();
|
2013-09-14 20:33:22 +00:00
|
|
|
|
|
|
|
if( m_footprintList.GetCount() )
|
|
|
|
{
|
|
|
|
SetItemCount( m_footprintList.GetCount() );
|
|
|
|
SetSelection( selection, true );
|
|
|
|
RefreshItems( 0L, m_footprintList.GetCount()-1 );
|
|
|
|
|
2013-10-31 21:30:57 +00:00
|
|
|
#if defined (__WXGTK__ ) //&& wxMINOR_VERSION == 8
|
2013-09-14 20:33:22 +00:00
|
|
|
// @bug On GTK and wxWidgets 2.8.x, this will assert in debug builds because the
|
2013-10-31 21:30:57 +00:00
|
|
|
|
2013-09-14 20:33:22 +00:00
|
|
|
// column parameter is -1. This was the only way to prevent GTK3 from
|
|
|
|
// ellipsizing long strings down to a few characters. It still doesn't set
|
|
|
|
// the scroll bars correctly (too short) but it's better than any of the
|
|
|
|
// other alternatives. If someone knows how to fix this, please do.
|
|
|
|
SetColumnWidth( -1, wxLIST_AUTOSIZE );
|
|
|
|
#else
|
|
|
|
SetColumnWidth( 0, wxLIST_AUTOSIZE );
|
|
|
|
#endif
|
|
|
|
}
|
2013-05-31 17:33:46 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
|
|
|
|
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 )
|
2013-06-06 15:37:48 +00: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 )
|
|
|
|
{
|
2013-06-06 15:37:48 +00:00
|
|
|
if( m_footprintList.IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
2013-06-08 16:06:26 +00:00
|
|
|
// If the footprint view window is displayed, update the footprint.
|
2014-03-21 11:50:04 +00:00
|
|
|
if( GetParent()->GetFpViewerFrame() )
|
2012-05-25 06:58:52 +00:00
|
|
|
GetParent()->CreateScreenCmp();
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2013-06-08 16:06:26 +00:00
|
|
|
GetParent()->DisplayStatus();
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2013-06-06 15:37:48 +00:00
|
|
|
case WXK_TAB:
|
|
|
|
case WXK_RIGHT:
|
|
|
|
case WXK_NUMPAD_RIGHT:
|
2013-06-08 16:06:26 +00:00
|
|
|
GetParent()->ChangeFocus( true );
|
2013-06-06 15:37:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case WXK_LEFT:
|
|
|
|
case WXK_NUMPAD_LEFT:
|
2013-06-08 16:06:26 +00:00
|
|
|
GetParent()->ChangeFocus( false );
|
2013-06-06 15:37:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
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 16:29:35 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
// Search for an item name starting by the key code:
|
2013-06-06 15:37:48 +00:00
|
|
|
key = toupper( key );
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2013-06-06 15:37:48 +00:00
|
|
|
for( unsigned ii = 0; ii < m_footprintList.GetCount(); ii++ )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2013-06-06 15:37:48 +00:00
|
|
|
wxString text = m_footprintList.Item( ii );
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2013-06-06 15:37:48 +00: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 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
|
|
|
{
|
|
|
|
SetSelection( ii, true ); // Ensure visible
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|