Commit 7f18b883 authored by Wayne Stambaugh's avatar Wayne Stambaugh

CvPcb filtering and other minor improvements.

* Change filtering from single selection to logically and each filter type.
* Remove clear filtering button and logic.
* Filter buttons now behave as true toggle buttons.
* Improve list control pane focus following when using arrow keys to change
  list pane.
* Remove unused parameters from list box constructors.
* Make tab key behave like right arrow key when moving focus to next list
  pane.
* Make list pane focus wrap around to next or previous control.
* Simplify component list filtering code.
* Improve status bar updating.
* Tell Bazaar to ignore .downloads-by-cmake instead of downloads-by-cmake.
parent 142306e2
include/boost
downloads-by-cmake
.downloads-by-cmake
common/netlist_keywords.*
common/netlist_lexer.h
common/pcb_plot_params_lexer.h
......
/*************************************************************************/
/* listboxes.cpp: class for displaying footprint list and component list */
/*************************************************************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* 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
*/
/**
* @file class_components_listbox.h
*/
#include <fctsys.h>
#include <wxstruct.h>
......@@ -8,15 +31,11 @@
#include <cvpcb.h>
#include <cvpcb_mainframe.h>
#include <cvstruct.h>
#include <cvpcb_id.h>
/**************************************************/
/* ListBox handling the schematic components list */
/**************************************************/
COMPONENTS_LISTBOX::COMPONENTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id,
const wxPoint& loc, const wxSize& size,
int nbitems, wxString choice[] ) :
const wxPoint& loc, const wxSize& size ) :
ITEMS_LISTBOX_BASE( parent, id, loc, size, LISTB_STYLE & ~wxLC_SINGLE_SEL )
{
}
......@@ -27,12 +46,10 @@ COMPONENTS_LISTBOX::~COMPONENTS_LISTBOX()
}
/* Build the events table for the schematic components list box
*/
BEGIN_EVENT_TABLE( COMPONENTS_LISTBOX, ITEMS_LISTBOX_BASE )
EVT_SIZE( ITEMS_LISTBOX_BASE::OnSize )
EVT_CHAR( COMPONENTS_LISTBOX::OnChar )
EVT_LIST_ITEM_SELECTED( ID_CVPCB_COMPONENT_LIST, COMPONENTS_LISTBOX::OnSelectComponent )
END_EVENT_TABLE()
......@@ -53,6 +70,7 @@ void COMPONENTS_LISTBOX::SetString( unsigned linecount, const wxString& text )
{
if( linecount >= m_ComponentList.Count() )
linecount = m_ComponentList.Count() - 1;
if( linecount >= 0 )
m_ComponentList[linecount] = text;
}
......@@ -65,19 +83,12 @@ void COMPONENTS_LISTBOX::AppendLine( const wxString& text )
}
/*
* Overlaid function: MUST be provided in wxLC_VIRTUAL mode
* because real data are not handled by ITEMS_LISTBOX_BASE
*/
wxString COMPONENTS_LISTBOX::OnGetItemText( long item, long column ) const
{
return m_ComponentList.Item( item );
}
/*
* Enable or disable an item
*/
void COMPONENTS_LISTBOX::SetSelection( unsigned index, bool State )
{
if( (int) index >= GetCount() )
......@@ -87,6 +98,7 @@ void COMPONENTS_LISTBOX::SetSelection( unsigned index, bool State )
{
Select( index, State );
EnsureVisible( index );
#ifdef __WXMAC__
Update();
#endif
......@@ -94,73 +106,74 @@ void COMPONENTS_LISTBOX::SetSelection( unsigned index, bool State )
}
/**
* Function OnChar
* called on a key pressed
* Call default handler for some special keys,
* and for "ascii" keys, select the first component
* that the name starts by the letter.
* This is the defaut behaviour of a listbox, but because we use
* virtual lists, the listbox does not know anything to what is displayed,
* we must handle this behaviour here.
* Furthermore the reference of components is not at the beginning of
* displayed lines (the first word is the line number)
*/
void COMPONENTS_LISTBOX::OnChar( wxKeyEvent& event )
{
int key = event.GetKeyCode();
switch( key )
{
case WXK_HOME:
case WXK_END:
case WXK_UP:
case WXK_DOWN:
case WXK_PAGEUP:
case WXK_PAGEDOWN:
event.Skip();
return;
case WXK_LEFT:
case WXK_NUMPAD_LEFT:
GetParent()->m_LibraryList->SetFocus();
return;
case WXK_RIGHT:
case WXK_NUMPAD_RIGHT:
GetParent()->m_FootprintList->SetFocus();
return;
default:
break;
case WXK_TAB:
case WXK_RIGHT:
case WXK_NUMPAD_RIGHT:
GetParent()->m_FootprintList->SetFocus();
return;
case WXK_LEFT:
case WXK_NUMPAD_LEFT:
GetParent()->m_LibraryList->SetFocus();
return;
case WXK_HOME:
case WXK_END:
case WXK_UP:
case WXK_DOWN:
case WXK_PAGEUP:
case WXK_PAGEDOWN:
event.Skip();
return;
default:
break;
}
// Search for an item name starting by the key code:
key = toupper(key);
key = toupper( key );
for( unsigned ii = 0; ii < m_ComponentList.GetCount(); ii++ )
{
wxString text = m_ComponentList.Item(ii);
/* search for the start char of the footprint name.
* we must skip the line number
*/
text.Trim(false); // Remove leading spaces in line
wxString text = m_ComponentList.Item( ii );
// Search for the start char of the footprint name. Skip the line number.
text.Trim( false ); // Remove leading spaces in line
unsigned jj = 0;
for( ; jj < text.Len(); jj++ )
{ // skip line number
if( text[jj] == ' ' )
break;
}
for( ; jj < text.Len(); jj++ )
{ // skip blanks
if( text[jj] != ' ' )
break;
}
int start_char = toupper(text[jj]);
if ( key == start_char )
int start_char = toupper( text[jj] );
if( key == start_char )
{
Focus( ii );
SetSelection( ii, true ); // Ensure visible
break;
}
}
}
void COMPONENTS_LISTBOX::OnSelectComponent( wxListEvent& event )
{
SetFocus();
GetParent()->OnSelectComponent( event );
}
......@@ -36,21 +36,14 @@
#include <cvpcb.h>
#include <cvpcb_mainframe.h>
#include <cvstruct.h>
#include <cvpcb_id.h>
/***************************************/
/* ListBox handling the footprint list */
/***************************************/
FOOTPRINTS_LISTBOX::FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent,
wxWindowID id, const wxPoint& loc,
const wxSize& size,
int nbitems, wxString choice[] ) :
const wxSize& size ) :
ITEMS_LISTBOX_BASE( parent, id, loc, size )
{
m_UseFootprintFullList = true;
m_ActiveFootprintList = NULL;
SetActiveFootprintList( true );
}
......@@ -59,24 +52,19 @@ FOOTPRINTS_LISTBOX::~FOOTPRINTS_LISTBOX()
}
/*
* Return number of items
*/
int FOOTPRINTS_LISTBOX::GetCount()
{
return m_ActiveFootprintList->Count();
return m_footprintList.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 >= m_footprintList.Count() )
linecount = m_footprintList.Count() - 1;
if( linecount >= 0 )
(*m_ActiveFootprintList)[linecount] = text;
m_footprintList[linecount] = text;
}
......@@ -87,7 +75,7 @@ wxString FOOTPRINTS_LISTBOX::GetSelectedFootprint()
if( ii >= 0 )
{
wxString msg = (*m_ActiveFootprintList)[ii];
wxString msg = m_footprintList[ii];
msg.Trim( true );
msg.Trim( false );
footprintName = msg.AfterFirst( wxChar( ' ' ) );
......@@ -99,24 +87,20 @@ wxString FOOTPRINTS_LISTBOX::GetSelectedFootprint()
void FOOTPRINTS_LISTBOX::AppendLine( const wxString& text )
{
m_ActiveFootprintList->Add( text );
SetItemCount( m_ActiveFootprintList->Count() );
m_footprintList.Add( text );
SetItemCount( m_footprintList.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 );
if( item < 0 || item >= (long)m_footprintList.GetCount() )
return wxEmptyString;
return m_footprintList.Item( item );
}
/*
* Enable or disable an item
*/
void FOOTPRINTS_LISTBOX::SetSelection( unsigned index, bool State )
{
if( (int) index >= GetCount() )
......@@ -127,7 +111,9 @@ void FOOTPRINTS_LISTBOX::SetSelection( unsigned index, bool State )
#ifndef __WXMAC__
Select( index, State );
#endif
EnsureVisible( index );
#ifdef __WXMAC__
Refresh();
#endif
......@@ -135,216 +121,79 @@ void FOOTPRINTS_LISTBOX::SetSelection( unsigned index, bool State )
}
void FOOTPRINTS_LISTBOX::SetFootprintFullList( FOOTPRINT_LIST& list )
void FOOTPRINTS_LISTBOX::SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName,
COMPONENT* aComponent, int aFilterType )
{
wxString msg;
int oldSelection = GetSelection();
wxArrayString newList;
wxString msg;
wxString oldSelection;
m_FullFootprintList.Clear();
if( GetSelection() >= 0 && GetSelection() < (int)m_footprintList.GetCount() )
oldSelection = m_footprintList[ GetSelection() ];
for( unsigned ii = 0; ii < list.GetCount(); ii++ )
for( unsigned ii = 0; ii < aList.GetCount(); ii++ )
{
FOOTPRINT_INFO & footprint = list.GetItem(ii);
msg.Printf( wxT( "%3zu %s" ), m_FullFootprintList.GetCount() + 1,
GetChars(footprint.m_Module) );
m_FullFootprintList.Add( msg );
}
SetActiveFootprintList( true );
if( GetCount() == 0 || oldSelection < 0 || oldSelection >= GetCount() )
SetSelection( 0, true );
Refresh();
}
void FOOTPRINTS_LISTBOX::SetFootprintFilteredList( COMPONENT* aComponent,
FOOTPRINT_LIST& list )
{
wxString msg;
unsigned jj;
int OldSelection = GetSelection();
bool hasItem = false;
m_FilteredFootprintList.Clear();
for( unsigned ii = 0; ii < list.GetCount(); ii++ )
{
FOOTPRINT_INFO& footprint = list.GetItem(ii);
// Search for matching footprints
// The search is case insensitive
wxString module = footprint.m_Module.Upper();
wxString candidate;
for( jj = 0; jj < aComponent->GetFootprintFilters().GetCount(); jj++ )
if( aFilterType == UNFILTERED )
{
candidate = aComponent->GetFootprintFilters()[jj].Upper();
if( !module.Matches( candidate ) )
continue;
msg.Printf( wxT( "%3zu %s" ), m_FilteredFootprintList.GetCount() + 1,
footprint.m_Module.GetData() );
m_FilteredFootprintList.Add( msg );
hasItem = true;
msg.Printf( wxT( "%3zu %s" ), newList.GetCount() + 1,
GetChars( aList.GetItem( ii ).m_Module ) );
newList.Add( msg );
continue;
}
}
if( hasItem )
SetActiveFootprintList( false );
else
SetActiveFootprintList( true );
if( (aFilterType & BY_LIBRARY) && !aLibName.IsEmpty()
&& (aList.GetItem( ii ).m_libName != aLibName) )
continue;
if( ( GetCount() == 0 ) || ( OldSelection >= GetCount() ) )
SetSelection( 0, true );
if( (aFilterType & BY_COMPONENT) && (aComponent != NULL)
&& !aComponent->MatchesFootprintFilters( aList.GetItem( ii ).m_Module ) )
continue;
Refresh();
}
void FOOTPRINTS_LISTBOX::SetFootprintFilteredByPinCount( COMPONENT* aComponent,
FOOTPRINT_LIST& list )
{
wxString msg;
int oldSelection = GetSelection();
bool hasItem = false;
if( (aFilterType & BY_PIN_COUNT) && (aComponent!= NULL)
&& (aComponent->GetNetCount() != aList.GetItem( ii ).m_padCount) )
continue;
m_FilteredFootprintList.Clear();
for( unsigned ii = 0; ii < list.GetCount(); ii++ )
{
FOOTPRINT_INFO& footprint = list.GetItem(ii);
if( aComponent->GetNetCount() == footprint.m_padCount )
{
msg.Printf( wxT( "%3zu %s" ), m_FilteredFootprintList.GetCount() + 1,
footprint.m_Module.GetData() );
m_FilteredFootprintList.Add( msg );
hasItem = true;
}
msg.Printf( wxT( "%3zu %s" ), newList.GetCount() + 1,
aList.GetItem( ii ).m_Module.GetData() );
newList.Add( msg );
}
if( hasItem )
SetActiveFootprintList( false );
else
SetActiveFootprintList( true );
if( ( GetCount() == 0 ) || ( oldSelection >= GetCount() ) )
SetSelection( 0, true );
Refresh();
}
void FOOTPRINTS_LISTBOX::SetFootprintFilteredByLibraryList( FOOTPRINT_LIST& list,
wxString SelectedLibrary ) {
wxString msg;
int oldSelection = GetSelection();
bool hasItem = false;
if( newList == m_footprintList )
return;
wxFileName filename = SelectedLibrary;
filename.SetExt( LegacyFootprintLibPathExtension );
wxString FullLibraryName = wxGetApp().FindLibraryPath( filename );
m_footprintList = newList;
m_FilteredFootprintList.Clear();
int selection = m_footprintList.Index( oldSelection );
for( unsigned ii = 0; ii < list.GetCount(); ii++ )
{
FOOTPRINT_INFO& footprint = list.GetItem(ii);
wxString LibName = footprint.m_libPath;
if( LibName.Matches( FullLibraryName ) )
{
msg.Printf( wxT( "%3d %s" ), m_FilteredFootprintList.GetCount() + 1,
footprint.m_Module.GetData() );
m_FilteredFootprintList.Add( msg );
hasItem = true;
}
}
if( hasItem )
SetActiveFootprintList( false );
else
SetActiveFootprintList( true );
if( ( GetCount() == 0 ) || ( oldSelection >= GetCount() ) )
SetSelection( 0, true );
if( selection == wxNOT_FOUND )
selection = 0;
DeleteAllItems();
SetItemCount( m_footprintList.GetCount() );
SetSelection( selection, true );
Refresh();
}
/** Set the footprint list. We can have 2 footprint list:
* The full footprint list
* The filtered footprint list (if the current selected component has a
* filter for footprints)
* @param FullList true = full footprint list, false = filtered footprint list
* @param Redraw = true to redraw the window
*/
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;
if( FullList )
new_selection = true;
else
new_selection = false;
if( new_selection != old_selection )
SetSelection( 0, true );
}
#endif
if( FullList )
{
m_UseFootprintFullList = true;
m_ActiveFootprintList = &m_FullFootprintList;
SetItemCount( m_FullFootprintList.GetCount() );
}
else
{
m_UseFootprintFullList = false;
m_ActiveFootprintList = &m_FilteredFootprintList;
SetItemCount( m_FilteredFootprintList.GetCount() );
}
if( Redraw )
{
if( !m_UseFootprintFullList || ( m_UseFootprintFullList != old_selection ) )
{
Refresh();
}
}
GetParent()->DisplayStatus();
}
/**************************************/
/* Event table for the footprint list */
/**************************************/
BEGIN_EVENT_TABLE( FOOTPRINTS_LISTBOX, ITEMS_LISTBOX_BASE )
EVT_SIZE( ITEMS_LISTBOX_BASE::OnSize )
EVT_CHAR( FOOTPRINTS_LISTBOX::OnChar )
EVT_LIST_ITEM_SELECTED( ID_CVPCB_FOOTPRINT_LIST, FOOTPRINTS_LISTBOX::OnLeftClick )
EVT_LIST_ITEM_ACTIVATED( ID_CVPCB_FOOTPRINT_LIST, FOOTPRINTS_LISTBOX::OnLeftDClick )
END_EVENT_TABLE()
void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event )
{
if( m_footprintList.IsEmpty() )
return;
FOOTPRINT_INFO* Module;
wxString footprintName = GetSelectedFootprint();
wxString footprintName = GetSelectedFootprint();
Module = GetParent()->m_footprints.GetModuleInfo( footprintName );
wxASSERT(Module);
wxASSERT( Module );
if( GetParent()->m_DisplayFootprintFrame )
{
// Refresh current selected footprint view:
......@@ -354,11 +203,10 @@ void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event )
if( Module )
{
wxString msg;
msg = Module->m_Doc;
msg = _( "Description: " ) + Module->m_Doc;
GetParent()->SetStatusText( msg, 0 );
msg = wxT( "KeyW: " );
msg += Module->m_KeyWord;
msg = _( "Key words: " ) + Module->m_KeyWord;
GetParent()->SetStatusText( msg, 1 );
}
}
......@@ -378,37 +226,39 @@ void FOOTPRINTS_LISTBOX::OnChar( wxKeyEvent& event )
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;
case WXK_TAB:
case WXK_RIGHT:
case WXK_NUMPAD_RIGHT:
GetParent()->m_LibraryList->SetFocus();
return;
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:
event.Skip();
return;
default:
break;
}
// Search for an item name starting by the key code:
key = toupper(key);
key = toupper( key );
for( unsigned ii = 0; ii < m_ActiveFootprintList->GetCount(); ii++ )
for( unsigned ii = 0; ii < m_footprintList.GetCount(); ii++ )
{
wxString text = m_ActiveFootprintList->Item(ii);
wxString text = m_footprintList.Item( ii );
/* search for the start char of the footprint name.
* we must skip the line number
*/
text.Trim(false); // Remove leading spaces in line
// Search for the start char of the footprint name. Skip the line number.
text.Trim( false ); // Remove leading spaces in line
unsigned jj = 0;
for( ; jj < text.Len(); jj++ )
......
......@@ -33,19 +33,17 @@
#include <cvpcb.h>
#include <cvpcb_mainframe.h>
#include <cvstruct.h>
#include <cvpcb_id.h>
/***************************************/
/* ListBox handling the library list */
/***************************************/
LIBRARY_LISTBOX::LIBRARY_LISTBOX( CVPCB_MAINFRAME* parent,
wxWindowID id, const wxPoint& loc,
const wxSize& size,
int nbitems, wxString choice[] ) :
LIBRARY_LISTBOX::LIBRARY_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id,
const wxPoint& loc, const wxSize& size ) :
ITEMS_LISTBOX_BASE( parent, id, loc, size )
{
//ListLibraries();
}
......@@ -54,24 +52,19 @@ LIBRARY_LISTBOX::~LIBRARY_LISTBOX()
}
/*
* Return number of items
*/
int LIBRARY_LISTBOX::GetCount()
{
return m_LibraryList.Count();
return m_libraryList.Count();
}
/*
* Change an item text
*/
void LIBRARY_LISTBOX::SetString( unsigned linecount, const wxString& text )
{
if( linecount >= m_LibraryList.Count() )
linecount = m_LibraryList.Count() - 1;
if( linecount >= m_libraryList.Count() )
linecount = m_libraryList.Count() - 1;
if( linecount >= 0 )
m_LibraryList[linecount] = text;
m_libraryList[linecount] = text;
}
......@@ -82,7 +75,7 @@ wxString LIBRARY_LISTBOX::GetSelectedLibrary()
if( ii >= 0 )
{
libraryName = m_LibraryList[ii];
libraryName = m_libraryList[ii];
}
return libraryName;
......@@ -91,23 +84,17 @@ wxString LIBRARY_LISTBOX::GetSelectedLibrary()
void LIBRARY_LISTBOX::AppendLine( const wxString& text )
{
m_LibraryList.Add( text );
SetItemCount( m_LibraryList.Count() );
m_libraryList.Add( text );
SetItemCount( m_libraryList.Count() );
}
/*
* Overlaid function: MUST be provided in wxLC_VIRTUAL mode
* because real data is not handled by ITEMS_LISTBOX_BASE
*/
wxString LIBRARY_LISTBOX::OnGetItemText( long item, long column ) const
{
return m_LibraryList.Item( item );
return m_libraryList.Item( item );
}
/*
* Enable or disable an item
*/
void LIBRARY_LISTBOX::SetSelection( unsigned index, bool State )
{
if( (int) index >= GetCount() )
......@@ -126,83 +113,69 @@ void LIBRARY_LISTBOX::SetSelection( unsigned index, bool State )
}
void LIBRARY_LISTBOX::SetLibraryList( wxArrayString list )
void LIBRARY_LISTBOX::SetLibraryList( const wxArrayString& aList )
{
wxString msg;
int oldSelection = GetSelection();
int oldSelection = GetSelection();
m_LibraryList.Clear();
m_libraryList = aList;
for( unsigned ii = 0; ii < list.GetCount(); ii++ )
{
msg = list.Item(ii);
m_LibraryList.Add( msg );
}
SetItemCount(list.GetCount());
SetItemCount( m_libraryList.GetCount() );
if( GetCount() == 0 || oldSelection < 0 || oldSelection >= GetCount() )
SetSelection( 0, true );
Refresh();
}
/**************************************/
/* Event table for the library list */
/**************************************/
BEGIN_EVENT_TABLE( LIBRARY_LISTBOX, ITEMS_LISTBOX_BASE )
EVT_SIZE( ITEMS_LISTBOX_BASE::OnSize )
EVT_CHAR( LIBRARY_LISTBOX::OnChar )
EVT_LIST_ITEM_SELECTED( ID_CVPCB_LIBRARY_LIST, LIBRARY_LISTBOX::OnSelectLibrary )
END_EVENT_TABLE()
/**
* Function OnChar
* called on a key pressed
* Call default handler for some special keys,
* and for "ascii" keys, select the first footprint
* that the name starts by the letter.
* This is the defaut behaviour of a listbox, but because we use
* virtual lists, the listbox does not know anything to what is displayed,
* we must handle this behaviour here.
* Furthermore the footprint name is not at the beginning of
* displayed lines (the first word is the line number)
*/
void LIBRARY_LISTBOX::OnChar( wxKeyEvent& event )
{
int key = event.GetKeyCode();
switch( key )
{
case WXK_RIGHT:
case WXK_NUMPAD_RIGHT:
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_LEFT:
case WXK_NUMPAD_LEFT:
event.Skip();
return;
default:
break;
case WXK_TAB:
case WXK_RIGHT:
case WXK_NUMPAD_RIGHT:
GetParent()->m_ListCmp->SetFocus();
return;
case WXK_LEFT:
case WXK_NUMPAD_LEFT:
GetParent()->m_FootprintList->SetFocus();
return;
case WXK_HOME:
case WXK_END:
case WXK_UP:
case WXK_DOWN:
case WXK_PAGEUP:
case WXK_PAGEDOWN:
event.Skip();
return;
default:
break;
}
// Search for an item name starting by the key code:
key = toupper(key);
for( unsigned ii = 0; ii < m_LibraryList.GetCount(); ii++ )
for( unsigned ii = 0; ii < m_libraryList.GetCount(); ii++ )
{
wxString text = m_LibraryList.Item(ii);
/* search for the start char of the footprint name.
* we must skip the line number
*/
text.Trim(false); // Remove leading spaces in line
wxString text = m_libraryList.Item( ii );
// Search for the start char of the footprint name. Skip the line number.
text.Trim( false ); // Remove leading spaces in line
unsigned jj = 0;
for( ; jj < text.Len(); jj++ )
{
// skip line number
......@@ -217,6 +190,7 @@ void LIBRARY_LISTBOX::OnChar( wxKeyEvent& event )
}
int start_char = toupper( text[jj] );
if( key == start_char )
{
Focus( ii );
......@@ -225,3 +199,10 @@ void LIBRARY_LISTBOX::OnChar( wxKeyEvent& event )
}
}
}
void LIBRARY_LISTBOX::OnSelectLibrary( wxListEvent& event )
{
SetFocus();
GetParent()->OnSelectComponent( event );
}
......@@ -87,20 +87,12 @@ BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, EDA_BASE_FRAME )
CVPCB_MAINFRAME::OnSelectFilteringFootprint )
EVT_TOOL( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST,
CVPCB_MAINFRAME::OnSelectFilteringFootprint )
EVT_TOOL( ID_CVPCB_FOOTPRINT_DISPLAY_FULL_LIST,
CVPCB_MAINFRAME::OnSelectFilteringFootprint )
// Frame events
EVT_CHAR( CVPCB_MAINFRAME::OnChar )
EVT_CLOSE( CVPCB_MAINFRAME::OnCloseWindow )
EVT_SIZE( CVPCB_MAINFRAME::OnSize )
// List item events
EVT_LIST_ITEM_SELECTED( ID_CVPCB_FOOTPRINT_LIST, CVPCB_MAINFRAME::OnLeftClick )
EVT_LIST_ITEM_ACTIVATED( ID_CVPCB_FOOTPRINT_LIST, CVPCB_MAINFRAME::OnLeftDClick )
EVT_LIST_ITEM_SELECTED( ID_CVPCB_COMPONENT_LIST, CVPCB_MAINFRAME::OnSelectComponent )
EVT_LIST_ITEM_SELECTED( ID_CVPCB_LIBRARY_LIST, CVPCB_MAINFRAME::OnSelectComponent )
EVT_UPDATE_UI( ID_CVPCB_CONFIG_KEEP_OPEN_ON_SAVE, CVPCB_MAINFRAME::OnUpdateKeepOpenOnSave )
END_EVENT_TABLE()
......@@ -111,14 +103,13 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( const wxString& title, long style ) :
EDA_BASE_FRAME( NULL, CVPCB_FRAME_TYPE, title, wxDefaultPosition,
wxDefaultSize, style, CVPCB_MAINFRAME_NAME )
{
m_FrameName = CVPCB_MAINFRAME_NAME;
m_ListCmp = NULL;
m_FootprintList = NULL;
m_LibraryList = NULL;
m_FrameName = CVPCB_MAINFRAME_NAME;
m_ListCmp = NULL;
m_FootprintList = NULL;
m_LibraryList = NULL;
m_DisplayFootprintFrame = NULL;
m_mainToolBar = NULL;
m_modified = false;
m_mainToolBar = NULL;
m_modified = false;
m_isEESchemaNetlist = false;
m_KeepCvpcbOpen = false;
m_undefinedComponentCnt = 0;
......@@ -200,22 +191,6 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( const wxString& title, long style ) :
CVPCB_MAINFRAME::~CVPCB_MAINFRAME()
{
wxConfig* config = wxGetApp().GetSettings();
if( config )
{
int state = 0;
if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST ) )
{
state = 1;
}
else if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST ) )
{
state = 2;
}
config->Write( wxT( FILTERFOOTPRINTKEY ), state );
}
m_auimgr.UnInit();
}
......@@ -242,6 +217,19 @@ void CVPCB_MAINFRAME::SaveSettings()
EDA_BASE_FRAME::SaveSettings();
cfg->Write( KeepCvpcbOpenEntry, m_KeepCvpcbOpen );
cfg->Write( FootprintDocFileEntry, m_DocModulesFileName );
int state = 0;
if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST ) )
state |= FOOTPRINTS_LISTBOX::BY_COMPONENT;
if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST ) )
state |= FOOTPRINTS_LISTBOX::BY_PIN_COUNT;
if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST ) )
state |= FOOTPRINTS_LISTBOX::BY_LIBRARY;
cfg->Write( wxT( FILTERFOOTPRINTKEY ), state );
}
......@@ -508,91 +496,46 @@ void CVPCB_MAINFRAME::DisplayDocFile( wxCommandEvent& event )
}
void CVPCB_MAINFRAME::OnLeftClick( wxListEvent& event )
{
m_FootprintList->OnLeftClick( event );
}
void CVPCB_MAINFRAME::OnLeftDClick( wxListEvent& event )
{
m_FootprintList->OnLeftDClick( event );
}
/* Called when clicking on a component in component list window
* * Updates the filtered footprint list, if the filtered list option is selected
* * Updates the current selected footprint in footprint list
* * Updates the footprint shown in footprint display window (if opened)
*/
void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
{
if( m_skipComponentSelect )
return;
#define REDRAW_LIST true
#define SELECT_FULL_LIST true
int selection = -1;
wxString SelectedLibrary;
if( !m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST )
&& !m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST )
&& !m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST )
)
m_FootprintList->SetActiveFootprintList( SELECT_FULL_LIST, REDRAW_LIST );
wxString libraryName;
COMPONENT* component = NULL;
int filter = FOOTPRINTS_LISTBOX::UNFILTERED;
else
{
selection = m_ListCmp->GetSelection();
if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST ) )
filter |= FOOTPRINTS_LISTBOX::BY_COMPONENT;
if( selection < 0 )
m_FootprintList->SetActiveFootprintList( SELECT_FULL_LIST, REDRAW_LIST );
if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST ) )
filter |= FOOTPRINTS_LISTBOX::BY_PIN_COUNT;
else
{
if( m_netlist.GetComponent( selection ) == NULL )
m_FootprintList->SetActiveFootprintList( SELECT_FULL_LIST, REDRAW_LIST );
else
{
if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST ) )
{
m_FootprintList->SetFootprintFilteredByPinCount( m_netlist.GetComponent( selection ),
m_footprints );
}
else
if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST ) )
{
SelectedLibrary=m_LibraryList->GetSelectedLibrary();
m_FootprintList->SetFootprintFilteredByLibraryList( m_footprints, SelectedLibrary );
}
else
{
m_FootprintList->SetFootprintFilteredList( m_netlist.GetComponent( selection ),
m_footprints );
}
}
}
}
if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST ) )
filter |= FOOTPRINTS_LISTBOX::BY_LIBRARY;
selection = m_ListCmp->GetSelection();
component = GetSelectedComponent();
libraryName = m_LibraryList->GetSelectedLibrary();
m_FootprintList->SetFootprints( m_footprints, libraryName, component, filter );
if( selection < 0 )
if( component == NULL )
return;
// Preview of the already assigned footprint.
// Find the footprint that was already choosen for this component and select it,
// but only if the selection is made from the component list.
// If the selection is made from the footprint list, do not change the current selected footprint.
// Find the footprint that was already chosen for this component and select it,
// but only if the selection is made from the component list. If the selection is
// made from the footprint list, do not change the current selected footprint.
if( FindFocus() == m_ListCmp )
if( FindFocus() == m_ListCmp )
{
wxString module = m_netlist.GetComponent( selection )->GetFootprintName();
wxString module = component->GetFootprintName();
bool found = false;
for( int ii = 0; ii < m_FootprintList->GetCount(); ii++ )
{
wxString footprintName;
wxString msg = (*m_FootprintList->m_ActiveFootprintList)[ii];
wxString msg = m_FootprintList->OnGetItemText( ii, 0 );
msg.Trim( true );
msg.Trim( false );
footprintName = msg.AfterFirst( wxChar( ' ' ) );
......@@ -604,11 +547,14 @@ void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
break;
}
}
if( ! found )
if( !found )
{
int ii = m_FootprintList->GetSelection();
if ( ii >= 0 )
m_FootprintList->SetSelection( ii, false );
if( m_DisplayFootprintFrame )
{
CreateScreenCmp();
......@@ -623,36 +569,6 @@ void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
void CVPCB_MAINFRAME::OnSelectFilteringFootprint( wxCommandEvent& event )
{
switch( event.GetId() )
{
case ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST:
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_FULL_LIST, false );
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST, false );
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST, false );
break;
case ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST:
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_FULL_LIST, false );
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST, false );
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST, false );
break;
case ID_CVPCB_FOOTPRINT_DISPLAY_FULL_LIST:
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST, false );
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST, false );
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST, false );
break;
case ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST:
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_FULL_LIST, false );
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST, false );
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST, false );
break;
default:
break;
}
wxListEvent l_event;
OnSelectComponent( l_event );
......@@ -667,35 +583,70 @@ void CVPCB_MAINFRAME::OnUpdateKeepOpenOnSave( wxUpdateUIEvent& event )
void CVPCB_MAINFRAME::DisplayStatus()
{
wxString msg;
wxString msg;
COMPONENT* component;
msg.Printf( _( "Components: %d (free: %d)" ), (int) m_netlist.GetCount(),
msg.Printf( _( "Components: %d, unassigned: %d" ), (int) m_netlist.GetCount(),
m_undefinedComponentCnt );
SetStatusText( msg, 0 );
SetStatusText( wxEmptyString, 1 );
msg.Empty();
if( m_FootprintList )
component = GetSelectedComponent();
if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST ) && component )
{
if( m_FootprintList->m_UseFootprintFullList )
msg.Printf( _( "Footprints (All): %d" ),
(int) m_FootprintList->m_ActiveFootprintList->GetCount() );
else
msg.Printf( _( "Footprints (filtered): %d" ),
(int) m_FootprintList->m_ActiveFootprintList->GetCount() );
for( unsigned ii = 0; ii < component->GetFootprintFilters().GetCount(); ii++ )
{
if( msg.IsEmpty() )
msg += component->GetFootprintFilters()[ii];
else
msg += wxT( ", " ) + component->GetFootprintFilters()[ii];
}
msg = _( "Filter list: " ) + msg;
}
else
SetStatusText( msg, 1 );
msg.Empty();
if( m_FootprintList )
{
msg.Empty();
}
if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST ) )
msg = _( "key words" );
if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST ) )
{
if( !msg.IsEmpty() )
msg += wxT( ", " );
msg += _( "pin count" );
}
SetStatusText( msg, 2 );
if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST ) )
{
if( !msg.IsEmpty() )
msg += wxT( ", " );
msg += _( "library" );
}
if( msg.IsEmpty() )
msg = _( "No filtering" );
else
msg = _( "Filtered by " ) + msg;
msg << wxT( ": " ) << m_FootprintList->GetCount();
SetStatusText( msg, 2 );
}
}
bool CVPCB_MAINFRAME::LoadFootprintFiles()
{
/* Check if there are footprint libraries in project file */
// Check if there are footprint libraries in project file.
if( m_ModuleLibNames.GetCount() == 0 )
{
wxMessageBox( _( "No PCB footprint libraries are listed in the current project file." ),
......@@ -705,10 +656,10 @@ bool CVPCB_MAINFRAME::LoadFootprintFiles()
m_footprints.ReadFootprintFiles( m_ModuleLibNames );
/* Display error messages, if any */
// Display error messages, if any.
if( !m_footprints.m_filesNotFound.IsEmpty() || !m_footprints.m_filesInvalid.IsEmpty() )
{
HTML_MESSAGE_BOX dialog( this, _("Load Error") );
HTML_MESSAGE_BOX dialog( this, _( "Load Error" ) );
if( !m_footprints.m_filesNotFound.IsEmpty() )
{
......@@ -717,7 +668,7 @@ bool CVPCB_MAINFRAME::LoadFootprintFiles()
dialog.ListSet( m_footprints.m_filesNotFound );
}
/* Display if there are invalid files */
// Display if there are invalid files.
if( !m_footprints.m_filesInvalid.IsEmpty() )
{
dialog.MessageSet( _( "Some files are invalid!" ) );
......@@ -815,7 +766,6 @@ int CVPCB_MAINFRAME::ReadSchematicNetlist()
return 1;
}
// We also remove footprint name if it is "$noname" because this is a dummy name,
// not the actual name of the footprint.
for( unsigned ii = 0; ii < m_netlist.GetCount(); ii++ )
......@@ -831,7 +781,7 @@ int CVPCB_MAINFRAME::ReadSchematicNetlist()
}
/* File header. */
// File header.
static char HeaderLinkFile[] = { "Cmp-Mod V01" };
......@@ -900,3 +850,86 @@ void CVPCB_MAINFRAME::CreateScreenCmp()
m_DisplayFootprintFrame->InitDisplay();
}
void CVPCB_MAINFRAME::BuildFOOTPRINTS_LISTBOX()
{
wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
if( m_FootprintList == NULL )
{
m_FootprintList = new FOOTPRINTS_LISTBOX( this, ID_CVPCB_FOOTPRINT_LIST,
wxDefaultPosition, wxDefaultSize );
m_FootprintList->SetFont( wxFont( guiFont.GetPointSize(),
wxFONTFAMILY_MODERN,
wxFONTSTYLE_NORMAL,
wxFONTWEIGHT_NORMAL ) );
}
m_FootprintList->SetFootprints( m_footprints, wxEmptyString, NULL,
FOOTPRINTS_LISTBOX::UNFILTERED );
DisplayStatus();
}
void CVPCB_MAINFRAME::BuildCmpListBox()
{
wxString msg;
COMPONENT* component;
wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
if( m_ListCmp == NULL )
{
m_ListCmp = new COMPONENTS_LISTBOX( this, ID_CVPCB_COMPONENT_LIST,
wxDefaultPosition, wxDefaultSize );
m_ListCmp->SetFont( wxFont( guiFont.GetPointSize(),
wxFONTFAMILY_MODERN,
wxFONTSTYLE_NORMAL,
wxFONTWEIGHT_NORMAL ) );
}
m_ListCmp->m_ComponentList.Clear();
for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
{
component = m_netlist.GetComponent( i );
msg.Printf( CMP_FORMAT, m_ListCmp->GetCount() + 1,
GetChars( component->GetReference() ),
GetChars( component->GetValue() ),
GetChars( component->GetFootprintName() ) );
m_ListCmp->m_ComponentList.Add( msg );
}
m_ListCmp->SetItemCount( m_ListCmp->m_ComponentList.Count() );
m_ListCmp->SetSelection( 0, true );
}
void CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX()
{
wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
if( m_LibraryList == NULL )
{
m_LibraryList = new LIBRARY_LISTBOX( this, ID_CVPCB_LIBRARY_LIST,
wxDefaultPosition, wxDefaultSize );
m_LibraryList->SetFont( wxFont( guiFont.GetPointSize(),
wxFONTFAMILY_MODERN,
wxFONTSTYLE_NORMAL,
wxFONTWEIGHT_NORMAL ) );
}
m_LibraryList->SetLibraryList( m_ModuleLibNames );
}
COMPONENT* CVPCB_MAINFRAME::GetSelectedComponent()
{
int selection = m_ListCmp->GetSelection();
if( selection >= 0 && selection < (int) m_netlist.GetCount() )
return m_netlist.GetComponent( selection );
return NULL;
}
......@@ -45,6 +45,7 @@ class FOOTPRINTS_LISTBOX;
class COMPONENTS_LISTBOX;
class LIBRARY_LISTBOX;
class DISPLAY_FOOTPRINTS_FRAME;
class COMPONENT;
/**
......@@ -52,8 +53,9 @@ class DISPLAY_FOOTPRINTS_FRAME;
*/
class CVPCB_MAINFRAME : public EDA_BASE_FRAME
{
public:
wxArrayString m_footprintListEntries;
public:
bool m_KeepCvpcbOpen;
FOOTPRINTS_LISTBOX* m_FootprintList;
LIBRARY_LISTBOX* m_LibraryList;
......@@ -81,9 +83,6 @@ public:
CVPCB_MAINFRAME( const wxString& title, long style = KICAD_DEFAULT_DRAWFRAME_STYLE );
~CVPCB_MAINFRAME();
void OnLeftClick( wxListEvent& event );
void OnLeftDClick( wxListEvent& event );
/**
* Function OnSelectComponent
* Called when clicking on a component in component list window
......@@ -275,6 +274,8 @@ public:
*/
void SendMessageToEESCHEMA();
COMPONENT* GetSelectedComponent();
DECLARE_EVENT_TABLE()
};
......
......@@ -29,6 +29,7 @@
#define CVSTRUCT_H
#include <wx/listctrl.h>
#include <cvpcb.h>
/* Forward declarations of all top-level window classes. */
......@@ -45,58 +46,64 @@ class ITEMS_LISTBOX_BASE : public wxListView
public:
ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId,
const wxPoint& aLocation, const wxSize& aSize,
long aStyle = wxLC_SINGLE_SEL);
long aStyle = wxLC_SINGLE_SEL );
~ITEMS_LISTBOX_BASE();
int GetSelection();
void OnSize( wxSizeEvent& event );
int GetSelection();
void OnSize( wxSizeEvent& event );
virtual CVPCB_MAINFRAME* GetParent();
};
/******************************************/
/* ListBox showing the list of footprints */
/******************************************/
class FOOTPRINTS_LISTBOX : public ITEMS_LISTBOX_BASE
{
private:
wxArrayString m_FullFootprintList;
wxArrayString m_FilteredFootprintList;
public:
wxArrayString* m_ActiveFootprintList;
bool m_UseFootprintFullList;
wxArrayString m_footprintList;
public:
enum FP_FILTER_T
{
UNFILTERED = 0,
BY_COMPONENT = 0x0001,
BY_PIN_COUNT = 0x0002,
BY_LIBRARY = 0x0004,
};
FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id,
const wxPoint& loc, const wxSize& size,
int nbitems, wxString choice[] );
const wxPoint& loc, const wxSize& size );
~FOOTPRINTS_LISTBOX();
int GetCount();
void SetSelection( unsigned index, bool State = true );
void SetString( unsigned linecount, const wxString& text );
void AppendLine( const wxString& text );
void SetFootprintFullList( FOOTPRINT_LIST& list );
void SetFootprintFilteredList( COMPONENT* aComponent,
FOOTPRINT_LIST& aList );
void SetFootprintFilteredByPinCount( COMPONENT* aComponent,
FOOTPRINT_LIST& aList );
void SetFootprintFilteredByLibraryList( FOOTPRINT_LIST& list,
wxString SelectedLibrary );
/**
* Set the footprint list. We can have 2 footprint list:
* The full footprint list
* The filtered footprint list (if the current selected component has a
* filter for footprints)
* @param FullList true = full footprint list, false = filtered footprint list
* @param Redraw = true to redraw the window
* Function SetFootprints
* populates the wxListCtrl with the footprints from \a aList that meet the filter
* criteria defined by \a aFilterType.
*
* @param aList is a #FOOTPRINT_LIST item containing the footprints.
* @param aLibName is wxString containing the name of the selected library. Can be
* wxEmptyString.
* @param aComponent is the #COMPONENT used by the filtering criteria. Can be NULL.
* @param aFilterType defines the criteria to filter \a aList.
*/
void SetActiveFootprintList( bool FullList, bool Redraw = false );
void SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName,
COMPONENT* aComponent, int aFilterType );
wxString GetSelectedFootprint();
/**
* Function OnGetItemText
* this overloaded function MUST be provided for the wxLC_VIRTUAL mode
* because real data is not handled by ITEMS_LISTBOX_BASE
*/
wxString OnGetItemText( long item, long column ) const;
// Events functions:
......@@ -107,43 +114,54 @@ public:
DECLARE_EVENT_TABLE()
};
/******************************************/
/* ListBox showing the list of library */
/******************************************/
class LIBRARY_LISTBOX : public ITEMS_LISTBOX_BASE
{
//private:
public:
wxArrayString m_LibraryList;
wxArrayString m_libraryList;
public:
LIBRARY_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id,
const wxPoint& loc, const wxSize& size,
int nbitems, wxString choice[] );
const wxPoint& loc, const wxSize& size );
~LIBRARY_LISTBOX();
int GetCount();
void SetSelection( unsigned index, bool State = true );
void SetString( unsigned linecount, const wxString& text );
void AppendLine( const wxString& text );
void SetLibraryList( wxArrayString list );
void SetLibraryList( const wxArrayString& aList );
wxString GetSelectedLibrary();
wxString OnGetItemText( long item, long column ) const;
// Events functions:
void OnLeftClick( wxListEvent& event );
void OnSelectLibrary( wxListEvent& event );
/**
* Function OnChar
* called on a key pressed
* Call default handler for some special keys,
* and for "ascii" keys, select the first footprint
* that the name starts by the letter.
* This is the defaut behaviour of a listbox, but because we use
* virtual lists, the listbox does not know anything to what is displayed,
* we must handle this behaviour here.
* Furthermore the footprint name is not at the beginning of
* displayed lines (the first word is the line number)
*/
void OnChar( wxKeyEvent& event );
DECLARE_EVENT_TABLE()
};
/****************************************************/
/* ListBox showing the list of schematic components */
/****************************************************/
class COMPONENTS_LISTBOX : public ITEMS_LISTBOX_BASE
{
public:
......@@ -153,21 +171,45 @@ public:
public:
COMPONENTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id,
const wxPoint& loc, const wxSize& size,
int nbitems, wxString choice[] );
const wxPoint& loc, const wxSize& size );
~COMPONENTS_LISTBOX();
void Clear();
int GetCount();
/**
* Function OnGetItemText
* this overloaded function MUST be provided for the wxLC_VIRTUAL mode
* because real data is not handled by ITEMS_LISTBOX_BASE
*/
wxString OnGetItemText( long item, long column ) const;
/*
* Enable or disable an item
*/
void SetSelection( unsigned index, bool State = true );
void SetString( unsigned linecount, const wxString& text );
void AppendLine( const wxString& text );
// Events functions:
/**
* Function OnChar
* called on a key pressed
* Call default handler for some special keys,
* and for "ascii" keys, select the first component
* that the name starts by the letter.
* This is the default behavior of a listbox, but because we use
* virtual lists, the listbox does not know anything to what is displayed,
* we must handle this behavior here.
* Furthermore the reference of components is not at the beginning of
* displayed lines (the first word is the line number)
*/
void OnChar( wxKeyEvent& event );
void OnSelectComponent( wxListEvent& event );
DECLARE_EVENT_TABLE()
};
......
......@@ -83,90 +83,3 @@ CVPCB_MAINFRAME* ITEMS_LISTBOX_BASE::GetParent()
{
return (CVPCB_MAINFRAME*) wxListView::GetParent();
}
/*
* Create or update the schematic components list.
*/
void CVPCB_MAINFRAME::BuildCmpListBox()
{
COMPONENT* component;
wxString msg;
wxSize size( 10, 10 );
wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
if( m_ListCmp == NULL )
{
m_ListCmp = new COMPONENTS_LISTBOX( this, ID_CVPCB_COMPONENT_LIST,
wxDefaultPosition, size,
0, NULL );
m_ListCmp->SetFont( wxFont( guiFont.GetPointSize(),
wxFONTFAMILY_MODERN,
wxFONTSTYLE_NORMAL,
wxFONTWEIGHT_NORMAL ) );
}
m_ListCmp->m_ComponentList.Clear();
for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
{
component = m_netlist.GetComponent( i );
msg.Printf( CMP_FORMAT, m_ListCmp->GetCount() + 1,
GetChars( component->GetReference() ),
GetChars( component->GetValue() ),
GetChars( component->GetFootprintName() ) );
m_ListCmp->m_ComponentList.Add( msg );
}
m_ListCmp->SetItemCount( m_ListCmp->m_ComponentList.Count() );
m_ListCmp->SetSelection( 0, true );
}
/*
* Create or update the footprint list.
*/
void CVPCB_MAINFRAME::BuildFOOTPRINTS_LISTBOX()
{
wxString msg;
wxSize size( 10, 10 );
wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
if( m_FootprintList == NULL )
{
m_FootprintList = new FOOTPRINTS_LISTBOX( this, ID_CVPCB_FOOTPRINT_LIST,
wxDefaultPosition, size,
0, NULL );
m_FootprintList->SetFont( wxFont( guiFont.GetPointSize(),
wxFONTFAMILY_MODERN,
wxFONTSTYLE_NORMAL,
wxFONTWEIGHT_NORMAL ) );
}
m_FootprintList->SetFootprintFullList( m_footprints );
DisplayStatus();
}
/*
* Create or update the library list.
*/
void CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX()
{
wxString msg;
wxSize size( 10, 10 );
wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
if( m_LibraryList == NULL )
{
m_LibraryList = new LIBRARY_LISTBOX( this, ID_CVPCB_LIBRARY_LIST,
wxDefaultPosition, size,
0 , NULL );
m_LibraryList->SetFont( wxFont( guiFont.GetPointSize(),
wxFONTFAMILY_MODERN,
wxFONTSTYLE_NORMAL,
wxFONTWEIGHT_NORMAL ) );
}
m_LibraryList->SetLibraryList( m_ModuleLibNames );
}
......@@ -94,36 +94,30 @@ void CVPCB_MAINFRAME::ReCreateHToolbar()
KiBitmap( module_filtered_list_xpm ),
wxNullBitmap,
true, NULL,
_( "Display the filtered footprint list for the current component" ),
_( "Filter the footprint list for the current component key words" ),
wxEmptyString );
m_mainToolBar->AddTool( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST,
KiBitmap( module_pin_filtered_list_xpm ),
wxNullBitmap,
true, NULL,
_( "Display the filtered footprint list by pin count for the current component" ),
_( "Filter the footprint list by pin count for the current component" ),
wxEmptyString );
m_mainToolBar->AddTool( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST,
KiBitmap( module_library_list_xpm ),
wxNullBitmap, true, NULL,
_( "Display the footprint list from selected library" ),
wxEmptyString );
m_mainToolBar->AddTool( ID_CVPCB_FOOTPRINT_DISPLAY_FULL_LIST,
KiBitmap( module_full_list_xpm ),
wxNullBitmap, true, NULL,
_( "Display the full footprint list (without filtering)" ),
_( "Filter the footprint list by the selected library" ),
wxEmptyString );
if( config )
{
wxString key = wxT( FILTERFOOTPRINTKEY );
int opt = config->Read( key, (long) 1 );
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST, opt == 3 );
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST, opt == 2 );
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST, opt == 1 );
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_FULL_LIST, opt == 0 );
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST, opt & 4 );
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST, opt & 2 );
m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST, opt & 1 );
}
// after adding the buttons to the toolbar, must call Realize() to reflect the changes
......
......@@ -92,6 +92,24 @@ const COMPONENT_NET& COMPONENT::GetNet( const wxString& aPinName )
}
bool COMPONENT::MatchesFootprintFilters( const wxString& aFootprintName ) const
{
if( m_footprintFilters.GetCount() == 0 )
return true;
// The matching is case insensitive
wxString name = aFootprintName.Upper();
for( unsigned ii = 0; ii < m_footprintFilters.GetCount(); ii++ )
{
if( name.Matches( m_footprintFilters[ii].Upper() ) )
return true;
}
return false;
}
#if defined(DEBUG)
void COMPONENT::Show( int aNestLevel, REPORTER& aReporter )
{
......
......@@ -197,6 +197,14 @@ public:
const wxArrayString& GetFootprintFilters() const { return m_footprintFilters; }
/**
* Function MatchesFootprintFilters
*
* @return true if \a aFootprintName matches any of the footprint filters or no footprint
* filters are defined.
*/
bool MatchesFootprintFilters( const wxString& aFootprintName ) const;
MODULE* GetModule( bool aRelease = false )
{
return ( aRelease ) ? m_footprint.release() : m_footprint.get();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment