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 *)
54 val mutable current_infos = None
55 val mutable current_mathml = None
57 method load_proof ((uri_opt, _, _, _) as proof, (goal_opt: int option)) =
58 let (annobj, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts,
59 ids_to_inner_types, ids_to_conjectures, ids_to_hypotheses) =
60 Cic2acic.acic_object_of_cic_object (cicCurrentProof proof)
62 current_infos <- Some (ids_to_terms, ids_to_father_ids, ids_to_conjectures,
65 ApplyTransformation.mml_of_cic_object ~explode_all:true
66 (unopt_uri uri_opt) annobj ids_to_inner_sorts ids_to_inner_types
68 match current_mathml with
70 debug_print "no previous MathML";
71 self#load_root ~root:mathml#get_documentElement ;
72 current_mathml <- Some mathml
73 | Some current_mathml ->
74 debug_print "Previous MathML available: xmldiffing ...";
76 XmlDiff.update_dom ~from:current_mathml mathml ;
80 class sequent_viewer obj =
83 inherit GMathViewAux.multi_selection_math_view obj
85 val mutable current_infos = None
87 method get_selected_terms =
88 let selections = self#get_selections in
92 ((node : Gdome.element)#getAttributeNS
93 ~namespaceURI:Misc.helmns
94 ~localName:(Gdome.domString "xref"))#to_string
96 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
98 match current_infos with
99 Some (ids_to_terms,_,_) ->
102 Hashtbl.find ids_to_terms id
103 with _ -> raise Skip)
104 | None -> assert false (* "ERROR: No current term!!!" *)
107 method get_selected_hypotheses =
108 let selections = self#get_selections in
112 ((node : Gdome.element)#getAttributeNS
113 ~namespaceURI:Misc.helmns
114 ~localName:(Gdome.domString "xref"))#to_string
116 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
118 match current_infos with
119 Some (_,_,ids_to_hypotheses) ->
122 Hashtbl.find ids_to_hypotheses id
123 with _ -> raise Skip)
124 | None -> assert false (* "ERROR: No current term!!!" *)
127 method load_sequent metasenv metano =
129 let (annconjecture, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts,
131 Cic2acic.asequent_of_sequent metasenv conjecture
134 let sequent = CicUtil.lookup_meta metano metasenv in
135 let (mathml, (ids_to_terms, ids_to_father_ids, ids_to_hypotheses)) =
136 ApplyTransformation.mml_of_cic_sequent metasenv sequent
138 current_infos <- Some (ids_to_terms, ids_to_father_ids, ids_to_hypotheses);
139 debug_print "load_sequent: dumping MathML to /tmp/prova";
140 ignore (Misc.domImpl#saveDocumentToFile ~name:"/tmp/prova" ~doc:mathml ());
141 self#load_root ~root:mathml#get_documentElement
145 class sequents_viewer ~(notebook:GPack.notebook)
146 ~(sequent_viewer:MatitaTypes.sequent_viewer) ~set_goal ()
149 val mutable pages = 0
150 val mutable switch_page_callback = None
151 val mutable page2goal = [] (* associative list: page no -> goal no *)
152 val mutable goal2page = [] (* the other way round *)
153 val mutable _metasenv = []
156 for i = 1 to pages do notebook#remove_page 0 done;
161 (match switch_page_callback with
163 GtkSignal.disconnect notebook#as_widget id;
164 switch_page_callback <- None
167 method load_sequents metasenv =
168 let sequents_no = List.length metasenv in
169 _metasenv <- metasenv;
170 debug_print (sprintf "sequents no: %d" sequents_no);
171 pages <- sequents_no;
172 let widget = sequent_viewer#coerce in
175 (fun (metano, _, _) ->
176 page2goal <- (!page, metano) :: page2goal;
177 goal2page <- (metano, !page) :: goal2page;
180 (GMisc.label ~text:(sprintf "?%d" metano) ~show:true ())#coerce
182 notebook#append_page ~tab_label widget)
184 switch_page_callback <-
185 (* TODO Zack the "#after" may probably be removed after Luca's fix for
186 * widget not loading documents before being realized *)
187 Some (notebook#connect#after#switch_page ~callback:(fun page ->
188 debug_print "switch_page callback";
191 List.assoc page page2goal
192 with Not_found -> assert false
195 self#render_page goal))
197 method private render_page goal =
198 sequent_viewer#load_sequent _metasenv goal
200 method goto_sequent goal =
203 List.assoc goal goal2page
204 with Not_found -> assert false
206 notebook#goto_page page;
207 self#render_page goal
213 let sequent_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
214 GtkBase.Widget.size_params
215 ~cont:(OgtkMathViewProps.pack_return (fun p ->
216 OgtkMathViewProps.set_params
217 (new sequent_viewer (GtkMathViewProps.MathView_GMetaDOM.create p))
218 ~font_size ~log_verbosity))
221 let proof_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 proof_viewer (GtkMathViewProps.MathView_GMetaDOM.create p))
226 ~font_size ~log_verbosity))
229 let sequents_viewer ~(notebook:GPack.notebook)
230 ~(sequent_viewer:MatitaTypes.sequent_viewer) ~set_goal ()
232 new sequents_viewer ~notebook ~sequent_viewer ~set_goal ()