1 (* Copyright (C) 2000-2002, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (***************************************************************************)
30 (* 29/01/2003 Claudio Sacerdoti Coen *)
33 (***************************************************************************)
36 let debug_print s = if debug then prerr_endline s
38 type mml_of_cic_sequent =
40 int * Cic.context * Cic.term ->
43 ((Cic.id, Cic.term) Hashtbl.t *
44 (Cic.id, Cic.id option) Hashtbl.t *
45 (string, Cic.hypothesis) Hashtbl.t *
46 (Cic.id, string) Hashtbl.t))
49 type mml_of_cic_object =
54 ((Cic.id, Cic.term) Hashtbl.t *
55 (Cic.id, Cic.id option) Hashtbl.t *
56 (Cic.id, Cic.conjecture) Hashtbl.t *
57 (Cic.id, Cic.hypothesis) Hashtbl.t *
58 (Cic.id, string) Hashtbl.t *
59 (Cic.id, Cic2acic.anntypes) Hashtbl.t))
61 (* List utility functions *)
77 (* End of the list utility functions *)
79 (** A widget to render sequents **)
81 class sequent_viewer ~(mml_of_cic_sequent:mml_of_cic_sequent) obj =
84 inherit GMathViewAux.multi_selection_math_view obj
86 val mutable current_infos = None
88 (* returns the list of selected terms *)
89 (* selections which are not terms are ignored *)
90 method get_selected_terms =
91 debug_print (string_of_int (List.length self#get_selections)) ;
92 let selections = self#get_selections in
96 ((node : Gdome.element)#getAttributeNS
97 ~namespaceURI:Misc.helm_ns
98 ~localName:(Gdome.domString "xref"))#to_string
100 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
102 match current_infos with
103 Some (ids_to_terms,_,_) ->
106 Hashtbl.find ids_to_terms id
107 with _ -> raise Skip)
108 | None -> assert false (* "ERROR: No current term!!!" *)
111 (* returns the list of selected hypotheses *)
112 (* selections which are not hypotheses are ignored *)
113 method get_selected_hypotheses =
114 let selections = self#get_selections in
118 ((node : Gdome.element)#getAttributeNS
119 ~namespaceURI:Misc.helm_ns
120 ~localName:(Gdome.domString "xref"))#to_string
122 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
124 match current_infos with
125 Some (_,_,ids_to_hypotheses) ->
128 Hashtbl.find ids_to_hypotheses id
129 with _ -> raise Skip)
130 | None -> assert false (* "ERROR: No current term!!!" *)
133 method load_sequent metasenv sequent =
135 let sequent_mml,(_,(ids_to_terms,ids_to_father_ids,ids_to_hypotheses,ids_to_inner_sorts)) =
136 mml_of_cic_sequent metasenv sequent
138 self#load_root ~root:sequent_mml#get_documentElement ;
139 ignore (Misc.domImpl#saveDocumentToFile ~name:"/tmp/pippo" ~doc:sequent_mml ());
141 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
145 let sequent_viewer ~(mml_of_cic_sequent: mml_of_cic_sequent)
146 ?hadjustment ?vadjustment ?font_size ?log_verbosity
148 GtkBase.Widget.size_params ~cont:(
149 OgtkMathViewProps.pack_return
151 OgtkMathViewProps.set_params
152 (new sequent_viewer ~mml_of_cic_sequent
153 (GtkMathViewProps.MathView_GMetaDOM.create p))
154 ~font_size ~log_verbosity)) []
158 let sequent_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
159 ?border_width ?width ?height ?packing ?show () =
161 GtkMathView.MathView.create
162 ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
163 ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
166 GtkBase.Container.set w ?border_width ?width ?height;
167 let mathview = GObj.pack_return (new sequent_viewer w) ~packing ~show in
170 | Some size -> mathview#set_font_size size
174 match font_manager with
175 | Some manager -> mathview#set_font_manager_type ~fm_type:manager
182 (** A widget to render proofs **)
184 class proof_viewer ~(mml_of_cic_object:mml_of_cic_object) obj =
187 inherit GMathViewAux.single_selection_math_view obj
189 (* initializer self#set_font_size 10 *)
191 val mutable current_infos = None
192 val mutable current_mml = None
194 method make_sequent_of_selected_term =
195 match self#get_selection with
198 ((node : Gdome.element)#getAttributeNS
199 ~namespaceURI:Misc.helm_ns
200 ~localName:(Gdome.domString "xref"))#to_string
202 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
205 match current_infos with
206 Some (ids_to_terms, ids_to_father_ids, _, _) ->
208 LogicalOperations.to_sequent id ids_to_terms ids_to_father_ids
209 | None -> assert false (* "ERROR: No current term!!!" *)
211 | None -> assert false (* "ERROR: No selection!!!" *)
213 method focus_sequent_of_selected_term =
214 match self#get_selection with
217 ((node : Gdome.element)#getAttributeNS
218 ~namespaceURI:Misc.helm_ns
219 ~localName:(Gdome.domString "xref"))#to_string
221 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
224 match current_infos with
225 Some (ids_to_terms, ids_to_father_ids, _, _) ->
227 LogicalOperations.focus id ids_to_terms ids_to_father_ids
228 | None -> assert false (* "ERROR: No current term!!!" *)
230 | None -> assert false (* "ERROR: No selection!!!" *)
232 method load_proof uri currentproof =
235 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,
236 ids_to_hypotheses,ids_to_inner_sorts,ids_to_inner_types)) =
237 mml_of_cic_object uri currentproof
241 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses);
242 (* self#load_doc ~dom:mml ;
243 current_mml <- Some mml ; *)
244 ignore(Misc.domImpl#saveDocumentToFile ~name:"/tmp/prova" ~doc:mml ());
245 (match current_mml with
247 let time1 = Sys.time () in
248 self#load_root ~root:mml#get_documentElement ;
249 let time2 = Sys.time () in
250 debug_print ("Loading and displaying the proof took " ^
251 string_of_float (time2 -. time1) ^ "seconds") ;
252 current_mml <- Some mml
253 | Some current_mml' ->
255 let time1 = Sys.time () in
256 XmlDiff.update_dom ~from:current_mml' mml ;
257 let time2 = Sys.time () in
258 debug_print ("XMLDIFF took " ^
259 string_of_float (time2 -. time1) ^ "seconds") ;
261 let time3 = Sys.time () in
262 debug_print ("The refresh of the widget took " ^
263 string_of_float (time3 -. time2) ^ "seconds"));
264 (acic, ids_to_inner_types, ids_to_inner_sorts)
269 let proof_viewer ~(mml_of_cic_object: mml_of_cic_object)
270 ?hadjustment ?vadjustment ?font_size ?log_verbosity
272 GtkBase.Widget.size_params ~cont:(
273 OgtkMathViewProps.pack_return
275 OgtkMathViewProps.set_params
276 (new proof_viewer ~mml_of_cic_object
277 (GtkMathViewProps.MathView_GMetaDOM.create p))
278 ~font_size ~log_verbosity)) []
282 let proof_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
283 ?border_width ?width ?height ?packing ?show () =
285 GtkMathView.MathView.create
286 ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
287 ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
290 GtkBase.Container.set w ?border_width ?width ?height;
291 let mathview = GObj.pack_return (new proof_viewer w) ~packing ~show in
294 | Some size -> mathview#set_font_size size
298 match font_manager with
299 | Some manager -> mathview#set_font_manager_type ~fm_type:manager