summaryrefslogtreecommitdiff
path: root/gerbonara/cad/protoserve.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-04-09 17:53:54 +0200
committerjaseg <git@jaseg.de>2023-04-10 23:57:15 +0200
commit888ae71889dfb4a9698f8f2607b649d384dd3738 (patch)
tree06f45df9adeddaf079c8bcc7a3376e90c8e06efc /gerbonara/cad/protoserve.py
parentfba189c69534fe0e88851e35716fe0e5d07a5c98 (diff)
downloadgerbonara-888ae71889dfb4a9698f8f2607b649d384dd3738.tar.gz
gerbonara-888ae71889dfb4a9698f8f2607b649d384dd3738.tar.bz2
gerbonara-888ae71889dfb4a9698f8f2607b649d384dd3738.zip
protoserve: Gerber download works
Diffstat (limited to 'gerbonara/cad/protoserve.py')
-rw-r--r--gerbonara/cad/protoserve.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/gerbonara/cad/protoserve.py b/gerbonara/cad/protoserve.py
index 0bf9dce..b594196 100644
--- a/gerbonara/cad/protoserve.py
+++ b/gerbonara/cad/protoserve.py
@@ -1,10 +1,10 @@
#!/usr/bin/env python
import importlib.resources
-from tempfile import TemporaryDirectory
+from tempfile import NamedTemporaryFile, TemporaryDirectory
from pathlib import Path
-from quart import Quart, request, Response
+from quart import Quart, request, Response, send_file
from . import protoboard as pb
from . import protoserve_data
@@ -104,10 +104,7 @@ def deserialize(obj, unit):
via_drill = float(obj['via_hole_dia'])
return pb.PatternProtoArea(pitch, pitch, pb.RFGroundProto(pitch, hole_dia, clearance, via_dia, via_drill, unit=MM), unit=MM)
-@app.route('/preview.svg', methods=['POST'])
-async def preview():
- obj = await request.get_json()
-
+def to_board(obj):
unit = Inch if obj.get('units' == 'us') else MM
w = float(obj.get('width', unit(100, MM)))
h = float(obj.get('height', unit(80, MM)))
@@ -118,13 +115,27 @@ async def preview():
content = deserialize(obj['children'][0], unit)
- board = pb.ProtoBoard(w, h, content,
+ return pb.ProtoBoard(w, h, content,
corner_radius=corner_radius,
mounting_hole_dia=mounting_hole_dia,
mounting_hole_offset=mounting_hole_offset,
unit=unit)
+
+@app.route('/preview.svg', methods=['POST'])
+async def preview():
+ obj = await request.get_json()
+ board = to_board(obj)
return Response(str(board.pretty_svg()), mimetype='image/svg+xml')
+@app.route('/gerbers.zip', methods=['POST'])
+async def gerbers():
+ obj = await request.get_json()
+ board = to_board(obj)
+ with NamedTemporaryFile(suffix='.zip') as f:
+ f = Path(f.name)
+ board.layer_stack().save_to_zipfile(f)
+ return Response(f.read_bytes(), mimetype='image/svg+xml')
+
if __name__ == '__main__':
app.run()