From 888ae71889dfb4a9698f8f2607b649d384dd3738 Mon Sep 17 00:00:00 2001 From: jaseg Date: Sun, 9 Apr 2023 17:53:54 +0200 Subject: protoserve: Gerber download works --- gerbonara/cad/protoserve.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'gerbonara/cad/protoserve.py') 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() -- cgit