-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.py
More file actions
345 lines (237 loc) · 9.19 KB
/
UI.py
File metadata and controls
345 lines (237 loc) · 9.19 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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
from tkinter import *
import ast
import classes
import option
#frameBuffer = {}
root = Tk()
p=[]
l=[]
po=[]
c=[]
cur=[]
editLines=[]
editPoints=[]
selected=None
grid = classes.Grid([50,30])
def selectedBlank(selected):
if isinstance(selected, classes.Polyline):
for line in selected.lines:
for point in line.points:
point.widget.configure(bg='white')
if selected.fillment:
for point in selected.fillment:
point.widget.configure(bg='white')
elif isinstance(selected, classes.Circle):
for point in selected.points:
point.widget.configure(bg='white')
elif isinstance(selected, classes.Curve):
for point in selected.curve:
point.widget.configure(bg='white')
def releventPoint(widget):
widget.configure(bg="black")
point = option.getCoordinates(grid, widget)
p.append(classes.Point(widget, point))
def editPoint(widget):
global selected
if widget['bg'] == 'blue':
for poly in po:
for li in poly.lines:
for point in li.points:
if point.widget == widget:
selected = poly
if selected:
for li in poly.lines:
for point in li.points:
point.widget.configure(bg='red')
break
for circle in c:
for point in circle.points:
if point.widget == widget:
selected = circle
if selected:
for point in circle.points:
point.widget.configure(bg='red')
for curve in cur:
for point in curve.curve:
if point.widget == widget:
selected = curve
if selected:
for point in curve.curve:
point.widget.configure(bg='red')
def clearAll(widget):
for i in range(grid.ysize):
for j in range(grid.xsize):
widget[i][j].configure(bg="white")
del p[:]
del l[:]
del po[:]
del c[:]
del cur[:]
global selected
selected = None
def translade(translade,selected):
selectedBlank(selected)
points = translade.get()
points = ast.literal_eval(points)
if isinstance(selected, classes.Polyline):
selected.translade(points, matriz)
if selected.fillment: scanLine(selected)
for line in selected.lines:
for point in line.points:
point.widget.configure(bg='red')
if isinstance(selected, classes.Circle):
selected.translade(points, matriz)
for point in selected.points:
point.widget.configure(bg='red')
if isinstance(selected, classes.Curve):
selected.translade(points, matriz, grid = grid)
for point in selected.curve:
point.widget.configure(bg='red')
def rotate(angle,selected):
selectedBlank(selected)
angle = angle.get()
angle = int(angle)
if isinstance(selected, classes.Polyline):
selected.rotate(angle, matriz)
if selected.fillment: scanLine(selected)
for line in selected.lines:
for points in line.points:
points.widget.configure(bg='red')
elif isinstance(selected, classes.Curve):
selected.rotate(angle, matriz, grid = grid)
for point in selected.curve:
point.widget.configure(bg='red')
def escale(escale, selected):
selectedBlank(selected)
escale = escale.get()
escale = ast.literal_eval(escale)
if isinstance(selected, classes.Polyline):
selected.escale(escale, matriz)
if selected.fillment: scanLine(selected)
for line in selected.lines:
for point in line.points:
point.widget.configure(bg='red')
elif isinstance(selected, classes.Circle):
selected.escale(escale, matriz)
for point in selected.points:
point.widget.configure(bg='red')
elif isinstance(selected, classes.Curve):
selected.escale(escale, matriz, grid = grid)
for point in selected.curve:
point.widget.configure(bg='red')
def scanLine(selected):
if isinstance(selected, classes.Polyline):
selected.scanLine(matriz)
for point in selected.fillment:
point.widget.configure(bg='blue')
for lines in selected.lines:
for point in lines.points:
point.widget.configure(bg='red')
def recursiveFill():
p[-1].recursiveFill(grid,matriz)
del p[:]
def drawLine():
generatedPoints = p[-2].connectPoints(p[-1])
line = []
for point in generatedPoints:
line.append(classes.Point(matriz[point[1]][point[0]], point))
for point in line:
point.widget.configure(bg='blue')
l.append(classes.Line(line))
newLine = l[-1]
if l == []:
newPoly = classes.Polyline()
newPoly.addLine(newLine)
po.append(newPoly)
else:
added = False
polylineFound = None
for poly in po:
if poly.ifVertex(newLine):
polylineFound = poly
poly.addLine(newLine)
added = True
if polylineFound:
for poly in po:
if poly.ifVertex(newLine) and poly != polylineFound:
polylineFound.mergePolyline(poly)
po.remove(poly)
if not added:
newPoly = classes.Polyline()
newPoly.addLine(newLine)
po.append(newPoly)
l.append(newLine)
del p[:]
def drawCircle():
r, generatedPoints = p[-2].connectCircle(newPoint = p[-1])
circle = []
for point in generatedPoints:
if point[0] >= 0 and point[1] >= 0 and point[0] <= grid.xsize-1 and point[1] <= grid.ysize-1:
circle.append(classes.Point(matriz[point[1]][point[0]], point))
p[-2].widget.configure(bg='white')
p[-1].widget.configure(bg='white')
for point in circle:
point.widget.configure(bg='blue')
c.append(classes.Circle(p[-2], r, circle))
del p[:]
def drawCurve():
points = [p[-4],p[-3],p[-2],p[-1]]
generatedPoints = p[-4].connectCurve([p[-3], p[-2], p[-1]], matriz, grid)
curve = []
for point in generatedPoints:
curve.append(classes.Point(matriz[point[1]][point[0]], point))
for point in points:
point.widget.configure(bg='white')
for point in curve:
point.widget.configure(bg='blue')
cur.append(classes.Curve(points, curve))
del p[:]
buttonFrame = Frame(root)
buttonFrame.grid(row=0,column=0, sticky=W, padx=5, pady=5)
inputFrame = Frame(root)
inputFrame.grid(row=1,column=1, sticky=N)
gridFrame = Frame(root)
gridFrame.grid(row=1,column=0)
matriz,linha=[],[]
for i in range(grid.ysize):
for j in range(grid.xsize):
linha.append(Frame(gridFrame,bg="white",height=15,width=15,bd=1,relief=SUNKEN))
matriz.append(linha)
linha=[]
for i in range(grid.ysize):
for j in range(grid.xsize):
matriz[i][j].bind("<Button-1>", lambda event, widget=matriz[i][j] : releventPoint(widget))
#matriz[i][j].bind("<Button-2>", lambda event, widget=matriz[i][j] : editPoint(widget))
matriz[i][j].bind("<Button-3>", lambda event, widget=matriz[i][j] : editPoint(widget))
matriz[i][j].grid(row=i,column=j)
grid.defineMatrix(matriz)
linha = Button(buttonFrame, text="Bresenham", command=lambda : drawLine())
linha.pack(side=LEFT, padx=5)
circulo = Button(buttonFrame, text="Circulo", command=lambda : drawCircle())
circulo.pack(side=LEFT, padx=5)
curva = Button(buttonFrame, text="Curva [4]", command=lambda : drawCurve())
curva.pack(side=LEFT, padx=5)
recur = Button(buttonFrame, text="Preenchimento Recursivo", command=lambda : recursiveFill())
recur.pack(side=LEFT, padx=5)
scan = Button(buttonFrame, text="Scan Line", command=lambda : scanLine(selected))
scan.pack(side=LEFT, padx=5)
#buffer = Button(buttonFrame, text="Return buffer", command=lambda : printBuffer())
#buffer.pack(side=LEFT, padx=5)
input_Translad = Button(inputFrame, text="Transladar [T1,T2]", command=lambda : translade(trans_input, selected))
input_Translad.pack(side=TOP, padx=5)
trans_input = StringVar()
inputTrans_box = Entry(inputFrame, textvariable=trans_input)
inputTrans_box.pack()
input_Rotation = Button(inputFrame, text="Rotacionar X", command=lambda : rotate(angle_input, selected))
input_Rotation.pack(side=TOP, padx=5)
angle_input = StringVar()
inputAngle_box = Entry(inputFrame, textvariable=angle_input)
inputAngle_box.pack()
input_Escalation = Button(inputFrame, text="Escalar [S1,S2]", command=lambda : escale(escale_input, selected))
input_Escalation.pack(side=TOP, padx=5)
escale_input = StringVar()
inputEscale_box = Entry(inputFrame, textvariable=escale_input)
inputEscale_box.pack()
clear = Button(buttonFrame, text="Clear", fg="Red", command=lambda : clearAll(matriz) )
clear.pack(side=RIGHT, padx=10)
root.mainloop()