Values in arrays now dragable and plotable with real-time plotter

This commit is contained in:
Pascal Brisset
2009-08-09 21:08:28 +00:00
parent 327d4951e4
commit fb462876ee
3 changed files with 16 additions and 5 deletions
+13 -4
View File
@@ -57,12 +57,14 @@ let one_page = fun sender class_name (notebook:GPack.notebook) bind m ->
try
let unit = try "("^Xml.attrib f "unit"^")" with _ -> "" in
let field_name = Xml.attrib f "name" in
let name = Printf.sprintf "%s %s %s: " (ExtXml.attrib f "type") field_name unit in
let type_ = ExtXml.attrib f "type" in
let name = Printf.sprintf "%s %s %s: " type_ field_name unit in
let h = GPack.hbox ~packing:v#pack () in
let field_label = GButton.button ~label:name ~packing:h#pack () in
let value = ref "XXXX" in
let l = GMisc.label ~text: !value ~packing:h#pack () in
let values = values_of_field f in
let literal_values = values_of_field f in
let alt_value =
try
let coeff = ExtXml.float_attrib f "alt_unit_coef"
@@ -74,7 +76,7 @@ let one_page = fun sender class_name (notebook:GPack.notebook) bind m ->
value :=
try
let i = Pprz.int_of_value x in
sprintf "%s (%d)" values.(i) i
sprintf "%s (%d)" literal_values.(i) i
with _ ->
alt_value (Pprz.string_of_value x)
and display_value = fun () ->
@@ -85,7 +87,14 @@ let one_page = fun sender class_name (notebook:GPack.notebook) bind m ->
field_label#drag#source_set dnd_targets ~modi:[`BUTTON1] ~actions:[`COPY];
let data_get = fun _ (sel:GObj.selection_context) ~info ~time ->
let scale = ExtXml.attrib_or_default f "alt_unit_coef" "1" in
sel#return (sprintf "%s:%s:%s:%s:%s" sender class_name id field_name scale) in
let field_descr =
if Pprz.is_array_type type_ then
match GToolbox.input_string ~title:"Index of value to drag" ~text:"0" "Index in the array ?" with
None -> field_name
| Some i -> sprintf "%s[%s]" field_name i
else
field_name in
sel#return (sprintf "%s:%s:%s:%s:%s" sender class_name id field_descr scale) in
ignore (field_label#drag#connect#data_get ~callback:data_get);
(update, display_value)::rest
+2
View File
@@ -56,6 +56,8 @@ external int32_of_bytes : string -> int -> int32 = "c_int32_of_indexed_bytes"
val separator : string
(** Separator in array values *)
val is_array_type : string -> bool
val size_of_field : field -> int
val string_of_value : value -> string
val int_of_value : value -> int (* May raise Invalid_argument *)
+1 -1
View File
@@ -299,7 +299,7 @@ let default_window = {title="Plotter"; geometry=""; curves=[]}
(** [index_of_fields s] Returns i if s matches x[i] else 0. *)
let base_and_index =
let field_regexp = Str.regexp "\\([^\\.]+\\)\\.\\[\\([0-9]+\\)\\]" in
let field_regexp = Str.regexp "\\([^\\.]+\\)\\[\\([0-9]+\\)\\]" in
fun field_descr ->
if Str.string_match field_regexp field_descr 0 then
( Str.matched_group 1 field_descr,