KiCad PCB EDA Suite
Loading...
Searching...
No Matches
DB_AUTOFILL Namespace Reference

Guesses the table and column mappings of a new database library from their names. More...

Classes

struct  ROLE
 One mapping to fill, such as the key column or the Value field. More...
 

Enumerations

enum  MATCH_SCORE {
  NO_MATCH = 0 , SUBSTRING = 10 , AFFIX = 30 , INNER_WORD = 60 ,
  EDGE_WORD = 80 , EXACT = 100 , REMEMBERED = 1000
}
 

Functions

static std::vector< wxString > SplitWords (const wxString &aName)
 Splits an identifier into lower case words: "PCBFootprint_ref2" gives pcb, footprint, ref, 2.
 
static bool sameWord (const wxString &aA, const wxString &aB)
 
static bool wordsMatchAt (const std::vector< wxString > &aWords, const std::vector< wxString > &aTerm, size_t aPos)
 
static wxString joined (const std::vector< wxString > &aWords)
 
static int MatchScore (const wxString &aName, const wxString &aTerm)
 
static int roleScore (const ROLE &aRole, const std::string &aColumn)
 
std::vector< std::string > AssignColumns (const std::vector< std::string > &aColumns, const std::vector< ROLE > &aRoles)
 Chooses a column for each role, best scores first, so no column serves two roles.
 
std::string MatchTable (const std::vector< std::string > &aTables, const std::string &aLibraryName)
 
std::map< std::string, size_t > RepeatCounts (const std::vector< std::map< std::string, std::any > > &aRows)
 Counts, per column, the rows whose value already appeared in an earlier row, with NULL counted as empty.
 
void RememberChoice (std::vector< std::string > &aHistory, const std::string &aColumn)
 Moves aColumn to the front of a role's history, dropping repeats and the oldest entries.
 

Variables

static constexpr size_t MAX_REMEMBERED = 8
 

Detailed Description

Guesses the table and column mappings of a new database library from their names.

Names are compared word by word, where words break at separators, digits and case changes, so "PartID" and "part_id" both end in the word "id" while "Identical" and "Flacid" only contain it.

Enumeration Type Documentation

◆ MATCH_SCORE

Enumerator
NO_MATCH 
SUBSTRING 

The term is buried inside a word: "myfootprintref" for "footprint".

AFFIX 

The name starts or ends with the term mid-word: "Identical", "partid".

INNER_WORD 

The term is a whole word inside the name: "Main ID Code".

EDGE_WORD 

The term is a whole word at either end: "PartID", "symbol_ref".

EXACT 

The name is the term: "ID", "Symbols".

REMEMBERED 

A column the user chose before; earlier choices score lower.

Definition at line 33 of file database_autofill.cpp.

Function Documentation

◆ AssignColumns()

KICOMMON_API std::vector< std::string > DB_AUTOFILL::AssignColumns ( const std::vector< std::string > & aColumns,
const std::vector< ROLE > & aRoles )

Chooses a column for each role, best scores first, so no column serves two roles.

Returns
the chosen column per role, or an empty string where nothing matched

Definition at line 183 of file database_autofill.cpp.

References candidates(), NO_MATCH, and roleScore().

Referenced by DIALOG_DATABASE_LIB_SETTINGS::autofillColumns().

◆ joined()

static wxString DB_AUTOFILL::joined ( const std::vector< wxString > & aWords)
static

Definition at line 110 of file database_autofill.cpp.

Referenced by MatchScore().

◆ MatchScore()

static int DB_AUTOFILL::MatchScore ( const wxString & aName,
const wxString & aTerm )
static
Returns
how well aName matches aTerm, from MATCH_SCORE; plurals match their singular

Definition at line 122 of file database_autofill.cpp.

References AFFIX, EDGE_WORD, EXACT, INNER_WORD, joined(), name, NO_MATCH, SplitWords(), SUBSTRING, and wordsMatchAt().

Referenced by MatchTable(), and roleScore().

◆ MatchTable()

KICOMMON_API std::string DB_AUTOFILL::MatchTable ( const std::vector< std::string > & aTables,
const std::string & aLibraryName )
Returns
the table named like the library, or an empty string when none shares a whole word

Definition at line 217 of file database_autofill.cpp.

References INNER_WORD, library, MatchScore(), name, and table.

Referenced by DIALOG_DATABASE_LIB_SETTINGS::autofillTable().

◆ RememberChoice()

KICOMMON_API void DB_AUTOFILL::RememberChoice ( std::vector< std::string > & aHistory,
const std::string & aColumn )

Moves aColumn to the front of a role's history, dropping repeats and the oldest entries.

Definition at line 264 of file database_autofill.cpp.

References MAX_REMEMBERED.

Referenced by DIALOG_DATABASE_LIB_SETTINGS::TransferDataFromWindow().

◆ RepeatCounts()

KICOMMON_API std::map< std::string, size_t > DB_AUTOFILL::RepeatCounts ( const std::vector< std::map< std::string, std::any > > & aRows)

Counts, per column, the rows whose value already appeared in an earlier row, with NULL counted as empty.

A key column needs a count of zero, or parts sharing a key hide each other.

Definition at line 241 of file database_autofill.cpp.

References text.

Referenced by DIALOG_DATABASE_LIB_SETTINGS::ensureSample().

◆ roleScore()

static int DB_AUTOFILL::roleScore ( const ROLE & aRole,
const std::string & aColumn )
static

◆ sameWord()

static bool DB_AUTOFILL::sameWord ( const wxString & aA,
const wxString & aB )
static

Definition at line 91 of file database_autofill.cpp.

Referenced by wordsMatchAt().

◆ SplitWords()

static std::vector< wxString > DB_AUTOFILL::SplitWords ( const wxString & aName)
static

Splits an identifier into lower case words: "PCBFootprint_ref2" gives pcb, footprint, ref, 2.

Definition at line 46 of file database_autofill.cpp.

Referenced by MatchScore().

◆ wordsMatchAt()

static bool DB_AUTOFILL::wordsMatchAt ( const std::vector< wxString > & aWords,
const std::vector< wxString > & aTerm,
size_t aPos )
static

Definition at line 98 of file database_autofill.cpp.

References sameWord().

Referenced by MatchScore().

Variable Documentation

◆ MAX_REMEMBERED

size_t DB_AUTOFILL::MAX_REMEMBERED = 8
staticconstexpr

Definition at line 31 of file database_autofill.cpp.

Referenced by RememberChoice().