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, 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#pragma once
26
27#include <boost/ptr_container/ptr_vector.hpp>
28#include <import_export.h>
29#include <ki_exception.h>
30#include <core/sync_queue.h>
31#include <lib_tree_item.h>
32#include <atomic>
33#include <functional>
34#include <memory>
35
36
38class FOOTPRINT_LIST;
41class wxTopLevelWindow;
42class KIWAY;
43class wxTextFile;
44
45
46/*
47 * Helper class to handle the list of footprints available in libraries. It stores
48 * footprint names, doc and keywords.
49 *
50 * This is a virtual class; its implementation lives in pcbnew/footprint_info_impl.cpp.
51 * To get instances of these classes, see FOOTPRINT_LIST::GetInstance().
52 */
54{
55public:
56 virtual ~FOOTPRINT_INFO() = default;
57
58 // These two accessors do not have to call ensure_loaded(), because constructor
59 // fills in these fields:
60
61 const wxString& GetFootprintName() const { return m_fpname; }
62
63 wxString GetLibNickname() const override { return m_nickname; }
64
65 wxString GetName() const override { return m_fpname; }
66
67 int GetPinCount() override { return GetUniquePadCount(); }
68
69 LIB_ID GetLIB_ID() const override
70 {
71 return LIB_ID( m_nickname, m_fpname );
72 }
73
74 wxString GetDesc() override
75 {
77 return m_doc;
78 }
79
80 wxString GetKeywords()
81 {
83 return m_keywords;
84 }
85
86 std::vector<SEARCH_TERM> GetSearchTerms() override;
87
88 unsigned GetPadCount()
89 {
91 return m_pad_count;
92 }
93
95 {
97 return m_unique_pad_count;
98 }
99
101 {
103 return m_num;
104 }
105
114 bool InLibrary( const wxString& aLibrary ) const;
115
119 friend bool operator<( const FOOTPRINT_INFO& lhs, const FOOTPRINT_INFO& rhs );
120
121protected:
123 {
124 if( !m_loaded )
125 load();
126 }
127
129 virtual void load() { };
130
132
134
135 wxString m_nickname;
136 wxString m_fpname;
137 int m_num;
138 unsigned m_pad_count;
140 wxString m_doc;
141 wxString m_keywords;
142};
143
144
153{
154public:
156 m_adapter( nullptr )
157 {
158 }
159
160 virtual ~FOOTPRINT_LIST() = default;
161
162 unsigned GetCount() const { return m_list.size(); }
163
164 const std::vector<std::unique_ptr<FOOTPRINT_INFO>>& GetList() const { return m_list; }
165
169 virtual void Clear() = 0;
170
174 FOOTPRINT_INFO* GetFootprintInfo( const wxString& aFootprintName );
175
179 FOOTPRINT_INFO* GetFootprintInfo( const wxString& aLibNickname, const wxString& aFootprintName );
180
187 FOOTPRINT_INFO& GetItem( unsigned aIdx ) const
188 {
189 return *m_list[aIdx];
190 }
191
192 unsigned GetErrorCount() const
193 {
194 return m_errors.size();
195 }
196
197 std::unique_ptr<IO_ERROR> PopError()
198 {
199 std::unique_ptr<IO_ERROR> error;
200
201 m_errors.pop( error );
202 return error;
203 }
204
205 void PushError( std::unique_ptr<IO_ERROR> aError )
206 {
207 m_errors.move_push( std::move( aError ) );
208 }
209
222 virtual bool ReadFootprintFiles( FOOTPRINT_LIBRARY_ADAPTER* aAdapter, const wxString* aNickname = nullptr,
223 PROGRESS_REPORTER* aProgressReporter = nullptr ) = 0;
224
229 wxString GetErrorMessages();
230
232
233protected:
235
236 std::vector<std::unique_ptr<FOOTPRINT_INFO>> m_list;
238};
239
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 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
wxString m_nickname
library as known in FP_LIB_TABLE
wxString GetDesc() override
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:295
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).
virtual std::vector< SEARCH_TERM > GetSearchTerms()
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.