summaryrefslogtreecommitdiff
path: root/gerbonara/cad/protoserve.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-04-09 18:46:36 +0200
committerjaseg <git@jaseg.de>2023-04-10 23:57:15 +0200
commit8181651a75fab99acc986bcf3105779317ac4e2e (patch)
treee5ac9f026d0c82477229608f4d41fd8ac559ab33 /gerbonara/cad/protoserve.py
parent888ae71889dfb4a9698f8f2607b649d384dd3738 (diff)
downloadgerbonara-8181651a75fab99acc986bcf3105779317ac4e2e.tar.gz
gerbonara-8181651a75fab99acc986bcf3105779317ac4e2e.tar.bz2
gerbonara-8181651a75fab99acc986bcf3105779317ac4e2e.zip
protoserve: Fix bugs, make gerber link more visible
Diffstat (limited to 'gerbonara/cad/protoserve.py')
-rw-r--r--gerbonara/cad/protoserve.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/gerbonara/cad/protoserve.py b/gerbonara/cad/protoserve.py
index b594196..a210e91 100644
--- a/gerbonara/cad/protoserve.py
+++ b/gerbonara/cad/protoserve.py
@@ -41,12 +41,21 @@ def deserialize(obj, unit):
pitch_y = float(obj.get('pitch_y', 1.27))
clearance = float(obj.get('clearance', 0.2))
+ mil = lambda x: x/1000 if unit == Inch else x
+
match obj['type']:
case 'layout':
+ if not obj.get('children'):
+ return pb.EmptyProtoArea()
+
proportions = [float(child['layout_prop']) for child in obj['children']]
content = [deserialize(child, unit) for child in obj['children']]
return pb.PropLayout(content, obj['direction'], proportions)
+ case 'twoside':
+ top, bottom = obj['children']
+ return pb.TwoSideLayout(deserialize(top, unit), deserialize(bottom, unit))
+
case 'placeholder':
return pb.EmptyProtoArea()
@@ -59,7 +68,7 @@ def deserialize(obj, unit):
return pb.PatternProtoArea(pitch_x, pitch_y, obj=pad, unit=unit)
case 'tht':
- hole_dia = float(obj['hole_dia'])
+ hole_dia = mil(float(obj['hole_dia']))
match obj['plating']:
case 'plated':
oneside, plated = False, True
@@ -85,16 +94,16 @@ def deserialize(obj, unit):
return pb.PatternProtoArea(pitch_x, pitch_y, obj=pb.ManhattanPads(pitch_x, pitch_y, clearance, unit=unit), unit=unit)
case 'powered':
- pitch = float(obj.get('pitch', 2.54))
- hole_dia = float(obj['hole_dia'])
- via_drill = float(obj['via_hole_dia'])
- trace_width = float(obj['trace_width'])
+ pitch = mil(float(obj.get('pitch', 2.54)))
+ hole_dia = mil(float(obj['hole_dia']))
+ via_drill = mil(float(obj['via_hole_dia']))
+ trace_width = mil(float(obj['trace_width']))
return pb.PatternProtoArea(pitch, pitch, pb.PoweredProto(pitch, hole_dia, clearance, via_size=via_drill, trace_width=trace_width, unit=unit), unit=unit)
case 'flower':
- pitch = float(obj.get('pitch', 2.54))
- hole_dia = float(obj['hole_dia'])
- pattern_dia = float(obj['pattern_dia'])
+ pitch = mil(float(obj.get('pitch', 2.54)))
+ hole_dia = mil(float(obj['hole_dia']))
+ pattern_dia = mil(float(obj['pattern_dia']))
return pb.PatternProtoArea(2*pitch, 2*pitch, pb.THTFlowerProto(pitch, hole_dia, pattern_dia, unit=unit), unit=unit)
case 'rf':
@@ -113,7 +122,10 @@ def to_board(obj):
mounting_hole_dia = float(holes.get('diameter', unit(3.2, MM)))
mounting_hole_offset = float(holes.get('offset', unit(5, MM)))
- content = deserialize(obj['children'][0], unit)
+ if obj.get('children'):
+ content = deserialize(obj['children'][0], unit)
+ else:
+ content = [pb.EmptyProtoArea()]
return pb.ProtoBoard(w, h, content,
corner_radius=corner_radius,