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 clickable_math_view obj =
48 let href = Gdome.domString "href" in
49 let xref = Gdome.domString "xref" in
51 inherit GMathViewAux.multi_selection_math_view obj
53 val mutable href_callback: (UriManager.uri -> unit) option = None
54 method set_href_callback f = href_callback <- f
57 ignore (self#connect#selection_changed self#choose_selection);
58 ignore (self#connect#click (fun (gdome_elt, _, _, _) ->
60 | Some elt (* element is an hyperlink, use href_callback on it *)
61 when elt#hasAttributeNS ~namespaceURI:Misc.xlink_ns ~localName:href ->
62 (match href_callback with
66 elt#getAttributeNS ~namespaceURI:Misc.xlink_ns ~localName:href
68 f (UriManager.uri_of_string (uri#to_string)))
69 | Some elt -> ignore (self#action_toggle elt)
71 method private choose_selection gdome_elt =
73 if elt#hasAttributeNS ~namespaceURI:Misc.helm_ns ~localName:xref then
74 self#set_selection (Some elt)
77 (match elt#get_parentNode with
78 | None -> assert false
79 | Some p -> aux (new Gdome.element_of_node p))
80 with GdomeInit.DOMCastException _ -> ()
81 (* debug_print "trying to select above the document root" *)
85 | None -> self#set_selection None
88 let clickable_math_view =
89 GtkBase.Widget.size_params
90 ~cont:(OgtkMathViewProps.pack_return (fun p ->
91 OgtkMathViewProps.set_params
92 (new clickable_math_view (GtkMathViewProps.MathView_GMetaDOM.create p))
93 ~font_size:None ~log_verbosity:None))
95 let clickable_math_view () = clickable_math_view ()
97 class proof_viewer obj =
100 inherit clickable_math_view obj
102 val mutable current_infos = None
103 val mutable current_mathml = None
105 method load_proof ((uri_opt, _, _, _) as proof, (goal_opt: int option)) =
106 let uri = unopt_uri uri_opt in
107 let obj = cicCurrentProof proof in
108 let (mathml, (_,(ids_to_terms, ids_to_father_ids, ids_to_conjectures,
109 ids_to_hypotheses,_,_))) =
110 ApplyTransformation.mml_of_cic_object uri obj
112 current_infos <- Some (ids_to_terms, ids_to_father_ids,
113 ids_to_conjectures, ids_to_hypotheses);
114 debug_print "load_proof: dumping MathML to ./proof";
115 ignore (Misc.domImpl#saveDocumentToFile ~name:"./proof" ~doc:mathml ());
116 match current_mathml with
118 self#load_root ~root:mathml#get_documentElement ;
119 current_mathml <- Some mathml
120 | Some current_mathml ->
122 XmlDiff.update_dom ~from:current_mathml mathml ;
126 class sequent_viewer obj =
129 inherit clickable_math_view obj
131 val mutable current_infos = None
133 method get_selected_terms =
134 let selections = self#get_selections in
138 ((node : Gdome.element)#getAttributeNS
139 ~namespaceURI:Misc.helm_ns
140 ~localName:(Gdome.domString "xref"))#to_string
142 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
144 match current_infos with
145 | Some (ids_to_terms,_,_) ->
147 Hashtbl.find ids_to_terms xpath
148 with _ -> raise Skip)
149 | None -> assert false) (* "ERROR: No current term!!!" *)
152 method get_selected_hypotheses =
153 let selections = self#get_selections in
157 ((node : Gdome.element)#getAttributeNS
158 ~namespaceURI:Misc.helm_ns
159 ~localName:(Gdome.domString "xref"))#to_string
161 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
163 match current_infos with
164 | Some (_,_,ids_to_hypotheses) ->
166 Hashtbl.find ids_to_hypotheses xpath
167 with _ -> raise Skip)
168 | None -> assert false) (* "ERROR: No current term!!!" *)
171 method load_sequent metasenv metano =
173 let (annconjecture, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts,
175 Cic2acic.asequent_of_sequent metasenv conjecture
178 let sequent = CicUtil.lookup_meta metano metasenv in
179 let (mathml,(_,(ids_to_terms, ids_to_father_ids, ids_to_hypotheses,_))) =
180 ApplyTransformation.mml_of_cic_sequent metasenv sequent
182 current_infos <- Some (ids_to_terms, ids_to_father_ids, ids_to_hypotheses);
183 debug_print "load_sequent: dumping MathML to ./prova";
184 ignore (Misc.domImpl#saveDocumentToFile ~name:"./prova" ~doc:mathml ());
185 self#load_root ~root:mathml#get_documentElement
189 class sequents_viewer ~(notebook:GPack.notebook)
190 ~(sequent_viewer:sequent_viewer) ~set_goal ()
192 let tab_label metano =
193 (GMisc.label ~text:(sprintf "?%d" metano) ~show:true ())#coerce
196 val mutable pages = 0
197 val mutable switch_page_callback = None
198 val mutable page2goal = [] (* associative list: page no -> goal no *)
199 val mutable goal2page = [] (* the other way round *)
200 val mutable goal2win = [] (* associative list: goal no -> scrolled win *)
201 val mutable _metasenv = []
204 for i = 1 to pages do notebook#remove_page 0 done;
210 (match switch_page_callback with
212 GtkSignal.disconnect notebook#as_widget id;
213 switch_page_callback <- None
216 method load_sequents metasenv =
217 let sequents_no = List.length metasenv in
218 _metasenv <- metasenv;
219 pages <- sequents_no;
222 GBin.scrolled_window ~hpolicy:`AUTOMATIC ~vpolicy:`AUTOMATIC
223 ~shadow_type:`IN ~show:true ()
226 match sequent_viewer#misc#parent with
227 | None -> w#add sequent_viewer#coerce
228 | Some _ -> sequent_viewer#misc#reparent w#coerce
230 goal2win <- (metano, reparent) :: goal2win;
235 (fun (metano, _, _) ->
236 page2goal <- (!page, metano) :: page2goal;
237 goal2page <- (metano, !page) :: goal2page;
239 notebook#append_page ~tab_label:(tab_label metano) (win metano))
241 switch_page_callback <-
242 Some (notebook#connect#switch_page ~callback:(fun page ->
245 List.assoc page page2goal
246 with Not_found -> assert false
249 self#render_page ~page ~goal))
251 method private render_page ~page ~goal =
252 sequent_viewer#load_sequent _metasenv goal;
254 List.assoc goal goal2win ();
255 sequent_viewer#set_selection None
256 with Not_found -> assert false
258 method goto_sequent goal =
261 List.assoc goal goal2page
262 with Not_found -> assert false
264 notebook#goto_page page;
265 self#render_page page goal;
271 let sequent_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
272 GtkBase.Widget.size_params
273 ~cont:(OgtkMathViewProps.pack_return (fun p ->
274 OgtkMathViewProps.set_params
275 (new sequent_viewer (GtkMathViewProps.MathView_GMetaDOM.create p))
276 ~font_size ~log_verbosity))
282 let gui = MatitaGui.instance () in
283 sequent_viewer ~show:true ~packing:gui#browser#scrolledBrowser#add ()
286 widget#set_href_callback (Some (fun uri -> self#load_uri uri))
288 method load_uri uri = ()
291 let proof_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
292 GtkBase.Widget.size_params
293 ~cont:(OgtkMathViewProps.pack_return (fun p ->
294 OgtkMathViewProps.set_params
295 (new proof_viewer (GtkMathViewProps.MathView_GMetaDOM.create p))
296 ~font_size ~log_verbosity))
299 let proof_viewer_instance =
300 let instance = lazy (
301 let gui = MatitaGui.instance () in
302 proof_viewer ~show:true ~packing:gui#proof#scrolledProof#add ()
304 fun () -> Lazy.force instance
307 let href_callback: (UriManager.uri -> unit) option ref = ref None in
311 (let gui = MatitaGui.instance () in
313 sequent_viewer ~show:true ~packing:gui#check#scrolledCheck#add ()
315 sequent_viewer#set_href_callback !href_callback;
318 method set_href_callback f = href_callback := f
320 method checkTerm sequent metasenv =
321 let (metano, context, expr) = sequent in
322 let widget = Lazy.force check_widget in
323 let gui = MatitaGui.instance () in
324 gui#check#checkWin#show ();
325 gui#main#showCheckMenuItem#set_active true;
326 widget#load_sequent (sequent :: metasenv) metano
328 method unload () = (proof_viewer_instance ())#unload
331 let sequents_viewer ~(notebook:GPack.notebook)
332 ~(sequent_viewer:sequent_viewer) ~set_goal ()
334 new sequents_viewer ~notebook ~sequent_viewer ~set_goal ()
336 let mathViewer () = new mathViewer
338 let cicBrowser () = new cicBrowser