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 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
34 (******************************************************************************)
36 let use_stylesheets = ref false;;(* false performs the transformations in OCaml*)
38 (* List utility functions *)
54 (* End of the list utility functions *)
56 (** A widget to render sequents **)
58 class sequent_viewer obj =
61 inherit GMathViewAux.multi_selection_math_view obj
63 val mutable current_infos = None
65 (* returns the list of selected terms *)
66 (* selections which are not terms are ignored *)
67 method get_selected_terms =
68 prerr_endline (string_of_int (List.length self#get_selections)) ;
69 let selections = self#get_selections in
73 ((node : Gdome.element)#getAttributeNS
74 ~namespaceURI:Misc.helmns
75 ~localName:(Gdome.domString "xref"))#to_string
77 prerr_endline ("YAHHHHHHHHHH " ^ xpath) ;
78 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
80 match current_infos with
81 Some (ids_to_terms,_,_) ->
84 Hashtbl.find ids_to_terms id
86 | None -> assert false (* "ERROR: No current term!!!" *)
89 (* returns the list of selected hypotheses *)
90 (* selections which are not hypotheses are ignored *)
91 method get_selected_hypotheses =
92 let selections = self#get_selections in
96 ((node : Gdome.element)#getAttributeNS
97 ~namespaceURI:Misc.helmns
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_hypotheses) ->
106 Hashtbl.find ids_to_hypotheses id
107 with _ -> raise Skip)
108 | None -> assert false (* "ERROR: No current term!!!" *)
111 method load_sequent metasenv sequent =
112 let sequent_mml,(ids_to_terms,ids_to_father_ids,ids_to_hypotheses) =
113 ApplyStylesheets.mml_of_cic_sequent metasenv sequent
115 self#load_doc ~dom:sequent_mml ;
116 Misc.domImpl#saveDocumentToFile ~name:"/tmp/pippo" ~doc:sequent_mml () ;
118 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
122 let sequent_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
123 GtkBase.Container.make_params ~cont:(
124 OgtkMathViewProps.pack_return
125 (fun p -> OgtkMathViewProps.set_params (new sequent_viewer (GtkMathViewProps.MathView.create p)) ~font_size ~log_verbosity)) []
129 let sequent_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
130 ?border_width ?width ?height ?packing ?show () =
132 GtkMathView.MathView.create
133 ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
134 ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
137 GtkBase.Container.set w ?border_width ?width ?height;
138 let mathview = GObj.pack_return (new sequent_viewer w) ~packing ~show in
141 | Some size -> mathview#set_font_size size
145 match font_manager with
146 | Some manager -> mathview#set_font_manager_type ~fm_type:manager
153 (** A widget to render proofs **)
155 class proof_viewer obj =
158 inherit GMathViewAux.single_selection_math_view obj
160 (* initializer self#set_font_size 10 *)
162 val mutable current_infos = None
163 val mutable current_mml = None
165 method make_sequent_of_selected_term =
166 match self#get_selection with
169 ((node : Gdome.element)#getAttributeNS
170 ~namespaceURI:Misc.helmns
171 ~localName:(Gdome.domString "xref"))#to_string
173 prerr_endline ("YAEEEEEEEEEEEEEEEEEEE " ^ xpath) ;
174 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
177 match current_infos with
178 Some (ids_to_terms, ids_to_father_ids, _, _) ->
180 LogicalOperations.to_sequent id ids_to_terms ids_to_father_ids
181 | None -> assert false (* "ERROR: No current term!!!" *)
183 | None -> assert false (* "ERROR: No selection!!!" *)
185 method focus_sequent_of_selected_term =
186 match self#get_selection with
189 ((node : Gdome.element)#getAttributeNS
190 ~namespaceURI:Misc.helmns
191 ~localName:(Gdome.domString "xref"))#to_string
193 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
196 match current_infos with
197 Some (ids_to_terms, ids_to_father_ids, _, _) ->
199 LogicalOperations.focus id ids_to_terms ids_to_father_ids
200 | None -> assert false (* "ERROR: No current term!!!" *)
202 | None -> assert false (* "ERROR: No selection!!!" *)
204 method load_proof uri currentproof =
206 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
207 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
209 Cic2acic.acic_object_of_cic_object currentproof
211 if !use_stylesheets then
213 ApplyStylesheets.mml_of_cic_object
214 ~explode_all:true uri acic ids_to_inner_sorts ids_to_inner_types
216 self#load_doc ~dom:mml ;
217 current_mml <- Some mml ;
220 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses) ;
223 Cic.ACurrentProof (id,idbody,n,conjectures,bo,ty,params) ->
224 let time1 = Sys.time () in
226 Cic2content.annobj2content
227 ~ids_to_inner_sorts ~ids_to_inner_types acic in
228 let pres = Content2pres.content2pres ~ids_to_inner_sorts content in
229 let time2 = Sys.time () in
230 (* prerr_endline ("Fine trasformazione:" ^ (string_of_float (time2 -. time1))); *)
231 let xmlpres = Mpresentation.print_mpres pres in
232 let time25 = Sys.time () in
234 prerr_endline ("FINE printing to stream:" ^ (string_of_float (time25 -. time2)));
235 Xml.pp xmlpres (Some "tmp");
236 let time3 = Sys.time () in
237 prerr_endline ("FINE valutazione e printing dello stream:" ^ (string_of_float (time3 -. time25)));
240 prerr_endline "(******** INIZIO DOM **********)";
241 let mml = Xml2Gdome.document_of_xml Misc.domImpl xmlpres in
242 let time3 = Sys.time () in
243 (* ignore (Misc.domImpl#saveDocumentToFile mml "tmp1" ()); *)
244 prerr_endline "(******** FINE DOM **********)";
245 (match current_mml with
247 let time1 = Sys.time () in
248 self#load_doc ~dom:mml ;
249 let time2 = Sys.time () in
250 prerr_endline ("Loading and displaying the proof took " ^ 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 prerr_endline ("XMLDIFF took " ^ string_of_float (time2 -. time1) ^ "seconds") ;
259 let time3 = Sys.time () in
260 prerr_endline ("The refresh of the widget took " ^ string_of_float (time3 -. time2) ^ "seconds")
263 self#load_doc ~dom:mml ;
264 current_mml <- Some mml ;
266 prerr_endline ("Fine loading:" ^ (string_of_float (time3 -. time2)))
269 let time4 = Sys.time () in
271 ("Fine loading:" ^ (string_of_float (time4 -. time3)))
273 with (GdomeInit.DOMException (_,s)) as e ->
274 prerr_endline s; raise e)
275 | _ -> assert false);
276 (acic, ids_to_inner_types, ids_to_inner_sorts)
280 let proof_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
281 GtkBase.Container.make_params ~cont:(
282 OgtkMathViewProps.pack_return
283 (fun p -> OgtkMathViewProps.set_params (new proof_viewer (GtkMathViewProps.MathView.create p)) ~font_size ~log_verbosity)) []
287 let proof_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
288 ?border_width ?width ?height ?packing ?show () =
290 GtkMathView.MathView.create
291 ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
292 ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
295 GtkBase.Container.set w ?border_width ?width ?height;
296 let mathview = GObj.pack_return (new proof_viewer w) ~packing ~show in
299 | Some size -> mathview#set_font_size size
303 match font_manager with
304 | Some manager -> mathview#set_font_manager_type ~fm_type:manager
312 Cexpr2pres_hashtbl.init Cexpr2pres.cexpr2pres Cexpr2pres.cexpr2pres_charcount