KiCad PCB EDA Suite
WIZARD_FPLIB_TABLE Class Reference

#include <wizard_add_fplib.h>

Inheritance diagram for WIZARD_FPLIB_TABLE:
WIZARD_FPLIB_TABLE_BASE

Classes

class  LIBRARY
 

Public Types

enum  LIB_SOURCE { LOCAL, GITHUB }
 

Source of the libraries (local files or Github)

More...
 
enum  LIB_SCOPE { GLOBAL = 1, PROJECT = 2 }
 

Scope (global/project)

More...
 

Public Member Functions

 WIZARD_FPLIB_TABLE (wxWindow *aParent)
 
 ~WIZARD_FPLIB_TABLE ()
 
wxWizardPage * GetFirstPage () const
 Function GetFirstPage Returns the welcoming page for the wizard. More...
 
wxString GetGithubURL () const
 Function GetGithubURL Returns the current Github repository URL set in the wizard. More...
 
void SetGithubURL (const wxString &aUrl)
 Function SetGithubURL Sets the current Github repository URL used by the wizard. More...
 
LIB_SOURCE GetLibSource () const
 Function GetLibSource Returns the source of libraries (local / Github). More...
 
LIB_SCOPE GetLibScope () const
 Function GetLibScope Returns the scope for the added libraries (global / project specific). More...
 
void OnSourceCheck (wxCommandEvent &aEvent)
 
void OnSelectFiles (wxCommandEvent &aEvent)
 
void OnCheckGithubList (wxCommandEvent &aEvent)
 
void OnPageChanged (wxWizardEvent &aEvent) override
 
void OnSelectAllGH (wxCommandEvent &aEvent) override
 
void OnUnselectAllGH (wxCommandEvent &aEvent) override
 
void OnChangeSearch (wxCommandEvent &aEvent) override
 
void OnWizardFinished (wxWizardEvent &aEvent) override
 
void OnBrowseButtonClick (wxCommandEvent &aEvent) override
 
void OnCheckSaveCopy (wxCommandEvent &aEvent) override
 
const std::vector< LIBRARY > & GetLibraries () const
 Function GetLibraries Returns libraries selected by the user. More...
 

Public Attributes

WizardPages m_pages
 

Protected Member Functions

void setupDialogOrder ()
 
void setupGithubList ()
 
void setupFileSelect ()
 
void setupReview ()
 
bool checkFiles () const
 

Checks the selection in file picker

More...
 
void setDownloadDir (const wxString &aDir)
 

Sets the target directory for libraries downloaded from Github

More...
 
wxString getDownloadDir ()
 

Gets the current target for downloaded libraries

More...
 
void getLibsListGithub (wxArrayString &aList)
 

Downloads the list of Github libraries

More...
 
bool downloadGithubLibsFromList (wxArrayString &aUrlList, wxString *aErrorMessage)
 

Saves a list of Github libraries locally.

More...
 
bool wantLocalCopy () const
 

Does the user want a local copy of Github libraries?

More...
 
void updateGithubControls ()
 

Enables Github widgets depending on the selected options.

More...
 
void updateLibraries ()
 

Updates m_libraries basing on dialogs contents

More...
 
void enableNext (bool aEnable)
 

Enables/disable 'Next' button

More...
 
virtual void OnPageChanging (wxWizardEvent &event)
 

Protected Attributes

wxArrayString m_githubLibs
 

Cache for the downloaded Github library list

More...
 
std::vector< LIBRARYm_libraries
 

Libraries selected in the wizard

More...
 
wxWizardPageSimple *const m_welcomeDlg
 
wxWizardPageSimple *const m_fileSelectDlg
 
wxWizardPageSimple *const m_githubListDlg
 
wxWizardPageSimple *const m_reviewDlg
 
wxWizardPageSimple *const m_targetDlg
 
int m_selectedFilter
 
wxString m_lastGithubDownloadDirectory
 
wxStaticText * m_staticText1
 
wxRadioButton * m_radioAddLocal
 
wxRadioButton * m_radioAddGithub
 
wxTextCtrl * m_textCtrlGithubURL
 
wxCheckBox * m_downloadGithub
 
wxStaticText * m_downloadDir
 
wxButton * m_btnBrowse
 
wxStaticText * m_invalidDir
 
wxStaticBitmap * m_bitmapRepo
 
wxHyperlinkCtrl * m_hyperlinkGithubKicad
 
wxStaticText * m_staticText7
 
wxGenericDirCtrl * m_filePicker
 
wxStaticText * m_staticText112
 
wxCheckListBox * m_checkListGH
 
wxButton * m_btnSelectAllGH
 
wxButton * m_btnUnselectAllGH
 
wxSearchCtrl * m_searchCtrlGH
 
wxStaticText * m_staticText1121
 
wxDataViewListCtrl * m_listCtrlReview
 
wxDataViewColumn * m_dvLibName
 
wxDataViewColumn * m_dvLibStatus
 
wxDataViewColumn * m_dvLibFormat
 
wxStaticText * m_staticText12
 
wxRadioButton * m_radioGlobal
 
wxRadioButton * m_radioProject
 

Detailed Description

Definition at line 33 of file wizard_add_fplib.h.

Member Enumeration Documentation

Scope (global/project)

Enumerator
GLOBAL 
PROJECT 

Definition at line 43 of file wizard_add_fplib.h.

43 { GLOBAL = 1, PROJECT = 2 };
Class PROJECT holds project specific data.
Definition: project.h:56

Source of the libraries (local files or Github)

Enumerator
LOCAL 
GITHUB 

Definition at line 40 of file wizard_add_fplib.h.

Constructor & Destructor Documentation

WIZARD_FPLIB_TABLE::WIZARD_FPLIB_TABLE ( wxWindow *  aParent)

Definition at line 288 of file wizard_add_fplib.cpp.

References PCAD2KICAD::Center, PGM_BASE::CommonSettings(), getFilterString(), FP_LIB_TABLE::GlobalPathEnvVariableName(), KICAD_FPLIBS_LAST_DOWNLOAD_DIR, KICAD_FPLIBS_URL_KEY, WIZARD_FPLIB_TABLE_BASE::m_filePicker, m_lastGithubDownloadDirectory, WIZARD_FPLIB_TABLE_BASE::m_pages, WIZARD_FPLIB_TABLE_BASE::m_radioAddGithub, WIZARD_FPLIB_TABLE_BASE::m_radioAddLocal, max, OnCheckGithubList(), OnSelectFiles(), OnSourceCheck(), Pgm(), setDownloadDir(), SetGithubURL(), setupDialogOrder(), and updateGithubControls().

288  :
289  WIZARD_FPLIB_TABLE_BASE( aParent ), m_welcomeDlg( m_pages[0] ),
292 {
293  m_filePicker->SetFilter( getFilterString() );
294 
295  // Initialize default download dir
296  wxString default_path;
297  wxGetEnv( FP_LIB_TABLE::GlobalPathEnvVariableName(), &default_path );
298  setDownloadDir( default_path );
299  m_filePicker->SetPath( default_path );
300 
301  // Restore the Github url
302  wxString githubUrl;
303 
304  wxConfigBase* cfg = Pgm().CommonSettings();
305  cfg->Read( KICAD_FPLIBS_URL_KEY, &githubUrl );
307 
308 
309  if( !m_lastGithubDownloadDirectory.IsEmpty() )
310  {
313  } else {
314  m_lastGithubDownloadDirectory = default_path;
315  }
316 
317  if( githubUrl.IsEmpty() )
318  githubUrl = wxT( "https://github.com/KiCad" );
319 
320  SetGithubURL( githubUrl );
321 
322  // Give the minimal size to the dialog, which allows displaying any page
323  wxSize minsize;
324 
325  for( unsigned ii = 0; ii < m_pages.size(); ii++ )
326  {
327  wxSize size = m_pages[ii]->GetSizer()->CalcMin();
328  minsize.x = std::max( minsize.x, size.x );
329  minsize.y = std::max( minsize.y, size.y );
330  }
331 
332  SetMinSize( minsize );
333  SetPageSize( minsize );
334  GetSizer()->SetSizeHints( this );
335  Center();
336 
337  if( !m_radioAddGithub->GetValue() && !m_radioAddLocal->GetValue() )
338  m_radioAddLocal->SetValue( true );
339 
342 
343  Connect( wxEVT_RADIOBUTTON, wxCommandEventHandler( WIZARD_FPLIB_TABLE::OnSourceCheck ), NULL, this );
344  Connect( wxEVT_DIRCTRL_SELECTIONCHANGED, wxCommandEventHandler( WIZARD_FPLIB_TABLE::OnSelectFiles ), NULL, this );
345  Connect( wxEVT_CHECKLISTBOX, wxCommandEventHandler( WIZARD_FPLIB_TABLE::OnCheckGithubList ), NULL, this );
346 }
wxWizardPageSimple *const m_fileSelectDlg
wxWizardPageSimple *const m_reviewDlg
void OnCheckGithubList(wxCommandEvent &aEvent)
static wxString getFilterString()
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
wxWizardPageSimple *const m_githubListDlg
wxWizardPageSimple *const m_targetDlg
wxGenericDirCtrl * m_filePicker
static const wxString GlobalPathEnvVariableName()
Function GlobalPathEnvVarVariableName.
void setDownloadDir(const wxString &aDir)
Sets the target directory for libraries downloaded from Github
void SetGithubURL(const wxString &aUrl)
Function SetGithubURL Sets the current Github repository URL used by the wizard.
WIZARD_FPLIB_TABLE_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Add Footprint Libraries Wizard"), const wxBitmap &bitmap=wxArtProvider::GetBitmap(wxART_HELP_BOOK, wxART_FRAME_ICON), const wxPoint &pos=wxDefaultPosition, long style=wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxRESIZE_BORDER)
#define max(a, b)
Definition: auxiliary.h:86
wxWizardPageSimple *const m_welcomeDlg
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:145
void OnSelectFiles(wxCommandEvent &aEvent)
wxString m_lastGithubDownloadDirectory
void OnSourceCheck(wxCommandEvent &aEvent)
#define KICAD_FPLIBS_LAST_DOWNLOAD_DIR
#define KICAD_FPLIBS_URL_KEY
Wizard for selecting footprint libraries consisting of 4 steps:
void updateGithubControls()
Enables Github widgets depending on the selected options.
WIZARD_FPLIB_TABLE::~WIZARD_FPLIB_TABLE ( )

Definition at line 349 of file wizard_add_fplib.cpp.

References PGM_BASE::CommonSettings(), GetGithubURL(), KICAD_FPLIBS_URL_KEY, and Pgm().

350 {
351  // Use this if you want to store kicad lib URL in pcbnew/cvpcb section config:
352 // wxConfigBase* cfg = Kiface().KifaceSettings();
353 
354  // Use this if you want to store kicad lib URL in common section config:
355  wxConfigBase* cfg = Pgm().CommonSettings();
356  cfg->Write( KICAD_FPLIBS_URL_KEY, GetGithubURL() );
357 }
wxString GetGithubURL() const
Function GetGithubURL Returns the current Github repository URL set in the wizard.
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:145
#define KICAD_FPLIBS_URL_KEY
Wizard for selecting footprint libraries consisting of 4 steps:

Member Function Documentation

bool WIZARD_FPLIB_TABLE::checkFiles ( ) const
protected

Checks the selection in file picker

Definition at line 557 of file wizard_add_fplib.cpp.

References downloadGithubLibsFromList(), enableNext(), PLUGIN::FootprintEnumerate(), PLUGIN::FootprintLoad(), PLUGIN::FootprintSave(), GetChars(), getDownloadDir(), GITHUB_GETLIBLIST::GetFootprintLibraryList(), getLibsListGithub(), IO_MGR::GITHUB, i, IO_MGR::KICAD_SEXP, WIZARD_FPLIB_TABLE_BASE::m_checkListGH, WIZARD_FPLIB_TABLE_BASE::m_filePicker, m_githubLibs, m_libraries, WIZARD_FPLIB_TABLE_BASE::m_listCtrlReview, WIZARD_FPLIB_TABLE_BASE::m_searchCtrlGH, WIZARD_FPLIB_TABLE_BASE::m_textCtrlGithubURL, passesFilter(), IO_MGR::PluginFind(), setupGithubList(), and IO_ERROR::What().

Referenced by GetLibraries(), OnSelectFiles(), and setupFileSelect().

558 {
559  // Get current selection (files & directories)
560  wxArrayString candidates;
561  m_filePicker->GetPaths( candidates );
562 
563  // Workaround, when you change filters "/" is automatically selected
564  int slash_index = candidates.Index( "/", true, true );
565  if( slash_index != wxNOT_FOUND )
566  candidates.RemoveAt( slash_index, 1 );
567 
568  if( candidates.IsEmpty() )
569  return false;
570 
571  // Verify all the files/folders comply to the selected library type filter
572  for( unsigned int i = 0; i < candidates.GetCount(); ++i )
573  {
574  if( !passesFilter( candidates[i], m_filePicker->GetFilterIndex() ) )
575  return false;
576  }
577 
578  return true;
579 }
wxGenericDirCtrl * m_filePicker
static bool passesFilter(const wxString &aFileName, int aFilterIndex)
size_t i
Definition: json11.cpp:597
bool WIZARD_FPLIB_TABLE::downloadGithubLibsFromList ( wxArrayString &  aUrlList,
wxString *  aErrorMessage 
)
protected

Saves a list of Github libraries locally.

Referenced by checkFiles(), getDownloadDir(), and OnWizardFinished().

void WIZARD_FPLIB_TABLE::enableNext ( bool  aEnable)
inlineprotected

Enables/disable 'Next' button

Definition at line 251 of file wizard_add_fplib.h.

Referenced by checkFiles(), OnCheckGithubList(), OnPageChanged(), OnSelectAllGH(), OnSelectFiles(), OnUnselectAllGH(), setupFileSelect(), setupReview(), and updateGithubControls().

252  {
253  wxWindow* nextBtn = FindWindowById( wxID_FORWARD );
254 
255  if( nextBtn )
256  nextBtn->Enable( aEnable );
257  }
wxString WIZARD_FPLIB_TABLE::getDownloadDir ( )
inlineprotected

Gets the current target for downloaded libraries

Definition at line 230 of file wizard_add_fplib.h.

References downloadGithubLibsFromList(), getLibsListGithub(), and WIZARD_FPLIB_TABLE_BASE::m_downloadDir.

Referenced by checkFiles(), OnBrowseButtonClick(), OnWizardFinished(), and updateGithubControls().

231  {
232  return m_downloadDir->GetLabel();
233  }
wxWizardPage* WIZARD_FPLIB_TABLE::GetFirstPage ( ) const
inline

Function GetFirstPage Returns the welcoming page for the wizard.

Definition at line 49 of file wizard_add_fplib.h.

References m_welcomeDlg.

Referenced by InvokeFootprintWizard(), and DIALOG_FP_LIB_TABLE::OnClickLibraryWizard().

50  {
51  return m_welcomeDlg;
52  }
wxWizardPageSimple *const m_welcomeDlg
wxString WIZARD_FPLIB_TABLE::GetGithubURL ( ) const
inline

Function GetGithubURL Returns the current Github repository URL set in the wizard.

Definition at line 58 of file wizard_add_fplib.h.

References WIZARD_FPLIB_TABLE_BASE::m_textCtrlGithubURL.

Referenced by OnWizardFinished(), updateLibraries(), and ~WIZARD_FPLIB_TABLE().

59  {
60  return m_textCtrlGithubURL->GetValue();
61  }
const std::vector<LIBRARY>& WIZARD_FPLIB_TABLE::GetLibraries ( ) const
inline

Function GetLibraries Returns libraries selected by the user.

Definition at line 207 of file wizard_add_fplib.h.

References checkFiles(), m_libraries, setupDialogOrder(), setupFileSelect(), setupGithubList(), and setupReview().

Referenced by InvokeFootprintWizard(), and DIALOG_FP_LIB_TABLE::OnClickLibraryWizard().

208  {
209  return m_libraries;
210  }
std::vector< LIBRARY > m_libraries
Libraries selected in the wizard
WIZARD_FPLIB_TABLE::LIB_SCOPE WIZARD_FPLIB_TABLE::GetLibScope ( ) const

Function GetLibScope Returns the scope for the added libraries (global / project specific).

Definition at line 371 of file wizard_add_fplib.cpp.

References GLOBAL, WIZARD_FPLIB_TABLE_BASE::m_radioGlobal, WIZARD_FPLIB_TABLE_BASE::m_radioProject, and PROJECT.

Referenced by InvokeFootprintWizard(), DIALOG_FP_LIB_TABLE::OnClickLibraryWizard(), and SetGithubURL().

372 {
373  if( m_radioGlobal->GetValue() )
374  return GLOBAL;
375 
376  wxASSERT( m_radioProject->GetValue() );
377 
378  return PROJECT;
379 }
void WIZARD_FPLIB_TABLE::getLibsListGithub ( wxArrayString &  aList)
protected

Downloads the list of Github libraries

Referenced by checkFiles(), and getDownloadDir().

WIZARD_FPLIB_TABLE::LIB_SOURCE WIZARD_FPLIB_TABLE::GetLibSource ( ) const

Function GetLibSource Returns the source of libraries (local / Github).

Definition at line 360 of file wizard_add_fplib.cpp.

References GITHUB, LOCAL, WIZARD_FPLIB_TABLE_BASE::m_radioAddGithub, and WIZARD_FPLIB_TABLE_BASE::m_radioAddLocal.

Referenced by OnWizardFinished(), SetGithubURL(), setupDialogOrder(), updateGithubControls(), and updateLibraries().

361 {
362  if( m_radioAddGithub->GetValue() )
363  return GITHUB;
364 
365  wxASSERT( m_radioAddLocal->GetValue() );
366 
367  return LOCAL;
368 }
void WIZARD_FPLIB_TABLE::OnBrowseButtonClick ( wxCommandEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_FPLIB_TABLE_BASE.

Definition at line 532 of file wizard_add_fplib.cpp.

References PGM_BASE::CommonSettings(), getDownloadDir(), KICAD_FPLIBS_LAST_DOWNLOAD_DIR, Pgm(), setDownloadDir(), and updateGithubControls().

Referenced by SetGithubURL().

533 {
534  wxString path = getDownloadDir();
535 
536  path = wxDirSelector( _("Choose a folder to save the downloaded libraries" ),
537  path, 0, wxDefaultPosition, this );
538 
539  if( !path.IsEmpty() && wxDirExists( path ) )
540  {
541  setDownloadDir( path );
542 
543  wxConfigBase* cfg = Pgm().CommonSettings();
544  cfg->Write( KICAD_FPLIBS_LAST_DOWNLOAD_DIR, path );
545 
547  }
548 }
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
void setDownloadDir(const wxString &aDir)
Sets the target directory for libraries downloaded from Github
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:145
wxString getDownloadDir()
Gets the current target for downloaded libraries
#define KICAD_FPLIBS_LAST_DOWNLOAD_DIR
void updateGithubControls()
Enables Github widgets depending on the selected options.
void WIZARD_FPLIB_TABLE::OnChangeSearch ( wxCommandEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_FPLIB_TABLE_BASE.

Definition at line 452 of file wizard_add_fplib.cpp.

References i, WIZARD_FPLIB_TABLE_BASE::m_checkListGH, m_githubLibs, and WIZARD_FPLIB_TABLE_BASE::m_searchCtrlGH.

Referenced by SetGithubURL().

453 {
454  wxString searchPhrase = m_searchCtrlGH->GetValue().Lower();
455 
456  // Store the current selection
457  wxArrayInt checkedIndices;
458  m_checkListGH->GetCheckedItems( checkedIndices );
459  wxArrayString checkedStrings;
460 
461  for( unsigned int i = 0; i < checkedIndices.GetCount(); ++i )
462  checkedStrings.Add( m_checkListGH->GetString( checkedIndices[i] ).AfterLast( '/' ) );
463 
464  m_checkListGH->Clear();
465 
466  // Rebuild the list, putting the matching entries on the top
467  int matching = 0; // number of entries matching the search phrase
468  for( unsigned int i = 0; i < m_githubLibs.GetCount(); ++i )
469  {
470  const wxString& lib = m_githubLibs[i].AfterLast( '/' );
471  bool wasChecked = ( checkedStrings.Index( lib ) != wxNOT_FOUND );
472  int insertedIdx = -1;
473 
474  if( !searchPhrase.IsEmpty() && lib.Lower().Contains( searchPhrase ) )
475  {
476  insertedIdx = m_checkListGH->Insert( lib, matching++ );
477  m_checkListGH->SetSelection( insertedIdx );
478  }
479  else
480  insertedIdx = m_checkListGH->Append( lib );
481 
482  if( wasChecked )
483  m_checkListGH->Check( insertedIdx );
484  }
485 
486  if( !m_checkListGH->IsEmpty() )
487  m_checkListGH->EnsureVisible( 0 );
488 }
wxArrayString m_githubLibs
Cache for the downloaded Github library list
size_t i
Definition: json11.cpp:597
void WIZARD_FPLIB_TABLE::OnCheckGithubList ( wxCommandEvent &  aEvent)

Definition at line 417 of file wizard_add_fplib.cpp.

References dummy(), enableNext(), and WIZARD_FPLIB_TABLE_BASE::m_checkListGH.

Referenced by SetGithubURL(), and WIZARD_FPLIB_TABLE().

418 {
419  wxArrayInt dummy;
420 
421  enableNext( m_checkListGH->GetCheckedItems( dummy ) > 0 );
422 }
void enableNext(bool aEnable)
Enables/disable &#39;Next&#39; button
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
void WIZARD_FPLIB_TABLE::OnCheckSaveCopy ( wxCommandEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_FPLIB_TABLE_BASE.

Definition at line 551 of file wizard_add_fplib.cpp.

References updateGithubControls().

Referenced by SetGithubURL().

552 {
554 }
void updateGithubControls()
Enables Github widgets depending on the selected options.
void WIZARD_FPLIB_TABLE::OnPageChanged ( wxWizardEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_FPLIB_TABLE_BASE.

Definition at line 382 of file wizard_add_fplib.cpp.

References enableNext(), KiBitmap(), m_fileSelectDlg, m_githubListDlg, m_reviewDlg, setupFileSelect(), setupGithubList(), and setupReview().

Referenced by SetGithubURL().

383 {
384  SetBitmap( KiBitmap( wizard_add_fplib_icon_xpm ) );
385  enableNext( true );
386 
387 #ifdef BUILD_GITHUB_PLUGIN
388  if( GetCurrentPage() == m_githubListDlg )
389  setupGithubList();
390  else
391 #endif
392  if( GetCurrentPage() == m_fileSelectDlg )
393  setupFileSelect();
394  else if( GetCurrentPage() == m_reviewDlg )
395  setupReview();
396 }
wxWizardPageSimple *const m_fileSelectDlg
wxWizardPageSimple *const m_reviewDlg
void enableNext(bool aEnable)
Enables/disable &#39;Next&#39; button
wxWizardPageSimple *const m_githubListDlg
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
virtual void WIZARD_FPLIB_TABLE_BASE::OnPageChanging ( wxWizardEvent &  event)
inlineprotectedvirtualinherited
void WIZARD_FPLIB_TABLE::OnSelectAllGH ( wxCommandEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_FPLIB_TABLE_BASE.

Definition at line 432 of file wizard_add_fplib.cpp.

References dummy(), enableNext(), i, and WIZARD_FPLIB_TABLE_BASE::m_checkListGH.

Referenced by SetGithubURL().

433 {
434  for( unsigned int i = 0; i < m_checkListGH->GetCount(); ++i )
435  m_checkListGH->Check( i, true );
436 
437  // The list might be empty, e.g. in case of download error
438  wxArrayInt dummy;
439  enableNext( m_checkListGH->GetCheckedItems( dummy ) > 0 );
440 }
void enableNext(bool aEnable)
Enables/disable &#39;Next&#39; button
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
size_t i
Definition: json11.cpp:597
void WIZARD_FPLIB_TABLE::OnSelectFiles ( wxCommandEvent &  aEvent)

Definition at line 399 of file wizard_add_fplib.cpp.

References checkFiles(), enableNext(), WIZARD_FPLIB_TABLE_BASE::m_filePicker, and m_selectedFilter.

Referenced by SetGithubURL(), and WIZARD_FPLIB_TABLE().

400 {
401  int filterIdx = m_filePicker->GetFilterIndex();
402 
403  if( m_selectedFilter != filterIdx )
404  {
405  m_selectedFilter = filterIdx;
406 
407  // Process the event again, as in the first iteration we cannot get the list of selected items
408  wxCommandEvent ev( wxEVT_DIRCTRL_SELECTIONCHANGED );
409  AddPendingEvent( ev );
410  return;
411  }
412 
413  enableNext( checkFiles() );
414 }
void enableNext(bool aEnable)
Enables/disable &#39;Next&#39; button
wxGenericDirCtrl * m_filePicker
bool checkFiles() const
Checks the selection in file picker
void WIZARD_FPLIB_TABLE::OnSourceCheck ( wxCommandEvent &  aEvent)

Definition at line 425 of file wizard_add_fplib.cpp.

References setupDialogOrder(), and updateGithubControls().

Referenced by SetGithubURL(), and WIZARD_FPLIB_TABLE().

426 {
429 }
void updateGithubControls()
Enables Github widgets depending on the selected options.
void WIZARD_FPLIB_TABLE::OnUnselectAllGH ( wxCommandEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_FPLIB_TABLE_BASE.

Definition at line 443 of file wizard_add_fplib.cpp.

References enableNext(), i, and WIZARD_FPLIB_TABLE_BASE::m_checkListGH.

Referenced by SetGithubURL().

444 {
445  for( unsigned int i = 0; i < m_checkListGH->GetCount(); ++i )
446  m_checkListGH->Check( i, false );
447 
448  enableNext( false );
449 }
void enableNext(bool aEnable)
Enables/disable &#39;Next&#39; button
size_t i
Definition: json11.cpp:597
void WIZARD_FPLIB_TABLE::OnWizardFinished ( wxWizardEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_FPLIB_TABLE_BASE.

Definition at line 491 of file wizard_add_fplib.cpp.

References DisplayError(), downloadGithubLibsFromList(), getDownloadDir(), GetGithubURL(), GetLibSource(), GITHUB, IO_MGR::GITHUB, WIZARD_FPLIB_TABLE::LIBRARY::INVALID, IO_MGR::KICAD_SEXP, WIZARD_FPLIB_TABLE_BASE::m_downloadGithub, and m_libraries.

Referenced by SetGithubURL().

492 {
493 #ifdef BUILD_GITHUB_PLUGIN
494  // Shall we download a localy copy of the libraries
495  if( GetLibSource() == GITHUB && m_downloadGithub->GetValue() )
496  {
497  wxString error;
498  wxArrayString libs;
499 
500  // Prepare a list of libraries to download
501  for( std::vector<LIBRARY>::const_iterator it = m_libraries.begin();
502  it != m_libraries.end(); ++it )
503  {
504  wxASSERT( it->GetPluginType() == IO_MGR::GITHUB );
505 
506  if( it->GetStatus() != LIBRARY::INVALID )
507  libs.Add( it->GetAbsolutePath() );
508  }
509 
510  if( !downloadGithubLibsFromList( libs, &error ) )
511  {
512  DisplayError( this, error );
513  m_libraries.clear();
514  }
515  else
516  {
517  // Now libraries are stored locally, so update the paths to point to the download folder
518  for( std::vector<LIBRARY>::iterator it = m_libraries.begin();
519  it != m_libraries.end(); ++it )
520  {
521  wxString path = it->GetAbsolutePath();
522  path.Replace( GetGithubURL(), getDownloadDir() );
523  it->setPath( path );
524  it->setPluginType( IO_MGR::KICAD_SEXP );
525  }
526  }
527  }
528 #endif
529 }
wxString GetGithubURL() const
Function GetGithubURL Returns the current Github repository URL set in the wizard.
bool downloadGithubLibsFromList(wxArrayString &aUrlList, wxString *aErrorMessage)
Saves a list of Github libraries locally.
LIB_SOURCE GetLibSource() const
Function GetLibSource Returns the source of libraries (local / Github).
std::vector< LIBRARY > m_libraries
Libraries selected in the wizard
wxString getDownloadDir()
Gets the current target for downloaded libraries
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:185
Read only http://github.com repo holding pretty footprints.
Definition: io_mgr.h:59
S-expression Pcbnew file format.
Definition: io_mgr.h:55
void WIZARD_FPLIB_TABLE::setDownloadDir ( const wxString &  aDir)
inlineprotected

Sets the target directory for libraries downloaded from Github

Definition at line 224 of file wizard_add_fplib.h.

References WIZARD_FPLIB_TABLE_BASE::m_downloadDir.

Referenced by OnBrowseButtonClick(), and WIZARD_FPLIB_TABLE().

225  {
226  m_downloadDir->SetLabel( aDir );
227  }
void WIZARD_FPLIB_TABLE::SetGithubURL ( const wxString &  aUrl)
inline

Function SetGithubURL Sets the current Github repository URL used by the wizard.

Parameters
aUrlis the new URL to be applied.

Definition at line 68 of file wizard_add_fplib.h.

References GetLibScope(), GetLibSource(), WIZARD_FPLIB_TABLE_BASE::m_textCtrlGithubURL, OnBrowseButtonClick(), OnChangeSearch(), OnCheckGithubList(), OnCheckSaveCopy(), OnPageChanged(), OnSelectAllGH(), OnSelectFiles(), OnSourceCheck(), OnUnselectAllGH(), and OnWizardFinished().

Referenced by WIZARD_FPLIB_TABLE().

69  {
70  m_textCtrlGithubURL->SetValue( aUrl );
71  }
void WIZARD_FPLIB_TABLE::setupDialogOrder ( )
protected

Definition at line 751 of file wizard_add_fplib.cpp.

References GetLibSource(), GITHUB, LOCAL, m_fileSelectDlg, m_githubListDlg, m_reviewDlg, and m_welcomeDlg.

Referenced by GetLibraries(), OnSourceCheck(), and WIZARD_FPLIB_TABLE().

752 {
753  // Alternate the wizard pages flow depending on the selected option
754  switch( GetLibSource() )
755  {
756  case LOCAL:
757  m_welcomeDlg->SetNext( m_fileSelectDlg );
758  m_fileSelectDlg->SetPrev( m_welcomeDlg );
759 
760  m_fileSelectDlg->SetNext( m_reviewDlg );
761  m_reviewDlg->SetPrev( m_fileSelectDlg );
762  break;
763 
764  case GITHUB:
765  m_welcomeDlg->SetNext( m_githubListDlg );
766  m_githubListDlg->SetPrev( m_welcomeDlg );
767 
768  m_githubListDlg->SetNext( m_reviewDlg );
769  m_reviewDlg->SetPrev( m_githubListDlg );
770  break;
771 
772  default:
773  wxASSERT( false );
774  break;
775  }
776 }
wxWizardPageSimple *const m_fileSelectDlg
wxWizardPageSimple *const m_reviewDlg
wxWizardPageSimple *const m_githubListDlg
LIB_SOURCE GetLibSource() const
Function GetLibSource Returns the source of libraries (local / Github).
wxWizardPageSimple *const m_welcomeDlg
void WIZARD_FPLIB_TABLE::setupFileSelect ( )
protected

Definition at line 779 of file wizard_add_fplib.cpp.

References checkFiles(), enableNext(), m_libraries, and WIZARD_FPLIB_TABLE_BASE::m_listCtrlReview.

Referenced by GetLibraries(), and OnPageChanged().

780 {
781  // Disable the button until something is selected
782  enableNext( checkFiles() );
783 
784  // Clear the review list so it will be reloaded
785  m_libraries.clear();
786  m_listCtrlReview->DeleteAllItems();
787 }
void enableNext(bool aEnable)
Enables/disable &#39;Next&#39; button
bool checkFiles() const
Checks the selection in file picker
std::vector< LIBRARY > m_libraries
Libraries selected in the wizard
wxDataViewListCtrl * m_listCtrlReview
void WIZARD_FPLIB_TABLE::setupGithubList ( )
protected
void WIZARD_FPLIB_TABLE::setupReview ( )
protected

Definition at line 790 of file wizard_add_fplib.cpp.

References enableNext(), Format(), WIZARD_FPLIB_TABLE::LIBRARY::INVALID, WIZARD_FPLIB_TABLE_BASE::m_dvLibName, m_libraries, WIZARD_FPLIB_TABLE_BASE::m_listCtrlReview, WIZARD_FPLIB_TABLE::LIBRARY::NOT_CHECKED, WIZARD_FPLIB_TABLE::LIBRARY::OK, and updateLibraries().

Referenced by GetLibraries(), and OnPageChanged().

791 {
792  wxBeginBusyCursor();
793  updateLibraries();
794 
795  int libTotalCount = m_libraries.size();
796  int libCount = 0;
797  bool validate = true;
798  // for OSX do not enable wPD_APP_MODAL, keep wxPD_AUTO_HIDE
799  wxProgressDialog progressDlg( _( "Please wait..." ), _( "Validating libraries" ),
800  libTotalCount, this,
801 #ifndef __WXMAC__
802  wxPD_APP_MODAL |
803 #endif
804  wxPD_CAN_ABORT | wxPD_AUTO_HIDE );
805 
806  m_dvLibName->SetWidth( 280 );
807 
808  // Prepare the review list
809  m_listCtrlReview->DeleteAllItems();
810 
811  for( std::vector<LIBRARY>::iterator it = m_libraries.begin(); it != m_libraries.end(); ++it )
812  {
813  wxVector<wxVariant> row;
814  LIBRARY::STATUS status = it->GetStatus();
815 
816  // Check if the library contents is valid
817  if( status == LIBRARY::NOT_CHECKED && validate )
818  {
819  it->Test();
820  status = it->GetStatus();
821  }
822 
823  row.push_back( wxVariant( it->GetDescription() ) );
824 
825  switch( it->GetStatus() )
826  {
828  row.push_back( wxVariant( _( "NOT CHECKED" ) ) );
829  break;
830 
831  case LIBRARY::OK:
832  row.push_back( wxVariant( _( "OK" ) ) );
833  break;
834 
835  case LIBRARY::INVALID:
836  row.push_back( wxVariant( _( "INVALID" ) ) );
837  break;
838  }
839 
840  row.push_back( wxVariant( it->GetPluginName() ) );
841 
842  m_listCtrlReview->AppendItem( row );
843 
844  ++libCount;
845  if( !progressDlg.Update( libCount, wxString::Format( _( "Validating libraries %d/%d" ),
846  libCount, libTotalCount ) ) )
847  validate = false;
848  }
849 
850  // The list should never be empty, but who knows?
851  enableNext( m_listCtrlReview->GetItemCount() > 0 );
852 
853  wxEndBusyCursor();
854 }
void enableNext(bool aEnable)
Enables/disable &#39;Next&#39; button
void updateLibraries()
Updates m_libraries basing on dialogs contents
std::vector< LIBRARY > m_libraries
Libraries selected in the wizard
STATUS
Possible states of validation.
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
wxDataViewColumn * m_dvLibName
wxDataViewListCtrl * m_listCtrlReview
void WIZARD_FPLIB_TABLE::updateGithubControls ( )
protected

Enables Github widgets depending on the selected options.

Definition at line 686 of file wizard_add_fplib.cpp.

References enableNext(), getDownloadDir(), GetLibSource(), GITHUB, WIZARD_FPLIB_TABLE_BASE::m_btnBrowse, WIZARD_FPLIB_TABLE_BASE::m_downloadDir, WIZARD_FPLIB_TABLE_BASE::m_downloadGithub, WIZARD_FPLIB_TABLE_BASE::m_invalidDir, WIZARD_FPLIB_TABLE_BASE::m_radioAddGithub, WIZARD_FPLIB_TABLE_BASE::m_textCtrlGithubURL, and wantLocalCopy().

Referenced by OnBrowseButtonClick(), OnCheckSaveCopy(), OnSourceCheck(), wantLocalCopy(), and WIZARD_FPLIB_TABLE().

687 {
688 #ifndef BUILD_GITHUB_PLUGIN
689  m_radioAddGithub->Enable( false );
690 #endif
691 
692  // Disable inputs that have no meaning for the selected source
693  bool githubEnabled = ( GetLibSource() == GITHUB );
694  m_textCtrlGithubURL->Enable( githubEnabled );
695  m_downloadGithub->Enable( githubEnabled );
696  m_downloadDir->Enable( githubEnabled && wantLocalCopy() );
697  m_btnBrowse->Enable( githubEnabled && wantLocalCopy() );
698 
699  bool valid = !( githubEnabled && wantLocalCopy() ) || wxFileName::IsDirWritable( getDownloadDir() );
700 
701  // Do not allow to go further unless there is a valid directory selected
702  m_invalidDir->Show( !valid );
703  enableNext( valid );
704 }
void enableNext(bool aEnable)
Enables/disable &#39;Next&#39; button
LIB_SOURCE GetLibSource() const
Function GetLibSource Returns the source of libraries (local / Github).
bool wantLocalCopy() const
Does the user want a local copy of Github libraries?
wxString getDownloadDir()
Gets the current target for downloaded libraries
void WIZARD_FPLIB_TABLE::updateLibraries ( )
protected

Updates m_libraries basing on dialogs contents

Definition at line 707 of file wizard_add_fplib.cpp.

References GetGithubURL(), GetLibSource(), GITHUB, i, LOCAL, WIZARD_FPLIB_TABLE_BASE::m_checkListGH, WIZARD_FPLIB_TABLE_BASE::m_filePicker, m_libraries, and WIZARD_FPLIB_TABLE_BASE::m_listCtrlReview.

Referenced by setupReview(), and wantLocalCopy().

708 {
709  // No need to update, the review list is ready
710  if( m_listCtrlReview->GetItemCount() != 0 )
711  return;
712 
713  switch( GetLibSource() )
714  {
715  case LOCAL:
716  {
717  wxArrayString libs;
718  m_filePicker->GetPaths( libs );
719 
720  // Workaround, when you change filters "/" is automatically selected
721  int slash_index = libs.Index( "/", true, true );
722  if( slash_index != wxNOT_FOUND )
723  libs.RemoveAt( slash_index, 1 );
724 
725  m_libraries.reserve( libs.GetCount() );
726 
727  for( unsigned int i = 0; i < libs.GetCount(); ++i )
728  m_libraries.push_back( libs[i] );
729  }
730  break;
731 
732  case GITHUB:
733  {
734  wxArrayInt checkedLibs;
735  m_checkListGH->GetCheckedItems( checkedLibs );
736 
737  m_libraries.reserve( checkedLibs.GetCount() );
738 
739  for( unsigned int i = 0; i < checkedLibs.GetCount(); ++i )
740  m_libraries.push_back( GetGithubURL() + "/" + m_checkListGH->GetString( checkedLibs[i] ) );
741  }
742  break;
743 
744  default:
745  wxASSERT( false );
746  break;
747  }
748 }
wxString GetGithubURL() const
Function GetGithubURL Returns the current Github repository URL set in the wizard.
wxGenericDirCtrl * m_filePicker
LIB_SOURCE GetLibSource() const
Function GetLibSource Returns the source of libraries (local / Github).
std::vector< LIBRARY > m_libraries
Libraries selected in the wizard
size_t i
Definition: json11.cpp:597
wxDataViewListCtrl * m_listCtrlReview
bool WIZARD_FPLIB_TABLE::wantLocalCopy ( ) const
inlineprotected

Does the user want a local copy of Github libraries?

Definition at line 242 of file wizard_add_fplib.h.

References WIZARD_FPLIB_TABLE_BASE::m_downloadGithub, updateGithubControls(), and updateLibraries().

Referenced by updateGithubControls().

242 { return m_downloadGithub->GetValue(); }

Member Data Documentation

wxStaticBitmap* WIZARD_FPLIB_TABLE_BASE::m_bitmapRepo
protectedinherited
wxButton* WIZARD_FPLIB_TABLE_BASE::m_btnBrowse
protectedinherited
wxButton* WIZARD_FPLIB_TABLE_BASE::m_btnSelectAllGH
protectedinherited
wxButton* WIZARD_FPLIB_TABLE_BASE::m_btnUnselectAllGH
protectedinherited
wxCheckListBox* WIZARD_FPLIB_TABLE_BASE::m_checkListGH
protectedinherited
wxStaticText* WIZARD_FPLIB_TABLE_BASE::m_downloadDir
protectedinherited
wxCheckBox* WIZARD_FPLIB_TABLE_BASE::m_downloadGithub
protectedinherited
wxDataViewColumn* WIZARD_FPLIB_TABLE_BASE::m_dvLibFormat
protectedinherited
wxDataViewColumn* WIZARD_FPLIB_TABLE_BASE::m_dvLibName
protectedinherited
wxDataViewColumn* WIZARD_FPLIB_TABLE_BASE::m_dvLibStatus
protectedinherited
wxGenericDirCtrl* WIZARD_FPLIB_TABLE_BASE::m_filePicker
protectedinherited
wxWizardPageSimple* const WIZARD_FPLIB_TABLE::m_fileSelectDlg
protected

Definition at line 267 of file wizard_add_fplib.h.

Referenced by OnPageChanged(), and setupDialogOrder().

wxArrayString WIZARD_FPLIB_TABLE::m_githubLibs
protected

Cache for the downloaded Github library list

Definition at line 260 of file wizard_add_fplib.h.

Referenced by checkFiles(), and OnChangeSearch().

wxWizardPageSimple* const WIZARD_FPLIB_TABLE::m_githubListDlg
protected

Definition at line 268 of file wizard_add_fplib.h.

Referenced by OnPageChanged(), and setupDialogOrder().

wxHyperlinkCtrl* WIZARD_FPLIB_TABLE_BASE::m_hyperlinkGithubKicad
protectedinherited
wxStaticText* WIZARD_FPLIB_TABLE_BASE::m_invalidDir
protectedinherited
wxString WIZARD_FPLIB_TABLE::m_lastGithubDownloadDirectory
protected

Definition at line 278 of file wizard_add_fplib.h.

Referenced by WIZARD_FPLIB_TABLE().

std::vector<LIBRARY> WIZARD_FPLIB_TABLE::m_libraries
protected

Libraries selected in the wizard

Definition at line 263 of file wizard_add_fplib.h.

Referenced by checkFiles(), GetLibraries(), OnWizardFinished(), setupFileSelect(), setupReview(), and updateLibraries().

wxDataViewListCtrl* WIZARD_FPLIB_TABLE_BASE::m_listCtrlReview
protectedinherited
WizardPages WIZARD_FPLIB_TABLE_BASE::m_pages
inherited
wxRadioButton* WIZARD_FPLIB_TABLE_BASE::m_radioAddGithub
protectedinherited
wxRadioButton* WIZARD_FPLIB_TABLE_BASE::m_radioAddLocal
protectedinherited
wxRadioButton* WIZARD_FPLIB_TABLE_BASE::m_radioGlobal
protectedinherited
wxRadioButton* WIZARD_FPLIB_TABLE_BASE::m_radioProject
protectedinherited
wxWizardPageSimple* const WIZARD_FPLIB_TABLE::m_reviewDlg
protected

Definition at line 269 of file wizard_add_fplib.h.

Referenced by OnPageChanged(), and setupDialogOrder().

wxSearchCtrl* WIZARD_FPLIB_TABLE_BASE::m_searchCtrlGH
protectedinherited
int WIZARD_FPLIB_TABLE::m_selectedFilter
protected

Definition at line 275 of file wizard_add_fplib.h.

Referenced by OnSelectFiles().

wxStaticText* WIZARD_FPLIB_TABLE_BASE::m_staticText1
protectedinherited
wxStaticText* WIZARD_FPLIB_TABLE_BASE::m_staticText112
protectedinherited
wxStaticText* WIZARD_FPLIB_TABLE_BASE::m_staticText1121
protectedinherited
wxStaticText* WIZARD_FPLIB_TABLE_BASE::m_staticText12
protectedinherited
wxStaticText* WIZARD_FPLIB_TABLE_BASE::m_staticText7
protectedinherited
wxWizardPageSimple* const WIZARD_FPLIB_TABLE::m_targetDlg
protected

Definition at line 270 of file wizard_add_fplib.h.

wxTextCtrl* WIZARD_FPLIB_TABLE_BASE::m_textCtrlGithubURL
protectedinherited
wxWizardPageSimple* const WIZARD_FPLIB_TABLE::m_welcomeDlg
protected

Definition at line 266 of file wizard_add_fplib.h.

Referenced by GetFirstPage(), and setupDialogOrder().


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