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 true;;(* 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 let selections = self#get_selections in
72 ((node : Gdome.element)#getAttributeNS
73 ~namespaceURI:Misc.helmns
74 ~localName:(Gdome.domString "xref"))#to_string
76 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
78 match current_infos with
79 Some (ids_to_terms,_,_) ->
82 Hashtbl.find ids_to_terms id
84 | None -> assert false (* "ERROR: No current term!!!" *)
87 (* returns the list of selected hypotheses *)
88 (* selections which are not hypotheses are ignored *)
89 method get_selected_hypotheses =
90 let selections = self#get_selections in
94 ((node : Gdome.element)#getAttributeNS
95 ~namespaceURI:Misc.helmns
96 ~localName:(Gdome.domString "xref"))#to_string
98 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
100 match current_infos with
101 Some (_,_,ids_to_hypotheses) ->
104 Hashtbl.find ids_to_hypotheses id
105 with _ -> raise Skip)
106 | None -> assert false (* "ERROR: No current term!!!" *)
109 method load_sequent metasenv sequent =
110 let sequent_mml,(ids_to_terms,ids_to_father_ids,ids_to_hypotheses) =
111 ApplyStylesheets.mml_of_cic_sequent metasenv sequent
113 self#load_doc ~dom:sequent_mml ;
115 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
119 let sequent_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
120 ?border_width ?width ?height ?packing ?show () =
122 GtkMathView.MathView.create
123 ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
124 ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
127 GtkBase.Container.set w ?border_width ?width ?height;
128 let mathview = GObj.pack_return (new sequent_viewer w) ~packing ~show in
131 | Some size -> mathview#set_font_size size
135 match font_manager with
136 | Some manager -> mathview#set_font_manager_type ~fm_type:manager
143 (** A widget to render proofs **)
145 class proof_viewer obj =
148 inherit GMathViewAux.single_selection_math_view obj
150 initializer self#set_font_size 10
152 val mutable current_infos = None
153 val mutable current_mml = None
155 method make_sequent_of_selected_term =
156 match self#get_selection with
159 ((node : Gdome.element)#getAttributeNS
160 ~namespaceURI:Misc.helmns
161 ~localName:(Gdome.domString "xref"))#to_string
163 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
166 match current_infos with
167 Some (ids_to_terms, ids_to_father_ids, _, _) ->
169 LogicalOperations.to_sequent id ids_to_terms ids_to_father_ids
170 | None -> assert false (* "ERROR: No current term!!!" *)
172 | None -> assert false (* "ERROR: No selection!!!" *)
174 method focus_sequent_of_selected_term =
175 match self#get_selection with
178 ((node : Gdome.element)#getAttributeNS
179 ~namespaceURI:Misc.helmns
180 ~localName:(Gdome.domString "xref"))#to_string
182 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
185 match current_infos with
186 Some (ids_to_terms, ids_to_father_ids, _, _) ->
188 LogicalOperations.focus id ids_to_terms ids_to_father_ids
189 | None -> assert false (* "ERROR: No current term!!!" *)
191 | None -> assert false (* "ERROR: No selection!!!" *)
193 method load_omdoc_proof uri ~ids_to_inner_sorts cobj =
194 if !use_stylesheets then
196 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
197 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
199 Cic2acic.acic_object_of_cic_object (Content2cic.cobj2obj cobj)
201 prerr_endline "0000000000000000 USO GLI STYLESHEETS" ;
203 ApplyStylesheets.mml_of_cic_object
204 ~explode_all:true uri acic ids_to_inner_sorts ids_to_inner_types
206 (match current_mml with
208 prerr_endline "0000000000000000 CARICO L'mml PRODOTTO" ;
209 self#load_doc ~dom:mml ;
210 current_mml <- Some mml
211 | Some current_mml ->
213 XmlDiff.update_dom ~from:current_mml mml ;
216 self#load_doc ~dom:mml ;
217 current_mml <- Some mml ;
221 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses) ;
223 let pres = Content2pres.content2pres ~ids_to_inner_sorts cobj in
224 let time2 = Sys.time () in
225 (* prerr_endline ("Fine trasformazione:" ^ (string_of_float (time2 -. time1))); *)
226 let xmlpres = Mpresentation.print_mpres pres in
227 let time25 = Sys.time () in
228 prerr_endline "(******** INIZIO CONTENT ==> PRES **********)";
230 prerr_endline ("FINE printing to stream:" ^ (string_of_float (time25 -. time2)));
231 Xml.pp xmlpres (Some "tmp");
232 let time3 = Sys.time () in
233 prerr_endline ("FINE valutazione e printing dello stream:" ^ (string_of_float (time3 -. time25)));
236 prerr_endline "(******** INIZIO DOM **********)";
237 let mml = Xml2Gdome.document_of_xml Misc.domImpl xmlpres in
238 let time3 = Sys.time () in
239 (* ignore (Misc.domImpl#saveDocumentToFile mml "tmp1" ()); *)
240 prerr_endline "(******** FINE DOM **********)";
241 (match current_mml with
243 self#load_doc ~dom:mml ;
244 current_mml <- Some mml
245 | Some current_mml ->
247 prerr_endline "XML_DIFF: prima passata";
249 ignore (Misc.domImpl#saveDocumentToFile current_mml "/tmp/current_mml_1.xml" ()) ;
250 ignore (Misc.domImpl#saveDocumentToFile mml "/tmp/mml_1.xml" ()) ;
252 XmlDiff.update_dom ~from:current_mml mml ;
254 prerr_endline "XML_DIFF: seconda passata";
255 ignore (Misc.domImpl#saveDocumentToFile current_mml "/tmp/current_mml_2.xml" ()) ;
256 ignore (Misc.domImpl#saveDocumentToFile mml "/tmp/mml_2.xml" ()) ;
257 XmlDiff.update_dom ~from:current_mml mml ;
258 ignore (Misc.domImpl#saveDocumentToFile current_mml "/tmp/current_mml_3.xml" ()) ;
259 ignore (Misc.domImpl#saveDocumentToFile mml "/tmp/mml_3.xml" ()) ;
261 prerr_endline "XML_DIFF: fine passate";
264 self#load_doc ~dom: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)
276 method load_proof uri currentproof =
278 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
279 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
281 Cic2acic.acic_object_of_cic_object currentproof
284 ApplyStylesheets.mml_of_cic_object
285 ~explode_all:true uri acic ids_to_inner_sorts ids_to_inner_types
287 self#load_doc ~dom:mml ;
288 current_mml <- Some mml ;
291 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses) ;
292 (acic, ids_to_inner_types, ids_to_inner_sorts)
296 let proof_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
297 ?border_width ?width ?height ?packing ?show () =
299 GtkMathView.MathView.create
300 ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
301 ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
304 GtkBase.Container.set w ?border_width ?width ?height;
305 let mathview = GObj.pack_return (new proof_viewer w) ~packing ~show in
308 | Some size -> mathview#set_font_size size
312 match font_manager with
313 | Some manager -> mathview#set_font_manager_type ~fm_type:manager
320 Cexpr2pres_hashtbl.init Cexpr2pres.cexpr2pres Cexpr2pres.cexpr2pres_charcount