working on Python library to emit lht footprints
authorBdale Garbee <bdale@gag.com>
Thu, 26 Dec 2019 11:28:54 +0000 (08:28 -0300)
committerBdale Garbee <bdale@gag.com>
Thu, 26 Dec 2019 11:28:54 +0000 (08:28 -0300)
packages/fplht.py [new file with mode: 0644]

diff --git a/packages/fplht.py b/packages/fplht.py
new file mode 100644 (file)
index 0000000..e4bbc50
--- /dev/null
@@ -0,0 +1,111 @@
+#! /usr/bin/python
+# Copyright 2020 by Bdale Garbee <bdale@gag.com>.  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 <bdale@gag.com>"
+       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("}")