cylindertransport-web.py

Tue, 04 Apr 2017 03:13:58 +0200

author
mdd
date
Tue, 04 Apr 2017 03:13:58 +0200
changeset 12
b3cf0176512e
parent 11
098335a1d510
child 14
ba3d8c56e6f5
permissions
-rwxr-xr-x

finished webrenderer

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

mercurial