[gcs] remove intruders when they no longer exist

This commit is contained in:
Gautier Hattenberger
2015-10-06 16:42:30 +02:00
parent 71111f889f
commit fed13bdbe8
4 changed files with 22 additions and 10 deletions
+2 -3
View File
@@ -30,15 +30,14 @@ type intruder = {
let intruders = Hashtbl.create 1
let new_intruder = fun id name time geomap ->
let track = new MapTrack.track ~size:10 ~icon:"intruder" ~name id geomap in
let track = new MapTrack.track ~size:20 ~icon:"intruder" ~name ~show_carrot:false id geomap in
let intruder = { intruder_track = track; last_update = time } in
Hashtbl.add intruders id intruder
let remove_intruder = fun id ->
try
let intruder = Hashtbl.find intruders id in
intruder.intruder_track#clear ();
(* TODO delete something more ? mapTrack object ? *)
intruder.intruder_track#destroy ();
Hashtbl.remove intruders id
with _ -> () (* no intruder *)
+5 -2
View File
@@ -168,9 +168,12 @@ let icon_home_template = {
}
let icon_intruder_template = {
lines = [];
lines = [
[| 0.; 0.; 0.; -24. |];
[| 6.; -15.; 0.; -24.; -6.; -15.|]; (** Front Marker **)
];
ellipse = [
[| -10.; -10.; 10.; 10.|];
[| -8.; -8.; 8.; 8.|];
];
width = 1
}
+13 -5
View File
@@ -53,7 +53,7 @@ type desired =
| DesiredCircle of LL.geographic*float*GnoCanvas.ellipse
| DesiredSegment of LL.geographic*LL.geographic*GnoCanvas.line
class track = fun ?(name="Noname") ?(icon="fixedwing") ?(size = 500) ?(color="red") (ac_id:string) (geomap:MapCanvas.widget) ->
class track = fun ?(name="Noname") ?(icon="fixedwing") ?(size = 500) ?(color="red") ?(show_carrot=true) (ac_id:string) (geomap:MapCanvas.widget) ->
let group = GnoCanvas.group geomap#canvas#root in
let empty = ({LL.posn_lat=0.; LL.posn_long=0.}, GnoCanvas.line group) in
let v_empty = ({LL.posn_lat=0.; LL.posn_long=0.}, 0.0) in
@@ -78,7 +78,10 @@ class track = fun ?(name="Noname") ?(icon="fixedwing") ?(size = 500) ?(color="re
let carrot = GnoCanvas.group group in
let _ac_carrot =
ignore (GnoCanvas.polygon ~points:[|0.;0.;-5.;-10.;5.;-10.|] ~props:[`WIDTH_UNITS 1.;`FILL_COLOR "orange"; `OUTLINE_COLOR "orange"; `FILL_STIPPLE (Gdk.Bitmap.create_from_data ~width:2 ~height:2 "\002\001")] carrot) in
if show_carrot then
ignore (GnoCanvas.polygon ~points:[|0.;0.;-5.;-10.;5.;-10.|] ~props:[`WIDTH_UNITS 1.;`FILL_COLOR "orange"; `OUTLINE_COLOR "orange"; `FILL_STIPPLE (Gdk.Bitmap.create_from_data ~width:2 ~height:2 "\002\001")] carrot)
else ()
in
let cam = GnoCanvas.group group in
@@ -126,6 +129,7 @@ object (self)
val zone = GnoCanvas.rect group
val mutable ac_cam_cover = GnoCanvas.rect ~fill_color:"grey" ~props:[`WIDTH_PIXELS 1 ; `FILL_STIPPLE (Gdk.Bitmap.create_from_data ~width:2 ~height:2 "\002\001")] cam
val mutable event_cb = None
val mutable destroyed = false
method color = color
method set_color c = color <- c
method track = track
@@ -361,9 +365,13 @@ object (self)
method set_event_cb = fun (cb: string -> unit) -> event_cb <- Some cb
initializer
ignore(geomap#zoom_adj#connect#value_changed
(fun () -> self#zoom geomap#zoom_adj#value))
(* could not properly disconnect adjustment signal, so only calling zoom method if group is still displayed *)
ignore(geomap#zoom_adj#connect#value_changed (fun () -> if not destroyed then self#zoom geomap#zoom_adj#value));
ignore(group#connect#destroy (fun () -> destroyed <- true))
(* destroy method *)
method destroy = fun () -> group#destroy ()
initializer
Gc.finalise (fun self -> group#destroy ()) self
Gc.finalise (fun self -> self#destroy ()) self
end
+2
View File
@@ -27,6 +27,7 @@ class track :
?icon:string ->
?size:int ->
?color:string ->
?show_carrot:bool ->
string ->
MapCanvas.widget ->
object
@@ -69,4 +70,5 @@ class track :
method zoom : float -> unit
method event : GnoCanvas.item_event -> bool
method set_event_cb : (string -> unit) -> unit
method destroy : unit -> unit
end