1 (* Copyright (C) 2004, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
30 (** {2 Internal status} *)
32 let (get_proof, set_proof, has_proof) =
33 let (current_proof: MatitaTypes.proof option ref) = ref None in
34 ((fun () -> (* get_proof *)
35 match !current_proof with
37 | None -> failwith "No current proof"),
38 (fun proof -> (* set_proof *)
39 current_proof := proof),
40 (fun () -> (* has_proof *)
41 !current_proof <> None))
45 let debug_print = MatitaTypes.debug_print
48 let domImpl = lazy (Gdome.domImplementation ()) in
51 ((Lazy.force domImpl)#saveDocumentToFile ~doc ~name:dest ~indent:true ())
53 (** {2 Initialization} *)
55 let _ = Helm_registry.load_from "matita.conf.xml"
56 let _ = GMain.Main.init ()
57 let gui = new MatitaGui.gui (Helm_registry.get "matita.glade_file")
58 let parserr = new MatitaDisambiguator.parserr ()
59 let mqiconn = MQIConn.init ()
61 new MatitaDisambiguator.disambiguator ~parserr ~mqiconn
62 ~chooseUris:(interactive_user_uri_choice ~gui)
63 ~chooseInterp:(interactive_interp_choice ~gui)
66 let frame = GBin.frame ~packing:(gui#proof#scrolledProof#add) ~show:true () in
67 MatitaMathView.proof_viewer ~show:true ~packing:(frame#add) ()
68 let sequent_viewer = MatitaMathView.sequent_viewer ~show:true ()
70 let new_proof (proof: MatitaTypes.proof) =
71 let xmldump_observer _ _ = print_endline proof#toString in
72 let proof_observer _ (status, metadata) =
73 debug_print "proof_observer";
74 let (acic, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts,
75 ids_to_inner_types, ids_to_conjectures, ids_to_hypotheses) =
78 let ((uri_opt, _, _, _), _) = status in
79 let uri = MatitaTypes.unopt_uri uri_opt in
80 debug_print "apply transformation";
82 ApplyTransformation.mml_of_cic_object
83 ~explode_all:true uri acic ids_to_inner_sorts ids_to_inner_types
85 if BuildTimeConf.debug then save_dom ~doc:mathml ~dest:"/tmp/matita.xml";
86 proof_viewer#load_proof mathml metadata;
87 debug_print "/proof_observer"
89 let sequents_observer =
91 let callback_id = ref None in
92 let mathmls = ref [] in
93 fun _ ((proof, goal_opt) as status, metadata) ->
94 debug_print "sequents_observer";
95 let notebook = gui#main#sequentsNotebook in
96 for i = 1 to !pages do
97 notebook#remove_page 0
100 (match !callback_id with
101 | Some id -> GtkSignal.disconnect notebook#as_widget id
103 if goal_opt <> None then begin
104 let sequents = snd metadata in
105 let sequents_no = List.length sequents in
106 debug_print (sprintf "sequents no: %d" sequents_no);
107 pages := sequents_no;
108 let widget = sequent_viewer#coerce in
110 (fun (metano, (asequent, _, _, ids_to_inner_sorts, _)) ->
112 (GMisc.label ~text:(sprintf "?%d" metano) ~show:true ())#coerce
114 notebook#append_page ~tab_label widget;
116 (let content_sequent = Cic2content.map_sequent asequent in
118 Sequent2pres.sequent2pres ~ids_to_inner_sorts content_sequent
120 let xmlpres = Box.document_of_box pres_sequent in
121 Xml2Gdome.document_of_xml Misc.domImpl xmlpres)
123 mathmls := (metano, mathml) :: !mathmls)
125 mathmls := List.rev !mathmls;
126 let render_page page =
127 let (metano, mathml) = List.nth !mathmls page in
128 sequent_viewer#load_sequent (Lazy.force mathml) metadata metano
131 (* TODO Zack the "#after" may probably be removed after Luca's fix for
132 * widget not loading documents before being realized *)
133 Some (notebook#connect#after#switch_page ~callback:(fun page ->
134 debug_print "switch_page callback";
137 | Some goal -> (* current goal available, go to corresponding page *)
142 if (metano = goal) then raise Exit;
146 debug_print (sprintf "going to page %d" !page);
147 notebook#goto_page !page;
151 debug_print "/sequents_observer"
153 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
155 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
157 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
160 set_proof (Some proof)
162 let quit () = (* quit program, asking for confirmation if needed *)
163 if not (has_proof ()) ||
164 (ask_confirmation ~gui
165 ~msg:("Proof in progress, are you sure you want to quit?") ())
170 MatitaTypes.not_implemented "Matita.abort_proof"
173 { MatitaTypes.get_proof = get_proof;
174 MatitaTypes.abort_proof = abort_proof;
175 MatitaTypes.has_proof = has_proof;
176 MatitaTypes.new_proof = new_proof;
177 MatitaTypes.quit = quit;
181 let console = gui#console in
182 new MatitaInterpreter.interpreter ~disambiguator ~proof_handler ~console ()
185 gui#setQuitCallback quit;
186 gui#setPhraseCallback interpreter#evalPhrase;
187 gui#main#debugMenu#misc#hide ();
188 ignore (gui#main#newProofMenuItem#connect#activate (fun _ ->
190 not (ask_confirmation ~gui
191 ~msg:("Proof in progress, are you sure you want to start a new one?")
194 () (* abort new proof process *)
196 let input = ask_text ~gui ~msg:"Insert proof goal" ~multiline:true () in
197 let (env, metasenv, expr) =
198 disambiguator#disambiguateTerm (Stream.of_string input)
200 let proof = MatitaProof.proof ~typ:expr ~metasenv () in
205 if BuildTimeConf.debug then begin
206 gui#main#debugMenu#misc#show ();
207 let addDebugItem ~label callback =
209 GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label ()
211 ignore (item#connect#activate callback)
213 addDebugItem "interactive user uri choice" (fun _ ->
216 interactive_user_uri_choice ~gui ~selection_mode:`MULTIPLE
217 ~msg:"messaggio" ~nonvars_button:true
218 ["cic:/uno.con"; "cic:/due.var"; "cic:/tre.con"; "cic:/quattro.con";
221 List.iter prerr_endline uris
222 with MatitaGtkMisc.Cancel -> MatitaTypes.error "no choice");
223 addDebugItem "toggle auto disambiguation" (fun _ ->
224 Helm_registry.set_bool "matita.auto_disambiguation"
225 (not (Helm_registry.get_bool "matita.auto_disambiguation")));
226 addDebugItem "mono line text input" (fun _ ->
227 prerr_endline (ask_text ~gui ~title:"title" ~msg:"message" ()));
228 addDebugItem "multi line text input" (fun _ ->
230 (ask_text ~gui ~title:"title" ~multiline:true ~msg:"message" ()));
231 addDebugItem "dump proof status to stdout" (fun _ ->
232 print_endline ((get_proof ())#toString));
236 let _ = GtkThread.main ()