assume stdout which simplifies things significantly
[hw/altusmetrum] / packages / fplht.py
1 #! /usr/bin/python
2 # Copyright 2020 by Bdale Garbee <bdale@gag.com>.  GPLv3
3
4 # Python library to assist in generating lihata format footprints for pcb-rnd
5
6 # Each footprint should have a parent Python script that initializes this 
7 # library and provides a high-level description of the primitives required.  
8 # The footprint is delivered to stdout, so the encapsulating Makefile and/or 
9 # iterating wrapper script is responsible for redirecting to the desired 
10 # <something>.lht file(s).
11
12 import math
13 import hashlib
14
15 class footprint(object):
16     def __init__(self):
17         self.units = "mm"
18         self.name = ""
19         self.description = ""
20         self.dist_license = "GPLv3"
21         self.use_license = "Unlimited"
22         self.author = "Bdale Garbee <bdale@gag.com>"
23         self.cnt = 0
24
25     # primitive objects
26     # (proposed argument lists taken from pcb land_patterns doc)
27     # -- can probably collapse sflags+nflags->flags?
28
29         # the basic plan is that each primitive function puts the object
30         # definition in the relevant dictionary .. when we go to emit the
31         # part, we'll do things like work out the minimum set of padstack
32         # prototypes by iterating over the dictionaries... then output the
33         # working set of required objects
34
35     ## for copper layers
36     # def pad():
37     #   x1, y1, x2, y2, thickness, clearance, mask, name, number, sflags, nflags
38     # def pin():
39     #   x, y, thickness, clearance, mask, drill, name, number, sflags, nflags
40     # def slot():
41
42     ## for silk layers
43     # def line():
44     #   x1, y1, x2, y2, thickness
45     # def arc():
46     #   x, y, width, height, startangle, deltaangle, thickness
47
48     def emit_padstack_prototypes(self):
49         print("prototypes will go here")
50
51     def emit_padstacks(self):
52         print("padstacks will go here")
53
54     def emit_top_silk(self):
55         print("top_silk will go here")
56
57     def emit_line(self, role, id, x1, y1, x2, y2, unit):
58         print("      ha:line.%u {" % id)
59         print("       clearance = 0")
60         print("       thickness = 0")
61         print("       ha:attributes {")
62         print("        subc-role = %s" % role)
63         print("       }")
64         print("       x1 = %u%s" % (x1, unit))
65         print("       y1 = %u%s" % (y1, unit))
66         print("       x2 = %u%s" % (x2, unit))
67         print("       y2 = %u%s" % (y2, unit))
68         print("      }")
69         self.cnt = self.cnt + 1
70
71     def emit_bbox(self):
72         self.cnt = 0
73         print("    ha:subc-aux {")
74         print("     lid = 1")
75         print("     ha:type {")
76         print("      top = 1")
77         print("      misc = 1")
78         print("      virtual = 1")
79         print("     }")
80         print("     li:objects {")
81         self.emit_line("origin", self.cnt, 0, 0, 0, 0, "mm");
82         self.emit_line("x", self.cnt, 0, 0, 1, 0, "mm");
83         self.emit_line("y", self.cnt, 0, 0, 0, 1, "mm");
84         print("     }")
85         print("    }")
86
87     def create_uuid(self):
88         return hashlib.md5(self.name).hexdigest()
89
90     def emit(self):
91         print("li:pcb-rnd-subcircuit-v4 {")
92         print(" ha:subc.0 {")
93         print("  ha:attributes {")
94         print("   description = %s" % self.description)
95         print("   dist_license = %s" % self.dist_license)
96         print("   use_license = %s" % self.use_license)
97         print("   author = %s" % self.author)
98         print("  }")
99         print("  uid = %s" % self.create_uuid())
100         print("  ha:data {")
101         self.emit_padstack_prototypes()
102         print("   li:objects {")
103         self.emit_padstacks()
104         print("   }")
105         print("   li:layers {")
106         self.emit_top_silk()
107         self.emit_bbox()
108         print("   }")
109         print("  }")
110         print(" }")
111         print("}")