KiCad PCB EDA Suite
wizard_add_fplib.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  * @author 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 
27 #include <wizard_add_fplib_base.h>
28 #include <io_mgr.h>
29 #include <boost/optional.hpp>
30 
31 class KIWAY_PLAYER;
32 
34 {
35 public:
36  WIZARD_FPLIB_TABLE( wxWindow* aParent );
38 
40  enum LIB_SOURCE { LOCAL, GITHUB };
41 
43  enum LIB_SCOPE { GLOBAL = 1, PROJECT = 2 };
44 
49  inline wxWizardPage* GetFirstPage() const
50  {
51  return m_welcomeDlg;
52  }
53 
58  inline wxString GetGithubURL() const
59  {
60  return m_textCtrlGithubURL->GetValue();
61  }
62 
68  inline void SetGithubURL( const wxString& aUrl )
69  {
70  m_textCtrlGithubURL->SetValue( aUrl );
71  }
72 
77  LIB_SOURCE GetLibSource() const;
78 
83  LIB_SCOPE GetLibScope() const;
84 
85  // Wizard event handlers
86  void OnSourceCheck( wxCommandEvent& aEvent );
87  void OnSelectFiles( wxCommandEvent& aEvent );
88  void OnCheckGithubList( wxCommandEvent& aEvent );
89  void OnPageChanged( wxWizardEvent& aEvent ) override;
90  void OnSelectAllGH( wxCommandEvent& aEvent ) override;
91  void OnUnselectAllGH( wxCommandEvent& aEvent ) override;
92  void OnChangeSearch( wxCommandEvent& aEvent ) override;
93  void OnWizardFinished( wxWizardEvent& aEvent ) override;
94  void OnBrowseButtonClick( wxCommandEvent& aEvent ) override;
95  void OnCheckSaveCopy( wxCommandEvent& aEvent ) override;
96 
97  class LIBRARY
98  {
99  public:
100  LIBRARY( const wxString& aPath, const wxString& aDescription = wxEmptyString );
102  {
103  }
104 
107 
113  bool Test();
114 
121  {
122  return m_plugin;
123  }
124 
129  wxString GetPluginName() const;
130 
135  inline const wxString& GetAbsolutePath() const
136  {
137  return m_path;
138  }
139 
147  wxString GetRelativePath( const wxString& aBase, const wxString& aSubstitution = wxEmptyString ) const;
148 
157  wxString GetAutoPath( LIB_SCOPE aScope ) const;
158 
164  wxString GetDescription() const;
165 
172  {
173  return m_status;
174  }
175 
176  protected:
177  inline void setPath( const wxString& aPath )
178  {
179  m_path = aPath;
180  }
181 
182  inline void setPluginType( IO_MGR::PCB_FILE_T aType )
183  {
184  m_plugin = aType;
185  }
186 
193  wxString replaceEnv( const wxString& aEnvVar, bool aFilePath = true ) const;
194 
195  wxString m_path;
196  wxString m_description;
199 
200  friend class WIZARD_FPLIB_TABLE;
201  };
202 
207  const std::vector<LIBRARY>& GetLibraries() const
208  {
209  return m_libraries;
210  }
211 
212 
213 protected:
214  // Initialization of wizard pages
215  void setupDialogOrder();
216  void setupGithubList();
217  void setupFileSelect();
218  void setupReview();
219 
221  bool checkFiles() const;
222 
224  void setDownloadDir( const wxString& aDir )
225  {
226  m_downloadDir->SetLabel( aDir );
227  }
228 
230  inline wxString getDownloadDir()
231  {
232  return m_downloadDir->GetLabel();
233  }
234 
236  void getLibsListGithub( wxArrayString& aList );
237 
239  bool downloadGithubLibsFromList( wxArrayString& aUrlList, wxString* aErrorMessage );
240 
242  inline bool wantLocalCopy() const { return m_downloadGithub->GetValue(); }
243 
245  void updateGithubControls();
246 
248  void updateLibraries();
249 
251  inline void enableNext( bool aEnable )
252  {
253  wxWindow* nextBtn = FindWindowById( wxID_FORWARD );
254 
255  if( nextBtn )
256  nextBtn->Enable( aEnable );
257  }
258 
260  wxArrayString m_githubLibs;
261 
263  std::vector<LIBRARY> m_libraries;
264 
265  // Aliases for wizard pages to make code more readable
266  wxWizardPageSimple* const m_welcomeDlg;
267  wxWizardPageSimple* const m_fileSelectDlg;
268  wxWizardPageSimple* const m_githubListDlg;
269  wxWizardPageSimple* const m_reviewDlg;
270  wxWizardPageSimple* const m_targetDlg;
271 
272  // Since the same event is used for changing the selection/filter type, we need a way to
273  // determine what's the real cause of the event. Therefore here we store the number of the
274  // selected file type filter.
276 
277  // path to the most recently used download directory from Github.
279 };
boost::optional< IO_MGR::PCB_FILE_T > m_plugin
wxString GetGithubURL() const
Function GetGithubURL Returns the current Github repository URL set in the wizard.
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:111
void setPath(const wxString &aPath)
Class PROJECT holds project specific data.
Definition: project.h:51
wxWizardPageSimple *const m_fileSelectDlg
void OnUnselectAllGH(wxCommandEvent &aEvent) override
wxWizardPageSimple *const m_reviewDlg
Class WIZARD_FPLIB_TABLE_BASE.
LIB_SCOPE GetLibScope() const
Function GetLibScope Returns the scope for the added libraries (global / project specific).
wxString GetPluginName() const
Function GetPluginName Returns the plugin name, as used in the FPLIB table editor.
void OnCheckGithubList(wxCommandEvent &aEvent)
void enableNext(bool aEnable)
Enables/disable 'Next' button
const wxString & GetAbsolutePath() const
Function GetAbsolutePath Returns the absolute path for the library.
wxString GetAutoPath(LIB_SCOPE aScope) const
Function GetAutoPath Returns path that is either absolute or related to KISYSMOD/KIPRJMOD if the file...
wxArrayString m_githubLibs
Cache for the downloaded Github library list
wxString GetDescription() const
Function GetDescription Returns the description for the library.
wxWizardPageSimple *const m_githubListDlg
boost::optional< IO_MGR::PCB_FILE_T > GetPluginType() const
Function GetPluginType Returns the plugin type, autodetected basing on the path.
bool downloadGithubLibsFromList(wxArrayString &aUrlList, wxString *aErrorMessage)
Saves a list of Github libraries locally.
STATUS GetStatus() const
Function GetStatus Returns the validity status for the library.
wxWizardPageSimple *const m_targetDlg
void OnSelectAllGH(wxCommandEvent &aEvent) override
void OnWizardFinished(wxWizardEvent &aEvent) override
LIB_SOURCE GetLibSource() const
Function GetLibSource Returns the source of libraries (local / Github).
void getLibsListGithub(wxArrayString &aList)
Downloads the list of Github libraries
bool wantLocalCopy() const
Does the user want a local copy of Github libraries?
void updateLibraries()
Updates m_libraries basing on dialogs contents
wxString replaceEnv(const wxString &aEnvVar, bool aFilePath=true) const
Function replaceEnv replaces path with environmental variable if applicable.
bool checkFiles() const
Checks the selection in file picker
LIB_SCOPE
Scope (global/project)
void setPluginType(IO_MGR::PCB_FILE_T aType)
const std::vector< LIBRARY > & GetLibraries() const
Function GetLibraries Returns libraries selected by the user.
std::vector< LIBRARY > m_libraries
Libraries selected in the wizard
LIBRARY(const wxString &aPath, const wxString &aDescription=wxEmptyString)
STATUS
Possible states of validation.
void OnPageChanged(wxWizardEvent &aEvent) override
void setDownloadDir(const wxString &aDir)
Sets the target directory for libraries downloaded from Github
void OnCheckSaveCopy(wxCommandEvent &aEvent) override
void SetGithubURL(const wxString &aUrl)
Function SetGithubURL Sets the current Github repository URL used by the wizard.
WIZARD_FPLIB_TABLE(wxWindow *aParent)
wxWizardPageSimple *const m_welcomeDlg
wxWizardPage * GetFirstPage() const
Function GetFirstPage Returns the welcoming page for the wizard.
void OnSelectFiles(wxCommandEvent &aEvent)
void OnChangeSearch(wxCommandEvent &aEvent) override
wxString m_lastGithubDownloadDirectory
bool Test()
Function Test Uses the associated plugin to validate the library contents.
wxString getDownloadDir()
Gets the current target for downloaded libraries
LIB_SOURCE
Source of the libraries (local files or Github)
void OnSourceCheck(wxCommandEvent &aEvent)
wxString GetRelativePath(const wxString &aBase, const wxString &aSubstitution=wxEmptyString) const
Function GetRelativePath Returns the relative path, based on the input path with the base part replac...
PCB_FILE_T
Enum PCB_FILE_T is a set of file types that the IO_MGR knows about, and for which there has been a pl...
Definition: io_mgr.h:51
void OnBrowseButtonClick(wxCommandEvent &aEvent) override
void updateGithubControls()
Enables Github widgets depending on the selected options.