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

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

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

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

Referenced by OnPageChanged().

797 {
798  // Disable the button until something is selected
799  enableNext( checkFiles() );
800 
801  // Clear the review list so it will be reloaded
802  m_libraries.clear();
803  m_listCtrlReview->DeleteAllItems();
804 }
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 807 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().

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

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

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