kicad/pcbnew/dialogs/wizard_add_fplib.h

280 lines
8.9 KiB
C
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
2015-03-30 16:42:39 +00:00
* Copyright (C) 2015 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch>
* Copyright (C) 2014-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <wizard_add_fplib_base.h>
2015-03-30 16:42:39 +00:00
#include <io_mgr.h>
#include <boost/optional.hpp>
2015-03-30 16:42:39 +00:00
class KIWAY_PLAYER;
class WIZARD_FPLIB_TABLE : public WIZARD_FPLIB_TABLE_BASE
{
public:
2015-03-30 16:42:39 +00:00
WIZARD_FPLIB_TABLE( wxWindow* aParent );
~WIZARD_FPLIB_TABLE();
2015-03-30 16:42:39 +00:00
///> Source of the libraries (local files or Github)
enum LIB_SOURCE { LOCAL, GITHUB };
///> Scope (global/project)
enum LIB_SCOPE { GLOBAL = 1, PROJECT = 2 };
/**
2015-03-30 16:42:39 +00:00
* Function GetFirstPage
* Returns the welcoming page for the wizard.
*/
2015-03-30 16:42:39 +00:00
inline wxWizardPage* GetFirstPage() const
{
2015-03-30 16:42:39 +00:00
return m_welcomeDlg;
}
2015-03-30 16:42:39 +00:00
/**
* Function GetGithubURL
* Returns the current Github repository URL set in the wizard.
*/
2015-03-30 16:42:39 +00:00
inline wxString GetGithubURL() const
{
return m_textCtrlGithubURL->GetValue();
}
2015-03-30 16:42:39 +00:00
/**
* Function SetGithubURL
* Sets the current Github repository URL used by the wizard.
* @param aUrl is the new URL to be applied.
*/
2015-03-30 16:42:39 +00:00
inline void SetGithubURL( const wxString& aUrl )
{
m_textCtrlGithubURL->SetValue( aUrl );
}
2015-03-30 16:42:39 +00:00
/**
* Function GetLibSource
* Returns the source of libraries (local / Github).
*/
2015-03-30 16:42:39 +00:00
LIB_SOURCE GetLibSource() const;
/**
2015-03-30 16:42:39 +00:00
* Function GetLibScope
* Returns the scope for the added libraries (global / project specific).
*/
2015-03-30 16:42:39 +00:00
LIB_SCOPE GetLibScope() const;
// Wizard event handlers
void OnSourceCheck( wxCommandEvent& aEvent );
void OnSelectFiles( wxCommandEvent& aEvent );
void OnCheckGithubList( wxCommandEvent& aEvent );
2016-09-24 18:53:15 +00:00
void OnPageChanged( wxWizardEvent& aEvent ) override;
void OnSelectAllGH( wxCommandEvent& aEvent ) override;
void OnUnselectAllGH( wxCommandEvent& aEvent ) override;
void OnChangeSearch( wxCommandEvent& aEvent ) override;
void OnWizardFinished( wxWizardEvent& aEvent ) override;
void OnBrowseButtonClick( wxCommandEvent& aEvent ) override;
void OnCheckSaveCopy( wxCommandEvent& aEvent ) override;
2015-03-30 16:42:39 +00:00
class LIBRARY
{
public:
LIBRARY( const wxString& aPath, const wxString& aDescription = wxEmptyString );
~LIBRARY()
{
}
///> Possible states of validation.
enum STATUS { OK, INVALID, NOT_CHECKED };
/**
* Function Test
* Uses the associated plugin to validate the library contents.
* @return True if the library and the matched plugin type are valid.
*/
bool Test();
/**
* Function GetPluginType
* Returns the plugin type, autodetected basing on the path.
* @return Returns empty boost::optional if the type could not be autodetected.
*/
inline boost::optional<IO_MGR::PCB_FILE_T> GetPluginType() const
{
return m_plugin;
}
/**
* Function GetPluginName
* Returns the plugin name, as used in the FPLIB table editor.
*/
wxString GetPluginName() const;
/**
* Function GetAbsolutePath
* Returns the absolute path for the library.
*/
inline const wxString& GetAbsolutePath() const
{
return m_path;
}
/**
* Function GetRelativePath
* Returns the relative path, based on the input path with the base part replaced.
* @param aBase is the base for the relative path.
* @param aSubstitution is the string to be replace the base path.
* @return Adjusted path if possible, or the absolute path when it is not possible.
*/
wxString GetRelativePath( const wxString& aBase, const wxString& aSubstitution = wxEmptyString ) const;
/**
* Function GetAutoPath
* Returns path that is either absolute or related to KISYSMOD/KIPRJMOD if the files
* are stored within one of the mentioned paths.
* @param aScoep is the scope for the library. It determines the environmental variables
* that are used to check the path (GLOBAL scope checks only KISYSMOD, while PROJECT
* scope checks both KISYSMOD & KIPRJMOD).
*/
wxString GetAutoPath( LIB_SCOPE aScope ) const;
/**
* Function GetDescription
* Returns the description for the library. If it is not specified in the constructor,
* it is just the filename.
*/
wxString GetDescription() const;
/**
* Function GetStatus
* Returns the validity status for the library. It requires running Test() before, to get
* a result different than NOT_CHECKED.
*/
STATUS GetStatus() const
{
return m_status;
}
protected:
inline void setPath( const wxString& aPath )
{
m_path = aPath;
}
inline void setPluginType( IO_MGR::PCB_FILE_T aType )
{
m_plugin = aType;
}
/**
* Function replaceEnv
* replaces path with environmental variable if applicable.
* @param aEnvVar is the environmental variable that should be substituted.
* @param aFilePath determines if the path is a file path (contrary to e.g. http address).
*/
wxString replaceEnv( const wxString& aEnvVar, bool aFilePath = true ) const;
wxString m_path;
wxString m_description;
boost::optional<IO_MGR::PCB_FILE_T> m_plugin;
STATUS m_status;
friend class WIZARD_FPLIB_TABLE;
};
2015-03-30 16:42:39 +00:00
/**
* Function GetLibraries
* Returns libraries selected by the user.
*/
const std::vector<LIBRARY>& GetLibraries() const
{
2015-03-30 16:42:39 +00:00
return m_libraries;
}
2015-03-30 16:42:39 +00:00
protected:
// Initialization of wizard pages
void setupDialogOrder();
void setupGithubList();
void setupFileSelect();
void setupReview();
///> Checks the selection in file picker
bool checkFiles() const;
///> Sets the target directory for libraries downloaded from Github
void setDownloadDir( const wxString& aDir )
{
2015-03-30 16:42:39 +00:00
m_downloadDir->SetLabel( aDir );
}
2015-03-30 16:42:39 +00:00
///> Gets the current target for downloaded libraries
inline wxString getDownloadDir()
{
return m_downloadDir->GetLabel();
}
2015-03-30 16:42:39 +00:00
///> Downloads the list of Github libraries
void getLibsListGithub( wxArrayString& aList );
2015-03-30 16:42:39 +00:00
///> Saves a list of Github libraries locally.
bool downloadGithubLibsFromList( wxArrayString& aUrlList, wxString* aErrorMessage );
2015-03-30 16:42:39 +00:00
///> Does the user want a local copy of Github libraries?
inline bool wantLocalCopy() const { return m_downloadGithub->GetValue(); }
2015-03-30 16:42:39 +00:00
///> Enables Github widgets depending on the selected options.
void updateGithubControls();
2015-03-30 16:42:39 +00:00
///> Updates m_libraries basing on dialogs contents
void updateLibraries();
2015-03-30 16:42:39 +00:00
///> Enables/disable 'Next' button
inline void enableNext( bool aEnable )
{
2015-03-30 16:42:39 +00:00
wxWindow* nextBtn = FindWindowById( wxID_FORWARD );
2015-03-30 16:42:39 +00:00
if( nextBtn )
nextBtn->Enable( aEnable );
}
2015-03-30 16:42:39 +00:00
///> Cache for the downloaded Github library list
wxArrayString m_githubLibs;
2015-03-30 16:42:39 +00:00
///> Libraries selected in the wizard
std::vector<LIBRARY> m_libraries;
2015-03-30 16:42:39 +00:00
// Aliases for wizard pages to make code more readable
wxWizardPageSimple* const m_welcomeDlg;
wxWizardPageSimple* const m_fileSelectDlg;
wxWizardPageSimple* const m_githubListDlg;
wxWizardPageSimple* const m_reviewDlg;
wxWizardPageSimple* const m_targetDlg;
2015-03-30 16:42:39 +00:00
// Since the same event is used for changing the selection/filter type, we need a way to
// determine what's the real cause of the event. Therefore here we store the number of the
// selected file type filter.
int m_selectedFilter;
// path to the most recently used download directory from Github.
wxString m_lastGithubDownloadDirectory;
};