diff --git a/pcbnew/swig/pcbnew.i b/pcbnew/swig/pcbnew.i index ee6de535e4..1c194b3662 100644 --- a/pcbnew/swig/pcbnew.i +++ b/pcbnew/swig/pcbnew.i @@ -77,6 +77,8 @@ class BASE_SET {}; #include BOARD *GetBoard(); /* get current editor board */ +wxArrayString GetFootprintLibraries(); +wxArrayString GetFootprints(const wxString& aNickName); %} diff --git a/pcbnew/swig/pcbnew_scripting_helpers.cpp b/pcbnew/swig/pcbnew_scripting_helpers.cpp index 6223367def..9e846eccff 100644 --- a/pcbnew/swig/pcbnew_scripting_helpers.cpp +++ b/pcbnew/swig/pcbnew_scripting_helpers.cpp @@ -34,12 +34,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include 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 ) { if( s_PcbEditFrame ) diff --git a/pcbnew/swig/pcbnew_scripting_helpers.h b/pcbnew/swig/pcbnew_scripting_helpers.h index 7bc7d48382..2c341943a6 100644 --- a/pcbnew/swig/pcbnew_scripting_helpers.h +++ b/pcbnew/swig/pcbnew_scripting_helpers.h @@ -49,6 +49,21 @@ BOARD* LoadBoard( wxString& aFileName ); // so no option to choose the file format. 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. * See http://www.autotraxeda.com/docs/SPECCTRA/SPECCTRA.pdf for the