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, <jp.charras@wanadoo.fr>
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 
43 class FP_LIB_TABLE;
44 class FOOTPRINT_LIST;
47 class PROGRESS_REPORTER;
48 class wxTopLevelWindow;
49 class KIWAY;
50 class wxTextFile;
51 
52 
53 /*
54  * Helper class to handle the list of footprints available in libraries. It stores
55  * footprint names, doc and keywords.
56  *
57  * This is a virtual class; its implementation lives in pcbnew/footprint_info_impl.cpp.
58  * To get instances of these classes, see FOOTPRINT_LIST::GetInstance().
59  */
61 {
62 public:
63  virtual ~FOOTPRINT_INFO()
64  {
65  }
66 
67  // These two accessors do not have to call ensure_loaded(), because constructor
68  // fills in these fields:
69 
70  const wxString& GetFootprintName() const { return m_fpname; }
71 
72  wxString GetLibNickname() const override { return m_nickname; }
73 
74  wxString GetName() const override { return m_fpname; }
75 
76  LIB_ID GetLibId() const override
77  {
78  return LIB_ID( m_nickname, m_fpname );
79  }
80 
81  wxString GetDescription() override
82  {
83  ensure_loaded();
84  return m_doc;
85  }
86 
87  wxString GetKeywords()
88  {
89  ensure_loaded();
90  return m_keywords;
91  }
92 
93  wxString GetSearchText() override
94  {
95  // Matches are scored by offset from front of string, so inclusion of this spacer
96  // discounts matches found after it.
97  static const wxString discount( wxT( " " ) );
98 
99  return GetKeywords() + discount + GetDescription();
100  }
101 
102  unsigned GetPadCount()
103  {
104  ensure_loaded();
105  return m_pad_count;
106  }
107 
108  unsigned GetUniquePadCount()
109  {
110  ensure_loaded();
111  return m_unique_pad_count;
112  }
113 
115  {
116  ensure_loaded();
117  return m_num;
118  }
119 
128  bool InLibrary( const wxString& aLibrary ) const;
129 
133  friend bool operator<( const FOOTPRINT_INFO& lhs, const FOOTPRINT_INFO& rhs );
134 
135 protected:
137  {
138  if( !m_loaded )
139  load();
140  }
141 
143  virtual void load() { };
144 
145  FOOTPRINT_LIST* m_owner;
146 
147  bool m_loaded;
148 
149  wxString m_nickname;
150  wxString m_fpname;
151  int m_num;
152  unsigned m_pad_count;
154  wxString m_doc;
155  wxString m_keywords;
156 };
157 
158 
167 {
168 public:
169  typedef std::vector<std::unique_ptr<FOOTPRINT_INFO>> FPILIST;
171 
172  FOOTPRINT_LIST() : m_lib_table( nullptr )
173  {
174  }
175 
176  virtual ~FOOTPRINT_LIST()
177  {
178  }
179 
180  virtual void WriteCacheToFile( const wxString& aFilePath ) {};
181  virtual void ReadCacheFromFile( const wxString& aFilePath ){};
182 
186  unsigned GetCount() const
187  {
188  return m_list.size();
189  }
190 
192  const FPILIST& GetList() const
193  {
194  return m_list;
195  }
196 
200  void Clear()
201  {
202  m_list.clear();
203  }
204 
208  FOOTPRINT_INFO* GetFootprintInfo( const wxString& aFootprintName );
209 
213  FOOTPRINT_INFO* GetFootprintInfo( const wxString& aLibNickname,
214  const wxString& aFootprintName );
215 
222  FOOTPRINT_INFO& GetItem( unsigned aIdx ) const
223  {
224  return *m_list[aIdx];
225  }
226 
227  unsigned GetErrorCount() const
228  {
229  return m_errors.size();
230  }
231 
232  std::unique_ptr<IO_ERROR> PopError()
233  {
234  std::unique_ptr<IO_ERROR> error;
235 
236  m_errors.pop( error );
237  return error;
238  }
239 
252  virtual bool ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* aNickname = nullptr,
253  PROGRESS_REPORTER* aProgressReporter = nullptr ) = 0;
254 
255  void DisplayErrors( wxTopLevelWindow* aCaller = nullptr );
256 
258  {
259  return m_lib_table;
260  }
261 
269  static FOOTPRINT_LIST* GetInstance( KIWAY& aKiway );
270 
271 protected:
276  virtual void startWorkers( FP_LIB_TABLE* aTable, const wxString* aNickname,
277  FOOTPRINT_ASYNC_LOADER* aLoader, unsigned aNThreads ) = 0;
278 
282  virtual bool joinWorkers() = 0;
283 
287  virtual void stopWorkers() = 0;
288 
289 private:
291 
292 protected:
294 
297 };
298 
299 
307 {
308 public:
313 
315 
320  void SetList( FOOTPRINT_LIST* aList );
321 
330  void Start( FP_LIB_TABLE* aTable, const wxString* aNickname = nullptr,
331  unsigned aNThreads = DEFAULT_THREADS );
332 
347  bool Join();
348 
352  void Abort();
353 
354 private:
359  static constexpr unsigned DEFAULT_THREADS = 6;
360 
361  friend class FOOTPRINT_LIST;
362  friend class FOOTPRINT_LIST_IMPL;
363 
365  std::string m_last_table;
366 
368 };
369 
370 
371 #endif // FOOTPRINT_INFO_H_
std::vector< std::unique_ptr< FOOTPRINT_INFO > > FPILIST
unsigned GetPadCount()
LIB_ID GetLibId() const override
#define APIEXPORT
Macros which export functions from a DLL/DSO.
Definition: import_export.h:44
wxString GetLibNickname() const override
A progress reporter interface for use in multi-threaded environments.
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
Definition: lib_tree_item.h:38
ERRLIST m_errors
some can be PARSE_ERRORs also
const FPILIST & GetList() const
Was forced to add this by modview_frame.cpp.
wxString GetSearchText() override
FP_LIB_TABLE * m_lib_table
no ownership
Synchronized, locking queue.
Definition: sync_queue.h:31
wxString GetDescription() override
Object used to populate a FOOTPRINT_LIST asynchronously.
unsigned m_pad_count
Number of pads.
int m_num
Order number in the display list.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
FOOTPRINT_LIST * m_list
FOOTPRINT_INFO & GetItem(unsigned aIdx) const
Get info for a footprint by index.
wxString m_doc
Footprint description.
unsigned GetCount() const
virtual void WriteCacheToFile(const wxString &aFilePath)
wxString m_fpname
Module name.
bool operator<(const FOOTPRINT_INFO &lhs, const FOOTPRINT_INFO &rhs)
wxString GetName() const override
SYNC_QUEUE< std::unique_ptr< IO_ERROR > > ERRLIST
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
virtual wxString GetDescription()=0
virtual ~FOOTPRINT_LIST()
virtual ~FOOTPRINT_INFO()
wxString m_keywords
Footprint keywords.
std::unique_ptr< IO_ERROR > PopError()
Holds a list of FOOTPRINT_INFO objects, along with a list of IO_ERRORs or PARSE_ERRORs that were thro...
virtual void ReadCacheFromFile(const wxString &aFilePath)
unsigned GetErrorCount() const
unsigned GetUniquePadCount()
wxString GetKeywords()
FP_LIB_TABLE * GetTable() const
wxString m_nickname
library as known in FP_LIB_TABLE
unsigned m_unique_pad_count
Number of unique pads.
const wxString & GetFootprintName() const