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 GetLIB_ID() const override
78 {
79 return LIB_ID( m_nickname, m_fpname );
80 }
81
82 wxString GetDesc() 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:
164 m_lib_table( nullptr )
165 {
166 }
167
169 {
170 }
171
172 virtual void WriteCacheToFile( const wxString& aFilePath ) {};
173 virtual void ReadCacheFromFile( const wxString& aFilePath ){};
174
178 unsigned GetCount() const
179 {
180 return m_list.size();
181 }
182
184 const std::vector<std::unique_ptr<FOOTPRINT_INFO>>& GetList() const
185 {
186 return m_list;
187 }
188
192 virtual void Clear() = 0;
193
197 FOOTPRINT_INFO* GetFootprintInfo( const wxString& aFootprintName );
198
202 FOOTPRINT_INFO* GetFootprintInfo( const wxString& aLibNickname,
203 const wxString& aFootprintName );
204
211 FOOTPRINT_INFO& GetItem( unsigned aIdx ) const
212 {
213 return *m_list[aIdx];
214 }
215
216 unsigned GetErrorCount() const
217 {
218 return m_errors.size();
219 }
220
221 std::unique_ptr<IO_ERROR> PopError()
222 {
223 std::unique_ptr<IO_ERROR> error;
224
225 m_errors.pop( error );
226 return error;
227 }
228
241 virtual bool ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* aNickname = nullptr,
242 PROGRESS_REPORTER* aProgressReporter = nullptr ) = 0;
243
244 void DisplayErrors( wxTopLevelWindow* aCaller = nullptr );
245
247 {
248 return m_lib_table;
249 }
250
258 static FOOTPRINT_LIST* GetInstance( KIWAY& aKiway );
259
260protected:
262
263 std::vector<std::unique_ptr<FOOTPRINT_INFO>> m_list;
265};
266
267
268
269#endif // FOOTPRINT_INFO_H_
wxString m_doc
Footprint description.
int m_num
Order number in the display list.
int GetPinCount() override
The pin count for symbols or the unique pad count for footprints.
LIB_ID GetLIB_ID() 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()
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
wxString GetDesc() override
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)
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.
FP_LIB_TABLE * GetTable() const
SYNC_QUEUE< std::unique_ptr< IO_ERROR > > m_errors
some can be PARSE_ERRORs also
unsigned GetCount() const
FOOTPRINT_INFO & GetItem(unsigned aIdx) const
Get info for a footprint by index.
std::vector< std::unique_ptr< FOOTPRINT_INFO > > m_list
virtual void Clear()=0
std::unique_ptr< IO_ERROR > PopError()
const std::vector< std::unique_ptr< FOOTPRINT_INFO > > & GetList() const
Was forced to add this by modview_frame.cpp.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:284
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 DESIGN_BLOCK_INFO &lhs, const DESIGN_BLOCK_INFO &rhs)
#define APIEXPORT
Macros which export functions from a DLL/DSO.
Definition: import_export.h:42