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, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26/*
27 * Functions to read footprint libraries and fill m_footprints by available footprints names
28 * and their documentation (comments and keywords)
29 */
30
31#include <footprint_info.h>
33#include <string_utils.h>
34#include <lib_id.h>
35#include <wx/tokenzr.h>
36
37FOOTPRINT_INFO* FOOTPRINT_LIST::GetFootprintInfo( const wxString& aLibNickname,
38 const wxString& aFootprintName )
39{
40 if( aFootprintName.IsEmpty() )
41 return nullptr;
42
43 for( std::unique_ptr<FOOTPRINT_INFO>& fp : m_list )
44 {
45 if( aLibNickname == fp->GetLibNickname() && aFootprintName == fp->GetFootprintName() )
46 return fp.get();
47 }
48
49 return nullptr;
50}
51
52
53FOOTPRINT_INFO* FOOTPRINT_LIST::GetFootprintInfo( const wxString& aFootprintName )
54{
55 if( aFootprintName.IsEmpty() )
56 return nullptr;
57
58 LIB_ID fpid;
59
60 wxCHECK_MSG( fpid.Parse( aFootprintName ) < 0, nullptr,
61 wxString::Format( wxT( "'%s' is not a valid LIB_ID." ), aFootprintName ) );
62
63 return GetFootprintInfo( fpid.GetLibNickname(), fpid.GetLibItemName() );
64}
65
66
67std::vector<SEARCH_TERM>& FOOTPRINT_INFO::GetSearchTerms()
68{
69 m_searchTerms.clear();
70 m_searchTerms.reserve( 6 );
71
72 m_searchTerms.emplace_back( SEARCH_TERM( GetLibNickname(), 4 ) );
73 m_searchTerms.emplace_back( SEARCH_TERM( GetName(), 8 ) );
74 m_searchTerms.emplace_back( SEARCH_TERM( GetLIB_ID().Format(), 16 ) );
75
76 wxStringTokenizer keywordTokenizer( GetKeywords(), " \t\r\n", wxTOKEN_STRTOK );
77
78 while( keywordTokenizer.HasMoreTokens() )
79 m_searchTerms.emplace_back( SEARCH_TERM( keywordTokenizer.GetNextToken(), 4 ) );
80
81 // Also include keywords as one long string, just in case
82 m_searchTerms.emplace_back( SEARCH_TERM( GetKeywords(), 1 ) );
83 m_searchTerms.emplace_back( SEARCH_TERM( GetDesc(), 1 ) );
84
85 return m_searchTerms;
86}
87
88
89bool FOOTPRINT_INFO::InLibrary( const wxString& aLibrary ) const
90{
91 return aLibrary == m_nickname;
92}
93
94
95bool operator<( const FOOTPRINT_INFO& lhs, const FOOTPRINT_INFO& rhs )
96{
97 int retv = StrNumCmp( lhs.m_nickname, rhs.m_nickname, false );
98
99 if( retv != 0 )
100 return retv < 0;
101
102 // Technically footprint names are not case sensitive because the file name is used
103 // as the footprint name. On windows this would be problematic because windows does
104 // not support case sensitive file names by default. This should not cause any issues
105 // and allow for a future change to use the name defined in the footprint file.
106 return StrNumCmp( lhs.m_fpname, rhs.m_fpname, false ) < 0;
107}
108
109
111{
112 wxString messages;
113
114 while( std::unique_ptr<IO_ERROR> error = PopError() )
115 {
116 if( !messages.IsEmpty() )
117 messages += wxS( "\n" );
118
119 messages += error->Problem();
120 }
121
122 return messages;
123}
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:49
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:52
const UTF8 & GetLibItemName() const
Definition lib_id.h:102
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition lib_id.h:87
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:198
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
A structure for storing weighted search terms.