2013-05-26 04:36:44 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Jean-Pierre Charras, <jp.charras@wanadoo.fr>
|
2020-12-19 16:00:52 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-05-26 04:36:44 +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 2
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @file footprint_info.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FOOTPRINT_INFO_H_
|
|
|
|
#define FOOTPRINT_INFO_H_
|
|
|
|
|
2013-06-07 12:15:32 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
#include <boost/ptr_container/ptr_vector.hpp>
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <import_export.h>
|
|
|
|
#include <ki_exception.h>
|
|
|
|
#include <sync_queue.h>
|
2018-07-29 00:11:39 +00:00
|
|
|
#include <lib_tree_item.h>
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <atomic>
|
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2013-05-28 16:54:59 +00:00
|
|
|
class FP_LIB_TABLE;
|
2013-12-12 16:01:03 +00:00
|
|
|
class FOOTPRINT_LIST;
|
2017-03-23 00:59:25 +00:00
|
|
|
class FOOTPRINT_LIST_IMPL;
|
|
|
|
class FOOTPRINT_ASYNC_LOADER;
|
2018-04-16 22:18:02 +00:00
|
|
|
class PROGRESS_REPORTER;
|
2013-12-09 18:09:58 +00:00
|
|
|
class wxTopLevelWindow;
|
2017-03-23 00:59:25 +00:00
|
|
|
class KIWAY;
|
2020-10-24 14:45:37 +00:00
|
|
|
class wxTextFile;
|
2013-05-28 16:54:59 +00:00
|
|
|
|
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
/*
|
2017-03-23 00:59:25 +00:00
|
|
|
* Helper class to handle the list of footprints available in libraries. It stores
|
|
|
|
* footprint names, doc and keywords.
|
|
|
|
*
|
|
|
|
* This is a virtual class; its implementation lives in pcbnew/footprint_info_impl.cpp.
|
|
|
|
* To get instances of these classes, see FOOTPRINT_LIST::GetInstance().
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
2018-07-29 00:11:39 +00:00
|
|
|
class APIEXPORT FOOTPRINT_INFO : public LIB_TREE_ITEM
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
2013-05-31 17:33:46 +00:00
|
|
|
public:
|
2017-03-23 00:59:25 +00:00
|
|
|
virtual ~FOOTPRINT_INFO()
|
|
|
|
{
|
|
|
|
}
|
2013-10-31 21:30:57 +00:00
|
|
|
|
2013-12-12 16:01:03 +00:00
|
|
|
// These two accessors do not have to call ensure_loaded(), because constructor
|
|
|
|
// fills in these fields:
|
2013-10-31 21:30:57 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
const wxString& GetFootprintName() const { return m_fpname; }
|
2013-10-31 21:30:57 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
wxString GetLibNickname() const override { return m_nickname; }
|
2013-10-31 21:30:57 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
wxString GetName() const override { return m_fpname; }
|
2018-07-29 00:11:39 +00:00
|
|
|
|
|
|
|
LIB_ID GetLibId() const override
|
|
|
|
{
|
|
|
|
return LIB_ID( m_nickname, m_fpname );
|
|
|
|
}
|
|
|
|
|
2019-11-08 20:50:04 +00:00
|
|
|
wxString GetDescription() override
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
2013-12-12 16:01:03 +00:00
|
|
|
ensure_loaded();
|
|
|
|
return m_doc;
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
|
|
|
|
2019-11-08 20:50:04 +00:00
|
|
|
wxString GetKeywords()
|
2013-12-12 16:01:03 +00:00
|
|
|
{
|
|
|
|
ensure_loaded();
|
|
|
|
return m_keywords;
|
|
|
|
}
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2018-07-29 00:11:39 +00:00
|
|
|
wxString GetSearchText() override
|
|
|
|
{
|
2018-08-05 11:56:02 +00:00
|
|
|
// Matches are scored by offset from front of string, so inclusion of this spacer
|
|
|
|
// discounts matches found after it.
|
|
|
|
static const wxString discount( wxT( " " ) );
|
|
|
|
|
|
|
|
return GetKeywords() + discount + GetDescription();
|
2018-07-29 00:11:39 +00:00
|
|
|
}
|
|
|
|
|
2013-12-12 16:01:03 +00:00
|
|
|
unsigned GetPadCount()
|
|
|
|
{
|
|
|
|
ensure_loaded();
|
|
|
|
return m_pad_count;
|
|
|
|
}
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2015-11-11 18:35:26 +00:00
|
|
|
unsigned GetUniquePadCount()
|
|
|
|
{
|
|
|
|
ensure_loaded();
|
|
|
|
return m_unique_pad_count;
|
|
|
|
}
|
|
|
|
|
2013-12-12 16:01:03 +00:00
|
|
|
int GetOrderNum()
|
|
|
|
{
|
|
|
|
ensure_loaded();
|
|
|
|
return m_num;
|
|
|
|
}
|
2013-06-07 12:15:32 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-23 00:59:25 +00:00
|
|
|
* Test if the #FOOTPRINT_INFO object was loaded from \a aLibrary.
|
2013-06-07 12:15:32 +00:00
|
|
|
*
|
2013-10-31 21:30:57 +00:00
|
|
|
* @param aLibrary is the nickname of the library to test.
|
|
|
|
*
|
2013-06-07 12:15:32 +00:00
|
|
|
* @return true if the #FOOTPRINT_INFO object was loaded from \a aLibrary. Otherwise
|
|
|
|
* false.
|
|
|
|
*/
|
|
|
|
bool InLibrary( const wxString& aLibrary ) const;
|
2013-12-12 16:01:03 +00:00
|
|
|
|
2020-10-15 22:39:33 +00:00
|
|
|
/**
|
|
|
|
* Less than comparison operator, intended for sorting FOOTPRINT_INFO objects
|
|
|
|
*/
|
|
|
|
friend bool operator<( const FOOTPRINT_INFO& lhs, const FOOTPRINT_INFO& rhs );
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
protected:
|
2013-12-12 16:01:03 +00:00
|
|
|
void ensure_loaded()
|
|
|
|
{
|
|
|
|
if( !m_loaded )
|
|
|
|
load();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// lazily load stuff not filled in by constructor. This may throw IO_ERRORS.
|
2018-08-03 16:53:38 +00:00
|
|
|
virtual void load() { };
|
2013-12-12 16:01:03 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
FOOTPRINT_LIST* m_owner; ///< provides access to FP_LIB_TABLE
|
2013-12-12 16:01:03 +00:00
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
bool m_loaded;
|
|
|
|
|
|
|
|
wxString m_nickname; ///< library as known in FP_LIB_TABLE
|
|
|
|
wxString m_fpname; ///< Module name.
|
|
|
|
int m_num; ///< Order number in the display list.
|
|
|
|
unsigned m_pad_count; ///< Number of pads
|
|
|
|
unsigned m_unique_pad_count; ///< Number of unique pads
|
|
|
|
wxString m_doc; ///< Footprint description.
|
|
|
|
wxString m_keywords; ///< Footprint keywords.
|
2013-05-26 04:36:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-12-09 18:09:58 +00:00
|
|
|
/**
|
2020-12-19 16:00:52 +00:00
|
|
|
* Holds a list of #FOOTPRINT_INFO objects, along with a list of IO_ERRORs or
|
2013-12-09 18:09:58 +00:00
|
|
|
* PARSE_ERRORs that were thrown acquiring the FOOTPRINT_INFOs.
|
2017-03-23 00:59:25 +00:00
|
|
|
*
|
|
|
|
* This is a virtual class; its implementation lives in pcbnew/footprint_info_impl.cpp.
|
|
|
|
* To get instances of these classes, see FOOTPRINT_LIST::GetInstance().
|
2013-12-09 18:09:58 +00:00
|
|
|
*/
|
2017-03-23 00:59:25 +00:00
|
|
|
class APIEXPORT FOOTPRINT_LIST
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
2020-12-19 16:00:52 +00:00
|
|
|
public:
|
2017-03-23 00:59:25 +00:00
|
|
|
typedef std::vector<std::unique_ptr<FOOTPRINT_INFO>> FPILIST;
|
|
|
|
typedef SYNC_QUEUE<std::unique_ptr<IO_ERROR>> ERRLIST;
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
FOOTPRINT_LIST() : m_lib_table( 0 )
|
2013-12-12 16:01:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
virtual ~FOOTPRINT_LIST()
|
2013-12-09 18:09:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-12-11 01:08:51 +00:00
|
|
|
virtual void WriteCacheToFile( const wxString& aFilePath ) {};
|
|
|
|
virtual void ReadCacheFromFile( const wxString& aFilePath ){};
|
2018-08-03 16:53:38 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
/**
|
|
|
|
* @return the number of items stored in list
|
|
|
|
*/
|
2017-03-23 00:59:25 +00:00
|
|
|
unsigned GetCount() const
|
|
|
|
{
|
|
|
|
return m_list.size();
|
|
|
|
}
|
2013-12-09 18:09:58 +00:00
|
|
|
|
|
|
|
/// Was forced to add this by modview_frame.cpp
|
2017-03-23 00:59:25 +00:00
|
|
|
const FPILIST& GetList() const
|
|
|
|
{
|
|
|
|
return m_list;
|
|
|
|
}
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2020-12-11 01:38:55 +00:00
|
|
|
/**
|
|
|
|
* @return Clears the footprint info cache
|
|
|
|
*/
|
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
m_list.clear();
|
|
|
|
}
|
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
/**
|
2020-11-13 02:57:11 +00:00
|
|
|
* Get info for a footprint by id.
|
2018-07-29 00:11:39 +00:00
|
|
|
*/
|
2020-11-07 14:31:50 +00:00
|
|
|
FOOTPRINT_INFO* GetFootprintInfo( const wxString& aFootprintName );
|
2018-07-29 00:11:39 +00:00
|
|
|
|
|
|
|
/**
|
2020-11-13 02:57:11 +00:00
|
|
|
* Get info for a footprint by libNickname/footprintName
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
2020-11-07 14:31:50 +00:00
|
|
|
FOOTPRINT_INFO* GetFootprintInfo( const wxString& aLibNickname,
|
|
|
|
const wxString& aFootprintName );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
/**
|
2020-11-13 02:57:11 +00:00
|
|
|
* Get info for a footprint by index.
|
2020-12-19 16:00:52 +00:00
|
|
|
*
|
|
|
|
* @param aIdx index of the given item.
|
|
|
|
* @return the aIdx item in list.
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
2021-03-06 09:27:41 +00:00
|
|
|
FOOTPRINT_INFO& GetItem( unsigned aIdx ) const
|
2017-03-23 00:59:25 +00:00
|
|
|
{
|
|
|
|
return *m_list[aIdx];
|
|
|
|
}
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
unsigned GetErrorCount() const
|
|
|
|
{
|
|
|
|
return m_errors.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<IO_ERROR> PopError()
|
|
|
|
{
|
2017-03-24 14:09:08 +00:00
|
|
|
std::unique_ptr<IO_ERROR> error;
|
2013-12-09 18:09:58 +00:00
|
|
|
|
2017-03-24 14:09:08 +00:00
|
|
|
m_errors.pop( error );
|
|
|
|
return error;
|
2017-03-23 00:59:25 +00:00
|
|
|
}
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2013-10-13 21:33:58 +00:00
|
|
|
/**
|
2017-03-23 00:59:25 +00:00
|
|
|
* Read all the footprints provided by the combination of aTable and aNickname.
|
2013-12-09 18:09:58 +00:00
|
|
|
*
|
2013-10-13 21:33:58 +00:00
|
|
|
* @param aTable defines all the libraries.
|
2020-12-19 16:00:52 +00:00
|
|
|
* @param aNickname is the library to read from, or if NULL means read all footprints
|
|
|
|
* from all known libraries in aTable.
|
|
|
|
* @param aProgressReporter is an optional progress reporter. ReadFootprintFiles() will
|
|
|
|
* use 2 phases within the reporter.
|
|
|
|
* @return true if it ran to completion, else false if it aborted after some number of
|
|
|
|
* errors. If true, it does not mean there were no errors, check GetErrorCount()
|
|
|
|
* for that, should be zero to indicate success.
|
2013-10-13 21:33:58 +00:00
|
|
|
*/
|
2018-02-10 13:32:57 +00:00
|
|
|
virtual bool ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* aNickname = nullptr,
|
2018-04-16 22:18:02 +00:00
|
|
|
PROGRESS_REPORTER* aProgressReporter = nullptr ) = 0;
|
2013-12-09 18:09:58 +00:00
|
|
|
|
|
|
|
void DisplayErrors( wxTopLevelWindow* aCaller = NULL );
|
2013-12-12 16:01:03 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
FP_LIB_TABLE* GetTable() const
|
|
|
|
{
|
|
|
|
return m_lib_table;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-19 16:00:52 +00:00
|
|
|
* Factory function to return a #FOOTPRINT_LIST via Kiway.
|
|
|
|
*
|
|
|
|
* This is not guaranteed to succeed and will return null if the kiface is not available.
|
2017-03-23 00:59:25 +00:00
|
|
|
*
|
2020-12-19 16:00:52 +00:00
|
|
|
* @param aKiway active kiway instance.
|
2017-03-23 00:59:25 +00:00
|
|
|
*/
|
2018-03-25 12:48:13 +00:00
|
|
|
static FOOTPRINT_LIST* GetInstance( KIWAY& aKiway );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
2020-12-19 16:00:52 +00:00
|
|
|
* Launch worker threads to load footprints. Part of the #FOOTPRINT_ASYNC_LOADER
|
|
|
|
* implementation.
|
2017-03-23 00:59:25 +00:00
|
|
|
*/
|
2020-11-16 11:16:44 +00:00
|
|
|
virtual void startWorkers( FP_LIB_TABLE* aTable, wxString const* aNickname,
|
|
|
|
FOOTPRINT_ASYNC_LOADER* aLoader, unsigned aNThreads ) = 0;
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Join worker threads. Part of the FOOTPRINT_ASYNC_LOADER implementation.
|
|
|
|
*/
|
2020-11-16 11:16:44 +00:00
|
|
|
virtual bool joinWorkers() = 0;
|
2018-05-23 15:52:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop worker threads. Part of the FOOTPRINT_ASYNC_LOADER implementation.
|
|
|
|
*/
|
2020-11-16 11:16:44 +00:00
|
|
|
virtual void stopWorkers() = 0;
|
2020-12-19 16:00:52 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class FOOTPRINT_ASYNC_LOADER;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
FP_LIB_TABLE* m_lib_table; ///< no ownership
|
|
|
|
|
|
|
|
FPILIST m_list;
|
|
|
|
ERRLIST m_errors; ///< some can be PARSE_ERRORs also
|
2013-05-26 04:36:44 +00:00
|
|
|
};
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-19 16:00:52 +00:00
|
|
|
* Object used to populate a #FOOTPRINT_LIST asynchronously.
|
|
|
|
*
|
|
|
|
* Construct one, calling #Start(), and then waiting until it reports completion. This is
|
|
|
|
* equivalent to calling #FOOTPRINT_LIST::ReadFootprintFiles().
|
2017-03-23 00:59:25 +00:00
|
|
|
*/
|
|
|
|
class APIEXPORT FOOTPRINT_ASYNC_LOADER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Construct an asynchronous loader.
|
|
|
|
*/
|
|
|
|
FOOTPRINT_ASYNC_LOADER();
|
|
|
|
|
2018-06-04 20:44:43 +00:00
|
|
|
~FOOTPRINT_ASYNC_LOADER();
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
/**
|
|
|
|
* Assign a FOOTPRINT_LIST to the loader. This does not take ownership of
|
|
|
|
* the list.
|
|
|
|
*/
|
|
|
|
void SetList( FOOTPRINT_LIST* aList );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Launch the worker threads.
|
2020-12-19 16:00:52 +00:00
|
|
|
*
|
2017-03-23 00:59:25 +00:00
|
|
|
* @param aTable defines all the libraries.
|
2020-12-19 16:00:52 +00:00
|
|
|
* @param aNickname is the library to read from, or if NULL means read all footprints from
|
|
|
|
* all known libraries in \a aTable.
|
2017-03-23 00:59:25 +00:00
|
|
|
* @param aNThreads is the number of worker threads.
|
|
|
|
*/
|
|
|
|
void Start( FP_LIB_TABLE* aTable, wxString const* aNickname = nullptr,
|
2020-11-07 14:31:50 +00:00
|
|
|
unsigned aNThreads = DEFAULT_THREADS );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wait until the worker threads are finished, and then perform any required
|
|
|
|
* single-threaded finishing on the list. This must be called before using
|
|
|
|
* the list, even if the completion callback was used!
|
|
|
|
*
|
|
|
|
* It is safe to call this method from a thread, but it is not safe to use
|
|
|
|
* the list from ANY thread until it completes. It is recommended to call
|
|
|
|
* this from the main thread because of this.
|
|
|
|
*
|
|
|
|
* It is safe to call this multiple times, but after the first it will
|
|
|
|
* always return true.
|
|
|
|
*
|
|
|
|
* @return true if no errors occurred
|
|
|
|
*/
|
|
|
|
bool Join();
|
|
|
|
|
2018-05-23 15:52:48 +00:00
|
|
|
/**
|
|
|
|
* Safely stop the current process.
|
|
|
|
*/
|
|
|
|
void Abort();
|
|
|
|
|
2020-12-19 16:00:52 +00:00
|
|
|
private:
|
2017-03-23 00:59:25 +00:00
|
|
|
/**
|
|
|
|
* Default number of worker threads. Determined empirically (by dickelbeck):
|
|
|
|
* More than 6 is not significantly faster, less than 6 is likely slower.
|
|
|
|
*/
|
|
|
|
static constexpr unsigned DEFAULT_THREADS = 6;
|
2020-12-19 16:00:52 +00:00
|
|
|
|
|
|
|
friend class FOOTPRINT_LIST;
|
|
|
|
friend class FOOTPRINT_LIST_IMPL;
|
|
|
|
|
|
|
|
FOOTPRINT_LIST* m_list;
|
|
|
|
std::string m_last_table;
|
|
|
|
|
|
|
|
int m_total_libs;
|
2017-03-23 00:59:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // FOOTPRINT_INFO_H_
|