Skip to content

Commit

Permalink
[settings/gcs] save and display settings as integer if step is integer
Browse files Browse the repository at this point in the history
  • Loading branch information
gautierhattenberger committed Mar 12, 2013
1 parent 04a901c commit b4ff042
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion sw/ground_segment/cockpit/page_settings.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ let one_setting = fun (i:int) (do_change:int -> float -> unit) packing dl_settin
fprintf stderr "Warning: 'step' attribute missing in '%s' setting. Default to 1\n%!" (Xml.to_string dl_setting);
1.
in
let digits = try ignore(int_of_string (ExtXml.attrib dl_setting "step")); 0 with _ -> 3 in
let page_incr = step_incr
and page_size = step_incr
and show_auto = try ExtXml.attrib dl_setting "auto" = "true" with _ -> false in
Expand Down Expand Up @@ -135,7 +136,7 @@ let one_setting = fun (i:int) (do_change:int -> float -> unit) packing dl_settin
else (* slider *)
let value = (lower +. upper) /. 2. in
let adj = GData.adjustment ~value ~lower ~upper:(upper+.step_incr) ~step_incr ~page_incr ~page_size () in
let _scale = GRange.scale `HORIZONTAL ~digits:3 ~update_policy:`DELAYED ~adjustment:adj ~packing:hbox#add () in
let _scale = GRange.scale `HORIZONTAL ~digits ~update_policy:`DELAYED ~adjustment:adj ~packing:hbox#add () in
let f = fun _ -> do_change i ((adj#value-.alt_b)/.alt_a) in
let callback = fun () -> modified := true; if auto_but#active then f () in
ignore (adj#connect#value_changed ~callback);
Expand Down
9 changes: 7 additions & 2 deletions sw/ground_segment/cockpit/saveSettings.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and col_settings_value = cols#add Gobject.Data.float
and col_airframe_value_new = cols#add Gobject.Data.float
and col_code_value = cols#add Gobject.Data.float
and col_to_save = cols#add Gobject.Data.boolean
and col_integer = cols#add Gobject.Data.boolean

let (//) = Filename.concat

Expand Down Expand Up @@ -94,7 +95,8 @@ let write_xml = fun (model:GTree.tree_store) old_file airframe_xml file ->
if model#get ~row ~column:col_to_save then begin
let new_value = model#get ~row ~column:col_airframe_value_new
and param = model#get ~row ~column:col_param in
new_xml := EditAirframe.set !new_xml param (string_of_float new_value)
let string_value = if model#get ~row ~column:col_integer then string_of_int (truncate new_value) else string_of_float new_value in
new_xml := EditAirframe.set !new_xml param string_value
end;
false);
if old_file = file then begin
Expand Down Expand Up @@ -171,6 +173,8 @@ let fill_data = fun (model:GTree.tree_store) settings airframe_xml ->
Failure "float_of_string" -> raise (EditAirframe.No_param param)
in
let airframe_value_new = value /. airframe_scale in
(* test if is has to be saved as integer or float *)
let integer = try ignore(int_of_string (attrib "step")); true with _ -> false in
(* Printf.fprintf stderr "param %s: airframe_scale=%f display_scale=%f extra_scale=%f\n" param airframe_scale display_scale extra_scale; flush stderr; *)
let row = model#append () in
model#set ~row ~column:col_index index;
Expand All @@ -179,7 +183,8 @@ let fill_data = fun (model:GTree.tree_store) settings airframe_xml ->
model#set ~row ~column:col_settings_value (value *. display_scale);
model#set ~row ~column:col_airframe_value_new airframe_value_new;
model#set ~row ~column:col_code_value value;
model#set ~row ~column:col_to_save (floats_not_equal airframe_value_scaled value)
model#set ~row ~column:col_to_save (floats_not_equal airframe_value_scaled value);
model#set ~row ~column:col_integer integer
with
Xml.No_attribute _ | Exit -> ()
| EditAirframe.No_param param ->
Expand Down

0 comments on commit b4ff042

Please sign in to comment.