mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-31 20:38:27 +08:00
[units] fix display of deg in messages (no conversion)
This commit is contained in:
@@ -67,7 +67,7 @@ let one_page = fun sender class_name (notebook:GPack.notebook) bind m ->
|
|||||||
let literal_values = values_of_field f in
|
let literal_values = values_of_field f in
|
||||||
let alt_value =
|
let alt_value =
|
||||||
try
|
try
|
||||||
let coeff = float_of_string (Pprz.alt_unit_coef_of_xml f)
|
let coeff = float_of_string (Pprz.alt_unit_coef_of_xml ~auto:"display" f)
|
||||||
and unit = Xml.attrib f "alt_unit" in
|
and unit = Xml.attrib f "alt_unit" in
|
||||||
fun value -> sprintf "%s (%f%s)" value (coeff*.float_of_string value) unit
|
fun value -> sprintf "%s (%f%s)" value (coeff*.float_of_string value) unit
|
||||||
with
|
with
|
||||||
@@ -86,7 +86,7 @@ let one_page = fun sender class_name (notebook:GPack.notebook) bind m ->
|
|||||||
(* box dragger *)
|
(* box dragger *)
|
||||||
field_label#drag#source_set dnd_targets ~modi:[`BUTTON1] ~actions:[`COPY];
|
field_label#drag#source_set dnd_targets ~modi:[`BUTTON1] ~actions:[`COPY];
|
||||||
let data_get = fun _ (sel:GObj.selection_context) ~info ~time ->
|
let data_get = fun _ (sel:GObj.selection_context) ~info ~time ->
|
||||||
let scale = Pprz.alt_unit_coef_of_xml f in
|
let scale = Pprz.alt_unit_coef_of_xml ~auto:"display" f in
|
||||||
let field_descr =
|
let field_descr =
|
||||||
if Pprz.is_array_type type_ then
|
if Pprz.is_array_type type_ then
|
||||||
match GToolbox.input_string ~title:"Index of value to drag" ~text:"0" "Index in the array ?" with
|
match GToolbox.input_string ~title:"Index of value to drag" ~text:"0" "Index in the array ?" with
|
||||||
|
|||||||
+10
-5
@@ -162,7 +162,7 @@ exception Unit_conversion_error of string
|
|||||||
exception Unknown_conversion of string * string
|
exception Unknown_conversion of string * string
|
||||||
exception No_automatic_conversion of string * string
|
exception No_automatic_conversion of string * string
|
||||||
|
|
||||||
let scale_of_units = fun from_unit to_unit ->
|
let scale_of_units = fun ?auto from_unit to_unit ->
|
||||||
if (from_unit = to_unit) then
|
if (from_unit = to_unit) then
|
||||||
1.0
|
1.0
|
||||||
else
|
else
|
||||||
@@ -173,7 +173,9 @@ let scale_of_units = fun from_unit to_unit ->
|
|||||||
(* will raise Xml.No_attribute if not a valid attribute *)
|
(* will raise Xml.No_attribute if not a valid attribute *)
|
||||||
let f = Xml.attrib u "from"
|
let f = Xml.attrib u "from"
|
||||||
and t = Xml.attrib u "to"
|
and t = Xml.attrib u "to"
|
||||||
and a = String.lowercase (ExtXml.attrib_or_default u "auto" "") in
|
and a = match auto with
|
||||||
|
| Some a -> a
|
||||||
|
| None -> String.lowercase (ExtXml.attrib_or_default u "auto" "") in
|
||||||
if (f = from_unit || a = "display") && (t = to_unit || a = "code") then true else false
|
if (f = from_unit || a = "display") && (t = to_unit || a = "code") then true else false
|
||||||
) (Xml.children units_xml) in
|
) (Xml.children units_xml) in
|
||||||
(* return coef, raise Failure if coef is not a numerical value *)
|
(* return coef, raise Failure if coef is not a numerical value *)
|
||||||
@@ -187,13 +189,16 @@ let scale_of_units = fun from_unit to_unit ->
|
|||||||
| _ -> raise (Unknown_conversion (from_unit, to_unit))
|
| _ -> raise (Unknown_conversion (from_unit, to_unit))
|
||||||
|
|
||||||
|
|
||||||
let alt_unit_coef_of_xml = function xml ->
|
let alt_unit_coef_of_xml = fun ?auto xml ->
|
||||||
try Xml.attrib xml "alt_unit_coef"
|
try Xml.attrib xml "alt_unit_coef"
|
||||||
with _ ->
|
with _ ->
|
||||||
let u = try Xml.attrib xml "unit" with _ -> "" in
|
let u = try Xml.attrib xml "unit" with _ -> "" in
|
||||||
let au = try Xml.attrib xml "alt_unit" with _ -> "" in
|
let au = try Xml.attrib xml "alt_unit" with _ -> "" in
|
||||||
let coef = try string_of_float (scale_of_units u au) with
|
let coef = try string_of_float (match auto with
|
||||||
Unit_conversion_error s -> prerr_endline (sprintf "Unit conversion error: %s" s); flush stderr; "1." (* Use coef 1. *)
|
| None -> scale_of_units u au
|
||||||
|
| Some a -> scale_of_units u au ~auto:a)
|
||||||
|
with
|
||||||
|
| Unit_conversion_error s -> prerr_endline (sprintf "Unit conversion error: %s" s); flush stderr; "1." (* Use coef 1. *)
|
||||||
| Unknown_conversion _ -> "1." (* Use coef 1. *)
|
| Unknown_conversion _ -> "1." (* Use coef 1. *)
|
||||||
| _ -> "1."
|
| _ -> "1."
|
||||||
in
|
in
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ exception No_automatic_conversion of string * string
|
|||||||
* and from_unit or to_unit are empty string
|
* and from_unit or to_unit are empty string
|
||||||
*)
|
*)
|
||||||
|
|
||||||
val scale_of_units : string -> string -> float
|
val scale_of_units : ?auto:string -> string -> string -> float
|
||||||
(** scale_of_units from to
|
(** scale_of_units from to
|
||||||
* Returns conversion factor between two units
|
* Returns conversion factor between two units
|
||||||
* The possible conversions are described in conf/units.xml
|
* The possible conversions are described in conf/units.xml
|
||||||
@@ -103,7 +103,7 @@ val scale_of_units : string -> string -> float
|
|||||||
* or if units.xml is not valid
|
* or if units.xml is not valid
|
||||||
*)
|
*)
|
||||||
|
|
||||||
val alt_unit_coef_of_xml : Xml.xml -> string
|
val alt_unit_coef_of_xml : ?auto:string -> Xml.xml -> string
|
||||||
(** Return coef for alternate unit
|
(** Return coef for alternate unit
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user