Skip to content

Commit

Permalink
[settings] uncheck settings if not compatible with target
Browse files Browse the repository at this point in the history
I wanted to make the line unsensitive, but it doesn't seems to be
possible. Either all the lines or nothing. As a fallback, the settings
is unselected. It is not perfect (some stuff might be missed, you can
check it back, ...) and the settings are removed at generation time
anyway.
Not sure it can be done better unless someone finds the way to control
the list element sensitivity one by one.
  • Loading branch information
gautierhattenberger committed Apr 11, 2015
1 parent ce93943 commit eb26366
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
4 changes: 2 additions & 2 deletions sw/lib/ocaml/gtk_tools.ml
Expand Up @@ -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) ->
Expand Down
2 changes: 1 addition & 1 deletion sw/lib/ocaml/gtk_tools.mli
Expand Up @@ -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

72 changes: 70 additions & 2 deletions sw/supervision/pc_aircraft.ml
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eb26366

Please sign in to comment.