Skip to content

Commit

Permalink
[papgets] start working on multi AC papgets
Browse files Browse the repository at this point in the history
  • Loading branch information
gautierhattenberger committed Jan 15, 2015
1 parent 912e5e5 commit c330c95
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions sw/ground_segment/cockpit/live.ml
Expand Up @@ -545,6 +545,7 @@ let create_ac = fun alert (geomap:G.widget) (acs_notebook:GPack.notebook) (ac_id
(* Drag for Drop *)
let papget = Papget_common.xml "goto_block" "button"
[ "block_name", block_name;
"sender", ac_id;
"icon", icon] in
Papget_common.dnd_source b#coerce papget;

Expand Down
15 changes: 12 additions & 3 deletions sw/ground_segment/cockpit/papgets.ml
Expand Up @@ -42,9 +42,11 @@ let papget_listener =
fun papget ->
try
let field = Papget_common.get_property "field" papget in
let sender = Papget_common.get_property "sender" papget in
prerr_endline field; flush stderr;
match Str.split sep field with
[msg_name; field_name] ->
(new Papget.message_field msg_name field_name)
(new Papget.message_field ~sender msg_name field_name)
| _ -> failwith (sprintf "Unexpected field spec: %s" field)
with
_ -> failwith (sprintf "field attr expected in '%s" (Xml.to_string papget))
Expand Down Expand Up @@ -72,7 +74,8 @@ let extra_functions =
let expression_listener = fun papget ->
let expr = Papget_common.get_property "expr" papget in
let expr = Expr_lexer.parse expr in
new Papget.expression ~extra_functions expr
let sender = Papget_common.get_property "sender" papget in
new Papget.expression ~extra_functions ~sender expr



Expand Down Expand Up @@ -125,12 +128,17 @@ let create = fun canvas_group papget ->
let block_name = Papget_common.get_property "block_name" papget in
let clicked = fun () ->
prerr_endline "Warning: goto_block papget sends to all A/C";
let sender = Papget_common.get_property "sender" papget in
printf "%s\n" sender; flush stdout;
Hashtbl.iter
(fun ac_id ac ->
printf "%s %s\n" sender ac_id; flush stdout;
if ac_id = sender then begin
let blocks = ExtXml.child ac.Live.fp "blocks" in
let block = ExtXml.child ~select:(fun x -> ExtXml.attrib x "name" = block_name) blocks "block" in
let block_id = ExtXml.int_attrib block "no" in
Live.jump_to_block ac_id block_id
end
)
Live.aircrafts
in
Expand Down Expand Up @@ -198,13 +206,14 @@ let parse_message_dnd =
| _ -> raise (Parse_message_dnd (Printf.sprintf "parse_dnd: %s" s))
let dnd_data_received = fun canvas_group _context ~x ~y data ~info ~time ->
try (* With the format sent by Messages *)
let (_sender, _class_name, msg_name, field_name,scale) = parse_message_dnd data#data in
let (sender, _class_name, msg_name, field_name,scale) = parse_message_dnd data#data in
let attrs =
[ "type", "message_field";
"display", "text";
"x", sprintf "%d" x; "y", sprintf "%d" y ]
and props =
[ Papget_common.property "field" (sprintf "%s:%s" msg_name field_name);
Papget_common.property "sender" sender;
Papget_common.property "scale" scale ] in
let papget_xml = Xml.Element ("papget", attrs, props) in
create canvas_group papget_xml
Expand Down
6 changes: 3 additions & 3 deletions sw/lib/ocaml/papget.ml
Expand Up @@ -83,7 +83,7 @@ object
end


let hash_vars = fun expr ->
let hash_vars = fun ?sender expr ->
let htable = Hashtbl.create 3 in
let rec loop = function
E.Ident i -> prerr_endline i
Expand Down Expand Up @@ -131,8 +131,8 @@ let eval_expr = fun (extra_functions:(string * (string list -> string)) list) h



class expression = fun ?(extra_functions=[]) expr ->
let h = hash_vars expr in
class expression = fun ?(extra_functions=[]) ?sender expr ->
let h = hash_vars ~sender expr in
object
val mutable callbacks = []
val mutable last_value = "0."
Expand Down
1 change: 1 addition & 0 deletions sw/lib/ocaml/papget.mli
Expand Up @@ -45,6 +45,7 @@ class message_field :

class expression :
?extra_functions:(string * (string list -> string)) list ->
?sender:string ->
Expr_syntax.expression ->
value

Expand Down

0 comments on commit c330c95

Please sign in to comment.