KiCad PCB EDA Suite
GITHUB_PLUGIN Class Reference

Class GITHUB_PLUGIN implements a portion of pcbnew's PLUGIN interface to provide read only access to a github repo consisting of pretty footprints, and optionally provides "Copy On Write" support of edited footprints. More...

#include <github_plugin.h>

Inheritance diagram for GITHUB_PLUGIN:
PCB_IO PLUGIN

Public Member Functions

const wxString PluginName () const override
 Function PluginName returns a brief hard coded name for this PLUGIN. More...
 
const wxString GetFileExtension () const override
 Function GetFileExtension returns the file extension for the PLUGIN. More...
 
void FootprintEnumerate (wxArrayString &aFootprintNames, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Return a list of footprint names contained within the library at aLibraryPath. More...
 
void PrefetchLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Function PrefetchLib If possible, prefetches the specified library (e.g. More...
 
MODULEFootprintLoad (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties) override
 Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a library format that this PLUGIN knows about. More...
 
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. More...
 
void FootprintDelete (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
 Function FootprintDelete deletes aFootprintName from the library at aLibraryPath. More...
 
bool IsFootprintLibWritable (const wxString &aLibraryPath) override
 Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable. More...
 
long long GetLibraryTimestamp (const wxString &aLibraryPath) const override
 Generate a timestamp representing all the files in the library (including the library directory). More...
 
void FootprintLibOptions (PROPERTIES *aListToAppendTo) const override
 Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 
void FootprintLibCreate (const wxString &aLibraryPath, const PROPERTIES *aProperties) override
 Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty. More...
 
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. More...
 
 GITHUB_PLUGIN ()
 
 ~GITHUB_PLUGIN ()
 
virtual void Save (const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=NULL) override
 Function Save will write aBoard to a storage file in a format that this PLUGIN implementation knows about, or it can be used to write a portion of aBoard to a special kind of export file. More...
 
BOARDLoad (const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=NULL) override
 Function Load loads information from some input file format that this PLUGIN implementation knows about, into either a new BOARD or an existing one. More...
 
MODULELoadEnumeratedFootprint (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
 Function LoadEnumeratedFootprint a version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management. More...
 
void Format (BOARD_ITEM *aItem, int aNestLevel=0) const
 Function Format outputs aItem to aFormatter in s-expression format. More...
 
std::string GetStringOutput (bool doClear)
 
void SetOutputFormatter (OUTPUTFORMATTER *aFormatter)
 
BOARD_ITEMParse (const wxString &aClipboardSourceInput)
 

Protected Member Functions

void init (const PROPERTIES *aProperties)
 
void cacheLib (const wxString &aLibraryPath, const PROPERTIES *aProperties)
 
void remoteGetZip (const wxString &aRepoURL)
 Function remoteGetZip fetches a zip file image from a github repo synchronously. More...
 
void validateCache (const wxString &aLibraryPath, bool checkModified=true)
 
MODULEdoLoadFootprint (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)
 
void formatSetup (BOARD *aBoard, int aNestLevel=0) const
 formats the board setup information More...
 
void formatGeneral (BOARD *aBoard, int aNestLevel=0) const
 formats the General section of the file More...
 
void formatBoardLayers (BOARD *aBoard, int aNestLevel=0) const
 formats the board layer information More...
 
void formatNetInformation (BOARD *aBoard, int aNestLevel=0) const
 formats the Nets and Netclasses More...
 
void formatHeader (BOARD *aBoard, int aNestLevel=0) const
 writes everything that comes before the board_items, like settings and layers etc More...
 

Static Protected Member Functions

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.com. More...
 

Protected Attributes

wxString m_lib_path
 from aLibraryPath, something like https://github.com/liftoff-sr/pretty_footprints More...
 
std::string m_zip_image
 byte image of the zip file in its entirety. More...
 
GH_CACHEm_gh_cache
 
wxString m_pretty_dir
 
wxString m_error
 for throwing exceptions More...
 
BOARDm_board
 which BOARD, no ownership here More...
 
const PROPERTIESm_props
 passed via Save() or Load(), no ownership, may be NULL. More...
 
FP_CACHEm_cache
 Footprint library cache. More...
 
LINE_READERm_reader
 no ownership here. More...
 
wxString m_filename
 for saves only, name is in m_reader for loads More...
 
int m_loading_format_version
 which SEXPR_BOARD_FILE_VERSION should be Load()ed? More...
 
STRING_FORMATTER m_sf
 
OUTPUTFORMATTERm_out
 output any Format()s to this, no ownership More...
 
int m_ctl
 
PCB_PARSERm_parser
 
NETINFO_MAPPINGm_mapping
 mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes More...
 

Detailed Description

Class GITHUB_PLUGIN implements a portion of pcbnew's PLUGIN interface to provide read only access to a github repo consisting of pretty footprints, and optionally provides "Copy On Write" support of edited footprints.

It could have used version 3 of the github.com API documented here:

    http://developer.github.com/v3/
    https://help.github.com/articles/creating-an-access-token-for-command-line-use

but it does not, since a better technique was discovered. Cleverly this plugin simply reads in a zip file of the repo and unzips it from RAM as needed. Therefore this "Github" plugin is read only for accessing remote pretty libraries at https://github.com.

The fp-lib-table dialog is entered via menu choice "Preferences | Library Tables". For easy options editing in the current row, click on the "Edit Options" button. The "Library Path" in the fp-lib-table row for a Github library should be set to the full https:// URL.

For example:

     https://github.com/liftoff-sr/pretty_footprints

This is typically

     https://github.com/user_name/repo_name

The "Plugin Type" should be set to "Github".

This plugin also supports "Copy On Write", a.k.a. "COW". Thus a Github library may take an optional option called allow_pretty_writing_to_this_dir. This option is essentially the "Library Path" for a local "KiCad" (pretty) type library which is combined to make up the Github library found in the same fp-lib-table row. If the option is missing, then the Github library is read only as always. If the option is present for a Github library, then any writes to this hybrid library will go to the local *.pretty directory. Note that the github.com resident portion of this hybrid COW library is always read only, meaning you cannot delete anything or modify any footprint at github directly. The aggregate library type remains "Github" in your discussions, but it consists of a local R/W portion and a remote R/O portion.

Below is an fp-lib-table entry for the case without option allow_pretty_writing_to_this_dir:

NicknameLibrary PathPlugin TypeOptions

Description

githubhttps://github.com/liftoff-sr/pretty_footprintsGithub Liftoff's GH footprints

Below is an fp-lib-table entry with the COW option given. Note the use of the environment variable ${HOME}, as an example only. The github.pretty directory is based in ${HOME}/pretty/. Anytime you use option allow_pretty_writing_to_this_dir, you will create that directory manually and it must end in extension .pretty.

NicknameLibrary PathPlugin TypeOptions

Description

githubhttps://github.com/liftoff-sr/pretty_footprintsGithub allow_pretty_writing_to_this_dir=${HOME}/pretty/github.pretty Liftoff's GH footprints

Any footprint loads will always give precedence to the local footprints found in the pretty dir given by option allow_pretty_writing_to_this_dir. So once you have written to the COW library's local directory by doing a footprint save, no github updates will be seen when loading a footprint by the same name as one for which you've written locally.

Always keep a separate local *.pretty directory for each Github library, never combine them by referring to the same directory more than once. Also, do not also use the same COW (*.pretty) directory in a "KiCad" fp-lib-table entry. This would likely create a mess. The COW directory should be manually created in advance, and the directory name must end with ".pretty". The value of the option allow_pretty_writing_to_this_dir will be path substituted with any environment variable strings embedded, just like the "Library Path" is.

What's the point of COW? It is to turbo-charge the sharing of footprints. If you periodically email your COW pretty footprint modifications to the Github repo maintainer, you can help update the Github copy. Simply email the individual *.kicad_mod files you find in your COW directories. After you've received confirmation that your changes have been committed up at github.com, you can safely delete your COW file(s) and those from github.com will flow down. Your goal should be to keep the COW file set as small as possible by contributing frequently to the shared master copies at https://github.com.

Note that if you use the module editor to delete a footprint and it is present in the COW local dir, it will get deleted from there. However, it may not be deleted from the library as a whole if the footprint of the same name also exists in the github repo. In this case deleting the local copy will simply unmask the one at the github repo. Remember, it is masked out if there is a local COW copy, since the local copy always takes precedence. And remember you cannot modify the github copy except by emailing a COW modification to the repo maintainer.

If you happen to be the repo maintainer, then the obvious solution for you is to make your COW directory be your working copy directory. From there you can push to github. And you can receive *.kicad_mod files by email and put them into your local working copy directory also and do diffs, reverting or denying when appropriate, editing when appropriate before pushing or denying the change. Ultimately you would owe the sender either a note of acceptance or denial by email.

Author
Dick Hollenbeck
Date
Original date: 10-Sep-2013

Definition at line 162 of file github_plugin.h.

Constructor & Destructor Documentation

GITHUB_PLUGIN::GITHUB_PLUGIN ( )

Definition at line 116 of file github_plugin.cpp.

116  :
117  PCB_IO(),
118  m_gh_cache( 0 )
119 {
120 }
PCB_IO(int aControlFlags=CTL_FOR_BOARD)
GH_CACHE * m_gh_cache
GITHUB_PLUGIN::~GITHUB_PLUGIN ( )

Definition at line 123 of file github_plugin.cpp.

References m_gh_cache.

124 {
125  delete m_gh_cache;
126 }
GH_CACHE * m_gh_cache

Member Function Documentation

void GITHUB_PLUGIN::cacheLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties 
)
protected

Definition at line 378 of file github_plugin.cpp.

References LIB_TABLE::ExpandSubstitutions(), Format(), FROM_UTF8(), GetChars(), m_gh_cache, m_lib_path, m_pretty_dir, m_zip_image, PRETTY_DIR, remoteGetZip(), THROW_IO_ERROR, and PROPERTIES::Value().

Referenced by FootprintDelete(), FootprintEnumerate(), FootprintLibCreate(), FootprintLibDelete(), FootprintLoad(), and FootprintSave().

379 {
380  // This is edge triggered based on a change in 'aLibraryPath',
381  // usually it does nothing. When the edge fires, m_pretty_dir is set
382  // to either:
383  // 1) empty or
384  // 2) a verified and validated, writable, *.pretty directory.
385 
386  if( !m_gh_cache || m_lib_path != aLibraryPath )
387  {
388  delete m_gh_cache;
389  m_gh_cache = 0;
390  m_pretty_dir.clear();
391 
392  if( !m_lib_path.empty() )
393  {
394  // Library path wasn't empty before - it's been changed. Flush out the prefetch cache.
395  m_zip_image.clear();
396  }
397 
398  if( aProperties )
399  {
400  UTF8 pretty_dir;
401 
402  if( aProperties->Value( PRETTY_DIR, &pretty_dir ) )
403  {
404  wxString wx_pretty_dir = pretty_dir;
405 
406  wx_pretty_dir = LIB_TABLE::ExpandSubstitutions( wx_pretty_dir );
407 
408  wxFileName wx_pretty_fn = wx_pretty_dir;
409 
410  if( !wx_pretty_fn.IsOk() ||
411  !wx_pretty_fn.IsDirWritable() ||
412  wx_pretty_fn.GetExt() != "pretty"
413  )
414  {
415  wxString msg = wxString::Format(
416  _( "option \"%s\" for Github library \"%s\" must point to a writable directory ending with '.pretty'." ),
418  GetChars( aLibraryPath )
419  );
420 
421  THROW_IO_ERROR( msg );
422  }
423 
424  m_pretty_dir = wx_pretty_dir;
425  }
426  }
427 
428  // operator==( wxString, wxChar* ) does not exist, construct wxString once here.
429  const wxString kicad_mod( "kicad_mod" );
430 
431  //D(printf("%s: this:%p m_lib_path:'%s' aLibraryPath:'%s'\n", __func__, this, TO_UTF8( m_lib_path), TO_UTF8(aLibraryPath) );)
432  m_gh_cache = new GH_CACHE();
433 
434  // INIT_LOGGER( "/tmp", "test.log" );
435  remoteGetZip( aLibraryPath );
436  // UNINIT_LOGGER();
437 
438  m_lib_path = aLibraryPath;
439 
440  wxMemoryInputStream mis( &m_zip_image[0], m_zip_image.size() );
441 
442  // Recently the zip standard adopted UTF8 encoded filenames within the
443  // internal zip directory block. Please only use zip files that conform
444  // to that standard. Github seems to now, but may not have earlier.
445  wxZipInputStream zis( mis, wxConvUTF8 );
446 
447  wxZipEntry* entry;
448  wxString fp_name;
449 
450  while( ( entry = zis.GetNextEntry() ) != NULL )
451  {
452  wxFileName fn( entry->GetName() ); // chop long name into parts
453 
454  if( fn.GetExt() == kicad_mod )
455  {
456  fp_name = fn.GetName(); // omit extension & path
457 
458  m_gh_cache->insert( fp_name, entry );
459  }
460  else
461  delete entry;
462  }
463  }
464 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
static const wxString ExpandSubstitutions(const wxString &aString)
Replaces any environment variable references with their values and is here to fully embellish the TAB...
bool Value(const char *aName, UTF8 *aFetchedValue=NULL) const
Function Value fetches a property by aName and returns true if that property was found, else false.
Definition: properties.cpp:24
std::string m_zip_image
byte image of the zip file in its entirety.
wxString m_lib_path
from aLibraryPath, something like https://github.com/liftoff-sr/pretty_footprints ...
wxString m_pretty_dir
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void remoteGetZip(const wxString &aRepoURL)
Function remoteGetZip fetches a zip file image from a github repo synchronously.
GH_CACHE * m_gh_cache
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
Class GH_CACHE assists only within GITHUB_PLUGIN and holds a map of footprint name to wxZipEntry...
static const char * PRETTY_DIR
MODULE * PCB_IO::doLoadFootprint ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties,
bool  checkModified 
)
protectedinherited

Definition at line 2007 of file kicad_plugin.cpp.

References FP_CACHE::GetModules(), PCB_IO::init(), PCB_IO::m_cache, and PCB_IO::validateCache().

Referenced by PCB_IO::FootprintLoad(), and PCB_IO::LoadEnumeratedFootprint().

2011 {
2012  LOCALE_IO toggle; // toggles on, then off, the C locale.
2013 
2014  init( aProperties );
2015 
2016  try
2017  {
2018  validateCache( aLibraryPath, checkModified );
2019  }
2020  catch( const IO_ERROR& )
2021  {
2022  // do nothing with the error
2023  }
2024 
2025  const MODULE_MAP& mods = m_cache->GetModules();
2026 
2027  MODULE_CITER it = mods.find( aFootprintName );
2028 
2029  if( it == mods.end() )
2030  {
2031  return NULL;
2032  }
2033 
2034  // copy constructor to clone the already loaded MODULE
2035  return new MODULE( *it->second->GetModule() );
2036 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_plugin.h:35
MODULE_MAP::const_iterator MODULE_CITER
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
MODULE_MAP & GetModules()
void GITHUB_PLUGIN::FootprintDelete ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function FootprintDelete deletes aFootprintName from the library at aLibraryPath.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aFootprintNameis the name of a footprint to delete from the specified library.
aPropertiesis an associative array that can be used to tell the library delete function anything special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem finding the footprint or the library, or deleting it.

Reimplemented from PLUGIN.

Definition at line 278 of file github_plugin.cpp.

References cacheLib(), PCB_IO::FootprintDelete(), PCB_IO::FootprintEnumerate(), Format(), GetChars(), IsFootprintLibWritable(), m_pretty_dir, PRETTY_DIR, StrPrintf(), THROW_IO_ERROR, and TO_UTF8.

280 {
281  // set m_pretty_dir to either empty or something in aProperties
282  cacheLib( aLibraryPath, aProperties );
283 
284  if( GITHUB_PLUGIN::IsFootprintLibWritable( aLibraryPath ) )
285  {
286  // Does the PCB_IO base class have this footprint?
287  // We cannot write to github.
288 
289  wxArrayString pretties;
290 
291  PCB_IO::FootprintEnumerate( pretties, m_pretty_dir, aProperties );
292 
293  if( pretties.Index( aFootprintName ) != wxNOT_FOUND )
294  {
295  PCB_IO::FootprintDelete( m_pretty_dir, aFootprintName, aProperties );
296  }
297  else
298  {
299  wxString msg = wxString::Format(
300  _( "Footprint\n\"%s\"\nis not in the writable portion of this Github library\n\"%s\"" ),
301  GetChars( aFootprintName ),
302  GetChars( aLibraryPath )
303  );
304 
305  THROW_IO_ERROR( msg );
306  }
307  }
308  else
309  {
310  // This typically will not happen if the caller first properly calls
311  // IsFootprintLibWritable() to determine if calling FootprintSave() is
312  // even legal, so I spend no time on internationalization here:
313 
314  string msg = StrPrintf( "Github library\n\"%s\"\nis only writable if you set option \"%s\" in Library Tables dialog.",
315  TO_UTF8( aLibraryPath ), PRETTY_DIR );
316 
317  THROW_IO_ERROR( msg );
318  }
319 }
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
Return a list of footprint names contained within the library at aLibraryPath.
int StrPrintf(std::string *result, const char *format,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:74
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
void cacheLib(const wxString &aLibraryPath, const PROPERTIES *aProperties)
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. ...
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
static const char * PRETTY_DIR
void GITHUB_PLUGIN::FootprintEnumerate ( wxArrayString &  aFootprintNames,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Return a list of footprint names contained within the library at aLibraryPath.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aPropertiesis an associative array that can be used to tell the plugin anything needed about how to perform with respect to aLibraryPath. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
aFootprintNamesis the array of available footprint names inside a library.
Exceptions
IO_ERRORif the library cannot be found, or footprint cannot be loaded.

Reimplemented from PLUGIN.

Definition at line 141 of file github_plugin.cpp.

References cacheLib(), PCB_IO::FootprintEnumerate(), i, m_gh_cache, and m_pretty_dir.

Referenced by remoteGetZip().

143 {
144  //D(printf("%s: this:%p aLibraryPath:\"%s\"\n", __func__, this, TO_UTF8(aLibraryPath) );)
145  cacheLib( aLibraryPath, aProperties );
146 
147  typedef std::set<wxString> MYSET;
148 
149  MYSET unique;
150 
151  if( m_pretty_dir.size() )
152  {
153  wxArrayString locals;
154 
156 
157  for( unsigned i=0; i<locals.GetCount(); ++i )
158  unique.insert( locals[i] );
159  }
160 
161  for( MODULE_ITER it = m_gh_cache->begin(); it!=m_gh_cache->end(); ++it )
162  {
163  unique.insert( it->first );
164  }
165 
166  for( MYSET::const_iterator it = unique.begin(); it != unique.end(); ++it )
167  {
168  aFootprintNames.Add( *it );
169  }
170 }
MODULE_MAP::iterator MODULE_ITER
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 cacheLib(const wxString &aLibraryPath, const PROPERTIES *aProperties)
wxString m_pretty_dir
size_t i
Definition: json11.cpp:597
GH_CACHE * m_gh_cache
void GITHUB_PLUGIN::FootprintLibCreate ( const wxString &  aLibraryPath,
const PROPERTIES aProperties 
)
overridevirtual

Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty.

It is an error to attempt to create an existing library or to attempt to create on a "read only" location.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aPropertiesis an associative array that can be used to tell the library create function anything special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem finding the library, or creating it.

Reimplemented from PLUGIN.

Definition at line 322 of file github_plugin.cpp.

References cacheLib(), PCB_IO::FootprintLibCreate(), and m_pretty_dir.

323 {
324  // set m_pretty_dir to either empty or something in aProperties
325  cacheLib( aLibraryPath, aProperties );
326 
327  if( m_pretty_dir.size() )
328  {
330  }
331  else
332  {
333  // THROW_IO_ERROR() @todo
334  }
335 }
void FootprintLibCreate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty...
void cacheLib(const wxString &aLibraryPath, const PROPERTIES *aProperties)
wxString m_pretty_dir
bool GITHUB_PLUGIN::FootprintLibDelete ( const wxString &  aLibraryPath,
const PROPERTIES aProperties 
)
overridevirtual

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.

Parameters
aLibraryPathis a locator for the "library", usually a directory or file which will contain footprints.
aPropertiesis an associative array that can be used to tell the library delete implementation function anything special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
bool - true if library deleted, false if library did not exist.
Exceptions
IO_ERRORif there is a problem deleting an existing library.

Reimplemented from PLUGIN.

Definition at line 338 of file github_plugin.cpp.

References cacheLib(), PCB_IO::FootprintLibDelete(), and m_pretty_dir.

339 {
340  // set m_pretty_dir to either empty or something in aProperties
341  cacheLib( aLibraryPath, aProperties );
342 
343  if( m_pretty_dir.size() )
344  {
345  return PCB_IO::FootprintLibDelete( m_pretty_dir, aProperties );
346  }
347  else
348  {
349  // THROW_IO_ERROR() @todo
350  return false;
351  }
352 }
void cacheLib(const wxString &aLibraryPath, const PROPERTIES *aProperties)
wxString m_pretty_dir
bool FootprintLibDelete(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) 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.
void GITHUB_PLUGIN::FootprintLibOptions ( PROPERTIES aListToAppendTo) const
overridevirtual

Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internationalized descriptions.

Options are typically appended so that a derived PLUGIN can call its base class function by the same name first, thus inheriting options declared there. (Some base class options could pertain to all Footprint*() functions in all derived PLUGINs.) Note that since aListToAppendTo is a PROPERTIES object, all options will be unique and last guy wins.

Parameters
aListToAppendToholds a tuple of
option
This eventually is what shows up into the fp-lib-table "options" field, possibly combined with others.
internationalized description
The internationalized description is displayed in DIALOG_FP_PLUGIN_OPTIONS. It may be multi-line and be quite explanatory of the option.

In the future perhaps aListToAppendTo evolves to something capable of also holding a wxValidator for the cells in said dialog: http://forums.wxwidgets.org/viewtopic.php?t=23277&p=104180. This would require a 3 column list, and introducing wx GUI knowledge to PLUGIN, which has been avoided to date.

Reimplemented from PLUGIN.

Definition at line 355 of file github_plugin.cpp.

References PLUGIN::FootprintLibOptions(), and PRETTY_DIR.

356 {
357  // inherit options supported by all PLUGINs.
358  PLUGIN::FootprintLibOptions( aListToAppendTo );
359 
360  (*aListToAppendTo)[ PRETTY_DIR ] = UTF8( _(
361  "Set this property to a directory where footprints are to be written as pretty "
362  "footprints when saving to this library. Anything saved will take precedence over "
363  "footprints by the same name in the github repo. These saved footprints can then "
364  "be sent to the library maintainer as updates. "
365  "<p>The directory <b>must</b> have a <b>.pretty</b> file extension because the "
366  "format of the save is pretty.</p>"
367  ));
368 
369  /*
370  (*aListToAppendTo)["cache_github_zip_in_this_dir"] = UTF8( _(
371  "Set this property to a directory where the github *.zip file will be cached. "
372  "This should speed up subsequent visits to this library."
373  ));
374  */
375 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
virtual void FootprintLibOptions(PROPERTIES *aListToAppendTo) const
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
Definition: plugin.cpp:131
static const char * PRETTY_DIR
MODULE * GITHUB_PLUGIN::FootprintLoad ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties 
)
overridevirtual

Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a library format that this PLUGIN knows about.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aFootprintNameis the name of the footprint to load.
aPropertiesis an associative array that can be used to tell the loader implementation to do something special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
MODULE* - if found caller owns it, else NULL if not found.
Exceptions
IO_ERRORif the library cannot be found or read. No exception is thrown in the case where aFootprintName cannot be found.

Reimplemented from PLUGIN.

Definition at line 185 of file github_plugin.cpp.

References cacheLib(), PCB_IO::FootprintLoad(), m_gh_cache, PCB_IO::m_parser, m_pretty_dir, m_zip_image, PCB_PARSER::Parse(), MODULE::SetFPID(), and PCB_PARSER::SetLineReader().

187 {
188  // D(printf("%s: this:%p aLibraryPath:\"%s\"\n", __func__, this, TO_UTF8(aLibraryPath) );)
189 
190  // clear or set to valid the variable m_pretty_dir
191  cacheLib( aLibraryPath, aProperties );
192 
193  if( m_pretty_dir.size() )
194  {
195  // API has FootprintLoad() *not* throwing an exception if footprint not found.
196  MODULE* local = PCB_IO::FootprintLoad( m_pretty_dir, aFootprintName, aProperties );
197 
198  if( local )
199  {
200  // It has worked, see <src>/scripts/test_kicad_plugin.py. So this was not firing:
201  // wxASSERT( aFootprintName == FROM_UTF8( local->GetFPID().GetLibItemName().c_str() ) );
202  // Moving it to higher API layer FP_LIB_TABLE::FootprintLoad().
203 
204  return local;
205  }
206  }
207 
208  MODULE_CITER it = m_gh_cache->find( aFootprintName );
209 
210  if( it != m_gh_cache->end() ) // fp_name is present
211  {
212  //std::string::data() ensures that the referenced data block is contiguous.
213  wxMemoryInputStream mis( m_zip_image.data(), m_zip_image.size() );
214 
215  // This decoder should always be UTF8, since it was saved that way by git.
216  // That is, since pretty footprints are UTF8, and they were pushed to the
217  // github repo, they are still UTF8.
218  wxZipInputStream zis( mis, wxConvUTF8 );
219  wxZipEntry* entry = (wxZipEntry*) it->second; // remove "const"-ness
220 
221  if( zis.OpenEntry( *entry ) )
222  {
223  INPUTSTREAM_LINE_READER reader( &zis, aLibraryPath );
224 
225  // I am a PCB_IO derivative with my own PCB_PARSER
226  m_parser->SetLineReader( &reader ); // ownership not passed
227 
228  MODULE* ret = (MODULE*) m_parser->Parse();
229 
230  // In a github library, (as well as in a "KiCad" library) the name of
231  // the pretty file defines the footprint name. That filename trumps
232  // any name found in the pretty file; any name in the pretty file
233  // must be ignored here. Also, the library nickname is unknown in
234  // this context so clear it just in case.
235  ret->SetFPID( aFootprintName );
236 
237  return ret;
238  }
239  }
240 
241  return NULL; // this API function returns NULL for "not found", per spec.
242 }
Class INPUTSTREAM_LINE_READER is a LINE_READER that reads from a wxInputStream object.
Definition: richio.h:290
std::string m_zip_image
byte image of the zip file in its entirety.
MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
void cacheLib(const wxString &aLibraryPath, const PROPERTIES *aProperties)
wxString m_pretty_dir
PCB_PARSER * m_parser
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:442
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one...
Definition: pcb_parser.h:289
MODULE_MAP::const_iterator MODULE_CITER
GH_CACHE * m_gh_cache
void SetFPID(const LIB_ID &aFPID)
Definition: class_module.h:192
void GITHUB_PLUGIN::FootprintSave ( const wxString &  aLibraryPath,
const MODULE aFootprint,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function FootprintSave will write aModule to an existing library located at aLibraryPath.

If a footprint by the same name already exists, it is replaced.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aFootprintis what to store in the library. The caller continues to own the footprint after this call.
aPropertiesis an associative array that can be used to tell the saver how to save the footprint, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem saving.

Reimplemented from PLUGIN.

Definition at line 254 of file github_plugin.cpp.

References cacheLib(), PCB_IO::FootprintSave(), IsFootprintLibWritable(), m_pretty_dir, PRETTY_DIR, StrPrintf(), THROW_IO_ERROR, and TO_UTF8.

256 {
257  // set m_pretty_dir to either empty or something in aProperties
258  cacheLib( aLibraryPath, aProperties );
259 
260  if( GITHUB_PLUGIN::IsFootprintLibWritable( aLibraryPath ) )
261  {
262  PCB_IO::FootprintSave( m_pretty_dir, aFootprint, aProperties );
263  }
264  else
265  {
266  // This typically will not happen if the caller first properly calls
267  // IsFootprintLibWritable() to determine if calling FootprintSave() is
268  // even legal, so I spend no time on internationalization here:
269 
270  string msg = StrPrintf( "Github library\n\"%s\"\nis only writable if you set option \"%s\" in Library Tables dialog.",
271  TO_UTF8( aLibraryPath ), PRETTY_DIR );
272 
273  THROW_IO_ERROR( msg );
274  }
275 }
int StrPrintf(std::string *result, const char *format,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:74
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
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.
void cacheLib(const wxString &aLibraryPath, const PROPERTIES *aProperties)
wxString m_pretty_dir
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
static const char * PRETTY_DIR
void PCB_IO::Format ( BOARD_ITEM aItem,
int  aNestLevel = 0 
) const
inherited

Function Format outputs aItem to aFormatter in s-expression format.

Parameters
aItemA pointer the an BOARD_ITEM object to format.
aNestLevelThe indentation nest level.
Exceptions
IO_ERRORon write error.

Definition at line 436 of file kicad_plugin.cpp.

References EDA_ITEM::GetClass(), PCB_DIMENSION_T, PCB_LINE_T, PCB_MODULE_EDGE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_PAD_T, PCB_T, PCB_TARGET_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_T, and EDA_ITEM::Type().

Referenced by FOOTPRINT_EDIT_FRAME::Export_Module(), PCB_IO::GetFileExtension(), CLIPBOARD_IO::Save(), and CLIPBOARD_IO::SaveSelection().

437 {
438  LOCALE_IO toggle; // public API function, perform anything convenient for caller
439 
440  switch( aItem->Type() )
441  {
442  case PCB_T:
443  format( static_cast<BOARD*>( aItem ), aNestLevel );
444  break;
445 
446  case PCB_DIMENSION_T:
447  format( static_cast<DIMENSION*>( aItem ), aNestLevel );
448  break;
449 
450  case PCB_LINE_T:
451  format( static_cast<DRAWSEGMENT*>( aItem ), aNestLevel );
452  break;
453 
454  case PCB_MODULE_EDGE_T:
455  format( static_cast<EDGE_MODULE*>( aItem ), aNestLevel );
456  break;
457 
458  case PCB_TARGET_T:
459  format( static_cast<PCB_TARGET*>( aItem ), aNestLevel );
460  break;
461 
462  case PCB_MODULE_T:
463  format( static_cast<MODULE*>( aItem ), aNestLevel );
464  break;
465 
466  case PCB_PAD_T:
467  format( static_cast<D_PAD*>( aItem ), aNestLevel );
468  break;
469 
470  case PCB_TEXT_T:
471  format( static_cast<TEXTE_PCB*>( aItem ), aNestLevel );
472  break;
473 
474  case PCB_MODULE_TEXT_T:
475  format( static_cast<TEXTE_MODULE*>( aItem ), aNestLevel );
476  break;
477 
478  case PCB_TRACE_T:
479  case PCB_VIA_T:
480  format( static_cast<TRACK*>( aItem ), aNestLevel );
481  break;
482 
483  case PCB_ZONE_AREA_T:
484  format( static_cast<ZONE_CONTAINER*>( aItem ), aNestLevel );
485  break;
486 
487  default:
488  wxFAIL_MSG( wxT( "Cannot format item " ) + aItem->GetClass() );
489  }
490 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
Definition: typeinfo.h:85
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
class MODULE, a footprint
Definition: typeinfo.h:89
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:100
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:101
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
virtual wxString GetClass() const =0
Function GetClass returns the class name.
void format(BOARD *aBoard, int aNestLevel=0) const
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
void PCB_IO::formatBoardLayers ( BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

formats the board layer information

Definition at line 646 of file kicad_plugin.cpp.

References B_Adhes, B_CrtYd, B_Fab, B_Mask, B_Paste, B_SilkS, Cmts_User, cu, LSET::CuStack(), DIM, Dwgs_User, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_CrtYd, F_Fab, F_Mask, F_Paste, F_SilkS, BOARD::GetEnabledLayers(), BOARD::GetLayerName(), BOARD::GetLayerType(), BOARD::GetVisibleLayers(), Margin, LSET::Seq(), and LAYER::ShowType().

Referenced by CLIPBOARD_IO::SaveSelection().

647 {
648  m_out->Print( aNestLevel, "(layers\n" );
649 
650  // Save only the used copper layers from front to back.
651  LSET visible_layers = aBoard->GetVisibleLayers();
652 
653  for( LSEQ cu = aBoard->GetEnabledLayers().CuStack(); cu; ++cu )
654  {
655  PCB_LAYER_ID layer = *cu;
656 
657  m_out->Print( aNestLevel+1, "(%d %s %s", layer,
658  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str(),
659  LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
660 
661  if( !visible_layers[layer] )
662  m_out->Print( 0, " hide" );
663 
664  m_out->Print( 0, ")\n" );
665  }
666 
667  // Save used non-copper layers in the order they are defined.
668  // desired sequence for non Cu BOARD layers.
669  static const PCB_LAYER_ID non_cu[] =
670  {
671  B_Adhes, // 32
672  F_Adhes,
673  B_Paste,
674  F_Paste,
675  B_SilkS,
676  F_SilkS,
677  B_Mask,
678  F_Mask,
679  Dwgs_User,
680  Cmts_User,
681  Eco1_User,
682  Eco2_User,
683  Edge_Cuts,
684  Margin,
685  B_CrtYd,
686  F_CrtYd,
687  B_Fab,
688  F_Fab
689  };
690 
691  for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, DIM( non_cu ) ); seq; ++seq )
692  {
693  PCB_LAYER_ID layer = *seq;
694 
695  m_out->Print( aNestLevel+1, "(%d %s user", layer,
696  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str() );
697 
698  if( !visible_layers[layer] )
699  m_out->Print( 0, " hide" );
700 
701  m_out->Print( 0, ")\n" );
702  }
703 
704  m_out->Print( aNestLevel, ")\n\n" );
705 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
LSEQ CuStack() const
Function CuStack returns a sequence of copper layers in starting from the front/top and extending to ...
Definition: lset.cpp:147
#define cu(a)
Definition: auxiliary.h:88
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
static const char * ShowType(LAYER_T aType)
Function ShowType converts a LAYER_T enum to a const char*.
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Function Seq returns an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:364
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:482
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
LSET GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Function GetLayerType returns the type of the copper layer given by aLayer.
void PCB_IO::formatGeneral ( BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

formats the General section of the file

Definition at line 624 of file kicad_plugin.cpp.

References BOARD::Drawings(), FMT_IU, TITLE_BLOCK::Format(), PAGE_INFO::Format(), BOARD_DESIGN_SETTINGS::GetBoardThickness(), DHEAD::GetCount(), BOARD::GetDesignSettings(), BOARD::GetNumSegmTrack(), BOARD::GetNumSegmZone(), BOARD::GetPageSettings(), BOARD::GetTitleBlock(), and BOARD::m_Modules.

625 {
626  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
627 
628  m_out->Print( 0, "\n" );
629  m_out->Print( aNestLevel, "(general\n" );
630  // Write Bounding box info
631  m_out->Print( aNestLevel+1, "(thickness %s)\n",
632  FMT_IU( dsnSettings.GetBoardThickness() ).c_str() );
633 
634  m_out->Print( aNestLevel+1, "(drawings %d)\n", aBoard->Drawings().Size() );
635  m_out->Print( aNestLevel+1, "(tracks %d)\n", aBoard->GetNumSegmTrack() );
636  m_out->Print( aNestLevel+1, "(zones %d)\n", aBoard->GetNumSegmZone() );
637  m_out->Print( aNestLevel+1, "(modules %d)\n", aBoard->m_Modules.GetCount() );
638  m_out->Print( aNestLevel+1, "(nets %d)\n", m_mapping->GetSize() );
639  m_out->Print( aNestLevel, ")\n\n" );
640 
641  aBoard->GetPageSettings().Format( m_out, aNestLevel, m_ctl );
642  aBoard->GetTitleBlock().Format( m_out, aNestLevel, m_ctl );
643 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
#define FMT_IU
int GetSize() const
Function GetSize.
Definition: netinfo.h:375
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:532
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the object to aFormatter in s-expression form.
Definition: worksheet.cpp:246
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...
int GetNumSegmTrack() const
Functions to get some items count.
const PAGE_INFO & GetPageSettings() const
Definition: class_board.h:547
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function GetStandardSizes returns the standard page types, such as "A4", "A3", etc.
Definition: page_info.cpp:267
TITLE_BLOCK & GetTitleBlock()
Definition: class_board.h:553
DLIST< MODULE > m_Modules
Definition: class_board.h:245
int GetNumSegmZone() const
Calculate the zone segment count.
unsigned GetCount() const
Function GetCount returns the number of elements in the list.
Definition: dlist.h:126
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
DLIST_ITERATOR_WRAPPER< BOARD_ITEM > Drawings()
Definition: class_board.h:251
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
void PCB_IO::formatHeader ( BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

writes everything that comes before the board_items, like settings and layers etc

Definition at line 738 of file kicad_plugin.cpp.

739 {
740  formatGeneral( aBoard, aNestLevel );
741  // Layers.
742  formatBoardLayers( aBoard, aNestLevel );
743  // Setup
744  formatSetup( aBoard, aNestLevel );
745  // Save net codes and names
746  formatNetInformation( aBoard, aNestLevel );
747 }
void formatGeneral(BOARD *aBoard, int aNestLevel=0) const
formats the General section of the file
void formatBoardLayers(BOARD *aBoard, int aNestLevel=0) const
formats the board layer information
void formatNetInformation(BOARD *aBoard, int aNestLevel=0) const
formats the Nets and Netclasses
void formatSetup(BOARD *aBoard, int aNestLevel=0) const
formats the board setup information
void PCB_IO::formatNetInformation ( BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

formats the Nets and Netclasses

Definition at line 708 of file kicad_plugin.cpp.

References NETCLASSES::begin(), NETCLASSES::end(), filterNetClass(), NETCLASS::Format(), BOARD_DESIGN_SETTINGS::GetDefault(), BOARD::GetDesignSettings(), and BOARD_DESIGN_SETTINGS::m_NetClasses.

Referenced by CLIPBOARD_IO::SaveSelection().

709 {
710  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
711  for( NETINFO_MAPPING::iterator net = m_mapping->begin(), netEnd = m_mapping->end();
712  net != netEnd; ++net )
713  {
714  m_out->Print( aNestLevel, "(net %d %s)\n",
715  m_mapping->Translate( net->GetNet() ),
716  m_out->Quotew( net->GetNetname() ).c_str() );
717  }
718 
719  m_out->Print( 0, "\n" );
720 
721  // Save the default net class first.
722  NETCLASS defaultNC = *dsnSettings.GetDefault();
723  filterNetClass( *aBoard, defaultNC ); // Remove empty nets (from a copy of a netclass)
724  defaultNC.Format( m_out, aNestLevel, m_ctl );
725 
726  // Save the rest of the net classes alphabetically.
727  for( NETCLASSES::const_iterator it = dsnSettings.m_NetClasses.begin();
728  it != dsnSettings.m_NetClasses.end();
729  ++it )
730  {
731  NETCLASS netclass = *it->second;
732  filterNetClass( *aBoard, netclass ); // Remove empty nets (from a copy of a netclass)
733  netclass.Format( m_out, aNestLevel, m_ctl );
734  }
735 }
iterator begin() const
Function begin() Returns iterator to the first entry in the mapping.
Definition: netinfo.h:355
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
NETCLASSPTR GetDefault() const
Function GetDefault.
iterator end()
Definition: netclass.h:256
NETCLASS_MAP::const_iterator const_iterator
Definition: netclass.h:258
iterator end() const
Function end() Returns iterator to the last entry in the mapping.
Definition: netinfo.h:366
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the net class to aFormatter in s-expression form.
Definition: netclass.cpp:253
iterator begin()
Definition: netclass.h:255
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function...
Class NETCLASS handles a collection of nets and the parameters used to route or test these nets...
Definition: netclass.h:55
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:532
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:482
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString, NETINFO_ITEM*>
Definition: netinfo.h:305
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...
void filterNetClass(const BOARD &aBoard, NETCLASS &aNetClass)
Removes empty nets (i.e. with node count equal zero) from net classes
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
NETCLASSES m_NetClasses
List of current netclasses. There is always the default netclass.
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
void PCB_IO::formatSetup ( BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

formats the board setup information

Definition at line 506 of file kicad_plugin.cpp.

References Double2Str(), FMT_IU, PCB_PLOT_PARAMS::Format(), BOARD::GetAuxOrigin(), BOARD_DESIGN_SETTINGS::GetCurrentTrackWidth(), BOARD_DESIGN_SETTINGS::GetDefault(), BOARD::GetDesignSettings(), D_PAD::GetDrillSize(), BOARD::GetGridOrigin(), BOARD::GetPlotOptions(), D_PAD::GetSize(), BOARD_DESIGN_SETTINGS::GetVisibleElements(), BOARD::GetZoneSettings(), BOARD_DESIGN_SETTINGS::m_BlindBuriedViaAllowed, BOARD_DESIGN_SETTINGS::m_DrawSegmentWidth, BOARD_DESIGN_SETTINGS::m_EdgeSegmentWidth, BOARD_DESIGN_SETTINGS::m_MicroViasAllowed, BOARD_DESIGN_SETTINGS::m_MicroViasMinDrill, BOARD_DESIGN_SETTINGS::m_MicroViasMinSize, BOARD_DESIGN_SETTINGS::m_ModuleSegmentWidth, BOARD_DESIGN_SETTINGS::m_ModuleTextSize, BOARD_DESIGN_SETTINGS::m_ModuleTextWidth, BOARD_DESIGN_SETTINGS::m_Pad_Master, BOARD_DESIGN_SETTINGS::m_PcbTextSize, BOARD_DESIGN_SETTINGS::m_PcbTextWidth, BOARD_DESIGN_SETTINGS::m_SolderMaskMargin, BOARD_DESIGN_SETTINGS::m_SolderMaskMinWidth, BOARD_DESIGN_SETTINGS::m_SolderPasteMargin, BOARD_DESIGN_SETTINGS::m_SolderPasteMarginRatio, BOARD_DESIGN_SETTINGS::m_TrackMinWidth, BOARD_DESIGN_SETTINGS::m_TrackWidthList, BOARD_DESIGN_SETTINGS::m_ViasDimensionsList, BOARD_DESIGN_SETTINGS::m_ViasMinDrill, BOARD_DESIGN_SETTINGS::m_ViasMinSize, ZONE_SETTINGS::m_Zone_45_Only, ZONE_SETTINGS::m_ZoneClearance, wxPoint::x, and wxPoint::y.

507 {
508  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
509 
510  // Setup
511  m_out->Print( aNestLevel, "(setup\n" );
512 
513  // Save current default track width, for compatibility with older Pcbnew version;
514  m_out->Print( aNestLevel+1, "(last_trace_width %s)\n",
515  FMT_IU( dsnSettings.GetCurrentTrackWidth() ).c_str() );
516 
517  // Save custom tracks width list (the first is not saved here: this is the netclass value
518  for( unsigned ii = 1; ii < dsnSettings.m_TrackWidthList.size(); ii++ )
519  m_out->Print( aNestLevel+1, "(user_trace_width %s)\n",
520  FMT_IU( dsnSettings.m_TrackWidthList[ii] ).c_str() );
521 
522  m_out->Print( aNestLevel+1, "(trace_clearance %s)\n",
523  FMT_IU( dsnSettings.GetDefault()->GetClearance() ).c_str() );
524 
525  // ZONE_SETTINGS
526  m_out->Print( aNestLevel+1, "(zone_clearance %s)\n",
527  FMT_IU( aBoard->GetZoneSettings().m_ZoneClearance ).c_str() );
528  m_out->Print( aNestLevel+1, "(zone_45_only %s)\n",
529  aBoard->GetZoneSettings().m_Zone_45_Only ? "yes" : "no" );
530 
531  m_out->Print( aNestLevel+1, "(trace_min %s)\n",
532  FMT_IU( dsnSettings.m_TrackMinWidth ).c_str() );
533 
534  m_out->Print( aNestLevel+1, "(segment_width %s)\n",
535  FMT_IU( dsnSettings.m_DrawSegmentWidth ).c_str() );
536  m_out->Print( aNestLevel+1, "(edge_width %s)\n",
537  FMT_IU( dsnSettings.m_EdgeSegmentWidth ).c_str() );
538 
539  // Save current default via size, for compatibility with older Pcbnew version;
540  m_out->Print( aNestLevel+1, "(via_size %s)\n",
541  FMT_IU( dsnSettings.GetDefault()->GetViaDiameter() ).c_str() );
542  m_out->Print( aNestLevel+1, "(via_drill %s)\n",
543  FMT_IU( dsnSettings.GetDefault()->GetViaDrill() ).c_str() );
544  m_out->Print( aNestLevel+1, "(via_min_size %s)\n",
545  FMT_IU( dsnSettings.m_ViasMinSize ).c_str() );
546  m_out->Print( aNestLevel+1, "(via_min_drill %s)\n",
547  FMT_IU( dsnSettings.m_ViasMinDrill ).c_str() );
548 
549  // Save custom vias diameters list (the first is not saved here: this is
550  // the netclass value
551  for( unsigned ii = 1; ii < dsnSettings.m_ViasDimensionsList.size(); ii++ )
552  m_out->Print( aNestLevel+1, "(user_via %s %s)\n",
553  FMT_IU( dsnSettings.m_ViasDimensionsList[ii].m_Diameter ).c_str(),
554  FMT_IU( dsnSettings.m_ViasDimensionsList[ii].m_Drill ).c_str() );
555 
556  // for old versions compatibility:
557  if( dsnSettings.m_BlindBuriedViaAllowed )
558  m_out->Print( aNestLevel+1, "(blind_buried_vias_allowed yes)\n" );
559 
560  m_out->Print( aNestLevel+1, "(uvia_size %s)\n",
561  FMT_IU( dsnSettings.GetDefault()->GetuViaDiameter() ).c_str() );
562  m_out->Print( aNestLevel+1, "(uvia_drill %s)\n",
563  FMT_IU( dsnSettings.GetDefault()->GetuViaDrill() ).c_str() );
564  m_out->Print( aNestLevel+1, "(uvias_allowed %s)\n",
565  ( dsnSettings.m_MicroViasAllowed ) ? "yes" : "no" );
566  m_out->Print( aNestLevel+1, "(uvia_min_size %s)\n",
567  FMT_IU( dsnSettings.m_MicroViasMinSize ).c_str() );
568  m_out->Print( aNestLevel+1, "(uvia_min_drill %s)\n",
569  FMT_IU( dsnSettings.m_MicroViasMinDrill ).c_str() );
570 
571  m_out->Print( aNestLevel+1, "(pcb_text_width %s)\n",
572  FMT_IU( dsnSettings.m_PcbTextWidth ).c_str() );
573  m_out->Print( aNestLevel+1, "(pcb_text_size %s %s)\n",
574  FMT_IU( dsnSettings.m_PcbTextSize.x ).c_str(),
575  FMT_IU( dsnSettings.m_PcbTextSize.y ).c_str() );
576 
577  m_out->Print( aNestLevel+1, "(mod_edge_width %s)\n",
578  FMT_IU( dsnSettings.m_ModuleSegmentWidth ).c_str() );
579  m_out->Print( aNestLevel+1, "(mod_text_size %s %s)\n",
580  FMT_IU( dsnSettings.m_ModuleTextSize.x ).c_str(),
581  FMT_IU( dsnSettings.m_ModuleTextSize.y ).c_str() );
582  m_out->Print( aNestLevel+1, "(mod_text_width %s)\n",
583  FMT_IU( dsnSettings.m_ModuleTextWidth ).c_str() );
584 
585  m_out->Print( aNestLevel+1, "(pad_size %s %s)\n",
586  FMT_IU( dsnSettings.m_Pad_Master.GetSize().x ).c_str(),
587  FMT_IU( dsnSettings.m_Pad_Master.GetSize().y ).c_str() );
588  m_out->Print( aNestLevel+1, "(pad_drill %s)\n",
589  FMT_IU( dsnSettings.m_Pad_Master.GetDrillSize().x ).c_str() );
590 
591  m_out->Print( aNestLevel+1, "(pad_to_mask_clearance %s)\n",
592  FMT_IU( dsnSettings.m_SolderMaskMargin ).c_str() );
593 
594  if( dsnSettings.m_SolderMaskMinWidth )
595  m_out->Print( aNestLevel+1, "(solder_mask_min_width %s)\n",
596  FMT_IU( dsnSettings.m_SolderMaskMinWidth ).c_str() );
597 
598  if( dsnSettings.m_SolderPasteMargin != 0 )
599  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance %s)\n",
600  FMT_IU( dsnSettings.m_SolderPasteMargin ).c_str() );
601 
602  if( dsnSettings.m_SolderPasteMarginRatio != 0 )
603  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance_ratio %s)\n",
604  Double2Str( dsnSettings.m_SolderPasteMarginRatio ).c_str() );
605 
606  m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
607  FMT_IU( aBoard->GetAuxOrigin().x ).c_str(),
608  FMT_IU( aBoard->GetAuxOrigin().y ).c_str() );
609 
610  if( aBoard->GetGridOrigin().x || aBoard->GetGridOrigin().y )
611  m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
612  FMT_IU( aBoard->GetGridOrigin().x ).c_str(),
613  FMT_IU( aBoard->GetGridOrigin().y ).c_str() );
614 
615  m_out->Print( aNestLevel+1, "(visible_elements %X)\n",
616  dsnSettings.GetVisibleElements() );
617 
618  aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 );
619 
620  m_out->Print( aNestLevel, ")\n\n" );
621 }
int m_SolderMaskMargin
Solder mask margin.
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const ZONE_SETTINGS & GetZoneSettings() const
Definition: class_board.h:556
int GetVisibleElements() const
Function GetVisibleElements returns a bit-mask of all the element categories that are visible...
NETCLASSPTR GetDefault() const
Function GetDefault.
const wxPoint & GetGridOrigin() const
Definition: class_board.h:350
int m_SolderPasteMargin
Solder paste margin absolute value.
int m_ModuleTextWidth
Default footprint texts thickness.
std::vector< int > m_TrackWidthList
Track width list.
int m_ModuleSegmentWidth
Default width for all graphic lines.
int m_PcbTextWidth
current Pcb (not module) Text width
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:61
const wxSize & GetDrillSize() const
Definition: class_pad.h:275
wxSize m_ModuleTextSize
Default footprint texts size.
#define FMT_IU
wxSize m_PcbTextSize
current Pcb (not module) Text size
int m_TrackMinWidth
track min value for width ((min copper size value
int m_ViasMinSize
vias (not micro vias) min diameter
int m_DrawSegmentWidth
current graphic line width (not EDGE layer)
int m_ViasMinDrill
vias (not micro vias) min drill diameter
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition: class_board.h:550
const wxSize & GetSize() const
Definition: class_pad.h:269
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:532
int m_ZoneClearance
Clearance value.
Definition: zone_settings.h:63
bool m_BlindBuriedViaAllowed
true to allow blind/buried vias
int m_MicroViasMinSize
micro vias (not vias) min diameter
const wxPoint & GetAuxOrigin() const
Definition: class_board.h:343
D_PAD m_Pad_Master
A dummy pad to store all default parameters.
std::vector< VIA_DIMENSION > m_ViasDimensionsList
Vias size and drill list.
bool m_MicroViasAllowed
true to allow micro vias
int m_MicroViasMinDrill
micro vias (not vias) min drill diameter
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControl=0) const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
int m_EdgeSegmentWidth
current graphic line width (EDGE layer only)
double m_SolderPasteMarginRatio
Solder pask margin ratio value of pad size The final margin is the sum of these 2 values...
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
int m_SolderMaskMinWidth
Solder mask min width.
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
const wxString GITHUB_PLUGIN::GetFileExtension ( ) const
overridevirtual

Function GetFileExtension returns the file extension for the PLUGIN.

Implements PLUGIN.

Definition at line 135 of file github_plugin.cpp.

136 {
137  return wxEmptyString;
138 }
long long GITHUB_PLUGIN::GetLibraryTimestamp ( const wxString &  aLibraryPath) const
overridevirtual

Generate a timestamp representing all the files in the library (including the library directory).

Timestamps should not be considered ordered; they either match or they don't.

Implements PLUGIN.

Definition at line 467 of file github_plugin.cpp.

References PCB_IO::GetLibraryTimestamp(), m_gh_cache, m_lib_path, and m_pretty_dir.

468 {
469  // This plugin currently relies on the nginx server for caching (see comments
470  // at top of file).
471  // Since only the nginx server holds the timestamp information, we must defeat
472  // all caching above the nginx server.
473  return wxDateTime::Now().GetValue().GetValue();
474 
475 #if 0
476  // If we have no cache, return a number which won't match any stored timestamps
477  if( !m_gh_cache || m_lib_path != aLibraryPath )
478  return wxDateTime::Now().GetValue().GetValue();
479 
480  long long hash = m_gh_cache->GetTimestamp();
481 
482  if( m_pretty_dir.size() )
484 
485  return hash;
486 #endif
487 }
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory)...
wxString m_lib_path
from aLibraryPath, something like https://github.com/liftoff-sr/pretty_footprints ...
wxString m_pretty_dir
GH_CACHE * m_gh_cache
std::string PCB_IO::GetStringOutput ( bool  doClear)
inlineinherited

Definition at line 160 of file pcbnew/kicad_plugin.h.

References STRING_FORMATTER::Clear(), STRING_FORMATTER::GetString(), and PCB_IO::m_sf.

Referenced by FOOTPRINT_EDIT_FRAME::Export_Module().

161  {
162  std::string ret = m_sf.GetString();
163  if( doClear )
164  m_sf.Clear();
165 
166  return ret;
167  }
const std::string & GetString()
Definition: richio.h:475
STRING_FORMATTER m_sf
void Clear()
Function Clear clears the buffer and empties the internal string.
Definition: richio.h:464
void GITHUB_PLUGIN::init ( const PROPERTIES aProperties)
protected
bool GITHUB_PLUGIN::IsFootprintLibWritable ( const wxString &  aLibraryPath)
overridevirtual

Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.

(Often system libraries are read only because of where they are installed.)

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
Exceptions
IO_ERRORif no library at aLibraryPath exists.

Reimplemented from PLUGIN.

Definition at line 245 of file github_plugin.cpp.

References PCB_IO::IsFootprintLibWritable(), and m_pretty_dir.

Referenced by FootprintDelete(), and FootprintSave().

246 {
247  if( m_pretty_dir.size() )
249  else
250  return false;
251 }
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
wxString m_pretty_dir
BOARD * PCB_IO::Load ( const wxString &  aFileName,
BOARD aAppendToMe,
const PROPERTIES aProperties = NULL 
)
overridevirtualinherited

Function Load loads information from some input file format that this PLUGIN implementation knows about, into either a new BOARD or an existing one.

This may be used to load an entire new BOARD, or to augment an existing one if aAppendToMe is not NULL.

Parameters
aFileNameis the name of the file to use as input and may be foreign in nature or native in nature.
aAppendToMeis an existing BOARD to append to, but if NULL then this means "do not append, rather load anew".
aPropertiesis an associative array that can be used to tell the loader how to load the file, because it can take any number of additional named arguments that the plugin is known to support. These are tuning parameters for the import or load. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
BOARD* - the successfully loaded board, or the same one as aAppendToMe if aAppendToMe was not NULL, and caller owns it.
Exceptions
IO_ERRORif there is a problem loading, and its contents should say what went wrong, using line number and character offsets of the input file if possible.

Reimplemented from PLUGIN.

Definition at line 1907 of file kicad_plugin.cpp.

References PCB_PARSER::GetRequiredVersion(), PCB_IO::init(), PCB_PARSER::IsTooRecent(), PCB_IO::m_parser, PCB_PARSER::Parse(), PCB_PARSER::SetBoard(), BOARD::SetFileName(), PCB_PARSER::SetLineReader(), and THROW_PARSE_ERROR.

Referenced by PCB_IO::GetFileExtension().

1908 {
1909  FILE_LINE_READER reader( aFileName );
1910 
1911  init( aProperties );
1912 
1913  m_parser->SetLineReader( &reader );
1914  m_parser->SetBoard( aAppendToMe );
1915 
1916  BOARD* board;
1917 
1918  try
1919  {
1920  board = dynamic_cast<BOARD*>( m_parser->Parse() );
1921  }
1922  catch( const FUTURE_FORMAT_ERROR& )
1923  {
1924  // Don't wrap a FUTURE_FORMAT_ERROR in another
1925  throw;
1926  }
1927  catch( const PARSE_ERROR& parse_error )
1928  {
1929  if( m_parser->IsTooRecent() )
1930  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
1931  else
1932  throw;
1933  }
1934 
1935  if( !board )
1936  {
1937  // The parser loaded something that was valid, but wasn't a board.
1938  THROW_PARSE_ERROR( _( "this file does not contain a PCB" ),
1939  m_parser->CurSource(), m_parser->CurLine(),
1940  m_parser->CurLineNumber(), m_parser->CurOffset() );
1941  }
1942 
1943  // Give the filename to the board if it's new
1944  if( !aAppendToMe )
1945  board->SetFileName( aFileName );
1946 
1947  return board;
1948 }
void init(const PROPERTIES *aProperties)
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:182
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
void SetBoard(BOARD *aBoard)
Definition: pcb_parser.h:296
void SetFileName(const wxString &aFileName)
Definition: class_board.h:232
PCB_PARSER * m_parser
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:442
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one...
Definition: pcb_parser.h:289
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:314
Struct PARSE_ERROR contains a filename or source description, a problem input line, a line number, a byte offset, and an error message which contains the the caller&#39;s report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:94
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:143
MODULE * PCB_IO::LoadEnumeratedFootprint ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
overridevirtualinherited

Function LoadEnumeratedFootprint a version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.

Reimplemented from PLUGIN.

Definition at line 2039 of file kicad_plugin.cpp.

References PCB_IO::doLoadFootprint().

Referenced by PCB_IO::GetFileExtension().

2042 {
2043  return doLoadFootprint( aLibraryPath, aFootprintName, aProperties, false );
2044 }
MODULE * doLoadFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)
BOARD_ITEM * PCB_IO::Parse ( const wxString &  aClipboardSourceInput)
inherited

Definition at line 414 of file kicad_plugin.cpp.

References TO_UTF8.

Referenced by CLIPBOARD_IO::Parse(), parse_module_kicad(), and PCB_IO::SetOutputFormatter().

415 {
416  std::string input = TO_UTF8( aClipboardSourceInput );
417 
418  STRING_LINE_READER reader( input, wxT( "clipboard" ) );
419 
420  m_parser->SetLineReader( &reader );
421 
422  try
423  {
424  return m_parser->Parse();
425  }
426  catch( const PARSE_ERROR& parse_error )
427  {
428  if( m_parser->IsTooRecent() )
429  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
430  else
431  throw;
432  }
433 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:182
PCB_PARSER * m_parser
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:442
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one...
Definition: pcb_parser.h:289
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:314
Struct PARSE_ERROR contains a filename or source description, a problem input line, a line number, a byte offset, and an error message which contains the the caller&#39;s report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:94
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:143
Class STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:254
const wxString GITHUB_PLUGIN::PluginName ( ) const
overridevirtual

Function PluginName returns a brief hard coded name for this PLUGIN.

Implements PLUGIN.

Definition at line 129 of file github_plugin.cpp.

130 {
131  return "Github";
132 }
void GITHUB_PLUGIN::PrefetchLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Function PrefetchLib If possible, prefetches the specified library (e.g.

performing downloads). Does not parse. Threadsafe.

This is a no-op for libraries that cannot be prefetched.

Plugins that cannot prefetch need not override this; a default no-op is provided.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aPropertiesis an associative array that can be used to tell the plugin anything needed about how to perform with respect to aLibraryPath. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is an error prefetching the library.

Reimplemented from PLUGIN.

Definition at line 173 of file github_plugin.cpp.

References m_lib_path, m_zip_image, and remoteGetZip().

175 {
176  if( m_lib_path != aLibraryPath )
177  {
178  m_zip_image.clear();
179  }
180 
181  remoteGetZip( aLibraryPath );
182 }
std::string m_zip_image
byte image of the zip file in its entirety.
wxString m_lib_path
from aLibraryPath, something like https://github.com/liftoff-sr/pretty_footprints ...
void remoteGetZip(const wxString &aRepoURL)
Function remoteGetZip fetches a zip file image from a github repo synchronously.
void GITHUB_PLUGIN::remoteGetZip ( const wxString &  aRepoURL)
protected

Function remoteGetZip fetches a zip file image from a github repo synchronously.

The byte image is received into the m_input_stream. If the image has already been stored, do nothing.

Definition at line 563 of file github_plugin.cpp.

References UTF8::c_str(), FootprintEnumerate(), Format(), KICAD_CURL_EASY::GetBuffer(), GetChars(), i, m_zip_image, main(), KICAD_CURL_EASY::Perform(), repoURL_zipURL(), KICAD_CURL_EASY::SetFollowRedirects(), KICAD_CURL_EASY::SetHeader(), KICAD_CURL_EASY::SetURL(), KICAD_CURL_EASY::SetUserAgent(), StrPrintf(), THROW_IO_ERROR, TO_UTF8, and IO_ERROR::What().

Referenced by cacheLib(), and PrefetchLib().

564 {
565  std::string zip_url;
566 
567  if( !m_zip_image.empty() )
568  return;
569 
570  if( !repoURL_zipURL( aRepoURL, &zip_url ) )
571  {
572  wxString msg = wxString::Format( _( "Unable to parse URL:\n\"%s\"" ), GetChars( aRepoURL ) );
573  THROW_IO_ERROR( msg );
574  }
575 
576  wxLogDebug( wxT( "Attempting to download: " ) + zip_url );
577 
578  KICAD_CURL_EASY kcurl; // this can THROW_IO_ERROR
579 
580  kcurl.SetURL( zip_url.c_str() );
581  kcurl.SetUserAgent( "http://kicad-pcb.org" );
582  kcurl.SetHeader( "Accept", "application/zip" );
583  kcurl.SetFollowRedirects( true );
584 
585  try
586  {
587  kcurl.Perform();
588  m_zip_image = kcurl.GetBuffer();
589  }
590  catch( const IO_ERROR& ioe )
591  {
592  // https "GET" has failed, report this to API caller.
593  // Note: kcurl.Perform() does not return an error if the file to download is not found
594  static const char errorcmd[] = "http GET command failed"; // Do not translate this message
595 
596  UTF8 fmt( _( "%s\nCannot get/download Zip archive: \"%s\"\nfor library path: \"%s\".\nReason: \"%s\"" ) );
597 
598  std::string msg = StrPrintf( fmt.c_str(),
599  errorcmd,
600  zip_url.c_str(),
601  TO_UTF8( aRepoURL ),
602  TO_UTF8( ioe.What() )
603  );
604 
605  THROW_IO_ERROR( msg );
606  }
607 
608  // If the zip archive is not existing, the received data is "Not Found" or "404: Not Found",
609  // and no error is returned by kcurl.Perform().
610  if( ( m_zip_image.compare( 0, 9, "Not Found", 9 ) == 0 ) ||
611  ( m_zip_image.compare( 0, 14, "404: Not Found", 14 ) == 0 ) )
612  {
613  UTF8 fmt( _( "Cannot download library \"%s\".\nThe library does not exist on the server" ) );
614  std::string msg = StrPrintf( fmt.c_str(), TO_UTF8( aRepoURL ) );
615 
616  THROW_IO_ERROR( msg );
617  }
618 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
bool SetUserAgent(const std::string &aAgent)
Function SetUserAgent sets the request user agent.
void Perform()
Function perform equivalent to curl_easy_perform.
bool SetFollowRedirects(bool aFollow)
Function SetFollowRedirects enables the following of HTTP(s) and other redirects, by default curl doe...
Class KICAD_CURL_EASY wrapper interface around the curl_easy API.
std::string m_zip_image
byte image of the zip file in its entirety.
int StrPrintf(std::string *result, const char *format,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:74
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
const std::string & GetBuffer()
Function GetBuffer returns a const reference to the recevied data buffer.
bool SetURL(const std::string &aURL)
Function SetURL sets the request URL.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
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...
void SetHeader(const std::string &aName, const std::string &aValue)
Function SetHeader sets an arbitrary header for the HTTP(s) request.
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
bool GITHUB_PLUGIN::repoURL_zipURL ( const wxString &  aRepoURL,
std::string *  aZipURL 
)
staticprotected

Function repoURL_zipURL translates a repo URL to a zipfile URL name as commonly seen on github.com.

Parameters
aRepoURLpoints to the base of the repo.
aZipURLis where to put the zip file URL.
Returns
bool - true if aRepoULR was parseable, else false

Definition at line 490 of file github_plugin.cpp.

Referenced by remoteGetZip().

491 {
492  // e.g. "https://github.com/liftoff-sr/pretty_footprints"
493  //D(printf("aRepoURL:%s\n", TO_UTF8( aRepoURL ) );)
494 
495  wxURI repo( aRepoURL );
496 
497  if( repo.HasServer() && repo.HasPath() )
498  {
499  // scheme might be "http" or if truly github.com then "https".
500  wxString zip_url;
501 
502  if( repo.GetServer() == "github.com" )
503  {
504  //codeload.github.com only supports https
505  zip_url = "https://";
506 #if 0 // A proper code path would be this one, but it is not the fastest.
507  zip_url += repo.GetServer();
508  zip_url += repo.GetPath(); // path comes with a leading '/'
509  zip_url += "/archive/master.zip";
510 #else
511  // Github issues a redirect for the "master.zip". i.e.
512  // "https://github.com/liftoff-sr/pretty_footprints/archive/master.zip"
513  // would be redirected to:
514  // "https://codeload.github.com/liftoff-sr/pretty_footprints/zip/master"
515 
516  // In order to bypass this redirect, saving time, we use the
517  // redirected URL on first attempt to save one HTTP GET hit.
518  zip_url += "codeload.github.com";
519  zip_url += repo.GetPath(); // path comes with a leading '/'
520  zip_url += "/zip/master";
521 #endif
522  }
523 
524  else
525  {
526  zip_url = repo.GetScheme();
527  zip_url += "://";
528 
529  // This is the generic code path for any server which can serve
530  // up zip files. The schemes tested include: http and https.
531 
532  // zip_url goal: "<scheme>://<server>[:<port>]/<path>"
533 
534  // Remember that <scheme>, <server>, <port> if present, and <path> all came
535  // from the lib_path in the fp-lib-table row.
536 
537  // This code path is used with the nginx proxy setup, but is useful
538  // beyond that.
539 
540  zip_url += repo.GetServer();
541 
542  if( repo.HasPort() )
543  {
544  zip_url += ':';
545  zip_url += repo.GetPort();
546  }
547 
548  zip_url += repo.GetPath(); // path comes with a leading '/'
549 
550  // Do not modify the path, we cannot anticipate the needs of all
551  // servers which are serving up zip files directly. URL modifications
552  // are more generally done in the server, rather than contaminating
553  // this code path with the needs of one particular inflexible server.
554  }
555 
556  *aZipURL = zip_url.utf8_str();
557  return true;
558  }
559  return false;
560 }
void PCB_IO::Save ( const wxString &  aFileName,
BOARD aBoard,
const PROPERTIES aProperties = NULL 
)
overridevirtualinherited

Function Save will write aBoard to a storage file in a format that this PLUGIN implementation knows about, or it can be used to write a portion of aBoard to a special kind of export file.

Parameters
aFileNameis the name of a file to save to on disk.
aBoardis the class BOARD in memory document tree from which to extract information when writing to aFileName. The caller continues to own the BOARD, and the plugin should refrain from modifying the BOARD if possible.
aPropertiesis an associative array that can be used to tell the saver how to save the file, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem saving or exporting.

Reimplemented from PLUGIN.

Reimplemented in CLIPBOARD_IO.

Definition at line 390 of file kicad_plugin.cpp.

References Format(), GetBuildVersion(), OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), and SEXPR_BOARD_FILE_VERSION.

Referenced by PCB_IO::GetFileExtension().

391 {
392  LOCALE_IO toggle; // toggles on, then off, the C locale.
393 
394  init( aProperties );
395 
396  m_board = aBoard; // after init()
397 
398  // Prepare net mapping that assures that net codes saved in a file are consecutive integers
399  m_mapping->SetBoard( aBoard );
400 
401  FILE_OUTPUTFORMATTER formatter( aFileName );
402 
403  m_out = &formatter; // no ownership
404 
405  m_out->Print( 0, "(kicad_pcb (version %d) (host pcbnew %s)\n", SEXPR_BOARD_FILE_VERSION,
406  formatter.Quotew( GetBuildVersion() ).c_str() );
407 
408  Format( aBoard, 1 );
409 
410  m_out->Print( 0, ")\n" );
411 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
void init(const PROPERTIES *aProperties)
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
void SetBoard(const BOARD *aBoard)
Function SetBoard Sets a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:281
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes ...
BOARD * m_board
which BOARD, no ownership here
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
void PCB_IO::SetOutputFormatter ( OUTPUTFORMATTER aFormatter)
inlineinherited

Definition at line 169 of file pcbnew/kicad_plugin.h.

References PCB_IO::m_out, and PCB_IO::Parse().

169 { m_out = aFormatter; }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
void PCB_IO::validateCache ( const wxString &  aLibraryPath,
bool  checkModified = true 
)
protectedinherited

Definition at line 1960 of file kicad_plugin.cpp.

References PCB_IO::FP_CACHE, FP_CACHE::IsModified(), FP_CACHE::IsPath(), FP_CACHE::Load(), and PCB_IO::m_cache.

Referenced by PCB_IO::doLoadFootprint(), PCB_IO::FootprintDelete(), PCB_IO::FootprintEnumerate(), PCB_IO::FootprintSave(), and PCB_IO::IsFootprintLibWritable().

1961 {
1962  if( !m_cache || !m_cache->IsPath( aLibraryPath ) || ( checkModified && m_cache->IsModified() ) )
1963  {
1964  // a spectacular episode in memory management:
1965  delete m_cache;
1966  m_cache = new FP_CACHE( this, aLibraryPath );
1967  m_cache->Load();
1968  }
1969 }
friend class FP_CACHE
bool IsModified()
Function IsModified Return true if the cache is not up-to-date.
FP_CACHE * m_cache
Footprint library cache.
bool IsPath(const wxString &aPath) const
Function IsPath checks if aPath is the same as the current cache path.
void Load()

Member Data Documentation

BOARD* PCB_IO::m_board
protectedinherited

which BOARD, no ownership here

Definition at line 176 of file pcbnew/kicad_plugin.h.

Referenced by PCB_IO::init(), CLIPBOARD_IO::Save(), CLIPBOARD_IO::SaveSelection(), and CLIPBOARD_IO::SetBoard().

int PCB_IO::m_ctl
protectedinherited

Definition at line 189 of file pcbnew/kicad_plugin.h.

Referenced by PCB_IO::FootprintSave().

wxString PCB_IO::m_error
protectedinherited

for throwing exceptions

Definition at line 175 of file pcbnew/kicad_plugin.h.

wxString PCB_IO::m_filename
protectedinherited

for saves only, name is in m_reader for loads

Definition at line 183 of file pcbnew/kicad_plugin.h.

GH_CACHE* GITHUB_PLUGIN::m_gh_cache
protected
wxString GITHUB_PLUGIN::m_lib_path
protected

from aLibraryPath, something like https://github.com/liftoff-sr/pretty_footprints

Definition at line 228 of file github_plugin.h.

Referenced by cacheLib(), GetLibraryTimestamp(), and PrefetchLib().

int PCB_IO::m_loading_format_version
protectedinherited

which SEXPR_BOARD_FILE_VERSION should be Load()ed?

Definition at line 185 of file pcbnew/kicad_plugin.h.

Referenced by PCB_IO::init().

NETINFO_MAPPING* PCB_IO::m_mapping
protectedinherited

mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes

Definition at line 191 of file pcbnew/kicad_plugin.h.

Referenced by CLIPBOARD_IO::Save(), CLIPBOARD_IO::SaveSelection(), and PCB_IO::~PCB_IO().

OUTPUTFORMATTER* PCB_IO::m_out
protectedinherited

output any Format()s to this, no ownership

Definition at line 188 of file pcbnew/kicad_plugin.h.

Referenced by CLIPBOARD_IO::CLIPBOARD_IO(), PCB_IO::PCB_IO(), CLIPBOARD_IO::Save(), and PCB_IO::SetOutputFormatter().

PCB_PARSER* PCB_IO::m_parser
protectedinherited

Definition at line 190 of file pcbnew/kicad_plugin.h.

Referenced by FootprintLoad(), PCB_IO::Load(), and PCB_IO::~PCB_IO().

const PROPERTIES* PCB_IO::m_props
protectedinherited

passed via Save() or Load(), no ownership, may be NULL.

Definition at line 179 of file pcbnew/kicad_plugin.h.

Referenced by PCB_IO::init().

LINE_READER* PCB_IO::m_reader
protectedinherited

no ownership here.

Definition at line 182 of file pcbnew/kicad_plugin.h.

Referenced by PCB_IO::init().

STRING_FORMATTER PCB_IO::m_sf
protectedinherited

Definition at line 187 of file pcbnew/kicad_plugin.h.

Referenced by PCB_IO::GetStringOutput(), and PCB_IO::PCB_IO().

std::string GITHUB_PLUGIN::m_zip_image
protected

byte image of the zip file in its entirety.

Definition at line 229 of file github_plugin.h.

Referenced by cacheLib(), FootprintLoad(), PrefetchLib(), and remoteGetZip().


The documentation for this class was generated from the following files: