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 (***************************************************************************)
39 (* List utility functions *)
55 (* End of the list utility functions *)
57 class sequent_viewer obj =
60 inherit GMathViewAux.multi_selection_math_view obj
62 val mutable current_infos = None
64 method get_selected_terms =
65 let selections = self#get_selections in
69 ((node : Gdome.element)#getAttributeNS
70 ~namespaceURI:Misc.helmns
71 ~localName:(Gdome.domString "xref"))#to_string
73 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
75 match current_infos with
76 Some (ids_to_terms,_,_) ->
79 Hashtbl.find ids_to_terms id
81 | None -> assert false (* "ERROR: No current term!!!" *)
84 method get_selected_hypotheses =
85 let selections = self#get_selections in
89 ((node : Gdome.element)#getAttributeNS
90 ~namespaceURI:Misc.helmns
91 ~localName:(Gdome.domString "xref"))#to_string
93 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
95 match current_infos with
96 Some (_,_,ids_to_hypotheses) ->
99 Hashtbl.find ids_to_hypotheses id
100 with _ -> raise Skip)
101 | None -> assert false (* "ERROR: No current term!!!" *)
104 method load_sequent (mml:Gdome.document)
105 (metadata:MatitaTypes.sequents_metadata) sequent_no
107 let (annconjecture, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts,
111 List.assoc sequent_no metadata
112 with Not_found -> assert false
114 current_infos <- Some (ids_to_terms, ids_to_father_ids, ids_to_hypotheses);
115 self#load_root ~root:mml#get_documentElement
118 class proof_viewer obj =
121 inherit GMathViewAux.single_selection_math_view obj
123 (* initializer self#set_log_verbosity 3 *)
125 val mutable current_infos = None
126 val mutable current_mml = None
128 method load_proof (mml:Gdome.document) (metadata:MatitaTypes.proof_metadata) =
129 let (acic, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts,
130 ids_to_inner_types, ids_to_conjectures, ids_to_hypotheses) =
135 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses);
136 match current_mml with
138 MatitaTypes.debug_print "no previous MathML";
139 self#load_root ~root:mml#get_documentElement ;
140 current_mml <- Some mml
141 | Some current_mml' ->
142 MatitaTypes.debug_print "Previous MathML available: xmldiffing ...";
144 XmlDiff.update_dom ~from:current_mml' mml ;
148 class sequents_viewer ~(notebook:GPack.notebook)
149 ~(sequent_viewer:MatitaTypes.sequent_viewer) ()
152 val mutable pages = 0
153 val mutable switch_page_callback = None
154 val mutable mathmls = []
155 val mutable metadata = None
156 val mutable page2goal = [] (* associative list: page no -> goal no *)
157 val mutable goal2page = [] (* the other way round *)
160 for i = 1 to pages do notebook#remove_page 0 done;
166 (match switch_page_callback with
168 GtkSignal.disconnect notebook#as_widget id;
169 switch_page_callback <- None
172 method load_sequents (metadata': MatitaTypes.sequents_metadata) =
173 metadata <- Some metadata';
174 let sequents = metadata' in
175 let sequents_no = List.length sequents in
176 debug_print (sprintf "sequents no: %d" sequents_no);
177 pages <- sequents_no;
178 let widget = sequent_viewer#coerce in
181 (fun (metano, (asequent, _, _, ids_to_inner_sorts, _)) ->
182 page2goal <- (!page, metano) :: page2goal;
183 goal2page <- (metano, !page) :: goal2page;
185 (GMisc.label ~text:(sprintf "?%d" metano) ~show:true ())#coerce
187 notebook#append_page ~tab_label widget;
189 (let content_sequent = Cic2content.map_sequent asequent in
191 Sequent2pres.sequent2pres ~ids_to_inner_sorts content_sequent
193 let xmlpres = Box.document_of_box pres_sequent in
194 Xml2Gdome.document_of_xml Misc.domImpl xmlpres)
196 mathmls <- (metano, mathml) :: mathmls)
198 mathmls <- List.rev mathmls;
199 switch_page_callback <-
200 (* TODO Zack the "#after" may probably be removed after Luca's fix for
201 * widget not loading documents before being realized *)
202 Some (notebook#connect#after#switch_page ~callback:(fun page ->
203 debug_print "switch_page callback";
204 self#render_page page))
206 method goto_sequent goal =
209 List.assoc goal goal2page
210 with Not_found -> assert false
212 notebook#goto_page page;
213 self#render_page page
215 method private render_page page =
217 match metadata with Some metadata -> metadata | None -> assert false
219 let (metano, mathml) = List.nth mathmls page in
220 sequent_viewer#load_sequent (Lazy.force mathml) metadata metano
226 let sequent_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
227 GtkBase.Widget.size_params
228 ~cont:(OgtkMathViewProps.pack_return (fun p ->
229 OgtkMathViewProps.set_params
230 (new sequent_viewer (GtkMathViewProps.MathView_GMetaDOM.create p))
231 ~font_size ~log_verbosity))
234 let proof_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
235 GtkBase.Widget.size_params
236 ~cont:(OgtkMathViewProps.pack_return (fun p ->
237 OgtkMathViewProps.set_params
238 (new proof_viewer (GtkMathViewProps.MathView_GMetaDOM.create p))
239 ~font_size ~log_verbosity))
242 let sequents_viewer ~(notebook:GPack.notebook)
243 ~(sequent_viewer:MatitaTypes.sequent_viewer) ()
245 new sequents_viewer ~notebook ~sequent_viewer ()