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 &aLibPath, bool aBestEfforts, 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...
 
BOARDDoLoad (LINE_READER &aReader, BOARD *aAppendToMe, const PROPERTIES *aProperties)
 
const MODULEGetEnumeratedFootprint (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
 Function GetEnumeratedFootprint a version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management. More...
 
bool FootprintExists (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
 Function FootprintExists check for the existence of a footprint. More...
 
void Format (BOARD_ITEM *aItem, int aNestLevel=0) const
 Output 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)
 
const MODULEgetFootprint (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 formatProperties (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::GITHUB_PLUGIN ( )

Definition at line 112 of file github_plugin.cpp.

112  :
113  PCB_IO(),
114  m_gh_cache( 0 )
115 {
116 }
PCB_IO(int aControlFlags=CTL_FOR_BOARD)
GH_CACHE * m_gh_cache

◆ ~GITHUB_PLUGIN()

GITHUB_PLUGIN::~GITHUB_PLUGIN ( )

Definition at line 119 of file github_plugin.cpp.

120 {
121  delete m_gh_cache;
122 }
GH_CACHE * m_gh_cache

References m_gh_cache.

Member Function Documentation

◆ cacheLib()

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

Definition at line 364 of file github_plugin.cpp.

365 {
366  // This is edge triggered based on a change in 'aLibraryPath',
367  // usually it does nothing. When the edge fires, m_pretty_dir is set
368  // to either:
369  // 1) empty or
370  // 2) a verified and validated, writable, *.pretty directory.
371 
372  if( !m_gh_cache || m_lib_path != aLibraryPath )
373  {
374  delete m_gh_cache;
375  m_gh_cache = 0;
376  m_pretty_dir.clear();
377 
378  if( !m_lib_path.empty() )
379  {
380  // Library path wasn't empty before - it's been changed. Flush out the prefetch cache.
381  m_zip_image.clear();
382  }
383 
384  if( aProperties )
385  {
386  UTF8 pretty_dir;
387 
388  if( aProperties->Value( PRETTY_DIR, &pretty_dir ) )
389  {
390  wxString wx_pretty_dir = pretty_dir;
391 
392  wx_pretty_dir = ExpandEnvVarSubstitutions( wx_pretty_dir, nullptr );
393 
394  wxFileName wx_pretty_fn = wx_pretty_dir;
395 
396  if( !wx_pretty_fn.IsOk() ||
397  !wx_pretty_fn.IsDirWritable() ||
398  wx_pretty_fn.GetExt() != "pretty"
399  )
400  {
401  wxString msg = wxString::Format(
402  _( "option \"%s\" for Github library \"%s\" must point to a writable directory ending with '.pretty'." ),
404  aLibraryPath
405  );
406 
407  THROW_IO_ERROR( msg );
408  }
409 
410  m_pretty_dir = wx_pretty_dir;
411  }
412  }
413 
414  // operator==( wxString, wxChar* ) does not exist, construct wxString once here.
415  const wxString kicad_mod( "kicad_mod" );
416 
417  m_gh_cache = new GH_CACHE();
418 
419  // INIT_LOGGER( "/tmp", "test.log" );
420  remoteGetZip( aLibraryPath );
421  // UNINIT_LOGGER();
422 
423  m_lib_path = aLibraryPath;
424 
425  wxMemoryInputStream mis( &m_zip_image[0], m_zip_image.size() );
426 
427  // Recently the zip standard adopted UTF8 encoded filenames within the
428  // internal zip directory block. Please only use zip files that conform
429  // to that standard. Github seems to now, but may not have earlier.
430  wxZipInputStream zis( mis, wxConvUTF8 );
431 
432  wxZipEntry* entry;
433  wxString fp_name;
434 
435  while( ( entry = zis.GetNextEntry() ) != NULL )
436  {
437  wxFileName fn( entry->GetName() ); // chop long name into parts
438 
439  if( fn.GetExt() == kicad_mod )
440  {
441  fp_name = fn.GetName(); // omit extension & path
442 
443  m_gh_cache->insert( fp_name, entry );
444  }
445  else
446  delete entry;
447  }
448  }
449 }
UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to...
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:109
const wxString ExpandEnvVarSubstitutions(const wxString &aString, PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp:255
std::string m_zip_image
byte image of the zip file in its entirety.
#define NULL
wxString m_lib_path
from aLibraryPath, something like https://github.com/liftoff-sr/pretty_footprints
wxString m_pretty_dir
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:201
#define _(s)
Definition: 3d_actions.cpp:33
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
GH_CACHE assists only within GITHUB_PLUGIN and holds a map of footprint name to wxZipEntry.
bool Value(const char *aName, UTF8 *aFetchedValue=NULL) const
Function Value fetches a property by aName and returns true if that property was found,...
Definition: properties.cpp:24
static const char * PRETTY_DIR

References _, ExpandEnvVarSubstitutions(), Format(), FROM_UTF8(), m_gh_cache, m_lib_path, m_pretty_dir, m_zip_image, NULL, PRETTY_DIR, remoteGetZip(), THROW_IO_ERROR, and PROPERTIES::Value().

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

◆ DoLoad()

BOARD * PCB_IO::DoLoad ( LINE_READER aReader,
BOARD aAppendToMe,
const PROPERTIES aProperties 
)
inherited

Definition at line 2069 of file kicad_plugin.cpp.

2070 {
2071  init( aProperties );
2072 
2073  m_parser->SetLineReader( &aReader );
2074  m_parser->SetBoard( aAppendToMe );
2075 
2076  BOARD* board;
2077 
2078  try
2079  {
2080  board = dynamic_cast<BOARD*>( m_parser->Parse() );
2081  }
2082  catch( const FUTURE_FORMAT_ERROR& )
2083  {
2084  // Don't wrap a FUTURE_FORMAT_ERROR in another
2085  throw;
2086  }
2087  catch( const PARSE_ERROR& parse_error )
2088  {
2089  if( m_parser->IsTooRecent() )
2090  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
2091  else
2092  throw;
2093  }
2094 
2095  if( !board )
2096  {
2097  // The parser loaded something that was valid, but wasn't a board.
2098  THROW_PARSE_ERROR( _( "this file does not contain a PCB" ),
2099  m_parser->CurSource(), m_parser->CurLine(),
2100  m_parser->CurLineNumber(), m_parser->CurOffset() );
2101  }
2102 
2103  return board;
2104 }
void init(const PROPERTIES *aProperties)
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:197
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:171
void SetBoard(BOARD *aBoard)
Definition: pcb_parser.h:374
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:485
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one,...
Definition: pcb_parser.h:367
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:395
Struct PARSE_ERROR contains a filename or source description, a problem input line,...
Definition: ki_exception.h:123
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
#define _(s)
Definition: 3d_actions.cpp:33
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:181

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

Referenced by PANEL_PCBNEW_COLOR_SETTINGS::createPreviewItems(), and PCB_IO::Load().

◆ FootprintDelete()

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 275 of file github_plugin.cpp.

277 {
278  // set m_pretty_dir to either empty or something in aProperties
279  cacheLib( aLibraryPath, aProperties );
280 
281  if( GITHUB_PLUGIN::IsFootprintLibWritable( aLibraryPath ) )
282  {
283  // Does the PCB_IO base class have this footprint?
284  // We cannot write to github.
285 
286  wxArrayString pretties;
287 
288  PCB_IO::FootprintEnumerate( pretties, m_pretty_dir, aProperties );
289 
290  if( pretties.Index( aFootprintName ) != wxNOT_FOUND )
291  {
292  PCB_IO::FootprintDelete( m_pretty_dir, aFootprintName, aProperties );
293  }
294  else
295  {
296  wxString msg = wxString::Format(
297  _( "Footprint\n\"%s\"\nis not in the writable portion of this Github library\n\"%s\"" ),
298  aFootprintName,
299  aLibraryPath
300  );
301 
302  THROW_IO_ERROR( msg );
303  }
304  }
305  else
306  {
307  // This typically will not happen if the caller first properly calls
308  // IsFootprintLibWritable() to determine if calling FootprintSave() is
309  // even legal, so I spend no time on internationalization here:
310 
311  string msg = StrPrintf( "Github library\n\"%s\"\nis only writable if you set option \"%s\" in Library Tables dialog.",
312  TO_UTF8( aLibraryPath ), PRETTY_DIR );
313 
314  THROW_IO_ERROR( msg );
315  }
316 }
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:78
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
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.
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:201
#define _(s)
Definition: 3d_actions.cpp:33
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const PROPERTIES *aProperties=NULL) override
Return a list of footprint names contained within the library at aLibraryPath.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
static const char * PRETTY_DIR

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

◆ FootprintEnumerate()

void GITHUB_PLUGIN::FootprintEnumerate ( wxArrayString &  aFootprintNames,
const wxString &  aLibraryPath,
bool  aBestEfforts,
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.
aBestEffortsif true, don't throw on errors, just return an empty list.
Exceptions
IO_ERRORif the library cannot be found, or footprint cannot be loaded.

Reimplemented from PLUGIN.

Definition at line 137 of file github_plugin.cpp.

139 {
140  try
141  {
142  cacheLib( aLibPath, aProperties );
143 
144  typedef std::set<wxString> MYSET;
145 
146  MYSET unique;
147 
148  if( m_pretty_dir.size() )
149  {
150  wxArrayString locals;
151 
152  PCB_IO::FootprintEnumerate( locals, m_pretty_dir, aBestEfforts );
153 
154  for( unsigned i=0; i<locals.GetCount(); ++i )
155  unique.insert( locals[i] );
156  }
157 
158  for( MODULE_ITER it = m_gh_cache->begin(); it!=m_gh_cache->end(); ++it )
159  unique.insert( it->first );
160 
161  for( MYSET::const_iterator it = unique.begin(); it != unique.end(); ++it )
162  aFootprintNames.Add( *it );
163  }
164  catch( const IO_ERROR& ioe )
165  {
166  if( !aBestEfforts )
167  throw ioe;
168  }
169 }
MODULE_MAP::iterator MODULE_ITER
void cacheLib(const wxString &aLibraryPath, const PROPERTIES *aProperties)
wxString m_pretty_dir
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const PROPERTIES *aProperties=NULL) override
Return a list of footprint names contained within the library at aLibraryPath.
GH_CACHE * m_gh_cache
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76

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

◆ FootprintExists()

bool PCB_IO::FootprintExists ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
overridevirtualinherited

Function FootprintExists check for the existence of a footprint.

Reimplemented from PLUGIN.

Definition at line 2194 of file kicad_plugin.cpp.

2196 {
2197  // Note: checking the cache sounds like a good idea, but won't catch files which differ
2198  // only in case.
2199  //
2200  // Since this goes out to the native filesystem, we get platform differences (ie: MSW's
2201  // case-insensitive filesystem) handled "for free".
2202  // Warning: footprint names frequently contain a point. So be careful when initializing
2203  // wxFileName, and use a CTOR with extension specified
2204  wxFileName footprintFile( aLibraryPath, aFootprintName, KiCadFootprintFileExtension );
2205 
2206  return footprintFile.Exists();
2207 }
const std::string KiCadFootprintFileExtension

References KiCadFootprintFileExtension.

◆ FootprintLibCreate()

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 319 of file github_plugin.cpp.

320 {
321  // set m_pretty_dir to either empty or something in aProperties
322  cacheLib( aLibraryPath, aProperties );
323 
324  if( m_pretty_dir.size() )
326 }
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

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

◆ FootprintLibDelete()

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 329 of file github_plugin.cpp.

330 {
331  // set m_pretty_dir to either empty or something in aProperties
332  cacheLib( aLibraryPath, aProperties );
333 
334  if( m_pretty_dir.size() )
335  return PCB_IO::FootprintLibDelete( m_pretty_dir, aProperties );
336 
337  return false;
338 }
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,...

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

◆ FootprintLibOptions()

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 341 of file github_plugin.cpp.

342 {
343  // inherit options supported by all PLUGINs.
344  PLUGIN::FootprintLibOptions( aListToAppendTo );
345 
346  (*aListToAppendTo)[ PRETTY_DIR ] = UTF8( _(
347  "Set this property to a directory where footprints are to be written as pretty "
348  "footprints when saving to this library. Anything saved will take precedence over "
349  "footprints by the same name in the github repo. These saved footprints can then "
350  "be sent to the library maintainer as updates. "
351  "<p>The directory <b>must</b> have a <b>.pretty</b> file extension because the "
352  "format of the save is pretty.</p>"
353  ));
354 
355  /*
356  (*aListToAppendTo)["cache_github_zip_in_this_dir"] = UTF8( _(
357  "Set this property to a directory where the github *.zip file will be cached. "
358  "This should speed up subsequent visits to this library."
359  ));
360  */
361 }
UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to...
Definition: utf8.h:73
virtual void FootprintLibOptions(PROPERTIES *aListToAppendTo) const
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
Definition: plugin.cpp:141
#define _(s)
Definition: 3d_actions.cpp:33
static const char * PRETTY_DIR

References _, PLUGIN::FootprintLibOptions(), and PRETTY_DIR.

◆ FootprintLoad()

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 184 of file github_plugin.cpp.

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

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

◆ FootprintSave()

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 251 of file github_plugin.cpp.

253 {
254  // set m_pretty_dir to either empty or something in aProperties
255  cacheLib( aLibraryPath, aProperties );
256 
257  if( GITHUB_PLUGIN::IsFootprintLibWritable( aLibraryPath ) )
258  {
259  PCB_IO::FootprintSave( m_pretty_dir, aFootprint, aProperties );
260  }
261  else
262  {
263  // This typically will not happen if the caller first properly calls
264  // IsFootprintLibWritable() to determine if calling FootprintSave() is
265  // even legal, so I spend no time on internationalization here:
266 
267  string msg = StrPrintf( "Github library\n\"%s\"\nis only writable if you set option \"%s\" in Library Tables dialog.",
268  TO_UTF8( aLibraryPath ), PRETTY_DIR );
269 
270  THROW_IO_ERROR( msg );
271  }
272 }
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:78
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
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

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

◆ Format()

void PCB_IO::Format ( BOARD_ITEM aItem,
int  aNestLevel = 0 
) const
inherited

Output 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 385 of file kicad_plugin.cpp.

386 {
387  LOCALE_IO toggle; // public API function, perform anything convenient for caller
388 
389  switch( aItem->Type() )
390  {
391  case PCB_T:
392  format( static_cast<BOARD*>( aItem ), aNestLevel );
393  break;
394 
395  case PCB_DIM_ALIGNED_T:
396  case PCB_DIM_CENTER_T:
398  case PCB_DIM_LEADER_T:
399  format( static_cast<DIMENSION*>( aItem ), aNestLevel );
400  break;
401 
402  case PCB_SHAPE_T:
403  format( static_cast<PCB_SHAPE*>( aItem ), aNestLevel );
404  break;
405 
406  case PCB_FP_SHAPE_T:
407  format( static_cast<FP_SHAPE*>( aItem ), aNestLevel );
408  break;
409 
410  case PCB_TARGET_T:
411  format( static_cast<PCB_TARGET*>( aItem ), aNestLevel );
412  break;
413 
414  case PCB_MODULE_T:
415  format( static_cast<MODULE*>( aItem ), aNestLevel );
416  break;
417 
418  case PCB_PAD_T:
419  format( static_cast<D_PAD*>( aItem ), aNestLevel );
420  break;
421 
422  case PCB_TEXT_T:
423  format( static_cast<PCB_TEXT*>( aItem ), aNestLevel );
424  break;
425 
426  case PCB_FP_TEXT_T:
427  format( static_cast<FP_TEXT*>( aItem ), aNestLevel );
428  break;
429 
430  case PCB_GROUP_T:
431  format( static_cast<PCB_GROUP*>( aItem ), aNestLevel );
432  break;
433 
434  case PCB_TRACE_T:
435  case PCB_ARC_T:
436  case PCB_VIA_T:
437  format( static_cast<TRACK*>( aItem ), aNestLevel );
438  break;
439 
440  case PCB_FP_ZONE_AREA_T:
441  case PCB_ZONE_AREA_T:
442  format( static_cast<ZONE_CONTAINER*>( aItem ), aNestLevel );
443  break;
444 
445  default:
446  wxFAIL_MSG( wxT( "Cannot format item " ) + aItem->GetClass() );
447  }
448 }
class ALIGNED_DIMENSION, a linear dimension (graphic item)
Definition: typeinfo.h:101
class ZONE_CONTAINER, managed by a footprint
Definition: typeinfo.h:95
class LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:102
Definition: typeinfo.h:85
class FP_TEXT, text in a footprint
Definition: typeinfo.h:93
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:109
class CENTER_DIMENSION, a center point marking (graphic item)
Definition: typeinfo.h:103
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:106
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
class MODULE, a footprint
Definition: typeinfo.h:89
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:105
virtual wxString GetClass() const =0
Function GetClass returns the class name.
void format(BOARD *aBoard, int aNestLevel=0) const
class ORTHOGONAL_DIMENSION, a linear dimension constrained to x/y
Definition: typeinfo.h:104
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:91
KICAD_T Type() const
Function Type()
Definition: eda_item.h:182

References PCB_IO::format(), EDA_ITEM::GetClass(), PCB_ARC_T, PCB_DIM_ALIGNED_T, PCB_DIM_CENTER_T, PCB_DIM_LEADER_T, PCB_DIM_ORTHOGONAL_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_ZONE_AREA_T, PCB_GROUP_T, PCB_MODULE_T, PCB_PAD_T, PCB_SHAPE_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::format(), CLIPBOARD_IO::Save(), FP_CACHE::Save(), PCB_IO::Save(), and CLIPBOARD_IO::SaveSelection().

◆ formatBoardLayers()

void PCB_IO::formatBoardLayers ( BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

formats the board layer information

Definition at line 504 of file kicad_plugin.cpp.

505 {
506  m_out->Print( aNestLevel, "(layers\n" );
507 
508  // Save only the used copper layers from front to back.
509 
510  for( LSEQ cu = aBoard->GetEnabledLayers().CuStack(); cu; ++cu )
511  {
512  PCB_LAYER_ID layer = *cu;
513 
514  m_out->Print( aNestLevel+1, "(%d %s %s", layer,
515  m_out->Quotew( LSET::Name( layer ) ).c_str(),
516  LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
517 
518  if( LSET::Name( layer ) != m_board->GetLayerName( layer ) )
519  m_out->Print( 0, " %s", m_out->Quotew( m_board->GetLayerName( layer ) ).c_str() );
520 
521  m_out->Print( 0, ")\n" );
522  }
523 
524  // Save used non-copper layers in the order they are defined.
525  // desired sequence for non Cu BOARD layers.
526  static const PCB_LAYER_ID non_cu[] =
527  {
528  B_Adhes, // 32
529  F_Adhes,
530  B_Paste,
531  F_Paste,
532  B_SilkS,
533  F_SilkS,
534  B_Mask,
535  F_Mask,
536  Dwgs_User,
537  Cmts_User,
538  Eco1_User,
539  Eco2_User,
540  Edge_Cuts,
541  Margin,
542  B_CrtYd,
543  F_CrtYd,
544  B_Fab,
545  F_Fab,
546  User_1,
547  User_2,
548  User_3,
549  User_4,
550  User_5,
551  User_6,
552  User_7,
553  User_8,
554  User_9
555  };
556 
557  for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, arrayDim( non_cu ) ); seq; ++seq )
558  {
559  PCB_LAYER_ID layer = *seq;
560 
561  m_out->Print( aNestLevel+1, "(%d %s user", layer,
562  m_out->Quotew( LSET::Name( layer ) ).c_str() );
563 
564  if( m_board->GetLayerName( layer ) != LSET::Name( layer ) )
565  m_out->Print( 0, " %s", m_out->Quotew( m_board->GetLayerName( layer ) ).c_str() );
566 
567  m_out->Print( 0, ")\n" );
568  }
569 
570  m_out->Print( aNestLevel, ")\n\n" );
571 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
LSEQ CuStack() const
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
Definition: lset.cpp:169
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings Returns a bit-mask of all t...
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:410
static const char * ShowType(LAYER_T aType)
Convert a LAYER_T enum to a string representation of the layer type.
PCB_LAYER_ID
A quick note on layer IDs:
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:81
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:121
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Return the type of the copper layer given by aLayer.
BOARD * m_board
which BOARD, no ownership here
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408

References arrayDim(), B_Adhes, B_CrtYd, B_Fab, B_Mask, B_Paste, B_SilkS, Cmts_User, LSET::CuStack(), 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(), PCB_IO::m_board, PCB_IO::m_out, Margin, LSET::Name(), OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), LSET::Seq(), LAYER::ShowType(), User_1, User_2, User_3, User_4, User_5, User_6, User_7, User_8, and User_9.

Referenced by PCB_IO::formatHeader(), and CLIPBOARD_IO::SaveSelection().

◆ formatGeneral()

void PCB_IO::formatGeneral ( BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

formats the General section of the file

Definition at line 488 of file kicad_plugin.cpp.

489 {
490  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
491 
492  m_out->Print( 0, "\n" );
493  m_out->Print( aNestLevel, "(general\n" );
494  m_out->Print( aNestLevel+1, "(thickness %s)\n",
495  FormatInternalUnits( dsnSettings.GetBoardThickness() ).c_str() );
496 
497  m_out->Print( aNestLevel, ")\n\n" );
498 
499  aBoard->GetPageSettings().Format( m_out, aNestLevel, m_ctl );
500  aBoard->GetTitleBlock().Format( m_out, aNestLevel, m_ctl );
501 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const PAGE_INFO & GetPageSettings() const
Definition: class_board.h:573
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: class_board.h:558
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:271
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the object to aFormatter in s-expression form.
Definition: title_block.cpp:28
TITLE_BLOCK & GetTitleBlock()
Definition: class_board.h:579
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.

References TITLE_BLOCK::Format(), PAGE_INFO::Format(), FormatInternalUnits(), BOARD_DESIGN_SETTINGS::GetBoardThickness(), BOARD::GetDesignSettings(), BOARD::GetPageSettings(), BOARD::GetTitleBlock(), PCB_IO::m_ctl, PCB_IO::m_out, and OUTPUTFORMATTER::Print().

Referenced by PCB_IO::formatHeader().

◆ formatHeader()

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 603 of file kicad_plugin.cpp.

604 {
605  formatGeneral( aBoard, aNestLevel );
606  // Layers list.
607  formatBoardLayers( aBoard, aNestLevel );
608 
609  // Setup
610  formatSetup( aBoard, aNestLevel );
611 
612  // Properties
613  formatProperties( aBoard, aNestLevel );
614 
615  // Save net codes and names
616  formatNetInformation( aBoard, aNestLevel );
617 }
void formatGeneral(BOARD *aBoard, int aNestLevel=0) const
formats the General section of the file
void formatNetInformation(BOARD *aBoard, int aNestLevel=0) const
formats the Nets and Netclasses
void formatProperties(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 formatBoardLayers(BOARD *aBoard, int aNestLevel=0) const
formats the board layer information

References PCB_IO::formatBoardLayers(), PCB_IO::formatGeneral(), PCB_IO::formatNetInformation(), PCB_IO::formatProperties(), and PCB_IO::formatSetup().

Referenced by PCB_IO::format().

◆ formatNetInformation()

void PCB_IO::formatNetInformation ( BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

formats the Nets and Netclasses

Definition at line 574 of file kicad_plugin.cpp.

575 {
576  for( NETINFO_ITEM* net : *m_mapping )
577  {
578  if( net == nullptr ) // Skip not actually existing nets (orphan nets)
579  continue;
580 
581  m_out->Print( aNestLevel, "(net %d %s)\n",
582  m_mapping->Translate( net->GetNet() ),
583  m_out->Quotew( net->GetNetname() ).c_str() );
584  }
585 
586  m_out->Print( 0, "\n" );
587 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function.

References PCB_IO::m_mapping, PCB_IO::m_out, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), and NETINFO_MAPPING::Translate().

Referenced by PCB_IO::formatHeader(), and CLIPBOARD_IO::SaveSelection().

◆ formatProperties()

void PCB_IO::formatProperties ( BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

formats the Nets and Netclasses

Definition at line 590 of file kicad_plugin.cpp.

591 {
592  for( const std::pair<const wxString, wxString>& prop : aBoard->GetProperties() )
593  {
594  m_out->Print( aNestLevel, "(property %s %s)\n",
595  m_out->Quotew( prop.first ).c_str(),
596  m_out->Quotew( prop.second ).c_str() );
597  }
598 
599  m_out->Print( 0, "\n" );
600 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const std::map< wxString, wxString > & GetProperties() const
Definition: class_board.h:307
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408

References BOARD::GetProperties(), PCB_IO::m_out, OUTPUTFORMATTER::Print(), and OUTPUTFORMATTER::Quotew().

Referenced by PCB_IO::formatHeader().

◆ formatSetup()

void PCB_IO::formatSetup ( BOARD aBoard,
int  aNestLevel = 0 
) const
protectedinherited

formats the board setup information

Definition at line 459 of file kicad_plugin.cpp.

460 {
461  // Setup
462  m_out->Print( aNestLevel, "(setup\n" );
463 
464  // Save the board physical stackup structure
466 
467  if( aBoard->GetDesignSettings().m_HasStackup )
468  stackup.FormatBoardStackup( m_out, aBoard, aNestLevel+1 );
469 
470  BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
471 
472  if( dsnSettings.m_AuxOrigin != wxPoint( 0, 0 ) )
473  m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
474  FormatInternalUnits( dsnSettings.m_AuxOrigin.x ).c_str(),
475  FormatInternalUnits( dsnSettings.m_AuxOrigin.y ).c_str() );
476 
477  if( dsnSettings.m_GridOrigin != wxPoint( 0, 0 ) )
478  m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
479  FormatInternalUnits( dsnSettings.m_GridOrigin.x ).c_str(),
480  FormatInternalUnits( dsnSettings.m_GridOrigin.y ).c_str() );
481 
482  aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 );
483 
484  m_out->Print( aNestLevel, ")\n\n" );
485 }
void FormatBoardStackup(OUTPUTFORMATTER *aFormatter, BOARD *aBoard, int aNestLevel) const
Writes the stackup info on board file.
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition: class_board.h:576
wxPoint m_GridOrigin
origin for grid offsets
this class manage the layers needed to make a physical board they are solder mask,...
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControl=0) const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: class_board.h:558
BOARD_STACKUP & GetStackupDescriptor()
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
wxPoint m_AuxOrigin
origin for plot exports
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.

References PCB_PLOT_PARAMS::Format(), BOARD_STACKUP::FormatBoardStackup(), FormatInternalUnits(), BOARD::GetDesignSettings(), BOARD::GetPlotOptions(), BOARD_DESIGN_SETTINGS::GetStackupDescriptor(), BOARD_DESIGN_SETTINGS::m_AuxOrigin, BOARD_DESIGN_SETTINGS::m_GridOrigin, BOARD_DESIGN_SETTINGS::m_HasStackup, PCB_IO::m_out, and OUTPUTFORMATTER::Print().

Referenced by PCB_IO::formatHeader().

◆ GetEnumeratedFootprint()

const MODULE * PCB_IO::GetEnumeratedFootprint ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
overridevirtualinherited

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

Reimplemented from PLUGIN.

Definition at line 2186 of file kicad_plugin.cpp.

2189 {
2190  return getFootprint( aLibraryPath, aFootprintName, aProperties, false );
2191 }
const MODULE * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)

References PCB_IO::getFootprint().

◆ GetFileExtension()

const wxString GITHUB_PLUGIN::GetFileExtension ( ) const
overridevirtual

Function GetFileExtension returns the file extension for the PLUGIN.

Implements PLUGIN.

Definition at line 131 of file github_plugin.cpp.

132 {
133  return wxEmptyString;
134 }

◆ getFootprint()

const MODULE * PCB_IO::getFootprint ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties,
bool  checkModified 
)
protectedinherited

Definition at line 2157 of file kicad_plugin.cpp.

2161 {
2162  LOCALE_IO toggle; // toggles on, then off, the C locale.
2163 
2164  init( aProperties );
2165 
2166  try
2167  {
2168  validateCache( aLibraryPath, checkModified );
2169  }
2170  catch( const IO_ERROR& )
2171  {
2172  // do nothing with the error
2173  }
2174 
2175  const MODULE_MAP& mods = m_cache->GetModules();
2176 
2177  MODULE_CITER it = mods.find( aFootprintName );
2178 
2179  if( it == mods.end() )
2180  return nullptr;
2181 
2182  return it->second->GetModule();
2183 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
FP_CACHE * m_cache
Footprint library cache.
void init(const PROPERTIES *aProperties)
MODULE_MAP::const_iterator MODULE_CITER
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_parser.h:51
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
MODULE_MAP & GetModules()

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

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

◆ GetLibraryTimestamp()

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 452 of file github_plugin.cpp.

453 {
454  // This plugin currently relies on the nginx server for caching (see comments
455  // at top of file).
456  // Since only the nginx server holds the timestamp information, we must defeat
457  // all caching above the nginx server.
458  return wxDateTime::Now().GetValue().GetValue();
459 
460 #if 0
461  // If we have no cache, return a number which won't match any stored timestamps
462  if( !m_gh_cache || m_lib_path != aLibraryPath )
463  return wxDateTime::Now().GetValue().GetValue();
464 
465  long long hash = m_gh_cache->GetTimestamp();
466 
467  if( m_pretty_dir.size() )
469 
470  return hash;
471 #endif
472 }
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

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

◆ GetStringOutput()

std::string PCB_IO::GetStringOutput ( bool  doClear)
inlineinherited

Definition at line 199 of file pcbnew/plugins/kicad/kicad_plugin.h.

200  {
201  std::string ret = m_sf.GetString();
202  if( doClear )
203  m_sf.Clear();
204 
205  return ret;
206  }
const std::string & GetString()
Definition: richio.h:476
void Clear()
Function Clear clears the buffer and empties the internal string.
Definition: richio.h:465

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

Referenced by FOOTPRINT_EDIT_FRAME::Export_Module().

◆ init()

void GITHUB_PLUGIN::init ( const PROPERTIES aProperties)
protected

◆ IsFootprintLibWritable()

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 242 of file github_plugin.cpp.

243 {
244  if( m_pretty_dir.size() )
246  else
247  return false;
248 }
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
wxString m_pretty_dir

References PCB_IO::IsFootprintLibWritable(), and m_pretty_dir.

Referenced by FootprintDelete(), and FootprintSave().

◆ Load()

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 2055 of file kicad_plugin.cpp.

2056 {
2057  FILE_LINE_READER reader( aFileName );
2058 
2059  BOARD* board = DoLoad( reader, aAppendToMe, aProperties );
2060 
2061  // Give the filename to the board if it's new
2062  if( !aAppendToMe )
2063  board->SetFileName( aFileName );
2064 
2065  return board;
2066 }
FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:181
void SetFileName(const wxString &aFileName)
Definition: class_board.h:277
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
BOARD * DoLoad(LINE_READER &aReader, BOARD *aAppendToMe, const PROPERTIES *aProperties)

References PCB_IO::DoLoad(), and BOARD::SetFileName().

◆ Parse()

BOARD_ITEM * PCB_IO::Parse ( const wxString &  aClipboardSourceInput)
inherited

Definition at line 363 of file kicad_plugin.cpp.

364 {
365  std::string input = TO_UTF8( aClipboardSourceInput );
366 
367  STRING_LINE_READER reader( input, wxT( "clipboard" ) );
368 
369  m_parser->SetLineReader( &reader );
370 
371  try
372  {
373  return m_parser->Parse();
374  }
375  catch( const PARSE_ERROR& parse_error )
376  {
377  if( m_parser->IsTooRecent() )
378  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
379  else
380  throw;
381  }
382 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:197
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:485
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one,...
Definition: pcb_parser.h:367
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:395
Struct PARSE_ERROR contains a filename or source description, a problem input line,...
Definition: ki_exception.h:123
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:181
STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:255

References PCB_PARSER::GetRequiredVersion(), PCB_PARSER::IsTooRecent(), PCB_IO::m_parser, PCB_PARSER::Parse(), PCB_PARSER::SetLineReader(), and TO_UTF8.

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

◆ PluginName()

const wxString GITHUB_PLUGIN::PluginName ( ) const
overridevirtual

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

Implements PLUGIN.

Definition at line 125 of file github_plugin.cpp.

126 {
127  return "Github";
128 }

◆ PrefetchLib()

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 172 of file github_plugin.cpp.

174 {
175  if( m_lib_path != aLibraryPath )
176  {
177  m_zip_image.clear();
178  }
179 
180  remoteGetZip( aLibraryPath );
181 }
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.

References m_lib_path, m_zip_image, and remoteGetZip().

◆ remoteGetZip()

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 547 of file github_plugin.cpp.

548 {
549  std::string zip_url;
550 
551  if( !m_zip_image.empty() )
552  return;
553 
554  if( !repoURL_zipURL( aRepoURL, &zip_url ) )
555  {
556  wxString msg = wxString::Format( _( "Unable to parse URL:\n\"%s\"" ), aRepoURL );
557  THROW_IO_ERROR( msg );
558  }
559 
560  KICAD_CURL_EASY kcurl; // this can THROW_IO_ERROR
561 
562  kcurl.SetURL( zip_url.c_str() );
563  kcurl.SetUserAgent( "http://kicad-pcb.org" );
564  kcurl.SetHeader( "Accept", "application/zip" );
565  kcurl.SetFollowRedirects( true );
566 
567  try
568  {
569  kcurl.Perform();
570  m_zip_image = kcurl.GetBuffer();
571  }
572  catch( const IO_ERROR& ioe )
573  {
574  // https "GET" has failed, report this to API caller.
575  // Note: kcurl.Perform() does not return an error if the file to download is not found
576  static const char errorcmd[] = "http GET command failed"; // Do not translate this message
577 
578  UTF8 fmt( _( "%s\nCannot get/download Zip archive: \"%s\"\nfor library path: \"%s\".\nReason: \"%s\"" ) );
579 
580  std::string msg = StrPrintf( fmt.c_str(),
581  errorcmd,
582  zip_url.c_str(),
583  TO_UTF8( aRepoURL ),
584  TO_UTF8( ioe.What() )
585  );
586 
587  THROW_IO_ERROR( msg );
588  }
589 
590  // If the zip archive is not existing, the received data is "Not Found" or "404: Not Found",
591  // and no error is returned by kcurl.Perform().
592  if( ( m_zip_image.compare( 0, 9, "Not Found", 9 ) == 0 ) ||
593  ( m_zip_image.compare( 0, 14, "404: Not Found", 14 ) == 0 ) )
594  {
595  UTF8 fmt( _( "Cannot download library \"%s\".\nThe library does not exist on the server" ) );
596  std::string msg = StrPrintf( fmt.c_str(), TO_UTF8( aRepoURL ) );
597 
598  THROW_IO_ERROR( msg );
599  }
600 }
UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to...
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...
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:78
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
const std::string & GetBuffer()
Function GetBuffer returns a const reference to the recevied data buffer.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
bool SetURL(const std::string &aURL)
Function SetURL sets the request URL.
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:201
#define _(s)
Definition: 3d_actions.cpp:33
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:76
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, UTF8::c_str(), Format(), KICAD_CURL_EASY::GetBuffer(), m_zip_image, 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().

◆ repoURL_zipURL()

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 475 of file github_plugin.cpp.

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

Referenced by remoteGetZip().

◆ Save()

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 325 of file kicad_plugin.cpp.

326 {
327  LOCALE_IO toggle; // toggles on, then off, the C locale.
328 
329  wxString sanityResult = aBoard->GroupsSanityCheck();
330 
331  if( sanityResult != wxEmptyString )
332  {
333  KIDIALOG dlg( nullptr, wxString::Format(
334  _( "Please report this bug. Error validating group structure: %s"
335  "\n\nSave anyway?" ), sanityResult ),
336  _( "Internal group data structure corrupt" ),
337  wxOK | wxCANCEL | wxICON_ERROR );
338  dlg.SetOKLabel( _( "Save Anyway" ) );
339 
340  if( dlg.ShowModal() == wxID_CANCEL )
341  return;
342  }
343 
344  init( aProperties );
345 
346  m_board = aBoard; // after init()
347 
348  // Prepare net mapping that assures that net codes saved in a file are consecutive integers
349  m_mapping->SetBoard( aBoard );
350 
351  FILE_OUTPUTFORMATTER formatter( aFileName );
352 
353  m_out = &formatter; // no ownership
354 
355  m_out->Print( 0, "(kicad_pcb (version %d) (generator pcbnew)\n", SEXPR_BOARD_FILE_VERSION );
356 
357  Format( aBoard, 1 );
358 
359  m_out->Print( 0, ")\n" );
360 }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: confirm.h:44
void init(const PROPERTIES *aProperties)
void SetBoard(const BOARD *aBoard)
Function SetBoard Sets a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:296
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
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:201
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
#define _(s)
Definition: 3d_actions.cpp:33
BOARD * m_board
which BOARD, no ownership here
FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:493
wxString GroupsSanityCheck(bool repair=false)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Output aItem to aFormatter in s-expression format.

References _, PCB_IO::Format(), Format(), BOARD::GroupsSanityCheck(), PCB_IO::init(), PCB_IO::m_board, PCB_IO::m_mapping, PCB_IO::m_out, OUTPUTFORMATTER::Print(), NETINFO_MAPPING::SetBoard(), SEXPR_BOARD_FILE_VERSION, and KIDIALOG::ShowModal().

Referenced by KI_TEST::DumpBoardToFile(), and ROUTER_TOOL::handleCommonEvents().

◆ SetOutputFormatter()

void PCB_IO::SetOutputFormatter ( OUTPUTFORMATTER aFormatter)
inlineinherited

Definition at line 208 of file pcbnew/plugins/kicad/kicad_plugin.h.

208 { m_out = aFormatter; }
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership

References PCB_IO::m_out.

Referenced by FP_CACHE::Save().

◆ validateCache()

void PCB_IO::validateCache ( const wxString &  aLibraryPath,
bool  checkModified = true 
)
protectedinherited

Definition at line 2116 of file kicad_plugin.cpp.

2117 {
2118  if( !m_cache || !m_cache->IsPath( aLibraryPath ) || ( checkModified && m_cache->IsModified() ) )
2119  {
2120  // a spectacular episode in memory management:
2121  delete m_cache;
2122  m_cache = new FP_CACHE( this, aLibraryPath );
2123  m_cache->Load();
2124  }
2125 }
bool IsModified()
Return true if the cache is not up-to-date.
FP_CACHE * m_cache
Footprint library cache.
bool IsPath(const wxString &aPath) const
Check if aPath is the same as the current cache path.
void Load()

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

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

Member Data Documentation

◆ m_board

BOARD* PCB_IO::m_board
protectedinherited

◆ m_cache

◆ m_ctl

int PCB_IO::m_ctl
protectedinherited

◆ m_error

wxString PCB_IO::m_error
protectedinherited

for throwing exceptions

Definition at line 214 of file pcbnew/plugins/kicad/kicad_plugin.h.

◆ m_filename

wxString PCB_IO::m_filename
protectedinherited

for saves only, name is in m_reader for loads

Definition at line 222 of file pcbnew/plugins/kicad/kicad_plugin.h.

◆ m_gh_cache

GH_CACHE* GITHUB_PLUGIN::m_gh_cache
protected

◆ m_lib_path

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().

◆ m_loading_format_version

int PCB_IO::m_loading_format_version
protectedinherited

which SEXPR_BOARD_FILE_VERSION should be Load()ed?

Definition at line 224 of file pcbnew/plugins/kicad/kicad_plugin.h.

Referenced by PCB_IO::init().

◆ m_mapping

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 230 of file pcbnew/plugins/kicad/kicad_plugin.h.

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

◆ m_out

◆ m_parser

PCB_PARSER* PCB_IO::m_parser
protectedinherited

◆ m_pretty_dir

◆ m_props

const PROPERTIES* PCB_IO::m_props
protectedinherited

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

Definition at line 218 of file pcbnew/plugins/kicad/kicad_plugin.h.

Referenced by PCB_IO::init().

◆ m_reader

LINE_READER* PCB_IO::m_reader
protectedinherited

no ownership here.

Definition at line 221 of file pcbnew/plugins/kicad/kicad_plugin.h.

Referenced by PCB_IO::init().

◆ m_sf

STRING_FORMATTER PCB_IO::m_sf
protectedinherited

Definition at line 226 of file pcbnew/plugins/kicad/kicad_plugin.h.

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

◆ m_zip_image

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: