1
(* Some useful function to use the graphical representation of a slicing
2
* project. (see tests/slicing/anim.ml for a test) *)
3
(*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
6
if (Unix.WEXITED 0) = Unix.system ("which dot > /dev/null 2>&1") then
10
(* function to append [string_of_int n] on 3 char to basename. *)
11
let nth_name basename n =
13
let str_n = string_of_int n in
14
let str_n = if n < 100 then ("0"^str_n) else str_n in
15
let str_n = if n < 10 then ("0"^str_n) else str_n in
19
(* generate the nth .jpg file (generate to .dot file and then remove it) *)
20
let print_proj basename title proj n =
21
let name = nth_name basename n in
22
let dot_name = (name^".dot") in
23
let jpg_name = (name^".jpg") in
24
!Db.Slicing.Project.print_dot ~filename:dot_name ~title:title proj;
26
ignore (Sys.command ("dot -Tjpg -o "^jpg_name^" "^dot_name^" 2>/dev/null"));
31
(* apply all requests of the project and generate a .jpg file for each step.
32
* (begin at number [n])
34
let build_all_graphs basename title proj first_n =
35
Format.printf "Processing %s : " basename;
39
!Db.Slicing.Request.apply_next_internal proj;
40
let title = title^" ("^(string_of_int (n - first_n))^")" in
41
let n = print_proj basename title proj n in
45
let next_num = next first_n in Format.printf "\n"; next_num
48
let all_files basename = basename^".*.jpg ";;
49
let display_cmd basename = "display -resize 1000x500 "^(all_files basename);;
50
let clean_cmd basename = "rm -f "^(all_files basename);;
51
let build_anim_cmd basename=
52
"convert -delay 10 -loop 1 "^(all_files basename)^" "^basename^".gif";;
54
let print_help basename =
55
let display_cmd = display_cmd basename in
56
let clean_cmd = clean_cmd basename in
57
Format.printf "To display '%s' use :\n\t%s\n" basename display_cmd;
58
Format.printf "\t- use : Space/Backspace to see next/previous step\n";
59
Format.printf "\t- use : 'q' to quit\n@\n";
61
"After that, you can clear the generated files with:\n\t%s\n" clean_cmd
63
let remove_all_files basename =
64
Format.printf "removing generated .jpg files\n";
65
ignore (Sys.command (clean_cmd basename))
67
(*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)