-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpg.py
289 lines (252 loc) · 7.4 KB
/
gpg.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
from json import JSONEncoder
import math
class depotEncoder(JSONEncoder):
def default(self, o):
return o.__dict__
class Point:
def __init__(self,x,y) -> None:
self.x = x
self.y = y
def translate(self, dx=0, dy=0):
self.x += dx
self.y += dy
def scale(self, cox=1, coy=1):
self.x *= cox
self.y *= coy
class Line:
def __init__(self,p1,p2) -> None:
self.p1 = p1;
self.p2 = p2;
class Shape:
def __init__(self, seq, vis=1) -> None:
self.seq = seq
self.length = len(seq)
self.visible = vis
def scale(self,cox=1, coy=1):
for i in range(self.length):
self.seq[i].scale(cox,coy)
def translate(self,dx=0, dy=0):
for i in range(self.length):
self.seq[i].translate(dx,dy)
class Container:
def __init__(self, contID, contSize, HangTau, Block, Bay, Row, Tier):
self.ContID = contID
self.ContTypeSizeID = contSize
self.HangTauID = HangTau
self.Block = Block
self.Bay = Bay
self.Row = Row
self.Tier = Tier
self.angle = 0
self.x=0
self.y=0
self.z=0
class Text:
def __init__(self, content, x,y,size=8, angle=0) -> None:
self.content = content
self.position = Point(x,y)
self.size = size
self.angle = angle
# read text
def read_text(path):
result = []
fi = open(path, "r")
str = fi.read()
a = 0
p = str.find("<text",a)
while p>0:
x = []
y = []
b = str.find("/text>",p)
k = str[p+27:b]
# print(k)
text = k[k.find('">')+2:k.find("</")]
k = k[0:k.find("rotate")]
obr = k.find("(")
cbr = k.find(")")
translate = k[obr+1:cbr]
# print(translate)
sp = translate.find(" ")
x = translate[0:sp]
y = translate[sp+1: len(translate)]
result.append(Text(text, int(x),int(y)))
# print("x", x, "y", y)
a = b
p = str.find("<text",a)
return result
def svg2layout(path):
file = open(path, "r")
str = file.read()
layout_array = []
a = 0
p = str.find("<polygon",a)
while p>0:
x = []
y = []
b = str.find("/>",p)
div = str[p+27:b-1]
# print("shape:", div)
chr_id=0
type = 0
sp = div.find(" ",chr_id)
while sp>0:
if type:
# print("y:",div[chr_id:sp])
y.append(int(div[chr_id:sp]))
else:
# print("x:",div[chr_id:sp])
x.append(int(div[chr_id:sp]))
type = 1-type
chr_id = sp
sp = div.find(" ", sp+1)
# print("y:",div[chr_id:len(div)])
y.append(int(div[chr_id:len(div)]))
a = b
p = str.find("<polygon",a)
# print(x)
# print(y)
seq = []
for i in range(len(x)):
seq.append(Point(x[i],y[i]))
layout_array.append(Shape(seq))
return layout_array
# read rect
def read_rect(path):
result = []
fi = open(path, "r")
str = fi.read()
a = 0
p = str.find("<rect",a)
while p>0:
# x = []
# y = []
b = str.find("/>",p)
k = str[p+5:b]
print(k)
px = k.find('x="');
pxe = k.find('" ', px)
x = k[px+3:pxe]
print(x)
py = k.find('y="')
pye =k.find('" ', py)
y = k[py+3:pye]
print(y)
pw = k.find('width="')
pwe =k.find('" ', pw)
w = k[pw+7:pwe]
# print(w)
ph = k.find('height="')
phe =k.find('" ', ph)
h = k[ph+8:phe]
# print(h)
a = b
p = str.find("<rect",a)
return result
def read_line(path):
result = []
fi = open(path, "r")
str = fi.read()
a = 0
p = str.find("<line",a)
while p>0:
# x = []
# y = []
b = str.find("/>",p)
k = str[p+16:b]
# print(k)
px = k.find('x1="');
pxe = k.find('" ', px)
x = k[px+4:pxe]
# print(x)
py = k.find('y1="')
pye =k.find('" ', py)
y = k[py+4:pye]
# print(y)
pw = k.find('x2="')
pwe =k.find('" ', pw)
w = k[pw+4:pwe]
# print(w)
ph = k.find('y2="')
phe =k.find('" ', ph)
h = k[ph+4:phe]
# print(h)
result.append(Line(Point(int(x),int(y)), Point(int(w),int(h))))
a = b
p = str.find("<line",a)
return result
class Area:
def __init__(self, name, x, y, offsetX=0, offsetY=0, angle=0, x_flip=False, y_flip=False, shapeID=None, num_of_bay=15, num_of_row=6, num_of_tier=6) -> None:
self.name = name
self.num_of_bay = num_of_bay
self.num_of_row = num_of_row
self.num_of_tier = num_of_tier
self.x_coor = x
self.y_coor = y
self.shapeID = shapeID
self.angle = angle
self.offset = Point(offsetX, offsetY)
self.x_flip = x_flip
self.y_flip = y_flip
class Layout:
def __init__(self,svg_path) -> None:
self.shape = svg2layout(svg_path)
self.text = read_text(svg_path)
self.line = read_line(svg_path)
def scale(self,cox=1, coy=1):
for i in range(len(self.shape)):
self.shape[i].scale(cox,coy)
for i in range(len(self.text)):
self.text[i].position.scale(cox, coy)
for i in range(len(self.line)):
self.line[i].p1.scale(cox,coy)
self.line[i].p2.scale(cox,coy)
def translate(self,dx=0, dy=0):
for i in range(len(self.shape)):
self.shape[i].translate(dx,dy)
for i in range(len(self.text)):
self.text[i].position.translate(dx, dy)
for i in range(len(self.line)):
self.line[i].p1.translate(dx,dy)
self.line[i].p2.translate(dx,dy)
class Ground:
def __init__(self, shapeID, offsetX=0, offsetY=0, offsetZ=0, angle=0, height=None, width=None, button = None):
self.shapeID = shapeID
self.offsetX = offsetX
self.offsetY = offsetY
self.offsetZ = offsetZ
self.angle = angle
self.button = button
self.hei = height
self.wid = width
class House:
def __init__(self, type, name, shape, height=100, angle=0, id1=0, id2=2, offsetX=0, offsetY=0) -> None:
self.type = type
self.name = name
self.shape = shape
self.height = height
class Depot:
def __init__(self, name, layout, ground=[], area=[], house=[], container_scale=1, offset=Point(0,0), scale=1, defaultGround=0) -> None:
self.name = name
self.layout = layout
self.contWidth = 8 * container_scale
self.contHeight = 8.5 * container_scale
self.contLength = 20 * container_scale
self.contHalfLength = 10 * container_scale
self.contGap = math.floor(self.contLength*0.084)
self.fontSize = 3*container_scale
self.Area = area
self.house = house
self.ground=ground
self.offset = offset
self.scale = scale
self.defaultGround = defaultGround
class Button:
def __init__(self, p, text, angle) -> None:
self.position = p
self.text = text
self.angle = angle
def translate(self, x=0, y=0):
self.position.x +=x;
self.position.y +=y;
def deg2rad(a):
return (((a)/360)*(2*math.pi))