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::WIZARD_3DSHAPE_LIBS_DOWNLOADER ( wxWindow *  aParent)

Definition at line 65 of file wizard_3DShape_Libs_downloader.cpp.

65  :
67 {
68  m_welcomeDlg = m_pages[0];
70  m_reviewDlg = m_pages[2];
71 
72  // Initialize default download dir (local target folder of 3D shapes libs)
73  wxString default_path;
74  wxGetEnv( KISYS3DMOD, &default_path );
75 
76  auto cfg = Pgm().GetCommonSettings();
77 
78  setDownloadDir( cfg->m_3DLibsDownloadPath.empty() ? default_path : cfg->m_3DLibsDownloadPath );
79 
80  // Restore the Github 3D shapes libs url
81  wxString githubUrl = cfg->m_3DLibsUrl;
82 
83  if( githubUrl.IsEmpty() )
85 
86  SetGithubURL( githubUrl );
87 
88 
89  // Give the minimal size to the dialog, which allows displaying any page
90  wxSize minsize;
91 
92  for( unsigned ii = 0; ii < m_pages.size(); ii++ )
93  {
94  wxSize size = m_pages[ii]->GetSizer()->CalcMin();
95  minsize.x = std::max( minsize.x, size.x );
96  minsize.y = std::max( minsize.y, size.y );
97  }
98 
99  SetMinSize( minsize );
100  SetPageSize( minsize );
101  GetSizer()->SetSizeHints( this );
102  Center();
103 
106 
107  // When starting m_textCtrlGithubURL has the focus, and the text is selected,
108  // and not fully visible.
109  // Forcing deselection does not work, at least on W7 with wxWidgets 3.0.2
110  // So (and also because m_textCtrlGithubURL and m_downloadDir are rarely modified
111  // the focus is given to another widget.
112  m_hyperlinkGithubKicad->SetFocus();
113 
114  Connect( wxEVT_RADIOBUTTON, wxCommandEventHandler( WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnSourceCheck ), NULL, this );
115  Connect( wxEVT_CHECKLISTBOX, wxCommandEventHandler( WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnCheckGithubList ), NULL, this );
116 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
#define KISYS3DMOD
A variable name whose value holds the path of 3D shape files.
Definition: eda_3d_viewer.h:45
void OnCheckGithubList(wxCommandEvent &aEvent)
void updateGithubControls()
Enables Github widgets depending on the selected options.
#define NULL
void SetGithubURL(const wxString &aUrl)
Function SetGithubURL Sets the current Github repository URL used by the wizard.
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

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

◆ ~WIZARD_3DSHAPE_LIBS_DOWNLOADER()

WIZARD_3DSHAPE_LIBS_DOWNLOADER::~WIZARD_3DSHAPE_LIBS_DOWNLOADER ( )

Definition at line 119 of file wizard_3DShape_Libs_downloader.cpp.

120 {
121  auto cfg = Pgm().GetCommonSettings();
122 
123  cfg->m_3DLibsUrl = GetGithubURL().ToStdString();
124  cfg->m_3DLibsDownloadPath = getDownloadDir().ToStdString();
125 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
wxString getDownloadDir()
Gets the current target for downloaded libraries
wxString GetGithubURL() const
Function GetGithubURL Returns the current Github repository URL set in the wizard.

References getDownloadDir(), GetGithubURL(), and Pgm().

Member Function Documentation

◆ downloadGithubLibsFromList()

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

Saves a list of Github libraries locally.

Definition at line 348 of file wizard_3DShape_Libs_downloader.cpp.

350 {
351  // Display a progress bar to show the download state
352  // The title is updated for each downloaded library.
353  // the state will be updated by downloadOneLib() for each file.
354  // for OSX do not enable wPD_APP_MODAL, keep wxPD_AUTO_HIDE
355  wxProgressDialog pdlg( _( "Downloading 3D libraries" ), wxEmptyString,
356  aUrlList.GetCount(), this,
357 #ifndef __WXMAC__
358  wxPD_APP_MODAL |
359 #endif
360  wxPD_CAN_ABORT | 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( size_t 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 [%lu/%lu]" ),
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
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
#define _(s)
Definition: 3d_actions.cpp:33
wxString GetGithubURL() const
Function GetGithubURL Returns the current Github repository URL set in the wizard.

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

Referenced by OnWizardFinished().

◆ downloadOneLib()

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.

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 }
#define NULL
static bool filter3dshapesfiles(const wxString &aData)
#define _(s)
Definition: 3d_actions.cpp:33
GITHUB_GETLIBLIST implements a portion of pcbnew's PLUGIN interface to provide read only access to a ...

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

Referenced by downloadGithubLibsFromList().

◆ enableNext()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::enableNext ( bool  aEnable)
inlineprotected

Enables/disable 'Next' button

Definition at line 119 of file wizard_3DShape_Libs_downloader.h.

120  {
121  wxWindow* nextBtn = FindWindowById( wxID_FORWARD );
122 
123  if( nextBtn )
124  nextBtn->Enable( aEnable );
125  }

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

◆ filter3dshapesfiles()

static bool WIZARD_3DSHAPE_LIBS_DOWNLOADER::filter3dshapesfiles ( const wxString &  aData)
inlinestaticprotected

Definition at line 128 of file wizard_3DShape_Libs_downloader.h.

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  }

Referenced by downloadOneLib().

◆ filter3dshapeslibraries()

static bool WIZARD_3DSHAPE_LIBS_DOWNLOADER::filter3dshapeslibraries ( const wxString &  aData)
inlinestaticprotected

Definition at line 139 of file wizard_3DShape_Libs_downloader.h.

140  {
141  return aData.Contains( wxT( ".3dshapes" ) );
142  }

Referenced by getLibsListGithub().

◆ getDownloadDir()

wxString WIZARD_3DSHAPE_LIBS_DOWNLOADER::getDownloadDir ( )
inlineprotected

◆ GetFirstPage()

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.

42  {
43  return m_welcomeDlg;
44  }

References m_welcomeDlg.

Referenced by Invoke3DShapeLibsDownloaderWizard().

◆ GetGithubURL()

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.

51  {
52  return m_textCtrlGithubURL->GetValue();
53  }

References WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_textCtrlGithubURL.

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

◆ getLibsListGithub()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::getLibsListGithub ( wxArrayString &  aList)
protected

Downloads the list of Github libraries

Definition at line 326 of file wizard_3DShape_Libs_downloader.cpp.

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

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

Referenced by setupGithubList().

◆ OnBrowseButtonClick()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnBrowseButtonClick ( wxCommandEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 290 of file wizard_3DShape_Libs_downloader.cpp.

291 {
292  wxString path = getDownloadDir();
293 
294  path = wxDirSelector( _("Choose a folder to save the downloaded libraries" ),
295  path, 0, wxDefaultPosition, this );
296 
297  if( !path.IsEmpty() && wxDirExists( path ) )
298  {
299  setDownloadDir( path );
301  }
302 }
wxString getDownloadDir()
Gets the current target for downloaded libraries
void updateGithubControls()
Enables Github widgets depending on the selected options.
#define _(s)
Definition: 3d_actions.cpp:33
void setDownloadDir(const wxString &aDir)
Sets the target directory for libraries downloaded from Github

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

◆ OnChangeSearch()

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 239 of file wizard_3DShape_Libs_downloader.cpp.

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

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

◆ OnCheckGithubList()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnCheckGithubList ( wxCommandEvent &  aEvent)

Definition at line 141 of file wizard_3DShape_Libs_downloader.cpp.

142 {
143  wxArrayInt dummy;
144 
145  enableNext( m_checkList3Dlibnames->GetCheckedItems( dummy ) > 0 );
146 }
void enableNext(bool aEnable)
Enables/disable 'Next' button
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.

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

Referenced by WIZARD_3DSHAPE_LIBS_DOWNLOADER().

◆ OnCheckSaveCopy()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnCheckSaveCopy ( wxCommandEvent &  aEvent)

Definition at line 320 of file wizard_3DShape_Libs_downloader.cpp.

321 {
323 }
void updateGithubControls()
Enables Github widgets depending on the selected options.

References updateGithubControls().

◆ OnDefault3DPathButtonClick()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnDefault3DPathButtonClick ( wxCommandEvent &  event)
overridevirtual

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 305 of file wizard_3DShape_Libs_downloader.cpp.

306 {
307  wxString default_path;
308  wxGetEnv( KISYS3DMOD, &default_path );
309 
310  if( !default_path.IsEmpty() && wxDirExists( default_path ) )
311  {
312  setDownloadDir( default_path );
314  }
315  else
316  wxMessageBox( _( "KISYS3DMOD path not defined , or not existing" ) );
317 }
#define KISYS3DMOD
A variable name whose value holds the path of 3D shape files.
Definition: eda_3d_viewer.h:45
void updateGithubControls()
Enables Github widgets depending on the selected options.
#define _(s)
Definition: 3d_actions.cpp:33
void setDownloadDir(const wxString &aDir)
Sets the target directory for libraries downloaded from Github

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

◆ OnGridLibReviewSize()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnGridLibReviewSize ( wxSizeEvent &  event)
overridevirtual

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 155 of file wizard_3DShape_Libs_downloader.cpp.

156 {
157  // Adjust the width of the column 1 of m_gridLibReview (library names) to the
158  // max available width.
159  int gridwidth = m_gridLibReview->GetClientSize().x;
160  gridwidth -= m_gridLibReview->GetColSize( 0 ) + m_gridLibReview->GetColLabelSize();
161 
162  if( gridwidth < 200 )
163  gridwidth = 200;
164 
165  m_gridLibReview->SetColSize( 1, gridwidth );
166 
167  event.Skip();
168 }

References WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_gridLibReview.

◆ OnLocalFolderChange()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnLocalFolderChange ( wxCommandEvent &  event)
overridevirtual

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 562 of file wizard_3DShape_Libs_downloader.cpp.

563 {
565 }
void updateGithubControls()
Enables Github widgets depending on the selected options.

References updateGithubControls().

◆ OnPageChanged()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnPageChanged ( wxWizardEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 129 of file wizard_3DShape_Libs_downloader.cpp.

130 {
131  SetBitmap( KiBitmap( wizard_add_fplib_icon_xpm ) );
132  enableNext( true );
133 
134  if( GetCurrentPage() == m_githubListDlg )
135  setupGithubList();
136  else if( GetCurrentPage() == m_reviewDlg )
137  setupReview();
138 }
void enableNext(bool aEnable)
Enables/disable 'Next' button
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
const BITMAP_OPAQUE wizard_add_fplib_icon_xpm[1]

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

◆ OnPageChanging()

virtual void WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::OnPageChanging ( wxWizardEvent &  event)
inlineprotectedvirtualinherited

◆ OnSelectAll3Dlibs()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnSelectAll3Dlibs ( wxCommandEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 219 of file wizard_3DShape_Libs_downloader.cpp.

220 {
221  for( unsigned int i = 0; i < m_checkList3Dlibnames->GetCount(); ++i )
222  m_checkList3Dlibnames->Check( i, true );
223 
224  // The list might be empty, e.g. in case of download error
225  wxArrayInt dummy;
226  enableNext( m_checkList3Dlibnames->GetCheckedItems( dummy ) > 0 );
227 }
void enableNext(bool aEnable)
Enables/disable 'Next' button
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.

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

◆ OnSourceCheck()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnSourceCheck ( wxCommandEvent &  aEvent)

Definition at line 149 of file wizard_3DShape_Libs_downloader.cpp.

150 {
153 }
void updateGithubControls()
Enables Github widgets depending on the selected options.

References setupDialogOrder(), and updateGithubControls().

Referenced by WIZARD_3DSHAPE_LIBS_DOWNLOADER().

◆ OnUnselectAll3Dlibs()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnUnselectAll3Dlibs ( wxCommandEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 230 of file wizard_3DShape_Libs_downloader.cpp.

231 {
232  for( unsigned int i = 0; i < m_checkList3Dlibnames->GetCount(); ++i )
233  m_checkList3Dlibnames->Check( i, false );
234 
235  enableNext( false );
236 }
void enableNext(bool aEnable)
Enables/disable 'Next' button

References enableNext(), and WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_checkList3Dlibnames.

◆ OnWizardFinished()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnWizardFinished ( wxWizardEvent &  aEvent)
overridevirtual

Reimplemented from WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.

Definition at line 278 of file wizard_3DShape_Libs_downloader.cpp.

279 {
280  // we download a localy copy of the libraries
281  wxString error;
282 
283  if( !downloadGithubLibsFromList( m_libraries, &error ) )
284  {
285  DisplayError( this, error );
286  }
287 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:239
wxArrayString m_libraries
Libraries names selected in the wizard
bool downloadGithubLibsFromList(wxArrayString &aUrlList, wxString *aErrorMessage)
Saves a list of Github libraries locally.

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

◆ setDownloadDir()

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.

93  {
94  m_downloadDir->SetValue( aDir );
95  }

References WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_downloadDir.

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

◆ SetGithubURL()

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.

61  {
62  m_textCtrlGithubURL->SetValue( aUrl );
63  }

References WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_textCtrlGithubURL.

Referenced by WIZARD_3DSHAPE_LIBS_DOWNLOADER().

◆ setupDialogOrder()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::setupDialogOrder ( )
protected

◆ setupGithubList()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::setupGithubList ( )
protected

Definition at line 503 of file wizard_3DShape_Libs_downloader.cpp.

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 the text has changed or the list is empty
511  if( m_githubLibs.GetCount() == 0 || m_textCtrlGithubURL->IsModified() )
512  {
513  m_githubLibs.Clear();
515 
516  // Populate the list
517  m_checkList3Dlibnames->Clear();
518  for( unsigned int i = 0; i < m_githubLibs.GetCount(); ++i )
519  {
520  const wxString& lib = m_githubLibs[i].AfterLast( '/' );
521  m_checkList3Dlibnames->Append( lib );
522  }
523 
524  m_textCtrlGithubURL->SetModified( 0 );
525  }
526 
527  if( !m_checkList3Dlibnames->IsEmpty() )
528  m_checkList3Dlibnames->EnsureVisible( 0 );
529 
530  // Clear the search box
531  m_searchCtrl3Dlibs->Clear();
532 
533  // Clear the review list so it will be reloaded
534  m_libraries.clear();
535 }
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

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

Referenced by OnPageChanged().

◆ setupReview()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::setupReview ( )
protected

Definition at line 171 of file wizard_3DShape_Libs_downloader.cpp.

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

References _, 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().

◆ updateGithubControls()

void WIZARD_3DSHAPE_LIBS_DOWNLOADER::updateGithubControls ( )
protected

Enables Github widgets depending on the selected options.

Definition at line 538 of file wizard_3DShape_Libs_downloader.cpp.

539 {
540  bool valid = wxFileName::IsDirWritable( getDownloadDir() );
541 
542  // Shows or not the warning text if the target 3d folder does not exist, or is not
543  // writable.
544  m_invalidDirWarningText->Show( !valid );
545  m_bitmapDirWarn->Show( !valid );
546 
547  // If the dialog starts with m_invalidDirWarningText and m_bitmapDirWarn not shown
548  // the size and position of the sizer containing these widgets can be incorrect,
549  // until a wxSizeEvent is fired, and the widgets are not shown, or truncated,
550  // at least on Windows. So fire a dummy wxSizeEvent if the size looks bad
551  if( m_invalidDirWarningText->IsShown() && m_invalidDirWarningText->GetSize().x < 2 )
552  {
553  wxSizeEvent event( GetSize() );
554  wxPostEvent( this, event );
555  }
556 
557  // Allow to go further only if there is a valid target directory selected
558  enableNext( valid );
559 }
wxString getDownloadDir()
Gets the current target for downloaded libraries
void enableNext(bool aEnable)
Enables/disable 'Next' button

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

Member Data Documentation

◆ m_bitmapDirWarn

wxStaticBitmap* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_bitmapDirWarn
protectedinherited

◆ m_bitmapRepo

wxStaticBitmap* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_bitmapRepo
protectedinherited

◆ m_btnBrowse

wxButton* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_btnBrowse
protectedinherited

◆ m_btnSelectAll3Dlibs

wxButton* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_btnSelectAll3Dlibs
protectedinherited

◆ m_btnUnselectAll3Dlibs

wxButton* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_btnUnselectAll3Dlibs
protectedinherited

◆ m_buttonDefault3DPath

wxButton* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_buttonDefault3DPath
protectedinherited

◆ m_checkList3Dlibnames

wxCheckListBox* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_checkList3Dlibnames
protectedinherited

◆ m_downloadDir

◆ m_githubLibs

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

◆ m_githubListDlg

wxWizardPageSimple* WIZARD_3DSHAPE_LIBS_DOWNLOADER::m_githubListDlg
protected

◆ m_gridLibReview

◆ m_hyperlinkGithubKicad

wxHyperlinkCtrl* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_hyperlinkGithubKicad
protectedinherited

◆ m_invalidDirWarningText

wxStaticText* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_invalidDirWarningText
protectedinherited

◆ m_libraries

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

◆ m_LocalFolderInfo

wxStaticText* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_LocalFolderInfo
protectedinherited

◆ m_pages

◆ m_reviewDlg

wxWizardPageSimple* WIZARD_3DSHAPE_LIBS_DOWNLOADER::m_reviewDlg
protected

◆ m_searchCtrl3Dlibs

◆ m_staticText112

wxStaticText* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_staticText112
protectedinherited

◆ m_staticText12

wxStaticText* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_staticText12
protectedinherited

◆ m_staticText8

wxStaticText* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_staticText8
protectedinherited

◆ m_staticText9

wxStaticText* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_staticText9
protectedinherited

◆ m_staticTextlocalfolder

wxStaticText* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_staticTextlocalfolder
protectedinherited

◆ m_staticTextWelcome

wxStaticText* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_staticTextWelcome
protectedinherited

◆ m_textCtrlGithubURL

wxTextCtrl* WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE::m_textCtrlGithubURL
protectedinherited

◆ m_welcomeDlg

wxWizardPageSimple* WIZARD_3DSHAPE_LIBS_DOWNLOADER::m_welcomeDlg
protected

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