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 
75  void OnChangeSearch( wxCommandEvent& aEvent ) override;
76 
77  void OnWizardFinished( wxWizardEvent& aEvent ) override;
78  void OnBrowseButtonClick( wxCommandEvent& aEvent ) override;
79  void OnCheckSaveCopy( wxCommandEvent& aEvent );
80  void OnDefault3DPathButtonClick( wxCommandEvent& event ) override;
81  void OnGridLibReviewSize( wxSizeEvent& event ) override;
82  void OnLocalFolderChange( wxCommandEvent& event ) override;
83 
84 protected:
85  // Initialization of wizard pages
86  void setupDialogOrder();
87  void setupGithubList(); // Prepare the second page
88  // (list of available .3dshapes libraries on github)
89  void setupReview(); // Prepare the last page
90 
92  void setDownloadDir( const wxString& aDir )
93  {
94  m_downloadDir->SetValue( aDir );
95  }
96 
98  inline wxString getDownloadDir()
99  {
100  return m_downloadDir->GetValue();
101  }
102 
104  void getLibsListGithub( wxArrayString& aList );
105 
107  bool downloadGithubLibsFromList( wxArrayString& aUrlList, wxString* aErrorMessage );
108 
110  bool downloadOneLib( const wxString& aLibURL,
111  const wxString& aLocalLibName,
112  wxProgressDialog * aIndicator,
113  wxString* aErrorMessage );
114 
116  void updateGithubControls();
117 
119  inline void enableNext( bool aEnable )
120  {
121  wxWindow* nextBtn = FindWindowById( wxID_FORWARD );
122 
123  if( nextBtn )
124  nextBtn->Enable( aEnable );
125  }
126 
127  // A callback function to filter 3D filenames
128  static bool filter3dshapesfiles( const wxString& aData )
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  }
137 
138  // A callback function to filter 3D folders names
139  static bool filter3dshapeslibraries( const wxString& aData )
140  {
141  return aData.Contains( wxT( ".3dshapes" ) );
142  }
143 
145  wxArrayString m_githubLibs;
146 
148  wxArrayString m_libraries;
149 
150  // Aliases for wizard pages to make code more readable
151  wxWizardPageSimple* m_welcomeDlg;
152  wxWizardPageSimple* m_githubListDlg;
153  wxWizardPageSimple* m_reviewDlg;
154 };
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:120
bool downloadGithubLibsFromList(wxArrayString &aUrlList, wxString *aErrorMessage)
Saves a list of Github libraries locally.
void OnUnselectAll3Dlibs(wxCommandEvent &aEvent) override
void OnChangeSearch(wxCommandEvent &aEvent) override
Called when the content of m_searchCtrl3Dlibs has changed.
void OnBrowseButtonClick(wxCommandEvent &aEvent) override
wxWizardPage * GetFirstPage() const
Function GetFirstPage Returns the welcoming page for the wizard.
wxArrayString m_githubLibs
Cache for the downloaded Github library list
wxString getDownloadDir()
Gets the current target for downloaded libraries
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)
wxString GetGithubURL() const
Function GetGithubURL Returns the current Github repository URL set in the wizard.
void setDownloadDir(const wxString &aDir)
Sets the target directory for libraries downloaded from Github
void OnDefault3DPathButtonClick(wxCommandEvent &event) override