KicadModTree package

KicadModTree.FileHandler module

class KicadModTree.FileHandler.FileHandler(kicad_mod)[source]

Bases: object

some basic methods to write footprints, and which is the base class of footprint writer implementations

Parameters:kicad_mod (KicadModTree.Footprint) – Main object representing the footprint
Example:
>>> from KicadModTree import *
>>> kicad_mod = Footprint("example_footprint")
>>> file_handler = KicadFileHandler(kicad_mod)  # KicadFileHandler is a implementation of FileHandler
>>> file_handler.writeFile('example_footprint.kicad_mod')
serialize(**kwargs)[source]

Get a valid string representation of the footprint in the specified format

Example:
>>> from KicadModTree import *
>>> kicad_mod = Footprint("example_footprint")
>>> file_handler = KicadFileHandler(kicad_mod)  # KicadFileHandler is a implementation of FileHandler
>>> print(file_handler.serialize())
writeFile(filename, **kwargs)[source]

Write the output of FileHandler.serialize to a file

Parameters:filename (str) – path of the output file
Example:
>>> from KicadModTree import *
>>> kicad_mod = Footprint("example_footprint")
>>> file_handler = KicadFileHandler(kicad_mod)  # KicadFileHandler is a implementation of FileHandler
>>> file_handler.writeFile('example_footprint.kicad_mod')

KicadModTree.KicadFileHandler module

class KicadModTree.KicadFileHandler.KicadFileHandler(kicad_mod)[source]

Bases: KicadModTree.FileHandler.FileHandler

Implementation of the FileHandler for .kicad_mod files

Parameters:kicad_mod (KicadModTree.Footprint) – Main object representing the footprint
Example:
>>> from KicadModTree import *
>>> kicad_mod = Footprint("example_footprint")
>>> file_handler = KicadFileHandler(kicad_mod)
>>> file_handler.writeFile('example_footprint.kicad_mod')
serialize(**kwargs)[source]

Get a valid string representation of the footprint in the .kicad_mod format

Example:
>>> from KicadModTree import *
>>> kicad_mod = Footprint("example_footprint")
>>> file_handler = KicadFileHandler(kicad_mod)
>>> print(file_handler.serialize())
writeFile(filename, **kwargs)

Write the output of FileHandler.serialize to a file

Parameters:filename (str) – path of the output file
Example:
>>> from KicadModTree import *
>>> kicad_mod = Footprint("example_footprint")
>>> file_handler = KicadFileHandler(kicad_mod)  # KicadFileHandler is a implementation of FileHandler
>>> file_handler.writeFile('example_footprint.kicad_mod')

KicadModTree.ModArgparser module

class KicadModTree.ModArgparser.ModArgparser(footprint_function)[source]

Bases: object

A general data loading class, which allows us to specify parts using .yml or .csv files.

Using this class allows us to seperate between the implementation of a footprint generator, and the data which represents a single footprint. To do so, we need to define which parameters are expected in those data-files.

To improve the usablity of this class, it is able to do type checks of provided parameters, as well as defining default values and do a simple check if a parameter can be considered as required or optional.

Parameters:footprint_function (function reference) – A function which is called for every footprint we want to generate
Example:
>>> from KicadModTree import *
>>> def footprint_gen(args):
...    print("create footprint: {}".format(args['name']))
...
>>> parser = ModArgparser(footprint_gen)
>>> parser.add_parameter("name", type=str, required=True)  # the root node of .yml files is parsed as name
>>> parser.add_parameter("datasheet", type=str, required=False)
>>> parser.add_parameter("courtyard", type=float, required=False, default=0.25)
>>> parser.add_parameter("pincount", type=int, required=True)
>>> parser.run()  # now run our script which handles the whole part of parsing the files
add_parameter(name, **kwargs)[source]

Add a parameter to the ModArgparser

Parameters:
  • name (str) – name of the argument
  • **kwargs – See below
Keyword Arguments:
 
  • type (type) – type of the argument
  • required (bool) – is the argument required or optional
  • default – a default value which is used when there is no value defined
Example:
>>> from KicadModTree import *
>>> def footprint_gen(args):
...    print("create footprint: {}".format(args['name']))
...
>>> parser = ModArgparser(footprint_gen)
>>> parser.add_parameter("name", type=str, required=True)  # the root node of .yml files is parsed as name
>>> parser.add_parameter("datasheet", type=str, required=False)
>>> parser.add_parameter("courtyard", type=float, required=False, default=0.25)
run()[source]

Execute the ModArgparser and run all tasks defined via the commandline arguments of this script

This method parses the commandline arguments to determine which actions to take. Beside of parsing .yml and .csv files, it also allows us to output example files.

>>> from KicadModTree import *
>>> def footprint_gen(args):
...    print("create footprint: {}".format(args['name']))
...
>>> parser = ModArgparser(footprint_gen)
>>> parser.add_parameter("name", type=str, required=True)  # the root node of .yml files is parsed as name
>>> parser.run()  # now run our script which handles the whole part of parsing the files
exception KicadModTree.ModArgparser.ParserException[source]

Bases: exceptions.Exception

KicadModTree.Vector module

class KicadModTree.Vector.Vector2D(coordinates=None, y=None)[source]

Bases: object

Representation of a 2D Vector in space

Example:
>>> from KicadModTree import *
>>> Vector2D(0, 0)
>>> Vector2D([0, 0])
>>> Vector2D((0, 0))
>>> Vector2D({'x': 0, 'y':0})
>>> Vector2D(Vector2D(0, 0))
__add__(value)[source]
__copy__()[source]
__dict__ = dict_proxy({'_Vector2D__arithmetic_parse': <staticmethod object>, '__module__': 'KicadModTree.Vector', '__repr__': <function __repr__>, 'render': <function render>, '__isub__': <function __isub__>, '__str__': <function __str__>, 'from_polar': <staticmethod object>, '__div__': <function __div__>, '__truediv__': <function __truediv__>, 'round_to': <function round_to>, '__add__': <function __add__>, '__dict__': <attribute '__dict__' of 'Vector2D' objects>, '__ne__': <function __ne__>, '__eq__': <function __eq__>, '__init__': <function __init__>, '__weakref__': <attribute '__weakref__' of 'Vector2D' objects>, 'rotate': <function rotate>, '__getitem__': <function __getitem__>, '__mul__': <function __mul__>, 'distance_to': <function distance_to>, '__setitem__': <function __setitem__>, '__iadd__': <function __iadd__>, 'from_homogeneous': <staticmethod object>, 'to_homogeneous': <function to_homogeneous>, 'to_dict': <function to_dict>, 'to_polar': <function to_polar>, '__iter__': <function __iter__>, '__sub__': <function __sub__>, '__copy__': <function __copy__>, '__doc__': "Representation of a 2D Vector in space\n\n :Example:\n\n >>> from KicadModTree import *\n >>> Vector2D(0, 0)\n >>> Vector2D([0, 0])\n >>> Vector2D((0, 0))\n >>> Vector2D({'x': 0, 'y':0})\n >>> Vector2D(Vector2D(0, 0))\n ", '__len__': <function __len__>, '__neg__': <function __neg__>})
__div__(value)[source]
__eq__(other)[source]

x.__eq__(y) <==> x==y

__getitem__(key)[source]
__iadd__(value)[source]
__init__(coordinates=None, y=None)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__isub__(value)[source]
__iter__()[source]
__len__()[source]
__module__ = 'KicadModTree.Vector'
__mul__(value)[source]
__ne__(other)[source]

x.__ne__(y) <==> x!=y

__neg__()[source]
__repr__() <==> repr(x)[source]
__setitem__(key, item)[source]
__str__() <==> str(x)[source]
__sub__(value)[source]
__truediv__(obj)[source]
__weakref__

list of weak references to the object (if defined)

distance_to(value)[source]

Distance between this and another point

Parameters:value – the other point
Returns:distance between self and other point
static from_homogeneous(source)[source]

Recover 2d vector from its homogeneous representation

Params:
  • source (Vector3D)
    3d homogeneous representation
static from_polar(radius, angle, origin=(0, 0), use_degrees=True)[source]

Generate a vector from its polar representation

Params:
  • radius (float)
    lenght of the vector
  • angle (float)
    angle of the vector
  • origin (Vector2D)
    origin point for polar conversion. default: (0, 0)
  • use_degrees (boolean)
    angle in degrees. default:True
render(formatcode)[source]
rotate(angle, origin=(0, 0), use_degrees=True)[source]

Rotate vector around given origin

Params:
  • angle (float)
    rotation angle
  • origin (Vector2D)
    origin point for the rotation. default: (0, 0)
  • use_degrees (boolean)
    rotation angle is given in degrees. default:True
round_to(base)[source]

Round to a specific base (like it’s required for a grid)

Parameters:base – base we want to round to
Returns:rounded point
>>> from KicadModTree import *
>>> Vector2D(0.1234, 0.5678).round_to(0.01)
to_dict()[source]
to_homogeneous()[source]

Get homogeneous representation

to_polar(origin=(0, 0), use_degrees=True)[source]

Get polar representation of the vector

Params:
  • origin (Vector2D)
    origin point for polar conversion. default: (0, 0)
  • use_degrees (boolean)
    angle in degrees. default:True
class KicadModTree.Vector.Vector3D(coordinates=None, y=None, z=None)[source]

Bases: KicadModTree.Vector.Vector2D

Representation of a 3D Vector in space

Example:
>>> from KicadModTree import *
>>> Vector3D(0, 0, 0)
>>> Vector3D([0, 0, 0])
>>> Vector3D((0, 0, 0))
>>> Vector3D({'x': 0, 'y':0, 'z':0})
>>> Vector3D(Vector2D(0, 0))
>>> Vector3D(Vector3D(0, 0, 0))
__add__(value)[source]
__copy__()[source]
__div__(value)[source]
__eq__(other)[source]

x.__eq__(y) <==> x==y

__getitem__(key)[source]
__iadd__(value)[source]
__init__(coordinates=None, y=None, z=None)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__isub__(value)[source]
__iter__()[source]
__len__()[source]
__module__ = 'KicadModTree.Vector'
__mul__(value)[source]
__ne__(other)[source]

x.__ne__(y) <==> x!=y

__neg__()[source]
__repr__() <==> repr(x)[source]
__setitem__(key, item)[source]
__str__() <==> str(x)[source]
__sub__(value)[source]
__truediv__(obj)[source]
cross_product(other)[source]
dot_product(other)[source]
render(formatcode)[source]
round_to(base)[source]

Round to a specific base (like it’s required for a grid)

Parameters:base – base we want to round to
Returns:rounded point
>>> from KicadModTree import *
>>> Vector3D(0.123, 0.456, 0.789).round_to(0.01)
to_dict()[source]