-
Notifications
You must be signed in to change notification settings - Fork 2
/
data.py
223 lines (161 loc) · 7.78 KB
/
data.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
import sys
import math
import pickle
import re
class CadData(object):
def __init__(self):
self.data =[
[
0,
'Noname','',
[[],[],[],[],[],[]]
]
]#color,filename,path//id,x,y,z,code,typecode
self.arc = []
self.snapp_xy = []
def new_file(self):
self.data.append(
[
0,
'Noname_' + str(len(self.data)),
'',
[[],[],[],[],[],[]]
]
)#color,filename,path//id,x,y,z,code,typecode
def open_file(self,filepath):
with open(filepath, 'rb') as handle:
self.data.append(pickle.load(handle))
def close_file(self,active_file):
self.data.pop(active_file)
#prompt for save or save as.
def save_file(self,active_file,directory):
if len(directory) > 0:
self.data[active_file][2] = directory
filename = re.findall(r'\w+(?=.cad)', directory, re.I)
self.data[active_file][1] = filename[-1]
with open(directory, 'wb') as handle:
pickle.dump(self.data[active_file], handle)
def save_close_all(self):
pass
def change_color(self, active_file, color):
self.data[active_file][0] = color
def paint(self, ide, MAP_X, MAP_Y, MAP_Z,code, keyes1, snapp, new, active_file): #Get values from gui.
x = MAP_X
y = MAP_Y
z = MAP_Z
# Catch Snapp Nerest
if snapp[0] == "sp":
maxl = 0
minl = 0
snapp_xy = []
for xy in range(len(self.data[active_file][3][1])):
l = math.sqrt((x - self.data[active_file][3][1][xy])**2+(y - self.data[active_file][3][2][xy])**2)
if l > minl:
maxl = l
minl = maxl
for xyz in range(len(self.data[active_file][3][1])):
l = math.sqrt((x - self.data[active_file][3][1][xyz])**2+(y - self.data[active_file][3][2][xyz])**2)
if l <= minl:
minl = l
del self.snapp_xy[:]
self.snapp_xy.append(self.data[active_file][3][1][xyz])
self.snapp_xy.append(self.data[active_file][3][2][xyz])
self.snapp_xy.append(self.data[active_file][3][3][xyz])
# Fix one point lines
if len(keyes1) == 1:
if len(self.data[active_file][3][5]) > 0:
if keyes1[0] != "dl" and self.data[active_file][3][5][len(self.data[active_file][3][5])-1] == "dl":
self.data[active_file][3][5][len(self.data[active_file][3][5])-1] = "dp"
print("did")
# Point
if keyes1[0] == "dp":
del self.arc[:]
self.data[active_file][3][0].append(ide)
if snapp[0] == "sp":
self.data[active_file][3][1].append(self.snapp_xy[0])
self.data[active_file][3][2].append(self.snapp_xy[1])
self.data[active_file][3][3].append(self.snapp_xy[2])
else:
self.data[active_file][3][1].append(x)
self.data[active_file][3][2].append(y)
self.data[active_file][3][3].append(z)
self.data[active_file][3][4].append(code)
self.data[active_file][3][5].append("dp")
# Line
elif keyes1[0] == "dl":
del self.arc[:]
self.data[active_file][3][0].append(ide)
if snapp[0] == "sp":
self.data[active_file][3][1].append(self.snapp_xy[0])
self.data[active_file][3][2].append(self.snapp_xy[1])
self.data[active_file][3][3].append(self.snapp_xy[2])
else:
self.data[active_file][3][1].append(x)
self.data[active_file][3][2].append(y)
self.data[active_file][3][3].append(z)
self.data[active_file][3][4].append(code)
index = len(self.data[active_file][3][5]) - 1
if index >= 0:
if self.data[active_file][3][5][index] == "dl" or self.data[active_file][3][5][index] == "/dl" and new[0] == 0:
self.data[active_file][3][5].append("/dl")
self.data[active_file][3][5][index] = "dl"
else:
self.data[active_file][3][5].append("dl")
else:
self.data[active_file][3][5].append("dl")
# Arc
elif keyes1[0] == "a3":
if len(self.arc) <= 9:
if snapp[0] == "sp":
self.arc.append(self.snapp_xy[0])
self.arc.append(self.snapp_xy[1])
self.arc.append(self.snapp_xy[2])
else:
self.arc.append(x)
self.arc.append(y)
self.arc.append(z)
if len(self.arc) == 6 and self.arc[0] == self.arc[3] and self.arc[1] == self.arc[4]:
#print("no")
self.arc.pop()
self.arc.pop()
self.arc.pop()
elif len(self.arc) == 9 and self.arc[0] == self.arc[6] and self.arc[1] == self.arc[7]:
#print("no")
self.arc.pop()
self.arc.pop()
self.arc.pop()
elif len(self.arc) == 9 and self.arc[3] == self.arc[6] and self.arc[4] == self.arc[7]:
#print("no")
self.arc.pop()
self.arc.pop()
self.arc.pop()
elif len(self.arc) == 9 and (
self.arc[0]*(self.arc[4]-self.arc[7])
+ self.arc[3]*(self.arc[7]-self.arc[1])
+ self.arc[6]*(self.arc[1]-self.arc[4])
) == 0:
print("no")
self.arc.pop()
self.arc.pop()
self.arc.pop()
if len(self.arc) == 9 :
print(self.arc)
i = 0
while i != 9:
self.data[active_file][3][0].append(ide)
self.data[active_file][3][1].append(self.arc[0 + i])
self.data[active_file][3][2].append(self.arc[1 + i])
self.data[active_file][3][3].append(self.arc[2 + i])
self.data[active_file][3][4].append(code)
if i == 6:
self.data[active_file][3][5].append("/a3")
else:
self.data[active_file][3][5].append("a3")
i = i + 3
del self.arc[:]
else:
pass
else:
pass
print(self.data)
return