forked from josauder/procedural_city_generation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UI.py
137 lines (101 loc) · 3.89 KB
/
UI.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import os
import sys
import procedural_city_generation
donemessage = "\n"+(150*"-")+"\n\t\t\t Done, waiting for command\n"+(150*"-")+"\n"
path = os.path.dirname(procedural_city_generation.__file__)
sys.path.append(path)
if not os.path.exists(path+"/temp/"):
os.system("mkdir "+path+"/temp")
if not os.path.exists(path+"/outputs/"):
os.system("mkdir "+path+"/outputs")
def setup_matplotlib():
"""
This function is used to set the matplotlib backend correctly.
Parameters
----------
Returns
--------
None
:return:
"""
if sys.version[0] == "3":
import matplotlib
try:
matplotlib.use("Qt4Agg")
except:
print("PyQt4 is not installed - outputs will only be saved as images and not be visible at runtime")
print("However, it is strongly recommended that you install PyQt4 in order to use the GUI")
matplotlib.use("agg")
from procedural_city_generation.roadmap import main as roadmap_main
from procedural_city_generation.polygons import main as polygons_main
from procedural_city_generation.building_generation import main as building_generation_main
from procedural_city_generation.additional_stuff.Singleton import Singleton
def setRoadmapGUI(gui):
roadmap_main.gui = gui
Singleton("roadmap").kill()
def setPolygonsGUI(gui):
polygons_main.gui = gui
Singleton("polygons").kill()
def setBuilding_generationGUI(gui):
building_generation_main.gui = gui
Singleton("building_generation").kill()
def roadmap():
roadmap_main.main()
Singleton("roadmap").kill()
print(donemessage)
def polygons():
polygons_main.main(None)
Singleton("polygons").kill()
print(donemessage)
def building_generation():
building_generation_main.main()
Singleton("building_generation").kill()
print(donemessage)
def visualization():
os.system("blender --python "+path+"/visualization/blenderize.py")
from procedural_city_generation.additional_stuff.Singleton import Singleton
Singleton("visualization").kill()
def main(args):
"""
Welcome to procedural_city_generation, a module for procedurally generating a 3D model of a city in Blender with python.
A call to this module from the command line should follow this format::
python UI.py <submodule-name> <options>
<submodule-name> is either "roadmap", "polygons", "building_generation, "visualization".
<options> is either "run" or "configure"
If you want to configure a paremeter, go with
python UI.py <submodule-name> --configure <parameter-name> <new value>
"""
if len(args) == 1:
print(main.__doc__)
return 0
if "configure" in args[2]:
config_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),
"procedural_city_generation/inputs/{0}.conf".format(args[1]))
if len(args) == 3:
os.system("nano {0}".format(config_file))
sys.exit(0)
elif args[3] and args[4]:
import json
with open(config_file, 'r') as f:
wb = json.loads(f.read())
i = 0
while True:
try:
old = wb[args[3+i]]['value']
wb[args[3+i]]['value'] = eval(args[4+i])
print("{0} was changed from {1} to {2}".format(args[3+i], old, args[4+i]))
i += 2
if len(args)-1 < i+4:
break
except:
print(i, len(args))
print("Either {0} is not a configurable parameter for {1}".format(args[3+i], args[1]))
return 0
with open(config_file, 'w') as f:
f.write(json.dumps(wb, indent=2))
return 0
elif "run" in args[2]:
setup_matplotlib()
eval(args[1])()
if __name__ == '__main__':
main(sys.argv)