2012-04-06 20:38:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
|
2021-07-19 23:56:05 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-04-06 20:38:32 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file module.i
|
2017-06-29 18:42:05 +00:00
|
|
|
* @brief Specific MODULE extensions and templates, and a few methods to access
|
|
|
|
* footprints in library files
|
2012-04-06 20:38:32 +00:00
|
|
|
*/
|
|
|
|
|
2016-09-21 01:07:41 +00:00
|
|
|
|
2021-01-25 05:51:44 +00:00
|
|
|
%template(MAP_STRING_STRING) std::map<wxString, wxString>;
|
2018-08-31 09:31:54 +00:00
|
|
|
%feature("flatnested");
|
2020-11-12 20:19:22 +00:00
|
|
|
%include footprint.h
|
2018-08-31 09:31:54 +00:00
|
|
|
%feature("flatnested", "");
|
2016-09-21 01:07:41 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
%rename(Get) operator FOOTPRINT*;
|
2016-09-21 01:07:41 +00:00
|
|
|
%{
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2016-09-21 01:07:41 +00:00
|
|
|
%}
|
2022-06-02 06:30:11 +00:00
|
|
|
%template(VECTOR_FP_3DMODEL) std::vector<FP_3DMODEL>;
|
2016-09-21 01:07:41 +00:00
|
|
|
|
2012-04-06 20:38:32 +00:00
|
|
|
|
2016-09-21 19:08:04 +00:00
|
|
|
// BOARD_ITEM_CONTAINER's interface functions will be implemented by SWIG
|
2016-09-23 00:12:36 +00:00
|
|
|
// automatically and inherited by the python wrapper class.
|
2016-09-21 19:08:04 +00:00
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
%extend FOOTPRINT
|
2014-10-02 17:09:32 +00:00
|
|
|
{
|
2016-09-21 01:07:41 +00:00
|
|
|
%pythoncode
|
|
|
|
%{
|
2014-10-02 17:09:32 +00:00
|
|
|
|
2012-04-06 20:38:32 +00:00
|
|
|
#def SaveToLibrary(self,filename):
|
2020-11-13 15:15:52 +00:00
|
|
|
# return SaveFootprintToLibrary(filename,self)
|
2014-10-02 17:09:32 +00:00
|
|
|
|
2012-04-06 20:38:32 +00:00
|
|
|
#
|
|
|
|
# add function, clears the thisown to avoid python from deleting
|
|
|
|
# the object in the garbage collector
|
|
|
|
#
|
2021-01-25 05:51:44 +00:00
|
|
|
|
2023-06-23 17:44:26 +00:00
|
|
|
def GetFieldsText(self):
|
|
|
|
""" Returns footprint fields name to text map. """
|
|
|
|
fields = self.GetFields()
|
2023-06-20 14:31:13 +00:00
|
|
|
return {str(field.GetName()): str(field.GetText()) for field in fields}
|
2021-01-25 05:51:44 +00:00
|
|
|
|
2023-06-23 17:44:26 +00:00
|
|
|
def GetFieldsShownText(self):
|
|
|
|
""" Returns footprint fields name to shown text map. """
|
|
|
|
fields = self.GetFields()
|
|
|
|
return {str(field.GetName()): str(field.GetShownText(False)) for field in fields}
|
|
|
|
|
|
|
|
def GetFieldText(self, key):
|
|
|
|
""" Returns Field text with a given key if it exists, throws KeyError otherwise. """
|
2023-06-20 14:31:13 +00:00
|
|
|
if self.HasFieldByName(key):
|
|
|
|
return self.GetFieldByName(key).GetText()
|
2022-01-03 04:21:07 +00:00
|
|
|
else:
|
2023-06-19 18:40:54 +00:00
|
|
|
raise KeyError("Field not found: " + key)
|
2022-01-03 04:21:07 +00:00
|
|
|
|
2023-06-23 17:44:26 +00:00
|
|
|
def GetFieldShownText(self, key):
|
|
|
|
""" Returns Field shown text with a given key if it exists, throws KeyError otherwise. """
|
|
|
|
if self.HasFieldByName(key):
|
|
|
|
return self.GetFieldByName(key).GetShownText(False)
|
|
|
|
else:
|
|
|
|
raise KeyError("Field not found: " + key)
|
|
|
|
|
2023-06-20 14:31:13 +00:00
|
|
|
def SetField(self, key, value):
|
|
|
|
if self.HasFieldByName(key):
|
|
|
|
self.GetFieldByName(key).SetText(value)
|
|
|
|
else:
|
|
|
|
field = PCB_FIELD(self, self.GetFieldCount(), key)
|
|
|
|
field.SetText(value)
|
|
|
|
self.AddField(field)
|
|
|
|
|
|
|
|
def HasField(self, key):
|
|
|
|
return self.HasFieldByName(key)
|
|
|
|
|
2023-06-19 18:40:54 +00:00
|
|
|
def SetFields(self, fields):
|
|
|
|
""" Sets footprint fields map. """
|
|
|
|
for k, v in fields.items():
|
2023-06-20 14:31:13 +00:00
|
|
|
self.SetField(k, v)
|
2021-01-25 05:51:44 +00:00
|
|
|
|
2016-09-21 01:07:41 +00:00
|
|
|
%}
|
2012-04-06 20:38:32 +00:00
|
|
|
}
|
|
|
|
|
2023-12-24 09:41:16 +00:00
|
|
|
|
|
|
|
%extend PCB_IO
|
2017-06-29 18:42:05 +00:00
|
|
|
{
|
|
|
|
// This version of FootprintEnumerate is for Python scripts, because the c++
|
|
|
|
// version of FootprintEnumerate is not easy to handle in these Python scripts
|
|
|
|
// if aExitOnError = true, footprintPyEnumerate throws a IO_ERROR.
|
|
|
|
// if false, errors are silently ignored
|
|
|
|
// in any case, only valid footprints are listed (especially for .pretty kicad libs
|
|
|
|
// and GEDA fp libs, which are folder containing separate fp files)
|
|
|
|
|
|
|
|
wxArrayString footprintPyEnumerate( const wxString& aLibraryPath, bool aExitOnError )
|
|
|
|
{
|
|
|
|
wxArrayString footprintNames;
|
|
|
|
|
2019-08-31 14:18:27 +00:00
|
|
|
self->FootprintEnumerate( footprintNames, aLibraryPath, !aExitOnError );
|
2017-06-29 18:42:05 +00:00
|
|
|
|
|
|
|
return footprintNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
%pythoncode
|
|
|
|
%{
|
|
|
|
def FootprintEnumerate(self, libname):
|
|
|
|
return self.footprintPyEnumerate( libname, True )
|
2023-12-27 00:25:41 +00:00
|
|
|
|
|
|
|
# Old function name for compatibility with pre-v8 scripts, use CreateLibrary() for new scripts.
|
|
|
|
def FootprintLibCreate(self, aLibraryPath, aProperties=None):
|
|
|
|
self.CreateLibrary(aLibraryPath, aProperties)
|
|
|
|
|
|
|
|
# Old function name for compatibility with pre-v8 scripts, use DeleteLibrary() for new scripts.
|
|
|
|
def FootprintLibDelete(self, aLibraryPath, aProperties=None):
|
|
|
|
return self.DeleteLibrary(aLibraryPath, aProperties)
|
|
|
|
|
|
|
|
# Old function name for compatibility with pre-v8 scripts, use IsLibraryWritable() for new scripts.
|
|
|
|
def IsFootprintLibWritable(self, aLibraryPath):
|
|
|
|
return self.IsLibraryWritable(aLibraryPath)
|
2017-06-29 18:42:05 +00:00
|
|
|
%}
|
|
|
|
}
|
2014-10-02 17:09:32 +00:00
|
|
|
|
2016-09-21 01:07:41 +00:00
|
|
|
%pythoncode
|
|
|
|
%{
|
2017-06-29 18:42:05 +00:00
|
|
|
def GetPluginForPath(libname):
|
2024-01-19 22:23:04 +00:00
|
|
|
plugin_type = PCB_IO_MGR.GuessPluginTypeFromLibPath( libname );
|
|
|
|
return PCB_IO_MGR.PluginFind(plugin_type)
|
2014-10-02 17:09:32 +00:00
|
|
|
|
2017-06-29 18:42:05 +00:00
|
|
|
def FootprintEnumerate(libname):
|
|
|
|
plug = GetPluginForPath(libname)
|
|
|
|
return plug.FootprintEnumerate(libname)
|
2014-10-02 17:09:32 +00:00
|
|
|
|
2022-06-29 19:09:07 +00:00
|
|
|
def FootprintLoad(libname,name,preserveUUID=False):
|
2017-06-29 18:42:05 +00:00
|
|
|
plug = GetPluginForPath(libname)
|
2022-06-29 19:09:07 +00:00
|
|
|
return plug.FootprintLoad(libname,name,preserveUUID)
|
2014-10-02 17:09:32 +00:00
|
|
|
|
2017-06-29 18:42:05 +00:00
|
|
|
def FootprintSave(libname,module):
|
|
|
|
plug = GetPluginForPath(libname)
|
|
|
|
return plug.FootprintSave(libname,module)
|
2014-10-02 17:09:32 +00:00
|
|
|
|
2017-06-29 18:42:05 +00:00
|
|
|
def FootprintDelete(libname,name):
|
|
|
|
plug = GetPluginForPath(libname)
|
|
|
|
plug.FootprintDelete(libname,name)
|
2014-10-02 17:09:32 +00:00
|
|
|
|
2017-06-29 18:42:05 +00:00
|
|
|
def FootprintLibCreate(libname):
|
|
|
|
plug = GetPluginForPath(libname)
|
2023-12-27 00:25:41 +00:00
|
|
|
plug.CreateLibrary(libname)
|
2014-10-02 17:09:32 +00:00
|
|
|
|
2017-06-29 18:42:05 +00:00
|
|
|
def FootprintLibDelete(libname):
|
|
|
|
plug = GetPluginForPath(libname)
|
2023-12-27 00:25:41 +00:00
|
|
|
plug.DeleteLibrary(libname)
|
2014-10-02 17:09:32 +00:00
|
|
|
|
2017-06-29 18:42:05 +00:00
|
|
|
def FootprintIsWritable(libname):
|
|
|
|
plug = GetPluginForPath(libname)
|
|
|
|
plug.FootprintLibIsWritable(libname)
|
2016-09-21 01:07:41 +00:00
|
|
|
%}
|
2012-05-10 08:53:05 +00:00
|
|
|
|
2016-09-21 19:08:04 +00:00
|
|
|
|
2012-05-10 08:53:05 +00:00
|
|
|
%{
|
2016-09-21 19:08:04 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2016-09-21 19:08:04 +00:00
|
|
|
// called from pcbnew/swig/pcbnew_footprint_wizards.cpp
|
2021-07-19 23:56:05 +00:00
|
|
|
FOOTPRINT* PyFootprint_to_FOOTPRINT( PyObject *obj0 )
|
2016-09-21 19:08:04 +00:00
|
|
|
{
|
|
|
|
void* argp;
|
2021-07-19 23:56:05 +00:00
|
|
|
int res1 = SWIG_ConvertPtr( obj0, &argp,SWIGTYPE_p_FOOTPRINT, 0 | 0 );
|
2020-11-13 15:15:52 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( !SWIG_IsOK( res1 ) )
|
2012-05-10 08:53:05 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
SWIG_exception_fail( SWIG_ArgError( res1 ), "Converting object to FOOTPRINT*" );
|
2016-09-21 19:08:04 +00:00
|
|
|
}
|
2014-10-02 17:09:32 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
return ( FOOTPRINT *) argp;
|
2014-10-02 17:09:32 +00:00
|
|
|
|
2016-09-21 19:08:04 +00:00
|
|
|
fail:
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2016-09-21 19:08:04 +00:00
|
|
|
}
|
2012-05-10 08:53:05 +00:00
|
|
|
|
2012-05-16 09:35:18 +00:00
|
|
|
%}
|