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, _, _, _) ->
58 prerr_endline (gdome_elt#get_nodeName#to_string);
59 ignore (self#action_toggle gdome_elt)
62 val mutable current_infos = None
63 val mutable current_mathml = None
65 method load_proof ((uri_opt, _, _, _) as proof, (goal_opt: int option)) =
66 let (annobj, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts,
67 ids_to_inner_types, ids_to_conjectures, ids_to_hypotheses) =
68 Cic2acic.acic_object_of_cic_object (cicCurrentProof proof)
70 current_infos <- Some (ids_to_terms, ids_to_father_ids, ids_to_conjectures,
73 ApplyTransformation.mml_of_cic_object ~explode_all:true
74 (unopt_uri uri_opt) annobj ids_to_inner_sorts ids_to_inner_types
76 debug_print "load_proof: dumping MathML to /tmp/proof";
77 ignore (Misc.domImpl#saveDocumentToFile ~name:"/tmp/proof" ~doc:mathml ());
78 match current_mathml with
80 debug_print "no previous MathML";
81 self#load_root ~root:mathml#get_documentElement ;
82 current_mathml <- Some mathml
83 | Some current_mathml ->
84 debug_print "Previous MathML available: xmldiffing ...";
86 XmlDiff.update_dom ~from:current_mathml mathml ;
90 class sequent_viewer obj =
93 inherit GMathViewAux.multi_selection_math_view obj
95 val mutable current_infos = None
97 method get_selected_terms =
98 let selections = self#get_selections in
102 ((node : Gdome.element)#getAttributeNS
103 ~namespaceURI:Misc.helmns
104 ~localName:(Gdome.domString "xref"))#to_string
106 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
108 match current_infos with
109 Some (ids_to_terms,_,_) ->
112 Hashtbl.find ids_to_terms id
113 with _ -> raise Skip)
114 | None -> assert false (* "ERROR: No current term!!!" *)
117 method get_selected_hypotheses =
118 let selections = self#get_selections in
122 ((node : Gdome.element)#getAttributeNS
123 ~namespaceURI:Misc.helmns
124 ~localName:(Gdome.domString "xref"))#to_string
126 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
128 match current_infos with
129 Some (_,_,ids_to_hypotheses) ->
132 Hashtbl.find ids_to_hypotheses id
133 with _ -> raise Skip)
134 | None -> assert false (* "ERROR: No current term!!!" *)
137 method load_sequent metasenv metano =
139 let (annconjecture, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts,
141 Cic2acic.asequent_of_sequent metasenv conjecture
144 let sequent = CicUtil.lookup_meta metano metasenv in
145 let (mathml, (ids_to_terms, ids_to_father_ids, ids_to_hypotheses)) =
146 ApplyTransformation.mml_of_cic_sequent metasenv sequent
148 current_infos <- Some (ids_to_terms, ids_to_father_ids, ids_to_hypotheses);
149 debug_print "load_sequent: dumping MathML to /tmp/prova";
150 ignore (Misc.domImpl#saveDocumentToFile ~name:"/tmp/prova" ~doc:mathml ());
151 self#load_root ~root:mathml#get_documentElement
155 class sequents_viewer ~(notebook:GPack.notebook)
156 ~(sequent_viewer:MatitaTypes.sequent_viewer) ~set_goal ()
159 val mutable pages = 0
160 val mutable switch_page_callback = None
161 val mutable page2goal = [] (* associative list: page no -> goal no *)
162 val mutable goal2page = [] (* the other way round *)
163 val mutable _metasenv = []
166 for i = 1 to pages do notebook#remove_page 0 done;
171 (match switch_page_callback with
173 GtkSignal.disconnect notebook#as_widget id;
174 switch_page_callback <- None
177 method load_sequents metasenv =
178 let sequents_no = List.length metasenv in
179 _metasenv <- metasenv;
180 debug_print (sprintf "sequents no: %d" sequents_no);
181 pages <- sequents_no;
182 let widget = sequent_viewer#coerce in
185 (fun (metano, _, _) ->
186 page2goal <- (!page, metano) :: page2goal;
187 goal2page <- (metano, !page) :: goal2page;
190 (GMisc.label ~text:(sprintf "?%d" metano) ~show:true ())#coerce
192 notebook#append_page ~tab_label widget)
194 switch_page_callback <-
195 (* TODO Zack the "#after" may probably be removed after Luca's fix for
196 * widget not loading documents before being realized *)
197 Some (notebook#connect#after#switch_page ~callback:(fun page ->
198 debug_print "switch_page callback";
201 List.assoc page page2goal
202 with Not_found -> assert false
205 self#render_page goal))
207 method private render_page goal =
208 sequent_viewer#load_sequent _metasenv goal
210 method goto_sequent goal =
213 List.assoc goal goal2page
214 with Not_found -> assert false
216 notebook#goto_page page;
217 self#render_page goal
223 let sequent_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
224 GtkBase.Widget.size_params
225 ~cont:(OgtkMathViewProps.pack_return (fun p ->
226 OgtkMathViewProps.set_params
227 (new sequent_viewer (GtkMathViewProps.MathView_GMetaDOM.create p))
228 ~font_size ~log_verbosity))
231 let proof_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
232 GtkBase.Widget.size_params
233 ~cont:(OgtkMathViewProps.pack_return (fun p ->
234 OgtkMathViewProps.set_params
235 (new proof_viewer (GtkMathViewProps.MathView_GMetaDOM.create p))
236 ~font_size ~log_verbosity))
239 let sequents_viewer ~(notebook:GPack.notebook)
240 ~(sequent_viewer:MatitaTypes.sequent_viewer) ~set_goal ()
242 new sequents_viewer ~notebook ~sequent_viewer ~set_goal ()