KiCad PCB EDA Suite
footprint_info.h
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) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25/*
26 * @file footprint_info.h
27 */
28
29#ifndef FOOTPRINT_INFO_H_
30#define FOOTPRINT_INFO_H_
31
32
33#include <boost/ptr_container/ptr_vector.hpp>
34#include <import_export.h>
35#include <ki_exception.h>
36#include <sync_queue.h>
37#include <lib_tree_item.h>
38#include <atomic>
39#include <functional>
40#include <memory>
41
42
43class FP_LIB_TABLE;
44class FOOTPRINT_LIST;
47class wxTopLevelWindow;
48class KIWAY;
49class wxTextFile;
50
51
52/*
53 * Helper class to handle the list of footprints available in libraries. It stores
54 * footprint names, doc and keywords.
55 *
56 * This is a virtual class; its implementation lives in pcbnew/footprint_info_impl.cpp.
57 * To get instances of these classes, see FOOTPRINT_LIST::GetInstance().
58 */
60{
61public:
63 {
64 }
65
66 // These two accessors do not have to call ensure_loaded(), because constructor
67 // fills in these fields:
68
69 const wxString& GetFootprintName() const { return m_fpname; }
70
71 wxString GetLibNickname() const override { return m_nickname; }
72
73 wxString GetName() const override { return m_fpname; }
74
75 LIB_ID GetLibId() const override
76 {
77 return LIB_ID( m_nickname, m_fpname );
78 }
79
80 wxString GetDescription() override
81 {
82 ensure_loaded();
83 return m_doc;
84 }
85
86 wxString GetKeywords()
87 {
88 ensure_loaded();
89 return m_keywords;
90 }
91
92 wxString GetSearchText() override
93 {
94 // Matches are scored by offset from front of string, so inclusion of this spacer
95 // discounts matches found after it.
96 static const wxString discount( wxT( " " ) );
97
98 return GetKeywords() + discount + GetDescription();
99 }
100
101 unsigned GetPadCount()
102 {
103 ensure_loaded();
104 return m_pad_count;
105 }
106
108 {
109 ensure_loaded();
110 return m_unique_pad_count;
111 }
112
114 {
115 ensure_loaded();
116 return m_num;
117 }
118
127 bool InLibrary( const wxString& aLibrary ) const;
128
132 friend bool operator<( const FOOTPRINT_INFO& lhs, const FOOTPRINT_INFO& rhs );
133
134protected:
136 {
137 if( !m_loaded )
138 load();
139 }
140
142 virtual void load() { };
143
145
147
148 wxString m_nickname;
149 wxString m_fpname;
150 int m_num;
151 unsigned m_pad_count;
153 wxString m_doc;
154 wxString m_keywords;
155};
156
157
166{
167public:
168 typedef std::vector<std::unique_ptr<FOOTPRINT_INFO>> FPILIST;
170
171 FOOTPRINT_LIST() : m_lib_table( nullptr )
172 {
173 }
174
176 {
177 }
178
179 virtual void WriteCacheToFile( const wxString& aFilePath ) {};
180 virtual void ReadCacheFromFile( const wxString& aFilePath ){};
181
185 unsigned GetCount() const
186 {
187 return m_list.size();
188 }
189
191 const FPILIST& GetList() const
192 {
193 return m_list;
194 }
195
199 void Clear()
200 {
201 m_list.clear();
202 }
203
207 FOOTPRINT_INFO* GetFootprintInfo( const wxString& aFootprintName );
208
212 FOOTPRINT_INFO* GetFootprintInfo( const wxString& aLibNickname,
213 const wxString& aFootprintName );
214
221 FOOTPRINT_INFO& GetItem( unsigned aIdx ) const
222 {
223 return *m_list[aIdx];
224 }
225
226 unsigned GetErrorCount() const
227 {
228 return m_errors.size();
229 }
230
231 std::unique_ptr<IO_ERROR> PopError()
232 {
233 std::unique_ptr<IO_ERROR> error;
234
235 m_errors.pop( error );
236 return error;
237 }
238
251 virtual bool ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* aNickname = nullptr,
252 PROGRESS_REPORTER* aProgressReporter = nullptr ) = 0;
253
254 void DisplayErrors( wxTopLevelWindow* aCaller = nullptr );
255
257 {
258 return m_lib_table;
259 }
260
268 static FOOTPRINT_LIST* GetInstance( KIWAY& aKiway );
269
270protected:
272
275};
276
277
278
279#endif // FOOTPRINT_INFO_H_
wxString GetSearchText() override
wxString m_doc
Footprint description.
int m_num
Order number in the display list.
LIB_ID GetLibId() const override
wxString GetName() const override
wxString m_fpname
Module name.
wxString GetLibNickname() const override
const wxString & GetFootprintName() const
unsigned GetPadCount()
virtual void load()
lazily load stuff not filled in by constructor. This may throw IO_ERRORS.
wxString m_keywords
Footprint keywords.
unsigned GetUniquePadCount()
wxString GetDescription() override
unsigned m_unique_pad_count
Number of unique pads.
wxString GetKeywords()
unsigned m_pad_count
Number of pads.
FOOTPRINT_LIST * m_owner
provides access to FP_LIB_TABLE
virtual ~FOOTPRINT_INFO()
wxString m_nickname
library as known in FP_LIB_TABLE
Holds a list of FOOTPRINT_INFO objects, along with a list of IO_ERRORs or PARSE_ERRORs that were thro...
virtual ~FOOTPRINT_LIST()
FP_LIB_TABLE * m_lib_table
no ownership
virtual void ReadCacheFromFile(const wxString &aFilePath)
unsigned GetErrorCount() const
virtual void WriteCacheToFile(const wxString &aFilePath)
std::vector< std::unique_ptr< FOOTPRINT_INFO > > FPILIST
virtual bool ReadFootprintFiles(FP_LIB_TABLE *aTable, const wxString *aNickname=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)=0
Read all the footprints provided by the combination of aTable and aNickname.
ERRLIST m_errors
some can be PARSE_ERRORs also
FP_LIB_TABLE * GetTable() const
unsigned GetCount() const
SYNC_QUEUE< std::unique_ptr< IO_ERROR > > ERRLIST
const FPILIST & GetList() const
Was forced to add this by modview_frame.cpp.
FOOTPRINT_INFO & GetItem(unsigned aIdx) const
Get info for a footprint by index.
std::unique_ptr< IO_ERROR > PopError()
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
Definition: lib_tree_item.h:40
virtual wxString GetDescription()=0
A progress reporter interface for use in multi-threaded environments.
Synchronized, locking queue.
Definition: sync_queue.h:32
bool operator<(const FOOTPRINT_INFO &lhs, const FOOTPRINT_INFO &rhs)
#define APIEXPORT
Macros which export functions from a DLL/DSO.
Definition: import_export.h:44