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:51

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 311 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().

311  :
312  WIZARD_FPLIB_TABLE_BASE( aParent ), m_welcomeDlg( m_pages[0] ),
315 {
316  m_filePicker->SetFilter( getFilterString() );
317 
318  // Initialize default download dir
319  wxString default_path;
320  wxGetEnv( FP_LIB_TABLE::GlobalPathEnvVariableName(), &default_path );
321  setDownloadDir( default_path );
322  m_filePicker->SetPath( default_path );
323 
324  // Restore the Github url
325  wxString githubUrl;
326 
327  wxConfigBase* cfg = Pgm().CommonSettings();
328  cfg->Read( KICAD_FPLIBS_URL_KEY, &githubUrl );
330 
331 
332  if( !m_lastGithubDownloadDirectory.IsEmpty() )
333  {
336  } else {
337  m_lastGithubDownloadDirectory = default_path;
338  }
339 
340  if( githubUrl.IsEmpty() )
341  githubUrl = wxT( "https://github.com/KiCad" );
342 
343  SetGithubURL( githubUrl );
344 
345  // Give the minimal size to the dialog, which allows displaying any page
346  wxSize minsize;
347 
348  for( unsigned ii = 0; ii < m_pages.size(); ii++ )
349  {
350  wxSize size = m_pages[ii]->GetSizer()->CalcMin();
351  minsize.x = std::max( minsize.x, size.x );
352  minsize.y = std::max( minsize.y, size.y );
353  }
354 
355  SetMinSize( minsize );
356  SetPageSize( minsize );
357  GetSizer()->SetSizeHints( this );
358  Center();
359 
360  if( !m_radioAddGithub->GetValue() && !m_radioAddLocal->GetValue() )
361  m_radioAddLocal->SetValue( true );
362 
365 
366  Connect( wxEVT_RADIOBUTTON, wxCommandEventHandler( WIZARD_FPLIB_TABLE::OnSourceCheck ), NULL, this );
367  Connect( wxEVT_DIRCTRL_SELECTIONCHANGED, wxCommandEventHandler( WIZARD_FPLIB_TABLE::OnSelectFiles ), NULL, this );
368  Connect( wxEVT_CHECKLISTBOX, wxCommandEventHandler( WIZARD_FPLIB_TABLE::OnCheckGithubList ), NULL, this );
369 }
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 372 of file wizard_add_fplib.cpp.

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

373 {
374  // Use this if you want to store kicad lib URL in pcbnew/cvpcb section config:
375 // wxConfigBase* cfg = Kiface().KifaceSettings();
376 
377  // Use this if you want to store kicad lib URL in common section config:
378  wxConfigBase* cfg = Pgm().CommonSettings();
379  cfg->Write( KICAD_FPLIBS_URL_KEY, GetGithubURL() );
380 }
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 580 of file wizard_add_fplib.cpp.

References WIZARD_FPLIB_TABLE_BASE::m_filePicker, and passesFilter().

Referenced by OnSelectFiles(), and setupFileSelect().

581 {
582  // Get current selection (files & directories)
583  wxArrayString candidates;
584  m_filePicker->GetPaths( candidates );
585 
586  // Workaround, when you change filters "/" is automatically selected
587  int slash_index = candidates.Index( "/", true, true );
588  if( slash_index != wxNOT_FOUND )
589  candidates.RemoveAt( slash_index, 1 );
590 
591  if( candidates.IsEmpty() )
592  return false;
593 
594  // Verify all the files/folders comply to the selected library type filter
595  for( unsigned int i = 0; i < candidates.GetCount(); ++i )
596  {
597  if( !passesFilter( candidates[i], m_filePicker->GetFilterIndex() ) )
598  return false;
599  }
600 
601  return true;
602 }
wxGenericDirCtrl * m_filePicker
static bool passesFilter(const wxString &aFileName, int aFilterIndex)
bool WIZARD_FPLIB_TABLE::downloadGithubLibsFromList ( wxArrayString &  aUrlList,
wxString *  aErrorMessage 
)
protected

Saves a list of Github libraries locally.

Referenced by 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 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 WIZARD_FPLIB_TABLE_BASE::m_downloadDir.

Referenced by 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 m_libraries.

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 394 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(), and DIALOG_FP_LIB_TABLE::OnClickLibraryWizard().

395 {
396  if( m_radioGlobal->GetValue() )
397  return GLOBAL;
398 
399  wxASSERT( m_radioProject->GetValue() );
400 
401  return PROJECT;
402 }
void WIZARD_FPLIB_TABLE::getLibsListGithub ( wxArrayString &  aList)
protected

Downloads the list of Github libraries

WIZARD_FPLIB_TABLE::LIB_SOURCE WIZARD_FPLIB_TABLE::GetLibSource ( ) const

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

Definition at line 383 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(), setupDialogOrder(), updateGithubControls(), and updateLibraries().

384 {
385  if( m_radioAddGithub->GetValue() )
386  return GITHUB;
387 
388  wxASSERT( m_radioAddLocal->GetValue() );
389 
390  return LOCAL;
391 }
void WIZARD_FPLIB_TABLE::OnBrowseButtonClick ( wxCommandEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_FPLIB_TABLE_BASE.

Definition at line 555 of file wizard_add_fplib.cpp.

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

556 {
557  wxString path = getDownloadDir();
558 
559  path = wxDirSelector( _("Choose a folder to save the downloaded libraries" ),
560  path, 0, wxDefaultPosition, this );
561 
562  if( !path.IsEmpty() && wxDirExists( path ) )
563  {
564  setDownloadDir( path );
565 
566  wxConfigBase* cfg = Pgm().CommonSettings();
567  cfg->Write( KICAD_FPLIBS_LAST_DOWNLOAD_DIR, path );
568 
570  }
571 }
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 475 of file wizard_add_fplib.cpp.

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

476 {
477  wxString searchPhrase = m_searchCtrlGH->GetValue().Lower();
478 
479  // Store the current selection
480  wxArrayInt checkedIndices;
481  m_checkListGH->GetCheckedItems( checkedIndices );
482  wxArrayString checkedStrings;
483 
484  for( unsigned int i = 0; i < checkedIndices.GetCount(); ++i )
485  checkedStrings.Add( m_checkListGH->GetString( checkedIndices[i] ).AfterLast( '/' ) );
486 
487  m_checkListGH->Clear();
488 
489  // Rebuild the list, putting the matching entries on the top
490  int matching = 0; // number of entries matching the search phrase
491  for( unsigned int i = 0; i < m_githubLibs.GetCount(); ++i )
492  {
493  const wxString& lib = m_githubLibs[i].AfterLast( '/' );
494  bool wasChecked = ( checkedStrings.Index( lib ) != wxNOT_FOUND );
495  int insertedIdx = -1;
496 
497  if( !searchPhrase.IsEmpty() && lib.Lower().Contains( searchPhrase ) )
498  {
499  insertedIdx = m_checkListGH->Insert( lib, matching++ );
500  m_checkListGH->SetSelection( insertedIdx );
501  }
502  else
503  insertedIdx = m_checkListGH->Append( lib );
504 
505  if( wasChecked )
506  m_checkListGH->Check( insertedIdx );
507  }
508 
509  if( !m_checkListGH->IsEmpty() )
510  m_checkListGH->EnsureVisible( 0 );
511 }
wxArrayString m_githubLibs
Cache for the downloaded Github library list
void WIZARD_FPLIB_TABLE::OnCheckGithubList ( wxCommandEvent &  aEvent)

Definition at line 440 of file wizard_add_fplib.cpp.

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

Referenced by WIZARD_FPLIB_TABLE().

441 {
442  wxArrayInt dummy;
443 
444  enableNext( m_checkListGH->GetCheckedItems( dummy ) > 0 );
445 }
void enableNext(bool aEnable)
Enables/disable 'Next' 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 574 of file wizard_add_fplib.cpp.

References updateGithubControls().

575 {
577 }
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 405 of file wizard_add_fplib.cpp.

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

406 {
407  SetBitmap( KiBitmap( wizard_add_fplib_icon_xpm ) );
408  enableNext( true );
409 
410 #ifdef BUILD_GITHUB_PLUGIN
411  if( GetCurrentPage() == m_githubListDlg )
412  setupGithubList();
413  else
414 #endif
415  if( GetCurrentPage() == m_fileSelectDlg )
416  setupFileSelect();
417  else if( GetCurrentPage() == m_reviewDlg )
418  setupReview();
419 }
wxWizardPageSimple *const m_fileSelectDlg
wxWizardPageSimple *const m_reviewDlg
void enableNext(bool aEnable)
Enables/disable 'Next' 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:36
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 455 of file wizard_add_fplib.cpp.

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

456 {
457  for( unsigned int i = 0; i < m_checkListGH->GetCount(); ++i )
458  m_checkListGH->Check( i, true );
459 
460  // The list might be empty, e.g. in case of download error
461  wxArrayInt dummy;
462  enableNext( m_checkListGH->GetCheckedItems( dummy ) > 0 );
463 }
void enableNext(bool aEnable)
Enables/disable 'Next' 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::OnSelectFiles ( wxCommandEvent &  aEvent)

Definition at line 422 of file wizard_add_fplib.cpp.

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

Referenced by WIZARD_FPLIB_TABLE().

423 {
424  int filterIdx = m_filePicker->GetFilterIndex();
425 
426  if( m_selectedFilter != filterIdx )
427  {
428  m_selectedFilter = filterIdx;
429 
430  // Process the event again, as in the first iteration we cannot get the list of selected items
431  wxCommandEvent ev( wxEVT_DIRCTRL_SELECTIONCHANGED );
432  AddPendingEvent( ev );
433  return;
434  }
435 
436  enableNext( checkFiles() );
437 }
void enableNext(bool aEnable)
Enables/disable 'Next' button
wxGenericDirCtrl * m_filePicker
bool checkFiles() const
Checks the selection in file picker
void WIZARD_FPLIB_TABLE::OnSourceCheck ( wxCommandEvent &  aEvent)

Definition at line 448 of file wizard_add_fplib.cpp.

References setupDialogOrder(), and updateGithubControls().

Referenced by WIZARD_FPLIB_TABLE().

449 {
452 }
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 466 of file wizard_add_fplib.cpp.

References enableNext(), and WIZARD_FPLIB_TABLE_BASE::m_checkListGH.

467 {
468  for( unsigned int i = 0; i < m_checkListGH->GetCount(); ++i )
469  m_checkListGH->Check( i, false );
470 
471  enableNext( false );
472 }
void enableNext(bool aEnable)
Enables/disable 'Next' button
void WIZARD_FPLIB_TABLE::OnWizardFinished ( wxWizardEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_FPLIB_TABLE_BASE.

Definition at line 514 of file wizard_add_fplib.cpp.

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

515 {
516 #ifdef BUILD_GITHUB_PLUGIN
517  // Shall we download a localy copy of the libraries
518  if( GetLibSource() == GITHUB && m_downloadGithub->GetValue() )
519  {
520  wxString error;
521  wxArrayString libs;
522 
523  // Prepare a list of libraries to download
524  for( std::vector<LIBRARY>::const_iterator it = m_libraries.begin();
525  it != m_libraries.end(); ++it )
526  {
527  wxASSERT( it->GetPluginType() == IO_MGR::GITHUB );
528 
529  if( it->GetStatus() != LIBRARY::INVALID )
530  libs.Add( it->GetAbsolutePath() );
531  }
532 
533  if( !downloadGithubLibsFromList( libs, &error ) )
534  {
535  DisplayError( this, error );
536  m_libraries.clear();
537  }
538  else
539  {
540  // Now libraries are stored locally, so update the paths to point to the download folder
541  for( std::vector<LIBRARY>::iterator it = m_libraries.begin();
542  it != m_libraries.end(); ++it )
543  {
544  wxString path = it->GetAbsolutePath();
545  path.Replace( GetGithubURL(), getDownloadDir() );
546  it->setPath( path );
547  it->setPluginType( IO_MGR::KICAD );
548  }
549  }
550  }
551 #endif
552 }
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).
S-expression Pcbnew file format.
Definition: io_mgr.h:54
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:69
Read only http://github.com repo holding pretty footprints.
Definition: io_mgr.h:58
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 WIZARD_FPLIB_TABLE_BASE::m_textCtrlGithubURL.

Referenced by WIZARD_FPLIB_TABLE().

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

Definition at line 766 of file wizard_add_fplib.cpp.

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

Referenced by OnSourceCheck(), and WIZARD_FPLIB_TABLE().

767 {
768  // Alternate the wizard pages flow depending on the selected option
769  switch( GetLibSource() )
770  {
771  case LOCAL:
772  m_welcomeDlg->SetNext( m_fileSelectDlg );
773  m_fileSelectDlg->SetPrev( m_welcomeDlg );
774 
775  m_fileSelectDlg->SetNext( m_reviewDlg );
776  m_reviewDlg->SetPrev( m_fileSelectDlg );
777  break;
778 
779  case GITHUB:
780  m_welcomeDlg->SetNext( m_githubListDlg );
781  m_githubListDlg->SetPrev( m_welcomeDlg );
782 
783  m_githubListDlg->SetNext( m_reviewDlg );
784  m_reviewDlg->SetPrev( m_githubListDlg );
785  break;
786 
787  default:
788  wxASSERT( false );
789  break;
790  }
791 }
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 794 of file wizard_add_fplib.cpp.

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

Referenced by OnPageChanged().

795 {
796  // Disable the button until something is selected
797  enableNext( checkFiles() );
798 
799  // Clear the review list so it will be reloaded
800  m_libraries.clear();
801  m_listCtrlReview->DeleteAllItems();
802 }
void enableNext(bool aEnable)
Enables/disable 'Next' 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

Referenced by OnPageChanged().

void WIZARD_FPLIB_TABLE::setupReview ( )
protected

Definition at line 805 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 OnPageChanged().

806 {
807  wxBeginBusyCursor();
808  updateLibraries();
809 
810  int libTotalCount = m_libraries.size();
811  int libCount = 0;
812  bool validate = true;
813  wxProgressDialog progressDlg( _( "Please wait..." ), _( "Validating libraries" ),
814  libTotalCount, this,
815  wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE );
816 
817  m_dvLibName->SetWidth( 280 );
818 
819  // Prepare the review list
820  m_listCtrlReview->DeleteAllItems();
821 
822  for( std::vector<LIBRARY>::iterator it = m_libraries.begin(); it != m_libraries.end(); ++it )
823  {
824  wxVector<wxVariant> row;
825  LIBRARY::STATUS status = it->GetStatus();
826 
827  // Check if the library contents is valid
828  if( status == LIBRARY::NOT_CHECKED && validate )
829  {
830  it->Test();
831  status = it->GetStatus();
832  }
833 
834  row.push_back( wxVariant( it->GetDescription() ) );
835 
836  switch( it->GetStatus() )
837  {
839  row.push_back( wxVariant( _( "NOT CHECKED" ) ) );
840  break;
841 
842  case LIBRARY::OK:
843  row.push_back( wxVariant( _( "OK" ) ) );
844  break;
845 
846  case LIBRARY::INVALID:
847  row.push_back( wxVariant( _( "INVALID" ) ) );
848  break;
849  }
850 
851  row.push_back( wxVariant( it->GetPluginName() ) );
852 
853  m_listCtrlReview->AppendItem( row );
854 
855  ++libCount;
856  if( !progressDlg.Update( libCount, wxString::Format( _( "Validating libraries %d/%d" ),
857  libCount, libTotalCount ) ) )
858  validate = false;
859  }
860 
861  // The list should never be empty, but who knows?
862  enableNext( m_listCtrlReview->GetItemCount() > 0 );
863 
864  wxEndBusyCursor();
865 }
void enableNext(bool aEnable)
Enables/disable 'Next' 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 701 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(), and WIZARD_FPLIB_TABLE().

702 {
703 #ifndef BUILD_GITHUB_PLUGIN
704  m_radioAddGithub->Enable( false );
705 #endif
706 
707  // Disable inputs that have no meaning for the selected source
708  bool githubEnabled = ( GetLibSource() == GITHUB );
709  m_textCtrlGithubURL->Enable( githubEnabled );
710  m_downloadGithub->Enable( githubEnabled );
711  m_downloadDir->Enable( githubEnabled && wantLocalCopy() );
712  m_btnBrowse->Enable( githubEnabled && wantLocalCopy() );
713 
714  bool valid = !( githubEnabled && wantLocalCopy() ) || wxFileName::IsDirWritable( getDownloadDir() );
715 
716  // Do not allow to go further unless there is a valid directory selected
717  m_invalidDir->Show( !valid );
718  enableNext( valid );
719 }
void enableNext(bool aEnable)
Enables/disable 'Next' 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 722 of file wizard_add_fplib.cpp.

References GetGithubURL(), GetLibSource(), GITHUB, 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().

723 {
724  // No need to update, the review list is ready
725  if( m_listCtrlReview->GetItemCount() != 0 )
726  return;
727 
728  switch( GetLibSource() )
729  {
730  case LOCAL:
731  {
732  wxArrayString libs;
733  m_filePicker->GetPaths( libs );
734 
735  // Workaround, when you change filters "/" is automatically selected
736  int slash_index = libs.Index( "/", true, true );
737  if( slash_index != wxNOT_FOUND )
738  libs.RemoveAt( slash_index, 1 );
739 
740  m_libraries.reserve( libs.GetCount() );
741 
742  for( unsigned int i = 0; i < libs.GetCount(); ++i )
743  m_libraries.push_back( libs[i] );
744  }
745  break;
746 
747  case GITHUB:
748  {
749  wxArrayInt checkedLibs;
750  m_checkListGH->GetCheckedItems( checkedLibs );
751 
752  m_libraries.reserve( checkedLibs.GetCount() );
753 
754  for( unsigned int i = 0; i < checkedLibs.GetCount(); ++i )
755  m_libraries.push_back( GetGithubURL() + "/" + m_checkListGH->GetString( checkedLibs[i] ) );
756  }
757  break;
758 
759  default:
760  wxASSERT( false );
761  break;
762  }
763 }
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
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.

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 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 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: