KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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 <core/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 int GetPinCount() override { return GetUniquePadCount(); }
76
77 LIB_ID GetLibId() const override
78 {
79 return LIB_ID( m_nickname, m_fpname );
80 }
81
82 wxString GetDescription() override
83 {
84 ensure_loaded();
85 return m_doc;
86 }
87
88 wxString GetKeywords()
89 {
90 ensure_loaded();
91 return m_keywords;
92 }
93
94 std::vector<SEARCH_TERM> GetSearchTerms() override;
95
96 unsigned GetPadCount()
97 {
98 ensure_loaded();
99 return m_pad_count;
100 }
101
103 {
104 ensure_loaded();
105 return m_unique_pad_count;
106 }
107
109 {
110 ensure_loaded();
111 return m_num;
112 }
113
122 bool InLibrary( const wxString& aLibrary ) const;
123
127 friend bool operator<( const FOOTPRINT_INFO& lhs, const FOOTPRINT_INFO& rhs );
128
129protected:
131 {
132 if( !m_loaded )
133 load();
134 }
135
137 virtual void load() { };
138
140
142
143 wxString m_nickname;
144 wxString m_fpname;
145 int m_num;
146 unsigned m_pad_count;
148 wxString m_doc;
149 wxString m_keywords;
150};
151
152
161{
162public:
163 typedef std::vector<std::unique_ptr<FOOTPRINT_INFO>> FPILIST;
165
166 FOOTPRINT_LIST() : m_lib_table( nullptr )
167 {
168 }
169
171 {
172 }
173
174 virtual void WriteCacheToFile( const wxString& aFilePath ) {};
175 virtual void ReadCacheFromFile( const wxString& aFilePath ){};
176
180 unsigned GetCount() const
181 {
182 return m_list.size();
183 }
184
186 const FPILIST& GetList() const
187 {
188 return m_list;
189 }
190
194 void Clear()
195 {
196 m_list.clear();
197 }
198
202 FOOTPRINT_INFO* GetFootprintInfo( const wxString& aFootprintName );
203
207 FOOTPRINT_INFO* GetFootprintInfo( const wxString& aLibNickname,
208 const wxString& aFootprintName );
209
216 FOOTPRINT_INFO& GetItem( unsigned aIdx ) const
217 {
218 return *m_list[aIdx];
219 }
220
221 unsigned GetErrorCount() const
222 {
223 return m_errors.size();
224 }
225
226 std::unique_ptr<IO_ERROR> PopError()
227 {
228 std::unique_ptr<IO_ERROR> error;
229
230 m_errors.pop( error );
231 return error;
232 }
233
246 virtual bool ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* aNickname = nullptr,
247 PROGRESS_REPORTER* aProgressReporter = nullptr ) = 0;
248
249 void DisplayErrors( wxTopLevelWindow* aCaller = nullptr );
250
252 {
253 return m_lib_table;
254 }
255
263 static FOOTPRINT_LIST* GetInstance( KIWAY& aKiway );
264
265protected:
267
270};
271
272
273
274#endif // FOOTPRINT_INFO_H_
wxString m_doc
Footprint description.
int m_num
Order number in the display list.
LIB_ID GetLibId() const override
int GetPinCount() override
The pin count for symbols or the unique pad count for footprints.
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:41
virtual std::vector< SEARCH_TERM > GetSearchTerms()
Definition: lib_tree_item.h:59
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:42