KiCad PCB EDA Suite
wizard_3DShape_Libs_downloader.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015 CERN
5  * Code derived from "wizard_add_fplib.h" (from Maciej Suminski <maciej.suminski@cern.ch>)
6  * Copyright (C) 2014-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
7  * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
28 
29 class KIWAY_PLAYER;
30 
32 {
33 public:
34  WIZARD_3DSHAPE_LIBS_DOWNLOADER( wxWindow* aParent );
36 
41  inline wxWizardPage* GetFirstPage() const
42  {
43  return m_welcomeDlg;
44  }
45 
50  inline wxString GetGithubURL() const
51  {
52  return m_textCtrlGithubURL->GetValue();
53  }
54 
60  inline void SetGithubURL( const wxString& aUrl )
61  {
62  m_textCtrlGithubURL->SetValue( aUrl );
63  }
64 
65  // Wizard event handlers
66  void OnSourceCheck( wxCommandEvent& aEvent );
67  void OnCheckGithubList( wxCommandEvent& aEvent );
68  void OnPageChanged( wxWizardEvent& aEvent ) override;
69  void OnSelectAll3Dlibs( wxCommandEvent& aEvent ) override;
70  void OnUnselectAll3Dlibs( wxCommandEvent& aEvent ) override;
71  void OnChangeSearch( wxCommandEvent& aEvent ) override;
72  void OnWizardFinished( wxWizardEvent& aEvent ) override;
73  void OnBrowseButtonClick( wxCommandEvent& aEvent ) override;
74  void OnCheckSaveCopy( wxCommandEvent& aEvent );
75  void OnDefault3DPathButtonClick( wxCommandEvent& event ) override;
76  void OnGridLibReviewSize( wxSizeEvent& event ) override;
77  void OnLocalFolderChange( wxCommandEvent& event ) override;
78 
79 protected:
80  // Initialization of wizard pages
81  void setupDialogOrder();
82  void setupGithubList(); // Prepare the second page
83  // (list of available .3dshapes libraries on github)
84  void setupReview(); // Prepare the last page
85 
87  void setDownloadDir( const wxString& aDir )
88  {
89  m_downloadDir->SetValue( aDir );
90  }
91 
93  inline wxString getDownloadDir()
94  {
95  return m_downloadDir->GetValue();
96  }
97 
99  void getLibsListGithub( wxArrayString& aList );
100 
102  bool downloadGithubLibsFromList( wxArrayString& aUrlList, wxString* aErrorMessage );
103 
105  bool downloadOneLib( const wxString& aLibURL,
106  const wxString& aLocalLibName,
107  wxProgressDialog * aIndicator,
108  wxString* aErrorMessage );
109 
111  void updateGithubControls();
112 
114  inline void enableNext( bool aEnable )
115  {
116  wxWindow* nextBtn = FindWindowById( wxID_FORWARD );
117 
118  if( nextBtn )
119  nextBtn->Enable( aEnable );
120  }
121 
122  // A callback function to filter 3D filenames
123  static bool filter3dshapesfiles( const wxString& aData )
124  {
125  return aData.Contains( wxT( ".wrl" ) ) || aData.Contains( wxT( ".wings" ) );
126  }
127 
128  // A callback function to filter 3D folders names
129  static bool filter3dshapeslibraries( const wxString& aData )
130  {
131  return aData.Contains( wxT( ".3dshapes" ) );
132  }
133 
135  wxArrayString m_githubLibs;
136 
138  wxArrayString m_libraries;
139 
140  // Aliases for wizard pages to make code more readable
141  wxWizardPageSimple* m_welcomeDlg;
142  wxWizardPageSimple* m_githubListDlg;
143  wxWizardPageSimple* m_reviewDlg;
144 };
wxArrayString m_libraries
Libraries names selected in the wizard
void OnWizardFinished(wxWizardEvent &aEvent) override
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:111
bool downloadGithubLibsFromList(wxArrayString &aUrlList, wxString *aErrorMessage)
Saves a list of Github libraries locally.
void OnUnselectAll3Dlibs(wxCommandEvent &aEvent) override
void OnChangeSearch(wxCommandEvent &aEvent) override
void OnBrowseButtonClick(wxCommandEvent &aEvent) override
wxArrayString m_githubLibs
Cache for the downloaded Github library list
wxWizardPage * GetFirstPage() const
Function GetFirstPage Returns the welcoming page for the wizard.
wxString getDownloadDir()
Gets the current target for downloaded libraries
wxString GetGithubURL() const
Function GetGithubURL Returns the current Github repository URL set in the wizard.
void OnCheckGithubList(wxCommandEvent &aEvent)
void updateGithubControls()
Enables Github widgets depending on the selected options.
void enableNext(bool aEnable)
Enables/disable 'Next' button
void getLibsListGithub(wxArrayString &aList)
Downloads the list of Github libraries
void OnSelectAll3Dlibs(wxCommandEvent &aEvent) override
static bool filter3dshapesfiles(const wxString &aData)
void OnGridLibReviewSize(wxSizeEvent &event) override
bool downloadOneLib(const wxString &aLibURL, const wxString &aLocalLibName, wxProgressDialog *aIndicator, wxString *aErrorMessage)
Saves a Github library aLibURL locally in aLocalLibName.
Class WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE.
void OnLocalFolderChange(wxCommandEvent &event) override
void SetGithubURL(const wxString &aUrl)
Function SetGithubURL Sets the current Github repository URL used by the wizard.
void OnPageChanged(wxWizardEvent &aEvent) override
static bool filter3dshapeslibraries(const wxString &aData)
void setDownloadDir(const wxString &aDir)
Sets the target directory for libraries downloaded from Github
void OnDefault3DPathButtonClick(wxCommandEvent &event) override