KiCad PCB EDA Suite
GPCB_PLUGIN Class Reference

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
 Return a brief hard coded name for this PLUGIN. More...
 
const wxString GetFileExtension () const override
 Returns the file extension for the PLUGIN. More...
 
void FootprintEnumerate (wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const PROPERTIES *aProperties=nullptr) override
 Return a list of footprint names contained within the library at aLibraryPath. More...
 
const FOOTPRINTGetEnumeratedFootprint (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=nullptr) override
 A version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management. More...
 
FOOTPRINTFootprintLoad (const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const PROPERTIES *aProperties=nullptr) override
 Load 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=nullptr) override
 Delete aFootprintName from the library at aLibraryPath. More...
 
bool FootprintLibDelete (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Delete 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
 Return true if 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=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
 Load information from some input file format that this PLUGIN implementation knows about into either a new BOARD or an existing one. More...
 
virtual std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints ()
 Return a container with the cached library footprints generated in the last call to Load. More...
 
virtual void Save (const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=nullptr)
 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=nullptr)
 If possible, prefetches the specified library (e.g. More...
 
virtual bool FootprintExists (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=nullptr)
 Check for the existence of a footprint. More...
 
virtual void FootprintSave (const wxString &aLibraryPath, const FOOTPRINT *aFootprint, const PROPERTIES *aProperties=nullptr)
 Write aFootprint to an existing library located at aLibraryPath. More...
 
virtual void FootprintLibCreate (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
 Create a new empty footprint library at aLibraryPath empty. More...
 
virtual void FootprintLibOptions (PROPERTIES *aListToAppendTo) const
 Append 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 FOOTPRINTgetFootprint (const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)
 
void init (const PROPERTIES *aProperties)
 

Friends

class GPCB_FPL_CACHE
 

Detailed Description

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 46 of file gpcb_plugin.h.

Constructor & Destructor Documentation

◆ GPCB_PLUGIN() [1/2]

GPCB_PLUGIN::GPCB_PLUGIN ( )

Definition at line 820 of file gpcb_plugin.cpp.

820  :
821  m_cache( nullptr ),
822  m_ctl( 0 )
823 {
824  m_reader = nullptr;
825  init( nullptr );
826 }
void init(const PROPERTIES *aProperties)
GPCB_FPL_CACHE * m_cache
Footprint library cache.
Definition: gpcb_plugin.h:102
LINE_READER * m_reader
no ownership here.
Definition: gpcb_plugin.h:104

References init(), and m_reader.

◆ GPCB_PLUGIN() [2/2]

GPCB_PLUGIN::GPCB_PLUGIN ( int  aControlFlags)

Definition at line 829 of file gpcb_plugin.cpp.

829  :
830  m_cache( nullptr ),
831  m_ctl( aControlFlags )
832 {
833  m_reader = nullptr;
834  init( nullptr );
835 }
void init(const PROPERTIES *aProperties)
GPCB_FPL_CACHE * m_cache
Footprint library cache.
Definition: gpcb_plugin.h:102
LINE_READER * m_reader
no ownership here.
Definition: gpcb_plugin.h:104

References init(), and m_reader.

◆ ~GPCB_PLUGIN()

GPCB_PLUGIN::~GPCB_PLUGIN ( )

Definition at line 838 of file gpcb_plugin.cpp.

839 {
840  delete m_cache;
841 }
GPCB_FPL_CACHE * m_cache
Footprint library cache.
Definition: gpcb_plugin.h:102

References m_cache.

Member Function Documentation

◆ FootprintDelete()

void GPCB_PLUGIN::FootprintDelete ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Delete 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 950 of file gpcb_plugin.cpp.

952 {
953  LOCALE_IO toggle; // toggles on, then off, the C locale.
954 
955  init( aProperties );
956 
957  validateCache( aLibraryPath );
958 
959  if( !m_cache->IsWritable() )
960  {
961  THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only." ),
962  aLibraryPath.GetData() ) );
963  }
964 
965  m_cache->Remove( aFootprintName );
966 }
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:102
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
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 = nullptr 
)
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 862 of file gpcb_plugin.cpp.

864 {
865  LOCALE_IO toggle; // toggles on, then off, the C locale.
866  wxDir dir( aLibraryPath );
867  wxString errorMsg;
868 
869  if( !dir.IsOpened() )
870  {
871  if( aBestEfforts )
872  return;
873  else
874  {
875  THROW_IO_ERROR( wxString::Format( _( "Footprint library '%s' not found." ),
876  aLibraryPath ) );
877  }
878  }
879 
880  init( aProperties );
881 
882  try
883  {
884  validateCache( aLibraryPath );
885  }
886  catch( const IO_ERROR& ioe )
887  {
888  errorMsg = ioe.What();
889  }
890 
891  // Some of the files may have been parsed correctly so we want to add the valid files to
892  // the library.
893 
894  for( const auto& footprint : m_cache->GetFootprints() )
895  aFootprintNames.Add( FROM_UTF8( footprint.first.c_str() ) );
896 
897  if( !errorMsg.IsEmpty() && !aBestEfforts )
898  THROW_IO_ERROR( errorMsg );
899 }
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
FOOTPRINT_MAP & GetFootprints()
void init(const PROPERTIES *aProperties)
GPCB_FPL_CACHE * m_cache
Footprint library cache.
Definition: gpcb_plugin.h:102
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

◆ FootprintExists()

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

Check for the existence of a footprint.

Reimplemented in PCB_IO.

Definition at line 89 of file plugin.cpp.

91 {
92  // default implementation
93  return FootprintLoad( aLibraryPath, aFootprintName, true, aProperties ) != nullptr;
94 }
virtual FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const PROPERTIES *aProperties=nullptr)
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PL...
Definition: plugin.cpp:97

References PLUGIN::FootprintLoad().

◆ FootprintLibCreate()

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

Create 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 PCB_IO.

Definition at line 124 of file plugin.cpp.

125 {
126  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
127  not_implemented( this, __FUNCTION__ );
128 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Throw an IO_ERROR and complains of an API function not being implemented.
Definition: plugin.cpp:38

References not_implemented().

◆ FootprintLibDelete()

bool GPCB_PLUGIN::FootprintLibDelete ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Delete 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
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 969 of file gpcb_plugin.cpp.

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

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

◆ FootprintLibOptions()

void PLUGIN::FootprintLibOptions ( PROPERTIES aListToAppendTo) const
virtualinherited

Append 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
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 EAGLE_PLUGIN.

Definition at line 147 of file plugin.cpp.

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

References _.

Referenced by EAGLE_PLUGIN::FootprintLibOptions().

◆ FootprintLoad()

FOOTPRINT * GPCB_PLUGIN::FootprintLoad ( const wxString &  aLibraryPath,
const wxString &  aFootprintName,
bool  aKeepUUID = false,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Load 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.
aKeepUUID= true to keep initial items UUID, false to set new UUID normally true if loaded in the footprint editor, false if loaded in the board editor. Make sense only in kicad_plugin
Returns
the FOOTPRINT object 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 932 of file gpcb_plugin.cpp.

936 {
937  const FOOTPRINT* footprint = getFootprint( aLibraryPath, aFootprintName, aProperties, true );
938 
939  if( footprint )
940  {
941  FOOTPRINT* copy = (FOOTPRINT*) footprint->Duplicate();
942  copy->SetParent( nullptr );
943  return copy;
944  }
945 
946  return nullptr;
947 }
const FOOTPRINT * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)
BOARD_ITEM * Duplicate() const override
Create a copy of this BOARD_ITEM.
Definition: footprint.cpp:1706

References copy, FOOTPRINT::Duplicate(), and getFootprint().

◆ FootprintSave()

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

Write aFootprint 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 PCB_IO.

Definition at line 108 of file plugin.cpp.

110 {
111  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
112  not_implemented( this, __FUNCTION__ );
113 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Throw an IO_ERROR and complains of an API function not being implemented.
Definition: plugin.cpp:38

References not_implemented().

◆ GetEnumeratedFootprint()

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

A version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.

Reimplemented from PLUGIN.

Definition at line 924 of file gpcb_plugin.cpp.

927 {
928  return getFootprint( aLibraryPath, aFootprintName, aProperties, false );
929 }
const FOOTPRINT * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)

References getFootprint().

◆ GetFileExtension()

const wxString GPCB_PLUGIN::GetFileExtension ( ) const
inlineoverridevirtual

Returns the file extension for the PLUGIN.

Implements PLUGIN.

Definition at line 54 of file gpcb_plugin.h.

55  {
56  return wxT( "fp" );
57  }

◆ getFootprint()

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

Definition at line 902 of file gpcb_plugin.cpp.

906 {
907  LOCALE_IO toggle; // toggles on, then off, the C locale.
908 
909  init( aProperties );
910 
911  validateCache( aLibraryPath, checkModified );
912 
913  const FOOTPRINT_MAP& mods = m_cache->GetFootprints();
914 
915  FOOTPRINT_MAP::const_iterator it = mods.find( TO_UTF8( aFootprintName ) );
916 
917  if( it == mods.end() )
918  return nullptr;
919 
920  return it->second->GetFootprint();
921 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
FOOTPRINT_MAP & GetFootprints()
void init(const PROPERTIES *aProperties)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
GPCB_FPL_CACHE * m_cache
Footprint library cache.
Definition: gpcb_plugin.h:102
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
Definition: eagle_parser.h:50

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

Referenced by FootprintLoad(), and GetEnumeratedFootprint().

◆ GetImportedCachedLibraryFootprints()

std::vector< FOOTPRINT * > PLUGIN::GetImportedCachedLibraryFootprints ( )
virtualinherited

Return a container with the cached library footprints generated in the last call to Load.

This function is intended to be used ONLY by the non-KiCad board importers for the purpose of obtaining the footprint library of the design and creating a project-specific library.

Returns
Footprints (caller owns the objects)

Reimplemented in EAGLE_PLUGIN, and CADSTAR_PCB_ARCHIVE_PLUGIN.

Definition at line 54 of file plugin.cpp.

55 {
56  not_implemented( this, __FUNCTION__ );
57  return std::vector<FOOTPRINT*>();
58 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Throw an IO_ERROR and complains of an API function not being implemented.
Definition: plugin.cpp:38

References not_implemented().

Referenced by PCB_EDIT_FRAME::OpenProjectFiles().

◆ 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 1047 of file gpcb_plugin.cpp.

1048 {
1049  return GPCB_FPL_CACHE::GetTimestamp( aLibraryPath );
1050 }
static long long GetTimestamp(const wxString &aLibPath)
Generate a timestamp representing all source files in the cache (including the parent directory).

References GPCB_FPL_CACHE::GetTimestamp().

◆ init()

void GPCB_PLUGIN::init ( const PROPERTIES aProperties)
private

Definition at line 844 of file gpcb_plugin.cpp.

845 {
846  m_props = aProperties;
847 }
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: gpcb_plugin.h:101

References m_props.

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

◆ IsFootprintLibWritable()

bool GPCB_PLUGIN::IsFootprintLibWritable ( const wxString &  aLibraryPath)
overridevirtual

Return true if the library at aLibraryPath is writable.

The system libraries are typically 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 1053 of file gpcb_plugin.cpp.

1054 {
1055  LOCALE_IO toggle;
1056 
1057  init( nullptr );
1058 
1059  validateCache( aLibraryPath );
1060 
1061  return m_cache->IsWritable();
1062 }
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:102
void validateCache(const wxString &aLibraryPath, bool checkModified=true)

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

◆ Load()

BOARD * PLUGIN::Load ( const wxString &  aFileName,
BOARD aAppendToMe,
const PROPERTIES aProperties = nullptr,
PROJECT aProject = nullptr,
PROGRESS_REPORTER aProgressReporter = nullptr 
)
virtualinherited

Load 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.
aProjectis the optional PROJECT object primarily used by third party importers.
aProgressReporteran optional progress reporter
aLineCounta line count (necessary if a progress reporter is supplied)
Returns
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, CLIPBOARD_IO, ALTIUM_DESIGNER_PLUGIN, PCAD_PLUGIN, ALTIUM_CIRCUIT_MAKER_PLUGIN, ALTIUM_CIRCUIT_STUDIO_PLUGIN, CADSTAR_PCB_ARCHIVE_PLUGIN, and FABMASTER_PLUGIN.

Definition at line 46 of file plugin.cpp.

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

References not_implemented().

Referenced by PCB_CONTROL::AppendBoard(), IO_MGR::Load(), and PCB_EDIT_FRAME::OpenProjectFiles().

◆ PluginName()

const wxString GPCB_PLUGIN::PluginName ( ) const
inlineoverridevirtual

Return a brief hard coded name for this PLUGIN.

Implements PLUGIN.

Definition at line 49 of file gpcb_plugin.h.

50  {
51  return wxT( "Geda PCB" );
52  }

◆ PrefetchLib()

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

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.

Definition at line 75 of file plugin.cpp.

76 {
77 }

◆ Save()

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

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 60 of file plugin.cpp.

61 {
62  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
63  not_implemented( this, __FUNCTION__ );
64 }
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Throw an IO_ERROR and complains of an API function not being implemented.
Definition: plugin.cpp:38

References not_implemented().

Referenced by IO_MGR::Save().

◆ validateCache()

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

Definition at line 850 of file gpcb_plugin.cpp.

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

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 97 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 103 of file gpcb_plugin.h.

◆ m_error

wxString GPCB_PLUGIN::m_error
protected

for throwing exceptions

Definition at line 100 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 105 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 101 of file gpcb_plugin.h.

Referenced by init().

◆ m_reader

LINE_READER* GPCB_PLUGIN::m_reader
protected

no ownership here.

Definition at line 104 of file gpcb_plugin.h.

Referenced by GPCB_PLUGIN().


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