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/.
31 (* List utility functions *)
47 class proof_viewer obj =
50 inherit GMathViewAux.single_selection_math_view obj
52 (* initializer self#set_log_verbosity 3 *)
55 ignore (self#connect#click (fun (gdome_elt, _, _, _) ->
57 | Some gdome_elt -> ignore (self#action_toggle gdome_elt)
60 val mutable current_infos = None
61 val mutable current_mathml = None
63 method load_proof ((uri_opt, _, _, _) as proof, (goal_opt: int option)) =
64 let (annobj, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts,
65 ids_to_inner_types, ids_to_conjectures, ids_to_hypotheses) =
66 Cic2acic.acic_object_of_cic_object (cicCurrentProof proof)
68 current_infos <- Some (ids_to_terms, ids_to_father_ids, ids_to_conjectures,
71 ApplyTransformation.mml_of_cic_object ~explode_all:true
72 (unopt_uri uri_opt) annobj ids_to_inner_sorts ids_to_inner_types
74 debug_print "load_proof: dumping MathML to /tmp/proof";
75 ignore (Misc.domImpl#saveDocumentToFile ~name:"/tmp/proof" ~doc:mathml ());
76 match current_mathml with
78 debug_print "no previous MathML";
79 self#load_root ~root:mathml#get_documentElement ;
80 current_mathml <- Some mathml
81 | Some current_mathml ->
82 debug_print "Previous MathML available: xmldiffing ...";
84 XmlDiff.update_dom ~from:current_mathml mathml ;
88 class sequent_viewer obj =
91 inherit GMathViewAux.multi_selection_math_view obj
93 val mutable current_infos = None
95 method get_selected_terms =
96 let selections = self#get_selections in
100 ((node : Gdome.element)#getAttributeNS
101 ~namespaceURI:Misc.helmns
102 ~localName:(Gdome.domString "xref"))#to_string
104 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
106 match current_infos with
107 Some (ids_to_terms,_,_) ->
110 Hashtbl.find ids_to_terms id
111 with _ -> raise Skip)
112 | None -> assert false (* "ERROR: No current term!!!" *)
115 method get_selected_hypotheses =
116 let selections = self#get_selections in
120 ((node : Gdome.element)#getAttributeNS
121 ~namespaceURI:Misc.helmns
122 ~localName:(Gdome.domString "xref"))#to_string
124 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
126 match current_infos with
127 Some (_,_,ids_to_hypotheses) ->
130 Hashtbl.find ids_to_hypotheses id
131 with _ -> raise Skip)
132 | None -> assert false (* "ERROR: No current term!!!" *)
135 method load_sequent metasenv metano =
137 let (annconjecture, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts,
139 Cic2acic.asequent_of_sequent metasenv conjecture
142 let sequent = CicUtil.lookup_meta metano metasenv in
143 let (mathml, (ids_to_terms, ids_to_father_ids, ids_to_hypotheses)) =
144 ApplyTransformation.mml_of_cic_sequent metasenv sequent
146 current_infos <- Some (ids_to_terms, ids_to_father_ids, ids_to_hypotheses);
147 debug_print "load_sequent: dumping MathML to /tmp/prova";
148 ignore (Misc.domImpl#saveDocumentToFile ~name:"/tmp/prova" ~doc:mathml ());
149 self#load_root ~root:mathml#get_documentElement
153 class sequents_viewer ~(notebook:GPack.notebook)
154 ~(sequent_viewer:MatitaTypes.sequent_viewer) ~set_goal ()
157 val mutable pages = 0
158 val mutable switch_page_callback = None
159 val mutable page2goal = [] (* associative list: page no -> goal no *)
160 val mutable goal2page = [] (* the other way round *)
161 val mutable _metasenv = []
164 for i = 1 to pages do notebook#remove_page 0 done;
169 (match switch_page_callback with
171 GtkSignal.disconnect notebook#as_widget id;
172 switch_page_callback <- None
175 method load_sequents metasenv =
176 let sequents_no = List.length metasenv in
177 _metasenv <- metasenv;
178 debug_print (sprintf "sequents no: %d" sequents_no);
179 pages <- sequents_no;
180 let widget = sequent_viewer#coerce in
183 (fun (metano, _, _) ->
184 page2goal <- (!page, metano) :: page2goal;
185 goal2page <- (metano, !page) :: goal2page;
188 (GMisc.label ~text:(sprintf "?%d" metano) ~show:true ())#coerce
190 notebook#append_page ~tab_label widget)
192 switch_page_callback <-
193 (* TODO Zack the "#after" may probably be removed after Luca's fix for
194 * widget not loading documents before being realized *)
195 Some (notebook#connect#after#switch_page ~callback:(fun page ->
196 debug_print "switch_page callback";
199 List.assoc page page2goal
200 with Not_found -> assert false
203 self#render_page goal))
205 method private render_page goal =
206 sequent_viewer#load_sequent _metasenv goal
208 method goto_sequent goal =
211 List.assoc goal goal2page
212 with Not_found -> assert false
214 notebook#goto_page page;
215 self#render_page goal
221 let sequent_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
222 GtkBase.Widget.size_params
223 ~cont:(OgtkMathViewProps.pack_return (fun p ->
224 OgtkMathViewProps.set_params
225 (new sequent_viewer (GtkMathViewProps.MathView_GMetaDOM.create p))
226 ~font_size ~log_verbosity))
229 let proof_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
230 GtkBase.Widget.size_params
231 ~cont:(OgtkMathViewProps.pack_return (fun p ->
232 OgtkMathViewProps.set_params
233 (new proof_viewer (GtkMathViewProps.MathView_GMetaDOM.create p))
234 ~font_size ~log_verbosity))
237 let sequents_viewer ~(notebook:GPack.notebook)
238 ~(sequent_viewer:MatitaTypes.sequent_viewer) ~set_goal ()
240 new sequents_viewer ~notebook ~sequent_viewer ~set_goal ()