]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaMathView.ml
snapshot
[helm.git] / helm / matita / matitaMathView.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 open MatitaTypes
36
37 (* List utility functions *)
38 exception Skip;;
39
40 let list_map_fail f =
41  let rec aux =
42   function
43      [] -> []
44    | he::tl ->
45       try
46        let he' = f he in
47         he'::(aux tl)
48       with Skip ->
49        (aux tl)
50  in
51   aux
52 ;;
53 (* End of the list utility functions *)
54
55 class sequent_viewer ~(mml_of_cic_sequent:mml_of_cic_sequent) obj =
56  object(self)
57
58   inherit GMathViewAux.multi_selection_math_view obj
59
60   val mutable current_infos = None
61
62   method get_selected_terms =
63    let selections = self#get_selections in
64     list_map_fail
65      (function node ->
66        let xpath =
67         ((node : Gdome.element)#getAttributeNS
68           ~namespaceURI:Misc.helmns
69           ~localName:(Gdome.domString "xref"))#to_string
70        in
71         if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
72         else
73          match current_infos with
74             Some (ids_to_terms,_,_) ->
75              let id = xpath in
76               (try
77                 Hashtbl.find ids_to_terms id
78                with _ -> raise Skip)
79           | None -> assert false (* "ERROR: No current term!!!" *)
80      ) selections
81
82   method get_selected_hypotheses =
83    let selections = self#get_selections in
84     list_map_fail
85      (function node ->
86        let xpath =
87         ((node : Gdome.element)#getAttributeNS
88           ~namespaceURI:Misc.helmns
89           ~localName:(Gdome.domString "xref"))#to_string
90        in
91         if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
92         else
93          match current_infos with
94             Some (_,_,ids_to_hypotheses) ->
95              let id = xpath in
96               (try
97                 Hashtbl.find ids_to_hypotheses id
98                with _ -> raise Skip)
99           | None -> assert false (* "ERROR: No current term!!!" *)
100      ) selections
101   
102   method load_sequent metasenv sequent =
103    let sequent_mml,(ids_to_terms,ids_to_father_ids,ids_to_hypotheses) =
104      mml_of_cic_sequent metasenv sequent
105    in
106     self#load_root ~root:sequent_mml#get_documentElement ;
107      current_infos <-
108       Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
109  end
110 ;;
111
112 class proof_viewer ~(mml_of_cic_object:mml_of_cic_object) obj =
113  object(self)
114
115   inherit GMathViewAux.single_selection_math_view obj
116
117   val mutable current_infos = None
118   val mutable current_mml = None
119
120   method load_proof uri currentproof =
121     let
122       (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
123        ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
124       = Cic2acic.acic_object_of_cic_object currentproof
125     in
126     let mml =
127       mml_of_cic_object
128         ~explode_all:true uri acic ids_to_inner_sorts ids_to_inner_types
129     in
130     current_infos <-
131       Some
132        (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses);
133     (match current_mml with
134       None ->
135         self#load_root ~root:mml#get_documentElement ;
136         current_mml <- Some mml
137     | Some current_mml' ->
138         self#freeze ;
139         XmlDiff.update_dom ~from:current_mml' mml ;
140         self#thaw);
141     (acic, ids_to_inner_types, ids_to_inner_sorts)
142   end
143
144  (** constructors *)
145
146 let sequent_viewer ~(mml_of_cic_sequent: mml_of_cic_sequent) =
147   GtkBase.Widget.size_params
148     ~cont:(OgtkMathViewProps.pack_return (fun p ->
149       OgtkMathViewProps.set_params
150         (new sequent_viewer ~mml_of_cic_sequent
151           (GtkMathViewProps.MathView_GMetaDOM.create p))
152         ?font_size:None ?log_verbosity:None))
153     ?width:None ?height:None []
154
155 let proof_viewer ~(mml_of_cic_object: mml_of_cic_object) =
156   GtkBase.Widget.size_params
157     ~cont:(OgtkMathViewProps.pack_return (fun p ->
158       OgtkMathViewProps.set_params
159         (new proof_viewer ~mml_of_cic_object
160           (GtkMathViewProps.MathView_GMetaDOM.create p))
161         ?font_size:None ?log_verbosity:None))
162     ?width:None ?height:None []
163