1 (* Copyright (C) 2003, HELM Team.
4 * This file is part of HELM, an Hypertextual, Electronic
5 * Library of Mathematics, developed at the Computer Science
6 * Department, University of Bologna, Italy.
8 * HELM is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * HELM is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with HELM; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 * For details, see the HELM World-Wide-Web page,
24 * http://cs.unibo.it/helm/.
28 Cic.context * (int * Cic.term * bool * int * (int * Cic.term) list) list *
29 (int * Cic.term * int) list *
31 let fake_goal = Cic.Implicit None;;
32 let fake_candidates = [];;
39 ProofEngineReduction.replace
40 ~equality:(fun a b -> match b with Cic.Meta _ -> true | _ -> false)
41 ~what:[Cic.Rel 1] ~with_what:[Cic.Implicit None] ~where:t
43 ApplyTransformation.txt_of_cic_term ~map_unicode_to_tex:false
46 let pp_goal context x =
47 if x == fake_goal then "" else pp context x
49 let pp_candidate context x = pp context x
51 let sublist start len l =
52 let rec aux pos len = function
53 | [] when pos < start -> aux (pos+1) len []
55 (0,fake_goal, false, 0, fake_candidates) :: aux (pos+1) (len-1) []
56 | [] (* when len <= 0 *) -> []
57 | he::tl when pos < start -> aux (pos+1) len tl
58 | he::tl when pos >= start && len > 0 -> he::aux (pos+1) (len-1) tl
59 | he::tl (* when pos >= start && len <= 0 *) -> []
64 let cell_of_candidate height context ?(active=false) g id c =
65 let tooltip = GData.tooltips () in (* should be only one isn't it? *)
68 ~label:(pp_candidate context c(* ^ " - " ^ string_of_int id*))
71 button#misc#set_size_request ~height ();
73 button#misc#set_sensitive false;
75 "Follow computation of "^pp_candidate context c^" on "^pp_goal context g
77 tooltip#set_tip ~text (button :> GObj.widget);
78 ignore(button#connect#clicked
80 let menu = GMenu.menu () in
81 let follow = GMenu.menu_item ~label:"Follow" () in
82 let prune = GMenu.menu_item ~label:"Prune" () in
83 ignore (follow#connect#activate
84 (fun _ -> HLog.warn (string_of_int id); Auto.give_hint id));
85 ignore (prune#connect#activate
86 (fun _ -> HLog.warn (string_of_int id); Auto.give_prune_hint id));
89 menu#popup 0 (GtkMain.Main.get_current_event_time ())));
92 let cell_of_goal height win_width context goal =
94 ~markup:(pp_goal context goal) ~xalign:0.0
95 ~width:(min (win_width * 60 / 100) 500)
101 let cell_of_row_header height n k id =
103 ~markup:("<span stretch=\"ultracondensed\">" ^ string_of_int n ^ "<sub>(" ^
104 string_of_int id ^ "|" ^ string_of_int k ^ ")</sub></span>")
105 ~line_wrap:true ~justify:`LEFT ~height ~width:80 ()
107 let cell_of_candidates height grey context goal cads =
108 let hbox = GPack.hbox () in
113 (cell_of_candidate height ~active:grey
114 context goal id c :> GObj.widget);
117 hbox#pack (cell_of_candidate height context goal id c :> GObj.widget)) tl;
121 let elems_to_rows height context win_width (table : GPack.table) (or_list) =
122 let height = height / ((List.length or_list) + 1) in
125 (fun position (goal_id, goal, grey, depth, candidates) ->
126 table#attach ~left:0 ~top:position
127 (cell_of_row_header height (position + !start)
128 depth goal_id :> GObj.widget);
129 table#attach ~left:1 ~top:position ~fill:`BOTH
130 (cell_of_goal height win_width context goal :> GObj.widget);
131 table#attach ~left:2 ~top:position
132 (cell_of_candidates height grey context goal candidates :> GObj.widget);
139 let old_displayed_status = ref [];;
140 let old_size = ref 0;;
142 let fill_win (win : MatitaGeneratedGui.autoWin) cb =
143 let init = Unix.gettimeofday () in
145 let (status : status) = cb () in
146 let win_size = win#toplevel#misc#allocation.Gtk.width in
147 let ctx, or_list, and_list, last_moves = status in
148 let displayed_status =
150 (or_list @ (List.map (fun (id,x,d) -> id,x,false,d,[]) and_list))
152 if displayed_status <> !old_displayed_status || !old_size <> win_size then
154 old_displayed_status := displayed_status;
155 old_size := win_size;
156 win#labelLAST#set_text
157 (String.concat ";" (List.map (pp_candidate ctx) last_moves));
158 List.iter win#table#remove win#table#children;
159 let height = win#viewportAREA#misc#allocation.Gtk.height in
160 elems_to_rows height ctx win_size win#table displayed_status;
162 "REDRAW COST: %2.1f\n%!" (Unix.gettimeofday () -. init);
164 with exn -> prerr_endline (Printexc.to_string exn); ()
167 let auto_dialog elems =
168 let win = new MatitaGeneratedGui.autoWin () in
169 let width = Gdk.Screen.width () in
170 let height = Gdk.Screen.height () in
171 let main_w = width * 70 / 100 in
172 let main_h = height * 60 / 100 in
173 win#toplevel#resize ~width:main_w ~height:main_h;
174 win#check_widgets ();
175 win#table#set_columns 3;
176 win#table#set_col_spacings 6;
177 win#table#set_row_spacings 4;
178 ignore(win#buttonUP#connect#clicked
179 (fun _ -> start := max 0 (!start -1); fill_win win elems));
180 ignore(win#buttonDOWN#connect#clicked
181 (fun _ -> incr start; fill_win win elems));
182 ignore(win#buttonCLOSE#connect#clicked
186 win#toplevel#destroy ();
187 GMain.Main.quit ()));
188 ignore(win#toplevel#event#connect#delete
192 win#toplevel#destroy ();
193 GMain.Main.quit ();true));
194 let redraw_callback _ = fill_win win elems;true in
195 let redraw = GMain.Timeout.add ~ms:400 ~callback:redraw_callback in
196 ignore(win#buttonPAUSE#connect#clicked
199 win#buttonPLAY#misc#set_sensitive true;
200 win#buttonPAUSE#misc#set_sensitive false;));
201 ignore(win#buttonPLAY#connect#clicked
205 win#buttonPLAY#misc#set_sensitive false;
206 win#buttonPAUSE#misc#set_sensitive true;));
207 ignore(win#buttonNEXT#connect#clicked
208 (fun _ -> Auto.step ()));
210 win#buttonPLAY#misc#set_sensitive true;
211 win#buttonPAUSE#misc#set_sensitive false;
213 win#toplevel#show ();
215 GMain.Timeout.remove redraw;