Expose the footprint library table to Python

This commit is contained in:
Paul Ewing 2020-06-05 22:21:41 +00:00 committed by Jon Evans
parent fb4f37f39c
commit 40250c427a
3 changed files with 66 additions and 0 deletions

View File

@ -77,6 +77,8 @@ class BASE_SET {};
#include <exporters/gerber_jobfile_writer.h> #include <exporters/gerber_jobfile_writer.h>
BOARD *GetBoard(); /* get current editor board */ BOARD *GetBoard(); /* get current editor board */
wxArrayString GetFootprintLibraries();
wxArrayString GetFootprints(const wxString& aNickName);
%} %}

View File

@ -34,12 +34,14 @@
#include <build_version.h> #include <build_version.h>
#include <class_board.h> #include <class_board.h>
#include <cstdlib> #include <cstdlib>
#include <fp_lib_table.h>
#include <io_mgr.h> #include <io_mgr.h>
#include <kicad_string.h> #include <kicad_string.h>
#include <macros.h> #include <macros.h>
#include <pcb_draw_panel_gal.h> #include <pcb_draw_panel_gal.h>
#include <pcbnew.h> #include <pcbnew.h>
#include <pcbnew_scripting_helpers.h> #include <pcbnew_scripting_helpers.h>
#include <project.h>
static PCB_EDIT_FRAME* s_PcbEditFrame = NULL; static PCB_EDIT_FRAME* s_PcbEditFrame = NULL;
@ -105,6 +107,53 @@ bool SaveBoard( wxString& aFileName, BOARD* aBoard )
} }
FP_LIB_TABLE* GetFootprintLibraryTable()
{
BOARD* board = GetBoard();
if( !board )
return nullptr;
PROJECT* project = board->GetProject();
if( !project )
return nullptr;
return project->PcbFootprintLibs();
}
wxArrayString GetFootprintLibraries()
{
wxArrayString footprintLibraryNames;
FP_LIB_TABLE* tbl = GetFootprintLibraryTable();
if( !tbl )
return footprintLibraryNames;
for( const wxString& name : tbl->GetLogicalLibs() )
footprintLibraryNames.Add( name );
return footprintLibraryNames;
}
wxArrayString GetFootprints( const wxString& aNickName )
{
wxArrayString footprintNames;
FP_LIB_TABLE* tbl = GetFootprintLibraryTable();
if( !tbl )
return footprintNames;
tbl->FootprintEnumerate( footprintNames, aNickName, true );
return footprintNames;
}
bool ExportSpecctraDSN( wxString& aFullFilename ) bool ExportSpecctraDSN( wxString& aFullFilename )
{ {
if( s_PcbEditFrame ) if( s_PcbEditFrame )

View File

@ -49,6 +49,21 @@ BOARD* LoadBoard( wxString& aFileName );
// so no option to choose the file format. // so no option to choose the file format.
bool SaveBoard( wxString& aFileName, BOARD* aBoard ); bool SaveBoard( wxString& aFileName, BOARD* aBoard );
/**
* will get the nicknames of all of the footprint libraries configured in
* pcbnew in both the project and global library tables
* @return the list of footprint library nicknames, empty on error
*/
wxArrayString GetFootprintLibraries();
/**
* will get the names of all of the footprints available in a footprint library
* @param aNickName is the nickname specifying which footprint library to fetch
* from
* @return the list of footprint names, empty on error
*/
wxArrayString GetFootprints( const wxString& aNickName );
/** /**
* will export the current BOARD to a specctra dsn file. * will export the current BOARD to a specctra dsn file.
* See http://www.autotraxeda.com/docs/SPECCTRA/SPECCTRA.pdf for the * See http://www.autotraxeda.com/docs/SPECCTRA/SPECCTRA.pdf for the