]> matita.cs.unibo.it Git - helm.git/blob - helm/gTopLevel/termViewer.ml
9a9c9c9b884ae941d0d976dcf20cb49735b39f1f
[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 (* List utility functions *)
37 exception Skip;;
38
39 let list_map_fail f =
40  let rec aux =
41   function
42      [] -> []
43    | he::tl ->
44       try
45        let he' = f he in
46         he'::(aux tl)
47       with Skip ->
48        (aux tl)
49  in
50   aux
51 ;;
52 (* End of the list utility functions *)
53
54 (** A widget to render sequents **)
55
56 class sequent_viewer obj =
57  object(self)
58
59   inherit GMathViewAux.multi_selection_math_view obj
60
61   val mutable current_infos = None
62
63   (* returns the list of selected terms         *)
64   (* selections which are not terms are ignored *)
65   method get_selected_terms =
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         if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
75         else
76          match current_infos with
77             Some (ids_to_terms,_,_) ->
78              let id = xpath in
79               (try
80                 Hashtbl.find ids_to_terms id
81                with _ -> raise Skip)
82           | None -> assert false (* "ERROR: No current term!!!" *)
83      ) selections
84
85   (* returns the list of selected hypotheses         *)
86   (* selections which are not hypotheses are ignored *)
87   method get_selected_hypotheses =
88    let selections = self#get_selections in
89     list_map_fail
90      (function node ->
91        let xpath =
92         ((node : Gdome.element)#getAttributeNS
93           ~namespaceURI:Misc.helmns
94           ~localName:(Gdome.domString "xref"))#to_string
95        in
96         if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
97         else
98          match current_infos with
99             Some (_,_,ids_to_hypotheses) ->
100              let id = xpath in
101               (try
102                 Hashtbl.find ids_to_hypotheses id
103                with _ -> raise Skip)
104           | None -> assert false (* "ERROR: No current term!!!" *)
105      ) selections
106   
107   method load_sequent metasenv sequent =
108    let sequent_mml,(ids_to_terms,ids_to_father_ids,ids_to_hypotheses) =
109     ApplyStylesheets.mml_of_cic_sequent metasenv sequent
110    in
111     self#load_doc ~dom:sequent_mml ;
112     current_infos <-
113      Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
114  end
115 ;;
116
117 let sequent_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
118  ?border_width ?width ?height ?packing ?show () =
119  let w =
120    GtkMathView.MathView.create
121     ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
122     ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
123     ()
124  in
125   GtkBase.Container.set w ?border_width ?width ?height;
126  let mathview = GObj.pack_return (new sequent_viewer w) ~packing ~show in
127  begin
128     match font_size with
129     | Some size -> mathview#set_font_size size
130     | None      -> ()
131   end;
132   begin
133     match font_manager with
134     | Some manager -> mathview#set_font_manager_type ~fm_type:manager
135     | None         -> ()
136   end;
137   mathview
138 ;;
139
140
141 (** A widget to render proofs **)
142
143 class proof_viewer obj =
144  object(self)
145
146   inherit GMathViewAux.single_selection_math_view obj
147
148   initializer self#set_font_size 10
149
150   val mutable current_infos = None
151
152   method make_sequent_of_selected_term =
153    match self#get_selection with
154       Some node ->
155        let xpath =
156         ((node : Gdome.element)#getAttributeNS
157           ~namespaceURI:Misc.helmns
158           ~localName:(Gdome.domString "xref"))#to_string
159        in
160         if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
161         else
162          begin
163           match current_infos with
164              Some (ids_to_terms, ids_to_father_ids, _, _) ->
165               let id = xpath in
166                LogicalOperations.to_sequent id ids_to_terms ids_to_father_ids
167            | None -> assert false (* "ERROR: No current term!!!" *)
168          end
169     | None -> assert false (* "ERROR: No selection!!!" *)
170
171   method focus_sequent_of_selected_term =
172    match self#get_selection with
173       Some node ->
174        let xpath =
175         ((node : Gdome.element)#getAttributeNS
176           ~namespaceURI:Misc.helmns
177           ~localName:(Gdome.domString "xref"))#to_string
178        in
179         if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
180         else
181          begin
182           match current_infos with
183              Some (ids_to_terms, ids_to_father_ids, _, _) ->
184               let id = xpath in
185                LogicalOperations.focus id ids_to_terms ids_to_father_ids
186            | None -> assert false (* "ERROR: No current term!!!" *)
187          end
188     | None -> assert false (* "ERROR: No selection!!!" *)
189
190   method load_proof uri currentproof =
191    let
192     (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
193      ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
194    =
195     Cic2acic.acic_object_of_cic_object currentproof
196    in
197     let mml =
198      ApplyStylesheets.mml_of_cic_object
199       ~explode_all:true uri acic ids_to_inner_sorts ids_to_inner_types
200     in
201      self#load_doc ~dom:mml ;
202      current_infos <-
203       Some
204        (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses) ;
205      (acic, ids_to_inner_types, ids_to_inner_sorts)
206  end
207 ;;
208
209 let proof_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
210  ?border_width ?width ?height ?packing ?show () =
211  let w =
212    GtkMathView.MathView.create
213     ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
214     ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
215     ()
216  in
217   GtkBase.Container.set w ?border_width ?width ?height;
218  let mathview = GObj.pack_return (new proof_viewer w) ~packing ~show in
219  begin
220     match font_size with
221     | Some size -> mathview#set_font_size size
222     | None      -> ()
223   end;
224   begin
225     match font_manager with
226     | Some manager -> mathview#set_font_manager_type ~fm_type:manager
227     | None         -> ()
228   end;
229   mathview
230 ;;