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 prerr_endline "PRIMA DI SALVARE IL FILE" ;
131 self#load_root ~root:sequent_mml#get_documentElement ;
132 prerr_endline "SALVO IL FILE IN TEMP" ;
133 ignore (Misc.domImpl#saveDocumentToFile ~name:"/tmp/pippo" ~doc:sequent_mml ());
135 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
139 let sequent_viewer ~(mml_of_cic_sequent: mml_of_cic_sequent)
140 ?hadjustment ?vadjustment ?font_size ?log_verbosity
142 GtkBase.Widget.size_params ~cont:(
143 OgtkMathViewProps.pack_return
145 OgtkMathViewProps.set_params
146 (new sequent_viewer ~mml_of_cic_sequent
147 (GtkMathViewProps.MathView_GMetaDOM.create p))
148 ~font_size ~log_verbosity)) []
152 let sequent_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
153 ?border_width ?width ?height ?packing ?show () =
155 GtkMathView.MathView.create
156 ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
157 ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
160 GtkBase.Container.set w ?border_width ?width ?height;
161 let mathview = GObj.pack_return (new sequent_viewer w) ~packing ~show in
164 | Some size -> mathview#set_font_size size
168 match font_manager with
169 | Some manager -> mathview#set_font_manager_type ~fm_type:manager
176 (** A widget to render proofs **)
178 class proof_viewer ~(mml_of_cic_object:mml_of_cic_object) obj =
181 inherit GMathViewAux.single_selection_math_view obj
183 (* initializer self#set_font_size 10 *)
185 val mutable current_infos = None
186 val mutable current_mml = None
188 method make_sequent_of_selected_term =
189 match self#get_selection with
192 ((node : Gdome.element)#getAttributeNS
193 ~namespaceURI:Misc.helmns
194 ~localName:(Gdome.domString "xref"))#to_string
196 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
199 match current_infos with
200 Some (ids_to_terms, ids_to_father_ids, _, _) ->
202 LogicalOperations.to_sequent id ids_to_terms ids_to_father_ids
203 | None -> assert false (* "ERROR: No current term!!!" *)
205 | None -> assert false (* "ERROR: No selection!!!" *)
207 method focus_sequent_of_selected_term =
208 match self#get_selection with
211 ((node : Gdome.element)#getAttributeNS
212 ~namespaceURI:Misc.helmns
213 ~localName:(Gdome.domString "xref"))#to_string
215 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
218 match current_infos with
219 Some (ids_to_terms, ids_to_father_ids, _, _) ->
221 LogicalOperations.focus id ids_to_terms ids_to_father_ids
222 | None -> assert false (* "ERROR: No current term!!!" *)
224 | None -> assert false (* "ERROR: No selection!!!" *)
226 method load_proof uri currentproof =
228 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
229 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
230 = Cic2acic.acic_object_of_cic_object currentproof
234 ~explode_all:true uri acic ids_to_inner_sorts ids_to_inner_types
238 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses);
239 (* self#load_doc ~dom:mml ;
240 current_mml <- Some mml ; *)
241 ignore(Misc.domImpl#saveDocumentToFile ~name:"/tmp/prova" ~doc:mml ());
242 (match current_mml with
244 let time1 = Sys.time () in
245 self#load_root ~root:mml#get_documentElement ;
246 let time2 = Sys.time () in
247 debug_print ("Loading and displaying the proof took " ^
248 string_of_float (time2 -. time1) ^ "seconds") ;
249 current_mml <- Some mml
250 | Some current_mml' ->
252 let time1 = Sys.time () in
253 XmlDiff.update_dom ~from:current_mml' mml ;
254 let time2 = Sys.time () in
255 debug_print ("XMLDIFF took " ^
256 string_of_float (time2 -. time1) ^ "seconds") ;
258 let time3 = Sys.time () in
259 debug_print ("The refresh of the widget took " ^
260 string_of_float (time3 -. time2) ^ "seconds"));
261 (acic, ids_to_inner_types, ids_to_inner_sorts)
266 let proof_viewer ~(mml_of_cic_object: mml_of_cic_object)
267 ?hadjustment ?vadjustment ?font_size ?log_verbosity
269 GtkBase.Widget.size_params ~cont:(
270 OgtkMathViewProps.pack_return
272 OgtkMathViewProps.set_params
273 (new proof_viewer ~mml_of_cic_object
274 (GtkMathViewProps.MathView_GMetaDOM.create p))
275 ~font_size ~log_verbosity)) []
279 let proof_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
280 ?border_width ?width ?height ?packing ?show () =
282 GtkMathView.MathView.create
283 ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
284 ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
287 GtkBase.Container.set w ?border_width ?width ?height;
288 let mathview = GObj.pack_return (new proof_viewer w) ~packing ~show in
291 | Some size -> mathview#set_font_size size
295 match font_manager with
296 | Some manager -> mathview#set_font_manager_type ~fm_type:manager