From c3f63ca63ba1465d54f0a18fb48e9a0a10e4c68d Mon Sep 17 00:00:00 2001 From: Gautier Hattenberger Date: Thu, 24 Jan 2013 11:35:41 +0100 Subject: [PATCH] [sim] check targets and ask which simulator to use --- sw/lib/ocaml/gtk_tools.ml | 8 ++++++++ sw/lib/ocaml/gtk_tools.mli | 1 + sw/simulator/ppzsim-launch | 8 ++++---- sw/supervision/paparazzicenter.ml | 2 +- sw/supervision/pc_control_panel.ml | 29 +++++++++++++++++++---------- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/sw/lib/ocaml/gtk_tools.ml b/sw/lib/ocaml/gtk_tools.ml index 140b7312e4..f42f89bf91 100644 --- a/sw/lib/ocaml/gtk_tools.ml +++ b/sw/lib/ocaml/gtk_tools.ml @@ -68,6 +68,14 @@ let combo_value = fun ((combo: #GEdit.combo_box), (_,column)) -> | None -> raise Not_found | Some row -> combo#model#get ~row ~column +let combo_values_list = fun (combo : combo) -> + let (store, column) = combo_model combo in + let values = ref [] in + store#foreach (fun _ row -> + values := !values @ [store#get ~row ~column]; + false); + !values + let combo_separator = "--" let combo = fun strings vbox -> diff --git a/sw/lib/ocaml/gtk_tools.mli b/sw/lib/ocaml/gtk_tools.mli index f0980b13d1..737f112040 100644 --- a/sw/lib/ocaml/gtk_tools.mli +++ b/sw/lib/ocaml/gtk_tools.mli @@ -54,6 +54,7 @@ val add_to_combo : combo -> string -> unit val combo_separator : string val combo_value : combo -> string +val combo_values_list : combo -> string list val select_in_combo : combo -> string -> unit val combo_connect : combo -> (string -> unit) -> unit diff --git a/sw/simulator/ppzsim-launch b/sw/simulator/ppzsim-launch index 3ae6532c15..ea1a1b276c 100755 --- a/sw/simulator/ppzsim-launch +++ b/sw/simulator/ppzsim-launch @@ -39,9 +39,9 @@ def main(): action="store", help="aircraft name to use") parser.add_option("-t", "--type", dest="simtype", - type='choice', choices=['simple_fw', 'jsbsim', 'nps'], - action="store", default="simple_fw", - help="Simlator type to start: simple_fw, jsbsim or nps (Default: %default)") + type='choice', choices=['sim', 'jsbsim', 'nps'], + action="store", default="sim", + help="Simlator type to start: sim, jsbsim or nps (Default: %default)") parser.add_option("-b", "--ivy_bus", dest="ivy_bus", action="store", help="Ivy Bus broadcast address.") parser.add_option("-f", "--fg_host", dest="fg_host", action="store", @@ -84,7 +84,7 @@ def main(): simargs = [] - if options.simtype == "simple_fw": + if options.simtype == "sim": simdir = "sim" if options.boot: simargs.append("-boot") diff --git a/sw/supervision/paparazzicenter.ml b/sw/supervision/paparazzicenter.ml index 63358ef104..cc4b8dc333 100644 --- a/sw/supervision/paparazzicenter.ml +++ b/sw/supervision/paparazzicenter.ml @@ -236,7 +236,7 @@ let () = AC.build_handler ~file gui ac_combo target_combo log; - let session_combo, execute_session = CP.supervision ~file gui log ac_combo in + let session_combo, execute_session = CP.supervision ~file gui log ac_combo target_combo in (* Quit button *) ignore (gui#menu_item_quit#connect#activate ~callback:(quit_button_callback gui ac_combo session_combo target_combo)); diff --git a/sw/supervision/pc_control_panel.ml b/sw/supervision/pc_control_panel.ml index 0df7e7fcd2..ca0f464e48 100644 --- a/sw/supervision/pc_control_panel.ml +++ b/sw/supervision/pc_control_panel.ml @@ -141,27 +141,36 @@ let double_quote = fun s -> else s -let get_simtype = fun () -> - match GToolbox.question_box ~title:"Simulator type" ~buttons:["Simple (fixedwing)"; "JSBSim"; "NPS (rotorcraft)"] "Choose the simulator type:" with - 1 -> "simple_fw" - | 2 -> "jsbsim" - | 3 -> "nps" - | _ -> "none" +let get_simtype = fun (target_combo : Gtk_tools.combo) -> + (* get the list of possible targets *) + let targets = Gtk_tools.combo_values_list target_combo in + (* filter non simulator targets *) + let sim_targets = ["sim"; "jsbsim"; "nps"] in + let targets = List.filter (fun t -> List.mem t sim_targets) targets in + (* open question box and return corresponding simulator type *) + match targets with + [] -> "none" + | [t] -> t + | l -> + match GToolbox.question_box ~title:"Simulator type" ~buttons:l "Choose the simulator type:" with + | 0 -> "none" + | choice -> List.nth targets (choice-1) -let supervision = fun ?file gui log (ac_combo : Gtk_tools.combo) -> +let supervision = fun ?file gui log (ac_combo : Gtk_tools.combo) (target_combo : Gtk_tools.combo) -> let run_gcs = fun () -> run_and_monitor ?file gui log "GCS" "" and run_server = fun args -> run_and_monitor ?file gui log "Server" args and run_sitl = fun ac_name -> - let get_args = fun simtype ac_name-> + let get_args = fun simtype ac_name -> match simtype with - "simple_fw" -> sprintf "-a %s -t %s --boot --norc" ac_name simtype + "sim" -> sprintf "-a %s -t %s --boot --norc" ac_name simtype | "jsbsim" -> sprintf "-a %s -t %s" ac_name simtype | "nps" -> sprintf "-a %s -t %s" ac_name simtype | _ -> sprintf "-a %s" ac_name in - let sim_type = get_simtype () in + let sim_type = get_simtype target_combo in + prerr_endline sim_type; let args = get_args sim_type ac_name in run_and_monitor ?file gui log "Simulator" args in