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-2020 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 private:
136  friend bool operator<( const FOOTPRINT_INFO& item1, const FOOTPRINT_INFO& item2 );
137 
138 protected:
140  {
141  if( !m_loaded )
142  load();
143  }
144 
146  virtual void load() { };
147 
148  FOOTPRINT_LIST* m_owner;
149 
150  bool m_loaded;
151 
152  wxString m_nickname;
153  wxString m_fpname;
154  int m_num;
155  unsigned m_pad_count;
157  wxString m_doc;
158  wxString m_keywords;
159 };
160 
161 
170 {
171 public:
172  typedef std::vector<std::unique_ptr<FOOTPRINT_INFO>> FPILIST;
174 
175  FOOTPRINT_LIST() : m_lib_table( 0 )
176  {
177  }
178 
179  virtual ~FOOTPRINT_LIST()
180  {
181  }
182 
183  virtual void WriteCacheToFile( const wxString& aFilePath ) {};
184  virtual void ReadCacheFromFile( const wxString& aFilePath ){};
185 
189  unsigned GetCount() const
190  {
191  return m_list.size();
192  }
193 
195  const FPILIST& GetList() const
196  {
197  return m_list;
198  }
199 
203  void Clear()
204  {
205  m_list.clear();
206  }
207 
211  FOOTPRINT_INFO* GetFootprintInfo( const wxString& aFootprintName );
212 
216  FOOTPRINT_INFO* GetFootprintInfo( const wxString& aLibNickname,
217  const wxString& aFootprintName );
218 
225  FOOTPRINT_INFO& GetItem( unsigned aIdx )
226  {
227  return *m_list[aIdx];
228  }
229 
230  unsigned GetErrorCount() const
231  {
232  return m_errors.size();
233  }
234 
235  std::unique_ptr<IO_ERROR> PopError()
236  {
237  std::unique_ptr<IO_ERROR> error;
238 
239  m_errors.pop( error );
240  return error;
241  }
242 
255  virtual bool ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* aNickname = nullptr,
256  PROGRESS_REPORTER* aProgressReporter = nullptr ) = 0;
257 
258  void DisplayErrors( wxTopLevelWindow* aCaller = NULL );
259 
261  {
262  return m_lib_table;
263  }
264 
272  static FOOTPRINT_LIST* GetInstance( KIWAY& aKiway );
273 
274 protected:
279  virtual void startWorkers( FP_LIB_TABLE* aTable, wxString const* aNickname,
280  FOOTPRINT_ASYNC_LOADER* aLoader, unsigned aNThreads ) = 0;
281 
285  virtual bool joinWorkers() = 0;
286 
290  virtual void stopWorkers() = 0;
291 
292 private:
294 
295 protected:
297 
300 };
301 
302 
310 {
311 public:
316 
318 
323  void SetList( FOOTPRINT_LIST* aList );
324 
333  void Start( FP_LIB_TABLE* aTable, wxString const* aNickname = nullptr,
334  unsigned aNThreads = DEFAULT_THREADS );
335 
350  bool Join();
351 
355  void Abort();
356 
357 private:
362  static constexpr unsigned DEFAULT_THREADS = 6;
363 
364  friend class FOOTPRINT_LIST;
365  friend class FOOTPRINT_LIST_IMPL;
366 
368  std::string m_last_table;
369 
371 };
372 
373 
374 #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 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:39
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
wxString m_doc
Footprint description.
unsigned GetCount() const
virtual void WriteCacheToFile(const wxString &aFilePath)
FOOTPRINT_INFO & GetItem(unsigned aIdx)
Get info for a footprint by index.
#define NULL
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