diff --git a/sw/ground_segment/cockpit/live.ml b/sw/ground_segment/cockpit/live.ml index 413b845314..b5b5abf876 100644 --- a/sw/ground_segment/cockpit/live.ml +++ b/sw/ground_segment/cockpit/live.ml @@ -104,20 +104,24 @@ let resize_track = fun ac track -> None -> () | Some s -> track#resize (int_of_string s) + +let send_move_waypoint_msg = fun ac i w -> + let wgs84 = w#pos in + let vs = ["ac_id", Pprz.String ac; + "wp_id", Pprz.Int i; + "lat", Pprz.Float ((Rad>>Deg)wgs84.posn_lat); + "long", Pprz.Float ((Rad>>Deg)wgs84.posn_long); + "alt", Pprz.Float w#alt + ] in + Ground_Pprz.message_send "map2d" "MOVE_WAYPOINT" vs + let commit_changes = fun ac -> let a = Hashtbl.find live_aircrafts ac in List.iter (fun w -> let (i, w) = a.fp_group#index w in if w#moved then - let wgs84 = w#pos in - let vs = ["ac_id", Pprz.String ac; - "wp_id", Pprz.Int i; - "lat", Pprz.Float ((Rad>>Deg)wgs84.posn_lat); - "long", Pprz.Float ((Rad>>Deg)wgs84.posn_long); - "alt", Pprz.Float w#alt - ] in - Ground_Pprz.message_send "map2d" "MOVE_WAYPOINT" vs) + send_move_waypoint_msg ac i w) a.fp_group#waypoints let center = fun geomap track () -> @@ -307,6 +311,13 @@ let create_ac = fun (geomap:G.widget) (acs_notebook:GPack.notebook) (ac_id:strin let id = list_casso block blocks in jump_to_block ac_id id); ignore (reset_wp_menu#connect#activate (reset_waypoints fp)); + + (** Monitor waypoints changes *) + List.iter + (fun w -> + let (i, w) = fp#index w in + w#set_commit_callback (fun () -> send_move_waypoint_msg ac_id i w)) + fp#waypoints; (** Add the short cut buttons in the strip *) List.iter (fun b -> diff --git a/sw/lib/ocaml/mapCanvas.ml b/sw/lib/ocaml/mapCanvas.ml index f54ccdfe79..a09e1e58ff 100644 --- a/sw/lib/ocaml/mapCanvas.ml +++ b/sw/lib/ocaml/mapCanvas.ml @@ -397,7 +397,7 @@ class basic_widget = fun ?(height=800) ?width ?(projection = Mercator) ?georef ( let current_point = LL.utm_of LL.WGS84 (self#of_world (xw, yw)) in let (east, north) = LL.utm_sub current_point starting_point in region_rectangle#set [`X2 xw; `Y2 yw]; - self#display_group (sprintf "[%.1fkm %.1fkm]" (east/.1000.) (north/.1000.)) + self#display_group (sprintf "[%.0fm %.0fm]" east north) | Polygon ps -> let points = convex ((xw,yw)::ps) in drawing <- Polygon points; diff --git a/sw/lib/ocaml/mapWaypoints.ml b/sw/lib/ocaml/mapWaypoints.ml index 29a0f46a3c..152d536b3a 100644 --- a/sw/lib/ocaml/mapWaypoints.ml +++ b/sw/lib/ocaml/mapWaypoints.ml @@ -73,11 +73,13 @@ class waypoint = fun (wpts_group:group) (name :string) ?(alt=0.) wgs84 -> val mutable alt = alt val mutable moved = None val mutable deleted = false + val mutable commit_cb = None initializer item#affine_absolute rotation_45; self#move xw yw method connect = fun (cb:unit -> unit) -> Hashtbl.add callbacks cb () + method set_commit_callback = fun (cb:unit -> unit) -> commit_cb <- Some cb method name = name method set_name n = if n <> name then begin @@ -90,7 +92,7 @@ class waypoint = fun (wpts_group:group) (name :string) ?(alt=0.) wgs84 -> method move dx dy = wpt_group#move dx dy method edit = - let dialog = GWindow.window ~border_width:10 ~title:"Waypoint Edit" () in + let dialog = GWindow.window ~position:`MOUSE ~border_width:10 ~title:"Waypoint Edit" () in let dvbx = GPack.box `VERTICAL ~packing:dialog#add () in let wgs84 = self#pos in @@ -114,12 +116,20 @@ class waypoint = fun (wpts_group:group) (name :string) ?(alt=0.) wgs84 -> updated (); if wpts_group#show_moved then moved <- anim moved; + begin + match commit_cb with + Some cb -> cb () + | None -> () + end; dialog#destroy () in let dhbx = GPack.box `HORIZONTAL ~packing: dvbx#add () in - let cancel = GButton.button ~stock:`CANCEL ~packing: dhbx#add () in - ignore(cancel#connect#clicked ~callback:dialog#destroy); + let cancel = GButton.button ~stock:`CANCEL ~packing: dhbx#add () in + let destroy = fun () -> + self#reset_moved (); + dialog#destroy () in + ignore(cancel#connect#clicked ~callback:destroy); if editable then begin let delete = GButton.button ~stock:`DELETE ~packing: dhbx#add () in @@ -173,8 +183,7 @@ class waypoint = fun (wpts_group:group) (name :string) ?(alt=0.) wgs84 -> | `BUTTON_RELEASE ev -> if GdkEvent.Button.button ev = 1 then begin item#ungrab (GdkEvent.Button.time ev); - if not motion then - self#edit + self#edit end | _ -> () end; diff --git a/sw/lib/ocaml/mapWaypoints.mli b/sw/lib/ocaml/mapWaypoints.mli index bdef5cfd8b..d8d0a05d28 100644 --- a/sw/lib/ocaml/mapWaypoints.mli +++ b/sw/lib/ocaml/mapWaypoints.mli @@ -60,6 +60,7 @@ class waypoint : method reset_moved : unit -> unit method deleted : bool method connect : (unit -> unit) -> unit + method set_commit_callback : (unit -> unit) -> unit end