]> matita.cs.unibo.it Git - helm.git/blob - helm/gTopLevel/termViewer.ml
c35cdb377d700c8df6de42375fa80a34617359ab
[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   val mutable current_infos = None
149
150   method make_sequent_of_selected_term =
151    match self#get_selection with
152       Some node ->
153        let xpath =
154         ((node : Gdome.element)#getAttributeNS
155           ~namespaceURI:Misc.helmns
156           ~localName:(Gdome.domString "xref"))#to_string
157        in
158         if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
159         else
160          begin
161           match current_infos with
162              Some (ids_to_terms, ids_to_father_ids, _, _) ->
163               let id = xpath in
164                LogicalOperations.to_sequent id ids_to_terms ids_to_father_ids
165            | None -> assert false (* "ERROR: No current term!!!" *)
166          end
167     | None -> assert false (* "ERROR: No selection!!!" *)
168
169   method focus_sequent_of_selected_term =
170    match self#get_selection with
171       Some node ->
172        let xpath =
173         ((node : Gdome.element)#getAttributeNS
174           ~namespaceURI:Misc.helmns
175           ~localName:(Gdome.domString "xref"))#to_string
176        in
177         if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
178         else
179          begin
180           match current_infos with
181              Some (ids_to_terms, ids_to_father_ids, _, _) ->
182               let id = xpath in
183                LogicalOperations.focus id ids_to_terms ids_to_father_ids
184            | None -> assert false (* "ERROR: No current term!!!" *)
185          end
186     | None -> assert false (* "ERROR: No selection!!!" *)
187
188   method load_proof uri currentproof =
189    let
190     (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
191      ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
192    =
193     Cic2acic.acic_object_of_cic_object currentproof
194    in
195     let mml =
196      ApplyStylesheets.mml_of_cic_object
197       ~explode_all:true uri acic ids_to_inner_sorts ids_to_inner_types
198     in
199      self#load_doc ~dom:mml ;
200      current_infos <-
201       Some
202        (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses) ;
203      (acic, ids_to_inner_types, ids_to_inner_sorts)
204  end
205 ;;
206
207 let proof_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager
208  ?border_width ?width ?height ?packing ?show () =
209  let w =
210    GtkMathView.MathView.create
211     ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth)
212     ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv)
213     ()
214  in
215   GtkBase.Container.set w ?border_width ?width ?height;
216  let mathview = GObj.pack_return (new proof_viewer w) ~packing ~show in
217  begin
218     match font_size with
219     | Some size -> mathview#set_font_size size
220     | None      -> ()
221   end;
222   begin
223     match font_manager with
224     | Some manager -> mathview#set_font_manager_type ~fm_type:manager
225     | None         -> ()
226   end;
227   mathview
228 ;;