diff --git a/sw/lib/ocaml/gtk_tools.ml b/sw/lib/ocaml/gtk_tools.ml index fc902bdafc8..65fc711a267 100644 --- a/sw/lib/ocaml/gtk_tools.ml +++ b/sw/lib/ocaml/gtk_tools.ml @@ -168,13 +168,13 @@ let get_selected_in_tree = fun (tree : tree) -> * if element is between brackets, set to unchecked * and remove brackets in tree name *) -let add_to_tree = fun (tree : tree) string -> +let add_to_tree = fun ?(force_unselect=false) (tree : tree) string -> let (store, name, check, _) = tree_model tree in let row = store#append () in let l = String.length string in let checked = not (string.[0] = '[' && string.[l - 1] = ']') in let string = if not checked then String.sub string 1 (l - 2) else string in - store#set ~row ~column:check checked; + store#set ~row ~column:check (checked && not force_unselect); store#set ~row ~column:name string let remove_selected_from_tree = fun (tree : tree) -> diff --git a/sw/lib/ocaml/gtk_tools.mli b/sw/lib/ocaml/gtk_tools.mli index 33b6676c8c6..f074b471b56 100644 --- a/sw/lib/ocaml/gtk_tools.mli +++ b/sw/lib/ocaml/gtk_tools.mli @@ -68,7 +68,7 @@ val tree_of : GTree.view -> (GTree.list_store * string GTree.column * bool GTree val tree_values : ?only_checked:bool -> tree -> string val get_selected_in_tree : tree -> GTree.row_reference list -val add_to_tree : tree -> string -> unit +val add_to_tree : ?force_unselect:bool -> tree -> string -> unit val remove_selected_from_tree : tree -> unit val clear_tree : tree -> unit diff --git a/sw/supervision/pc_aircraft.ml b/sw/supervision/pc_aircraft.ml index e027d8e8d42..751c8c02f1f 100644 --- a/sw/supervision/pc_aircraft.ml +++ b/sw/supervision/pc_aircraft.ml @@ -215,6 +215,33 @@ let first_word = fun s -> with Not_found -> s +(** Test if an element is available for the current target *) +let is_element_unselected = fun target_combo name -> + let target = Gtk_tools.combo_value target_combo in + let test_targets = fun targets -> + List.exists (fun t -> t = target) targets + in + try + let name = (Env.paparazzi_home // "conf" // name) in + let xml = Xml.parse_file name in + match Xml.tag xml with + | "settings" -> + let targets = Xml.attrib xml "target" in + let target_list = Str.split (Str.regexp "|") targets in + not (test_targets target_list) + | "module" -> + let targets = List.map (fun x -> + match String.lowercase (Xml.tag x) with + | "makefile" -> Gen_common.targets_of_field x Env.default_module_targets + | _ -> [] + ) (Xml.children xml) in + let targets = (List.flatten targets) in + (* singletonized list *) + let targets = Gen_common.singletonize (List.sort compare targets) in + not (test_targets targets) + | _ -> false + with _ -> false + (** Get list of targets of an airframe *) let get_targets_list = fun ac_xml -> let firmwares = List.filter (fun x -> ExtXml.tag_is x "firmware") (Xml.children ac_xml) in @@ -312,7 +339,10 @@ let ac_combo_handler = fun gui (ac_combo:Gtk_tools.combo) target_combo flash_com | Tree t -> ignore (Gtk_tools.clear_tree t); let names = Str.split regexp_space (value a) in - List.iter (fun n -> Gtk_tools.add_to_tree t n) names; + List.iter (fun n -> + let force_unselect = is_element_unselected target_combo n in + Gtk_tools.add_to_tree ~force_unselect t n + ) names; ) ac_files; let ac_id = ExtXml.attrib aircraft "ac_id" and gui_color = ExtXml.attrib_or_default aircraft "gui_color" "white" in @@ -336,6 +366,41 @@ let ac_combo_handler = fun gui (ac_combo:Gtk_tools.combo) target_combo flash_com in Gtk_tools.combo_connect ac_combo update_params; + (* connect target combo *) + Gtk_tools.combo_connect target_combo (fun target -> + let ac_name = Gtk_tools.combo_value ac_combo in + try + let aircraft = Hashtbl.find Utils.aircrafts ac_name in + let sample = aircraft_sample ac_name "42" in + (* update list of modules settings *) + let settings_modules = try + let af_xml = Xml.parse_file (Env.paparazzi_home // "conf" // (Xml.attrib aircraft "airframe")) in + get_settings_modules af_xml (ExtXml.attrib_or_default aircraft "settings_modules" "") + with + | Failure x -> prerr_endline x; [] + | _ -> [] + in + (* update aicraft hashtable *) + let aircraft = ExtXml.subst_attrib "settings_modules" (String.concat " " settings_modules) aircraft in + begin try Hashtbl.remove Utils.aircrafts ac_name with _ -> () end; + Hashtbl.add Utils.aircrafts ac_name aircraft; + let value = fun a -> try (ExtXml.attrib aircraft a) with _ -> Xml.attrib sample a in + (* update elements *) + List.iter (fun (a, _subdir, label, _, _, _, _) -> + match label with + | Label l -> l#set_text (value a) + | Tree t -> + ignore (Gtk_tools.clear_tree t); + let names = Str.split regexp_space (value a) in + List.iter (fun n -> + let force_unselect = is_element_unselected target_combo n in + Gtk_tools.add_to_tree ~force_unselect t n + ) names; + ) ac_files + with + Not_found -> () + ); + (* New A/C button *) let callback = fun _ -> match GToolbox.input_string ~title:"New A/C" ~text:"MYAC" "New A/C name ?" with @@ -422,7 +487,10 @@ let ac_combo_handler = fun gui (ac_combo:Gtk_tools.combo) target_combo flash_com let names = String.concat " " names in l#set_text names | Tree t -> - List.iter (fun n -> Gtk_tools.add_to_tree t n) names + List.iter (fun n -> + let force_unselect = is_element_unselected target_combo n in + Gtk_tools.add_to_tree ~force_unselect t n + ) names ); save_callback gui ac_combo tree_set tree_set_mod (); let ac_name = Gtk_tools.combo_value ac_combo in