footprint module#

A catalogue footprint, fetched from LCSC and reduced to plain geometry.

EasyEDA is the source: easyeda2kicad fetches a part’s CAD data and parses it into its own intermediate model, and this module stops there. Nothing from easyeda2kicad.kicad is used, so none of the KiCad file format’s conventions reach a JITX design. See export/orientation.py, which does the same thing for pads alone.

Two things are normalized on the way in, and both are reflections rather than sign conventions, so getting either wrong yields a mirror image rather than a small error:

  • coordinates are made relative to the footprint’s own origin, which EasyEDA keeps in bbox, because everything it emits is in absolute canvas units;

  • the y axis is flipped, because EasyEDA’s points down and JITX’s points up.

Lengths are millimetres and angles are counter-clockwise degrees once here, which is what JITX wants. The result is JSON-serializable by design: it is what lcsc.lock.json records, so that a design builds the same landpattern on a machine that never reaches the network.

DECORATIVE = frozenset({100, 101})#

Layers EasyEDA draws for its own editor and that mean nothing on a board.

LEAD_SHAPE is the outline of the part’s leads and COMPONENT_POLARITY the little circle it puts on pin 1; neither is fabricated, and both would end up as silkscreen if they were translated.

exception FootprintError[source]#

Bases: Exception

A catalogue footprint that cannot be fetched or understood.

class Segment(to, radii=None, rotation=0.0, large=False, clockwise=False)[source]#

Bases: object

One step of a path: a straight line, or an elliptical arc, to to.

Parameters:
  • to (tuple[float, float]) – the point the step ends at.

  • radii (tuple[float, float] | None) – ellipse radii, or None for a straight line.

  • rotation (float) – the ellipse’s x-axis rotation in counter-clockwise degrees.

  • large (bool) – take the longer of the two arcs that fit.

  • clockwise (bool) – sweep direction, clockwise in the y-up frame.

to: tuple[float, float]#
radii: tuple[float, float] | None = None#
rotation: float = 0.0#
large: bool = False#
clockwise: bool = False#
json()[source]#
Return type:

dict[str, Any]

static parse(entry)[source]#
Return type:

Segment

Parameters:

entry (Mapping[str, Any])

class Path(start, segments, closed=False)[source]#

Bases: object

A run of segments from start, closed into a region or left open.

Parameters:
start: tuple[float, float]#
segments: tuple[Segment, ...]#
closed: bool = False#
property points: tuple[tuple[float, float], ...]#

The path’s corners, ignoring the curvature of any arc in it.

property straight: bool#

Whether every segment is a straight line.

json()[source]#
Return type:

dict[str, Any]

static parse(entry)[source]#
Return type:

Path

Parameters:

entry (Mapping[str, Any])

class Pad(number, shape, x, y, width, height, rotation=0.0, layer=1, hole_radius=0.0, hole_length=0.0, outline=())[source]#

Bases: object

One pad of the catalogue footprint.

Parameters:
  • number (str) – pin number as EasyEDA states it. Not necessarily a number, and not necessarily unique: a part with two pads on one pin states the same number twice.

  • shape (str) – “RECT”, “ELLIPSE”, “OVAL” or “POLYGON”.

  • x (float) – centre, millimetres, y-up, relative to the footprint origin.

  • y (float) – centre, millimetres, y-up, relative to the footprint origin.

  • width (float) – x extent before rotation is applied.

  • height (float) – y extent before rotation is applied.

  • rotation (float) – counter-clockwise degrees.

  • layer (int) – EasyEDA layer id. TOP_COPPER is a surface-mount pad and MULTI_LAYER a through-hole one.

  • hole_radius (float) – drill radius, zero for a surface-mount pad.

  • hole_length (float) – drill length for a slot, zero for a round hole.

  • outline (tuple[tuple[float, float], ...]) – the corners of a “POLYGON” pad, empty otherwise.

EasyEDA’s plating flag is not carried: it marks every surface-mount pad unplated, and it marks a USB-C receptacle’s shield tabs unplated as well, so it says nothing. A pad is somewhere a pin is connected and is therefore plated; an unplated hole is a Hole, which is what EasyEDA draws one as.

number: str#
shape: str#
x: float#
y: float#
width: float#
height: float#
rotation: float = 0.0#
layer: int = 1#
hole_radius: float = 0.0#
hole_length: float = 0.0#
outline: tuple[tuple[float, float], ...] = ()#
property through_hole: bool#
json()[source]#
Return type:

dict[str, Any]

static parse(entry)[source]#
Return type:

Pad

Parameters:

entry (Mapping[str, Any])

class Hole(x, y, radius)[source]#

Bases: object

An unplated hole that is not part of a pad.

Parameters:
x: float#
y: float#
radius: float#
json()[source]#
Return type:

dict[str, Any]

static parse(entry)[source]#
Return type:

Hole

Parameters:

entry (Mapping[str, Any])

class Via(x, y, diameter, hole_radius)[source]#

Bases: object

A via drawn into the footprint itself, as a thermal pad’s often is.

Parameters:
x: float#
y: float#
diameter: float#
hole_radius: float#
json()[source]#
Return type:

dict[str, Any]

static parse(entry)[source]#
Return type:

Via

Parameters:

entry (Mapping[str, Any])

class Curve(layer, width, path)[source]#

Bases: object

A stroked line or arc on a graphical layer.

Parameters:
layer: int#
width: float#
path: Path#
json()[source]#
Return type:

dict[str, Any]

static parse(entry)[source]#
Return type:

Curve

Parameters:

entry (Mapping[str, Any])

class Circle(layer, x, y, radius, width)[source]#

Bases: object

A stroked circle on a graphical layer.

Parameters:
layer: int#
x: float#
y: float#
radius: float#
width: float#
json()[source]#
Return type:

dict[str, Any]

static parse(entry)[source]#
Return type:

Circle

Parameters:

entry (Mapping[str, Any])

class Region(layer, kind, path)[source]#

Bases: object

A filled region on a graphical layer.

Parameters:
  • layer (int) – EasyEDA layer id.

  • kind (str) – “solid”, “cutout” or “npth”, as EasyEDA states it.

  • path (Path) – the region’s boundary, closed.

layer: int#
kind: str#
path: Path#
json()[source]#
Return type:

dict[str, Any]

static parse(entry)[source]#
Return type:

Region

Parameters:

entry (Mapping[str, Any])

class Text(layer, x, y, size, width, rotation, string, kind='N', mirrored=False, visible=True)[source]#

Bases: object

A text item on a graphical layer.

Parameters:
  • kind (str) – “N” for a plain note, “P” for the part’s prefix (reference designator) placeholder, “L” for its value placeholder.

  • mirrored (bool) – EasyEDA draws it mirrored, which a bottom-side item is.

  • visible (bool) – EasyEDA hides it in the editor.

  • layer (int)

  • x (float)

  • y (float)

  • size (float)

  • width (float)

  • rotation (float)

  • string (str)

layer: int#
x: float#
y: float#
size: float#
width: float#
rotation: float#
string: str#
kind: str = 'N'#
mirrored: bool = False#
visible: bool = True#
json()[source]#
Return type:

dict[str, Any]

static parse(entry)[source]#
Return type:

Text

Parameters:

entry (Mapping[str, Any])

class Footprint(name, pads=(), holes=(), vias=(), curves=(), circles=(), regions=(), texts=())[source]#

Bases: object

A catalogue footprint in millimetres, y-up, about its own origin.

Parameters:
  • name (str) – EasyEDA’s own name for the package, such as “SOIC-8_L4.9-W3.9-P1.27-LS6.0-BL”.

  • pads (tuple[Pad, ...]) – the geometry, each item carrying the EasyEDA layer it was drawn on.

  • holes (tuple[Hole, ...]) – the geometry, each item carrying the EasyEDA layer it was drawn on.

  • vias (tuple[Via, ...]) – the geometry, each item carrying the EasyEDA layer it was drawn on.

  • curves (tuple[Curve, ...]) – the geometry, each item carrying the EasyEDA layer it was drawn on.

  • circles (tuple[Circle, ...]) – the geometry, each item carrying the EasyEDA layer it was drawn on.

  • regions (tuple[Region, ...]) – the geometry, each item carrying the EasyEDA layer it was drawn on.

  • texts (tuple[Text, ...]) – the geometry, each item carrying the EasyEDA layer it was drawn on.

name: str#
pads: tuple[Pad, ...] = ()#
holes: tuple[Hole, ...] = ()#
vias: tuple[Via, ...] = ()#
curves: tuple[Curve, ...] = ()#
circles: tuple[Circle, ...] = ()#
regions: tuple[Region, ...] = ()#
texts: tuple[Text, ...] = ()#
json()[source]#

The record as it is written to lcsc.lock.json.

Empty collections are left out, so that the common footprint is a handful of pads and nothing else.

Return type:

dict[str, Any]

static parse(entry)[source]#

Read back a record written by json.

Raises:

FootprintError – the record is not one this understands. A hand edited lock file is the likely source, so the message says what was wrong rather than leaving a KeyError to surface.

Return type:

Footprint

Parameters:

entry (Mapping[str, Any])

from_easyeda(source)[source]#

Reduce an easyeda2kicad footprint to the normalized model.

Decorative layers are dropped; everything else is kept with the layer it was drawn on, so that deciding what a layer means is the landpattern’s job rather than this one’s.

Return type:

Footprint

Parameters:

source (EeFootprint)

fetch(partnumber)[source]#

Fetch a part’s catalogue footprint from LCSC.

This reaches the network. Callers are expected to have looked in lcsc.lock.json first and to record what comes back, so that a build that has already seen a part never gets here.

Raises:

FootprintError – the part has no CAD data, or easyeda2kicad is not installed.

Return type:

Footprint

Parameters:

partnumber (str)