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 (***************************************************************************)
35 let use_stylesheets = ref false;;(* false performs the transformations in OCaml*)
37 (* List utility functions *)
53 (* End of the list utility functions *)
55 (** A widget to render sequents **)
57 class sequent_viewer obj =
60 inherit GMathViewAux.multi_selection_math_view obj
62 val mutable current_infos = None
64 (* returns the list of selected terms *)
65 (* selections which are not terms are ignored *)
66 method get_selected_terms =
67 prerr_endline (string_of_int (List.length self#get_selections)) ;
68 let selections = self#get_selections in
72 ((node : Gdome.element)#getAttributeNS
73 ~namespaceURI:Misc.helmns
74 ~localName:(Gdome.domString "xref"))#to_string
76 prerr_endline ("YAHHHHHHHHHH " ^ xpath) ;
77 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
79 match current_infos with
80 Some (ids_to_terms,_,_) ->
83 Hashtbl.find ids_to_terms id
85 | None -> assert false (* "ERROR: No current term!!!" *)
88 (* returns the list of selected hypotheses *)
89 (* selections which are not hypotheses are ignored *)
90 method get_selected_hypotheses =
91 let selections = self#get_selections in
95 ((node : Gdome.element)#getAttributeNS
96 ~namespaceURI:Misc.helmns
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_hypotheses) ->
105 Hashtbl.find ids_to_hypotheses id
106 with _ -> raise Skip)
107 | None -> assert false (* "ERROR: No current term!!!" *)
110 method load_sequent metasenv sequent =
112 let sequent_mml,(ids_to_terms,ids_to_father_ids,ids_to_hypotheses) =
113 if !use_stylesheets then
114 ApplyStylesheets.mml_of_cic_sequent metasenv sequent
116 ApplyTransformation.mml_of_cic_sequent metasenv sequent
118 self#load_doc ~dom:sequent_mml ;
120 Misc.domImpl#saveDocumentToFile ~name:"/tmp/pippo" ~doc:sequent_mml () ;
123 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
127 let sequent_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
128 GtkBase.Container.make_params ~cont:(
129 OgtkMathViewProps.pack_return
130 (fun p -> OgtkMathViewProps.set_params (new sequent_viewer (GtkMathViewProps.MathView.create p)) ~font_size ~log_verbosity)) []
134 let sequent_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
135 ?border_width ?width ?height ?packing ?show () =
137 GtkMathView.MathView.create
138 ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
139 ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
142 GtkBase.Container.set w ?border_width ?width ?height;
143 let mathview = GObj.pack_return (new sequent_viewer w) ~packing ~show in
146 | Some size -> mathview#set_font_size size
150 match font_manager with
151 | Some manager -> mathview#set_font_manager_type ~fm_type:manager
158 (** A widget to render proofs **)
160 class proof_viewer obj =
163 inherit GMathViewAux.single_selection_math_view obj
165 (* initializer self#set_font_size 10 *)
167 val mutable current_infos = None
168 val mutable current_mml = None
170 method make_sequent_of_selected_term =
171 match self#get_selection with
174 ((node : Gdome.element)#getAttributeNS
175 ~namespaceURI:Misc.helmns
176 ~localName:(Gdome.domString "xref"))#to_string
178 prerr_endline ("YAEEEEEEEEEEEEEEEEEEE " ^ xpath) ;
179 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
182 match current_infos with
183 Some (ids_to_terms, ids_to_father_ids, _, _) ->
185 LogicalOperations.to_sequent id ids_to_terms ids_to_father_ids
186 | None -> assert false (* "ERROR: No current term!!!" *)
188 | None -> assert false (* "ERROR: No selection!!!" *)
190 method focus_sequent_of_selected_term =
191 match self#get_selection with
194 ((node : Gdome.element)#getAttributeNS
195 ~namespaceURI:Misc.helmns
196 ~localName:(Gdome.domString "xref"))#to_string
198 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
201 match current_infos with
202 Some (ids_to_terms, ids_to_father_ids, _, _) ->
204 LogicalOperations.focus id ids_to_terms ids_to_father_ids
205 | None -> assert false (* "ERROR: No current term!!!" *)
207 | None -> assert false (* "ERROR: No selection!!!" *)
209 method load_proof uri currentproof =
211 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
212 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
213 = Cic2acic.acic_object_of_cic_object currentproof
216 if !use_stylesheets then
217 ApplyStylesheets.mml_of_cic_object
218 ~explode_all:true uri acic ids_to_inner_sorts ids_to_inner_types
220 ApplyTransformation.mml_of_cic_object
221 ~explode_all:true uri acic ids_to_inner_sorts ids_to_inner_types in
224 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses);
225 (* self#load_doc ~dom:mml ;
226 current_mml <- Some mml ; *)
227 (match current_mml with
229 let time1 = Sys.time () in
230 self#load_doc ~dom:mml ;
231 let time2 = Sys.time () in
232 prerr_endline ("Loading and displaying the proof took " ^ string_of_float (time2 -. time1) ^ "seconds") ;
233 current_mml <- Some mml
234 | Some current_mml' ->
236 let time1 = Sys.time () in
237 XmlDiff.update_dom ~from:current_mml' mml ;
238 let time2 = Sys.time () in
239 prerr_endline ("XMLDIFF took " ^ string_of_float (time2 -. time1) ^ "seconds") ;
241 let time3 = Sys.time () in
242 prerr_endline ("The refresh of the widget took " ^ string_of_float (time3 -. time2) ^ "seconds"));
243 (acic, ids_to_inner_types, ids_to_inner_sorts)
248 let proof_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
249 GtkBase.Container.make_params ~cont:(
250 OgtkMathViewProps.pack_return
251 (fun p -> OgtkMathViewProps.set_params (new proof_viewer (GtkMathViewProps.MathView.create p)) ~font_size ~log_verbosity)) []
255 let proof_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
256 ?border_width ?width ?height ?packing ?show () =
258 GtkMathView.MathView.create
259 ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
260 ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
263 GtkBase.Container.set w ?border_width ?width ?height;
264 let mathview = GObj.pack_return (new proof_viewer w) ~packing ~show in
267 | Some size -> mathview#set_font_size size
271 match font_manager with
272 | Some manager -> mathview#set_font_manager_type ~fm_type:manager
280 Cexpr2pres_hashtbl.init Cexpr2pres.cexpr2pres Cexpr2pres.cexpr2pres_charcount