Tue, 04 Apr 2017 03:13:58 +0200
finished webrenderer
11 | 1 | #!/usr/bin/env python |
2 | # -*- coding: UTF-8 -*- | |
3 | ||
4 | import cgi, data, json, config | |
5 | from cylindertransport import CylinderSpacerCalculator | |
6 | ||
7 | # enable debugging | |
8 | import cgitb, sys | |
9 | sys.stderr = sys.stdout | |
10 | #cgitb.enable() | |
11 | ||
12 | ||
13 | def do_action(args): | |
14 | if args["action"].value == "calculate": | |
15 | cylinders = args.getlist("cylinders[]") | |
16 | calc = CylinderSpacerCalculator(cylinders) | |
17 | calc.calculate() | |
18 | print json.dumps({ | |
19 | "objects": calc.circles, | |
20 | "scale3d": config.SCALE3D | |
21 | }) | |
22 | else: | |
23 | print "unknown Action %s" % args["action"].value | |
24 | ||
25 | ||
26 | ||
27 | ||
28 | ||
29 | ||
30 | print("Content-Type: text/html;charset=utf-8") | |
31 | print("") | |
32 | ||
33 | args = cgi.FieldStorage() | |
34 | if "action" in args: | |
35 | do_action(args) | |
36 | else: | |
37 | # display the html content | |
38 | content = open("stlviewer.html", "r").read() | |
39 | cyls = "" | |
40 | for cyl in sorted(data.CYLINDER.keys()): | |
41 | cyls += "<li key=\"%s\" weight=\"%s\">%s</li>" % ( | |
42 | cyl, data.CYLINDER[cyl][3], data.CYLINDER[cyl][4]); | |
43 | content = content.replace("<!-- PLACEHOLDER CYLINDERS -->", cyls) | |
44 | ||
45 | print content |