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
;
6 with Gtk
.Main
; use Gtk
.Main
;
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
);
24 Simulator
.Monitor
.Quit
;
26 Put_Line
("GUI: delete event occurred");
30 procedure Destroy
(Widget
: access Gtk_Widget_Record
'Class) is
31 pragma Unreferenced
(Widget
);
37 procedure Gtk_New
(Monitor
: out Monitor_Access
) is
39 Monitor
:= new Monitor_Record
;
41 Simulator
.Monitor
.Gui
.Initialize
(Monitor
);
44 procedure Initialize
(Monitor
: access Monitor_Record
'Class) is
45 pragma Suppress
(All_Checks
);
46 Pixmaps_Dir
: constant String := "pixmaps/";
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
);
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
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
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
);
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
);
182 Gtk_New
(Monitor
.Frame2
);
183 Set_Label_Align
(Monitor
.Frame2
, 0.0, 0.5);
184 Set_Shadow_Type
(Monitor
.Frame2
, Shadow_Etched_In
);
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);
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));
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
);
281 Monitor
.Scrolledwindow2
,
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
);
304 Gtk_New
(Monitor
.Frame3
);
305 Set_Label_Align
(Monitor
.Frame3
, 0.0, 0.5);
306 Set_Shadow_Type
(Monitor
.Frame3
, Shadow_Etched_In
);
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);
333 Monitor
.BestLap_Info
,
340 Monitor
.MaxSpeed_Info
,
345 Add
(Monitor
.Alignment3
, Monitor
.HBox3
);
361 Add
(Monitor
, Monitor
.Vbox2
);
362 Set_Size_Request
(Monitor
, 800, 350);
365 procedure Update_Model
(Pos
: Positive;
369 Intermediate
: Natural;
370 WakeupTime
: Duration;
372 TimeElapsed
: Duration) is
373 Iter
: Gtk_Tree_Iter
;
374 Iter1
: Gtk_Tree_Iter
;
376 StrTime
: String := "tttttttttt";
377 StrVel
: String := "vvvvvvvv";
383 -- Put_Line("Update gui-monitor's data. Id: " & CarId'Img & ", Pos: " & Pos'Img & ".");
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
);
391 if (Iter
/= Null_Iter
) then
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
398 Set
(Ref
.Model1
, Iter
, 4, GInt
(Lap
));
399 Set
(Ref
.Model1
, Iter
, 5, GInt
(Intermediate
));
401 Set
(Ref
.Model1
, Iter
, 4, 0);
402 Set
(Ref
.Model1
, Iter
, 5, 0);
405 Set
(Ref
.Model1
, Iter
, 6, "running");
407 if( Pos
- OldPos
= 0) then
408 ChangePosition
(CarId
) := 0;
410 ChangePosition
(CarId
) :=ChangePosition
(CarId
)+ Pos
- OldPos
;
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");
418 Set
(Ref
.Model1
, Iter
, 2, "white");
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");
435 Set
(Ref
.Model1
, Iter
, 2, "red");
440 Next
(Ref
.Model1
, Iter
);
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
452 Set
(Ref
.Model1
, Iter
, 4, GInt
(Lap
));
453 Set
(Ref
.Model1
, Iter
, 5, GInt
(Intermediate
));
455 Set
(Ref
.Model1
, Iter
, 4, 0);
456 Set
(Ref
.Model1
, Iter
, 5, 0);
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, "--");
464 -- aggiorno i valori massimi
465 if ((Lap
> Ref
.LastLap
or ((Lap
= Ref
.LastLap
) and (Intermediate
> Ref
.LastInt
))) and Ref
.Observing
= False) then
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
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
));
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);
487 DurationIO
.Put
(StrTime
, (WakeupTime
- Ref
.LastTime
), Aft
=> 3);
488 Set
(Ref
.Model2
, Iter
, 2, "+ "&StrTime
&" s");
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);
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");
507 Set
(Ref
.Model1
, Iter1
, 2, "red");
510 Next
(Ref
.Model1
, Iter1
);
512 Next
(Ref
.Model2
, Iter
);
518 procedure UpdateLapTime
( Id
: CarId_T
; LastLap
: Duration; BestLap
: Duration) is
519 Iter
: Gtk_Tree_Iter
;
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
);
532 if (Iter
/= Null_Iter
) then
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);
540 Set
(Ref
.Model1
, Iter
, 8, "--");
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);
548 Set
(Ref
.Model1
, Iter
, 9, "--");
554 procedure UpdateCarStatus
( Id
: CarId_T
; Status
: CarStatus_T
) is
555 Iter
: Gtk_Tree_Iter
;
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
);
565 if (Iter
/= Null_Iter
) then
569 Set
(Ref
.Model1
, Iter
, 6, "retired");
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);
575 Set
(Ref
.Model1
, Iter
, 6, "finished");
577 Set
(Ref
.Model1
, Iter
, 6, "running");
579 Set
(Ref
.Model1
, Iter
, 6, "uknown");
585 procedure Update_BestLap
(Id
: CarId_T
; Lap
: Positive; Time
: Duration) is
590 -- Put_Line("Update monitor's best lap.");
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);
600 procedure Update_MaxSpeed
(Id
: CarId_T
; Val
: Float) is
601 StrSpeed
: String := "vvvvvv";
603 -- Put_Line("Update monitor's max speed.");
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);
610 procedure ToggleLock
(Widget
: access Gtk_Widget_Record
'Class) is
612 Ref
.Observing
:= not Ref
.Observing
;
613 if (Ref
.Observing
) then
614 Set_Label
(Ref
.Lock
, "Unlock");
616 Set_Label
(Ref
.Lock
, "Lock");
621 ans
: Message_Dialog_Buttons
;
624 ans
:= Message_Dialog
("Race Finished !", Buttons
=> Button_OK
);
628 end Simulator
.Monitor
.Gui
;