Skip to content

Commit fb3a623

Browse files
committed
Improve compatibility with KiCad 4
1 parent aba9006 commit fb3a623

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

InteractiveHtmlBom/generate_interactive_bom.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ def parse_draw_segment(d):
115115
"width": d.GetWidth() * 1e-6
116116
}
117117
if shape == "circle":
118-
print "Circle shape", d.GetRadius() * 1e-6
119118
return {
120119
"type": shape,
121120
"start": start,
@@ -137,11 +136,16 @@ def parse_draw_segment(d):
137136
"width": d.GetWidth() * 1e-6
138137
}
139138
if shape == "polygon":
139+
if hasattr(d, "GetPolyShape"):
140+
polygons = parse_poly_set(d.GetPolyShape())
141+
else:
142+
print "Polygons not supported for KiCad 4"
143+
polygons = []
140144
return {
141145
"type": shape,
142146
"pos": start,
143147
"angle": d.GetParentModule().GetOrientation() * 0.1,
144-
"polygons": parse_poly_set(d.GetPolyShape())
148+
"polygons": polygons
145149
}
146150

147151

@@ -169,12 +173,22 @@ def parse_text(d):
169173
if d.GetClass() == "MTEXT":
170174
angle = d.GetDrawRotation() * 0.1
171175
else:
172-
angle = d.GetTextAngle() * 0.1
176+
if hasattr(d, "GetTextAngle"):
177+
angle = d.GetTextAngle() * 0.1
178+
else:
179+
angle = d.GetOrientation() * 0.1
180+
print d, angle
181+
if hasattr(d, "GetTextHeight"):
182+
height = d.GetTextHeight() * 1e-6
183+
width = d.GetTextWidth() * 1e-6
184+
else:
185+
height = d.GetHeight() * 1e-6
186+
width = d.GetWidth() * 1e-6
173187
return {
174188
"pos": pos,
175189
"text": d.GetText(),
176-
"height": d.GetTextHeight() * 1e-6,
177-
"width": d.GetTextWidth() * 1e-6,
190+
"height": height,
191+
"width": width,
178192
"horiz_justify": d.GetHorizJustify(),
179193
"angle": angle
180194
}
@@ -268,13 +282,16 @@ def parse_modules(pcb):
268282
size = normalize(p.GetSize())
269283
is_pin1 = p.GetPadName() == "1" or p.GetPadName() == "A1"
270284
angle = p.GetOrientation() * -0.1
271-
shape = {
285+
shape_lookup = {
272286
pcbnew.PAD_SHAPE_RECT: "rect",
273287
pcbnew.PAD_SHAPE_OVAL: "oval",
274288
pcbnew.PAD_SHAPE_CIRCLE: "circle",
275-
pcbnew.PAD_SHAPE_ROUNDRECT: "roundrect",
276-
pcbnew.PAD_SHAPE_CUSTOM: "custom",
277-
}.get(p.GetShape(), "unsupported")
289+
}
290+
if hasattr(pcbnew, "PAD_SHAPE_ROUNDRECT"):
291+
shape_lookup[pcbnew.PAD_SHAPE_ROUNDRECT] = "roundrect"
292+
if hasattr(pcbnew, "PAD_SHAPE_CUSTOM"):
293+
shape_lookup[pcbnew.PAD_SHAPE_CUSTOM] = "custom"
294+
shape = shape_lookup.get(p.GetShape(), "unsupported")
278295
if shape == "unsupported":
279296
print "Unsupported pad shape ", p.GetShape()
280297
pad_dict = {
@@ -384,8 +401,10 @@ def main(pcb, launch_browser=True):
384401
html_content = html_content.replace('///PCBDATA///', pcbdata_js)
385402
with open(bom_file_name, "wt") as bom:
386403
bom.write(html_content)
404+
print "Created file", bom_file_name
387405

388406
if launch_browser:
407+
print "Opening it in browser"
389408
open_file(os.path.join(bom_file_dir, 'ibom.html'))
390409

391410

0 commit comments

Comments
 (0)