| author | Christian Sternagel |
| Thu, 13 Dec 2012 13:11:38 +0100 | |
| changeset 50516 | ed6b40d15d1c |
| parent 50450 | 358b6020f8b6 |
| child 50715 | 8cfd585b9162 |
| permissions | -rw-r--r-- |
| 49561 | 1 |
(* Title: Pure/General/graph_display.ML |
2 |
Author: Makarius |
|
3 |
||
|
49565
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
4 |
Generic graph display, with browser and graphview backends. |
| 49561 | 5 |
*) |
6 |
||
7 |
signature GRAPH_DISPLAY = |
|
8 |
sig |
|
9 |
type node = |
|
10 |
{name: string, ID: string, dir: string, unfold: bool,
|
|
11 |
path: string, parents: string list, content: Pretty.T list} |
|
12 |
type graph = node list |
|
|
49565
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
13 |
val write_graph_browser: Path.T -> graph -> unit |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
14 |
val browserN: string |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
15 |
val graphviewN: string |
|
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
16 |
val graphview_reportN: string |
| 49561 | 17 |
val display_graph: graph -> unit |
18 |
end; |
|
19 |
||
20 |
structure Graph_Display: GRAPH_DISPLAY = |
|
21 |
struct |
|
22 |
||
23 |
(* external graph representation *) |
|
24 |
||
25 |
type node = |
|
26 |
{name: string, ID: string, dir: string, unfold: bool,
|
|
27 |
path: string, parents: string list, content: Pretty.T list}; |
|
28 |
||
29 |
type graph = node list; |
|
30 |
||
|
49565
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
31 |
|
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
32 |
(* print modes *) |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
33 |
|
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
34 |
val browserN = "browser"; |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
35 |
val graphviewN = "graphview"; |
|
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
36 |
val graphview_reportN = "graphview_report"; |
|
49565
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
37 |
|
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
38 |
fun write_graph_browser path (graph: graph) = |
| 49561 | 39 |
File.write path (cat_lines (map (fn {name, ID, dir, unfold, path, parents, ...} =>
|
40 |
"\"" ^ name ^ "\" \"" ^ ID ^ "\" \"" ^ dir ^ (if unfold then "\" + \"" else "\" \"") ^ |
|
41 |
path ^ "\" > " ^ space_implode " " (map quote parents) ^ " ;") graph)); |
|
42 |
||
43 |
||
|
49565
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
44 |
val encode_content = YXML.parse_body o Pretty.symbolic_string_of o Pretty.chunks; |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
45 |
|
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
46 |
fun encode_graphview (graph: graph) = |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
47 |
Graph.empty |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
48 |
|> fold (fn {ID, name, content, ...} => Graph.new_node (ID, (name, content))) graph
|
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
49 |
|> fold (fn {ID = a, parents = bs, ...} => fold (fn b => Graph.add_edge (b, a)) bs) graph
|
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
50 |
|> let open XML.Encode in Graph.encode string (pair string encode_content) end; |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
51 |
|
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
52 |
fun write_graph_graphview path graph = |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
53 |
File.write path (YXML.string_of_body (encode_graphview graph)); |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
54 |
|
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
55 |
|
| 49561 | 56 |
(* display graph *) |
57 |
||
58 |
fun display_graph graph = |
|
|
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
59 |
if print_mode_active graphview_reportN then |
|
50450
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50201
diff
changeset
|
60 |
let |
|
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50201
diff
changeset
|
61 |
val markup = Active.make_markup Markup.graphviewN {implicit = false, properties = []};
|
|
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50201
diff
changeset
|
62 |
val ((bg1, bg2), en) = YXML.output_markup_elem markup; |
|
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50201
diff
changeset
|
63 |
val graph_yxml = YXML.string_of_body (encode_graphview graph); |
|
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50201
diff
changeset
|
64 |
in writeln ("See " ^ bg1 ^ graph_yxml ^ bg2 ^ "graphview" ^ en) end
|
|
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
65 |
else |
|
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
66 |
let |
|
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
67 |
val browser = |
|
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
68 |
(case find_first (fn m => m = browserN orelse m = graphviewN) (print_mode_value ()) of |
|
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
69 |
SOME m => m = browserN |
|
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
70 |
| NONE => true); |
|
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
71 |
val (write, tool) = |
|
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
72 |
if browser then (write_graph_browser, "browser") |
|
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
73 |
else (write_graph_graphview, "graphview"); |
|
49565
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49561
diff
changeset
|
74 |
|
|
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
75 |
val _ = writeln "Displaying graph ..."; |
|
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
76 |
val path = Isabelle_System.create_tmp_path "graph" ""; |
|
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
77 |
val _ = write path graph; |
|
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
78 |
val _ = Isabelle_System.isabelle_tool tool ("-c " ^ File.shell_path path ^ " &");
|
|
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49565
diff
changeset
|
79 |
in () end; |
| 49561 | 80 |
|
81 |
end; |
|
82 |