2017-03-23 00:59:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-01-07 08:13:00 +00:00
|
|
|
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-03-23 00:59:25 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FOOTPRINT_INFO_IMPL_H
|
|
|
|
#define FOOTPRINT_INFO_IMPL_H
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
|
|
|
#include <thread>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <footprint_info.h>
|
|
|
|
#include <sync_queue.h>
|
|
|
|
|
|
|
|
class LOCALE_IO;
|
|
|
|
|
|
|
|
class FOOTPRINT_INFO_IMPL : public FOOTPRINT_INFO
|
|
|
|
{
|
|
|
|
public:
|
2018-04-16 22:18:02 +00:00
|
|
|
FOOTPRINT_INFO_IMPL( FOOTPRINT_LIST* aOwner, const wxString& aNickname,
|
|
|
|
const wxString& aFootprintName )
|
2017-03-23 00:59:25 +00:00
|
|
|
{
|
|
|
|
m_owner = aOwner;
|
|
|
|
m_loaded = false;
|
|
|
|
m_nickname = aNickname;
|
|
|
|
m_fpname = aFootprintName;
|
|
|
|
m_num = 0;
|
|
|
|
m_pad_count = 0;
|
|
|
|
m_unique_pad_count = 0;
|
|
|
|
#if !USE_FPI_LAZY
|
|
|
|
load();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void load() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FOOTPRINT_LIST_IMPL : public FOOTPRINT_LIST
|
|
|
|
{
|
|
|
|
FOOTPRINT_ASYNC_LOADER* m_loader;
|
2018-04-04 00:19:20 +00:00
|
|
|
const wxString* m_library;
|
2017-03-23 00:59:25 +00:00
|
|
|
std::vector<std::thread> m_threads;
|
|
|
|
SYNC_QUEUE<wxString> m_queue_in;
|
|
|
|
SYNC_QUEUE<wxString> m_queue_out;
|
2018-01-07 08:13:00 +00:00
|
|
|
std::atomic_size_t m_count_finished;
|
2018-02-23 12:21:06 +00:00
|
|
|
long long m_list_timestamp;
|
2018-04-16 22:18:02 +00:00
|
|
|
PROGRESS_REPORTER* m_progress_reporter;
|
2018-02-10 13:32:57 +00:00
|
|
|
std::atomic_bool m_cancelled;
|
2018-06-04 20:44:43 +00:00
|
|
|
std::mutex m_join;
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Call aFunc, pushing any IO_ERRORs and std::exceptions it throws onto m_errors.
|
|
|
|
*
|
|
|
|
* @return true if no error occurred.
|
|
|
|
*/
|
2017-09-23 09:20:10 +00:00
|
|
|
bool CatchErrors( const std::function<void()>& aFunc );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
protected:
|
2018-04-16 22:18:02 +00:00
|
|
|
void StartWorkers( FP_LIB_TABLE* aTable, wxString const* aNickname,
|
|
|
|
FOOTPRINT_ASYNC_LOADER* aLoader, unsigned aNThreads ) override;
|
|
|
|
bool JoinWorkers() override;
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2018-05-23 15:52:48 +00:00
|
|
|
void StopWorkers() override;
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
/**
|
|
|
|
* Function loader_job
|
|
|
|
* loads footprints from m_queue_in.
|
|
|
|
*/
|
|
|
|
void loader_job();
|
|
|
|
|
|
|
|
public:
|
|
|
|
FOOTPRINT_LIST_IMPL();
|
|
|
|
virtual ~FOOTPRINT_LIST_IMPL();
|
|
|
|
|
2018-04-04 00:19:20 +00:00
|
|
|
bool ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* aNickname = nullptr,
|
2018-04-16 22:18:02 +00:00
|
|
|
PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
|
2017-03-23 00:59:25 +00:00
|
|
|
};
|
|
|
|
|
2018-03-25 12:48:13 +00:00
|
|
|
extern FOOTPRINT_LIST_IMPL GFootprintList; // KIFACE scope.
|
|
|
|
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
#endif // FOOTPRINT_INFO_IMPL_H
|