forked from reds98/Tarea1GR02-CE3104-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.bak
477 lines (398 loc) · 18.6 KB
/
ui.bak
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
#lang racket/gui
(require 2htdp/image)
(require racket/include)
(require "Logic.rkt")
;_____________________________________________________________Funciones Para Graficar el Mapa
(define (lugar-numero lugar contador)
(define elemento (first(hash-ref nodos (number->string contador))))
(cond
[(eq? contador cantidad-nodos)
]
[(equal? lugar elemento )
contador]
[else
(lugar-numero lugar (+ contador 1))]
))
;; ESTAS SON LAS VARIABLES PARA SABER DONDE SE ENCUENTRAN LOS NODOS
;;(define nodos (hash "1" '("Cartago" 100 100) "2" '("SanJose" 400 400)))
(define cantidad-nodos 1 )
(define nodos (make-hash))
;;Esta es la funcion que me actualiza el hast table de nodos con sus nombres
(define (agregar-nodo nombre ids pesos bi )
(define valor1 ids)
(define valor2 pesos)
(define valor bi)
(cond
[(eq? cantidad-nodos 1)
(anadirAlGrafo cantidad-nodos '(0) '(0) '(0))
(hash-set! nodos (number->string cantidad-nodos) (list nombre (random 700) (random 700)))
(set! cantidad-nodos (+ cantidad-nodos 1))
]
[else
(quote ids)
(anadirAlGrafo cantidad-nodos ids pesos bi)
(hash-set! nodos (number->string cantidad-nodos) (list nombre (random 700) (random 700)))
(set! cantidad-nodos (+ cantidad-nodos 1))] )
)
(define (dibujar-rutas cantidad-nodos )
(cond
[(zero? cantidad-nodos )
'()
]
[else
(dibujar-rutas-aux2 cantidad-nodos (car(infoNodo cantidad-nodos)) (cadr(infoNodo cantidad-nodos)) (cadr(cdr (infoNodo cantidad-nodos) )) (-(largo (car (infoNodo cantidad-nodos) ))1))
(dibujar-rutas (- cantidad-nodos 1))
]
)
)
(define (dibujar-rutas-aux2 nodo ids pesos bi size )
(cond
[(and(not(equal? size -1)) )
;;(hash-ref nodos (number->string cantidad-de-nodos-restantes))
(define id (list-ref ids size))
(define peso (list-ref pesos size))
(define direccion (list-ref bi size) )
(define xInicial (+(cadr(hash-ref nodos (number->string nodo))) 50))
(define yInicial (+ (cadr(cdr(hash-ref nodos (number->string nodo))))50))
(define xFinal (+(cadr(hash-ref nodos (number->string id)))50))
(define yFinal (+ (cadr(cdr(hash-ref nodos (number->string id))))50))
(define xTexto (- xInicial 50))
(define yTexto (- yInicial 50))
(cond
[(zero? direccion)
(dibujar-linea xInicial yInicial xFinal yFinal canvas "VIOLET" 14)
(dibujar-texto xTexto yTexto 1 canvas (number->string peso))
(dibujar-rutas-aux2 nodo ids pesos bi (- size 1) )
]
[else
(dibujar-linea xInicial yInicial xFinal yFinal canvas "PURPLE" 14)
(dibujar-texto xTexto yTexto 1 canvas (number->string peso))
(dibujar-rutas-aux2 nodo ids pesos bi (- size 1) )]
)
]
)
)
;;Esta es la funcion que dibujara los nodos despues haber agregado uno o varios
(define (dibujar-nodos cantidad-de-nodos-restantes)
(cond
[(not (zero? cantidad-de-nodos-restantes ))
(define valores (hash-ref nodos (number->string cantidad-de-nodos-restantes)))
(define nombre-del-nodo(first valores))
(define posicion-x (first(rest valores) ))
(define posicion-y (first(rest(rest valores) )))
(dibujar-nodo posicion-x posicion-y 100 canvas nombre-del-nodo)
(dibujar-nodos ( - cantidad-de-nodos-restantes 1))
]
[else '()])
)
;;Funcion necesarias para obtener x y de un nodo
(define (dame-posiciones nodo-buscar)
(rest(hash-ref nodos (number->string nodo-buscar)))
)
;;Esta funcion es la dibujara la mejor ruta
(define (dibujar-mejor-ruta lista-mejores)
(cond
[(not(null? (rest lista-mejores)))
(define nodo-inicial (first lista-mejores))
(define nodo-final (first(rest lista-mejores)))
(define pos-inicial (dame-posiciones nodo-inicial))
(define pos-final (dame-posiciones nodo-final))
(dibujar-linea (first pos-inicial) (first(rest pos-inicial))(first pos-final)(first(rest pos-final)) canvas "RED" 13)
(dibujar-mejor-ruta (rest lista-mejores))
]
[else '()]))
; ESTOS SON LOS COLORES QUE MANTENDRAN DISPONIUBLES PARA DIBUJAR
;
(define white (make-object color% "white"))
(define black (make-object color% "black"))
(define red (make-object color% "red"))
(define blue (make-object color% "blue"))
; algunos lapices y brochas
(define no-pen (make-object pen% "BLACK" 1 'transparent))
(define no-brush (make-object brush% "BLACK" 'transparent))
(define blue-brush (make-object brush% "BLUE" 'solid))
(define yellow-brush (make-object brush% "YELLOW" 'solid))
(define red-pen (make-object pen% "RED" 2 'solid))
;;ESTE ES EL METODO QUE DIBUJA UN TEXTO EN EL CANVAS
(define (dibujar-texto x y size canvas texto )
(define dc (send canvas get-dc))
(send dc set-scale size size)
(send dc set-text-foreground "blue")
(send dc draw-text texto x y)
)
;;ESTE ES EL METODO QUE REALIZA LOS NODOS CON CIERTO TAMAÑO Y CIERTO TEXTO EN ELLOS
(define (dibujar-nodo x y radio canvas texto)
(define dc (send canvas get-dc))
(send dc set-pen no-pen)
(send dc set-brush yellow-brush)
(send dc draw-ellipse x y radio radio)
(dibujar-texto x (+ y (/ radio 2)) 1 canvas texto)
)
;; ESTE ES EL METODO PARA DIBUJAR LA LINEA DE LAS RUTAS
(define (dibujar-linea x y x2 y2 canvas color grosor)
(define lapiz (instantiate pen% (color grosor 'solid)))
(define dc (send canvas get-dc))
(send dc set-pen lapiz)
(send dc draw-line x y x2 y2)
)
;------------------------------------------------------------------------------------------------------
;;(require "Rutas Panel.rkt")
;Blank bitmap for resize
(define bitmap-blank
(lambda [[w 0] [h #false] #:backing-scale [backing-scale 2.0]]
(define width (max 1 (exact-ceiling w)))
(define height (max 1 (exact-ceiling (or h w))))
(make-bitmap width height #:backing-scale backing-scale)))
;Resize bitmap
(define bitmap-scale
(case-lambda
[(bmp scale)
(if (= scale 1.0) bmp (bitmap-scale bmp scale scale))]
[(bmp scale-x scale-y)
(cond [(and (= scale-x 1.0) (= scale-y 1.0)) bmp]
[else (let ([w (max 1 (exact-ceiling (* (send bmp get-width) scale-x)))]
[h (max 1 (exact-ceiling (* (send bmp get-height) scale-y)))])
(define dc (make-object bitmap-dc% (bitmap-blank w h)))
(send dc set-smoothing 'aligned)
(send dc set-scale scale-x scale-y)
(send dc draw-bitmap bmp 0 0)
(or (send dc get-bitmap) (bitmap-blank)))])]))
";_________________________________________________________________________________________________________________________Main Menu;"
; Main menu Screen
(define menuScreen (new frame% [label "Wazitico"]
[width 800]
[height 600]
[style '(no-resize-border)]))
; Load images
(define arcadiabayButtonIcon (make-object bitmap% "assets/arcadiabay_button.png"))
(define arcadiabay_map (make-object bitmap% "assets/maps/arcadiabay_map.png"))
(define background (make-object bitmap% "/home/jose/Desktop/Racket/Wazecheme/assets/start_button.png"))
(define hyruleButtonIcon (make-object bitmap% "assets/hyrule_button.png"))
(define hyrule_map (make-object bitmap% "assets/maps/hyrule_map.png"))
(define logo_namePic (make-object bitmap% "assets/logo_name.png"))
(define logoPic (make-object bitmap% "assets/logo.png"))
(define namePic (make-object bitmap% "assets/name.png"))
(define selectBackground (make-object bitmap% "assets/background_citySelect.png"))
(define startButtonIcon (make-object bitmap% "/home/jose/Desktop/Racket/Wazecheme/assets/start_button.png"))
";_______________________________________________________________________________________________________________________Menu Screen;"
; Build the Main Menu frame
(define menuPanel (new panel% [parent menuScreen]
[border 0]
[vert-margin 0]
[spacing 0]
[alignment '(center center)]))
; Control menu frame show with boolean value
(define (showMenu bool)
(cond ((equal? bool #t)
(send menuScreen show #t))
(else
(send menuScreen show #f))))
; Changes Frame to MapScreen from ConfigurationScreen
(define (toMapFromMenuScreen)
(send mapScreen show #t)
(showMenu #f))
; Changes from MenuScreen to MapScreen
(new button% [parent menuPanel]
[label (bitmap-scale startButtonIcon 0.6)]
[callback (lambda (button event)
(toMapFromMenuScreen))])
";________________________________________________________________________________________________________________________Map Screen;"
(define listaChoice null)
(define (prueba)
(begin
(set! listaChoice (append (list "Ruta Principal") (list "Ruta Alterna")))
(prueba2 listaChoice)))
(define (prueba2 lista)
(cond ((null? lista)
0)
(else
1)))
; Build the Map frame
(define mapScreen (new frame% [label "Wazitico"]
[width 1000]
[height 900]))
; Map panel
(define mapPanel (new pane% [parent mapScreen]
[border 0]
[spacing 0]
[vert-margin 0]
[alignment '(center center)]))
; Map canvas
(define canvas (new canvas% [parent mapPanel]))
; Changes from ConfigurationScreen to MapScreen
(define (toMenuFromMapScreen)
(send mapScreen show #f)
(showMenu #t))
; Make a button in the Map frame to return to the Menu
(new button% [parent mapScreen]
[label "Regresar al Menu"]
[callback (lambda (button event)
(toMenuFromMapScreen))])
; Changes frame from MapScreen to ConfigurationScreen
(define (toConfigFromMapScreen)
(send mapScreen show #f)
(send configScreen show #t)
)
(define msgPesos (new message% [parent mapScreen]
[label (string-append "Peso de la ruta: " "(pesoRuta-string)")]))
; Changes frame from ConfigurationScreen to MapScreen button
(new button% [parent mapScreen]
[label "Agregar Elementos"]
[callback (lambda (button event)
(toConfigFromMapScreen))])
;;_________________________________________________________________________________________________________________
(define (better-route )
(define inicio (send search-box get-value ))
(define fin (send search-box2 get-value ))
(set! inicio (lugar-numero inicio 1))
(set! fin (lugar-numero fin 1))
;;(define rutas dis '((1 3 2) (2 1 3)))
(dibujar-mejor-ruta (cadr(dijkstra inicio fin))))
";______________________________________________________________________________________________________________Configuration Screen;"
; Config Screen
(define configScreen (new frame% [label "Wazitico"]
[width 600]
[height 625]))
; Changes Frame to MapScreen from ConfigurationScreen
(define (toMapFromConfigScreen)
(dibujar-nodos (- cantidad-nodos 1))
(dibujar-rutas(- cantidad-nodos 1))
(send mapScreen show #t)
(send configScreen show #f))
(define msg (new message% [parent configScreen]
[label "Configuración de Ruta y Nodos"]))
(define search-box (new text-field% [parent configScreen]
[label " Lugar de Inicio: "]))
(define search-box2 (new text-field% [parent configScreen]
[label " Lugar de Destino: "]))
; Returns from ConfigScreen to MapScreen
(new button% [parent configScreen]
[label "Crear ruta"]
[callback (lambda (button event)
(better-route))])
(define espacio (new message% [parent configScreen]
[label "_____________________________________________________________________________________"]))
(define search-box3 (new text-field% [parent configScreen]
[label " Nombre del lugar por crear: "]))
(define espacio2 (new message% [parent configScreen]
[label " "]))
(define txtConfig (new message% [parent configScreen]
[label " Configuración del nodo por crear:"]))
;Node 1 ready to connect
(define search-box4 (new text-field% [parent configScreen]
[label " 1. Nodo con el que estará conectado: "]))
(define search-box4.1 (new text-field% [parent configScreen]
[label " Su peso: "]))
(define check-box (new check-box% [parent configScreen]
[label "<- Si este nodo es bidireccional seleccione la casilla "]))
(define espacio3 (new message% [parent configScreen]
[label " "]))
;Node 2 ready to connect
(define search-box5 (new text-field% [parent configScreen]
[label " 2. Nodo con el que estará conectado: "]))
(define search-box5.1 (new text-field% [parent configScreen]
[label " Su peso: "]))
(define check-box2 (new check-box% [parent configScreen]
[label "<- Si este nodo es bidireccional seleccione la casilla "]))
(define espacio4 (new message% [parent configScreen]
[label " "]))
;Node 3 ready to connect
(define search-box6 (new text-field% [parent configScreen]
[label " 3. Nodo con el que estará conectado: "]))
(define search-box6.1 (new text-field% [parent configScreen]
[label " Su peso: "]))
(define check-box3 (new check-box% [parent configScreen]
[label "<- Si este nodo es bidireccional seleccione la casilla "]))
(define (set-texts)
(send search-box4 set-value "")
(send search-box4.1 set-value "")
(send search-box5 set-value "")
(send search-box5.1 set-value "")
(send search-box6 set-value "")
(send search-box6.1 set-value ""))
; Returns from ConfigScreen to MapScreen
(new button% [parent configScreen]
[label "Crear Lugar"]
[callback (lambda (button event)
(validacionNodos))])
(define espacio6 (new message% [parent configScreen]
[label "_____________________________________________________________________________________"]))
(define search-box7 (new text-field% [parent configScreen]
[label "Número de ruta que quiere seguir: "]))
(define msgRutas (new message% [parent configScreen]
[label (string-append "Número de rutas: " "(numeroRutas-string)")]))
; Returns from ConfigScreen to MapScreen
(new button% [parent configScreen]
[label "Regresar al Mapa"]
[callback (lambda (button event)
(toMapFromConfigScreen))])
";___________________________________________________________________________________________________Conexion de Logica con interfaz;"
; Validacion para que haya informacion en los text-field y no crear nodos sin informacion
(define (validacionNodos)
(define valor (send search-box3 get-value) )
(cond
((equal? (send search-box4 get-value) "" )
(agregar-nodo valor 1 2 3))
((equal? (send search-box5 get-value) "")
(crearNodo1conexion))
((equal? (send search-box6 get-value) "")
(crearNodo2conexiones))
(else
(crearNodo3conexiones))))
; Convertir el valor booleano del check-box en 1 si esta seleccionado o 0 si no lo esta
(define (boolCheck-box1)
(cond ((equal? (send check-box get-value) #t)
1)
(else
0)))
; Convertir el valor booleano del check-box2 en 1 si esta seleccionado o 0 si no lo esta
(define (boolCheck-box2)
(cond ((equal? (send check-box2 get-value) #t)
1)
(else
0)))
; Convertir el valor booleano del check-box3 en 1 si esta seleccionado o 0 si no lo esta
(define (boolCheck-box3)
(cond ((equal? (send check-box3 get-value) #t)
1)
(else
0)))
; Crear conexion entre el nodo nuevo y uno existente
(define (crearNodo1conexion)
(cond ((equal? (send search-box4.1 get-value) "")
"Nada que hacer")
(else
(define pos (list(lugar-numero (send search-box4 get-value) 1)) )
(define pesos (list (string->number(send search-box4.1 get-value))))
(define binario (list (boolCheck-box1)))
(agregar-nodo (send search-box3 get-value); String
(list(lugar-numero (send search-box4 get-value) 1)); list al que me quiero conectar
(list (string->number(send search-box4.1 get-value))); list peso
(list (boolCheck-box1)))))); list direccion
; Crear conexion entre el nodo nuevo y dos existentes
(define (crearNodo2conexiones)
(cond ((equal? (send search-box5.1 get-value) "")
"Nada que hacer")
(else
(agregar-nodo (send search-box3 get-value); int el que estoy creando
(list (lugar-numero(send search-box4 get-value )1)
(lugar-numero(send search-box5 get-value )1)); list al que me quiero conectar
(list ( string->number(send search-box4.1 get-value))
( string->number(send search-box5.1 get-value))); list peso
(list (boolCheck-box1) (boolCheck-box2)))))); list direccion
; Crear conexion entre el nodo nuevo y tres existentes
(define (crearNodo3conexiones)
(cond ((equal? (send search-box6.1 get-value) "")
"Nada que hacer")
(else
(agregar-nodo (send search-box3 get-value); int el que estoy creando
(list (lugar-numero(send search-box4 get-value )1)
(lugar-numero(send search-box5 get-value )1)
(lugar-numero(send search-box6 get-value )1)); list al que me quiero conectar
(list ( string->number(send search-box4.1 get-value))
( string->number(send search-box5.1 get-value))
( string->number(send search-box6.1 get-value)));; list peso
(list (boolCheck-box1) (boolCheck-box2) (boolCheck-box3))))
)); list direccion
;______________________________________________________________________________________________________________________Run;
(showMenu #t)