Better footprint association and filtering:

1. If a footprint filter contains a : (colon) character, then the filter is matched against the pattern <LibName>:<FootprintName>
2. If there is *no* : (colon) character present, then it is matched against <FootprintName>
3. The same behaviour applies for the manual filter string in CvPCB
This commit is contained in:
Oliver 2017-02-26 18:15:23 +01:00 committed by jean-pierre charras
parent 6b431b4791
commit d6097cf1aa
3 changed files with 52 additions and 25 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2017 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
@ -150,29 +150,40 @@ void FOOTPRINTS_LISTBOX::SetFootprints( FOOTPRINT_LIST& aList, const wxString& a
continue;
}
// Filter footprints by selected library
if( (aFilterType & FILTERING_BY_LIBRARY) && !aLibName.IsEmpty()
&& !aList.GetItem( ii ).InLibrary( aLibName ) )
continue;
// Filter footprints by symbol fp-filters
if( (aFilterType & FILTERING_BY_COMPONENT_KEYWORD) && aComponent
&& !aComponent->MatchesFootprintFilters( aList.GetItem( ii ).GetFootprintName() ) )
&& !aComponent->MatchesFootprintFilters( aList.GetItem( ii ).GetNickname(), aList.GetItem( ii ).GetFootprintName() ) )
continue;
// Filter footprints by symbol pin-count
if( (aFilterType & FILTERING_BY_PIN_COUNT) && aComponent
&& aComponent->GetNetCount() != aList.GetItem( ii ).GetUniquePadCount() )
continue;
// We can search (Using case insensitive search) in full LIB_ID or only
// in the fp name itself.
// After tests, only in the fp name itself looks better.
// However, the code to take in account the nickname is just commented, no removed.
wxString currname = //aList.GetItem( ii ).GetNickname().Lower() + ":" +
aList.GetItem( ii ).GetFootprintName().Lower();
if( (aFilterType & FILTERING_BY_NAME) && !aFootPrintFilterPattern.IsEmpty()
&& patternFilter.Find( currname ) == EDA_PATTERN_NOT_FOUND )
// Filter footprints by text-input
if( (aFilterType & FILTERING_BY_NAME ) && !aFootPrintFilterPattern.IsEmpty() )
{
continue;
wxString currname = "";
// If the search string contains a ':' character,
// include the library name in the search string
// e.g. LibName:FootprintName
if( aFootPrintFilterPattern.Contains( ":" ) )
{
currname = aList.GetItem( ii ).GetNickname().Lower() + ":";
}
currname += aList.GetItem( ii ).GetFootprintName().Lower();
if( patternFilter.Find( currname ) == EDA_PATTERN_NOT_FOUND )
{
continue;
}
}
msg.Printf( wxT( "%3d %s:%s" ), int( newList.GetCount() + 1 ),

View File

@ -6,7 +6,7 @@
*
* Copyright (C) 1992-2011 Jean-Pierre Charras.
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>.
* Copyright (C) 1992-2011 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 1992-2017 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
@ -33,6 +33,7 @@
#include <pcb_netlist.h>
#include <class_module.h>
#include <eda_pattern_match.h>
int COMPONENT_NET::Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl )
@ -72,18 +73,32 @@ const COMPONENT_NET& COMPONENT::GetNet( const wxString& aPinName )
}
bool COMPONENT::MatchesFootprintFilters( const wxString& aFootprintName ) const
bool COMPONENT::MatchesFootprintFilters( const wxString& aLibraryName, const wxString& aFootprintName ) const
{
if( m_footprintFilters.GetCount() == 0 )
return true;
// The matching is case insensitive
wxString name = aFootprintName.Upper();
wxString name = "";
EDA_PATTERN_MATCH_WILDCARD patternFilter;
for( unsigned ii = 0; ii < m_footprintFilters.GetCount(); ii++ )
{
if( name.Matches( m_footprintFilters[ii].Upper() ) )
// If the filter contains a ':' character, include the library name in the pattern
if( m_footprintFilters[ii].Contains( ":" ) )
{
name = aLibraryName.Lower() + ":";
}
name += aFootprintName.Lower();
patternFilter.SetPattern( m_footprintFilters[ii].Lower() );
if( patternFilter.Find( name ) != EDA_PATTERN_NOT_FOUND )
{
return true;
}
}
return false;

View File

@ -1,16 +1,9 @@
#ifndef PCB_NETLIST_H
#define PCB_NETLIST_H
/**
* @file pcb_netlist.h
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras.
* Copyright (C) 2013-2016 Wayne Stambaugh <stambaughw@verizon.net>.
* Copyright (C) 2012-2016 KiCad Developers, see CHANGELOG.TXT for contributors.
* Copyright (C) 2012-2017 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
@ -30,6 +23,14 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef PCB_NETLIST_H
#define PCB_NETLIST_H
/**
* @file pcb_netlist.h
*/
#include <boost/ptr_container/ptr_vector.hpp>
#include <wx/arrstr.h>
@ -179,7 +180,7 @@ public:
* @return true if \a aFootprintName matches any of the footprint filters or no footprint
* filters are defined.
*/
bool MatchesFootprintFilters( const wxString& aFootprintName ) const;
bool MatchesFootprintFilters( const wxString& aLibraryName, const wxString& aFootprintName ) const;
MODULE* GetModule( bool aRelease = false )
{