Versione finale relazione
[toni-reis.git] / src / simulator-monitor-gui.adb
bloba1492099bc0f7f815d6f796085876121ed188031
1 with Ada.Text_IO; use Ada.Text_IO;
2 with Ada.Float_Text_IO; use Ada.Float_Text_IO;
3 with Ada.Calendar.Formatting;
5 with Glib; use Glib;
6 with Gtk.Main; use Gtk.Main;
7 with Gtk; use Gtk;
8 with Gdk.Event; use Gdk.Event;
9 with Gdk.Types; use Gdk.Types;
10 with Gtk.Enums; use Gtk.Enums;
11 with Gdk.Threads; use Gdk.Threads;
12 with Gtkada.Dialogs; use Gtkada.Dialogs;
14 with Simulator.Statistics; use Simulator.Statistics;
16 package body Simulator.Monitor.Gui is
17 package DurationIO is new Ada.Text_IO.Fixed_Io(Duration);
19 function Delete_Event (Widget : access Gtk_Widget_Record'Class; Event : Gdk_Event) return Boolean
21 pragma Unreferenced (Event);
22 pragma Unreferenced (Widget);
23 begin
24 Simulator.Monitor.Quit;
25 Gtk.Main.Main_Quit;
26 Put_Line ("GUI: delete event occurred");
27 return False;
28 end Delete_Event;
30 procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
31 pragma Unreferenced (Widget);
32 begin
33 Gtk.Main.Gtk_Exit(0);
34 end Destroy;
37 procedure Gtk_New (Monitor : out Monitor_Access) is
38 begin
39 Monitor := new Monitor_Record;
40 Ref := Monitor;
41 Simulator.Monitor.Gui.Initialize (Monitor);
42 end Gtk_New;
44 procedure Initialize (Monitor : access Monitor_Record'Class) is
45 pragma Suppress (All_Checks);
46 Pixmaps_Dir : constant String := "pixmaps/";
47 Num : Gint;
48 begin
49 Gtk.Window.Initialize (Monitor, Window_Toplevel);
50 Set_Border_Width (Monitor, 2);
51 Set_Title (Monitor, "Monitor");
52 Set_Position (Monitor, Win_Pos_None);
53 Set_Modal (Monitor, False);
54 Set_Resizable (Monitor, True);
56 -- collego i segnali per la chiusura dell'applicazione
57 Return_Handlers.Connect(Monitor, "delete_event", Return_Handlers.To_Marshaller (Delete_Event'Access));
58 Handlers.Connect(Monitor, "destroy", Handlers.To_Marshaller (Destroy'Access));
60 Gtk_New_Vbox (Monitor.Vbox2, False, 5);
61 Gtk_New_Hbox (Monitor.Hbox1, False, 5);
63 Gtk_New (Monitor.Frame1);
64 Set_Label_Align (Monitor.Frame1, 0.0, 0.5);
65 Set_Shadow_Type (Monitor.Frame1, Shadow_Etched_In);
67 Gtk_New
68 (Monitor.Alignment1, 0.5, 0.5, 1.0, 1.0);
69 Set_Border_Width (Monitor.Alignment1, 5);
71 Gtk_New (Monitor.Scrolledwindow1);
72 Set_Policy (Monitor.Scrolledwindow1, Policy_Automatic, Policy_Automatic);
73 Set_Shadow_Type (Monitor.Scrolledwindow1, Shadow_In);
74 Set_Placement (Monitor.Scrolledwindow1, Corner_Top_Left);
76 -- Creo il modello dati per la classifica
77 Gtk_New (Monitor.Model1,
78 (0 => GType_Int, -- Pos
79 1 => GType_Int, -- Id
80 2 => GType_String, -- Colore
81 3 => GType_String, -- Name
82 4 => GType_Int, -- Lap
83 5 => GType_Int, -- Intermediate
84 6 => GType_String, -- Status
85 7 => GType_Int, -- # of PitStop
86 8 => GType_String, -- Best Lap
87 9 => GType_String -- Last Lap
88 ));
90 Gtk_New_With_Model (Monitor.Model1_Sort, Monitor.Model1);
92 Gtk_New (Monitor.Treeview1, Monitor.Model1_Sort);
93 Set_Sort_Column_Id (+(Monitor.Model1_Sort), 0 , Sort_Ascending);
94 Gtk_New(Monitor.Col);
95 Gtk_New(Monitor.Text_R);
96 Set_Title (Monitor.Col, "Pos");
97 Num := Append_Column (Monitor.Treeview1, Monitor.Col);
98 Pack_Start (Monitor.Col, Monitor.Text_R, True);
99 Add_Attribute (Monitor.Col, Monitor.Text_R, "text", 0);
101 Gtk_New(Monitor.Col);
102 Gtk_New(Monitor.Text_R);
103 Set_Title (Monitor.Col, "Id");
104 Num := Append_Column (Monitor.Treeview1, Monitor.Col);
105 Pack_Start (Monitor.Col, Monitor.Text_R, True);
106 Add_Attribute (Monitor.Col, Monitor.Text_R, "text", 1);
107 Add_Attribute (Monitor.Col, Monitor.Text_R, "background", 2);
109 Gtk_New(Monitor.Col);
110 Gtk_New(Monitor.Text_R);
111 Set_Title (Monitor.Col, "Name");
112 Num := Append_Column (Monitor.Treeview1, Monitor.Col);
113 Pack_Start (Monitor.Col, Monitor.Text_R, True);
114 Add_Attribute (Monitor.Col, Monitor.Text_R, "text", 3);
116 Gtk_New(Monitor.Col);
117 Gtk_New(Monitor.Text_R);
118 Set_Title (Monitor.Col, "Lap");
119 Num := Append_Column (Monitor.Treeview1, Monitor.Col);
120 Pack_Start (Monitor.Col, Monitor.Text_R, True);
121 Add_Attribute (Monitor.Col, Monitor.Text_R, "text", 4);
123 Gtk_New(Monitor.Col);
124 Gtk_New(Monitor.Text_R);
125 Set_Title (Monitor.Col, "Int");
126 Num := Append_Column (Monitor.Treeview1, Monitor.Col);
127 Pack_Start (Monitor.Col, Monitor.Text_R, True);
128 Add_Attribute (Monitor.Col, Monitor.Text_R, "text", 5);
130 Gtk_New(Monitor.Col);
131 Gtk_New(Monitor.Text_R);
132 Set_Title (Monitor.Col, "Status");
133 Num := Append_Column (Monitor.Treeview1, Monitor.Col);
134 Pack_Start (Monitor.Col, Monitor.Text_R, True);
135 Add_Attribute (Monitor.Col, Monitor.Text_R, "text", 6);
137 Gtk_New(Monitor.Col);
138 Gtk_New(Monitor.Text_R);
139 Set_Title (Monitor.Col, "Stops");
140 Num := Append_Column (Monitor.Treeview1, Monitor.Col);
141 Pack_Start (Monitor.Col, Monitor.Text_R, True);
142 Add_Attribute (Monitor.Col, Monitor.Text_R, "text", 7);
144 Gtk_New(Monitor.Col);
145 Gtk_New(Monitor.Text_R);
146 Set_Title (Monitor.Col, "Best Lap");
147 Num := Append_Column (Monitor.Treeview1, Monitor.Col);
148 Pack_Start (Monitor.Col, Monitor.Text_R, True);
149 Add_Attribute (Monitor.Col, Monitor.Text_R, "text", 8);
151 Gtk_New(Monitor.Col);
152 Gtk_New(Monitor.Text_R);
153 Set_Title (Monitor.Col, "Last Lap");
154 Num := Append_Column (Monitor.Treeview1, Monitor.Col);
155 Pack_Start (Monitor.Col, Monitor.Text_R, True);
156 Add_Attribute (Monitor.Col, Monitor.Text_R, "text", 9);
158 Set_Headers_Visible (Monitor.Treeview1, True);
159 Set_Rules_Hint (Monitor.Treeview1, True);
160 Set_Reorderable (Monitor.Treeview1, False);
161 Set_Enable_Search (Monitor.Treeview1, False);
163 Add (Monitor.Scrolledwindow1, Monitor.Treeview1);
164 Add (Monitor.Alignment1, Monitor.Scrolledwindow1);
165 Add (Monitor.Frame1, Monitor.Alignment1);
166 Gtk_New (Monitor.Label1, "Ranking");
167 Set_Alignment (Monitor.Label1, 0.5, 0.5);
168 Set_Padding (Monitor.Label1, 0, 0);
169 Set_Justify (Monitor.Label1, Justify_Left);
170 Set_Line_Wrap (Monitor.Label1, False);
171 Set_Selectable (Monitor.Label1, False);
172 Set_Use_Markup (Monitor.Label1, True);
173 Set_Use_Underline (Monitor.Label1, False);
174 Set_Label_Widget (Monitor.Frame1,Monitor.Label1);
176 Pack_Start
177 (Monitor.Hbox1,
178 Monitor.Frame1,
179 Expand => True,
180 Fill => True,
181 Padding => 5);
182 Gtk_New (Monitor.Frame2);
183 Set_Label_Align (Monitor.Frame2, 0.0, 0.5);
184 Set_Shadow_Type (Monitor.Frame2, Shadow_Etched_In);
186 Gtk_New
187 (Monitor.Alignment2, 0.5, 0.5, 1.0, 1.0);
188 Set_Border_Width (Monitor.Alignment2, 5);
190 Gtk_New (Monitor.Scrolledwindow2);
191 Set_Policy (Monitor.Scrolledwindow2, Policy_Automatic, Policy_Automatic);
192 Set_Shadow_Type (Monitor.Scrolledwindow2, Shadow_In);
193 Set_Placement (Monitor.Scrolledwindow2, Corner_Top_Left);
195 -- Creo il modello dati per gli intertempi
196 Gtk_New (Monitor.Model2,
197 (0 => GType_Int, -- Pos
198 1 => GType_Int, -- Id
199 2 => GType_String, -- Distacco
200 3 => GType_String -- Velocita'
203 Gtk_New (Monitor.Treeview2, Monitor.Model2);
204 Set_Size_Request (Monitor.Treeview2, 250, 250);
205 Gtk_New(Monitor.Col);
206 Gtk_New(Monitor.Text_R);
207 Set_Title (Monitor.Col, "Pos");
208 Num := Append_Column (Monitor.Treeview2, Monitor.Col);
209 Pack_Start (Monitor.Col, Monitor.Text_R, True);
210 Add_Attribute (Monitor.Col, Monitor.Text_R, "text", 0);
212 Gtk_New(Monitor.Col);
213 Gtk_New(Monitor.Text_R);
214 Set_Title (Monitor.Col, "Id");
215 Num := Append_Column (Monitor.Treeview2, Monitor.Col);
216 Pack_Start (Monitor.Col, Monitor.Text_R, True);
217 Add_Attribute (Monitor.Col, Monitor.Text_R, "text", 1);
219 Gtk_New(Monitor.Col);
220 Gtk_New(Monitor.Text_R);
221 Set_Title (Monitor.Col, "Time");
222 Num := Append_Column (Monitor.Treeview2, Monitor.Col);
223 Pack_Start (Monitor.Col, Monitor.Text_R, True);
224 Add_Attribute (Monitor.Col, Monitor.Text_R, "text", 2);
226 Gtk_New(Monitor.Col);
227 Gtk_New(Monitor.Text_R);
228 Set_Title (Monitor.Col, "Vel");
229 Num := Append_Column (Monitor.Treeview2, Monitor.Col);
230 Pack_Start (Monitor.Col, Monitor.Text_R, True);
231 Add_Attribute (Monitor.Col, Monitor.Text_R, "text", 3);
233 Gtk_New_Vbox (Monitor.Vbox1, False, 0);
234 Gtk_New_Hbox (Monitor.Hbox2, False, 0);
236 Gtk_New (Monitor.Int_Info, "Lap: -- Intermediate: --");
237 Set_Alignment (Monitor.Int_Info, 0.0, 0.5);
238 Set_Padding (Monitor.Int_Info, 0, 0);
239 Set_Justify (Monitor.Int_Info, Justify_Left);
240 Set_Line_Wrap (Monitor.Int_Info, False);
241 Set_Selectable (Monitor.Int_Info, False);
242 Set_Use_Markup (Monitor.Int_Info, False);
243 Set_Use_Underline (Monitor.Int_Info, False);
245 Pack_Start
246 (Monitor.Hbox2,
247 Monitor.Int_Info,
248 Expand => True,
249 Fill => True,
250 Padding => 0);
252 -- Bottone Lock Statistics
253 Gtk_New (Monitor.Lock, "Lock");
254 -- callback del tasto Lock
255 Handlers.Connect(Monitor.Lock, "clicked", Handlers.To_Marshaller (ToggleLock'Access));
257 Pack_Start
258 (Monitor.Hbox2,
259 Monitor.Lock,
260 Expand => False,
261 Fill => False,
262 Padding => 0);
264 Pack_Start
265 (Monitor.Vbox1,
266 Monitor.Hbox2,
267 Expand => False,
268 Fill => False,
269 Padding => 0);
271 Set_Headers_Visible (Monitor.Treeview2, True);
272 Set_Rules_Hint (Monitor.Treeview2, True);
273 Set_Reorderable (Monitor.Treeview2, True);
274 Set_Enable_Search (Monitor.Treeview2, False);
276 Add (Monitor.Scrolledwindow2, Monitor.Treeview2);
277 Add (Monitor.Alignment2, Monitor.VBox1);
279 Pack_Start
280 (Monitor.Vbox1,
281 Monitor.Scrolledwindow2,
282 Expand => True,
283 Fill => True,
284 Padding => 0);
286 Add (Monitor.Frame2, Monitor.Alignment2);
287 Gtk_New (Monitor.Label2, "Statistics");
288 Set_Alignment (Monitor.Label2, 0.5, 0.5);
289 Set_Padding (Monitor.Label2, 0, 0);
290 Set_Justify (Monitor.Label2, Justify_Left);
291 Set_Line_Wrap (Monitor.Label2, False);
292 Set_Selectable (Monitor.Label2, False);
293 Set_Use_Markup (Monitor.Label2, True);
294 Set_Use_Underline (Monitor.Label2, False);
295 Set_Label_Widget (Monitor.Frame2,Monitor.Label2);
297 Pack_Start
298 (Monitor.Hbox1,
299 Monitor.Frame2,
300 Expand => False,
301 Fill => True,
302 Padding => 5);
304 Gtk_New (Monitor.Frame3);
305 Set_Label_Align (Monitor.Frame3, 0.0, 0.5);
306 Set_Shadow_Type (Monitor.Frame3, Shadow_Etched_In);
308 Gtk_New
309 (Monitor.Alignment3, 0.5, 0.5, 1.0, 1.0);
310 Set_Border_Width (Monitor.Alignment3, 5);
312 Add (Monitor.Frame3, Monitor.Alignment3);
313 Gtk_New (Monitor.Label3, "Record");
314 Set_Alignment (Monitor.Label3, 0.5, 0.5);
315 Set_Padding (Monitor.Label3, 0, 0);
316 Set_Justify (Monitor.Label3, Justify_Left);
317 Set_Line_Wrap (Monitor.Label3, False);
318 Set_Selectable (Monitor.Label3, False);
319 Set_Use_Markup (Monitor.Label3, True);
320 Set_Use_Underline (Monitor.Label3, False);
321 Set_Label_Widget (Monitor.Frame3,Monitor.Label3);
323 Gtk_New_Hbox (Monitor.Hbox3, False, 0);
325 Gtk_New (Monitor.BestLap_Info, "Best Lap: -- : -- : --- Car: -- on lap --");
326 Set_Alignment (Monitor.BestLap_Info, 0.0, 0.5);
328 Gtk_New (Monitor.MaxSpeed_Info, "Max Speed: ---,-- km/h Car: --");
329 Set_Alignment (Monitor.MaxSpeed_Info, 0.0, 0.5);
331 Pack_Start
332 (Monitor.Hbox3,
333 Monitor.BestLap_Info,
334 Expand => True,
335 Fill => True,
336 Padding => 5);
338 Pack_Start
339 (Monitor.Hbox3,
340 Monitor.MaxSpeed_Info,
341 Expand => True,
342 Fill => True,
343 Padding => 5);
345 Add (Monitor.Alignment3, Monitor.HBox3);
347 Pack_Start
348 (Monitor.Vbox2,
349 Monitor.Hbox1,
350 Expand => True,
351 Fill => True,
352 Padding => 5);
354 Pack_Start
355 (Monitor.Vbox2,
356 Monitor.Frame3,
357 Expand => False,
358 Fill => False,
359 Padding => 5);
361 Add (Monitor, Monitor.Vbox2);
362 Set_Size_Request (Monitor, 800, 350);
363 end Initialize;
365 procedure Update_Model (Pos: Positive;
366 CarId: CarId_T;
367 Name : String;
368 Lap: Natural;
369 Intermediate: Natural;
370 WakeupTime: Duration;
371 Vel: Float;
372 TimeElapsed: Duration) is
373 Iter : Gtk_Tree_Iter;
374 Iter1: Gtk_Tree_Iter;
375 OldPos : Positive;
376 StrTime : String := "tttttttttt";
377 StrVel : String := "vvvvvvvv";
378 m : Integer;
379 s : Integer;
380 c : Integer;
381 begin
382 Gdk.Threads.Enter;
383 -- Put_Line("Update gui-monitor's data. Id: " & CarId'Img & ", Pos: " & Pos'Img & ".");
384 -- cerco riga auto
385 Iter := Get_Iter_First(Ref.Model1);
386 while (Iter /= Null_Iter and then Get_Int(Ref.Model1, Iter, 1) /= GInt(CarId)) loop
387 Next(Ref.Model1, Iter);
388 end loop;
390 -- aggiorno dati
391 if (Iter /= Null_Iter) then
392 -- aggiorno i valori
393 OldPos := Positive(Get_Int(Ref.Model1, Iter, 0));
394 Set (Ref.Model1, Iter, 0, GInt(Pos));
395 Set (Ref.Model1, Iter, 1, GInt(CarId));
396 -- alla partneza non segno zero ma un piĆ¹ chiaro 0 0
397 if (Lap /= 0) then
398 Set (Ref.Model1, Iter, 4, GInt(Lap));
399 Set (Ref.Model1, Iter, 5, GInt(Intermediate));
400 else
401 Set (Ref.Model1, Iter, 4, 0);
402 Set (Ref.Model1, Iter, 5, 0);
403 end if;
405 Set (Ref.Model1, Iter, 6, "running");
407 if( Pos - OldPos = 0) then
408 ChangePosition(CarId) := 0;
409 else
410 ChangePosition(CarId) :=ChangePosition(CarId)+ Pos - OldPos;
411 end if;
413 Put_Line("Posizione auto "&CarId'Img&" cambiata di: "&ChangePosition(CarId)'Img);
414 -- coloro di verde la posizione
415 if (ChangePosition(CarId) < 0) then
416 Set (Ref.Model1, Iter, 2, "light green");
417 else
418 Set (Ref.Model1, Iter, 2, "white");
419 end if;
421 -- Aggiorno le posizioni delle macchine coinvolte nel sorpasso
422 Iter := Get_Iter_First(Ref.Model1);
424 while( Iter /= Null_Iter) loop
425 if (Get_Int(Ref.Model1, Iter, 0) >= GInt(Pos) and then Get_Int(Ref.Model1, Iter, 0) < GInt(OldPos) and then Get_Int(Ref.Model1, Iter, 1) /= GInt(CarId)) then
426 Set (Ref.Model1, Iter, 0, GInt(Get_Int(Ref.Model1, Iter, 0)+1));
427 -- aggiorno cambio posizioni e coloro
428 ChangePosition(CarId_T(Get_Int(Ref.Model1, Iter, 1))) := ChangePosition(CarId_T(Get_Int(Ref.Model1, Iter, 1))) +1;
429 if ( ChangePosition(CarId_T(Get_Int(Ref.Model1, Iter, 1)))< 0) then
430 -- coloro di verde la posizione
431 Set (Ref.Model1, Iter, 2, "light green");
432 elsif ( ChangePosition(CarId_T(Get_Int(Ref.Model1, Iter, 1)))= 0) then
433 Set (Ref.Model1, Iter, 2, "white");
434 else
435 Set (Ref.Model1, Iter, 2, "red");
436 end if;
437 else
438 null;
439 end if;
440 Next(Ref.Model1, Iter);
441 end loop;
442 else
443 -- appendo in fondo alla lista
444 Put_Line("Aggiungo a monitor Id: " & CarId'Img & ", Pos: " & Pos'Img & ".");
445 Append(Ref.Model1, Iter);
446 Set (Ref.Model1, Iter, 0, GInt(Pos));
447 Set (Ref.Model1, Iter, 1, GInt(CarId));
448 Set (Ref.Model1, Iter, 2, "white");
449 Set (Ref.Model1, Iter, 3, Name);
450 -- alla partneza non segno lap zero int 1 ma un piĆ¹ chiaro 0 0
451 if (Lap /= 0) then
452 Set (Ref.Model1, Iter, 4, GInt(Lap));
453 Set (Ref.Model1, Iter, 5, GInt(Intermediate));
454 else
455 Set (Ref.Model1, Iter, 4, 0);
456 Set (Ref.Model1, Iter, 5, 0);
457 end if;
458 Set (Ref.Model1, Iter, 6, "running");
459 Set (Ref.Model1, Iter, 7, 0);
460 Set (Ref.Model1, Iter, 8, "--");
461 Set (Ref.Model1, Iter, 9, "--");
462 end if;
464 -- aggiorno i valori massimi
465 if ((Lap > Ref.LastLap or ((Lap = Ref.LastLap) and (Intermediate > Ref.LastInt))) and Ref.Observing = False) then
466 Ref.LastLap := Lap;
467 Ref.LastInt := Intermediate;
468 Ref.LastTime := WakeupTime;
469 Set_Text(Ref.Int_Info, "Lap: "&Ref.LastLap'Img&" Intermediate: "&Ref.LastInt'Img);
470 -- e pulisco le statistiche
471 Clear(Ref.Model2);
472 end if;
474 -- se giro e settore giusto aggiungo a statistics
475 if ((Lap = Ref.LastLap) and (Intermediate = Ref.LastInt)) then
476 -- Put_Line("Aggiungo a monitor di destra Id: " & CarId'Img & ", Pos: " & Pos'Img & ".");
477 Insert(Ref.Model2, Iter, GInt(Pos)-1);
478 Set (Ref.Model2, Iter, 0, GInt(Pos));
479 Set (Ref.Model2, Iter, 1, GInt(CarId));
480 if (Pos = 1) then
481 -- Prima auto, scrivo il tempo di gara trascorso
482 m := Integer(Float'Truncation(Float(TimeElapsed)/60.0));
483 s := Integer(Float'Truncation(Float(TimeElapsed))) - m*60;
484 c := Integer(Float'Truncation(Float(TimeElapsed * 1000))) - m*60000 -s *1000;
485 Set (Ref.Model2, Iter, 2, m'Img & ":" & s'Img & ":" & c'Img);
486 else
487 DurationIO.Put(StrTime, (WakeupTime - Ref.LastTime), Aft => 3);
488 Set (Ref.Model2, Iter, 2, "+ "&StrTime&" s");
489 end if;
490 Put(StrVel, Vel*3.6, Aft => 2, Exp => 0);
491 Set (Ref.Model2, Iter, 3, StrVel&" km/h");
492 Next(Ref.Model2, Iter);
493 while (Iter /= Null_Iter) loop
494 Set (Ref.Model2, Iter, 0, Get_Int(Ref.Model2, Iter, 0)+1);
495 Put_Line("DEBUG: Calcolo le posizioni scorrette");
496 Iter1 := Get_Iter_First(Ref.Model1);
497 while (Iter1 /= Null_Iter) loop
498 if ( Get_Int(Ref.Model1, Iter1, 1) = Get_Int(Ref.Model2, Iter, 1)) then
499 --Put_Line("DEBUG: Guadagno posizioni auto "&Get_Int(Ref.Model1, Iter1, 1)'Img&": "&ChangePosition(CarId_T(Get_Int(Ref.Model1, Iter1, 1)))'Img);
500 --colora
501 if ( ChangePosition(CarId_T(Get_Int(Ref.Model1, Iter1, 1)))< 0) then
502 -- coloro di verde la posizione
503 Set (Ref.Model1, Iter1, 2, "light green");
504 elsif ( ChangePosition(CarId_T(Get_Int(Ref.Model1, Iter1, 1)))= 0) then
505 Set (Ref.Model1, Iter1, 2, "white");
506 else
507 Set (Ref.Model1, Iter1, 2, "red");
508 end if;
509 end if;
510 Next(Ref.Model1, Iter1);
511 end loop;
512 Next(Ref.Model2, Iter);
513 end loop;
514 end if;
515 Gdk.Threads.Leave;
516 end Update_Model;
518 procedure UpdateLapTime ( Id: CarId_T; LastLap : Duration; BestLap: Duration) is
519 Iter : Gtk_Tree_Iter;
520 m : Integer;
521 s : Integer;
522 c : Integer;
524 begin
525 Gdk.Threads.Enter;
526 Iter := Get_Iter_First(Ref.Model1);
527 while (Iter /= Null_Iter and then Get_Int(Ref.Model1, Iter, 1) /= GInt(Id)) loop
528 Next(Ref.Model1, Iter);
529 end loop;
531 -- aggiorno dati
532 if (Iter /= Null_Iter) then
533 -- aggiorno i valori
534 if (BestLap /= Duration'Last) then
535 m := Integer(Float'Truncation(Float(BestLap)/60.0));
536 s := Integer(Float'Truncation(Float(BestLap))) - m*60;
537 c := Integer(Float'Truncation(Float(BestLap * 1000))) - m*60000 -s *1000;
538 Set (Ref.Model1, Iter, 8, m'Img & ":" & s'Img & ":" & c'Img);
539 else
540 Set (Ref.Model1, Iter, 8, "--");
541 end if;
542 if (LastLap /= Duration'Last) then
543 m := Integer(Float'Truncation(Float(LastLap)/60.0));
544 s := Integer(Float'Truncation(Float(LastLap))) - m*60;
545 c := Integer(Float'Truncation(Float(LastLap * 1000))) - m*60000 -s *1000;
546 Set (Ref.Model1, Iter, 9, m'Img & ":" & s'Img & ":" & c'Img);
547 else
548 Set (Ref.Model1, Iter, 9, "--");
549 end if;
550 end if;
551 Gdk.Threads.Leave;
552 end UpdateLapTime;
554 procedure UpdateCarStatus ( Id: CarId_T; Status : CarStatus_T) is
555 Iter : Gtk_Tree_Iter;
556 begin
557 Gdk.Threads.Enter;
558 -- search for the correct model row
559 Iter := Get_Iter_First(Ref.Model1);
560 while (Iter /= Null_Iter and then Get_Int(Ref.Model1, Iter, 1) /= GInt(Id)) loop
561 Next(Ref.Model1, Iter);
562 end loop;
564 -- aggiorno dati
565 if (Iter /= Null_Iter) then
566 -- aggiorno lo stato
567 case Status is
568 when Retired =>
569 Set (Ref.Model1, Iter, 6, "retired");
570 when Box =>
571 Set (Ref.Model1, Iter, 6, "BOX");
572 -- aggiungo 1 al numero di soste
573 Set (Ref.Model1, Iter, 7, Get_Int(Ref.Model1, Iter, 7)+1);
574 when Finished =>
575 Set (Ref.Model1, Iter, 6, "finished");
576 when Running =>
577 Set (Ref.Model1, Iter, 6, "running");
578 when others =>
579 Set (Ref.Model1, Iter, 6, "uknown");
580 end case;
581 end if;
582 Gdk.Threads.Leave;
583 end UpdateCarStatus;
585 procedure Update_BestLap(Id : CarId_T; Lap : Positive; Time : Duration) is
586 m : Integer;
587 s : Integer;
588 c : Integer;
589 begin
590 -- Put_Line("Update monitor's best lap.");
591 Ref.BestLap := Time;
592 Ref.BestLap_Id := Id;
593 Ref.BestLap_Lap := Lap;
594 m := Integer(Float'Truncation(Float(Time)/60.0));
595 s := Integer(Float'Truncation(Float(Time))) - m*60;
596 c := Integer(Float'Truncation(Float(Time * 1000))) - m*60000 -s *1000;
597 Set_Text(Ref.BestLap_Info, "Best Lap: "&m'Img&":"&s'Img&"."&c'Img &" Car: "&Id'Img&" on lap "&Lap'Img);
598 end Update_BestLap;
600 procedure Update_MaxSpeed(Id : CarId_T; Val : Float) is
601 StrSpeed : String := "vvvvvv";
602 begin
603 -- Put_Line("Update monitor's max speed.");
604 Ref.MaxSpeed := Val;
605 Ref.MaxSpeed_Id := Id;
606 Put(StrSpeed, Val*3.6, Aft => 2, Exp => 0);
607 Set_Text(Ref.MaxSpeed_Info, "Max Speed: "&StrSpeed&" km/h Car: "&Id'Img);
608 end Update_MaxSpeed;
610 procedure ToggleLock (Widget : access Gtk_Widget_Record'Class) is
611 begin
612 Ref.Observing := not Ref.Observing;
613 if (Ref.Observing) then
614 Set_Label(Ref.Lock, "Unlock");
615 else
616 Set_Label(Ref.Lock, "Lock");
617 end if;
618 end ToggleLock;
620 procedure EndRace is
621 ans : Message_Dialog_Buttons;
622 begin
623 Gdk.Threads.Enter;
624 ans := Message_Dialog("Race Finished !", Buttons => Button_OK);
625 Gdk.Threads.Leave;
626 end EndRace;
628 end Simulator.Monitor.Gui;