KiCad PCB EDA Suite
FOOTPRINT_LIST Class Referenceabstract

Holds a list of FOOTPRINT_INFO objects, along with a list of IO_ERRORs or PARSE_ERRORs that were thrown acquiring the FOOTPRINT_INFOs. More...

#include <footprint_info.h>

Inheritance diagram for FOOTPRINT_LIST:
FOOTPRINT_LIST_IMPL

Public Member Functions

 FOOTPRINT_LIST ()
 
virtual ~FOOTPRINT_LIST ()
 
virtual void WriteCacheToFile (wxTextFile *aFile)
 
virtual void ReadCacheFromFile (wxTextFile *aFile)
 
unsigned GetCount () const
 
const FPILISTGetList () const
 Was forced to add this by modview_frame.cpp. More...
 
FOOTPRINT_INFOGetModuleInfo (const wxString &aFootprintId)
 Get info for a module by id. More...
 
FOOTPRINT_INFOGetModuleInfo (const wxString &aLibNickname, const wxString &aFootprintName)
 Get info for a module by libNickname/footprintName. More...
 
FOOTPRINT_INFOGetItem (unsigned aIdx)
 Get info for a module by index. More...
 
unsigned GetErrorCount () const
 
std::unique_ptr< IO_ERRORPopError ()
 
virtual bool ReadFootprintFiles (FP_LIB_TABLE *aTable, const wxString *aNickname=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)=0
 Read all the footprints provided by the combination of aTable and aNickname. More...
 
void DisplayErrors (wxTopLevelWindow *aCaller=NULL)
 
FP_LIB_TABLEGetTable () const
 

Static Public Member Functions

static FOOTPRINT_LISTGetInstance (KIWAY &aKiway)
 Factory function to return a FOOTPRINT_LIST via Kiway. More...
 

Protected Types

typedef std::vector< std::unique_ptr< FOOTPRINT_INFO > > FPILIST
 
typedef SYNC_QUEUE< std::unique_ptr< IO_ERROR > > ERRLIST
 

Protected Member Functions

virtual void StartWorkers (FP_LIB_TABLE *aTable, wxString const *aNickname, FOOTPRINT_ASYNC_LOADER *aLoader, unsigned aNThreads)=0
 Launch worker threads to load footprints. More...
 
virtual bool JoinWorkers ()=0
 Join worker threads. More...
 
virtual void StopWorkers ()=0
 Stop worker threads. More...
 

Protected Attributes

FP_LIB_TABLEm_lib_table
 no ownership More...
 
FPILIST m_list
 
ERRLIST m_errors
 some can be PARSE_ERRORs also More...
 

Friends

class FOOTPRINT_ASYNC_LOADER
 

Detailed Description

Holds a list of FOOTPRINT_INFO objects, along with a list of IO_ERRORs or PARSE_ERRORs that were thrown acquiring the FOOTPRINT_INFOs.

This is a virtual class; its implementation lives in pcbnew/footprint_info_impl.cpp. To get instances of these classes, see FOOTPRINT_LIST::GetInstance().

Definition at line 187 of file footprint_info.h.

Member Typedef Documentation

typedef SYNC_QUEUE<std::unique_ptr<IO_ERROR> > FOOTPRINT_LIST::ERRLIST
protected

Definition at line 195 of file footprint_info.h.

typedef std::vector<std::unique_ptr<FOOTPRINT_INFO> > FOOTPRINT_LIST::FPILIST
protected

Definition at line 194 of file footprint_info.h.

Constructor & Destructor Documentation

FOOTPRINT_LIST::FOOTPRINT_LIST ( )
inline

Definition at line 201 of file footprint_info.h.

201  : m_lib_table( 0 )
202  {
203  }
FP_LIB_TABLE * m_lib_table
no ownership
virtual FOOTPRINT_LIST::~FOOTPRINT_LIST ( )
inlinevirtual

Definition at line 205 of file footprint_info.h.

206  {
207  }

Member Function Documentation

void FOOTPRINT_LIST::DisplayErrors ( wxTopLevelWindow *  aCaller = NULL)

Definition at line 84 of file footprint_info.cpp.

References HTML_MESSAGE_BOX::AddHTML_Text(), HTML_MESSAGE_BOX::MessageSet(), and PopError().

Referenced by FOOTPRINT_EDIT_FRAME::initLibraryTree(), CVPCB_MAINFRAME::LoadFootprintFiles(), and PCB_BASE_FRAME::SelectFootprintFromLibTree().

85 {
86  // @todo: go to a more HTML !<table>! ? centric output, possibly with
87  // recommendations for remedy of errors. Add numeric error codes
88  // to PARSE_ERROR, and switch on them for remedies, etc. Full
89  // access is provided to everything in every exception!
90 
91  HTML_MESSAGE_BOX dlg( aWindow, _( "Load Error" ) );
92 
93  dlg.MessageSet( _( "Errors were encountered loading footprints:" ) );
94 
95  wxString msg;
96 
97  while( auto error = PopError() )
98  {
99  wxString tmp = error->Problem();
100 
101  // Preserve new lines in error messages so queued errors don't run together.
102  tmp.Replace( "\n", "<BR>" );
103  msg += wxT( "<p>" ) + tmp + wxT( "</p>" );
104  }
105 
106  dlg.AddHTML_Text( msg );
107 
108  dlg.ShowModal();
109 }
Class HTML_MESSAGE_BOX.
std::unique_ptr< IO_ERROR > PopError()
unsigned FOOTPRINT_LIST::GetCount ( ) const
inline
Returns
the number of items stored in list

Definition at line 215 of file footprint_info.h.

Referenced by FOOTPRINT_FILTER::ITERATOR::dereference(), FOOTPRINT_FILTER::end(), GetInstance(), FOOTPRINT_FILTER::ITERATOR::increment(), and PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME().

216  {
217  return m_list.size();
218  }
unsigned FOOTPRINT_LIST::GetErrorCount ( ) const
inline

Definition at line 246 of file footprint_info.h.

References SYNC_QUEUE< T >::size().

Referenced by FOOTPRINT_EDIT_FRAME::initLibraryTree(), CVPCB_MAINFRAME::LoadFootprintFiles(), and PCB_BASE_FRAME::SelectFootprintFromLibTree().

247  {
248  return m_errors.size();
249  }
size_t size() const
Return the size of the queue.
Definition: sync_queue.h:94
ERRLIST m_errors
some can be PARSE_ERRORs also
FOOTPRINT_LIST * FOOTPRINT_LIST::GetInstance ( KIWAY aKiway)
static

Factory function to return a FOOTPRINT_LIST via Kiway.

NOT guaranteed to succeed; will return null if the kiface is not available.

Parameters
aKiway- active kiway instance

Definition at line 137 of file footprint_info.cpp.

References get_instance_from_id(), GetCount(), PROJECT::GetProjectPath(), KIFACE_FOOTPRINT_LIST, KIWAY::Prj(), and ReadCacheFromFile().

Referenced by DIALOG_CHOOSE_COMPONENT::ConstructRightPanel(), CVPCB_MAINFRAME::CVPCB_MAINFRAME(), FOOTPRINT_SELECT_WIDGET::Load(), and FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList().

138 {
139  FOOTPRINT_LIST* footprintInfo = get_instance_from_id( aKiway, KIFACE_FOOTPRINT_LIST );
140 
141  if( ! footprintInfo )
142  return nullptr;
143 
144  if( !footprintInfo->GetCount() )
145  {
146  wxTextFile footprintInfoCache( aKiway.Prj().GetProjectPath() + "fp-info-cache" );
147  footprintInfo->ReadCacheFromFile( &footprintInfoCache );
148  }
149 
150  return footprintInfo;
151 }
static FOOTPRINT_LIST * get_instance_from_id(KIWAY &aKiway, int aId)
virtual void ReadCacheFromFile(wxTextFile *aFile)
unsigned GetCount() const
VTBL_ENTRY PROJECT & Prj() const
Function Prj returns the PROJECT associated with this KIWAY.
Definition: kiway.cpp:142
Holds a list of FOOTPRINT_INFO objects, along with a list of IO_ERRORs or PARSE_ERRORs that were thro...
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:102
Return a pointer to the global instance of FOOTPRINT_LIST from pcbnew.
Definition: kiface_ids.h:39
FOOTPRINT_INFO& FOOTPRINT_LIST::GetItem ( unsigned  aIdx)
inline

Get info for a module by index.

Parameters
aIdx= index of the given item
Returns
the aIdx item in list

Definition at line 241 of file footprint_info.h.

Referenced by FOOTPRINT_FILTER::ITERATOR::dereference().

242  {
243  return *m_list[aIdx];
244  }
const FPILIST& FOOTPRINT_LIST::GetList ( ) const
inline

Was forced to add this by modview_frame.cpp.

Definition at line 221 of file footprint_info.h.

References FOOTPRINT_ASYNC_LOADER::m_list.

Referenced by FP_TREE_MODEL_ADAPTER::getFootprints().

222  {
223  return m_list;
224  }
FOOTPRINT_INFO * FOOTPRINT_LIST::GetModuleInfo ( const wxString &  aFootprintId)

Get info for a module by id.

Definition at line 64 of file footprint_info.cpp.

References Format(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), LIB_ID::ID_PCB, and LIB_ID::Parse().

Referenced by CVPCB_MAINFRAME::AutomaticFootprintMatching(), CVPCB_MAINFRAME::DisplayStatus(), DISPLAY_FOOTPRINTS_FRAME::InitDisplay(), and PCB_BASE_FRAME::SelectFootprintFromLibTree().

65 {
66  if( aFootprintName.IsEmpty() )
67  return NULL;
68 
69  LIB_ID fpid;
70 
71  wxCHECK_MSG( fpid.Parse( aFootprintName, LIB_ID::ID_PCB ) < 0, NULL,
72  wxString::Format( wxT( "\"%s\" is not a valid LIB_ID." ), aFootprintName ) );
73 
74  return GetModuleInfo( fpid.GetLibNickname(), fpid.GetLibItemName() );
75 }
FOOTPRINT_INFO * GetModuleInfo(const wxString &aFootprintId)
Get info for a module by id.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
int Parse(const UTF8 &aId, LIB_ID_TYPE aType, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
FOOTPRINT_INFO * FOOTPRINT_LIST::GetModuleInfo ( const wxString &  aLibNickname,
const wxString &  aFootprintName 
)

Get info for a module by libNickname/footprintName.

Definition at line 48 of file footprint_info.cpp.

References m_list.

50 {
51  if( aFootprintName.IsEmpty() )
52  return NULL;
53 
54  for( auto& fp : m_list )
55  {
56  if( aLibNickname == fp->GetLibNickname() && aFootprintName == fp->GetFootprintName() )
57  return &*fp;
58  }
59 
60  return NULL;
61 }
FP_LIB_TABLE* FOOTPRINT_LIST::GetTable ( ) const
inline

Definition at line 276 of file footprint_info.h.

Referenced by FOOTPRINT_INFO_IMPL::load().

277  {
278  return m_lib_table;
279  }
FP_LIB_TABLE * m_lib_table
no ownership
virtual bool FOOTPRINT_LIST::JoinWorkers ( )
protectedpure virtual

Join worker threads.

Part of the FOOTPRINT_ASYNC_LOADER implementation.

Implemented in FOOTPRINT_LIST_IMPL.

Referenced by FOOTPRINT_ASYNC_LOADER::Join().

std::unique_ptr<IO_ERROR> FOOTPRINT_LIST::PopError ( )
inline

Definition at line 251 of file footprint_info.h.

References SYNC_QUEUE< T >::pop().

Referenced by DisplayErrors().

252  {
253  std::unique_ptr<IO_ERROR> error;
254 
255  m_errors.pop( error );
256  return error;
257  }
bool pop(T &aReceiver)
Pop a value off the queue into the provided variable.
Definition: sync_queue.h:66
ERRLIST m_errors
some can be PARSE_ERRORs also
virtual void FOOTPRINT_LIST::ReadCacheFromFile ( wxTextFile *  aFile)
inlinevirtual

Reimplemented in FOOTPRINT_LIST_IMPL.

Definition at line 210 of file footprint_info.h.

Referenced by GetInstance().

210 { };
virtual bool FOOTPRINT_LIST::ReadFootprintFiles ( FP_LIB_TABLE aTable,
const wxString *  aNickname = nullptr,
PROGRESS_REPORTER aProgressReporter = nullptr 
)
pure virtual

Read all the footprints provided by the combination of aTable and aNickname.

Parameters
aTabledefines all the libraries.
aNicknameis the library to read from, or if NULL means read all footprints from all known libraries in aTable.
aProgressReporteris an optional progress reporter. ReadFootprintFiles() will use 2 phases within the reporter.
Returns
bool - 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.

Implemented in FOOTPRINT_LIST_IMPL.

Referenced by FOOTPRINT_SELECT_WIDGET::Load(), CVPCB_MAINFRAME::LoadFootprintFiles(), and CVPCB_MAINFRAME::OnEditFootprintLibraryTable().

virtual void FOOTPRINT_LIST::StartWorkers ( FP_LIB_TABLE aTable,
wxString const *  aNickname,
FOOTPRINT_ASYNC_LOADER aLoader,
unsigned  aNThreads 
)
protectedpure virtual

Launch worker threads to load footprints.

Part of the FOOTPRINT_ASYNC_LOADER implementation.

Implemented in FOOTPRINT_LIST_IMPL.

Referenced by FOOTPRINT_ASYNC_LOADER::Start().

virtual void FOOTPRINT_LIST::StopWorkers ( )
protectedpure virtual

Stop worker threads.

Part of the FOOTPRINT_ASYNC_LOADER implementation.

Implemented in FOOTPRINT_LIST_IMPL.

Referenced by FOOTPRINT_ASYNC_LOADER::Abort().

virtual void FOOTPRINT_LIST::WriteCacheToFile ( wxTextFile *  aFile)
inlinevirtual

Reimplemented in FOOTPRINT_LIST_IMPL.

Definition at line 209 of file footprint_info.h.

209 { };

Friends And Related Function Documentation

friend class FOOTPRINT_ASYNC_LOADER
friend

Definition at line 189 of file footprint_info.h.

Member Data Documentation

ERRLIST FOOTPRINT_LIST::m_errors
protected
FP_LIB_TABLE* FOOTPRINT_LIST::m_lib_table
protected

The documentation for this class was generated from the following files: