KiCad PCB EDA Suite
github_plugin.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) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
5  * Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef GITHUB_PLUGIN_H_
26 #define GITHUB_PLUGIN_H_
27 
28 #include <kicad_plugin.h>
29 
30 struct GH_CACHE;
31 
32 
162 class GITHUB_PLUGIN : public PCB_IO
163 {
164 public:
165  //-----<PLUGIN API>----------------------------------------------------------
166  const wxString PluginName() const override;
167 
168  const wxString GetFileExtension() const override;
169 
170  void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
171  const PROPERTIES* aProperties = NULL ) override;
172 
173  void PrefetchLib( const wxString& aLibraryPath,
174  const PROPERTIES* aProperties = NULL ) override;
175 
176  MODULE* FootprintLoad( const wxString& aLibraryPath,
177  const wxString& aFootprintName, const PROPERTIES* aProperties ) override;
178 
179  void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint,
180  const PROPERTIES* aProperties = NULL ) override;
181 
182  void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
183  const PROPERTIES* aProperties = NULL ) override;
184 
185  bool IsFootprintLibWritable( const wxString& aLibraryPath ) override;
186 
187  long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override;
188 
189  void FootprintLibOptions( PROPERTIES* aListToAppendTo ) const override;
190 
191  // Since I derive from PCB_IO, I have to implement this, else I'd inherit his, which is bad since
192  // my lib_path is not his. Note: it is impossible to create a Github library, but can the C.O.W. portion.
193  void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties ) override;
194 
195  // Since I derive from PCB_IO, I have to implement this, else I'd inherit his, which is bad since
196  // my lib_path is not his. Note: it is impossible to delete a Github library, but can the C.O.W portion.
197  bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties ) override;
198 
199  //-----</PLUGIN API>---------------------------------------------------------
200 
201  GITHUB_PLUGIN(); // constructor, if any, must be zero arg
202  ~GITHUB_PLUGIN();
203 
204 protected:
205 
206  void init( const PROPERTIES* aProperties );
207 
208  void cacheLib( const wxString& aLibraryPath, const PROPERTIES* aProperties );
209 
218  static bool repoURL_zipURL( const wxString& aRepoURL, std::string* aZipURL );
219 
226  void remoteGetZip( const wxString& aRepoURL );
227 
228  wxString m_lib_path;
229  std::string m_zip_image;
231  wxString m_pretty_dir;
232 };
233 
234 
235 #endif // GITHUB_PLUGIN_H_
const wxString PluginName() const override
Function PluginName returns a brief hard coded name for this PLUGIN.
Class PCB_IO is a PLUGIN derivation for saving and loading Pcbnew s-expression formatted files...
void init(const PROPERTIES *aProperties)
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
Return a list of footprint names contained within the library at aLibraryPath.
void FootprintLibOptions(PROPERTIES *aListToAppendTo) const override
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
std::string m_zip_image
byte image of the zip file in its entirety.
void FootprintSave(const wxString &aLibraryPath, const MODULE *aFootprint, const PROPERTIES *aProperties=NULL) override
Function FootprintSave will write aModule to an existing library located at aLibraryPath.
wxString m_lib_path
from aLibraryPath, something like https://github.com/liftoff-sr/pretty_footprints ...
void cacheLib(const wxString &aLibraryPath, const PROPERTIES *aProperties)
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory)...
Class GITHUB_PLUGIN implements a portion of pcbnew&#39;s PLUGIN interface to provide read only access to ...
wxString m_pretty_dir
void FootprintDelete(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
Function FootprintDelete deletes aFootprintName from the library at aLibraryPath. ...
void PrefetchLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
Function PrefetchLib If possible, prefetches the specified library (e.g.
void FootprintLibCreate(const wxString &aLibraryPath, const PROPERTIES *aProperties) override
Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty...
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
void remoteGetZip(const wxString &aRepoURL)
Function remoteGetZip fetches a zip file image from a github repo synchronously.
bool FootprintLibDelete(const wxString &aLibraryPath, const PROPERTIES *aProperties) override
Function FootprintLibDelete deletes an existing footprint library and returns true, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason.
GH_CACHE * m_gh_cache
MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties) override
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
static bool repoURL_zipURL(const wxString &aRepoURL, std::string *aZipURL)
Function repoURL_zipURL translates a repo URL to a zipfile URL name as commonly seen on github...
Class GH_CACHE assists only within GITHUB_PLUGIN and holds a map of footprint name to wxZipEntry...
const wxString GetFileExtension() const override
Function GetFileExtension returns the file extension for the PLUGIN.