-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.py
More file actions
682 lines (631 loc) · 32.9 KB
/
UI.py
File metadata and controls
682 lines (631 loc) · 32.9 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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
# -*- coding: UTF-8 -*-
#
# generated by wxGlade 0.8.0b3 on Tue Mar 13 00:17:16 2018
#
import wx
import os
import time
from Aestrela import *
# begin wxGlade: dependencies
# end wxGlade
# begin wxGlade: extracode
# end wxGlade
class MainFrame(wx.Frame):
def __init__(self, *args, **kwds):
self.timeNow = 0.0
self.timespan = .5 # Tempo para atualizar interface(ms)
# [lin, col, inicio, alvo, ch, cv, cd, movimento, obstaculo]
self.Results = False
self.MapaHeuristica = []
self.Alternatives = []
self.Caminho = []
self.Aberto = []
self.Fechado = []
self.MapaCustoG = []
self.MapaCustoH = []
self.MapaCaminho = []
self.Buttons = []
self.Labels = []
self.Obstaculos = [2, 5]
self.Inicio = 1
self.Alvo = 9
self.Linhas = 3
self.Colunas = 3
self.CustoV = 1
self.CustoH = 1
self.CustoD = 12
self.Movimento = {'N': True, 'S': True, 'E': True, 'O': True, 'NE': True, 'NO': True, 'SE': True, 'SO': True}
self.DirName = ""
self.FileName = ""
self.DeltaX = 0
self.DeltaY = 0
# begin wxGlade: MainFrame.__init__
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.SetSize((900, 720))
self.notebook = wx.Notebook(self, wx.ID_ANY)
self.notebook_settings = wx.Panel(self.notebook, wx.ID_ANY)
self.open_button = wx.Button(self.notebook_settings, wx.ID_ANY, "Abrir")
self.open_path = wx.TextCtrl(self.notebook_settings, wx.ID_ANY, "")
self.update_button = wx.Button(self.notebook_settings, wx.ID_ANY, "Carregar")
self.panel_1 = wx.Panel(self.notebook_settings, wx.ID_ANY)
self.lines_spin = wx.SpinCtrl(self.panel_1, wx.ID_ANY, "3", min=2, max=100, style=wx.SP_ARROW_KEYS | wx.TE_NO_VSCROLL)
self.Bind(wx.EVT_SPINCTRL, self.UpdateStartGoal, self.lines_spin)
self.columns_spin = wx.SpinCtrl(self.panel_1, wx.ID_ANY, "3", min=2, max=100, style=wx.SP_ARROW_KEYS | wx.TE_LEFT | wx.TE_NO_VSCROLL)
self.Bind(wx.EVT_SPINCTRL, self.UpdateStartGoal, self.columns_spin)
self.start_combo = wx.ComboBox(self.panel_1, wx.ID_ANY, choices=["1", "2", "3", "4", "5", "6", "7", "8"], style=wx.CB_DROPDOWN | wx.CB_READONLY)
self.goal_combo = wx.ComboBox(self.panel_1, wx.ID_ANY, choices=["2", "3", "4", "5", "6", "7", "8", "9"], style=wx.CB_DROPDOWN | wx.CB_READONLY)
self.hcost_spin = wx.SpinCtrl(self.panel_1, wx.ID_ANY, "1", min=1, max=100, style=wx.SP_ARROW_KEYS | wx.TE_LEFT | wx.TE_NO_VSCROLL)
self.vcost_spin = wx.SpinCtrl(self.panel_1, wx.ID_ANY, "1", min=1, max=100, style=wx.SP_ARROW_KEYS | wx.TE_LEFT | wx.TE_NO_VSCROLL)
self.dcost_combo = wx.ComboBox(self.panel_1, wx.ID_ANY, choices=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "CH +CV", u"\u221a(CH\u00b2+CV\u00b2)"], style=wx.CB_DROPDOWN | wx.CB_READONLY)
self.nw_button = wx.Button(self.panel_1, wx.ID_ANY, "NO")
self.n_button = wx.Button(self.panel_1, wx.ID_ANY, "N")
self.ne_button = wx.Button(self.panel_1, wx.ID_ANY, "NE")
self.w_button = wx.Button(self.panel_1, wx.ID_ANY, "O")
self.dumb_button = wx.Button(self.panel_1, wx.ID_ANY, u"\u2297")
self.e_button = wx.Button(self.panel_1, wx.ID_ANY, "E")
self.sw_button = wx.Button(self.panel_1, wx.ID_ANY, "SO")
self.s_button = wx.Button(self.panel_1, wx.ID_ANY, "S")
self.se_button = wx.Button(self.panel_1, wx.ID_ANY, "SE")
self.panel_2 = wx.Panel(self.panel_1, wx.ID_ANY)
self.button_1 = wx.Button(self.panel_2, wx.ID_ANY, "1")
self.button_2 = wx.Button(self.panel_2, wx.ID_ANY, "2")
self.button_3 = wx.Button(self.panel_2, wx.ID_ANY, "3")
self.button_4 = wx.Button(self.panel_2, wx.ID_ANY, "4")
self.button_5 = wx.Button(self.panel_2, wx.ID_ANY, "5")
self.button_6 = wx.Button(self.panel_2, wx.ID_ANY, "6")
self.button_7 = wx.Button(self.panel_2, wx.ID_ANY, "7")
self.button_8 = wx.Button(self.panel_2, wx.ID_ANY, "8")
self.button_9 = wx.Button(self.panel_2, wx.ID_ANY, "9")
self.notebook_lab = wx.Panel(self.notebook, wx.ID_ANY)
self.run_button = wx.Button(self.notebook_lab, wx.ID_ANY, "Executar algoritmo!")
self.results_button = wx.Button(self.notebook_lab, wx.ID_ANY, "Mostrar resultados!\n")
self.output_panel = wx.Panel(self.notebook_lab, wx.ID_ANY)
self.output_panel.Bind(wx.EVT_PAINT, self.DrawMap)
self.output_panel.Bind(wx.EVT_LEFT_DCLICK, self.onMapClick)
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_BUTTON, self.OnOpen, self.open_button)
self.Bind(wx.EVT_TEXT_ENTER, self.OnPathEnter, self.open_path)
self.Bind(wx.EVT_BUTTON, self.OnPathEnter, self.update_button)
self.Bind(wx.EVT_COMBOBOX, self.UpdateStartGoal, self.start_combo)
self.Bind(wx.EVT_COMBOBOX, self.UpdateStartGoal, self.goal_combo)
self.Bind(wx.EVT_BUTTON, self.UpdateMovement, self.nw_button)
self.Bind(wx.EVT_BUTTON, self.UpdateMovement, self.n_button)
self.Bind(wx.EVT_BUTTON, self.UpdateMovement, self.ne_button)
self.Bind(wx.EVT_BUTTON, self.UpdateMovement, self.w_button)
self.Bind(wx.EVT_BUTTON, self.UpdateMovement, self.e_button)
self.Bind(wx.EVT_BUTTON, self.UpdateMovement, self.sw_button)
self.Bind(wx.EVT_BUTTON, self.UpdateMovement, self.s_button)
self.Bind(wx.EVT_BUTTON, self.UpdateMovement, self.se_button)
self.Bind(wx.EVT_BUTTON, self.UpdateObstacles, self.button_1)
self.Bind(wx.EVT_BUTTON, self.UpdateObstacles, self.button_2)
self.Bind(wx.EVT_BUTTON, self.UpdateObstacles, self.button_3)
self.Bind(wx.EVT_BUTTON, self.UpdateObstacles, self.button_4)
self.Bind(wx.EVT_BUTTON, self.UpdateObstacles, self.button_5)
self.Bind(wx.EVT_BUTTON, self.UpdateObstacles, self.button_6)
self.Bind(wx.EVT_BUTTON, self.UpdateObstacles, self.button_7)
self.Bind(wx.EVT_BUTTON, self.UpdateObstacles, self.button_8)
self.Bind(wx.EVT_BUTTON, self.UpdateObstacles, self.button_9)
self.Bind(wx.EVT_BUTTON, self.OnRun, self.run_button)
self.Bind(wx.EVT_BUTTON, self.OnExport, self.results_button)
self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.ResetPath, self.notebook)
# end wxGlade
# Bindings user added in wxGlade
# self.Bind(wx.EVT_SPINCTRL, self.UpdateSettings, self.lines_spin)
# self.Bind(wx.EVT_SPINCTRL, self.UpdateSettings, self.columns_spin)
def __set_properties(self):
# path para o icone geral - entre pcs
_icon = wx.NullIcon
scrip_dir = os.path.dirname(__file__)
_icon.CopyFromBitmap(wx.Bitmap(scrip_dir + "\\design\\icone_Qab_icon.ico", wx.BITMAP_TYPE_ANY))
self.SetIcon(_icon)
# begin wxGlade: MainFrame.__set_properties
self.SetTitle("A Estrela - Aplicativo")
self.open_button.SetToolTip(u"Abrir o arquivo de configura\u00e7\u00f5es.")
self.open_path.SetToolTip("Local do arquivo.")
self.update_button.SetToolTip(u"Carrega as configura\u00e7\u00f5es do arquivo")
self.lines_spin.SetMinSize((149, 25))
self.lines_spin.SetToolTip(u"N\u00famero de linhas do labirinto")
self.columns_spin.SetMinSize((149, 25))
self.columns_spin.SetToolTip(u"N\u00famero de colunas do labirinto")
self.start_combo.SetMinSize((149, 25))
self.start_combo.SetToolTip(u"Posi\u00e7\u00f5es de Partida")
self.start_combo.SetSelection(0)
self.goal_combo.SetMinSize((149, 25))
self.goal_combo.SetToolTip(u"Posi\u00e7\u00e3o alvo")
self.goal_combo.SetSelection(7)
self.hcost_spin.SetMinSize((149, 25))
self.hcost_spin.SetToolTip("Custo do movimento horizontal")
self.vcost_spin.SetMinSize((149, 25))
self.vcost_spin.SetToolTip("Custo do movimento vertical\n")
self.dcost_combo.SetMinSize((149, 25))
self.dcost_combo.SetToolTip(u"Custo damovimenta\u00e7\u00e3o na diagonal")
self.dcost_combo.SetSelection(11)
self.nw_button.SetBackgroundColour(wx.Colour(0, 255, 0))
self.nw_button.SetToolTip(u"Permite/Bloqueia a movimenta\u00e7\u00e3o nessa dire\u00e7\u00e3o.")
self.n_button.SetBackgroundColour(wx.Colour(0, 255, 0))
self.n_button.SetToolTip(u"Permite/Bloqueia a movimenta\u00e7\u00e3o nessa dire\u00e7\u00e3o.")
self.ne_button.SetBackgroundColour(wx.Colour(0, 255, 0))
self.ne_button.SetToolTip(u"Permite/Bloqueia a movimenta\u00e7\u00e3o nessa dire\u00e7\u00e3o.")
self.w_button.SetBackgroundColour(wx.Colour(0, 255, 0))
self.w_button.SetToolTip(u"Permite/Bloqueia a movimenta\u00e7\u00e3o nessa dire\u00e7\u00e3o.")
self.dumb_button.SetToolTip(u"Posi\u00e7\u00e3o de partida")
self.dumb_button.Enable(False)
self.e_button.SetBackgroundColour(wx.Colour(0, 255, 0))
self.e_button.SetToolTip(u"Permite/Bloqueia a movimenta\u00e7\u00e3o nessa dire\u00e7\u00e3o.")
self.sw_button.SetBackgroundColour(wx.Colour(0, 255, 0))
self.sw_button.SetToolTip(u"Permite/Bloqueia a movimenta\u00e7\u00e3o nessa dire\u00e7\u00e3o.")
self.s_button.SetBackgroundColour(wx.Colour(0, 255, 0))
self.s_button.SetToolTip(u"Permite/Bloqueia a movimenta\u00e7\u00e3o nessa dire\u00e7\u00e3o.")
self.se_button.SetBackgroundColour(wx.Colour(0, 255, 0))
self.se_button.SetToolTip(u"Permite/Bloqueia a movimenta\u00e7\u00e3o nessa dire\u00e7\u00e3o.")
self.button_1.SetBackgroundColour(wx.Colour(0, 255, 0))
self.button_1.SetToolTip(u"Clique para ativa/desativar o obst\u00e1culo")
self.button_1.Enable(False)
self.button_2.SetBackgroundColour(wx.Colour(255, 0, 0))
self.button_2.SetToolTip(u"Clique para ativa/desativar o obst\u00e1culo\n")
self.button_3.SetToolTip(u"Clique para ativa/desativar o obst\u00e1culo\n")
self.button_4.SetToolTip(u"Clique para ativa/desativar o obst\u00e1culo\n")
self.button_5.SetBackgroundColour(wx.Colour(255, 0, 0))
self.button_5.SetToolTip(u"Clique para ativa/desativar o obst\u00e1culo\n")
self.button_6.SetToolTip(u"Clique para ativa/desativar o obst\u00e1culo\n")
self.button_7.SetToolTip(u"Clique para ativa/desativar o obst\u00e1culo\n")
self.button_8.SetToolTip(u"Clique para ativa/desativar o obst\u00e1culo\n")
self.button_9.SetBackgroundColour(wx.Colour(255, 255, 0))
self.button_9.SetToolTip(u"Clique para ativa/desativar o obst\u00e1culo\n")
self.button_9.Enable(False)
self.run_button.SetMinSize((123, 37))
self.run_button.SetToolTip(u"Executa o algoritmo para as configura\u00e7\u00f5es dadas")
self.results_button.SetToolTip("Mostra os resultados no mapa ilustrado.")
# end wxGlade
def __do_layout(self):
# begin wxGlade: MainFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_10 = wx.BoxSizer(wx.VERTICAL)
sizer_11 = wx.BoxSizer(wx.HORIZONTAL)
sizer_2 = wx.BoxSizer(wx.VERTICAL)
sizer_4 = wx.StaticBoxSizer(wx.StaticBox(self.notebook_settings, wx.ID_ANY, "Manual"), wx.VERTICAL)
sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
sizer_9 = wx.StaticBoxSizer(wx.StaticBox(self.panel_2, wx.ID_ANY, u"Pr\u00e9-Visualiza\u00e7\u00e3o - Obst\u00e1culos"), wx.VERTICAL)
self.preview_sizer = wx.GridSizer(3, 3, 1, 1)
sizer_7 = wx.BoxSizer(wx.VERTICAL)
sizer_8 = wx.StaticBoxSizer(wx.StaticBox(self.panel_1, wx.ID_ANY, u"Movimenta\u00e7\u00e3o Permitida"), wx.VERTICAL)
grid_sizer_2 = wx.GridSizer(0, 3, 0, 0)
grid_sizer_1 = wx.GridSizer(7, 2, 1, 1)
sizer_3 = wx.StaticBoxSizer(wx.StaticBox(self.notebook_settings, wx.ID_ANY, "Importar de Arquivo"), wx.VERTICAL)
sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
sizer_5.Add(self.open_button, 1, wx.ALIGN_CENTER | wx.ALL, 0)
sizer_5.Add(self.open_path, 5, wx.ALIGN_CENTER, 0)
sizer_5.Add(self.update_button, 1, wx.ALIGN_CENTER, 0)
sizer_3.Add(sizer_5, 1, wx.EXPAND, 0)
sizer_2.Add(sizer_3, 0, wx.EXPAND, 0)
lines_label = wx.StaticText(self.panel_1, wx.ID_ANY, u"N\u00famero de Linhas", style=wx.ALIGN_LEFT)
lines_label.SetMinSize((140, 25))
lines_label.SetToolTip(u"N\u00famero de linhas do labirinto")
grid_sizer_1.Add(lines_label, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, 0)
grid_sizer_1.Add(self.lines_spin, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.ALL, 0)
columns_label = wx.StaticText(self.panel_1, wx.ID_ANY, u"N\u00famero de Colunas", style=wx.ALIGN_LEFT)
columns_label.SetMinSize((140, 25))
columns_label.SetToolTip(u"N\u00famero de colunas do labirinto")
grid_sizer_1.Add(columns_label, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, 0)
grid_sizer_1.Add(self.columns_spin, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, 0)
start_label = wx.StaticText(self.panel_1, wx.ID_ANY, u"Posi\u00e7\u00e3o Inicial", style=wx.ALIGN_LEFT)
start_label.SetMinSize((140, 25))
start_label.SetToolTip(u"Posi\u00e7\u00e3o Inicial")
grid_sizer_1.Add(start_label, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, 0)
grid_sizer_1.Add(self.start_combo, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.ALL, 0)
goal_label = wx.StaticText(self.panel_1, wx.ID_ANY, u"Posi\u00e7\u00e3o Alvo", style=wx.ALIGN_LEFT)
goal_label.SetMinSize((140, 25))
goal_label.SetToolTip(u"Posi\u00e7\u00e3o final")
grid_sizer_1.Add(goal_label, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, 0)
grid_sizer_1.Add(self.goal_combo, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.ALL, 0)
hcost_label = wx.StaticText(self.panel_1, wx.ID_ANY, "Custo Horizontal", style=wx.ALIGN_LEFT)
hcost_label.SetMinSize((140, 25))
hcost_label.SetToolTip("Custo do movimento horizontal")
grid_sizer_1.Add(hcost_label, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, 0)
grid_sizer_1.Add(self.hcost_spin, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.ALL, 0)
vcost_label = wx.StaticText(self.panel_1, wx.ID_ANY, "Custo Vertical", style=wx.ALIGN_LEFT)
vcost_label.SetMinSize((140, 25))
vcost_label.SetToolTip("Custo do movimento vertical\n")
grid_sizer_1.Add(vcost_label, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, 0)
grid_sizer_1.Add(self.vcost_spin, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.ALL, 0)
dcost_label = wx.StaticText(self.panel_1, wx.ID_ANY, "Custo Diagonal", style=wx.ALIGN_LEFT)
dcost_label.SetMinSize((140, 25))
dcost_label.SetToolTip("Custo do movimento diagonal.\n")
grid_sizer_1.Add(dcost_label, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, 0)
grid_sizer_1.Add(self.dcost_combo, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.ALL, 0)
sizer_7.Add(grid_sizer_1, 0, 0, 0)
grid_sizer_2.Add(self.nw_button, 0, wx.EXPAND, 0)
grid_sizer_2.Add(self.n_button, 0, wx.EXPAND, 0)
grid_sizer_2.Add(self.ne_button, 0, wx.EXPAND, 0)
grid_sizer_2.Add(self.w_button, 0, wx.EXPAND, 0)
grid_sizer_2.Add(self.dumb_button, 0, wx.EXPAND, 0)
grid_sizer_2.Add(self.e_button, 0, wx.EXPAND, 0)
grid_sizer_2.Add(self.sw_button, 0, wx.EXPAND, 0)
grid_sizer_2.Add(self.s_button, 0, wx.EXPAND, 0)
grid_sizer_2.Add(self.se_button, 0, wx.EXPAND, 0)
sizer_8.Add(grid_sizer_2, 1, wx.EXPAND, 0)
sizer_7.Add(sizer_8, 1, wx.EXPAND, 0)
sizer_6.Add(sizer_7, 0, wx.EXPAND, 0)
self.preview_sizer.Add(self.button_1, 0, wx.EXPAND, 0)
self.preview_sizer.Add(self.button_2, 0, wx.EXPAND, 0)
self.preview_sizer.Add(self.button_3, 0, wx.EXPAND, 0)
self.preview_sizer.Add(self.button_4, 0, wx.EXPAND, 0)
self.preview_sizer.Add(self.button_5, 0, wx.EXPAND, 0)
self.preview_sizer.Add(self.button_6, 0, wx.EXPAND, 0)
self.preview_sizer.Add(self.button_7, 0, wx.EXPAND, 0)
self.preview_sizer.Add(self.button_8, 0, wx.EXPAND, 0)
self.preview_sizer.Add(self.button_9, 0, wx.EXPAND, 0)
sizer_9.Add(self.preview_sizer, 1, wx.ALIGN_CENTER | wx.EXPAND, 0)
self.panel_2.SetSizer(sizer_9)
sizer_6.Add(self.panel_2, 1, wx.EXPAND, 0)
self.panel_1.SetSizer(sizer_6)
sizer_4.Add(self.panel_1, 1, wx.EXPAND, 0)
sizer_2.Add(sizer_4, 5, wx.EXPAND, 0)
self.notebook_settings.SetSizer(sizer_2)
sizer_11.Add(self.run_button, 0, 0, 0)
sizer_11.Add(self.results_button, 0, 0, 0)
sizer_10.Add(sizer_11, 0, 0, 0)
sizer_10.Add(self.output_panel, 1, wx.EXPAND, 0)
self.notebook_lab.SetSizer(sizer_10)
self.notebook.AddPage(self.notebook_settings, u"Configua\u00e7\u00f5es")
self.notebook.AddPage(self.notebook_lab, "Labirinto")
sizer_1.Add(self.notebook, 1, wx.EXPAND, 0)
self.SetSizer(sizer_1)
self.Layout()
self.Centre()
# end wxGlade
def setting_file(self, path):
with open(path) as f:
l_0 = f.readline().splitlines()
l_remaining = f.readlines()
line0 = l_0[0].split()
self.lines_spin.SetValue(int(line0[0]))
self.columns_spin.SetValue(int(line0[1]))
#self.hcost_spin.SetValue(int(line0[3]))
#self.vcost_spin.SetValue(int(line0[2]))
# bug custos h e v invertidos
self.hcost_spin.SetValue(int(line0[2]))
self.vcost_spin.SetValue(int(line0[3]))
# Limpa os dados antigos
self.Obstaculos.clear()
nlinhas = int(line0[0])
ncolunas = int(line0[1])
for i in range(nlinhas):
item = l_remaining[i].strip().split()
for j in range(ncolunas):
# Posição atual sendo analisada
pos = i*ncolunas + j + 1
if item[j] == '1':
self.Obstaculos.append(pos)
elif item[j] == '2':
self.Inicio = int(pos)
elif item[j] == '3':
self.Alvo = int(pos)
# Atualiza os valores possíveis da posição inicial/final
self.UpdateStartGoal(wx.EVT_ENTER_WINDOW, start=self.Inicio, goal=self.Alvo)
def OnOpen(self, event): # wxGlade: MainFrame.<event_handler>
""" Open a file"""
dlg = wx.FileDialog(self, "Choose a file", self.DirName, "", "*.*", wx.FD_OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.FileName = dlg.GetFilename()
self.DirName = dlg.GetDirectory()
path = os.path.join(self.DirName, self.FileName)
self.setting_file(path)
self.open_path.SetLabelText(path)
dlg.Destroy()
def OnPathEnter(self, event): # wxGlade: MainFrame.<event_handler>
if len(self.DirName) != 0:
self.setting_file(os.path.join(self.DirName, self.FileName))
else:
event.Skip()
def UpdateMovement(self, event): # wxGlade: MainFrame.<event_handler>
""" Atualiza as possibilidades de movimentação"""
button = event.GetEventObject()
label = button.GetLabel()
if button.BackgroundColour == wx.Colour(0, 255, 0):
button.SetBackgroundColour(wx.Colour(255, 0, 0))
self.Movimento[label] = False
else:
button.SetBackgroundColour(wx.Colour(0, 255, 0))
self.Movimento[label] = True
print(self.Movimento)
def melhor_caminho(self, pos):
caminho = [pos]
pos_index = np.argwhere(mapaLabirinto == pos)
x_0 = pos_index[0][0]
y_0 = pos_index[0][1]
anterior = self.MapaCaminho[x_0][y_0]
while anterior != self.Inicio:
caminho.append(anterior)
n_index = np.argwhere(mapaLabirinto == anterior)
x_n = n_index[0][0]
y_n = n_index[0][1]
anterior = self.MapaCaminho[x_n][y_n]
caminho.append(self.Inicio)
return list(reversed(caminho))
def OnRun(self, event): # wxGlade: MainFrame.<event_handler>
# Atualiza os custos
self.CustoH = int(self.hcost_spin.GetValue())
self.CustoV = int(self.vcost_spin.GetValue())
self.CustoD = int(self.dcost_combo.GetSelection()) + 1
atualizar_config(self.Linhas, self.Colunas, self.Inicio, self.Alvo, self.CustoV, self.CustoH, self.CustoD,
self.Movimento, self.Obstaculos)
print(self.Linhas, self.Colunas, self.Inicio, self.Alvo, self.CustoH, self.CustoV, self.CustoD,
self.Movimento, self.Obstaculos)
self.Caminho.clear()
# Seis resultados: Caminho, Aberto, Fechado, MapaCustoG, MapaCustoH, MapaCaminho
self.Caminho, self.Aberto, self.Fechado, self.MapaCustoG, self.MapaCustoH, self.MapaHeuristica, self.MapaCaminho = run_a_estrela()
print(self.MapaCaminho)
if not self.Caminho:
self.Warning("Não há solução, diminua os obstáculos ou as restrições de movimentação.")
self.Caminho = []
else:
self.output_panel.Refresh()
def onMapClick(self, event):
""" Recebe a posição do mouse e converte em caminho adicionado no self.Alternatives """
if self.Results:
pos = event.GetPosition()
print(pos)
y = int(pos.x / self.DeltaX)
x = int(pos.y / self.DeltaY)
print(x,y)
print(mapaLabirinto[x][y])
conjunto = self.Aberto + self.Fechado
conjunto.remove(self.Inicio)
if mapaLabirinto[x][y] in conjunto:
self.Alternatives.append(mapaLabirinto[x][y])
self.output_panel.Refresh()
def Info(self, message, caption='Aviso!'):
dlg = wx.MessageDialog(self, message, caption, wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
def Warning(self, message, caption='Falha!'):
dlg = wx.MessageDialog(self, message, caption, wx.OK | wx.ICON_WARNING)
dlg.ShowModal()
dlg.Destroy()
def DrawCost(self, drawc):
if self.Results:
dc = drawc
dx = self.DeltaX
dy = self.DeltaY
font_size = 50
# max(min(90 - (li + co) * 4.8, 45), 6)
font = wx.Font(font_size, wx.ROMAN, wx.NORMAL, wx.NORMAL)
dc.SetFont(font)
dc.SetTextForeground(wx.WHITE)
# dc.DrawText("Hello wxPython", 200, 10)
string = "g = 000\nh' = 000\nf' = 000" # Valor máximo aproximado do texto
size = dc.GetFullMultiLineTextExtent(string)
while size[0] > (dy - 3) or size[1] > (dx - 3):
font_size -= 1
font = font.Smaller()
dc.SetFont(font)
size = dc.GetFullMultiLineTextExtent(string)
for i in (self.Aberto + self.Fechado):
index = np.argwhere(mapaLabirinto == i)
p = wx.Point((index[0][1]) * dx + 4, (index[0][0]) * dy + 4)
size = wx.Size(dx, dy)
g = round(float(self.MapaCustoG[index[0][0]][index[0][1]]), 1)
h = round(float(self.MapaHeuristica[index[0][0]][index[0][1]]), 1)
f = round(g + h, 1)
string = "g = " + str(g) + "\nh' = " + str(h) + "\nf' = " + str(f)
retangulo = wx.Rect(p, size)
dc.DrawLabel(string, retangulo, wx.ALIGN_LEFT, 1)
# dc.DrawText(string, p)
def DrawResults(self, drawc):
if self.Results:
dc = drawc
dc.SetPen(wx.Pen(wx.BLACK, 3))
dx = self.DeltaX
dy = self.DeltaY
size = wx.Size(dx, dy)
li = self.Linhas
co = self.Colunas
for i in range(1, li * co + 1):
index = np.argwhere(mapaLabirinto == i)
p = wx.Point(index[0][1] * dx, index[0][0] * dy)
if i in self.Aberto:
dc.SetBrush(wx.Brush(wx.Colour(16, 127, 201), wx.SOLID)) # Aberto
dc.DrawRectangle(p, size)
elif i in self.Fechado:
dc.SetBrush(wx.Brush(wx.Colour(12, 15, 140), wx.SOLID)) # Fechado
dc.DrawRectangle(p, size)
elif i in self.Obstaculos:
dc.SetBrush(wx.Brush(wx.Colour(255, 0, 0), wx.SOLID)) # Obstaculos
dc.DrawRectangle(p, size)
else:
dc.SetBrush(wx.Brush(wx.Colour(255, 255, 255), wx.SOLID)) # Não Acessados
dc.DrawRectangle(p, size)
def DrawAlternatives (self, drawc):
for item in self.Alternatives:
caminho = self.melhor_caminho(item)
self.DrawPath(drawc, caminho, 1)
def DrawPath(self, drawc, path, pen=0):
if len(path) > 0:
if pen == 0:
pen = wx.Pen(wx.Colour(255, 0, 0), 10)
else:
# pen = wx.Pen(wx.Colour(random.randrange(0, 255, 25), random.randrange(0, 255, 25),
# random.randrange(0, 255, 25)), 5)
pen = wx.Pen(wx.Colour(255, 255, 0), 5)
dc = drawc
dc.SetPen(pen)
dx = self.DeltaX
dy = self.DeltaY
points = []
for i in path:
index = np.argwhere(mapaLabirinto == i)
points.append(wx.Point((index[0][1]) * dx + dx / 2, (index[0][0]) * dy + dy / 2))
dc.DrawLines(points)
def OnExport(self, event): # wxGlade: MainFrame.<event_handler>
""" Verifique se está pronto para mostrar os resultados"""
if len(self.Caminho) > 0:
self.Results = True
# Desenha no painel
self.output_panel.Refresh()
else:
self.Info("Execute o algoritmo com sucesso antes.")
def UpdateObstacles(self, event): # wxGlade: MainFrame.<event_handler>
button = event.GetEventObject()
pos = int(button.GetLabel())
# Adiciona/Remove a posição da lista dependendo da cor do botao
if pos not in self.Obstaculos:
self.Obstaculos.append(pos)
button.BackgroundColour = wx.Colour(255, 0, 0)
else:
self.Obstaculos.remove(pos)
button.BackgroundColour = wx.Colour(wx.NullColour)
# Atualiza do Labirinto
# self.UpdatePreview()
def DrawMap(self, event):
li = self.Linhas
co = self.Colunas
dc = wx.PaintDC(self.output_panel)
dc.Clear()
# dc = wx.ClientDC(self.output_panel)
dc.SetPen(wx.Pen(wx.BLACK, 3))
# set brush transparent for non-filled rectangle
dc.SetBrush(wx.Brush("blue", wx.TRANSPARENT))
xmax, ymax = self.output_panel.GetSize()
deltax = int(xmax / co)
deltay = int(ymax / li)
pointsx0 = [wx.Point(a*deltax, 0) for a in range(co + 1)]
pointsxf = [wx.Point(a * deltax, ymax) for a in range(co + 1)]
pointsy0 = [wx.Point(0, a * deltay) for a in range(li + 1)]
pointsyf = [wx.Point(xmax, a * deltay) for a in range(li + 1)]
for i in range(co + 1):
# Linhas Verticais
dc.DrawLine(pointsx0[i], pointsxf[i])
for j in range(li + 1):
# Linhas Horizontais
dc.DrawLine(pointsy0[j], pointsyf[j])
self.DeltaX = deltax
self.DeltaY = deltay
# Desenha os obstaculos/inicio /alvo
dc.SetPen(wx.Pen(wx.BLACK, 4))
size = wx.Size(deltax, deltay)
for i in range(1, li * co + 1):
index = np.argwhere(mapaLabirinto == i)
p = wx.Point(index[0][1] * deltax, index[0][0] * deltay)
if i in self.Obstaculos:
dc.SetBrush(wx.Brush("red", wx.SOLID))
dc.DrawRectangle(p, size)
elif i == self.Inicio:
dc.SetBrush(wx.Brush("green", wx.SOLID))
dc.DrawRectangle(p, size)
elif i == self.Alvo:
dc.DrawRectangle(p, size)
dc.SetBrush(wx.Brush("yellow", wx.SOLID))
dc.DrawRectangle(p, size)
# Desenha o caminho caso esteja pronto
self.DrawResults(dc)
self.DrawPath(dc, self.Caminho)
self.DrawCost(dc)
self.DrawAlternatives(dc)
def UpdatePreview(self, event): # wxGlade: MainFrame.<event_handler>
tempo = time.time()
if abs(self.timeNow - tempo) >= self.timespan:
self.timeNow = time.time()
# Reseta os dados antigos
self.Caminho.clear()
self.Labels.clear()
self.Buttons.clear()
# Coleta os dados para o preview
self.Inicio = int(self.start_combo.GetValue())
self.Alvo = int(self.goal_combo.GetValue())
linhas = self.lines_spin.GetValue()
colunas = self.columns_spin.GetValue()
self.Linhas = int(linhas)
self.Colunas = int(colunas)
self.CustoH = int(self.hcost_spin.GetValue())
self.CustoV = int(self.vcost_spin.GetValue())
# bug custos invertidos
#self.CustoH = int(self.vcost_spin.GetValue())
#self.CustoV = int(self.hcost_spin.GetValue())
self.CustoD = int(self.dcost_combo.GetSelection()) + 1
font_size = max(9, (130 - (linhas + colunas)*5))
# Destroi os botões antigos
botoes = self.preview_sizer.GetChildren()
for item in botoes:
window = item.GetWindow()
window.Destroy()
# Destroi os labels antigos
# labels = self.lab_sizer.GetChildren()
# for item in labels:
# window = item.GetWindow()
# window.Destroy()
# Cria os novos botões/labels
self.preview_sizer.SetCols(colunas)
self.preview_sizer.SetRows(linhas)
# self.lab_sizer.SetCols(colunas)
# self.lab_sizer.SetRows(linhas)
for pos in range(1, linhas * colunas + 1):
button = wx.Button(self.panel_2, wx.ID_ANY, str(pos))
# label = wx.StaticText(self.output_panel, wx.ID_ANY, str(pos), style=wx.ALIGN_CENTER)
# label.SetFont(wx.Font(font_size, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
if pos == self.Inicio:
# label.SetBackgroundColour(wx.Colour(0, 255, 0))
button.SetBackgroundColour(wx.Colour(0, 255, 0))
button.Enable(False)
elif pos == self.Alvo:
# label.SetBackgroundColour(wx.Colour(255, 255, 0))
button.SetBackgroundColour(wx.Colour(255, 255, 0))
button.Enable(False)
elif pos in self.Obstaculos:
# label.SetBackgroundColour(wx.Colour(255, 0, 0))
button.SetBackgroundColour(wx.Colour(255, 0, 0))
# Ligas ao sizer e Bindings
self.preview_sizer.Add(button, 0, wx.EXPAND, 0)
# self.lab_sizer.Add(label, 1, wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, 2)
self.Bind(wx.EVT_BUTTON, self.UpdateObstacles, button)
# Adiciona a lista de botões
self.Buttons.append(button)
# self.Labels.append(label)
# Atualiza a interface
global mapaLabirinto
mapaLabirinto = np.arange(1, self.Linhas * self.Colunas + 1, 1).reshape(self.Linhas, self.Colunas)
self.preview_sizer.Layout()
# self.lab_sizer.Layout()
def UpdateStartGoal(self, event, start=0, goal=0): # wxGlade: MainFrame.<event_handler>
# Dados iniciais
if start == 0:
self.Inicio = int(self.start_combo.GetValue())
self.Alvo = int(self.goal_combo.GetValue())
else:
self.Alvo = start
self.Alvo = goal
linhas = self.lines_spin.GetValue()
colunas = self.columns_spin.GetValue()
total = linhas * colunas
# Remove as opções antigas de posicao inicio/alvo e atualiza
self.start_combo.Clear()
self.goal_combo.Clear()
posicoes = [str(s) for s in range(1, total + 1)]
self.goal_combo.Set(posicoes)
self.start_combo.Set(posicoes)
self.start_combo.SetSelection(self.Inicio - 1)
self.goal_combo.SetSelection(self.Alvo - 1)
# Remove as posições semelhantes
self.goal_combo.Delete(self.Inicio - 1)
self.start_combo.Delete(self.Alvo - 1)
# Atualiza o preview
self.UpdatePreview(wx.EVT_ENTER_WINDOW)
def ResetPath(self, event): # wxGlade: MainFrame.<event_handler>
""" Remove os desenhos ao mudar para a aba configurações"""
# Reseta o caminho, e os resultados anteriores
self.Caminho = []
self.Aberto = []
self.Fechado = []
self.MapaCustoG = []
self.Results = False
self.Alternatives = []
# end of class MainFrame
if __name__ == "__main__":
app = wx.App()
wx.InitAllImageHandlers()
MainFrame = MainFrame(None, -1, "")
app.SetTopWindow(MainFrame)
MainFrame.Show()
app.MainLoop()