(* Copyright (C) 2000-2002, HELM Team. * * This file is part of HELM, an Hypertextual, Electronic * Library of Mathematics, developed at the Computer Science * Department, University of Bologna, Italy. * * HELM is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * HELM is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HELM; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * * For details, see the HELM World-Wide-Web page, * http://cs.unibo.it/helm/. *) (***************************************************************************) (* *) (* PROJECT HELM *) (* *) (* 29/01/2003 Claudio Sacerdoti Coen *) (* *) (* *) (***************************************************************************) let debug = false let debug_print s = if debug then prerr_endline s type mml_of_cic_sequent = Cic.metasenv -> int * Cic.context * Cic.term -> Gdome.document * (Cic.annconjecture * ((Cic.id, Cic.term) Hashtbl.t * (Cic.id, Cic.id option) Hashtbl.t * (string, Cic.hypothesis) Hashtbl.t * (Cic.id, string) Hashtbl.t)) type mml_of_cic_object = Cic.obj -> Gdome.document * (Cic.annobj * ((Cic.id, Cic.term) Hashtbl.t * (Cic.id, Cic.id option) Hashtbl.t * (Cic.id, Cic.conjecture) Hashtbl.t * (Cic.id, Cic.hypothesis) Hashtbl.t * (Cic.id, string) Hashtbl.t * (Cic.id, Cic2acic.anntypes) Hashtbl.t)) (* List utility functions *) exception Skip;; let list_map_fail f = let rec aux = function [] -> [] | he::tl -> try let he' = f he in he'::(aux tl) with Skip -> (aux tl) in aux ;; (* End of the list utility functions *) (** A widget to render sequents **) class sequent_viewer ~(mml_of_cic_sequent:mml_of_cic_sequent) obj = object(self) inherit GMathViewAux.multi_selection_math_view obj val mutable current_infos = None (* returns the list of selected terms *) (* selections which are not terms are ignored *) method get_selected_terms = debug_print (string_of_int (List.length self#get_selections)) ; let selections = self#get_selections in list_map_fail (function node -> let xpath = ((node : Gdome.element)#getAttributeNS ~namespaceURI:Misc.helm_ns ~localName:(Gdome.domString "xref"))#to_string in if xpath = "" then assert false (* "ERROR: No xref found!!!" *) else match current_infos with Some (ids_to_terms,_,_) -> let id = xpath in (try Hashtbl.find ids_to_terms id with _ -> raise Skip) | None -> assert false (* "ERROR: No current term!!!" *) ) selections (* returns the list of selected hypotheses *) (* selections which are not hypotheses are ignored *) method get_selected_hypotheses = let selections = self#get_selections in list_map_fail (function node -> let xpath = ((node : Gdome.element)#getAttributeNS ~namespaceURI:Misc.helm_ns ~localName:(Gdome.domString "xref"))#to_string in if xpath = "" then assert false (* "ERROR: No xref found!!!" *) else match current_infos with Some (_,_,ids_to_hypotheses) -> let id = xpath in (try Hashtbl.find ids_to_hypotheses id with _ -> raise Skip) | None -> assert false (* "ERROR: No current term!!!" *) ) selections method load_sequent metasenv sequent = (**** SIAM QUI ****) let sequent_mml,(_,(ids_to_terms,ids_to_father_ids,ids_to_hypotheses,ids_to_inner_sorts)) = mml_of_cic_sequent metasenv sequent in self#load_root ~root:sequent_mml#get_documentElement ; ignore (Misc.domImpl#saveDocumentToFile ~name:"/tmp/pippo" ~doc:sequent_mml ()); current_infos <- Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses) end ;; let sequent_viewer ~(mml_of_cic_sequent: mml_of_cic_sequent) ?hadjustment ?vadjustment ?font_size ?log_verbosity = GtkBase.Widget.size_params ~cont:( OgtkMathViewProps.pack_return (fun p -> OgtkMathViewProps.set_params (new sequent_viewer ~mml_of_cic_sequent (GtkMathViewProps.MathView_GMetaDOM.create p)) ~font_size ~log_verbosity)) [] ;; (* let sequent_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager ?border_width ?width ?height ?packing ?show () = let w = GtkMathView.MathView.create ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth) ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv) () in GtkBase.Container.set w ?border_width ?width ?height; let mathview = GObj.pack_return (new sequent_viewer w) ~packing ~show in begin match font_size with | Some size -> mathview#set_font_size size | None -> () end; begin match font_manager with | Some manager -> mathview#set_font_manager_type ~fm_type:manager | None -> () end; mathview ;; *) (** A widget to render proofs **) class proof_viewer ~(mml_of_cic_object:mml_of_cic_object) obj = object(self) inherit GMathViewAux.single_selection_math_view obj (* initializer self#set_font_size 10 *) val mutable current_infos = None val mutable current_mml = None method make_sequent_of_selected_term = match self#get_selection with Some node -> let xpath = ((node : Gdome.element)#getAttributeNS ~namespaceURI:Misc.helm_ns ~localName:(Gdome.domString "xref"))#to_string in if xpath = "" then assert false (* "ERROR: No xref found!!!" *) else begin match current_infos with Some (ids_to_terms, ids_to_father_ids, _, _) -> let id = xpath in LogicalOperations.to_sequent id ids_to_terms ids_to_father_ids | None -> assert false (* "ERROR: No current term!!!" *) end | None -> assert false (* "ERROR: No selection!!!" *) method focus_sequent_of_selected_term = match self#get_selection with Some node -> let xpath = ((node : Gdome.element)#getAttributeNS ~namespaceURI:Misc.helm_ns ~localName:(Gdome.domString "xref"))#to_string in if xpath = "" then assert false (* "ERROR: No xref found!!!" *) else begin match current_infos with Some (ids_to_terms, ids_to_father_ids, _, _) -> let id = xpath in LogicalOperations.focus id ids_to_terms ids_to_father_ids | None -> assert false (* "ERROR: No current term!!!" *) end | None -> assert false (* "ERROR: No selection!!!" *) method load_proof currentproof = let mml, (acic, (ids_to_terms,ids_to_father_ids,ids_to_conjectures, ids_to_hypotheses,ids_to_inner_sorts,ids_to_inner_types)) = mml_of_cic_object currentproof in current_infos <- Some (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses); (* self#load_doc ~dom:mml ; current_mml <- Some mml ; *) ignore(Misc.domImpl#saveDocumentToFile ~name:"/tmp/prova" ~doc:mml ()); (match current_mml with None -> let time1 = Sys.time () in self#load_root ~root:mml#get_documentElement ; let time2 = Sys.time () in debug_print ("Loading and displaying the proof took " ^ string_of_float (time2 -. time1) ^ "seconds") ; current_mml <- Some mml | Some current_mml' -> self#freeze ; let time1 = Sys.time () in XmlDiff.update_dom ~from:current_mml' mml ; let time2 = Sys.time () in debug_print ("XMLDIFF took " ^ string_of_float (time2 -. time1) ^ "seconds") ; self#thaw ; let time3 = Sys.time () in debug_print ("The refresh of the widget took " ^ string_of_float (time3 -. time2) ^ "seconds")); (acic, ids_to_inner_types, ids_to_inner_sorts) end ;; let proof_viewer ~(mml_of_cic_object: mml_of_cic_object) ?hadjustment ?vadjustment ?font_size ?log_verbosity = GtkBase.Widget.size_params ~cont:( OgtkMathViewProps.pack_return (fun p -> OgtkMathViewProps.set_params (new proof_viewer ~mml_of_cic_object (GtkMathViewProps.MathView_GMetaDOM.create p)) ~font_size ~log_verbosity)) [] ;; (* let proof_viewer ?adjustmenth ?adjustmentv ?font_size ?font_manager ?border_width ?width ?height ?packing ?show () = let w = GtkMathView.MathView.create ?adjustmenth:(Gaux.may_map ~f:GData.as_adjustment adjustmenth) ?adjustmentv:(Gaux.may_map ~f:GData.as_adjustment adjustmentv) () in GtkBase.Container.set w ?border_width ?width ?height; let mathview = GObj.pack_return (new proof_viewer w) ~packing ~show in begin match font_size with | Some size -> mathview#set_font_size size | None -> () end; begin match font_manager with | Some manager -> mathview#set_font_manager_type ~fm_type:manager | None -> () end; mathview ;; *)