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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <boost/ptr_container/ptr_vector.hpp>
24#include <import_export.h>
25#include <ki_exception.h>
26#include <core/sync_queue.h>
27#include <lib_tree_item.h>
28#include <atomic>
29#include <functional>
30#include <memory>
31
32
34class FOOTPRINT_LIST;
37class wxTopLevelWindow;
38class KIWAY;
39class wxTextFile;
40
41
42/*
43 * Helper class to handle the list of footprints available in libraries. It stores
44 * footprint names, doc and keywords.
45 *
46 * This is a virtual class; its implementation lives in pcbnew/footprint_info_impl.cpp.
47 * To get instances of these classes, see FOOTPRINT_LIST::GetInstance().
48 */
50{
51public:
52 virtual ~FOOTPRINT_INFO() = default;
53
54 // These two accessors do not have to call ensure_loaded(), because constructor
55 // fills in these fields:
56
57 const wxString& GetFootprintName() const { return m_fpname; }
58
59 wxString GetLibNickname() const override { return m_nickname; }
60
61 wxString GetName() const override { return m_fpname; }
62
63 int GetPinCount() override { return GetNumberedPadCount(); }
64
65 LIB_ID GetLIB_ID() const override
66 {
67 return LIB_ID( m_nickname, m_fpname );
68 }
69
70 wxString GetDesc() override
71 {
73 return m_doc;
74 }
75
76 wxString GetKeywords()
77 {
79 return m_keywords;
80 }
81
86 std::vector<SEARCH_TERM>& GetSearchTerms() override;
87
89 {
92 }
93
95 {
97 return m_num;
98 }
99
108 bool InLibrary( const wxString& aLibrary ) const;
109
113 friend bool operator<( const FOOTPRINT_INFO& lhs, const FOOTPRINT_INFO& rhs );
114
115protected:
117 {
118 if( !m_loaded )
119 load();
120 }
121
123 virtual void load() { };
124
129 void cacheSearchTerms();
130
132
134
135 wxString m_nickname;
136 wxString m_fpname;
137 int m_num;
139 wxString m_doc;
140 wxString m_keywords;
141
142 std::vector<SEARCH_TERM> m_searchTerms;
143};
144
145
154{
155public:
157 m_adapter( nullptr )
158 {
159 }
160
161 virtual ~FOOTPRINT_LIST() = default;
162
163 unsigned GetCount() const { return m_list.size(); }
164
165 const std::vector<std::unique_ptr<FOOTPRINT_INFO>>& GetList() const { return m_list; }
166
170 virtual void Clear() = 0;
171
175 FOOTPRINT_INFO* GetFootprintInfo( const wxString& aFootprintName );
176
180 FOOTPRINT_INFO* GetFootprintInfo( const wxString& aLibNickname, const wxString& aFootprintName );
181
188 FOOTPRINT_INFO& GetItem( unsigned aIdx ) const
189 {
190 return *m_list[aIdx];
191 }
192
193 unsigned GetErrorCount() const
194 {
195 return m_errors.size();
196 }
197
198 std::unique_ptr<IO_ERROR> PopError()
199 {
200 std::unique_ptr<IO_ERROR> error;
201
202 m_errors.pop( error );
203 return error;
204 }
205
206 void PushError( std::unique_ptr<IO_ERROR> aError )
207 {
208 m_errors.move_push( std::move( aError ) );
209 }
210
223 virtual bool ReadFootprintFiles( FOOTPRINT_LIBRARY_ADAPTER* aAdapter, const wxString* aNickname = nullptr,
224 PROGRESS_REPORTER* aProgressReporter = nullptr ) = 0;
225
230 wxString GetErrorMessages();
231
233
234protected:
236
237 std::vector<std::unique_ptr<FOOTPRINT_INFO>> m_list;
239};
240
wxString m_doc
Footprint description.
virtual ~FOOTPRINT_INFO()=default
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 GetNumberedPadCount()
virtual void load()
lazily load stuff not filled in by constructor. This may throw IO_ERRORS.
wxString m_keywords
Footprint keywords.
unsigned m_numbered_pad_count
Number of unique electrical pads (numeric or BGA-style numbers)
wxString GetKeywords()
FOOTPRINT_LIST * m_owner
provides access to FP_LIB_TABLE
wxString m_nickname
library as known in FP_LIB_TABLE
wxString GetDesc() override
std::vector< SEARCH_TERM > m_searchTerms
An interface to the global shared library manager that is schematic-specific and linked to one projec...
Holds a list of FOOTPRINT_INFO objects, along with a list of IO_ERRORs or PARSE_ERRORs that were thro...
virtual bool ReadFootprintFiles(FOOTPRINT_LIBRARY_ADAPTER *aAdapter, const wxString *aNickname=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)=0
Read all the footprints provided by the combination of aTable and aNickname.
unsigned GetErrorCount() const
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.
virtual ~FOOTPRINT_LIST()=default
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
FOOTPRINT_LIBRARY_ADAPTER * m_adapter
no ownership
std::unique_ptr< IO_ERROR > PopError()
const std::vector< std::unique_ptr< FOOTPRINT_INFO > > & GetList() const
FOOTPRINT_LIBRARY_ADAPTER * GetAdapter() const
void PushError(std::unique_ptr< IO_ERROR > aError)
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:340
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
virtual std::vector< SEARCH_TERM > & GetSearchTerms()=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.