From 07c55e467bb07b8dcb80a5efaea037f4b24dbf76 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Thu, 26 Dec 2019 08:28:54 -0300 Subject: [PATCH] working on Python library to emit lht footprints --- packages/fplht.py | 111 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 packages/fplht.py diff --git a/packages/fplht.py b/packages/fplht.py new file mode 100644 index 0000000..e4bbc50 --- /dev/null +++ b/packages/fplht.py @@ -0,0 +1,111 @@ +#! /usr/bin/python +# Copyright 2020 by Bdale Garbee . GPLv3 + +# Python library to assist in generating lihata format footprints for pcb-rnd + +import math +import sys +import hashlib + +class footprint(object): + def __init__(self, + output = sys.stdout): + self.output = output + self.units = "mm" + self.name = "" + self.description = "" + self.dist_license = "GPLv3" + self.use_license = "Unlimited" + self.author = "Bdale Garbee " + self.cnt = 0 + + # primitive objects + # (proposed argument lists taken from pcb land_patterns doc) + # -- can probably collapse sflags+nflags->flags? + + # the basic plan is that each primitive function puts the object + # definition in the relevant dictionary .. when we go to emit the + # part, we'll do things like work out the minimum set of padstack + # prototypes by iterating over the dictionaries... then output the + # working set of required objects + + ## for copper layers + # def pad(): + # x1, y1, x2, y2, thickness, clearance, mask, name, number, sflags, nflags + # def pin(): + # x, y, thickness, clearance, mask, drill, name, number, sflags, nflags + # def slot(): + + ## for silk layers + # def line(): + # x1, y1, x2, y2, thickness + # def arc(): + # x, y, width, height, startangle, deltaangle, thickness + + def writeln(self, stuff): + self.output.write(stuff + "\n") + + def emit_padstack_prototypes(self): + self.writeln("prototypes will go here") + + def emit_padstacks(self): + self.writeln("padstacks will go here") + + def emit_top_silk(self): + self.writeln("top_silk will go here") + + def emit_line(self, role, id, x1, y1, x2, y2, unit): + self.writeln(" ha:line.%u {" % id) + self.writeln(" clearance = 0") + self.writeln(" thickness = 0") + self.writeln(" ha:attributes {") + self.writeln(" subc-role = %s" % role) + self.writeln(" }") + self.writeln(" x1 = %u%s" % (x1, unit)) + self.writeln(" y1 = %u%s" % (y1, unit)) + self.writeln(" x2 = %u%s" % (x2, unit)) + self.writeln(" y2 = %u%s" % (y2, unit)) + self.writeln(" }") + self.cnt = self.cnt + 1 + + def emit_bbox(self): + self.cnt = 0 + self.writeln(" ha:subc-aux {") + self.writeln(" lid = 1") + self.writeln(" ha:type {") + self.writeln(" top = 1") + self.writeln(" misc = 1") + self.writeln(" virtual = 1") + self.writeln(" }") + self.writeln(" li:objects {") + self.emit_line("origin", self.cnt, 0, 0, 0, 0, "mm"); + self.emit_line("x", self.cnt, 0, 0, 1, 0, "mm"); + self.emit_line("y", self.cnt, 0, 0, 0, 1, "mm"); + self.writeln(" }") + self.writeln(" }") + + def create_uuid(self): + return hashlib.md5(self.name).hexdigest() + + def emit(self): + self.writeln("li:pcb-rnd-subcircuit-v4 {") + self.writeln(" ha:subc.0 {") + self.writeln(" ha:attributes {") + self.writeln(" description = %s" % self.description) + self.writeln(" dist_license = %s" % self.dist_license) + self.writeln(" use_license = %s" % self.use_license) + self.writeln(" author = %s" % self.author) + self.writeln(" }") + self.writeln(" uid = %s" % self.create_uuid()) + self.writeln(" ha:data {") + self.emit_padstack_prototypes() + self.writeln(" li:objects {") + self.emit_padstacks() + self.writeln(" }") + self.writeln(" li:layers {") + self.emit_top_silk() + self.emit_bbox() + self.writeln(" }") + self.writeln(" }") + self.writeln(" }") + self.writeln("}") -- 2.30.2