]> matita.cs.unibo.it Git - helm.git/blob - helm/gTopLevel/termViewer.ml
sort CProp added
[helm.git] / helm / gTopLevel / termViewer.ml
1 (* Copyright (C) 2000-2002, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 (******************************************************************************)
27 (*                                                                            *)
28 (*                               PROJECT HELM                                 *)
29 (*                                                                            *)
30 (*                Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>               *)
31 (*                                 29/01/2003                                 *)
32 (*                                                                            *)
33 (*                                                                            *)
34 (******************************************************************************)
35
36 let use_stylesheets = ref false;;(* false performs the transformations in OCaml*)
37
38 (* List utility functions *)
39 exception Skip;;
40
41 let list_map_fail f =
42  let rec aux =
43   function
44      [] -> []
45    | he::tl ->
46       try
47        let he' = f he in
48         he'::(aux tl)
49       with Skip ->
50        (aux tl)
51  in
52   aux
53 ;;
54 (* End of the list utility functions *)
55
56 (** A widget to render sequents **)
57
58 class sequent_viewer obj =
59  object(self)
60
61   inherit GMathViewAux.multi_selection_math_view obj
62
63   val mutable current_infos = None
64
65   (* returns the list of selected terms         *)
66   (* selections which are not terms are ignored *)
67   method get_selected_terms =
68    prerr_endline (string_of_int (List.length self#get_selections)) ;
69    let selections = self#get_selections in
70     list_map_fail
71      (function node ->
72        let xpath =
73         ((node : Gdome.element)#getAttributeNS
74           ~namespaceURI:Misc.helmns
75           ~localName:(Gdome.domString "xref"))#to_string
76        in
77         prerr_endline ("YAHHHHHHHHHH " ^ xpath) ;
78         if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
79         else
80          match current_infos with
81             Some (ids_to_terms,_,_) ->
82              let id = xpath in
83               (try
84                 Hashtbl.find ids_to_terms id
85                with _ -> raise Skip)
86           | None -> assert false (* "ERROR: No current term!!!" *)
87      ) selections
88
89   (* returns the list of selected hypotheses         *)
90   (* selections which are not hypotheses are ignored *)
91   method get_selected_hypotheses =
92    let selections = self#get_selections in
93     list_map_fail
94      (function node ->
95        let xpath =
96         ((node : Gdome.element)#getAttributeNS
97           ~namespaceURI:Misc.helmns
98           ~localName:(Gdome.domString "xref"))#to_string
99        in
100         if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
101         else
102          match current_infos with
103             Some (_,_,ids_to_hypotheses) ->
104              let id = xpath in
105               (try
106                 Hashtbl.find ids_to_hypotheses id
107                with _ -> raise Skip)
108           | None -> assert false (* "ERROR: No current term!!!" *)
109      ) selections
110   
111   method load_sequent metasenv sequent =
112    let sequent_mml,(ids_to_terms,ids_to_father_ids,ids_to_hypotheses) =
113     ApplyStylesheets.mml_of_cic_sequent metasenv sequent
114    in
115     self#load_doc ~dom:sequent_mml ;
116 (*
117 Misc.domImpl#saveDocumentToFile ~name:"/tmp/pippo" ~doc:sequent_mml () ;
118 *)
119      current_infos <-
120      Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
121  end
122 ;;
123
124 let sequent_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
125   GtkBase.Container.make_params ~cont:(
126   OgtkMathViewProps.pack_return
127     (fun p -> OgtkMathViewProps.set_params (new sequent_viewer (GtkMathViewProps.MathView.create p)) ~font_size ~log_verbosity)) []
128 ;;
129
130 (*
131 let sequent_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
132  ?border_width ?width ?height ?packing ?show () =
133  let w =
134    GtkMathView.MathView.create
135     ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
136     ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
137     ()
138  in
139   GtkBase.Container.set w ?border_width ?width ?height;
140  let mathview = GObj.pack_return (new sequent_viewer w) ~packing ~show in
141  begin
142     match font_size with
143     | Some size -> mathview#set_font_size size
144     | None      -> ()
145   end;
146   begin
147     match font_manager with
148     | Some manager -> mathview#set_font_manager_type ~fm_type:manager
149     | None         -> ()
150   end;
151   mathview
152 ;;
153 *)
154
155 (** A widget to render proofs **)
156
157 class proof_viewer obj =
158  object(self)
159
160   inherit GMathViewAux.single_selection_math_view obj
161
162 (*   initializer self#set_font_size 10 *)
163
164   val mutable current_infos = None
165   val mutable current_mml = None
166
167   method make_sequent_of_selected_term =
168    match self#get_selection with
169       Some node ->
170        let xpath =
171         ((node : Gdome.element)#getAttributeNS
172           ~namespaceURI:Misc.helmns
173           ~localName:(Gdome.domString "xref"))#to_string
174        in
175         prerr_endline ("YAEEEEEEEEEEEEEEEEEEE " ^ xpath) ;
176         if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
177         else
178          begin
179           match current_infos with
180              Some (ids_to_terms, ids_to_father_ids, _, _) ->
181               let id = xpath in
182                LogicalOperations.to_sequent id ids_to_terms ids_to_father_ids
183            | None -> assert false (* "ERROR: No current term!!!" *)
184          end
185     | None -> assert false (* "ERROR: No selection!!!" *)
186
187   method focus_sequent_of_selected_term =
188    match self#get_selection with
189       Some node ->
190        let xpath =
191         ((node : Gdome.element)#getAttributeNS
192           ~namespaceURI:Misc.helmns
193           ~localName:(Gdome.domString "xref"))#to_string
194        in
195         if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
196         else
197          begin
198           match current_infos with
199              Some (ids_to_terms, ids_to_father_ids, _, _) ->
200               let id = xpath in
201                LogicalOperations.focus id ids_to_terms ids_to_father_ids
202            | None -> assert false (* "ERROR: No current term!!!" *)
203          end
204     | None -> assert false (* "ERROR: No selection!!!" *)
205
206   method load_proof uri currentproof =
207    let
208     (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
209      ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
210    =
211     Cic2acic.acic_object_of_cic_object currentproof
212    in
213     if !use_stylesheets then
214      let mml =
215       ApplyStylesheets.mml_of_cic_object
216        ~explode_all:true uri acic ids_to_inner_sorts ids_to_inner_types
217      in
218       self#load_doc ~dom:mml ;
219       current_mml <- Some mml ;
220       current_infos <-
221        Some
222         (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses) ;
223     else
224      (match acic with
225          Cic.ACurrentProof (id,idbody,n,conjectures,bo,ty,params) ->
226            let time1 = Sys.time () in
227            let content = 
228               Cic2content.annobj2content 
229                 ~ids_to_inner_sorts ~ids_to_inner_types acic in
230            let pres = Content2pres.content2pres ~ids_to_inner_sorts content in
231            let time2 = Sys.time () in
232            (* prerr_endline ("Fine trasformazione:" ^ (string_of_float (time2 -. time1))); *)
233            let xmlpres = Mpresentation.print_mpres pres in
234            let time25 = Sys.time () in
235             (*
236             prerr_endline ("FINE printing to stream:" ^ (string_of_float (time25 -. time2)));
237             Xml.pp xmlpres (Some "tmp");
238             let time3 = Sys.time () in
239              prerr_endline ("FINE valutazione e printing dello stream:" ^ (string_of_float (time3 -. time25)));
240             *)
241            (try 
242              prerr_endline "(******** INIZIO DOM **********)";
243              let mml = Xml2Gdome.document_of_xml Misc.domImpl xmlpres in
244              let time3 = Sys.time () in
245              (* ignore (Misc.domImpl#saveDocumentToFile mml "tmp1" ()); *)
246              prerr_endline "(******** FINE DOM **********)";
247              (match current_mml with
248                  None ->
249                   let time1 = Sys.time () in
250                   self#load_doc ~dom:mml ;
251                   let time2 = Sys.time () in
252                   prerr_endline ("Loading and displaying the proof took " ^ string_of_float (time2 -. time1) ^ "seconds") ;
253                   current_mml <- Some mml
254                | Some current_mml' ->
255                   self#freeze ;
256                   let time1 = Sys.time () in
257                   XmlDiff.update_dom ~from:current_mml' mml ;
258                   let time2 = Sys.time () in
259                   prerr_endline ("XMLDIFF took " ^ string_of_float (time2 -. time1) ^ "seconds") ;
260                   self#thaw ;
261                   let time3 = Sys.time () in
262                   prerr_endline ("The refresh of the widget took " ^ string_of_float (time3 -. time2) ^ "seconds")
263                   ) ;
264 (*
265               self#load_doc ~dom:mml ;
266               current_mml <- Some mml ;
267 *)
268              prerr_endline ("Fine loading:" ^ (string_of_float (time3 -. time2)))
269             (*
270              self#load_uri "tmp";
271              let time4 = Sys.time () in
272              prerr_endline
273               ("Fine loading:" ^ (string_of_float (time4 -. time3)))
274             *)
275            with (GdomeInit.DOMException (_,s)) as e ->
276               prerr_endline s; raise e)
277        | _ -> assert false);
278     (acic, ids_to_inner_types, ids_to_inner_sorts)
279  end
280 ;;
281
282 let proof_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
283   GtkBase.Container.make_params ~cont:(
284   OgtkMathViewProps.pack_return
285     (fun p -> OgtkMathViewProps.set_params (new proof_viewer (GtkMathViewProps.MathView.create p)) ~font_size ~log_verbosity)) []
286 ;;
287
288 (*
289 let proof_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
290  ?border_width ?width ?height ?packing ?show () =
291  let w =
292    GtkMathView.MathView.create
293     ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
294     ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
295     ()
296  in
297   GtkBase.Container.set w ?border_width ?width ?height;
298  let mathview = GObj.pack_return (new proof_viewer w) ~packing ~show in
299  begin
300     match font_size with
301     | Some size -> mathview#set_font_size size
302     | None      -> ()
303   end;
304   begin
305     match font_manager with
306     | Some manager -> mathview#set_font_manager_type ~fm_type:manager
307     | None         -> ()
308   end;
309   mathview
310 ;;
311 *)
312
313 let _ =
314  Cexpr2pres_hashtbl.init Cexpr2pres.cexpr2pres Cexpr2pres.cexpr2pres_charcount
315 ;;