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 val mutable current_infos = None
53 val mutable current_mathml = None
56 ignore (self#connect#click (fun (gdome_elt, _, _, _) ->
59 prerr_endline (gdome_elt#get_nodeName#to_string);
60 ignore (self#action_toggle gdome_elt)
62 (* bugfix: until mapping gtkmathview doesn't draw anything *)
63 ignore (self#misc#connect#after#map (fun _ ->
64 match current_mathml with
66 | Some mathml -> self#load_root ~root:mathml#get_documentElement))
68 method load_proof ((uri_opt, _, _, _) as proof, (goal_opt: int option)) =
69 let (annobj, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts,
70 ids_to_inner_types, ids_to_conjectures, ids_to_hypotheses) =
71 Cic2acic.acic_object_of_cic_object (cicCurrentProof proof)
73 current_infos <- Some (ids_to_terms, ids_to_father_ids, ids_to_conjectures,
76 ApplyTransformation.mml_of_cic_object ~explode_all:true
77 (unopt_uri uri_opt) annobj ids_to_inner_sorts ids_to_inner_types
79 debug_print "load_proof: dumping MathML to /tmp/proof";
80 ignore (Misc.domImpl#saveDocumentToFile ~name:"/tmp/proof" ~doc:mathml ());
81 match current_mathml with
83 self#load_root ~root:mathml#get_documentElement ;
84 current_mathml <- Some mathml
85 | Some current_mathml ->
87 XmlDiff.update_dom ~from:current_mathml mathml ;
91 class sequent_viewer obj =
94 inherit GMathViewAux.multi_selection_math_view obj
96 val mutable current_infos = None
98 method get_selected_terms =
99 let selections = self#get_selections in
103 ((node : Gdome.element)#getAttributeNS
104 ~namespaceURI:Misc.helmns
105 ~localName:(Gdome.domString "xref"))#to_string
107 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
109 match current_infos with
110 Some (ids_to_terms,_,_) ->
113 Hashtbl.find ids_to_terms id
114 with _ -> raise Skip)
115 | None -> assert false (* "ERROR: No current term!!!" *)
118 method get_selected_hypotheses =
119 let selections = self#get_selections in
123 ((node : Gdome.element)#getAttributeNS
124 ~namespaceURI:Misc.helmns
125 ~localName:(Gdome.domString "xref"))#to_string
127 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
129 match current_infos with
130 Some (_,_,ids_to_hypotheses) ->
133 Hashtbl.find ids_to_hypotheses id
134 with _ -> raise Skip)
135 | None -> assert false (* "ERROR: No current term!!!" *)
138 method load_sequent metasenv metano =
140 let (annconjecture, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts,
142 Cic2acic.asequent_of_sequent metasenv conjecture
145 let sequent = CicUtil.lookup_meta metano metasenv in
146 let (mathml, (ids_to_terms, ids_to_father_ids, ids_to_hypotheses)) =
147 ApplyTransformation.mml_of_cic_sequent metasenv sequent
149 current_infos <- Some (ids_to_terms, ids_to_father_ids, ids_to_hypotheses);
150 debug_print "load_sequent: dumping MathML to /tmp/prova";
151 ignore (Misc.domImpl#saveDocumentToFile ~name:"/tmp/prova" ~doc:mathml ());
152 self#load_root ~root:mathml#get_documentElement
156 class sequents_viewer ~(notebook:GPack.notebook)
157 ~(sequent_viewer:MatitaTypes.sequent_viewer) ~set_goal ()
159 let tab_label metano =
160 (GMisc.label ~text:(sprintf "?%d" metano) ~show:true ())#coerce
163 val mutable pages = 0
164 val mutable switch_page_callback = None
165 val mutable page2goal = [] (* associative list: page no -> goal no *)
166 val mutable goal2page = [] (* the other way round *)
167 val mutable goal2win = [] (* associative list: goal no -> scrolled win *)
168 val mutable _metasenv = []
171 for i = 1 to pages do notebook#remove_page 0 done;
177 (match switch_page_callback with
179 GtkSignal.disconnect notebook#as_widget id;
180 switch_page_callback <- None
183 method load_sequents metasenv =
184 let sequents_no = List.length metasenv in
185 _metasenv <- metasenv;
186 pages <- sequents_no;
189 GBin.scrolled_window ~hpolicy:`AUTOMATIC ~vpolicy:`AUTOMATIC
193 match sequent_viewer#misc#parent with
194 | None -> w#add sequent_viewer#coerce
195 | Some _ -> sequent_viewer#misc#reparent w#coerce
197 goal2win <- (metano, reparent) :: goal2win;
202 (fun (metano, _, _) ->
203 page2goal <- (!page, metano) :: page2goal;
204 goal2page <- (metano, !page) :: goal2page;
206 notebook#append_page ~tab_label:(tab_label metano) (win metano))
208 switch_page_callback <-
209 Some (notebook#connect#after#switch_page ~callback:(fun page ->
212 List.assoc page page2goal
213 with Not_found -> assert false
216 self#render_page ~page ~goal))
218 method private render_page ~page ~goal =
219 sequent_viewer#load_sequent _metasenv goal;
221 List.assoc goal goal2win ()
222 with Not_found -> assert false
224 method goto_sequent goal =
227 List.assoc goal goal2page
228 with Not_found -> assert false
230 notebook#goto_page page;
231 self#render_page page goal
237 let sequent_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
238 GtkBase.Widget.size_params
239 ~cont:(OgtkMathViewProps.pack_return (fun p ->
240 OgtkMathViewProps.set_params
241 (new sequent_viewer (GtkMathViewProps.MathView_GMetaDOM.create p))
242 ~font_size ~log_verbosity))
245 let proof_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
246 GtkBase.Widget.size_params
247 ~cont:(OgtkMathViewProps.pack_return (fun p ->
248 OgtkMathViewProps.set_params
249 (new proof_viewer (GtkMathViewProps.MathView_GMetaDOM.create p))
250 ~font_size ~log_verbosity))
253 let proof_viewer_instance =
254 let instance = lazy (
255 let gui = MatitaGui.instance () in
257 GBin.frame ~packing:(gui#proof#scrolledProof#add_with_viewport)
260 proof_viewer ~show:true ~packing:(frame#add) ()
262 fun () -> Lazy.force instance
264 let sequents_viewer ~(notebook:GPack.notebook)
265 ~(sequent_viewer:MatitaTypes.sequent_viewer) ~set_goal ()
267 new sequents_viewer ~notebook ~sequent_viewer ~set_goal ()