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 =
53 ((Cic.id, Cic.term) Hashtbl.t *
54 (Cic.id, Cic.id option) Hashtbl.t *
55 (Cic.id, Cic.conjecture) Hashtbl.t *
56 (Cic.id, Cic.hypothesis) Hashtbl.t *
57 (Cic.id, string) Hashtbl.t *
58 (Cic.id, Cic2acic.anntypes) Hashtbl.t))
60 (* List utility functions *)
76 (* End of the list utility functions *)
78 (** A widget to render sequents **)
80 class sequent_viewer ~(mml_of_cic_sequent:mml_of_cic_sequent) obj =
83 inherit GMathViewAux.multi_selection_math_view obj
85 val mutable current_infos = None
87 (* returns the list of selected terms *)
88 (* selections which are not terms are ignored *)
89 method get_selected_terms =
90 debug_print (string_of_int (List.length self#get_selections)) ;
91 let selections = self#get_selections in
95 ((node : Gdome.element)#getAttributeNS
96 ~namespaceURI:Misc.helm_ns
97 ~localName:(Gdome.domString "xref"))#to_string
99 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
101 match current_infos with
102 Some (ids_to_terms,_,_) ->
105 Hashtbl.find ids_to_terms id
106 with _ -> raise Skip)
107 | None -> assert false (* "ERROR: No current term!!!" *)
110 (* returns the list of selected hypotheses *)
111 (* selections which are not hypotheses are ignored *)
112 method get_selected_hypotheses =
113 let selections = self#get_selections in
117 ((node : Gdome.element)#getAttributeNS
118 ~namespaceURI:Misc.helm_ns
119 ~localName:(Gdome.domString "xref"))#to_string
121 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
123 match current_infos with
124 Some (_,_,ids_to_hypotheses) ->
127 Hashtbl.find ids_to_hypotheses id
128 with _ -> raise Skip)
129 | None -> assert false (* "ERROR: No current term!!!" *)
132 method load_sequent metasenv sequent =
134 let sequent_mml,(_,(ids_to_terms,ids_to_father_ids,ids_to_hypotheses,ids_to_inner_sorts)) =
135 mml_of_cic_sequent metasenv sequent
137 self#load_root ~root:sequent_mml#get_documentElement ;
138 ignore (Misc.domImpl#saveDocumentToFile ~name:"/tmp/pippo" ~doc:sequent_mml ());
140 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
144 let sequent_viewer ~(mml_of_cic_sequent: mml_of_cic_sequent)
145 ?hadjustment ?vadjustment ?font_size ?log_verbosity
147 GtkBase.Widget.size_params ~cont:(
148 OgtkMathViewProps.pack_return
150 OgtkMathViewProps.set_params
151 (new sequent_viewer ~mml_of_cic_sequent
152 (GtkMathViewProps.MathView_GMetaDOM.create p))
153 ~font_size ~log_verbosity)) []
157 let sequent_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
158 ?border_width ?width ?height ?packing ?show () =
160 GtkMathView.MathView.create
161 ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
162 ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
165 GtkBase.Container.set w ?border_width ?width ?height;
166 let mathview = GObj.pack_return (new sequent_viewer w) ~packing ~show in
169 | Some size -> mathview#set_font_size size
173 match font_manager with
174 | Some manager -> mathview#set_font_manager_type ~fm_type:manager
181 (** A widget to render proofs **)
183 class proof_viewer ~(mml_of_cic_object:mml_of_cic_object) obj =
186 inherit GMathViewAux.single_selection_math_view obj
188 (* initializer self#set_font_size 10 *)
190 val mutable current_infos = None
191 val mutable current_mml = None
193 method make_sequent_of_selected_term =
194 match self#get_selection with
197 ((node : Gdome.element)#getAttributeNS
198 ~namespaceURI:Misc.helm_ns
199 ~localName:(Gdome.domString "xref"))#to_string
201 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
204 match current_infos with
205 Some (ids_to_terms, ids_to_father_ids, _, _) ->
207 LogicalOperations.to_sequent id ids_to_terms ids_to_father_ids
208 | None -> assert false (* "ERROR: No current term!!!" *)
210 | None -> assert false (* "ERROR: No selection!!!" *)
212 method focus_sequent_of_selected_term =
213 match self#get_selection with
216 ((node : Gdome.element)#getAttributeNS
217 ~namespaceURI:Misc.helm_ns
218 ~localName:(Gdome.domString "xref"))#to_string
220 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
223 match current_infos with
224 Some (ids_to_terms, ids_to_father_ids, _, _) ->
226 LogicalOperations.focus id ids_to_terms ids_to_father_ids
227 | None -> assert false (* "ERROR: No current term!!!" *)
229 | None -> assert false (* "ERROR: No selection!!!" *)
231 method load_proof currentproof =
234 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,
235 ids_to_hypotheses,ids_to_inner_sorts,ids_to_inner_types)) =
236 mml_of_cic_object currentproof
240 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses);
241 (* self#load_doc ~dom:mml ;
242 current_mml <- Some mml ; *)
243 ignore(Misc.domImpl#saveDocumentToFile ~name:"/tmp/prova" ~doc:mml ());
244 (match current_mml with
246 let time1 = Sys.time () in
247 self#load_root ~root:mml#get_documentElement ;
248 let time2 = Sys.time () in
249 debug_print ("Loading and displaying the proof took " ^
250 string_of_float (time2 -. time1) ^ "seconds") ;
251 current_mml <- Some mml
252 | Some current_mml' ->
254 let time1 = Sys.time () in
255 XmlDiff.update_dom ~from:current_mml' mml ;
256 let time2 = Sys.time () in
257 debug_print ("XMLDIFF took " ^
258 string_of_float (time2 -. time1) ^ "seconds") ;
260 let time3 = Sys.time () in
261 debug_print ("The refresh of the widget took " ^
262 string_of_float (time3 -. time2) ^ "seconds"));
263 (acic, ids_to_inner_types, ids_to_inner_sorts)
268 let proof_viewer ~(mml_of_cic_object: mml_of_cic_object)
269 ?hadjustment ?vadjustment ?font_size ?log_verbosity
271 GtkBase.Widget.size_params ~cont:(
272 OgtkMathViewProps.pack_return
274 OgtkMathViewProps.set_params
275 (new proof_viewer ~mml_of_cic_object
276 (GtkMathViewProps.MathView_GMetaDOM.create p))
277 ~font_size ~log_verbosity)) []
281 let proof_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
282 ?border_width ?width ?height ?packing ?show () =
284 GtkMathView.MathView.create
285 ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
286 ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
289 GtkBase.Container.set w ?border_width ?width ?height;
290 let mathview = GObj.pack_return (new proof_viewer w) ~packing ~show in
293 | Some size -> mathview#set_font_size size
297 match font_manager with
298 | Some manager -> mathview#set_font_manager_type ~fm_type:manager