KiCad PCB EDA Suite
GPCB_PLUGIN Class Reference

GPCB_PLUGIN is a PLUGIN derivation for saving and loading Geda PCB files. More...

#include <gpcb_plugin.h>

Inheritance diagram for GPCB_PLUGIN:
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, bool aBestEfforts, const PROPERTIES *aProperties=NULL) override
 Return a list of footprint names contained within the library at aLibraryPath. More...
 
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...
 
MODULEFootprintLoad (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
 Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a library format that this PLUGIN knows about. 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 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. More...
 
long long GetLibraryTimestamp (const wxString &aLibraryPath) const override
 Generate a timestamp representing all the files in the library (including the library directory). More...
 
bool IsFootprintLibWritable (const wxString &aLibraryPath) override
 Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable. More...
 
 GPCB_PLUGIN ()
 
 GPCB_PLUGIN (int aControlFlags)
 
 ~GPCB_PLUGIN ()
 
virtual BOARDLoad (const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=NULL)
 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...
 
virtual void Save (const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=NULL)
 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...
 
virtual void PrefetchLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
 Function PrefetchLib If possible, prefetches the specified library (e.g. More...
 
virtual bool FootprintExists (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
 Function FootprintExists check for the existence of a footprint. More...
 
virtual void FootprintSave (const wxString &aLibraryPath, const MODULE *aFootprint, const PROPERTIES *aProperties=NULL)
 Function FootprintSave will write aModule to an existing library located at aLibraryPath. More...
 
virtual void FootprintLibCreate (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
 Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty. More...
 
virtual void FootprintLibOptions (PROPERTIES *aListToAppendTo) const
 Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 

Protected Attributes

wxString m_error
 for throwing exceptions More...
 
const PROPERTIESm_props
 passed via Save() or Load(), no ownership, may be NULL. More...
 
GPCB_FPL_CACHEm_cache
 Footprint library cache. More...
 
int m_ctl
 
LINE_READERm_reader
 no ownership here. More...
 
wxString m_filename
 for saves only, name is in m_reader for loads More...
 

Private Member Functions

void validateCache (const wxString &aLibraryPath, bool checkModified=true)
 
const MODULEgetFootprint (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)
 
void init (const PROPERTIES *aProperties)
 

Friends

class GPCB_FPL_CACHE
 

Detailed Description

GPCB_PLUGIN is a PLUGIN derivation for saving and loading Geda PCB files.

Note
This class is not thread safe, but it is re-entrant multiple times in sequence.
Currently only reading GPCB footprint files is implemented.

Definition at line 47 of file gpcb_plugin.h.

Constructor & Destructor Documentation

◆ GPCB_PLUGIN() [1/2]

GPCB_PLUGIN::GPCB_PLUGIN ( )

Definition at line 826 of file gpcb_plugin.cpp.

826  :
827  m_cache( 0 ),
828  m_ctl( 0 )
829 {
830  m_reader = NULL;
831  init( 0 );
832 }
void init(const PROPERTIES *aProperties)
GPCB_FPL_CACHE * m_cache
Footprint library cache.
Definition: gpcb_plugin.h:97
#define NULL
LINE_READER * m_reader
no ownership here.
Definition: gpcb_plugin.h:99

References init(), m_reader, and NULL.

◆ GPCB_PLUGIN() [2/2]

GPCB_PLUGIN::GPCB_PLUGIN ( int  aControlFlags)

Definition at line 835 of file gpcb_plugin.cpp.

835  :
836  m_cache( 0 ),
837  m_ctl( aControlFlags )
838 {
839  m_reader = NULL;
840  init( 0 );
841 }
void init(const PROPERTIES *aProperties)
GPCB_FPL_CACHE * m_cache
Footprint library cache.
Definition: gpcb_plugin.h:97
#define NULL
LINE_READER * m_reader
no ownership here.
Definition: gpcb_plugin.h:99

References init(), m_reader, and NULL.

◆ ~GPCB_PLUGIN()

GPCB_PLUGIN::~GPCB_PLUGIN ( )

Definition at line 844 of file gpcb_plugin.cpp.

845 {
846  delete m_cache;
847 }
GPCB_FPL_CACHE * m_cache
Footprint library cache.
Definition: gpcb_plugin.h:97

References m_cache.

Member Function Documentation

◆ FootprintDelete()

void GPCB_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 948 of file gpcb_plugin.cpp.

950 {
951  LOCALE_IO toggle; // toggles on, then off, the C locale.
952 
953  init( aProperties );
954 
955  validateCache( aLibraryPath );
956 
957  if( !m_cache->IsWritable() )
958  {
959  THROW_IO_ERROR( wxString::Format( _( "Library \"%s\" is read only" ),
960  aLibraryPath.GetData() ) );
961  }
962 
963  m_cache->Remove( aFootprintName );
964 }
bool IsWritable() const
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
void Remove(const wxString &aFootprintName)
void init(const PROPERTIES *aProperties)
GPCB_FPL_CACHE * m_cache
Footprint library cache.
Definition: gpcb_plugin.h:97
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 validateCache(const wxString &aLibraryPath, bool checkModified=true)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, Format(), init(), GPCB_FPL_CACHE::IsWritable(), m_cache, GPCB_FPL_CACHE::Remove(), THROW_IO_ERROR, and validateCache().

◆ FootprintEnumerate()

void GPCB_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 868 of file gpcb_plugin.cpp.

870 {
871  LOCALE_IO toggle; // toggles on, then off, the C locale.
872  wxDir dir( aLibraryPath );
873  wxString errorMsg;
874 
875  if( !dir.IsOpened() )
876  {
877  if( aBestEfforts )
878  return;
879  else
880  {
881  THROW_IO_ERROR( wxString::Format( _( "footprint library path \"%s\" does not exist" ),
882  aLibraryPath ) );
883  }
884  }
885 
886  init( aProperties );
887 
888  try
889  {
890  validateCache( aLibraryPath );
891  }
892  catch( const IO_ERROR& ioe )
893  {
894  errorMsg = ioe.What();
895  }
896 
897  // Some of the files may have been parsed correctly so we want to add the valid files to
898  // the library.
899 
900  for( MODULE_CITER it = m_cache->GetModules().begin(); it != m_cache->GetModules().end(); ++it )
901  aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
902 
903  if( !errorMsg.IsEmpty() && !aBestEfforts )
904  THROW_IO_ERROR( errorMsg );
905 }
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
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
MODULE_MAP & GetModules()
MODULE_MAP::const_iterator MODULE_CITER
void init(const PROPERTIES *aProperties)
GPCB_FPL_CACHE * m_cache
Footprint library cache.
Definition: gpcb_plugin.h:97
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
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 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
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, Format(), FROM_UTF8(), GPCB_FPL_CACHE::GetModules(), init(), m_cache, THROW_IO_ERROR, validateCache(), and IO_ERROR::What().

◆ FootprintExists()

bool PLUGIN::FootprintExists ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
virtualinherited

Function FootprintExists check for the existence of a footprint.

Reimplemented in PCB_IO.

Definition at line 85 of file plugin.cpp.

87 {
88  // default implementation
89  return FootprintLoad( aLibraryPath, aFootprintName, aProperties ) != nullptr;
90 }
virtual MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
Definition: plugin.cpp:93

References PLUGIN::FootprintLoad().

◆ FootprintLibCreate()

void PLUGIN::FootprintLibCreate ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
virtualinherited

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 in GITHUB_PLUGIN, and PCB_IO.

Definition at line 118 of file plugin.cpp.

119 {
120  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
121  not_implemented( this, __FUNCTION__ );
122 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: plugin.cpp:39

References not_implemented().

◆ FootprintLibDelete()

bool GPCB_PLUGIN::FootprintLibDelete ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
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 967 of file gpcb_plugin.cpp.

968 {
969  wxFileName fn;
970  fn.SetPath( aLibraryPath );
971 
972  // Return if there is no library path to delete.
973  if( !fn.DirExists() )
974  return false;
975 
976  if( !fn.IsDirWritable() )
977  {
978  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to delete directory \"%s\"" ),
979  aLibraryPath.GetData() ) );
980  }
981 
982  wxDir dir( aLibraryPath );
983 
984  if( dir.HasSubDirs() )
985  {
986  THROW_IO_ERROR( wxString::Format( _( "library directory \"%s\" has unexpected sub-directories" ),
987  aLibraryPath.GetData() ) );
988  }
989 
990  // All the footprint files must be deleted before the directory can be deleted.
991  if( dir.HasFiles() )
992  {
993  unsigned i;
994  wxFileName tmp;
995  wxArrayString files;
996 
997  wxDir::GetAllFiles( aLibraryPath, &files );
998 
999  for( i = 0; i < files.GetCount(); i++ )
1000  {
1001  tmp = files[i];
1002 
1003  if( tmp.GetExt() != KiCadFootprintFileExtension )
1004  {
1005  THROW_IO_ERROR( wxString::Format( _( "unexpected file \"%s\" was found in library path \"%s\"" ),
1006  files[i].GetData(), aLibraryPath.GetData() ) );
1007  }
1008  }
1009 
1010  for( i = 0; i < files.GetCount(); i++ )
1011  {
1012  wxRemoveFile( files[i] );
1013  }
1014  }
1015 
1016  wxLogTrace( traceGedaPcbPlugin, wxT( "Removing footprint library '%s'" ),
1017  aLibraryPath.GetData() );
1018 
1019  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
1020  // we don't want that. we want bare metal portability with no UI here.
1021  if( !wxRmdir( aLibraryPath ) )
1022  {
1023  THROW_IO_ERROR( wxString::Format( _( "footprint library \"%s\" cannot be deleted" ),
1024  aLibraryPath.GetData() ) );
1025  }
1026 
1027  // For some reason removing a directory in Windows is not immediately updated. This delay
1028  // prevents an error when attempting to immediately recreate the same directory when over
1029  // writing an existing library.
1030 #ifdef __WINDOWS__
1031  wxMilliSleep( 250L );
1032 #endif
1033 
1034  if( m_cache && m_cache->GetPath() == aLibraryPath )
1035  {
1036  delete m_cache;
1037  m_cache = NULL;
1038  }
1039 
1040  return true;
1041 }
wxString GetPath() const
const wxChar *const traceGedaPcbPlugin
Flag to enable GEDA PCB plugin debug output.
const std::string KiCadFootprintFileExtension
GPCB_FPL_CACHE * m_cache
Footprint library cache.
Definition: gpcb_plugin.h:97
#define NULL
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
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, Format(), GPCB_FPL_CACHE::GetPath(), KiCadFootprintFileExtension, m_cache, NULL, THROW_IO_ERROR, and traceGedaPcbPlugin.

◆ FootprintLibOptions()

void PLUGIN::FootprintLibOptions ( PROPERTIES aListToAppendTo) const
virtualinherited

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 in GITHUB_PLUGIN, and EAGLE_PLUGIN.

Definition at line 141 of file plugin.cpp.

142 {
143  // disable all these in another couple of months, after everyone has seen them:
144 #if 1
145  (*aListToAppendTo)["debug_level"] = UTF8( _(
146  "Enable <b>debug</b> logging for Footprint*() functions in this PLUGIN."
147  ));
148 
149  (*aListToAppendTo)["read_filter_regex"] = UTF8( _(
150  "Regular expression <b>footprint name</b> filter."
151  ));
152 
153  (*aListToAppendTo)["enable_transaction_logging"] = UTF8( _(
154  "Enable transaction logging. The mere presence of this option turns on the "
155  "logging, no need to set a Value."
156  ));
157 
158  (*aListToAppendTo)["username"] = UTF8( _(
159  "User name for <b>login</b> to some special library server."
160  ));
161 
162  (*aListToAppendTo)["password"] = UTF8( _(
163  "Password for <b>login</b> to some special library server."
164  ));
165 #endif
166 
167 #if 1
168  // Suitable for a C++ to python PLUGIN::Footprint*() adapter, move it to the adapter
169  // if and when implemented.
170  (*aListToAppendTo)["python_footprint_plugin"] = UTF8( _(
171  "Enter the python module which implements the PLUGIN::Footprint*() functions."
172  ));
173 #endif
174 }
UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to...
Definition: utf8.h:73
#define _(s)
Definition: 3d_actions.cpp:33

References _.

Referenced by EAGLE_PLUGIN::FootprintLibOptions(), and GITHUB_PLUGIN::FootprintLibOptions().

◆ FootprintLoad()

MODULE * GPCB_PLUGIN::FootprintLoad ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = NULL 
)
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 940 of file gpcb_plugin.cpp.

942 {
943  const MODULE* footprint = getFootprint( aLibraryPath, aFootprintName, aProperties, true );
944  return footprint ? (MODULE*) footprint->Duplicate() : nullptr;
945 }
const MODULE * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)
BOARD_ITEM * Duplicate() const override
Function Duplicate creates a copy of a BOARD_ITEM.

References MODULE::Duplicate(), and getFootprint().

◆ FootprintSave()

void PLUGIN::FootprintSave ( const wxString &  aLibraryPath,
const MODULE aFootprint,
const PROPERTIES aProperties = NULL 
)
virtualinherited

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 in GITHUB_PLUGIN, and PCB_IO.

Definition at line 102 of file plugin.cpp.

104 {
105  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
106  not_implemented( this, __FUNCTION__ );
107 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: plugin.cpp:39

References not_implemented().

◆ GetEnumeratedFootprint()

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

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

Reimplemented from PLUGIN.

Definition at line 932 of file gpcb_plugin.cpp.

935 {
936  return getFootprint( aLibraryPath, aFootprintName, aProperties, false );
937 }
const MODULE * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)

References getFootprint().

◆ GetFileExtension()

const wxString GPCB_PLUGIN::GetFileExtension ( ) const
inlineoverridevirtual

Function GetFileExtension returns the file extension for the PLUGIN.

Implements PLUGIN.

Definition at line 60 of file gpcb_plugin.h.

61  {
62  return wxT( "fp" );
63  }

◆ getFootprint()

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

Definition at line 908 of file gpcb_plugin.cpp.

912 {
913  LOCALE_IO toggle; // toggles on, then off, the C locale.
914 
915  init( aProperties );
916 
917  validateCache( aLibraryPath, checkModified );
918 
919  const MODULE_MAP& mods = m_cache->GetModules();
920 
921  MODULE_CITER it = mods.find( TO_UTF8( aFootprintName ) );
922 
923  if( it == mods.end() )
924  {
925  return NULL;
926  }
927 
928  return it->second->GetModule();
929 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
MODULE_MAP & GetModules()
MODULE_MAP::const_iterator MODULE_CITER
void init(const PROPERTIES *aProperties)
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_parser.h:51
#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
GPCB_FPL_CACHE * m_cache
Footprint library cache.
Definition: gpcb_plugin.h:97
#define NULL
void validateCache(const wxString &aLibraryPath, bool checkModified=true)

References GPCB_FPL_CACHE::GetModules(), init(), m_cache, NULL, TO_UTF8, and validateCache().

Referenced by FootprintLoad(), and GetEnumeratedFootprint().

◆ GetLibraryTimestamp()

long long GPCB_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 1044 of file gpcb_plugin.cpp.

1045 {
1046  return GPCB_FPL_CACHE::GetTimestamp( aLibraryPath );
1047 }
static long long GetTimestamp(const wxString &aLibPath)
Function GetTimestamp Generate a timestamp representing all source files in the cache (including the ...

References GPCB_FPL_CACHE::GetTimestamp().

◆ init()

void GPCB_PLUGIN::init ( const PROPERTIES aProperties)
private

Definition at line 850 of file gpcb_plugin.cpp.

851 {
852  m_props = aProperties;
853 }
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: gpcb_plugin.h:96

References m_props.

Referenced by FootprintDelete(), FootprintEnumerate(), getFootprint(), GPCB_PLUGIN(), and IsFootprintLibWritable().

◆ IsFootprintLibWritable()

bool GPCB_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 1050 of file gpcb_plugin.cpp.

1051 {
1052  LOCALE_IO toggle;
1053 
1054  init( NULL );
1055 
1056  validateCache( aLibraryPath );
1057 
1058  return m_cache->IsWritable();
1059 }
bool IsWritable() const
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
void init(const PROPERTIES *aProperties)
GPCB_FPL_CACHE * m_cache
Footprint library cache.
Definition: gpcb_plugin.h:97
#define NULL
void validateCache(const wxString &aLibraryPath, bool checkModified=true)

References init(), GPCB_FPL_CACHE::IsWritable(), m_cache, NULL, and validateCache().

◆ Load()

BOARD * PLUGIN::Load ( const wxString &  aFileName,
BOARD aAppendToMe,
const PROPERTIES aProperties = NULL 
)
virtualinherited

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 in PCB_IO, EAGLE_PLUGIN, LEGACY_PLUGIN, CADSTAR_PCB_ARCHIVE_PLUGIN, CLIPBOARD_IO, PCAD_PLUGIN, ALTIUM_CIRCUIT_MAKER_PLUGIN, ALTIUM_CIRCUIT_STUDIO_PLUGIN, and ALTIUM_DESIGNER_PLUGIN.

Definition at line 47 of file plugin.cpp.

48 {
49  not_implemented( this, __FUNCTION__ );
50  return NULL;
51 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: plugin.cpp:39
#define NULL

References not_implemented(), and NULL.

Referenced by PCBNEW_CONTROL::AppendBoard(), and IO_MGR::Load().

◆ PluginName()

const wxString GPCB_PLUGIN::PluginName ( ) const
inlineoverridevirtual

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

Implements PLUGIN.

Definition at line 55 of file gpcb_plugin.h.

56  {
57  return wxT( "Geda PCB" );
58  }

◆ PrefetchLib()

void PLUGIN::PrefetchLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
virtualinherited

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 in GITHUB_PLUGIN.

Definition at line 69 of file plugin.cpp.

70 {
71  (void) aLibraryPath;
72  (void) aProperties;
73 }

◆ Save()

void PLUGIN::Save ( const wxString &  aFileName,
BOARD aBoard,
const PROPERTIES aProperties = NULL 
)
virtualinherited

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 in PCB_IO, and CLIPBOARD_IO.

Definition at line 54 of file plugin.cpp.

55 {
56  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
57  not_implemented( this, __FUNCTION__ );
58 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: plugin.cpp:39

References not_implemented().

Referenced by IO_MGR::Save().

◆ validateCache()

void GPCB_PLUGIN::validateCache ( const wxString &  aLibraryPath,
bool  checkModified = true 
)
private

Definition at line 856 of file gpcb_plugin.cpp.

857 {
858  if( !m_cache || ( checkModified && m_cache->IsModified() ) )
859  {
860  // a spectacular episode in memory management:
861  delete m_cache;
862  m_cache = new GPCB_FPL_CACHE( this, aLibraryPath );
863  m_cache->Load();
864  }
865 }
GPCB_FPL_CACHE * m_cache
Footprint library cache.
Definition: gpcb_plugin.h:97
void Load()
Save not implemented for the Geda PCB footprint library format.
bool IsModified()
Function IsModified Return true if the cache is not up-to-date.
friend class GPCB_FPL_CACHE
Definition: gpcb_plugin.h:49

References GPCB_FPL_CACHE, GPCB_FPL_CACHE::IsModified(), GPCB_FPL_CACHE::Load(), and m_cache.

Referenced by FootprintDelete(), FootprintEnumerate(), getFootprint(), and IsFootprintLibWritable().

Friends And Related Function Documentation

◆ GPCB_FPL_CACHE

friend class GPCB_FPL_CACHE
friend

Definition at line 49 of file gpcb_plugin.h.

Referenced by validateCache().

Member Data Documentation

◆ m_cache

GPCB_FPL_CACHE* GPCB_PLUGIN::m_cache
protected

◆ m_ctl

int GPCB_PLUGIN::m_ctl
protected

Definition at line 98 of file gpcb_plugin.h.

◆ m_error

wxString GPCB_PLUGIN::m_error
protected

for throwing exceptions

Definition at line 95 of file gpcb_plugin.h.

◆ m_filename

wxString GPCB_PLUGIN::m_filename
protected

for saves only, name is in m_reader for loads

Definition at line 100 of file gpcb_plugin.h.

◆ m_props

const PROPERTIES* GPCB_PLUGIN::m_props
protected

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

Definition at line 96 of file gpcb_plugin.h.

Referenced by init().

◆ m_reader

LINE_READER* GPCB_PLUGIN::m_reader
protected

no ownership here.

Definition at line 99 of file gpcb_plugin.h.

Referenced by GPCB_PLUGIN().


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