-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplace_things.py
More file actions
69 lines (56 loc) · 1.9 KB
/
place_things.py
File metadata and controls
69 lines (56 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# This script places the things described in furnashings/things.json
# onto floor_plan_cleanup/cleaned_up.svg to produce a static
# floor_plan.svg file. This is an interim measure until I can get
# things running as a web service.
# Now that placement.js is working, this script is no longer needed.
import json
import os.path
import sys
import xml.dom
import xml.dom.minidom
import cssutils # pip install cssutils
import cssutils.css
# What's the right way to load these?
sys.path.insert(
0, os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"lib"))
from transform import *
from xml_utils import *
from stylesheet import *
INPUT = "floor_plan_cleanup/cleaned_up.svg"
OUTPUT = "floor_plan.svg"
THINGS = "furnashings/things.json"
THING_STYLES= '''
.thing {
stroke: red;
fill: lightgray;
stroke-width: 1;
vector-effect: non-scaling-stroke;
}
'''
def main():
doc = xml.dom.minidom.parse(INPUT)
real_world = getElementById(doc, "real-world")
stylesheet = ensure_stylesheet(doc, "thing-styles")
stylesheet.appendChild(doc.createTextNode(THING_STYLES))
with open(THINGS, "r") as f:
things = json.load(f)
for thing in things:
print(thing["name"])
rect = doc.createElement("rect")
real_world.appendChild(rect)
title = doc.createElement("title")
title.appendChild(doc.createTextNode(thing["name"]))
rect.appendChild(title)
rect.setAttribute("class", thing["cssClass"])
rect.setAttribute("width", str(thing["width"]))
rect.setAttribute("height", str(thing["depth"]))
rect.setAttribute("x", str(- thing["width"] / 2))
rect.setAttribute("y", str(- thing["depth"] / 2))
rect.setAttribute("transform",
Transform.rotate(thing["rotation"]).toSVG() + " " +
Transform.translate(thing["x"], thing["y"]).toSVG())
write_pretty(doc, OUTPUT)
if __name__ == "__main__":
main()