cartridge/kicad_footprint.py
2023-06-19 17:57:22 +00:00

75 lines
1.7 KiB
Python

import uuid
import enum
_footprint = """
(footprint "{name}" (version 20221018) (generator kicad_footprint)
(layer "F.Cu")
(attr smd)
(fp_text reference "REF**" (at 0 -0.5 unlocked) (layer "F.SilkS")
(effects (font (size 1 1) (thickness 0.1)))
(tstamp {uuid_reference})
)
(fp_text value "{value}" (at 0 1 unlocked) (layer "F.Fab")
(effects (font (size 1 1) (thickness 0.15)))
(tstamp {uuid_value})
)
(fp_text user "${{REFERENCE}}" (at 0 2.5 unlocked) (layer "F.Fab")
(effects (font (size 1 1) (thickness 0.15)))
(tstamp {uuid_user})
)
{pads}
)
""".strip('\n')
def footprint(name, value, pads):
return _footprint.format(
name=name,
value=value,
uuid_reference=uuid.uuid4(),
uuid_value=uuid.uuid4(),
uuid_user=uuid.uuid4(),
pads=pads,
)
_pad = """
(pad "{number}" smd rect (at {x} {y}) (size {w} {h}) (layers "{cu}" "{paste}" "{mask}")
(thermal_bridge_angle 45) (tstamp {uuid}))
""".strip('\n')
class side(enum.Enum):
front=enum.auto()
back=enum.auto()
def pad(number, x, y, w, h, s):
s = "F" if s is side.front else "B"
cu = f"{s}.Cu"
paste = f"{s}.Paste"
mask = f"{s}.Mask"
return _pad.format(
number=number,
x=x,
y=y,
w=w,
h=h,
cu=cu,
paste=paste,
mask=mask,
uuid=uuid.uuid4()
)
_fp_line = """
(fp_line (start {x0} {y0}) (end {x1} {y1})
(stroke (width {width}) (type solid)) (layer "{layer}") (tstamp {uuid}))
"""
def fp_line(x0, y0, x1, y1, width, layer):
return _fp_line.format(
x0=x0,
y0=y0,
x1=x1,
y1=y1,
width=width,
layer=layer,
uuid=uuid.uuid4()
)