From d6097cf1aa0adc00e56cd971e427a116c503fd89 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 26 Feb 2017 18:15:23 +0100 Subject: [PATCH] Better footprint association and filtering: 1. If a footprint filter contains a : (colon) character, then the filter is matched against the pattern : 2. If there is *no* : (colon) character present, then it is matched against 3. The same behaviour applies for the manual filter string in CvPCB --- cvpcb/class_footprints_listbox.cpp | 35 ++++++++++++++++++++---------- pcbnew/pcb_netlist.cpp | 23 ++++++++++++++++---- pcbnew/pcb_netlist.h | 19 ++++++++-------- 3 files changed, 52 insertions(+), 25 deletions(-) diff --git a/cvpcb/class_footprints_listbox.cpp b/cvpcb/class_footprints_listbox.cpp index 74965c3f83..4d3f5b0b58 100644 --- a/cvpcb/class_footprints_listbox.cpp +++ b/cvpcb/class_footprints_listbox.cpp @@ -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 ), diff --git a/pcbnew/pcb_netlist.cpp b/pcbnew/pcb_netlist.cpp index 90a45a2981..cb54855dfc 100644 --- a/pcbnew/pcb_netlist.cpp +++ b/pcbnew/pcb_netlist.cpp @@ -6,7 +6,7 @@ * * Copyright (C) 1992-2011 Jean-Pierre Charras. * Copyright (C) 2013 Wayne Stambaugh . - * 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 #include +#include 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; diff --git a/pcbnew/pcb_netlist.h b/pcbnew/pcb_netlist.h index 9b694ca4ae..25b79f52c9 100644 --- a/pcbnew/pcb_netlist.h +++ b/pcbnew/pcb_netlist.h @@ -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 . - * 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 #include @@ -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 ) {