KiCad PCB EDA Suite
WIZARD_3DSHAPE_LIBS_DOWNLOADER Class Reference

#include <wizard_3DShape_Libs_downloader.h>

Inheritance diagram for WIZARD_3DSHAPE_LIBS_DOWNLOADER:
WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE

Public Member Functions

 WIZARD_3DSHAPE_LIBS_DOWNLOADER (wxWindow *aParent)
 
 ~WIZARD_3DSHAPE_LIBS_DOWNLOADER ()
 
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...
 
void OnSourceCheck (wxCommandEvent &aEvent)
 
void OnCheckGithubList (wxCommandEvent &aEvent)
 
void OnPageChanged (wxWizardEvent &aEvent) override
 
void OnSelectAll3Dlibs (wxCommandEvent &aEvent) override
 
void OnUnselectAll3Dlibs (wxCommandEvent &aEvent) override
 
void OnChangeSearch (wxCommandEvent &aEvent) override
 Called when the content of m_searchCtrl3Dlibs has changed. More...
 
void OnWizardFinished (wxWizardEvent &aEvent) override
 
void OnBrowseButtonClick (wxCommandEvent &aEvent) override
 
void OnCheckSaveCopy (wxCommandEvent &aEvent)
 
void OnDefault3DPathButtonClick (wxCommandEvent &event) override
 
void OnGridLibReviewSize (wxSizeEvent &event) override
 
void OnLocalFolderChange (wxCommandEvent &event) override
 

Public Attributes

WizardPages m_pages
 

Protected Member Functions

void setupDialogOrder ()
 
void setupGithubList ()
 
void setupReview ()
 
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 downloadOneLib (const wxString &aLibURL, const wxString &aLocalLibName, wxProgressDialog *aIndicator, wxString *aErrorMessage)
 

Saves a Github library aLibURL locally in aLocalLibName.

More...
 
void updateGithubControls ()
 

Enables Github widgets depending on the selected options.

More...
 
void enableNext (bool aEnable)
 

Enables/disable 'Next' button

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

Static Protected Member Functions

static bool filter3dshapesfiles (const wxString &aData)
 
static bool filter3dshapeslibraries (const wxString &aData)
 

Protected Attributes

wxArrayString m_githubLibs
 

Cache for the downloaded Github library list

More...
 
wxArrayString m_libraries
 

Libraries names selected in the wizard

More...
 
wxWizardPageSimple * m_welcomeDlg
 
wxWizardPageSimple * m_githubListDlg
 
wxWizardPageSimple * m_reviewDlg
 
wxStaticText * m_staticTextWelcome
 
wxStaticText * m_staticText8
 
wxTextCtrl * m_textCtrlGithubURL
 
wxStaticText * m_staticText9
 
wxTextCtrl * m_downloadDir
 
wxButton * m_btnBrowse
 
wxButton * m_buttonDefault3DPath
 
wxStaticBitmap * m_bitmapDirWarn
 
wxStaticText * m_invalidDirWarningText
 
wxStaticBitmap * m_bitmapRepo
 
wxHyperlinkCtrl * m_hyperlinkGithubKicad
 
wxStaticText * m_staticText112
 
wxCheckListBox * m_checkList3Dlibnames
 
wxButton * m_btnSelectAll3Dlibs
 
wxButton * m_btnUnselectAll3Dlibs
 
wxSearchCtrl * m_searchCtrl3Dlibs
 
wxStaticText * m_staticTextlocalfolder
 
wxStaticText * m_LocalFolderInfo
 
wxStaticText * m_staticText12
 
wxGrid * m_gridLibReview
 

Detailed Description

Definition at line 31 of file wizard_3DShape_Libs_downloader.h.

Constructor & Destructor Documentation

WIZARD_3DSHAPE_LIBS_DOWNLOADER::WIZARD_3DSHAPE_LIBS_DOWNLOADER ( wxWindow *  aParent)

Definition at line 64 of file wizard_3DShape_Libs_downloader.cpp.

References PCAD2KICAD::Center, PGM_BASE::CommonSettings(), DEFAULT_GITHUB_3DSHAPES_LIBS_URL, KICAD_3DLIBS_LAST_DOWNLOAD_DIR, KICAD_3DLIBS_URL_KEY, KISYS3DMOD, m_githubListDlg, WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_hyperlinkGithubKicad, WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_pages, m_reviewDlg, m_welcomeDlg, max, OnCheckGithubList(), OnSourceCheck(), Pgm(), setDownloadDir(), SetGithubURL(), setupDialogOrder(), and updateGithubControls().

64  :
66 {
67  m_welcomeDlg = m_pages[0];
69  m_reviewDlg = m_pages[2];
70 
71  // Initialize default download dir (local target folder of 3D shapes libs)
72  wxString default_path;
73  wxGetEnv( KISYS3DMOD, &default_path );
74 
75  wxConfigBase* cfg = Pgm().CommonSettings();
76  wxString tmp;
77  cfg->Read( KICAD_3DLIBS_LAST_DOWNLOAD_DIR, &tmp, default_path );
78  setDownloadDir( tmp );
79 
80  // Restore the Github 3D shapes libs url
81  wxString githubUrl;
82  cfg->Read( KICAD_3DLIBS_URL_KEY, &githubUrl );
83 
84  if( githubUrl.IsEmpty() )
86 
87  SetGithubURL( githubUrl );
88 
89 
90  // Give the minimal size to the dialog, which allows displaying any page
91  wxSize minsize;
92 
93  for( unsigned ii = 0; ii < m_pages.size(); ii++ )
94  {
95  wxSize size = m_pages[ii]->GetSizer()->CalcMin();
96  minsize.x = std::max( minsize.x, size.x );
97  minsize.y = std::max( minsize.y, size.y );
98  }
99 
100  SetMinSize( minsize );
101  SetPageSize( minsize );
102  GetSizer()->SetSizeHints( this );
103  Center();
104 
107 
108  // When starting m_textCtrlGithubURL has the focus, and the text is selected,
109  // and not fully visible.
110  // Forcing deselection does not work, at least on W7 with wxWidgets 3.0.2
111  // So (and also because m_textCtrlGithubURL and m_downloadDir are rarely modified
112  // the focus is given to an other widget.
113  m_hyperlinkGithubKicad->SetFocus();
114 
115  Connect( wxEVT_RADIOBUTTON, wxCommandEventHandler( WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnSourceCheck ), NULL, this );
116  Connect( wxEVT_CHECKLISTBOX, wxCommandEventHandler( WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnCheckGithubList ), NULL, this );
117 }
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
void OnCheckGithubList(wxCommandEvent &aEvent)
void updateGithubControls()
Enables Github widgets depending on the selected options.
#define KICAD_3DLIBS_LAST_DOWNLOAD_DIR
#define KISYS3DMOD
A variable name whose value holds the path of 3D shape files.
Definition: 3d_viewer.h:38
#define KICAD_3DLIBS_URL_KEY
Wizard for selecting and dowloading D shapes libraries of footprints consisting of 3 steps: ...
void SetGithubURL(const wxString &aUrl)
Function SetGithubURL Sets the current Github repository URL used by the wizard.
#define max(a, b)
Definition: auxiliary.h:86
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:145
WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Add 3D Shape 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)
void setDownloadDir(const wxString &aDir)
Sets the target directory for libraries downloaded from Github
#define DEFAULT_GITHUB_3DSHAPES_LIBS_URL
WIZARD_3DSHAPE_LIBS_DOWNLOADER::~WIZARD_3DSHAPE_LIBS_DOWNLOADER ( )

Definition at line 120 of file wizard_3DShape_Libs_downloader.cpp.

References PGM_BASE::CommonSettings(), getDownloadDir(), GetGithubURL(), KICAD_3DLIBS_LAST_DOWNLOAD_DIR, KICAD_3DLIBS_URL_KEY, and Pgm().

121 {
122  // Use this if you want to store kicad lib URL in pcbnew/cvpcb section config:
123  // wxConfigBase* cfg = Kiface().KifaceSettings();
124 
125  // Use this if you want to store kicad lib URL in common section config:
126  wxConfigBase* cfg = Pgm().CommonSettings();
127  cfg->Write( KICAD_3DLIBS_URL_KEY, GetGithubURL() );
129 }
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
wxString getDownloadDir()
Gets the current target for downloaded libraries
wxString GetGithubURL() const
Function GetGithubURL Returns the current Github repository URL set in the wizard.
#define KICAD_3DLIBS_LAST_DOWNLOAD_DIR
#define KICAD_3DLIBS_URL_KEY
Wizard for selecting and dowloading D shapes libraries of footprints consisting of 3 steps: ...
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:145

Member Function Documentation

bool WIZARD_3DSHAPE_LIBS_DOWNLOADER::downloadGithubLibsFromList ( wxArrayString &  aUrlList,
wxString *  aErrorMessage 
)
protected

Saves a list of Github libraries locally.

Definition at line 352 of file wizard_3DShape_Libs_downloader.cpp.

References downloadOneLib(), Format(), getDownloadDir(), GetGithubURL(), and m_githubLibs.

Referenced by OnWizardFinished().

354 {
355  // Display a progress bar to show the download state
356  // The title is updated for each downloaded library.
357  // the state will be updated by downloadOneLib() for each file.
358  wxProgressDialog pdlg( _( "Downloading 3D libraries" ), wxEmptyString,
359  aUrlList.GetCount(), GetParent(),
360  wxPD_CAN_ABORT | wxPD_APP_MODAL | wxPD_AUTO_HIDE );
361 
362  // Built the full server name string:
363  wxURI repo( GetGithubURL() );
364  wxString server = repo.GetScheme() + "://" + repo.GetServer();
365 
366  // Download libs:
367  for( unsigned ii = 0; ii < aUrlList.GetCount(); ii++ )
368  {
369  wxString& libsrc_name = aUrlList[ii];
370 
371  // Recover the full URL lib from short name:
372  // (note: m_githubLibs stores the URL relative to the server name)
373  wxString url;
374 
375  for( unsigned jj = 0; jj < m_githubLibs.GetCount(); jj++ )
376  {
377  if( m_githubLibs[jj].EndsWith( libsrc_name ) )
378  {
379  url = server + m_githubLibs[jj];
380  break;
381  }
382  }
383 
384  wxFileName fn( libsrc_name );
385  // Set our local path
386  fn.SetPath( getDownloadDir() );
387  wxString libdst_name = fn.GetFullPath();
388 
389  // Display the name of the library to download in the wxProgressDialog
390  pdlg.SetTitle( wxString::Format( wxT("%s [%d/%d]" ),
391  libsrc_name.AfterLast( '/' ).GetData(),
392  ii + 1, aUrlList.GetCount() ) );
393 
394  if( !wxDirExists( libdst_name ) )
395  wxMkdir( libdst_name );
396 
397  if( !downloadOneLib( url, libdst_name, &pdlg, aErrorMessage ) )
398  return false;
399  }
400 
401  return true;
402 }
wxArrayString m_githubLibs
Cache for the downloaded Github library list
wxString getDownloadDir()
Gets the current target for downloaded libraries
wxString GetGithubURL() const
Function GetGithubURL Returns the current Github repository URL set in the wizard.
bool downloadOneLib(const wxString &aLibURL, const wxString &aLocalLibName, wxProgressDialog *aIndicator, wxString *aErrorMessage)
Saves a Github library aLibURL locally in aLocalLibName.
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
bool WIZARD_3DSHAPE_LIBS_DOWNLOADER::downloadOneLib ( const wxString &  aLibURL,
const wxString &  aLocalLibName,
wxProgressDialog *  aIndicator,
wxString *  aErrorMessage 
)
protected

Saves a Github library aLibURL locally in aLocalLibName.

Definition at line 405 of file wizard_3DShape_Libs_downloader.cpp.

References filter3dshapesfiles(), GITHUB_GETLIBLIST::Get3DshapesLibsList(), and GITHUB_GETLIBLIST::GetBuffer().

Referenced by downloadGithubLibsFromList().

408 {
409  wxArrayString fileslist;
410 
411  bool success;
412 
413  // Get the list of candidate files: with ext .wrl .stp .step .STEP .STP or .wings
414  do
415  {
416  GITHUB_GETLIBLIST getter( aLibURL );
417  success = getter.Get3DshapesLibsList( &fileslist, filter3dshapesfiles );
418  } while( 0 );
419 
420  if( !success )
421  return false;
422 
423  // Load each file in list:
424  wxURI repo( aLibURL );
425 
426  wxString server = repo.GetServer();
427 
428  // Github gives the current url of files inside .3dshapes folders like:
429  // "https://github.com/KiCad/kicad-library/blob/master/modules/packages3d/Capacitors_SMD.3dshapes/C_0402.wrl"
430  // which displays a html page showing the file in html form.
431  //
432  // the URL of the corresponding raw file is
433  // "https://github.com/KiCad/kicad-library/raw/master/modules/packages3d/Capacitors_SMD.3dshapes/C_0402.wrl"
434  //
435  // However Github redirects this current url to raw.githubusercontent.com/fullfilename
436  // when trying to download raw files.
437  // "https://github.com/KiCad/kicad-library/raw/master/modules/packages3d/Capacitors_SMD.3dshapes/C_0402.wrl"
438  // would be redirected to:
439  // "https://raw.githubusercontent.com/KiCad/kicad-library/master/modules/packages3d/Capacitors_SMD.3dshapes/C_0402.wrl"
440  // So use raw.githubusercontent.com instead of github.com
441  // (and removes the "/raw" in path) speed up the downloads (x2 faster).
442  //
443  // wxURI has no way to change the server name, so we need to use tricks to make the URL.
444  //
445  // Comment this next line to use the github.com URL
446 #define FORCE_GITHUB_RAW_URL
447 
448 #ifdef FORCE_GITHUB_RAW_URL
449  if( server.Cmp( wxT( "github.com" ) ) == 0 )
450  server = wxT( "raw.githubusercontent.com" );
451 #endif
452 
453  wxString full_url_base = repo.GetScheme() + wxT( "://" ) + server;
454  wxString target_full_url;
455 
456  for( unsigned ii = 0; ii < fileslist.GetCount(); ii++ )
457  {
458  target_full_url = full_url_base + fileslist[ii];
459 
460 #ifdef FORCE_GITHUB_RAW_URL
461  // Remove "blob/" in URL string to build the URL on "raw.githubusercontent.com"
462  // server from "github.com" URL string:
463  target_full_url.Replace( wxT( "blob/" ), wxT( "" ) );
464 #else
465  // Replace "blob" by "raw" in URL to access the raw file itself, not the html page
466  // on "github.com" server
467  target_full_url.Replace( wxT( "blob" ), wxT( "raw" ) );
468 #endif
469  aIndicator->SetRange( fileslist.GetCount() );
470  bool abort = !aIndicator->Update( ii, target_full_url.AfterLast( '/' ) );
471 
472  if( abort )
473  {
474  if( aErrorMessage )
475  *aErrorMessage << _( "Aborted by user" );
476  return false;
477  }
478 
479  // Download the current file.
480  // Get3DshapesLibsList actually downloads and stores the target_full_url content.
481  GITHUB_GETLIBLIST getter( target_full_url );
482  success = getter.Get3DshapesLibsList( NULL, NULL );
483 
484  if( !success )
485  break;
486 
487  wxFileName fn;
488  fn.AssignDir( aLocalLibName );
489  fn.SetFullName( fileslist[ii].AfterLast( '/' ) );
490 
491  // The entire downloaded file is stored in getter buffer
492  const std::string& buffer = getter.GetBuffer();
493 
494  // Write is "as this". It can be a binary file.
495  wxFile file(fn.GetFullPath(), wxFile::write);
496  file.Write( &buffer[0], buffer.size() );
497  }
498 
499  return success;
500 }
static bool filter3dshapesfiles(const wxString &aData)
Class GITHUB_GETLIBLIST implements a portion of pcbnew's PLUGIN interface to provide read only access...
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::enableNext ( bool  aEnable)
inlineprotected

Enables/disable 'Next' button

Definition at line 119 of file wizard_3DShape_Libs_downloader.h.

Referenced by OnCheckGithubList(), OnPageChanged(), OnSelectAll3Dlibs(), OnUnselectAll3Dlibs(), setupGithubList(), and updateGithubControls().

120  {
121  wxWindow* nextBtn = FindWindowById( wxID_FORWARD );
122 
123  if( nextBtn )
124  nextBtn->Enable( aEnable );
125  }
static bool WIZARD_3DSHAPE_LIBS_DOWNLOADER::filter3dshapesfiles ( const wxString &  aData)
inlinestaticprotected

Definition at line 128 of file wizard_3DShape_Libs_downloader.h.

Referenced by downloadOneLib().

129  {
130  return aData.Contains( wxT( ".wrl" ) ) ||
131  aData.Contains( wxT( ".wings" ) ) ||
132  aData.Contains( wxT( ".stp" ) ) ||
133  aData.Contains( wxT( ".step" ) ) ||
134  aData.Contains( wxT( ".STP" ) ) ||
135  aData.Contains( wxT( ".STEP" ) );
136  }
static bool WIZARD_3DSHAPE_LIBS_DOWNLOADER::filter3dshapeslibraries ( const wxString &  aData)
inlinestaticprotected

Definition at line 139 of file wizard_3DShape_Libs_downloader.h.

Referenced by getLibsListGithub().

140  {
141  return aData.Contains( wxT( ".3dshapes" ) );
142  }
wxString WIZARD_3DSHAPE_LIBS_DOWNLOADER::getDownloadDir ( )
inlineprotected
wxWizardPage* WIZARD_3DSHAPE_LIBS_DOWNLOADER::GetFirstPage ( ) const
inline

Function GetFirstPage Returns the welcoming page for the wizard.

Definition at line 41 of file wizard_3DShape_Libs_downloader.h.

References m_welcomeDlg.

Referenced by Invoke3DShapeLibsDownloaderWizard().

42  {
43  return m_welcomeDlg;
44  }
wxString WIZARD_3DSHAPE_LIBS_DOWNLOADER::GetGithubURL ( ) const
inline

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

Definition at line 50 of file wizard_3DShape_Libs_downloader.h.

References WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_textCtrlGithubURL.

Referenced by downloadGithubLibsFromList(), and ~WIZARD_3DSHAPE_LIBS_DOWNLOADER().

51  {
52  return m_textCtrlGithubURL->GetValue();
53  }
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::getLibsListGithub ( wxArrayString &  aList)
protected

Downloads the list of Github libraries

Definition at line 330 of file wizard_3DShape_Libs_downloader.cpp.

References filter3dshapeslibraries(), GITHUB_GETLIBLIST::Get3DshapesLibsList(), and WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_textCtrlGithubURL.

Referenced by setupGithubList().

331 {
332  wxBeginBusyCursor();
333 
334  // Be sure there is no trailing '/' at the end of the repo name
335  wxString git_url = m_textCtrlGithubURL->GetValue();
336 
337  if( git_url.EndsWith( wxT( "/" ) ) )
338  {
339  git_url.RemoveLast();
340  m_textCtrlGithubURL->SetValue( git_url );
341  }
342 
343  GITHUB_GETLIBLIST getter( git_url );
344  getter.Get3DshapesLibsList( &aList, filter3dshapeslibraries );
345 
346  wxEndBusyCursor();
347 }
static bool filter3dshapeslibraries(const wxString &aData)
Class GITHUB_GETLIBLIST implements a portion of pcbnew's PLUGIN interface to provide read only access...
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnBrowseButtonClick ( wxCommandEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 294 of file wizard_3DShape_Libs_downloader.cpp.

References getDownloadDir(), setDownloadDir(), and updateGithubControls().

295 {
296  wxString path = getDownloadDir();
297 
298  path = wxDirSelector( _("Choose a folder to save the downloaded libraries" ),
299  path, 0, wxDefaultPosition, this );
300 
301  if( !path.IsEmpty() && wxDirExists( path ) )
302  {
303  setDownloadDir( path );
305  }
306 }
wxString getDownloadDir()
Gets the current target for downloaded libraries
void updateGithubControls()
Enables Github widgets depending on the selected options.
void setDownloadDir(const wxString &aDir)
Sets the target directory for libraries downloaded from Github
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnChangeSearch ( wxCommandEvent &  aEvent)
overridevirtual

Called when the content of m_searchCtrl3Dlibs has changed.

Rebuild the list of libraries, lib cacdidate first

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 243 of file wizard_3DShape_Libs_downloader.cpp.

References WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_checkList3Dlibnames, m_githubLibs, and WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_searchCtrl3Dlibs.

244 {
245  wxString searchPhrase = m_searchCtrl3Dlibs->GetValue().Lower();
246 
247  // Store the current selection
248  wxArrayInt checkedIndices;
249  m_checkList3Dlibnames->GetCheckedItems( checkedIndices );
250  wxArrayString checkedStrings;
251 
252  for( unsigned int i = 0; i < checkedIndices.GetCount(); ++i )
253  checkedStrings.Add( m_checkList3Dlibnames->GetString( checkedIndices[i] ).AfterLast( '/' ) );
254 
255  m_checkList3Dlibnames->Clear();
256 
257  // Rebuild the list, putting the matching entries on the top
258  int matching = 0; // number of entries matching the search phrase
259  for( unsigned int i = 0; i < m_githubLibs.GetCount(); ++i )
260  {
261  const wxString& lib = m_githubLibs[i].AfterLast( '/' );
262  bool wasChecked = ( checkedStrings.Index( lib ) != wxNOT_FOUND );
263  int insertedIdx = -1;
264 
265  if( !searchPhrase.IsEmpty() && lib.Lower().BeforeLast( '.' ).Contains( searchPhrase ) )
266  {
267  insertedIdx = m_checkList3Dlibnames->Insert( lib, matching++ );
268  m_checkList3Dlibnames->SetSelection( insertedIdx );
269  }
270  else
271  insertedIdx = m_checkList3Dlibnames->Append( lib );
272 
273  if( wasChecked )
274  m_checkList3Dlibnames->Check( insertedIdx );
275  }
276 
277  if( !m_checkList3Dlibnames->IsEmpty() )
278  m_checkList3Dlibnames->EnsureVisible( 0 );
279 }
wxArrayString m_githubLibs
Cache for the downloaded Github library list
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnCheckGithubList ( wxCommandEvent &  aEvent)

Definition at line 145 of file wizard_3DShape_Libs_downloader.cpp.

References dummy(), enableNext(), and WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_checkList3Dlibnames.

Referenced by WIZARD_3DSHAPE_LIBS_DOWNLOADER().

146 {
147  wxArrayInt dummy;
148 
149  enableNext( m_checkList3Dlibnames->GetCheckedItems( dummy ) > 0 );
150 }
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_3DSHAPE_LIBS_DOWNLOADER::OnCheckSaveCopy ( wxCommandEvent &  aEvent)

Definition at line 324 of file wizard_3DShape_Libs_downloader.cpp.

References updateGithubControls().

325 {
327 }
void updateGithubControls()
Enables Github widgets depending on the selected options.
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnDefault3DPathButtonClick ( wxCommandEvent &  event)
overridevirtual

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 309 of file wizard_3DShape_Libs_downloader.cpp.

References KISYS3DMOD, setDownloadDir(), and updateGithubControls().

310 {
311  wxString default_path;
312  wxGetEnv( KISYS3DMOD, &default_path );
313 
314  if( !default_path.IsEmpty() && wxDirExists( default_path ) )
315  {
316  setDownloadDir( default_path );
318  }
319  else
320  wxMessageBox( _( "KISYS3DMOD path not defined , or not existing" ) );
321 }
void updateGithubControls()
Enables Github widgets depending on the selected options.
#define KISYS3DMOD
A variable name whose value holds the path of 3D shape files.
Definition: 3d_viewer.h:38
void setDownloadDir(const wxString &aDir)
Sets the target directory for libraries downloaded from Github
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnGridLibReviewSize ( wxSizeEvent &  event)
overridevirtual

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 159 of file wizard_3DShape_Libs_downloader.cpp.

References WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_gridLibReview.

160 {
161  // Adjust the width of the column 1 of m_gridLibReview (library names) to the
162  // max available width.
163  int gridwidth = m_gridLibReview->GetClientSize().x;
164  gridwidth -= m_gridLibReview->GetColSize( 0 ) + m_gridLibReview->GetColLabelSize();
165 
166  if( gridwidth < 200 )
167  gridwidth = 200;
168 
169  m_gridLibReview->SetColSize( 1, gridwidth );
170 
171  event.Skip();
172 }
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnLocalFolderChange ( wxCommandEvent &  event)
overridevirtual

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 545 of file wizard_3DShape_Libs_downloader.cpp.

References updateGithubControls().

546 {
548 }
void updateGithubControls()
Enables Github widgets depending on the selected options.
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnPageChanged ( wxWizardEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 133 of file wizard_3DShape_Libs_downloader.cpp.

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

134 {
135  SetBitmap( KiBitmap( wizard_add_fplib_icon_xpm ) );
136  enableNext( true );
137 
138  if( GetCurrentPage() == m_githubListDlg )
139  setupGithubList();
140  else if( GetCurrentPage() == m_reviewDlg )
141  setupReview();
142 }
void enableNext(bool aEnable)
Enables/disable 'Next' button
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_3DSHAPE_LIBS_DOWNLOADER_BASE::OnPageChanging ( wxWizardEvent &  event)
inlineprotectedvirtualinherited
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnSelectAll3Dlibs ( wxCommandEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 223 of file wizard_3DShape_Libs_downloader.cpp.

References dummy(), enableNext(), and WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_checkList3Dlibnames.

224 {
225  for( unsigned int i = 0; i < m_checkList3Dlibnames->GetCount(); ++i )
226  m_checkList3Dlibnames->Check( i, true );
227 
228  // The list might be empty, e.g. in case of download error
229  wxArrayInt dummy;
230  enableNext( m_checkList3Dlibnames->GetCheckedItems( dummy ) > 0 );
231 }
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_3DSHAPE_LIBS_DOWNLOADER::OnSourceCheck ( wxCommandEvent &  aEvent)

Definition at line 153 of file wizard_3DShape_Libs_downloader.cpp.

References setupDialogOrder(), and updateGithubControls().

Referenced by WIZARD_3DSHAPE_LIBS_DOWNLOADER().

154 {
157 }
void updateGithubControls()
Enables Github widgets depending on the selected options.
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnUnselectAll3Dlibs ( wxCommandEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 234 of file wizard_3DShape_Libs_downloader.cpp.

References enableNext(), and WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_checkList3Dlibnames.

235 {
236  for( unsigned int i = 0; i < m_checkList3Dlibnames->GetCount(); ++i )
237  m_checkList3Dlibnames->Check( i, false );
238 
239  enableNext( false );
240 }
void enableNext(bool aEnable)
Enables/disable 'Next' button
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnWizardFinished ( wxWizardEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 282 of file wizard_3DShape_Libs_downloader.cpp.

References DisplayError(), downloadGithubLibsFromList(), and m_libraries.

283 {
284  // we download a localy copy of the libraries
285  wxString error;
286 
287  if( !downloadGithubLibsFromList( m_libraries, &error ) )
288  {
289  DisplayError( GetParent(), error );
290  }
291 }
wxArrayString m_libraries
Libraries names selected in the wizard
bool downloadGithubLibsFromList(wxArrayString &aUrlList, wxString *aErrorMessage)
Saves a list of Github libraries locally.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:71
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::setDownloadDir ( const wxString &  aDir)
inlineprotected

Sets the target directory for libraries downloaded from Github

Definition at line 92 of file wizard_3DShape_Libs_downloader.h.

References WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_downloadDir.

Referenced by OnBrowseButtonClick(), OnDefault3DPathButtonClick(), and WIZARD_3DSHAPE_LIBS_DOWNLOADER().

93  {
94  m_downloadDir->SetValue( aDir );
95  }
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::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 60 of file wizard_3DShape_Libs_downloader.h.

References WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_textCtrlGithubURL.

Referenced by WIZARD_3DSHAPE_LIBS_DOWNLOADER().

61  {
62  m_textCtrlGithubURL->SetValue( aUrl );
63  }
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::setupDialogOrder ( )
protected
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::setupGithubList ( )
protected

Definition at line 503 of file wizard_3DShape_Libs_downloader.cpp.

References enableNext(), getLibsListGithub(), WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_checkList3Dlibnames, m_githubLibs, m_libraries, and WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_searchCtrl3Dlibs.

Referenced by OnPageChanged().

504 {
505  // Enable 'Next' only if there is at least one library selected
506  wxArrayInt checkedIndices;
507  m_checkList3Dlibnames->GetCheckedItems( checkedIndices );
508  enableNext( checkedIndices.GetCount() > 0 );
509 
510  // Update only if necessary
511  if( m_githubLibs.GetCount() == 0 )
513 
514  m_searchCtrl3Dlibs->Clear();
515 
516  // Clear the review list so it will be reloaded
517  m_libraries.clear();
518 }
wxArrayString m_libraries
Libraries names selected in the wizard
wxArrayString m_githubLibs
Cache for the downloaded Github library list
void enableNext(bool aEnable)
Enables/disable 'Next' button
void getLibsListGithub(wxArrayString &aList)
Downloads the list of Github libraries
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::setupReview ( )
protected

Definition at line 175 of file wizard_3DShape_Libs_downloader.cpp.

References delta, getDownloadDir(), WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_checkList3Dlibnames, WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_gridLibReview, m_libraries, and WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_LocalFolderInfo.

Referenced by OnPageChanged().

176 {
177  // Prepare the last page of the wizard.
178 
179  m_LocalFolderInfo->SetLabel( getDownloadDir() );
180 
181  wxArrayInt checkedIndices;
182  m_checkList3Dlibnames->GetCheckedItems( checkedIndices );
183 
184  m_libraries.Clear();
185 
186  // populate m_libraries with the name of libraries, without the github path:
187  for( unsigned int ii = 0; ii < checkedIndices.GetCount(); ++ii )
188  {
189  m_libraries.Add( m_checkList3Dlibnames->GetString( checkedIndices[ii] ).AfterLast( '/' ) );
190  }
191 
192  // Adjust number of rows in m_gridLibReview:
193  int delta = m_libraries.GetCount() - m_gridLibReview->GetNumberRows();
194 
195  if( delta < 0 )
196  m_gridLibReview->DeleteRows( -delta );
197  else if( delta > 0 )
198  m_gridLibReview->AppendRows( delta );
199 
200  // For user info, verify the existence of these libs in local folder
201  wxArrayString liblist;
202  wxFileName fn;
203  fn.AssignDir( getDownloadDir() );
204 
205  for( unsigned int ii = 0; ii < m_libraries.GetCount(); ++ii )
206  {
207  fn.SetName( m_libraries[ii] );
208 
209  wxDir dirs;
210  bool isNew = ! dirs.Exists( fn.GetFullPath() );
211  wxString info = isNew ? _( "New" ) : _( "Update" );
212 
213  liblist.Add( info + wxT(" ") + m_libraries[ii] );
214 
215  m_gridLibReview->SetCellValue( ii, 0, info );
216  m_gridLibReview->SetCellValue( ii, 1, m_libraries[ii] );
217  }
218 
219  m_gridLibReview->AutoSizeColumn( 0 );
220 }
wxArrayString m_libraries
Libraries names selected in the wizard
static const int delta[8][2]
Definition: solve.cpp:112
wxString getDownloadDir()
Gets the current target for downloaded libraries
void WIZARD_3DSHAPE_LIBS_DOWNLOADER::updateGithubControls ( )
protected

Enables Github widgets depending on the selected options.

Definition at line 521 of file wizard_3DShape_Libs_downloader.cpp.

References enableNext(), getDownloadDir(), WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_bitmapDirWarn, and WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_invalidDirWarningText.

Referenced by OnBrowseButtonClick(), OnCheckSaveCopy(), OnDefault3DPathButtonClick(), OnLocalFolderChange(), OnSourceCheck(), and WIZARD_3DSHAPE_LIBS_DOWNLOADER().

522 {
523  bool valid = wxFileName::IsDirWritable( getDownloadDir() );
524 
525  // Shows or not the warning text if the target 3d folder does not exist, or is not
526  // writable.
527  m_invalidDirWarningText->Show( !valid );
528  m_bitmapDirWarn->Show( !valid );
529 
530  // If the dialog starts with m_invalidDirWarningText and m_bitmapDirWarn not shown
531  // the size and position of the sizer containing these widgets can be incorrect,
532  // until a wxSizeEvent is fired, and the widgets are not shown, or truncated,
533  // at least on Windows. So fire a dummy wxSizeEvent if the size looks bad
534  if( m_invalidDirWarningText->IsShown() && m_invalidDirWarningText->GetSize().x < 2 )
535  {
536  wxSizeEvent event( GetSize() );
537  wxPostEvent( this, event );
538  }
539 
540  // Allow to go further only if there is a valid target directory selected
541  enableNext( valid );
542 }
wxString getDownloadDir()
Gets the current target for downloaded libraries
void enableNext(bool aEnable)
Enables/disable 'Next' button

Member Data Documentation

wxStaticBitmap* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_bitmapDirWarn
protectedinherited
wxStaticBitmap* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_bitmapRepo
protectedinherited
wxButton* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_btnBrowse
protectedinherited
wxButton* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_btnSelectAll3Dlibs
protectedinherited
wxButton* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_btnUnselectAll3Dlibs
protectedinherited
wxButton* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_buttonDefault3DPath
protectedinherited
wxCheckListBox* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_checkList3Dlibnames
protectedinherited
wxArrayString WIZARD_3DSHAPE_LIBS_DOWNLOADER::m_githubLibs
protected

Cache for the downloaded Github library list

Definition at line 145 of file wizard_3DShape_Libs_downloader.h.

Referenced by downloadGithubLibsFromList(), OnChangeSearch(), and setupGithubList().

wxWizardPageSimple* WIZARD_3DSHAPE_LIBS_DOWNLOADER::m_githubListDlg
protected
wxHyperlinkCtrl* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_hyperlinkGithubKicad
protectedinherited
wxStaticText* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_invalidDirWarningText
protectedinherited
wxArrayString WIZARD_3DSHAPE_LIBS_DOWNLOADER::m_libraries
protected

Libraries names selected in the wizard

Definition at line 148 of file wizard_3DShape_Libs_downloader.h.

Referenced by OnWizardFinished(), setupGithubList(), and setupReview().

wxStaticText* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_LocalFolderInfo
protectedinherited
wxWizardPageSimple* WIZARD_3DSHAPE_LIBS_DOWNLOADER::m_reviewDlg
protected
wxStaticText* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_staticText112
protectedinherited
wxStaticText* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_staticText12
protectedinherited
wxStaticText* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_staticText8
protectedinherited
wxStaticText* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_staticText9
protectedinherited
wxStaticText* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_staticTextlocalfolder
protectedinherited
wxStaticText* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_staticTextWelcome
protectedinherited
wxTextCtrl* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_textCtrlGithubURL
protectedinherited
wxWizardPageSimple* WIZARD_3DSHAPE_LIBS_DOWNLOADER::m_welcomeDlg
protected

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