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-2017 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 
35 #include <import_export.h>
36 #include <ki_exception.h>
37 #include <kicad_string.h>
38 #include <sync_queue.h>
39 #include <lib_tree_item.h>
40 
41 #include <atomic>
42 #include <functional>
43 #include <memory>
44 
45 
46 class FP_LIB_TABLE;
47 class FOOTPRINT_LIST;
50 class PROGRESS_REPORTER;
51 class wxTopLevelWindow;
52 class KIWAY;
53 
54 
55 /*
56  * Helper class to handle the list of footprints available in libraries. It stores
57  * footprint names, doc and keywords.
58  *
59  * This is a virtual class; its implementation lives in pcbnew/footprint_info_impl.cpp.
60  * To get instances of these classes, see FOOTPRINT_LIST::GetInstance().
61  */
63 {
64  friend bool operator<( const FOOTPRINT_INFO& item1, const FOOTPRINT_INFO& item2 );
65 
66 public:
67  virtual ~FOOTPRINT_INFO()
68  {
69  }
70 
71  // These two accessors do not have to call ensure_loaded(), because constructor
72  // fills in these fields:
73 
74  const wxString& GetFootprintName() const
75  {
76  return m_fpname;
77  }
78 
79  wxString GetLibNickname() const override
80  {
81  return m_nickname;
82  }
83 
84  const wxString& GetName() const override
85  {
86  return m_fpname;
87  }
88 
89  LIB_ID GetLibId() const override
90  {
91  return LIB_ID( m_nickname, m_fpname );
92  }
93 
94  const wxString& GetDescription() override
95  {
96  ensure_loaded();
97  return m_doc;
98  }
99 
100  const wxString& GetKeywords()
101  {
102  ensure_loaded();
103  return m_keywords;
104  }
105 
106  wxString GetSearchText() override
107  {
108  // Matches are scored by offset from front of string, so inclusion of this spacer
109  // discounts matches found after it.
110  static const wxString discount( wxT( " " ) );
111 
112  return GetKeywords() + discount + GetDescription();
113  }
114 
115  unsigned GetPadCount()
116  {
117  ensure_loaded();
118  return m_pad_count;
119  }
120 
121  unsigned GetUniquePadCount()
122  {
123  ensure_loaded();
124  return m_unique_pad_count;
125  }
126 
128  {
129  ensure_loaded();
130  return m_num;
131  }
132 
141  bool InLibrary( const wxString& aLibrary ) const;
142 
143 protected:
145  {
146  if( !m_loaded )
147  load();
148  }
149 
151  virtual void load() { };
152 
153  FOOTPRINT_LIST* m_owner;
154 
155  bool m_loaded;
156 
157  wxString m_nickname;
158  wxString m_fpname;
159  int m_num;
160  unsigned m_pad_count;
162  wxString m_doc;
163  wxString m_keywords;
164 };
165 
166 
168 inline bool operator<( const FOOTPRINT_INFO& item1, const FOOTPRINT_INFO& item2 )
169 {
170  int retv = StrNumCmp( item1.m_nickname, item2.m_nickname, true );
171 
172  if( retv != 0 )
173  return retv < 0;
174 
175  return StrNumCmp( item1.m_fpname, item2.m_fpname, true ) < 0;
176 }
177 
178 
187 {
189 
190 protected:
192 
193  typedef std::vector<std::unique_ptr<FOOTPRINT_INFO>> FPILIST;
195 
198 
199 public:
200  FOOTPRINT_LIST() : m_lib_table( 0 )
201  {
202  }
203 
204  virtual ~FOOTPRINT_LIST()
205  {
206  }
207 
208  virtual void WriteCacheToFile( wxTextFile* aFile ) { };
209  virtual void ReadCacheFromFile( wxTextFile* aFile ) { };
210 
214  unsigned GetCount() const
215  {
216  return m_list.size();
217  }
218 
220  const FPILIST& GetList() const
221  {
222  return m_list;
223  }
224 
228  FOOTPRINT_INFO* GetModuleInfo( const wxString& aFootprintId );
229 
233  FOOTPRINT_INFO* GetModuleInfo( const wxString& aLibNickname, const wxString& aFootprintName );
234 
240  FOOTPRINT_INFO& GetItem( unsigned aIdx )
241  {
242  return *m_list[aIdx];
243  }
244 
245  unsigned GetErrorCount() const
246  {
247  return m_errors.size();
248  }
249 
250  std::unique_ptr<IO_ERROR> PopError()
251  {
252  std::unique_ptr<IO_ERROR> error;
253 
254  m_errors.pop( error );
255  return error;
256  }
257 
270  virtual bool ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* aNickname = nullptr,
271  PROGRESS_REPORTER* aProgressReporter = nullptr ) = 0;
272 
273  void DisplayErrors( wxTopLevelWindow* aCaller = NULL );
274 
276  {
277  return m_lib_table;
278  }
279 
286  static FOOTPRINT_LIST* GetInstance( KIWAY& aKiway );
287 
288 protected:
293  virtual void StartWorkers( FP_LIB_TABLE* aTable, wxString const* aNickname,
294  FOOTPRINT_ASYNC_LOADER* aLoader, unsigned aNThreads ) = 0;
295 
299  virtual bool JoinWorkers() = 0;
300 
304  virtual void StopWorkers() = 0;
305 };
306 
307 
314 {
315  friend class FOOTPRINT_LIST;
316  friend class FOOTPRINT_LIST_IMPL;
317 
319  std::string m_last_table;
320 
322 
323 public:
328 
330 
335  void SetList( FOOTPRINT_LIST* aList );
336 
344  void Start( FP_LIB_TABLE* aTable, wxString const* aNickname = nullptr,
345  unsigned aNThreads = DEFAULT_THREADS );
346 
361  bool Join();
362 
366  void Abort();
367 
372  static constexpr unsigned DEFAULT_THREADS = 6;
373 };
374 
375 
376 #endif // FOOTPRINT_INFO_H_
std::vector< std::unique_ptr< FOOTPRINT_INFO > > FPILIST
unsigned GetPadCount()
LIB_ID GetLibId() const override
const wxString & GetName() const override
#define APIEXPORT
Macros which export functions from a DLL/DSO.
Definition: import_export.h:44
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
Definition: string.cpp:342
bool pop(T &aReceiver)
Pop a value off the queue into the provided variable.
Definition: sync_queue.h:66
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:30
This class can be used to populate a FOOTPRINT_LIST asynchronously.
const wxString & GetDescription() override
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
virtual void WriteCacheToFile(wxTextFile *aFile)
virtual void ReadCacheFromFile(wxTextFile *aFile)
wxString m_doc
Footprint description.
unsigned GetCount() const
FOOTPRINT_INFO & GetItem(unsigned aIdx)
Get info for a module by index.
wxString m_fpname
Module name.
SYNC_QUEUE< std::unique_ptr< IO_ERROR > > ERRLIST
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
const wxString & GetKeywords()
virtual const wxString & GetDescription()=0
virtual ~FOOTPRINT_LIST()
virtual ~FOOTPRINT_INFO()
static bool Join(wxPoint *aIntersectPoint, wxPoint a0, wxPoint a1, wxPoint b0, wxPoint b1)
Function Join finds the point where line segment (b1,b0) intersects with segment (a1,...
wxString m_keywords
Footprint keywords.
std::unique_ptr< IO_ERROR > PopError()
size_t size() const
Return the size of the queue.
Definition: sync_queue.h:94
Holds a list of FOOTPRINT_INFO objects, along with a list of IO_ERRORs or PARSE_ERRORs that were thro...
unsigned GetErrorCount() const
unsigned GetUniquePadCount()
bool operator<(const FOOTPRINT_INFO &item1, const FOOTPRINT_INFO &item2)
FOOTPRINT object list sort function.
friend class FOOTPRINT_ASYNC_LOADER
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