You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
5.3 KiB

  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. #include <wizard_3DShape_Libs_downloader_base.h>
  27. class KIWAY_PLAYER;
  28. class WIZARD_3DSHAPE_LIBS_DOWNLOADER : public WIZARD_3DSHAPE_LIBS_DOWNLOADER_BASE
  29. {
  30. public:
  31. WIZARD_3DSHAPE_LIBS_DOWNLOADER( wxWindow* aParent );
  32. ~WIZARD_3DSHAPE_LIBS_DOWNLOADER();
  33. /**
  34. * Function GetFirstPage
  35. * Returns the welcoming page for the wizard.
  36. */
  37. inline wxWizardPage* GetFirstPage() const
  38. {
  39. return m_welcomeDlg;
  40. }
  41. /**
  42. * Function GetGithubURL
  43. * Returns the current Github repository URL set in the wizard.
  44. */
  45. inline wxString GetGithubURL() const
  46. {
  47. return m_textCtrlGithubURL->GetValue();
  48. }
  49. /**
  50. * Function SetGithubURL
  51. * Sets the current Github repository URL used by the wizard.
  52. * @param aUrl is the new URL to be applied.
  53. */
  54. inline void SetGithubURL( const wxString& aUrl )
  55. {
  56. m_textCtrlGithubURL->SetValue( aUrl );
  57. }
  58. // Wizard event handlers
  59. void OnSourceCheck( wxCommandEvent& aEvent );
  60. void OnCheckGithubList( wxCommandEvent& aEvent );
  61. void OnPageChanged( wxWizardEvent& aEvent ) override;
  62. void OnSelectAll3Dlibs( wxCommandEvent& aEvent ) override;
  63. void OnUnselectAll3Dlibs( wxCommandEvent& aEvent ) override;
  64. /** Called when the content of m_searchCtrl3Dlibs has changed.
  65. * Rebuild the list of libraries, lib cacdidate first
  66. */
  67. void OnChangeSearch( wxCommandEvent& aEvent ) override;
  68. void OnWizardFinished( wxWizardEvent& aEvent ) override;
  69. void OnBrowseButtonClick( wxCommandEvent& aEvent ) override;
  70. void OnCheckSaveCopy( wxCommandEvent& aEvent );
  71. void OnDefault3DPathButtonClick( wxCommandEvent& event ) override;
  72. void OnGridLibReviewSize( wxSizeEvent& event ) override;
  73. void OnLocalFolderChange( wxCommandEvent& event ) override;
  74. protected:
  75. // Initialization of wizard pages
  76. void setupDialogOrder();
  77. void setupGithubList(); // Prepare the second page
  78. // (list of available .3dshapes libraries on github)
  79. void setupReview(); // Prepare the last page
  80. ///> Sets the target directory for libraries downloaded from Github
  81. void setDownloadDir( const wxString& aDir )
  82. {
  83. m_downloadDir->SetValue( aDir );
  84. }
  85. ///> Gets the current target for downloaded libraries
  86. inline wxString getDownloadDir()
  87. {
  88. return m_downloadDir->GetValue();
  89. }
  90. ///> Downloads the list of Github libraries
  91. void getLibsListGithub( wxArrayString& aList );
  92. ///> Saves a list of Github libraries locally.
  93. bool downloadGithubLibsFromList( wxArrayString& aUrlList, wxString* aErrorMessage );
  94. ///> Saves a Github library aLibURL locally in aLocalLibName.
  95. bool downloadOneLib( const wxString& aLibURL,
  96. const wxString& aLocalLibName,
  97. wxProgressDialog * aIndicator,
  98. wxString* aErrorMessage );
  99. ///> Enables Github widgets depending on the selected options.
  100. void updateGithubControls();
  101. ///> Enables/disable 'Next' button
  102. inline void enableNext( bool aEnable )
  103. {
  104. wxWindow* nextBtn = FindWindowById( wxID_FORWARD );
  105. if( nextBtn )
  106. nextBtn->Enable( aEnable );
  107. }
  108. // A callback function to filter 3D filenames
  109. static bool filter3dshapesfiles( const wxString& aData )
  110. {
  111. return aData.Contains( wxT( ".wrl" ) ) ||
  112. aData.Contains( wxT( ".wings" ) ) ||
  113. aData.Contains( wxT( ".stp" ) ) ||
  114. aData.Contains( wxT( ".step" ) ) ||
  115. aData.Contains( wxT( ".STP" ) ) ||
  116. aData.Contains( wxT( ".STEP" ) );
  117. }
  118. // A callback function to filter 3D folders names
  119. static bool filter3dshapeslibraries( const wxString& aData )
  120. {
  121. return aData.Contains( wxT( ".3dshapes" ) );
  122. }
  123. ///> Cache for the downloaded Github library list
  124. wxArrayString m_githubLibs;
  125. ///> Libraries names selected in the wizard
  126. wxArrayString m_libraries;
  127. // Aliases for wizard pages to make code more readable
  128. wxWizardPageSimple* m_welcomeDlg;
  129. wxWizardPageSimple* m_githubListDlg;
  130. wxWizardPageSimple* m_reviewDlg;
  131. };