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 ->
42 ((Cic.id, Cic.term) Hashtbl.t *
43 (Cic.id, Cic.id option) Hashtbl.t *
44 (string, Cic.hypothesis) Hashtbl.t)
46 type mml_of_cic_object =
50 (string, string) Hashtbl.t ->
51 (string, Cic2acic.anntypes) Hashtbl.t -> Gdome.document
53 (* List utility functions *)
69 (* End of the list utility functions *)
71 (** A widget to render sequents **)
73 class sequent_viewer ~(mml_of_cic_sequent:mml_of_cic_sequent) obj =
76 inherit GMathViewAux.multi_selection_math_view obj
78 val mutable current_infos = None
80 (* returns the list of selected terms *)
81 (* selections which are not terms are ignored *)
82 method get_selected_terms =
83 debug_print (string_of_int (List.length self#get_selections)) ;
84 let selections = self#get_selections in
88 ((node : Gdome.element)#getAttributeNS
89 ~namespaceURI:Misc.helmns
90 ~localName:(Gdome.domString "xref"))#to_string
92 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
94 match current_infos with
95 Some (ids_to_terms,_,_) ->
98 Hashtbl.find ids_to_terms id
100 | None -> assert false (* "ERROR: No current term!!!" *)
103 (* returns the list of selected hypotheses *)
104 (* selections which are not hypotheses are ignored *)
105 method get_selected_hypotheses =
106 let selections = self#get_selections in
110 ((node : Gdome.element)#getAttributeNS
111 ~namespaceURI:Misc.helmns
112 ~localName:(Gdome.domString "xref"))#to_string
114 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
116 match current_infos with
117 Some (_,_,ids_to_hypotheses) ->
120 Hashtbl.find ids_to_hypotheses id
121 with _ -> raise Skip)
122 | None -> assert false (* "ERROR: No current term!!!" *)
125 method load_sequent metasenv sequent =
127 let sequent_mml,(ids_to_terms,ids_to_father_ids,ids_to_hypotheses) =
128 mml_of_cic_sequent metasenv sequent
130 self#load_root ~root:sequent_mml#get_documentElement ;
131 ignore (Misc.domImpl#saveDocumentToFile ~name:"/tmp/pippo" ~doc:sequent_mml ());
133 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
137 let sequent_viewer ~(mml_of_cic_sequent: mml_of_cic_sequent)
138 ?hadjustment ?vadjustment ?font_size ?log_verbosity
140 GtkBase.Widget.size_params ~cont:(
141 OgtkMathViewProps.pack_return
143 OgtkMathViewProps.set_params
144 (new sequent_viewer ~mml_of_cic_sequent
145 (GtkMathViewProps.MathView_GMetaDOM.create p))
146 ~font_size ~log_verbosity)) []
150 let sequent_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
151 ?border_width ?width ?height ?packing ?show () =
153 GtkMathView.MathView.create
154 ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
155 ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
158 GtkBase.Container.set w ?border_width ?width ?height;
159 let mathview = GObj.pack_return (new sequent_viewer w) ~packing ~show in
162 | Some size -> mathview#set_font_size size
166 match font_manager with
167 | Some manager -> mathview#set_font_manager_type ~fm_type:manager
174 (** A widget to render proofs **)
176 class proof_viewer ~(mml_of_cic_object:mml_of_cic_object) obj =
179 inherit GMathViewAux.single_selection_math_view obj
181 (* initializer self#set_font_size 10 *)
183 val mutable current_infos = None
184 val mutable current_mml = None
186 method make_sequent_of_selected_term =
187 match self#get_selection with
190 ((node : Gdome.element)#getAttributeNS
191 ~namespaceURI:Misc.helmns
192 ~localName:(Gdome.domString "xref"))#to_string
194 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
197 match current_infos with
198 Some (ids_to_terms, ids_to_father_ids, _, _) ->
200 LogicalOperations.to_sequent id ids_to_terms ids_to_father_ids
201 | None -> assert false (* "ERROR: No current term!!!" *)
203 | None -> assert false (* "ERROR: No selection!!!" *)
205 method focus_sequent_of_selected_term =
206 match self#get_selection with
209 ((node : Gdome.element)#getAttributeNS
210 ~namespaceURI:Misc.helmns
211 ~localName:(Gdome.domString "xref"))#to_string
213 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
216 match current_infos with
217 Some (ids_to_terms, ids_to_father_ids, _, _) ->
219 LogicalOperations.focus id ids_to_terms ids_to_father_ids
220 | None -> assert false (* "ERROR: No current term!!!" *)
222 | None -> assert false (* "ERROR: No selection!!!" *)
224 method load_proof uri currentproof =
226 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
227 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
228 = Cic2acic.acic_object_of_cic_object currentproof
232 ~explode_all:true uri acic ids_to_inner_sorts ids_to_inner_types
236 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses);
237 (* self#load_doc ~dom:mml ;
238 current_mml <- Some mml ; *)
239 ignore(Misc.domImpl#saveDocumentToFile ~name:"/tmp/prova" ~doc:mml ());
240 (match current_mml with
242 let time1 = Sys.time () in
243 self#load_root ~root:mml#get_documentElement ;
244 let time2 = Sys.time () in
245 debug_print ("Loading and displaying the proof took " ^
246 string_of_float (time2 -. time1) ^ "seconds") ;
247 current_mml <- Some mml
248 | Some current_mml' ->
250 let time1 = Sys.time () in
251 XmlDiff.update_dom ~from:current_mml' mml ;
252 let time2 = Sys.time () in
253 debug_print ("XMLDIFF took " ^
254 string_of_float (time2 -. time1) ^ "seconds") ;
256 let time3 = Sys.time () in
257 debug_print ("The refresh of the widget took " ^
258 string_of_float (time3 -. time2) ^ "seconds"));
259 (acic, ids_to_inner_types, ids_to_inner_sorts)
264 let proof_viewer ~(mml_of_cic_object: mml_of_cic_object)
265 ?hadjustment ?vadjustment ?font_size ?log_verbosity
267 GtkBase.Widget.size_params ~cont:(
268 OgtkMathViewProps.pack_return
270 OgtkMathViewProps.set_params
271 (new proof_viewer ~mml_of_cic_object
272 (GtkMathViewProps.MathView_GMetaDOM.create p))
273 ~font_size ~log_verbosity)) []
277 let proof_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
278 ?border_width ?width ?height ?packing ?show () =
280 GtkMathView.MathView.create
281 ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
282 ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
285 GtkBase.Container.set w ?border_width ?width ?height;
286 let mathview = GObj.pack_return (new proof_viewer w) ~packing ~show in
289 | Some size -> mathview#set_font_size size
293 match font_manager with
294 | Some manager -> mathview#set_font_manager_type ~fm_type:manager