Add contexts to EDA_COMBINED_MATCHER.

This commit is contained in:
Jeff Young 2022-08-13 00:51:19 +01:00
parent 6b349fdb0a
commit 18ac169ac7
6 changed files with 57 additions and 18 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2017 Chris Pavlina <pavlina.chris@gmail.com>
* Copyright (C) 2015-2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2015-2022 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
@ -85,6 +85,20 @@ bool EDA_PATTERN_MATCH_REGEX::SetPattern( const wxString& aPattern )
}
bool EDA_PATTERN_MATCH_REGEX_EXPLICIT::SetPattern( const wxString& aPattern )
{
wxString pattern( aPattern );
if( !pattern.StartsWith( wxT( "^" ) ) )
pattern = wxT( "^" ) + pattern;
if( !pattern.EndsWith( wxT( "$" ) ) )
pattern += wxT( "$" );
return EDA_PATTERN_MATCH_REGEX::SetPattern( pattern );
}
wxString const& EDA_PATTERN_MATCH_REGEX::GetPattern() const
{
return m_pattern;
@ -349,16 +363,27 @@ const std::map<wxString, double> EDA_PATTERN_MATCH_RELATIONAL::m_units = {
{ "ti", 1099511627776. } };
EDA_COMBINED_MATCHER::EDA_COMBINED_MATCHER( const wxString& aPattern )
EDA_COMBINED_MATCHER::EDA_COMBINED_MATCHER( const wxString& aPattern,
COMBINED_MATCHER_CONTEXT aContext )
: m_pattern( aPattern )
{
// Whatever syntax users prefer, it shall be matched.
AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_REGEX>() );
AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_WILDCARD>() );
AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_RELATIONAL>() );
// If any of the above matchers couldn't be created because the pattern
// syntax does not match, the substring will try its best.
AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_SUBSTR>() );
switch( aContext )
{
case CTX_LIBITEM:
// Whatever syntax users prefer, it shall be matched.
AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_REGEX>() );
AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_WILDCARD>() );
AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_RELATIONAL>() );
// If any of the above matchers couldn't be created because the pattern
// syntax does not match, the substring will try its best.
AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_SUBSTR>() );
break;
case CTX_NETCLASS:
AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_REGEX_EXPLICIT>() );
AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_WILDCARD_EXPLICIT>() );
break;
}
}

View File

@ -222,7 +222,7 @@ void FOOTPRINT_FILTER::FilterByTextPattern( wxString const& aPattern )
while( tokenizer.HasMoreTokens() )
{
const wxString term = tokenizer.GetNextToken().Lower();
m_pattern_filters.push_back( std::make_unique<EDA_COMBINED_MATCHER>( term ) );
m_pattern_filters.push_back( std::make_unique<EDA_COMBINED_MATCHER>( term, CTX_LIBITEM ) );
}
m_filter_type |= FILTERING_BY_TEXT_PATTERN;

View File

@ -191,7 +191,7 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( const wxString& aSearch, bool a
term = term.AfterFirst( ':' );
}
EDA_COMBINED_MATCHER matcher( term );
EDA_COMBINED_MATCHER matcher( term, CTX_LIBITEM );
m_tree.UpdateScore( matcher, lib );
}

View File

@ -610,7 +610,7 @@ bool SYMBOL_VIEWER_FRAME::ReCreateLibList()
while( tokenizer.HasMoreTokens() )
{
const wxString term = tokenizer.GetNextToken().Lower();
EDA_COMBINED_MATCHER matcher( term );
EDA_COMBINED_MATCHER matcher( term, CTX_LIBITEM );
int matches, position;
for( const wxString& lib : libs )
@ -683,7 +683,7 @@ bool SYMBOL_VIEWER_FRAME::ReCreateSymbolList()
while( tokenizer.HasMoreTokens() )
{
const wxString term = tokenizer.GetNextToken().Lower();
EDA_COMBINED_MATCHER matcher( term );
EDA_COMBINED_MATCHER matcher( term, CTX_LIBITEM );
int matches, position;
for( LIB_SYMBOL* symbol : symbols )

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2015-2022 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
@ -112,6 +112,13 @@ protected:
};
class EDA_PATTERN_MATCH_REGEX_EXPLICIT : public EDA_PATTERN_MATCH_REGEX
{
public:
virtual bool SetPattern( const wxString& aPattern ) override;
};
class EDA_PATTERN_MATCH_WILDCARD : public EDA_PATTERN_MATCH_REGEX
{
public:
@ -167,10 +174,17 @@ protected:
};
enum COMBINED_MATCHER_CONTEXT
{
CTX_LIBITEM,
CTX_NETCLASS
};
class EDA_COMBINED_MATCHER
{
public:
EDA_COMBINED_MATCHER( const wxString& aPattern );
EDA_COMBINED_MATCHER( const wxString& aPattern, COMBINED_MATCHER_CONTEXT aContext );
/*
* Look in all existing matchers, return the earliest match of any of

View File

@ -202,7 +202,7 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent
// In viewer, the default net clearance is not known (it depends on the actual board).
// So we do not show the default clearance, by setting it to 0
// The footprint or pad specific clearance will be shown
GetBoard()->GetDesignSettings().GetDefault()->SetClearance( 0 );
GetBoard()->GetDesignSettings().m_NetSettings->m_DefaultNetClass->SetClearance( 0 );
// Don't show the default board solder mask clearance in the footprint viewer. Only the
// footprint or pad clearance setting should be shown if it is not 0.
@ -477,7 +477,7 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList()
while( tokenizer.HasMoreTokens() )
{
const wxString term = tokenizer.GetNextToken().Lower();
EDA_COMBINED_MATCHER matcher( term );
EDA_COMBINED_MATCHER matcher( term, CTX_LIBITEM );
int matches, position;
for( const wxString& nickname : nicknames )
@ -554,7 +554,7 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList()
while( tokenizer.HasMoreTokens() )
{
const wxString term = tokenizer.GetNextToken().Lower();
EDA_COMBINED_MATCHER matcher( term );
EDA_COMBINED_MATCHER matcher( term, CTX_LIBITEM );
int matches, position;
for( const std::unique_ptr<FOOTPRINT_INFO>& footprint : fp_info_list->GetList() )