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