]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/matita.ml
Class mathViewer got rid of. The circular dependency between
[helm.git] / matita / matita / matita.ml
1 (* Copyright (C) 2004-2005, 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://helm.cs.unibo.it/
24  *)
25
26 (* $Id$ *)
27
28 open Printf
29
30 open MatitaGtkMisc
31 open GrafiteTypes
32
33 (** {2 Initialization} *)
34
35 let _ = 
36   MatitaInit.add_cmdline_spec
37     ["-tptppath",Arg.String 
38       (fun s -> Helm_registry.set_string "matita.tptppath" s),
39       "Where to find the Axioms/ and Problems/ directory"];
40   MatitaInit.initialize_all ()
41 ;;
42
43 (* let _ = Saturation.init () (* ALB to link paramodulation *) *)
44
45 (** {2 GUI callbacks} *)
46
47 let gui = MatitaGui.instance ()
48
49 let script =
50   let s = 
51     MatitaScript.script 
52       ~source_view:gui#sourceView
53       ~urichooser:(fun uris ->
54         try
55           MatitaGui.interactive_uri_choice ~selection_mode:`SINGLE
56           ~title:"Matita: URI chooser" 
57           ~msg:"Select the URI" ~hide_uri_entry:true
58           ~hide_try:true ~ok_label:"_Apply" ~ok_action:`SELECT
59           ~copy_cb:(fun s -> gui#sourceView#buffer#insert ("\n"^s^"\n"))
60           () ~id:"boh?" uris
61         with MatitaTypes.Cancel -> [])
62       ~set_star:gui#setStar
63       ~ask_confirmation:
64         (fun ~title ~message -> 
65             MatitaGtkMisc.ask_confirmation ~title ~message 
66             ~parent:gui#main#toplevel ())
67       ()
68   in
69   Predefined_virtuals.load_predefined_virtuals ();
70   Predefined_virtuals.load_predefined_classes ();
71   gui#sourceView#source_buffer#begin_not_undoable_action ();
72   s#reset (); 
73   s#template (); 
74   gui#sourceView#source_buffer#end_not_undoable_action ();
75   s
76   
77   (* math viewers *)
78 let _ =
79   let sequents_viewer = MatitaMathView.sequentsViewer_instance () in
80   sequents_viewer#load_logo;
81   let browser_observer _ = MatitaMathView.refresh_all_browsers () in
82   let sequents_observer grafite_status =
83     sequents_viewer#reset;
84     match grafite_status#ng_mode with
85        `ProofMode ->
86         sequents_viewer#nload_sequents grafite_status;
87         (try
88           script#setGoal
89            (Some (Continuationals.Stack.find_goal grafite_status#stack));
90           let goal =
91            match script#goal with
92               None -> assert false
93             | Some n -> n
94           in
95            sequents_viewer#goto_sequent grafite_status goal
96         with Failure _ -> script#setGoal None);
97      | `CommandMode -> sequents_viewer#load_logo
98   in
99   script#addObserver sequents_observer;
100   script#addObserver browser_observer
101
102   (** {{{ Debugging *)
103 let _ =
104   if BuildTimeConf.debug ||
105      Helm_registry.get_bool "matita.debug_menu" 
106   then begin
107     gui#main#debugMenu#misc#show ();
108     let addDebugItem label callback =
109       let item =
110         GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label () in
111       ignore (item#connect#activate callback) 
112     in
113     let addDebugCheckbox label ?(init=false) callback =
114       let item =
115         GMenu.check_menu_item 
116           ~packing:gui#main#debugMenu_menu#append ~label () in
117       item#set_active init;
118       ignore (item#connect#toggled (callback item)) 
119     in
120     let addDebugSeparator () =
121       ignore (GMenu.separator_item ~packing:gui#main#debugMenu_menu#append ())
122     in
123     addDebugItem "dump aliases" (fun _ ->
124       let status = script#grafite_status in
125       GrafiteDisambiguate.dump_aliases prerr_endline "" status);
126 (* FG: DEBUGGING   
127     addDebugItem "dump interpretations" (fun _ ->
128       let status = script#lexicon_status in
129       let filter = 
130        List.filter (function LexiconAst.Interpretation _ -> true | _ -> false)
131       in
132       HLog.debug (String.concat "\n"
133        (List.fold_right
134          (fun x l -> (LexiconAstPp.pp_command x)::l)
135          (filter status.LexiconEngine.lexicon_content_rev) [])));
136 *)
137     addDebugSeparator ();
138     addDebugCheckbox "high level pretty printer" ~init:true
139       (fun mi () -> assert false (* MATITA 1.0 *));
140     addDebugSeparator ();
141     addDebugItem "always show all disambiguation errors"
142       (fun _ -> MatitaGui.all_disambiguation_passes := true);
143     addDebugItem "prune disambiguation errors"
144       (fun _ -> MatitaGui.all_disambiguation_passes := false);
145     addDebugSeparator ();
146     addDebugCheckbox "multiple disambiguation passes" ~init:true
147       (fun mi () -> MultiPassDisambiguator.only_one_pass := mi#active);
148     addDebugCheckbox "tactics logging" 
149       (fun mi () -> NTacStatus.debug := mi#active);
150     addDebugCheckbox "disambiguation/refiner/unification/metasubst logging"
151       (fun mi () -> NCicRefiner.debug := mi#active; NCicUnification.debug :=
152               mi#active; MultiPassDisambiguator.debug := mi#active; NCicMetaSubst.debug := mi#active);
153     addDebugCheckbox "reduction logging"
154       (fun mi () -> NCicReduction.debug := mi#active);
155     addDebugSeparator ();
156     addDebugItem "Expand virtuals"
157     (fun _ -> (MatitaScript.current ())#expandAllVirtuals);
158   end
159   (** Debugging }}} *)
160
161   (** {2 Main} *)
162
163 let _ =
164   at_exit (fun () -> print_endline "\nThanks for using Matita!\n");
165   Sys.catch_break true;
166   let args = Helm_registry.get_list Helm_registry.string "matita.args" in
167   (try gui#loadScript (List.hd args) with Failure _ -> ());
168   gui#main#mainWin#show ();
169   try
170    GtkThread.main ()
171   with Sys.Break ->
172    Sys.set_signal Sys.sigint
173     (Sys.Signal_handle
174       (fun _ ->
175         prerr_endline "Still cleaning the library: don't be impatient!"));
176    prerr_endline "Matita is cleaning up. Please wait.";
177    let baseuri = 
178     (MatitaScript.current ())#grafite_status#baseuri
179    in
180      LibraryClean.clean_baseuris [baseuri]
181
182 (* vim:set foldmethod=marker: *)