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 let choose_selection mmlwidget (element : Gdome.element option) =
49 if element#hasAttributeNS
50 ~namespaceURI:Misc.helmns
51 ~localName:(Gdome.domString "xref")
53 mmlwidget#set_selection (Some element)
56 match element#get_parentNode with
57 | None -> assert false
58 | Some p -> aux (new Gdome.element_of_node p)
59 with GdomeInit.DOMCastException _ ->
60 debug_print "trying to select above the document root"
64 | None -> mmlwidget#set_selection None
66 class proof_viewer obj =
69 inherit GMathViewAux.single_selection_math_view obj
71 val mutable current_infos = None
72 val mutable current_mathml = None
75 ignore (self#connect#click (fun (gdome_elt, _, _, _) ->
78 prerr_endline (gdome_elt#get_nodeName#to_string);
79 ignore (self#action_toggle gdome_elt)
81 ignore (self#connect#selection_changed (choose_selection self))
83 method load_proof ((uri_opt, _, _, _) as proof, (goal_opt: int option)) =
84 let (annobj, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts,
85 ids_to_inner_types, ids_to_conjectures, ids_to_hypotheses) =
86 Cic2acic.acic_object_of_cic_object (cicCurrentProof proof)
88 current_infos <- Some (ids_to_terms, ids_to_father_ids, ids_to_conjectures,
91 ApplyTransformation.mml_of_cic_object ~explode_all:true
92 (unopt_uri uri_opt) annobj ids_to_inner_sorts ids_to_inner_types
94 debug_print "load_proof: dumping MathML to ./proof";
95 ignore (Misc.domImpl#saveDocumentToFile ~name:"./proof" ~doc:mathml ());
96 match current_mathml with
98 self#load_root ~root:mathml#get_documentElement ;
99 current_mathml <- Some mathml
100 | Some current_mathml ->
102 XmlDiff.update_dom ~from:current_mathml mathml ;
106 class sequent_viewer obj =
109 inherit GMathViewAux.multi_selection_math_view obj
112 ignore (self#connect#selection_changed (choose_selection self))
114 val mutable current_infos = None
116 method get_selected_terms =
117 let selections = self#get_selections in
121 ((node : Gdome.element)#getAttributeNS
122 ~namespaceURI:Misc.helmns
123 ~localName:(Gdome.domString "xref"))#to_string
125 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
127 match current_infos with
128 Some (ids_to_terms,_,_) ->
131 Hashtbl.find ids_to_terms id
132 with _ -> raise Skip)
133 | None -> assert false (* "ERROR: No current term!!!" *)
136 method get_selected_hypotheses =
137 let selections = self#get_selections in
141 ((node : Gdome.element)#getAttributeNS
142 ~namespaceURI:Misc.helmns
143 ~localName:(Gdome.domString "xref"))#to_string
145 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
147 match current_infos with
148 Some (_,_,ids_to_hypotheses) ->
151 Hashtbl.find ids_to_hypotheses id
152 with _ -> raise Skip)
153 | None -> assert false (* "ERROR: No current term!!!" *)
156 method load_sequent metasenv metano =
158 let (annconjecture, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts,
160 Cic2acic.asequent_of_sequent metasenv conjecture
163 let sequent = CicUtil.lookup_meta metano metasenv in
164 let (mathml, (ids_to_terms, ids_to_father_ids, ids_to_hypotheses)) =
165 ApplyTransformation.mml_of_cic_sequent metasenv sequent
167 current_infos <- Some (ids_to_terms, ids_to_father_ids, ids_to_hypotheses);
168 debug_print "load_sequent: dumping MathML to ./prova";
169 ignore (Misc.domImpl#saveDocumentToFile ~name:"./prova" ~doc:mathml ());
170 self#load_root ~root:mathml#get_documentElement
174 class sequents_viewer ~(notebook:GPack.notebook)
175 ~(sequent_viewer:sequent_viewer) ~set_goal ()
177 let tab_label metano =
178 (GMisc.label ~text:(sprintf "?%d" metano) ~show:true ())#coerce
181 val mutable pages = 0
182 val mutable switch_page_callback = None
183 val mutable page2goal = [] (* associative list: page no -> goal no *)
184 val mutable goal2page = [] (* the other way round *)
185 val mutable goal2win = [] (* associative list: goal no -> scrolled win *)
186 val mutable _metasenv = []
189 for i = 1 to pages do notebook#remove_page 0 done;
195 (match switch_page_callback with
197 GtkSignal.disconnect notebook#as_widget id;
198 switch_page_callback <- None
201 method load_sequents metasenv =
202 let sequents_no = List.length metasenv in
203 _metasenv <- metasenv;
204 pages <- sequents_no;
207 GBin.scrolled_window ~hpolicy:`AUTOMATIC ~vpolicy:`AUTOMATIC
208 ~shadow_type:`IN ~show:true ()
211 match sequent_viewer#misc#parent with
212 | None -> w#add sequent_viewer#coerce
213 | Some _ -> sequent_viewer#misc#reparent w#coerce
215 goal2win <- (metano, reparent) :: goal2win;
220 (fun (metano, _, _) ->
221 page2goal <- (!page, metano) :: page2goal;
222 goal2page <- (metano, !page) :: goal2page;
224 notebook#append_page ~tab_label:(tab_label metano) (win metano))
226 switch_page_callback <-
227 Some (notebook#connect#switch_page ~callback:(fun page ->
230 List.assoc page page2goal
231 with Not_found -> assert false
234 self#render_page ~page ~goal))
236 method private render_page ~page ~goal =
237 sequent_viewer#load_sequent _metasenv goal;
239 List.assoc goal goal2win ();
240 sequent_viewer#set_selection None
241 with Not_found -> assert false
243 method goto_sequent goal =
246 List.assoc goal goal2page
247 with Not_found -> assert false
249 notebook#goto_page page;
250 self#render_page page goal;
256 let sequent_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
257 GtkBase.Widget.size_params
258 ~cont:(OgtkMathViewProps.pack_return (fun p ->
259 OgtkMathViewProps.set_params
260 (new sequent_viewer (GtkMathViewProps.MathView_GMetaDOM.create p))
261 ~font_size ~log_verbosity))
264 let proof_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
265 GtkBase.Widget.size_params
266 ~cont:(OgtkMathViewProps.pack_return (fun p ->
267 OgtkMathViewProps.set_params
268 (new proof_viewer (GtkMathViewProps.MathView_GMetaDOM.create p))
269 ~font_size ~log_verbosity))
272 let proof_viewer_instance =
273 let instance = lazy (
274 let gui = MatitaGui.instance () in
275 proof_viewer ~show:true ~packing:gui#proof#scrolledProof#add ()
277 fun () -> Lazy.force instance
279 let sequents_viewer ~(notebook:GPack.notebook)
280 ~(sequent_viewer:sequent_viewer) ~set_goal ()
282 new sequents_viewer ~notebook ~sequent_viewer ~set_goal ()
286 (let gui = MatitaGui.instance () in
287 sequent_viewer ~show:true ~packing:gui#check#scrolledCheck#add ())
291 method checkTerm sequent metasenv =
292 let (metano, context, expr) = sequent in
293 let widget = Lazy.force check_widget in
294 let gui = MatitaGui.instance () in
295 gui#check#checkWin#show ();
296 gui#main#showCheckMenuItem#set_active true;
297 widget#load_sequent (sequent :: metasenv) metano
299 method unload () = (proof_viewer_instance ())#unload
302 let mathViewer () = new mathViewer