KiCad PCB EDA Suite
Loading...
Searching...
No Matches
footprint_info.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2011 Jean-Pierre Charras, <[email protected]>
5 * Copyright (C) 2013-2016 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22/*
23 * Functions to read footprint libraries and fill m_footprints by available footprints names
24 * and their documentation (comments and keywords)
25 */
26
27#include <footprint_info.h>
29#include <string_utils.h>
30#include <lib_id.h>
31#include <wx/tokenzr.h>
32
33FOOTPRINT_INFO* FOOTPRINT_LIST::GetFootprintInfo( const wxString& aLibNickname,
34 const wxString& aFootprintName )
35{
36 if( aFootprintName.IsEmpty() )
37 return nullptr;
38
39 for( std::unique_ptr<FOOTPRINT_INFO>& fp : m_list )
40 {
41 if( aLibNickname == fp->GetLibNickname() && aFootprintName == fp->GetFootprintName() )
42 return fp.get();
43 }
44
45 return nullptr;
46}
47
48
49FOOTPRINT_INFO* FOOTPRINT_LIST::GetFootprintInfo( const wxString& aFootprintName )
50{
51 if( aFootprintName.IsEmpty() )
52 return nullptr;
53
54 LIB_ID fpid;
55
56 wxCHECK_MSG( fpid.Parse( aFootprintName ) < 0, nullptr,
57 wxString::Format( wxT( "'%s' is not a valid LIB_ID." ), aFootprintName ) );
58
59 return GetFootprintInfo( fpid.GetLibNickname(), fpid.GetLibItemName() );
60}
61
62
63std::vector<SEARCH_TERM>& FOOTPRINT_INFO::GetSearchTerms()
64{
65 m_searchTerms.clear();
66 m_searchTerms.reserve( 6 );
67
68 m_searchTerms.emplace_back( SEARCH_TERM( GetLibNickname(), 4 ) );
69 m_searchTerms.emplace_back( SEARCH_TERM( GetName(), 8 ) );
70 m_searchTerms.emplace_back( SEARCH_TERM( GetLIB_ID().Format(), 16 ) );
71
72 wxStringTokenizer keywordTokenizer( GetKeywords(), " \t\r\n", wxTOKEN_STRTOK );
73
74 while( keywordTokenizer.HasMoreTokens() )
75 m_searchTerms.emplace_back( SEARCH_TERM( keywordTokenizer.GetNextToken(), 4 ) );
76
77 // Also include keywords as one long string, just in case
78 m_searchTerms.emplace_back( SEARCH_TERM( GetKeywords(), 1 ) );
79 m_searchTerms.emplace_back( SEARCH_TERM( GetDesc(), 1 ) );
80
81 return m_searchTerms;
82}
83
84
85bool FOOTPRINT_INFO::InLibrary( const wxString& aLibrary ) const
86{
87 return aLibrary == m_nickname;
88}
89
90
91bool operator<( const FOOTPRINT_INFO& lhs, const FOOTPRINT_INFO& rhs )
92{
93 int retv = StrNumCmp( lhs.m_nickname, rhs.m_nickname, false );
94
95 if( retv != 0 )
96 return retv < 0;
97
98 // Technically footprint names are not case sensitive because the file name is used
99 // as the footprint name. On windows this would be problematic because windows does
100 // not support case sensitive file names by default. This should not cause any issues
101 // and allow for a future change to use the name defined in the footprint file.
102 return StrNumCmp( lhs.m_fpname, rhs.m_fpname, false ) < 0;
103}
104
105
107{
108 wxString messages;
109
110 while( std::unique_ptr<IO_ERROR> error = PopError() )
111 {
112 if( !messages.IsEmpty() )
113 messages += wxS( "\n" );
114
115 messages += error->Problem();
116 }
117
118 return messages;
119}
bool InLibrary(const wxString &aLibrary) const
Test if the FOOTPRINT_INFO object was loaded from aLibrary.
LIB_ID GetLIB_ID() const override
wxString GetName() const override
wxString m_fpname
Module name.
wxString GetLibNickname() const override
wxString GetKeywords()
wxString m_nickname
library as known in FP_LIB_TABLE
std::vector< SEARCH_TERM > & GetSearchTerms() override
wxString GetDesc() override
std::vector< SEARCH_TERM > m_searchTerms
wxString GetErrorMessages()
Returns all accumulated errors as a newline-separated string for display in the status bar.
FOOTPRINT_INFO * GetFootprintInfo(const wxString &aFootprintName)
Get info for a footprint by id.
std::vector< std::unique_ptr< FOOTPRINT_INFO > > m_list
std::unique_ptr< IO_ERROR > PopError()
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:48
const UTF8 & GetLibItemName() const
Definition lib_id.h:98
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition lib_id.h:83
bool operator<(const FOOTPRINT_INFO &lhs, const FOOTPRINT_INFO &rhs)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition ptree.cpp:194
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
A structure for storing weighted search terms.