-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
71 lines (58 loc) · 2.11 KB
/
main.py
File metadata and controls
71 lines (58 loc) · 2.11 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
68
69
70
71
from svg import SVG
from ui import UserInterface
from geojson import GeoJSON
class Controller:
def __init__(self):
self.ui = UserInterface(self)
self.svg = None
self.geojson = None
self.layer_output = []
self.bounds = [0.0, 0.0, 0.0, 0.0]
self.rotation = 0.0
self.last_click = None
self.ui.run()
def load_svg(self, path):
with open(path) as file:
svg = SVG(file.read())
self.svg = svg
self.geojson = GeoJSON(self.svg)
self.layer_output = list(self.svg.get_layers())
self.update_result()
self.ui.load_preview(path)
layers = self.svg.get_layers()
self.ui.load_layers(layers)
def set_layer_output(self, layer: str, enable: bool):
if enable:
self.layer_output.append(layer)
else:
self.layer_output.remove(layer)
def update_boundaries(self, direction: chr, value, update_ui=True):
if direction == 'N':
self.bounds[0] = value
elif direction == 'S':
self.bounds[1] = value
elif direction == 'E':
self.bounds[2] = value
elif direction == 'W':
self.bounds[3] = value
if update_ui:
self.ui.set_boundaries(self.bounds)
self.update_result()
def update_rotation(self, rotation):
self.rotation = rotation
self.update_result()
def update_result(self):
print(f'Updating to match the bounds {self.bounds} with {self.rotation}º of rotation.')
geojson = self.geojson.calculate(self.layer_output, self.bounds, self.rotation)
self.ui.set_output(geojson)
self.ui.draw_polygons(self.geojson.polygons)
def record_click(self, lon: float, lat: float):
self.last_click = lon, lat
self.ui.set_last_click(lon, lat)
def replace_lim(self, direction: chr):
if direction in ('N', 'S'):
self.update_boundaries(direction, self.last_click[1])
else:
self.update_boundaries(direction, self.last_click[0])
if __name__ == "__main__":
Controller()