KiCad PCB EDA Suite
footprint_info_impl.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) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef FOOTPRINT_INFO_IMPL_H
21 #define FOOTPRINT_INFO_IMPL_H
22 
23 #include <atomic>
24 #include <functional>
25 #include <memory>
26 #include <thread>
27 #include <vector>
28 
29 #include <footprint_info.h>
30 #include <sync_queue.h>
31 
32 class LOCALE_IO;
33 
35 {
36 public:
37  FOOTPRINT_INFO_IMPL( FOOTPRINT_LIST* aOwner, const wxString& aNickname,
38  const wxString& aFootprintName )
39  {
40  m_nickname = aNickname;
41  m_fpname = aFootprintName;
42  m_num = 0;
43  m_pad_count = 0;
45 
46  m_owner = aOwner;
47  m_loaded = false;
48  load();
49  }
50 
51  // A constructor for cached items
52  FOOTPRINT_INFO_IMPL( const wxString& aNickname, const wxString& aFootprintName,
53  const wxString& aDescription, const wxString& aKeywords,
54  int aOrderNum, unsigned int aPadCount, unsigned int aUniquePadCount )
55  {
56  m_nickname = aNickname;
57  m_fpname = aFootprintName;
58  m_num = aOrderNum;
59  m_pad_count = aPadCount;
60  m_unique_pad_count = aUniquePadCount;
61  m_doc = aDescription;
62  m_keywords = aKeywords;
63 
64  m_owner = nullptr;
65  m_loaded = true;
66  }
67 
68 
69  // A dummy constructor for use as a target in a binary search
70  FOOTPRINT_INFO_IMPL( const wxString& aNickname, const wxString& aFootprintName )
71  {
72  m_nickname = aNickname;
73  m_fpname = aFootprintName;
74 
75  m_owner = nullptr;
76  m_loaded = true;
77  }
78 
79 protected:
80  virtual void load() override;
81 };
82 
83 
85 {
87  std::vector<std::thread> m_threads;
90  std::atomic_size_t m_count_finished;
91  long long m_list_timestamp;
93  std::atomic_bool m_cancelled;
94  std::mutex m_join;
95 
101  bool CatchErrors( const std::function<void()>& aFunc );
102 
103 protected:
104  void StartWorkers( FP_LIB_TABLE* aTable, wxString const* aNickname,
105  FOOTPRINT_ASYNC_LOADER* aLoader, unsigned aNThreads ) override;
106  bool JoinWorkers() override;
107 
108  void StopWorkers() override;
109 
114  void loader_job();
115 
116 public:
118  virtual ~FOOTPRINT_LIST_IMPL();
119 
120  void WriteCacheToFile( wxTextFile* aFile ) override;
121  void ReadCacheFromFile( wxTextFile* aFile ) override;
122 
123  bool ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* aNickname = nullptr,
124  PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
125 };
126 
127 extern FOOTPRINT_LIST_IMPL GFootprintList; // KIFACE scope.
128 
129 
130 #endif // FOOTPRINT_INFO_IMPL_H
FOOTPRINT_INFO_IMPL(FOOTPRINT_LIST *aOwner, const wxString &aNickname, const wxString &aFootprintName)
SYNC_QUEUE< wxString > m_queue_out
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:179
A progress reporter for use in multi-threaded environments.
std::atomic_bool m_cancelled
This class can be used to populate a FOOTPRINT_LIST asynchronously.
unsigned m_pad_count
Number of pads.
std::vector< std::thread > m_threads
int m_num
Order number in the display list.
FOOTPRINT_LIST * m_owner
provides access to FP_LIB_TABLE
SYNC_QUEUE< wxString > m_queue_in
wxString m_doc
Footprint description.
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: pcbnew.cpp:338
PROGRESS_REPORTER * m_progress_reporter
FOOTPRINT_INFO_IMPL(const wxString &aNickname, const wxString &aFootprintName)
wxString m_fpname
Module name.
std::atomic_size_t m_count_finished
wxString m_keywords
Footprint keywords.
FOOTPRINT_ASYNC_LOADER * m_loader
Holds a list of FOOTPRINT_INFO objects, along with a list of IO_ERRORs or PARSE_ERRORs that were thro...
FOOTPRINT_INFO_IMPL(const wxString &aNickname, const wxString &aFootprintName, const wxString &aDescription, const wxString &aKeywords, int aOrderNum, unsigned int aPadCount, unsigned int aUniquePadCount)
wxString m_nickname
library as known in FP_LIB_TABLE
virtual void load() override
lazily load stuff not filled in by constructor. This may throw IO_ERRORS.
unsigned m_unique_pad_count
Number of unique pads.