]> matita.cs.unibo.it Git - helm.git/blob - helm/gTopLevel/termViewer.ml
91b2dd1a795fe470f8c72b282892ac04a7616df0
[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 (*                  29/01/2003 Claudio Sacerdoti Coen                      *)
31 (*                                                                         *)
32 (*                                                                         *)
33 (***************************************************************************)
34
35 (* List utility functions *)
36 exception Skip;;
37
38 let list_map_fail f =
39  let rec aux =
40   function
41      [] -> []
42    | he::tl ->
43       try
44        let he' = f he in
45         he'::(aux tl)
46       with Skip ->
47        (aux tl)
48  in
49   aux
50 ;;
51 (* End of the list utility functions *)
52
53 (** A widget to render sequents **)
54
55 class sequent_viewer obj =
56  object(self)
57
58   inherit GMathViewAux.multi_selection_math_view obj
59
60   val mutable current_infos = None
61
62   (* returns the list of selected terms         *)
63   (* selections which are not terms are ignored *)
64   method get_selected_terms =
65    prerr_endline (string_of_int (List.length self#get_selections)) ;
66    let selections = self#get_selections in
67     list_map_fail
68      (function node ->
69        let xpath =
70         ((node : Gdome.element)#getAttributeNS
71           ~namespaceURI:Misc.helmns
72           ~localName:(Gdome.domString "xref"))#to_string
73        in
74         prerr_endline ("YAHHHHHHHHHH " ^ xpath) ;
75         if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
76         else
77          match current_infos with
78             Some (ids_to_terms,_,_) ->
79              let id = xpath in
80               (try
81                 Hashtbl.find ids_to_terms id
82                with _ -> raise Skip)
83           | None -> assert false (* "ERROR: No current term!!!" *)
84      ) selections
85
86   (* returns the list of selected hypotheses         *)
87   (* selections which are not hypotheses are ignored *)
88   method get_selected_hypotheses =
89    let selections = self#get_selections in
90     list_map_fail
91      (function node ->
92        let xpath =
93         ((node : Gdome.element)#getAttributeNS
94           ~namespaceURI:Misc.helmns
95           ~localName:(Gdome.domString "xref"))#to_string
96        in
97         if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
98         else
99          match current_infos with
100             Some (_,_,ids_to_hypotheses) ->
101              let id = xpath in
102               (try
103                 Hashtbl.find ids_to_hypotheses id
104                with _ -> raise Skip)
105           | None -> assert false (* "ERROR: No current term!!!" *)
106      ) selections
107   
108   method load_sequent metasenv sequent =
109 (**** SIAM QUI ****)
110    let sequent_mml,(ids_to_terms,ids_to_father_ids,ids_to_hypotheses) =
111      ChosenTransformer.mml_of_cic_sequent metasenv sequent
112    in
113     self#load_doc ~dom:sequent_mml ;
114 (*
115 Misc.domImpl#saveDocumentToFile ~name:"/tmp/pippo" ~doc:sequent_mml () ;
116 *)
117      current_infos <-
118      Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
119  end
120 ;;
121
122 let sequent_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
123   GtkBase.Container.make_params ~cont:(
124   OgtkMathViewProps.pack_return
125     (fun p -> OgtkMathViewProps.set_params (new sequent_viewer (GtkMathViewProps.MathView.create p)) ~font_size ~log_verbosity)) []
126 ;;
127
128 (*
129 let sequent_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
130  ?border_width ?width ?height ?packing ?show () =
131  let w =
132    GtkMathView.MathView.create
133     ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
134     ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
135     ()
136  in
137   GtkBase.Container.set w ?border_width ?width ?height;
138  let mathview = GObj.pack_return (new sequent_viewer w) ~packing ~show in
139  begin
140     match font_size with
141     | Some size -> mathview#set_font_size size
142     | None      -> ()
143   end;
144   begin
145     match font_manager with
146     | Some manager -> mathview#set_font_manager_type ~fm_type:manager
147     | None         -> ()
148   end;
149   mathview
150 ;;
151 *)
152
153 (** A widget to render proofs **)
154
155 class proof_viewer obj =
156  object(self)
157
158   inherit GMathViewAux.single_selection_math_view obj
159
160 (*   initializer self#set_font_size 10 *)
161
162   val mutable current_infos = None
163   val mutable current_mml = None
164
165   method make_sequent_of_selected_term =
166    match self#get_selection with
167       Some node ->
168        let xpath =
169         ((node : Gdome.element)#getAttributeNS
170           ~namespaceURI:Misc.helmns
171           ~localName:(Gdome.domString "xref"))#to_string
172        in
173         prerr_endline ("YAEEEEEEEEEEEEEEEEEEE " ^ xpath) ;
174         if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
175         else
176          begin
177           match current_infos with
178              Some (ids_to_terms, ids_to_father_ids, _, _) ->
179               let id = xpath in
180                LogicalOperations.to_sequent id ids_to_terms ids_to_father_ids
181            | None -> assert false (* "ERROR: No current term!!!" *)
182          end
183     | None -> assert false (* "ERROR: No selection!!!" *)
184
185   method focus_sequent_of_selected_term =
186    match self#get_selection with
187       Some node ->
188        let xpath =
189         ((node : Gdome.element)#getAttributeNS
190           ~namespaceURI:Misc.helmns
191           ~localName:(Gdome.domString "xref"))#to_string
192        in
193         if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
194         else
195          begin
196           match current_infos with
197              Some (ids_to_terms, ids_to_father_ids, _, _) ->
198               let id = xpath in
199                LogicalOperations.focus id ids_to_terms ids_to_father_ids
200            | None -> assert false (* "ERROR: No current term!!!" *)
201          end
202     | None -> assert false (* "ERROR: No selection!!!" *)
203
204   method load_proof uri currentproof =
205     let
206       (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
207        ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
208       = Cic2acic.acic_object_of_cic_object currentproof
209     in
210     let mml =
211       ChosenTransformer.mml_of_cic_object
212         ~explode_all:true uri acic ids_to_inner_sorts ids_to_inner_types
213     in
214     current_infos <-
215       Some
216        (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses);
217     (* self#load_doc ~dom:mml ;
218        current_mml <- Some mml ; *)
219     (match current_mml with
220       None ->
221         let time1 = Sys.time () in
222         self#load_doc ~dom:mml ;
223         let time2 = Sys.time () in
224         prerr_endline ("Loading and displaying the proof took " ^ string_of_float (time2 -. time1) ^ "seconds") ;
225         current_mml <- Some mml
226     | Some current_mml' ->
227         self#freeze ;
228         let time1 = Sys.time () in
229         XmlDiff.update_dom ~from:current_mml' mml ;
230         let time2 = Sys.time () in
231         prerr_endline ("XMLDIFF took " ^ string_of_float (time2 -. time1) ^ "seconds") ;
232         self#thaw ;
233         let time3 = Sys.time () in
234         prerr_endline ("The refresh of the widget took " ^ string_of_float (time3 -. time2) ^ "seconds"));
235     (acic, ids_to_inner_types, ids_to_inner_sorts)
236   end
237 ;;
238
239
240 let proof_viewer ?hadjustment ?vadjustment ?font_size ?log_verbosity =
241   GtkBase.Container.make_params ~cont:(
242   OgtkMathViewProps.pack_return
243     (fun p -> OgtkMathViewProps.set_params (new proof_viewer (GtkMathViewProps.MathView.create p)) ~font_size ~log_verbosity)) []
244 ;;
245
246 (*
247 let proof_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
248  ?border_width ?width ?height ?packing ?show () =
249  let w =
250    GtkMathView.MathView.create
251     ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
252     ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
253     ()
254  in
255   GtkBase.Container.set w ?border_width ?width ?height;
256  let mathview = GObj.pack_return (new proof_viewer w) ~packing ~show in
257  begin
258     match font_size with
259     | Some size -> mathview#set_font_size size
260     | None      -> ()
261   end;
262   begin
263     match font_manager with
264     | Some manager -> mathview#set_font_manager_type ~fm_type:manager
265     | None         -> ()
266   end;
267   mathview
268 ;;
269 *)
270
271 let _ =
272  Cexpr2pres_hashtbl.init Cexpr2pres.cexpr2pres Cexpr2pres.cexpr2pres_charcount
273 ;;