text
stringlengths 0
601k
|
---|
module Make ( Node_id : S . NODE_ID ) ( Node : S . NODE with type nid := Node_id . t ) : S . VIEW with type nid := Node_id . t and type node := Node . t = struct let min x y = if x < y then x else y let max x y = if x < y then y else x module I = struct type t = int let compare ( a : int ) b = compare a b end module IntSet = Set . Make ( I ) module View = Map . Make ( Node_id ) type t = Node . t View . t let empty = View . empty let mem = View . mem let find = View . find_opt let length = View . cardinal let is_empty = View . is_empty let filter = View . filter let fold = View . fold let iter = View . iter let map = View . mapi let remove = View . remove let add node t = let nid = Node . id node in View . add nid node t let zero_age t = View . map ( fun node -> Node . zero_age node ) t let inc_age t = View . map ( fun node -> Node . inc_age node ) t let adjust_trust r t = View . map ( fun node -> let node = Node . set_known node false in Node . adjust_trust node r ) t let filter_trust min_trust t = View . filter ( fun _nid node -> min_trust <= Node . trust node ) t let filter_overlap view t = View . filter ( fun nid _node -> not ( View . mem nid view ) ) t let min_trust t = View . fold ( fun _nid node min_trust -> min min_trust ( Node . trust node ) ) t 2 . 0 let max_trust t = View . fold ( fun _nid node max_trust -> max max_trust ( Node . trust node ) ) t ( - 1 . 0 ) let sum_trust t = View . fold ( fun _nid node sum -> sum . + Node . trust node ) t 0 . 0 let oldest t = match View . fold ( fun nid node oldest -> match oldest with | None -> Some ( nid , node , 1 ) | Some ( _onid , onode , _n ) when ( Node . age onode ) < ( Node . age node ) -> Some ( nid , node , 1 ) | Some ( onid , onode , n ) when ( Node . age onode ) = ( Node . age node ) -> let n = n + 1 in let max = 1000 in if float_of_int ( Rng . Int . gen max ) . / float_of_int max < 1 . . / float_of_int n then Some ( nid , node , n ) else Some ( onid , onode , n ) | _ -> oldest ) t None with | Some ( _nid , node , _n ) -> Some node | None -> None let random t = let len = length t in if 0 < len then let r = Rng . Int . gen len in let ( rnode , _ ) = View . fold ( fun _nid node a -> let ( rnode , n ) = a in if ( n = r ) then ( Some node , n + 1 ) else ( rnode , n + 1 ) ) t ( None , 0 ) in rnode else None let rnd ( ) = Float . of_int ( ( Rng . Int . gen 1000 ) + 1 ) . / 1000 . let uniform_sample len t = if len < length t then begin let wlist = View . fold ( fun _nid node lst -> ( node , ( 0 . . - ( Float . log ( rnd ( ) ) ) ) . / ( Node . trust node ) ) :: lst ) t [ ] in let swlist = List . fast_sort ( fun a b -> Float . compare ( snd a ) ( snd b ) ) wlist in let rview = let rec add_head rview swlist = if length rview < len then match swlist with | hd :: tl -> add_head ( add ( fst hd ) rview ) tl | [ ] -> rview else rview in add_head View . empty swlist in rview end else t let weighted_sample len t = if len < length t then begin let wlist = View . fold ( fun _nid node lst -> ( node , ( 0 . . - ( Float . log ( rnd ( ) ) ) ) . / ( Node . trust node ) ) :: lst ) t [ ] in let swlist = List . fast_sort ( fun a b -> Float . compare ( snd a ) ( snd b ) ) wlist in let rview = let rec add_head rview swlist = if length rview < len then match swlist with | hd :: tl -> add_head ( add ( fst hd ) rview ) tl | [ ] -> rview else rview in add_head View . empty swlist in rview end else t let union t1 t2 = View . union ( fun _nid node1 node2 -> let newer_node = if ( Node . version node1 ) < ( Node . version node2 ) then node2 else node1 in let trust = if ( Node . known node1 ) then ( Node . trust node1 ) else if ( Node . known node2 ) then ( Node . trust node2 ) else max ( Node . trust node1 ) ( Node . trust node2 ) in Some ( Node . set_trust newer_node trust ) ) t1 t2 let choose_view x y = if View . is_empty x then y else if View . is_empty y then x else if 0 = Rng . Int . gen 1 then x else y let to_list t = List . map ( fun ( _nid , node ) -> node ) ( View . bindings t ) let of_list l = List . fold_left ( fun t node -> add node t ) empty l let pp ppf t = View . iter ( fun _nid node -> Fmt . pf ppf " - % a \ n " Node . pp node ) t end |
let list_modules ~ path = List . fold_left path ~ init [ ] : ~ f : begin fun modules dir -> let l = List . filter ( Useunix . get_files_in_directory dir ) ~ f ( : fun x -> Filename . check_suffix x " . cmi " ) in let l = List . map l ~ f : begin fun x -> String . capitalize ( Filename . chop_suffix x " . cmi " ) end in List . fold_left l ~ init : modules ~ f ( : fun modules item -> if List . mem item modules then modules else item :: modules ) end |
let reset_modules box = Listbox . delete box ~ first ( ` : Num 0 ) ~ last ` : End ; module_list := Sort . list ( Jg_completion . lt_string ~ nocase : true ) ( list_modules ~ path :! Config . load_path ) ; Listbox . insert box ~ index ` : End ~ texts :! module_list ; Jg_box . recenter box ~ index ( ` : Num 0 ) |
let view_symbol ~ kind ~ env ? path id = let name = match id with Lident x -> x | Ldot ( _ , x ) -> x | _ -> match kind with Pvalue | Ptype | Plabel -> " z " | _ -> " Z " in match kind with Pvalue -> let path , vd = lookup_value id env in view_signature_item ~ path ~ env [ Tsig_value ( Ident . create name , vd ) ] | Ptype -> view_type_id id ~ env | Plabel -> let ld = lookup_label id env in begin match ld . lbl_res . desc with Tconstr ( path , _ , _ ) -> view_type_decl path ~ env | _ -> ( ) end | Pconstructor -> let cd = lookup_constructor id env in begin match cd . cstr_res . desc with Tconstr ( cpath , _ , _ ) -> if Path . same cpath Predef . path_exn then view_signature ~ title ( : string_of_longident id ) ~ env ? path [ Tsig_exception ( Ident . create name , cd . cstr_args ) ] else view_type_decl cpath ~ env | _ -> ( ) end | Pmodule -> view_module_id id ~ env | Pmodtype -> view_modtype_id id ~ env | Pclass -> view_class_id id ~ env | Pcltype -> view_cltype_id id ~ env |
let choose_symbol ~ title ~ env ? signature ? path l = if match path with None -> false | Some path -> is_shown_module path then ( ) else let tl = Jg_toplevel . titled title in Jg_bind . escape_destroy tl ; top_widgets := coe tl :: ! top_widgets ; let buttons = Frame . create tl in let all = Button . create buttons ~ text " : Show all " ~ padx : 20 and ok = Jg_button . create_destroyer tl ~ parent : buttons and detach = Button . create buttons ~ text " : Detach " and edit = Button . create buttons ~ text " : Impl " and intf = Button . create buttons ~ text " : Intf " in let l = List . sort l ~ cmp ( : fun ( li1 , _ ) ( li2 , _ ) -> compare li1 li2 ) in let nl = List . map l ~ f : begin fun ( li , k ) -> string_of_longident li ^ " ( " ^ string_of_kind k ^ " ) " end in let fb = Frame . create tl in let box = new Jg_multibox . c fb ~ cols : 3 ~ texts : nl ~ maxheight : 3 ~ width : 21 in box # init ; box # bind_kbd ~ events [ ` : KeyPressDetail " Escape " ] ~ action ( : fun _ ~ index -> destroy tl ; break ( ) ) ; if List . length nl > 9 then ignore ( Jg_multibox . add_scrollbar box ) ; Jg_multibox . add_completion box ~ action : begin fun pos -> let li , k = List . nth l pos in let path = match path , li with None , Ldot ( lip , _ ) -> begin try Some ( fst ( lookup_module lip env ) ) with Not_found -> None end | _ -> path in view_symbol li ~ kind : k ~ env ? path end ; pack [ buttons ] ~ side ` : Bottom ~ fill ` : X ; pack [ fb ] ~ side ` : Top ~ fill ` : Both ~ expand : true ; begin match signature with None -> pack [ ok ] ~ fill ` : X ~ expand : true | Some signature -> Button . configure all ~ command : begin fun ( ) -> view_signature signature ~ title ~ env ? path end ; pack [ ok ; all ] ~ side ` : Right ~ fill ` : X ~ expand : true end ; begin match path with None -> ( ) | Some path -> let frame = Frame . create tl in pack [ frame ] ~ side ` : Bottom ~ fill ` : X ; add_shown_module path ~ widgets { : mw_frame = frame ; mw_title = None ; mw_detach = detach ; mw_edit = edit ; mw_intf = intf } end |
let choose_symbol_ref = ref choose_symbol |
let guess_search_mode s : [ ` Type | ` Long | ` Pattern ] = let is_type = ref false and is_long = ref false in for i = 0 to String . length s - 2 do if s . [ i ] = ' ' - && s . [ i + 1 ] = ' ' > then is_type := true ; if s . [ i ] = ' . ' then is_long := true done ; if ! is_type then ` Type else if ! is_long then ` Long else ` Pattern |
let search_string ( ? mode " = symbol " ) ew = let text = Entry . get ew in try if text = " " then ( ) else let l = match mode with " Name " -> begin match guess_search_mode text with ` Long -> search_string_symbol text | ` Pattern -> search_pattern_symbol text | ` Type -> search_string_type text ~ mode ` : Included end | " Type " -> search_string_type text ~ mode ` : Included | " Exact " -> search_string_type text ~ mode ` : Exact | _ -> assert false in match l with [ ] -> ( ) | [ lid , kind ] -> view_symbol lid ~ kind ~ env :! start_env | l -> choose_symbol ~ title " : Choose symbol " ~ env :! start_env l with Searchid . Error ( s , e ) -> Entry . icursor ew ~ index ( ` : Num s ) |
let search_which = ref " Name " |
let search_symbol ( ) = if ! module_list = [ ] then module_list := List . sort ~ cmp : compare ( list_modules ~ path :! Config . load_path ) ; let tl = Jg_toplevel . titled " Search symbol " in Jg_bind . escape_destroy tl ; let ew = Entry . create tl ~ width : 30 in let choice = Frame . create tl and which = Textvariable . create ~ on : tl ( ) in let itself = Radiobutton . create choice ~ text " : Itself " ~ variable : which ~ value " : Name " and extype = Radiobutton . create choice ~ text " : Exact type " ~ variable : which ~ value " : Exact " and iotype = Radiobutton . create choice ~ text " : Included type " ~ variable : which ~ value " : Type " and buttons = Frame . create tl in let search = Button . create buttons ~ text " : Search " ~ command : begin fun ( ) -> search_which := Textvariable . get which ; search_string ew ~ mode :! search_which end and ok = Jg_button . create_destroyer tl ~ parent : buttons ~ text " : Cancel " in Focus . set ew ; Jg_bind . return_invoke ew ~ button : search ; Textvariable . set which ! search_which ; pack [ itself ; extype ; iotype ] ~ side ` : Left ~ anchor ` : W ; pack [ search ; ok ] ~ side ` : Left ~ fill ` : X ~ expand : true ; pack [ coe ew ; coe choice ; coe buttons ] ~ side ` : Top ~ fill ` : X ~ expand : true |
let ident_of_decl ~ modlid = function Tsig_value ( id , _ ) -> Lident ( Ident . name id ) , Pvalue | Tsig_type ( id , _ , _ ) -> Lident ( Ident . name id ) , Ptype | Tsig_exception ( id , _ ) -> Ldot ( modlid , Ident . name id ) , Pconstructor | Tsig_module ( id , _ , _ ) -> Lident ( Ident . name id ) , Pmodule | Tsig_modtype ( id , _ ) -> Lident ( Ident . name id ) , Pmodtype | Tsig_class ( id , _ , _ ) -> Lident ( Ident . name id ) , Pclass | Tsig_cltype ( id , _ , _ ) -> Lident ( Ident . name id ) , Pcltype |
let view_defined ~ env ( ? show_all = false ) modlid = try match lookup_module modlid env with path , Tmty_signature sign -> let rec iter_sign sign idents = match sign with [ ] -> List . rev idents | decl :: rem -> let rem = match decl , rem with Tsig_class _ , cty :: ty1 :: ty2 :: rem -> rem | Tsig_cltype _ , ty1 :: ty2 :: rem -> rem | _ , rem -> rem in iter_sign rem ( ident_of_decl ~ modlid decl :: idents ) in let l = iter_sign sign [ ] in let title = string_of_path path in let env = open_signature path sign env in ! choose_symbol_ref l ~ title ~ signature : sign ~ env ~ path ; if show_all then view_signature sign ~ title ~ env ~ path | _ -> ( ) with Not_found -> ( ) | Env . Error err -> let tl , tw , finish = Jg_message . formatted ~ title " : Error " ! ( ) in Env . report_error Format . std_formatter err ; finish ( ) |
let close_all_views ( ) = List . iter ! top_widgets ~ f ( : fun tl -> try destroy tl with Protocol . TkError _ -> ( ) ) ; top_widgets := [ ] |
let shell_counter = ref 1 |
let default_shell = ref " ocaml " |
let start_shell master = let tl = Jg_toplevel . titled " Start New Shell " in Wm . transient_set tl ~ master ; let input = Frame . create tl and buttons = Frame . create tl in let ok = Button . create buttons ~ text " : Ok " and cancel = Jg_button . create_destroyer tl ~ parent : buttons ~ text " : Cancel " and labels = Frame . create input and entries = Frame . create input in let l1 = Label . create labels ~ text " : Command " : and l2 = Label . create labels ~ text " : Title " : and e1 = Jg_entry . create entries ~ command ( : fun _ -> Button . invoke ok ) and e2 = Jg_entry . create entries ~ command ( : fun _ -> Button . invoke ok ) and names = List . map ~ f : fst ( Shell . get_all ( ) ) in Entry . insert e1 ~ index ` : End ~ text :! default_shell ; let shell_name ( ) = " Shell " # ^ string_of_int ! shell_counter in while List . mem ( shell_name ( ) ) names do incr shell_counter done ; Entry . insert e2 ~ index ` : End ~ text ( : shell_name ( ) ) ; Button . configure ok ~ command ( : fun ( ) -> if not ( List . mem ( Entry . get e2 ) names ) then begin default_shell := Entry . get e1 ; Shell . f ~ prog :! default_shell ~ title ( : Entry . get e2 ) ; destroy tl end ) ; pack [ l1 ; l2 ] ~ side ` : Top ~ anchor ` : W ; pack [ e1 ; e2 ] ~ side ` : Top ~ fill ` : X ~ expand : true ; pack [ labels ; entries ] ~ side ` : Left ~ fill ` : X ~ expand : true ; pack [ ok ; cancel ] ~ side ` : Left ~ fill ` : X ~ expand : true ; pack [ input ; buttons ] ~ side ` : Top ~ fill ` : X ~ expand : true |
let show_help ( ) = let tl = Jg_toplevel . titled " OCamlBrowser Help " in Jg_bind . escape_destroy tl ; let fw , tw , sb = Jg_text . create_with_scrollbar tl in let ok = Jg_button . create_destroyer ~ parent : tl ~ text " : Ok " tl in Text . insert tw ~ index : tend ~ text : Help . text ; Text . configure tw ~ state ` : Disabled ; Jg_bind . enter_focus tw ; pack [ tw ] ~ side ` : Left ~ fill ` : Both ~ expand : true ; pack [ sb ] ~ side ` : Right ~ fill ` : Y ; pack [ fw ] ~ side ` : Top ~ expand : true ~ fill ` : Both ; pack [ ok ] ~ side ` : Bottom ~ fill ` : X |
let f ( ? dir = Unix . getcwd ( ) ) ? on ( ) = let ( top , tl ) = match on with None -> let tl = Jg_toplevel . titled " Module viewer " in ignore ( Jg_bind . escape_destroy tl ) ; ( tl , coe tl ) | Some top -> Wm . title_set top " OCamlBrowser " ; Wm . iconname_set top " OCamlBrowser " ; let tl = Frame . create top in bind tl ~ events [ ` : Destroy ] ~ action ( : fun _ -> exit 0 ) ; pack [ tl ] ~ expand : true ~ fill ` : Both ; ( top , coe tl ) in let menus = Jg_menu . menubar top in let filemenu = new Jg_menu . c " File " ~ parent : menus and modmenu = new Jg_menu . c " Modules " ~ parent : menus in let fmbox , mbox , msb = Jg_box . create_with_scrollbar tl in Jg_box . add_completion mbox ~ nocase : true ~ action : begin fun index -> view_defined ( Lident ( Listbox . get mbox ~ index ) ) ~ env :! start_env end ; Setpath . add_update_hook ( fun ( ) -> reset_modules mbox ) ; let ew = Entry . create tl in let buttons = Frame . create tl in let search = Button . create buttons ~ text " : Search " ~ pady : 1 ~ command ( : fun ( ) -> search_string ew ) and close = Button . create buttons ~ text " : Close all " ~ pady : 1 ~ command : close_all_views in Jg_bind . enter_focus ew ; Jg_bind . return_invoke ew ~ button : search ; bind close ~ events [ ` : Modified ( [ ` Double ] , ` ButtonPressDetail 1 ) ] ~ action ( : fun _ -> destroy tl ) ; filemenu # add_command " Open . . . " ~ command ( : fun ( ) -> ! editor_ref ~ opendialog : true ( ) ) ; filemenu # add_command " Editor . . . " ~ command ( : fun ( ) -> ! editor_ref ( ) ) ; filemenu # add_command " Shell . . . " ~ command ( : fun ( ) -> start_shell tl ) ; filemenu # add_command " Quit " ~ command ( : fun ( ) -> destroy tl ) ; modmenu # add_command " Path editor . . . " ~ command ( : fun ( ) -> Setpath . set ~ dir ) ; modmenu # add_command " Reset cache " ~ command ( : fun ( ) -> reset_modules mbox ; Env . reset_cache ( ) ) ; modmenu # add_command " Search symbol . . . " ~ command : search_symbol ; pack [ close ; search ] ~ fill ` : X ~ side ` : Right ~ expand : true ; pack [ coe buttons ; coe ew ] ~ fill ` : X ~ side ` : Bottom ; pack [ msb ] ~ side ` : Right ~ fill ` : Y ; pack [ mbox ] ~ side ` : Left ~ fill ` : Both ~ expand : true ; pack [ fmbox ] ~ fill ` : Both ~ expand : true ~ side ` : Top ; reset_modules mbox let ( top , tl ) = match on with None -> let tl = Jg_toplevel . titled " Module viewer " in ignore ( Jg_bind . escape_destroy tl ) ; ( tl , coe tl ) | Some top -> Wm . title_set top " OCamlBrowser " ; Wm . iconname_set top " OCamlBrowser " ; let tl = Frame . create top in bind tl ~ events [ ` : Destroy ] ~ action ( : fun _ -> exit 0 ) ; pack [ tl ] ~ side ` : Bottom ~ expand : true ~ fill ` : Both ; ( top , coe tl ) in let menus = Menu . create top ~ name " : menubar " ~ typ ` : Menubar in let ( ) = Toplevel . configure top ~ menu : menus in let filemenu = new Jg_menu . c " File " ~ parent : menus and modmenu = new Jg_menu . c " Modules " ~ parent : menus and viewmenu = new Jg_menu . c " View " ~ parent : menus and helpmenu = new Jg_menu . c " Help " ~ parent : menus in let search_frame = Frame . create tl in let boxes_frame = Frame . create tl ~ name " : boxes " in let label = Label . create tl ~ anchor ` : W ~ padx : 5 in let view = Frame . create tl in let buttons = Frame . create tl in let _all = Button . create buttons ~ text " : Show all " ~ padx : 20 and close = Button . create buttons ~ text " : Close all " ~ command : close_all_views and detach = Button . create buttons ~ text " : Detach " and edit = Button . create buttons ~ text " : Impl " and intf = Button . create buttons ~ text " : Intf " in val mutable boxes = [ ] val mutable show_all = fun ( ) -> ( ) method create_box = let fmbox , mbox , sb = Jg_box . create_with_scrollbar boxes_frame in bind mbox ~ events [ ` : Modified ( [ ` Double ] , ` ButtonPressDetail 1 ) ] ~ action ( : fun _ -> show_all ( ) ) ; bind mbox ~ events [ ` : Modified ( [ ` Double ] , ` KeyPressDetail " Return " ) ] ~ action ( : fun _ -> show_all ( ) ) ; boxes <- boxes @ [ fmbox , mbox ] ; pack [ sb ] ~ side ` : Right ~ fill ` : Y ; pack [ mbox ] ~ side ` : Left ~ fill ` : Both ~ expand : true ; pack [ fmbox ] ~ side ` : Left ~ fill ` : Both ~ expand : true ; fmbox , mbox initializer let ew = Entry . create search_frame and searchtype = Textvariable . create ~ on : tl ( ) in bind ew ~ events [ ` : KeyPressDetail " Return " ] ~ action : ( fun _ -> search_string ew ~ mode ( : Textvariable . get searchtype ) ) ; Jg_bind . enter_focus ew ; let search_button ? value text = Radiobutton . create search_frame ~ text ~ variable : searchtype ~ value : text in let symbol = search_button " Name " and atype = search_button " Type " in Radiobutton . select symbol ; pack [ Label . create search_frame ~ text " : Search " ] ~ side ` : Left ~ ipadx : 5 ; pack [ ew ] ~ fill ` : X ~ expand : true ~ side ` : Left ; pack [ Label . create search_frame ~ text " : by " ] ~ side ` : Left ~ ipadx : 5 ; pack [ symbol ; atype ] ~ side ` : Left ; pack [ Label . create search_frame ] ~ side ` : Right initializer let fmbox , mbox = self # create_box in Jg_box . add_completion mbox ~ nocase : true ~ double : false ~ action : begin fun index -> view_defined ( Lident ( Listbox . get mbox ~ index ) ) ~ env :! start_env end ; Setpath . add_update_hook ( fun ( ) -> reset_modules mbox ; self # hide_after 1 ) ; List . iter [ 1 ; 2 ] ~ f ( : fun _ -> ignore self # create_box ) ; Searchpos . default_frame := Some { mw_frame = view ; mw_title = Some label ; mw_detach = detach ; mw_edit = edit ; mw_intf = intf } ; Searchpos . set_path := self # set_path ; pack [ close ] ~ side ` : Right ~ fill ` : X ~ expand : true ; bind close ~ events [ ` : Modified ( [ ` Double ] , ` ButtonPressDetail 1 ) ] ~ action ( : fun _ -> destroy tl ) ; filemenu # add_command " Open . . . " ~ command ( : fun ( ) -> ! editor_ref ~ opendialog : true ( ) ) ; filemenu # add_command " Editor . . . " ~ command ( : fun ( ) -> ! editor_ref ( ) ) ; filemenu # add_command " Shell . . . " ~ command ( : fun ( ) -> start_shell tl ) ; filemenu # add_command " Quit " ~ command ( : fun ( ) -> destroy tl ) ; viewmenu # add_command " Show all defs " ~ command ( : fun ( ) -> show_all ( ) ) ; let show_search = Textvariable . create ~ on : tl ( ) in Textvariable . set show_search " 1 " ; Menu . add_checkbutton viewmenu # menu ~ label " : Search Entry " ~ variable : show_search ~ indicatoron : true ~ state ` : Active ~ command : begin fun ( ) -> let v = Textvariable . get show_search in if v = " 1 " then begin pack [ search_frame ] ~ after : menus ~ fill ` : X end else Pack . forget [ search_frame ] end ; modmenu # add_command " Path editor . . . " ~ command ( : fun ( ) -> Setpath . set ~ dir ) ; modmenu # add_command " Reset cache " ~ command ( : fun ( ) -> reset_modules mbox ; Env . reset_cache ( ) ) ; modmenu # add_command " Search symbol . . . " ~ command : search_symbol ; helpmenu # add_command " Manual . . . " ~ command : show_help ; pack [ search_frame ] ~ fill ` : X ; pack [ boxes_frame ] ~ fill ` : Both ~ expand : true ; pack [ buttons ] ~ fill ` : X ~ side ` : Bottom ; pack [ view ] ~ fill ` : Both ~ side ` : Bottom ~ expand : true ; reset_modules mbox val mutable shown_paths = [ ] method hide_after n = for i = n to List . length boxes - 1 do let fm , box = List . nth boxes i in if i < 3 then Listbox . delete box ~ first ( ` : Num 0 ) ~ last ` : End else destroy fm done ; let rec firsts n = function [ ] -> [ ] | a :: l -> if n > 0 then a :: firsts ( pred n ) l else [ ] in shown_paths <- firsts ( n - 1 ) shown_paths ; boxes <- firsts ( max 3 n ) boxes method get_box ~ path = let rec path_index p = function [ ] -> raise Not_found | a :: l -> if Path . same p a then 1 else path_index p l + 1 in try let n = path_index path shown_paths in self # hide_after ( n + 1 ) ; n with Not_found -> match path with Path . Pdot ( path ' , _ , _ ) -> let n = self # get_box ~ path : path ' in shown_paths <- shown_paths @ [ path ] ; if n + 1 >= List . length boxes then ignore self # create_box ; n + 1 | _ -> self # hide_after 2 ; shown_paths <- [ path ] ; 1 method set_path path ~ sign = let rec path_elems l path = match path with Path . Pdot ( path , _ , _ ) -> path_elems ( path :: l ) path | _ -> [ ] in let path_elems path = match path with | Path . Pident _ -> [ path ] | _ -> path_elems [ ] path in let see_path ~ box : n ( ? sign [ ] ) = path = let ( _ , box ) = List . nth boxes n in let texts = Listbox . get_range box ~ first ( ` : Num 0 ) ~ last ` : End in let rec index s = function [ ] -> raise Not_found | a :: l -> if a = s then 0 else 1 + index s l in try let modlid , s = match path with Path . Pdot ( p , s , _ ) -> longident_of_path p , s | Path . Pident i -> Longident . Lident " M " , Ident . name i | _ -> assert false in let li , k = if sign = [ ] then Longident . Lident s , Pmodule else ident_of_decl ~ modlid ( List . hd sign ) in let s = if n = 0 then string_of_longident li else string_of_longident li ^ " ( " ^ string_of_kind k ^ " ) " in let n = index s texts in Listbox . see box ( ` Num n ) ; Listbox . activate box ( ` Num n ) with Not_found -> ( ) in let l = path_elems path in if l <> [ ] then begin List . iter l ~ f : begin fun path -> if not ( List . mem path shown_paths ) then view_symbol ( longident_of_path path ) ~ kind : Pmodule ~ env : Env . initial ~ path ; let n = self # get_box path - 1 in see_path path ~ box : n end ; see_path path ~ box ( : self # get_box path ) ~ sign end method choose_symbol ~ title ~ env ? signature ? path l = let n = match path with None -> 1 | Some path -> self # get_box ~ path in let l = List . sort l ~ cmp ( : fun ( li1 , _ ) ( li2 , _ ) -> compare li1 li2 ) in let nl = List . map l ~ f : begin fun ( li , k ) -> string_of_longident li ^ " ( " ^ string_of_kind k ^ " ) " end in let _ , box = List . nth boxes n in Listbox . delete box ~ first ( ` : Num 0 ) ~ last ` : End ; Listbox . insert box ~ index ` : End ~ texts : nl ; let current = ref None in let display index = let ` Num pos = Listbox . index box ~ index in try let li , k = List . nth l pos in self # hide_after ( n + 1 ) ; if ! current = Some ( li , k ) then ( ) else let path = match path , li with None , Ldot ( lip , _ ) -> begin try Some ( fst ( lookup_module lip env ) ) with Not_found -> None end | _ -> path in current := Some ( li , k ) ; view_symbol li ~ kind : k ~ env ? path with Failure " nth " -> ( ) in Jg_box . add_completion box ~ double : false ~ action : display ; bind box ~ events [ ` : KeyRelease ] ~ fields [ ` : Char ] ~ action ( : fun ev -> display ` Active ) ; begin match signature with None -> ( ) | Some signature -> show_all <- begin fun ( ) -> current := None ; view_signature signature ~ title ~ env ? path end end end |
let st_viewer ? dir ? on ( ) = let viewer = new st_viewer ? dir ? on ( ) in choose_symbol_ref := viewer # choose_symbol |
let pi = 4 . . * atan 1 . |
module F ( M : sig type font type color type text val white : color type ctx val save : ctx -> unit val restore : ctx -> unit val scale : ctx -> sx : float -> sy : float -> unit val translate : ctx -> tx : float -> ty : float -> unit val begin_path : ctx -> unit val close_path : ctx -> unit val move_to : ctx -> x : float -> y : float -> unit val line_to : ctx -> x : float -> y : float -> unit val curve_to : ctx -> x1 : float -> y1 : float -> x2 : float -> y2 : float -> x3 : float -> y3 : float -> unit val arc : ctx -> xc : float -> yc : float -> radius : float -> angle1 : float -> angle2 : float -> unit val rectangle : ctx -> x : float -> y : float -> width : float -> height : float -> unit val fill : ctx -> color -> unit val stroke : ctx -> color -> unit val clip : ctx -> unit val draw_text : ctx -> float -> float -> text -> font -> color option -> color option -> unit type window type drawable type pixmap val get_drawable : window -> drawable val make_pixmap : window -> int -> int -> pixmap val drawable_of_pixmap : pixmap -> drawable val get_context : pixmap -> ctx val put_pixmap : dst : drawable -> x : int -> y : int -> xsrc : int -> ysrc : int -> width : int -> height : int -> pixmap -> unit type rectangle = { x : int ; y : int ; width : int ; height : int } val compute_extents : ctx -> ( color , font , text ) Scene . element array -> ( float * float * float * float ) array struct open M let empty_rectangle = { x = 0 ; y = 0 ; width = 0 ; height = 0 } let rectangle_is_empty r = r . width = 0 || r . height = 0 type pixmap = { mutable pixmap : M . pixmap option ; mutable p_width : int ; mutable p_height : int ; mutable valid_rect : rectangle } let make_pixmap ( ) = { pixmap = None ; p_width = 0 ; p_height = 0 ; valid_rect = empty_rectangle } let invalidate_pixmap p = p . valid_rect <- empty_rectangle let grow_pixmap pm window width height = let width = max width pm . p_width in let height = max height pm . p_height in if width > pm . p_width || height > pm . p_height then ( let old_p = pm . pixmap in let p = M . make_pixmap window width height in let r = pm . valid_rect in ( match old_p with | Some old_p -> put_pixmap ~ dst ( : drawable_of_pixmap p ) ~ x : 0 ~ y : 0 ~ xsrc : 0 ~ ysrc : 0 ~ width : r . width ~ height : r . height old_p | None -> ( ) ) ; pm . pixmap <- Some p ; pm . p_width <- width ; pm . p_height <- height ) let get_pixmap pm = match pm . pixmap with | Some p -> p | None -> assert false type st = { mutable bboxes : ( float * float * float * float ) array ; scene : ( color , font , text ) Scene . element array ; mutable zoom_factor : float ; st_x : float ; st_y : float ; st_width : float ; st_height : float ; st_pixmap : pixmap } let perform_draw ctx fill stroke = ( match fill with | Some c -> M . fill ctx c | None -> ( ) ) ; match stroke with | Some c -> M . stroke ctx c | None -> ( ) let draw_element ctx e = begin_path ctx ; match e with | Path ( cmd , fill , stroke ) -> Array . iter ( fun c -> match c with | Move_to ( x , y ) -> move_to ctx ~ x ~ y | Curve_to ( x1 , y1 , x2 , y2 , x3 , y3 ) -> curve_to ctx ~ x1 ~ y1 ~ x2 ~ y2 ~ x3 ~ y3 ) cmd ; perform_draw ctx fill stroke | Ellipse ( cx , cy , rx , ry , fill , stroke ) -> save ctx ; translate ctx ~ tx : cx ~ ty : cy ; scale ctx ~ sx : rx ~ sy : ry ; arc ctx ~ xc : 0 . ~ yc : 0 . ~ radius : 1 . ~ angle1 : 0 . ~ angle2 ( : 2 . . * pi ) ; restore ctx ; perform_draw ctx fill stroke | Polygon ( points , fill , stroke ) -> Array . iteri ( fun i ( x , y ) -> if i = 0 then move_to ctx ~ x ~ y else line_to ctx ~ x ~ y ) points ; close_path ctx ; perform_draw ctx fill stroke | Text ( x , y , txt , font , fill , stroke ) -> draw_text ctx x y txt font fill stroke let intersects ( ( x1 , y1 , x2 , y2 ) : float * float * float * float ) ( x3 , y3 , x4 , y4 ) = x1 <= x4 && y1 <= y4 && x3 <= x2 && y3 <= y2 let redraw st scale x y x ' y ' w h = let ctx = get_context ( get_pixmap st . st_pixmap ) in save ctx ; if Array . length st . bboxes = 0 && Array . length st . scene > 0 then st . bboxes <- compute_extents ctx st . scene ; begin_path ctx ; rectangle ctx ~ x ( : float x ' ) ~ y ( : float y ' ) ~ width ( : float w ) ~ height ( : float h ) ; M . fill ctx M . white ; clip ctx ; let x = float x . / scale in let y = float y . / scale in M . scale ctx ~ sx : scale ~ sy : scale ; translate ctx ~ tx ( . :- st . st_x . - x ) ~ ty ( . :- st . st_y . - y ) ; let bbox = let x = st . st_x . + x . + ( float x ' . / scale ) in let y = st . st_y . + y . + ( float y ' . / scale ) in ( x , y , x . + ( float st . st_pixmap . p_width . / scale ) , y . + ( float st . st_pixmap . p_height . / scale ) ) in for i = 0 to Array . length st . scene - 1 do let box = st . bboxes . ( i ) in let e = st . scene . ( i ) in if intersects box bbox then draw_element ctx e done ; restore ctx let redraw st scale x0 y0 window a x y width height = let pm = st . st_pixmap in grow_pixmap pm window a . width a . height ; let round x = truncate ( ( x . * scale ) . + 0 . 5 ) in let x0 = round x0 in let x0 ' = round ( ( ( float a . width . / scale ) . - st . st_width ) . / 2 . ) in let x0 = if x0 ' > 0 then - x0 ' else x0 in let y0 = round y0 in let y0 ' = round ( ( ( float a . height . / scale ) . - st . st_height ) . / 2 . ) in let y0 = if y0 ' > 0 then - y0 ' else y0 in let dx = pm . valid_rect . x - x0 in let dy = pm . valid_rect . y - y0 in if ( dx > 0 && pm . valid_rect . width + dx < a . width ) || ( dy > 0 && pm . valid_rect . height + dy < a . height ) then pm . valid_rect <- empty_rectangle else if not ( rectangle_is_empty pm . valid_rect ) then ( let p = get_pixmap pm in let r = pm . valid_rect in if dx <> 0 || dy <> 0 then put_pixmap ~ dst ( : drawable_of_pixmap p ) ~ x : dx ~ y : dy ~ xsrc : 0 ~ ysrc : 0 ~ width : r . width ~ height : r . height p ; let offset p l d m = if p + d + l <= 0 then 0 , 0 else if p + d < 0 then 0 , l + p + d else if p + d >= m then m , 0 else if p + d + l > m then p + d , m - p - d else p + d , l in let x , width = offset 0 r . width dx pm . p_width in let y , height = offset 0 r . height dy pm . p_height in if height > 0 then if x > 0 then ( assert ( x + width >= a . width ) ; redraw st scale x0 y0 0 y x height ) else ( assert ( x = 0 ) ; if a . width > width then redraw st scale x0 y0 width y ( a . width - width ) height ) ; if y > 0 then ( assert ( y + height >= a . height ) ; redraw st scale x0 y0 0 0 a . width y ) else ( assert ( y = 0 ) ; if a . height > height then redraw st scale x0 y0 0 height a . width ( a . height - height ) ) ; pm . valid_rect <- { x = x0 ; y = y0 ; width = a . width ; height = a . height } ) ; let r = pm . valid_rect in if x < 0 || y < 0 || x + width > r . width || y + height > r . height then ( redraw st scale x0 y0 0 0 a . width a . height ; pm . valid_rect <- { x = x0 ; y = y0 ; width = a . width ; height = a . height } ) ; put_pixmap ~ dst ( : get_drawable window ) ~ x ~ y ~ xsrc : x ~ ysrc : y ~ width ~ height ( get_pixmap pm ) end |
type rect = { x : int ; y : int ; width : int ; height : int } |
let create_canvas w h = let c = Html . createCanvas Html . document in c . ## width := w ; c . ## height := h ; c |
module Common = Viewer_common . F ( struct type font = Js . js_string Js . t type color = Js . js_string Js . t type text = Js . js_string Js . t let white = Js . string " white " type ctx = Html . canvasRenderingContext2D Js . t let save ctx = ctx ## save let restore ctx = ctx ## restore let scale ctx ~ sx ~ sy = ctx ## scale sx sy let translate ctx ~ tx ~ ty = ctx ## translate tx ty let begin_path ctx = ctx ## beginPath let close_path ctx = ctx ## closePath let move_to ctx ~ x ~ y = ctx ## moveTo x y let line_to ctx ~ x ~ y = ctx ## lineTo x y let curve_to ctx ~ x1 ~ y1 ~ x2 ~ y2 ~ x3 ~ y3 = ctx ## bezierCurveTo x1 y1 x2 y2 x3 y3 let arc ctx ~ xc ~ yc ~ radius ~ angle1 ~ angle2 = ctx ## arc xc yc radius angle1 angle2 Js . _true let rectangle ctx ~ x ~ y ~ width ~ height = ctx ## rect x y width height let fill ctx c = ctx . ## fillStyle := c ; ctx ## fill let stroke ctx c = ctx . ## strokeStyle := c ; ctx ## stroke let clip ctx = ctx ## clip let draw_text ( ctx : ctx ) x y txt font fill_color stroke_color = ctx . ## font := font ; ctx . ## textAlign := Js . string " center " ; ctx . ## textBaseline := Js . string " middle " ; ( match fill_color with | Some c -> ctx . ## fillStyle := c ; ctx ## fillText txt x y | None -> ( ) ) ; match stroke_color with | Some c -> ctx . ## strokeStyle := c ; ctx ## strokeText txt x y | None -> ( ) type window = Html . canvasElement Js . t type drawable = window * ctx type pixmap = drawable let get_drawable w = let ctx = w ## getContext Html . _2d_ in ctx . ## lineWidth := 2 . ; w , ctx let make_pixmap _ width height = let c = Html . createCanvas Html . document in c . ## width := width ; c . ## height := height ; get_drawable c let drawable_of_pixmap p = p let get_context ( _p , c ) = c let put_pixmap ~ dst ( ( : _p , c ) : drawable ) ~ x ~ y ~ xsrc ~ ysrc ~ width ~ height ( ( p , _ ) : pixmap ) = c ## drawImage_fullFromCanvas p ( float xsrc ) ( float ysrc ) ( float width ) ( float height ) ( float x ) ( float y ) ( float width ) ( float height ) type rectangle = rect = { x : int ; y : int ; width : int ; height : int } let compute_extents _ = assert false end ) |
let redraw st s h v ( canvas : Html . canvasElement Js . t ) = let width = canvas . ## width in let height = canvas . ## height in redraw st s h v canvas { x = 0 ; y = 0 ; width ; height } 0 0 width height |
let json : < parse : Js . js_string Js . t -> ' a > Js . t = Js . Unsafe . pure_js_expr " JSON " |
let ( >>= ) = Lwt . bind |
let http_get url = XmlHttpRequest . get url >>= fun { XmlHttpRequest . code = cod ; content = msg ; _ } -> if cod = 0 || cod = 200 then Lwt . return msg else fst ( Lwt . wait ( ) ) |
let getfile f = try Lwt . return ( Sys_js . read_file ~ name : f ) with Not_found -> http_get f ( ? value = 0 . ) ( ? lower = 0 . ) ( ? upper = 100 . ) ( ? step_incr = 1 . ) ( ? page_incr = 10 . ) ( ? page_size = 10 . ) ( ) = object val mutable _value = value method value = _value val mutable _lower = lower method lower = _lower val mutable _upper = upper method upper = _upper val mutable _step_incr = step_incr method step_increment = _step_incr val mutable _page_incr = page_incr method page_increment = _page_incr val mutable _page_size = page_size method page_size = _page_size method set_value v = _value <- v method set_bounds ? lower ? upper ? step_incr ? page_incr ? page_size ( ) = ( match lower with | Some v -> _lower <- v | None -> ( ) ) ; ( match upper with | Some v -> _upper <- v | None -> ( ) ) ; ( match step_incr with | Some v -> _step_incr <- v | None -> ( ) ) ; ( match page_incr with | Some v -> _page_incr <- v | None -> ( ) ) ; match page_size with | Some v -> _page_size <- v | None -> ( ) end |
let handle_drag element f = let mx = ref 0 in let my = ref 0 in element . ## onmousedown := Html . handler ( fun ev -> mx := ev . ## clientX ; my := ev . ## clientY ; element . ## style . ## cursor := Js . string " move " ; let c1 = Html . addEventListener Html . document Html . Event . mousemove ( Html . handler ( fun ev -> let x = ev . ## clientX and y = ev . ## clientY in let x ' = ! mx and y ' = ! my in mx := x ; my := y ; f ( x - x ' ) ( y - y ' ) ; Js . _true ) ) Js . _true in let c2 = ref Js . null in c2 := Js . some ( Html . addEventListener Html . document Html . Event . mouseup ( Html . handler ( fun _ -> Html . removeEventListener c1 ; Js . Opt . iter ! c2 Html . removeEventListener ; element . ## style . ## cursor := Js . string " " ; Js . _true ) ) Js . _true ) ; Js . _true ) |
let start ( ) = let doc = Html . document in let page = doc . ## documentElement in page . ## style . ## overflow := Js . string " hidden " ; doc . ## body . ## style . ## overflow := Js . string " hidden " ; doc . ## body . ## style . ## margin := Js . string " 0px " ; let started = ref false in let p = Html . createP doc in p . ## innerHTML := Js . string " Loading graph . . . " ; p . ## style . ## display := Js . string " none " ; Dom . appendChild doc . ## body p ; ignore ( Lwt_js . sleep 0 . 5 >>= fun ( ) -> if not ! started then p . ## style . ## display := Js . string " inline " ; Lwt . return ( ) ) ; getfile " scene . json " >>= fun s -> let ( x1 , y1 , x2 , y2 ) , bboxes , scene = json ## parse ( Js . string s ) in started := true ; Dom . removeChild doc . ## body p ; let st = { bboxes ; scene ; zoom_factor = 1 . . / 20 . ; st_x = x1 ; st_y = y1 ; st_width = x2 . - x1 ; st_height = y2 . - y1 ; st_pixmap = Common . make_pixmap ( ) } in let canvas = create_canvas page . ## clientWidth page . ## clientHeight in Dom . appendChild doc . ## body canvas ; let allocation ( ) = { x = 0 ; y = 0 ; width = canvas . ## width ; height = canvas . ## height } in let hadj = new adjustment ( ) in let vadj = new adjustment ( ) in let sadj = new adjustment ~ upper : 20 . ~ step_incr : 1 . ~ page_incr : 0 . ~ page_size : 0 . ( ) in let zoom_steps = 8 . in let set_zoom_factor f = let count = ceil ( log f . / log 2 . . * zoom_steps ) in let f = 2 . ** ( count . / zoom_steps ) in sadj # set_bounds ~ upper : count ( ) ; st . zoom_factor <- f in let get_scale ( ) = ( 2 . ** ( sadj # value . / zoom_steps ) ) . / st . zoom_factor in let redraw_queued = ref false in let update_view _force = let a = allocation ( ) in let scale = get_scale ( ) in let aw = ceil ( float a . width . / scale ) in let ah = ceil ( float a . height . / scale ) in hadj # set_bounds ~ step_incr ( : aw . / 20 . ) ~ page_incr ( : aw . / 2 . ) ~ page_size ( : min aw st . st_width ) ~ upper : st . st_width ( ) ; let mv = st . st_width . - hadj # page_size in if hadj # value < 0 . then hadj # set_value 0 . ; if hadj # value > mv then hadj # set_value mv ; vadj # set_bounds ~ step_incr ( : ah . / 20 . ) ~ page_incr ( : ah . / 2 . ) ~ page_size ( : min ah st . st_height ) ~ upper : st . st_height ( ) ; let mv = st . st_height . - vadj # page_size in if vadj # value < 0 . then vadj # set_value 0 . ; if vadj # value > mv then vadj # set_value mv ; if not ! redraw_queued then ( redraw_queued := true ; let ( _ : Html . animation_frame_request_id ) = Html . window ## requestAnimationFrame ( Js . wrap_callback ( fun ( _ : float ) -> redraw_queued := false ; redraw st ( get_scale ( ) ) hadj # value vadj # value canvas ) ) in ( ) ) Lwt_js . yield ( ) >>= fun ( ) -> redraw_queued := false ; redraw st ( get_scale ( ) ) hadj # value vadj # value canvas ; Lwt . return ( ) ) ) * in let a = allocation ( ) in let zoom_factor = max ( st . st_width . / float a . width ) ( st . st_height . / float a . height ) in set_zoom_factor zoom_factor ; let prev_scale = ref ( get_scale ( ) ) in let rescale x y = let scale = get_scale ( ) in let r = 1 . . - ( ! prev_scale . / scale ) in hadj # set_value ( hadj # value . + ( hadj # page_size . * r . * x ) ) ; vadj # set_value ( vadj # value . + ( vadj # page_size . * r . * y ) ) ; prev_scale := scale ; invalidate_pixmap st . st_pixmap ; update_view false in let size = 16 in let height = 300 - size in let points d = Js . string ( Printf . sprintf " % dpx " d ) in let size_px = points size in let pos = ref height in let thumb = Html . createDiv doc in let style = thumb . ## style in style . ## position := Js . string " absolute " ; style . ## width := size_px ; style . ## height := size_px ; style . ## top := points ! pos ; style . ## left := Js . string " 0px " ; style . ## margin := Js . string " 1px " ; style . ## backgroundColor := Js . string " black " ; let slider = Html . createDiv doc in let style = slider . ## style in style . ## position := Js . string " absolute " ; style . ## width := size_px ; style . ## height := points ( height + size ) ; style . ## border := Js . string " 2px solid black " ; style . ## padding := Js . string " 1px " ; style . ## top := Js . string " 10px " ; style . ## left := Js . string " 10px " ; Dom . appendChild slider thumb ; Dom . appendChild doc . ## body slider ; let set_slider_position pos ' = if pos ' <> ! pos then ( thumb . ## style . ## top := points pos ' ; pos := pos ' ; sadj # set_value ( float ( height - pos ' ) . * sadj # upper . / float height ) ; rescale 0 . 5 0 . 5 ) in handle_drag thumb ( fun _dx dy -> set_slider_position ( min height ( max 0 ( ! pos + dy ) ) ) ) ; slider . ## onmousedown := Html . handler ( fun ev -> let ey = ev . ## clientY in let _ , sy = Dom_html . elementClientPosition slider in set_slider_position ( max 0 ( min height ( ey - sy - ( size / 2 ) ) ) ) ; Js . _false ) ; let adjust_slider ( ) = let pos ' = height - truncate ( ( sadj # value . * float height . / sadj # upper ) . + 0 . 5 ) in thumb . ## style . ## top := points pos ' ; pos := pos ' in Html . window . ## onresize := Html . handler ( fun _ -> let page = doc . ## documentElement in canvas . ## width := page . ## clientWidth ; canvas . ## height := page . ## clientHeight ; update_view true ; Js . _true ) ; handle_drag canvas ( fun dx dy -> let scale = get_scale ( ) in let offset a d = a # set_value ( min ( a # value . - ( float d . / scale ) ) ( a # upper . - a # page_size ) ) in offset hadj dx ; offset vadj dy ; update_view true ) ; let bump_scale x y v = let a = allocation ( ) in let x = x . / float a . width in let y = y . / float a . height in let prev = sadj # value in let vl = min sadj # upper ( max sadj # lower ( prev . + ( v . * sadj # step_increment ) ) ) in if vl <> prev then ( sadj # set_value vl ; adjust_slider ( ) ; if x >= 0 . && x <= 1 . && y >= 0 . && y <= 1 . then rescale x y else rescale 0 . 5 0 . 5 ) ; Js . _false in ignore ( Html . addMousewheelEventListener canvas ( fun ev ~ dx : _ ~ dy -> let ex , ey = Dom_html . elementClientPosition canvas in let x = float ( ev . ## clientX - ex ) in let y = float ( ev . ## clientY - ey ) in if dy < 0 then bump_scale x y 1 . else if dy > 0 then bump_scale x y ( - 1 . ) else Js . _false ) Js . _true ) ; Js . _false | 38 -> Js . _false | 39 -> Js . _false | 40 -> Js . _false | _ -> Firebug . console ## log ( - 1 - e ## keyCode ) ; Js . _true ) ) Js . _true ; ) * let handle_key_event ev = match ev . ## keyCode with | 37 -> hadj # set_value ( hadj # value . - hadj # step_increment ) ; update_view false ; Js . _false | 38 -> vadj # set_value ( vadj # value . - vadj # step_increment ) ; update_view false ; Js . _false | 39 -> hadj # set_value ( hadj # value . + hadj # step_increment ) ; update_view false ; Js . _false | 40 -> vadj # set_value ( vadj # value . + vadj # step_increment ) ; update_view false ; Js . _false | _ -> Js . _true in let ignored_keycode = ref ( - 1 ) in Html . document . ## onkeydown := Html . handler ( fun e -> ignored_keycode := e . ## keyCode ; handle_key_event e ) ; Html . document . ## onkeypress := Html . handler ( fun e -> let k = ! ignored_keycode in ignored_keycode := - 1 ; if e . ## keyCode = k then Js . _true else handle_key_event e ) ; update_view true ; Lwt . return ( ) |
let _ = Html . window . ## onload := Html . handler ( fun _ -> ignore ( start ( ) ) ; Js . _false ) |
type t_point = float * float |
type t_coord = t_point * t_point |
type t_shape = Srect | Sellipse |
type t_gtk_obj = GnomeCanvas . re_p GnoCanvas . item |
module Node = struct type t = string * ( t_shape * t_coord * t_gtk_obj ) option let id n = fst n let coord n = match snd n with None -> None | Some ( _ , c , _ ) -> Some c let item n = match snd n with None -> None | Some ( _ , _ , r ) -> Some r end |
type t_graph = B . G . t * GnoCanvas . pixbuf |
let get_graph g = fst g |
let get_pixbuf g = snd g |
let get_node_info n = B . G . V . label n |
let get_coord n = Node . coord ( get_node_info n ) |
let get_id n = Node . id ( get_node_info n ) |
let get_obj n = Node . item ( get_node_info n ) |
let get_info attr_list_list = let get ( shp , p , w , h ) ( attr , val_opt ) = match attr , val_opt with | ( Dot_ast . Ident " shape " ) , Some ( Dot_ast . String s ) -> ( Some s ) , p , w , h | ( Dot_ast . Ident " pos " ) , Some ( Dot_ast . String s ) -> shp , ( Some s ) , w , h | ( Dot_ast . Ident " width " ) , Some ( Dot_ast . String s ) -> shp , p , ( Some s ) , h | ( Dot_ast . Ident " height " ) , Some ( Dot_ast . String s ) -> shp , p , w , ( Some s ) | ( Dot_ast . Ident _ ) , Some ( Dot_ast . String _ ) -> ( shp , p , w , h ) | _ -> ( shp , p , w , h ) in let get acc attr_list = List . fold_left get acc attr_list in List . fold_left get ( None , None , None , None ) attr_list_list |
let compute_coord pos w h = let dot_ppi = 72 . in let dot_png_ppi = 96 . in try let w = float_of_string w in let h = float_of_string h in let x , y = Scanf . sscanf pos " % d , % d " ( fun x y -> ( x , y ) ) in let pad = 4 in let x = float_of_int ( x + pad ) in let y = float_of_int ( y + pad ) in let dx = w . * dot_ppi . / 2 . in let dy = h . * dot_ppi . / 2 . in let x1 = x . - dx in let y1 = y . - dy in let x2 = x . + dx in let y2 = y . + dy in let factor = dot_png_ppi . / dot_ppi in let x1 = x1 . * factor in let y1 = y1 . * factor in let x2 = x2 . * factor in let y2 = y2 . * factor in Some ( ( x1 , y1 ) , ( x2 , y2 ) ) with e -> let s = Printexc . to_string e in Format . printf " compute_coord failled : % s . " @ s ; None |
module DotParser ( C : sig val mk_node : t_shape -> t_coord -> t_gtk_obj end ) = Dot . Parse ( B ) ( struct let node ( id , _ ) attr_list = let name = match id with | Dot_ast . Ident s | Dot_ast . Number s | Dot_ast . String s | Dot_ast . Html s -> s in let info = match get_info attr_list with | shp , Some pos , Some w , Some h -> let shp = match shp with | Some " ellipse " -> Sellipse | Some " box " -> Srect | Some _ -> Srect | None -> Sellipse in begin match compute_coord pos w h with | None -> None | Some coord -> let n_obj = C . mk_node shp coord in Some ( shp , coord , n_obj ) end | _ -> Format . printf " info KO for % s . " @ name ; None in ( name , info ) let edge _ = ( ) end ) |
let png_graph_image dot_cmd dot_file png_file = let cmd = Printf . sprintf " % s - T png % s > % s " dot_cmd dot_file png_file in match Sys . command cmd with | 0 -> png_file | _ -> raise ( DotError cmd ) |
let build_graph dot_cmd dot_file annot_dot_file mk_node_item = let cmd = Printf . sprintf " % s - y % s > % s " dot_cmd dot_file annot_dot_file in match Sys . command cmd with | 0 -> let module Parser = DotParser ( struct let mk_node = mk_node_item end ) in let graph = Parser . parse annot_dot_file in graph | _ -> raise ( DotError cmd ) |
let get_neighbours graph n = let graph = get_graph graph in let preds = B . G . pred graph n in let succs = B . G . succ graph n in ( preds , succs ) |
module type SigCb = sig type t_env val button_one_press_on_graph : t_env -> unit val button_two_press_on_graph : t_env -> unit val button_three_press_on_graph : t_env -> unit val button_one_press_on_node : t_env -> t_node -> unit val button_two_press_on_node : t_env -> t_node -> unit val button_three_press_on_node : t_env -> t_node -> unit val enter_node : t_env -> t_node -> unit val leave_node : t_env -> t_node -> unit end |
module EmptyCb = struct type t_env = unit let button_one_press_on_graph _env = ( ) let button_two_press_on_graph _env = ( ) let button_three_press_on_graph _env = ( ) let button_one_press_on_node _env _n = ( ) let button_two_press_on_node _env _n = ( ) let button_three_press_on_node _env _n = ( ) let enter_node _env _n = ( ) let leave_node _env _n = ( ) end |
module M ( Cb : SigCb ) = struct let mk_node_item canvas shp ( ( x1 , y1 ) , ( x2 , y2 ) ) = let no_color = [ ` FILL_COLOR " black " ; ` FILL_STIPPLE ( Gdk . Bitmap . create_from_data ~ width : 1 ~ height : 1 " \ 000 " ) ] in let props = [ ` X1 x1 ; ` Y1 y1 ; ` X2 x2 ; ` Y2 y2 ] @ no_color in let n_obj = match shp with | Srect -> GnoCanvas . rect canvas # root ~ props | Sellipse -> GnoCanvas . ellipse canvas # root ~ props in n_obj let graph_event env ev = begin match ev with | ` BUTTON_PRESS ev -> begin match GdkEvent . Button . button ev with | 1 -> Cb . button_one_press_on_graph env | 2 -> Cb . button_two_press_on_graph env | 3 -> Cb . button_three_press_on_graph env | _ -> ( ) end | _ -> ( ) end ; false let node_event env node ev = begin match ev with | ` ENTER_NOTIFY _ -> Cb . enter_node env node | ` LEAVE_NOTIFY _ -> Cb . leave_node env node | ` BUTTON_PRESS ev -> begin match GdkEvent . Button . button ev with | 1 -> Cb . button_one_press_on_node env node | 2 -> Cb . button_two_press_on_node env node | 3 -> Cb . button_three_press_on_node env node | _ -> ( ) end | _ -> ( ) end ; false let add_node_items env graph = let do_it n = match get_obj n with | None -> ( ) | Some n_rect -> ignore ( n_rect # connect # event ~ callback ( : node_event env n ) ) in B . G . iter_vertex do_it graph let remove_node_items graph = let do_it n = match get_obj n with | None -> ( ) | Some n_rect -> n_rect # destroy ( ) in B . G . iter_vertex do_it graph let install_image ( canvas : GnoCanvas . canvas ) png_file = let im = GdkPixbuf . from_file png_file in let w = GdkPixbuf . get_width im in let h = GdkPixbuf . get_height im in let _ = canvas # set_scroll_region ~ x1 : 0 . ~ y1 : 0 . ~ x2 ( : float w ) ~ y2 ( : float h ) in let px = GnoCanvas . pixbuf ~ x : 0 . ~ y : 0 . ~ pixbuf : im canvas # root in px let open_dot_file env ( canvas : GnoCanvas . canvas ) ( ? dot_cmd " = dot " ) dot_file = let basename = try Filename . chop_extension dot_file with Invalid_argument _ -> dot_file in let png_file = Printf . sprintf " % s . png " basename in let annot_dot_file = Printf . sprintf " % s_annot " dot_file in let graph = build_graph dot_cmd dot_file annot_dot_file ( mk_node_item canvas ) in let png_file = png_graph_image dot_cmd dot_file png_file in let pixbuf = install_image canvas png_file in let _ = pixbuf # connect # event ~ callback ( : graph_event env ) in let _ = add_node_items env graph in let _ = pixbuf # lower_to_bottom ( ) in ( graph , pixbuf ) let clear _canvas graph = let pixbuf = get_pixbuf graph in pixbuf # destroy ( ) ; let graph = get_graph graph in remove_node_items graph end |
module CircLists = struct type t_elem = ViewGraph_core . t_node type t_lists = t_elem list * t_elem list * t_elem list type t = bool * t_lists let mk ( l1 , l2 ) = match l1 , l2 with | [ ] , [ ] -> true , ( [ ] , [ ] , [ ] ) | [ ] , l2 -> false , ( l2 , [ ] , [ ] ) | l1 , l2 -> true , ( l1 , l2 , [ ] ) let current_node lists = match lists with | _ , ( [ ] , _ , _ ) -> None | b , ( n :: _ , _ , _ ) -> Some ( b , n ) let go_next lists = let lists = match lists with | _ , ( [ ] , [ ] , [ ] ) -> lists | _ , ( [ ] , _ , _ ) -> assert false | b , ( n [ ] , :: [ ] , l3 ) -> b , ( l3 @ [ n ] , [ ] , [ ] ) | b , ( n [ ] , :: l2 , l3 ) -> not b , ( l2 , l3 @ [ n ] , [ ] ) | b , ( n :: l1 , l2 , l3 ) -> b , ( l1 , l2 , l3 @ [ n ] ) in lists let goto_n ( ( _ , ( l1 , l2 , l3 ) ) as lists ) n = let max = List . length l1 + List . length l2 + List . length l3 in let rec find nb_iter lists = match current_node lists with | None -> raise Not_found | Some ( _ , cur_n ) -> if cur_n = n then lists else if nb_iter >= 0 then find ( nb_iter - 1 ) ( go_next lists ) else raise Not_found in find max lists end |
type t_options = { sel_1_color : string ; sel_2_color : string ; center_node_when_selected : bool ; } |
let default_options = { sel_1_color = " red " ; sel_2_color = " green " ; center_node_when_selected = true ; } |
type t_widgets = { canvas : GnoCanvas . canvas ; sel_1_txt : GMisc . label ; sel_edge_txt : GMisc . label ; sel_2_txt : GMisc . label ; } |
type t_state = { w : t_widgets ; opt : t_options ; mutable graph : ViewGraph_core . t_graph option ; mutable ppu : float ; mutable selected : ViewGraph_core . t_node option ; mutable neighbours : CircLists . t option ; mutable gui_sel : ( ViewGraph_core . t_gtk_obj option ) array ; } |
let change_zoom state delta = state . ppu <- state . ppu . + delta ; state . w . canvas # set_pixels_per_unit state . ppu |
let center_selected_node state = match state . selected with | None -> ( ) | Some n -> match ViewGraph_core . get_coord n with | None -> ( ) | Some ( ( x1 , y1 ) , ( x2 , y2 ) ) -> let canvas = state . w . canvas in let x = x1 . + ( x2 . - x1 ) . / 2 . in let y = y1 . + ( y2 . - y1 ) . / 2 . in let w = canvas # hadjustment # page_size in let h = canvas # vadjustment # page_size in let sx = x . - ( w . / 2 . ) in let sy = y . - ( h . / 2 . ) in let sx , sy = canvas # w2c ~ wx : sx ~ wy : sy in canvas # scroll_to ~ x : sx ~ y : sy |
let key_press state ev = let canvas = state . w . canvas in let ( x , y ) = canvas # get_scroll_offsets in match GdkEvent . Key . keyval ev with | k when k = GdkKeysyms . _Up -> canvas # scroll_to ~ x ~ y ( : y - 20 ) ; true | k when k = GdkKeysyms . _Down -> canvas # scroll_to ~ x ~ y ( : y + 20 ) ; true | k when k = GdkKeysyms . _Left -> canvas # scroll_to ~ x ( : x - 10 ) ~ y ; true | k when k = GdkKeysyms . _Right -> canvas # scroll_to ~ x ( : x + 10 ) ~ y ; true | k when k = GdkKeysyms . _Page_Down -> change_zoom state 0 . 1 ; true | k when k = GdkKeysyms . _Page_Up -> change_zoom state ( - 0 . 1 ) ; true | k when k = GdkKeysyms . _Home -> center_selected_node state ; true | _ -> false |
let init options ( canvas : GnoCanvas . canvas ) pack_txt = let _ = GMisc . label ~ text " : Selected : " ~ packing : pack_txt ( ) in let sel_1_txt = GMisc . label ~ packing : pack_txt ( ) in let sel_edge_txt = GMisc . label ~ packing : pack_txt ( ) in let sel_2_txt = GMisc . label ~ packing : pack_txt ( ) in let w = { canvas = canvas ; sel_1_txt = sel_1_txt ; sel_edge_txt = sel_edge_txt ; sel_2_txt = sel_2_txt } in let state = { w = w ; opt = options ; gui_sel = [ | None ; None ] | ; graph = None ; ppu = 1 . ; selected = None ; neighbours = None } in let _ = canvas # event # connect # after # key_press ~ callback ( : key_press state ) in state |
let sel_1_bitmap ( ) = Gdk . Bitmap . create_from_data ~ width : 2 ~ height : 2 " \ 002 \ 001 " |
let sel_2_bitmap ( ) = Gdk . Bitmap . create_from_data ~ width : 2 ~ height : 2 " \ 002 \ 001 " |
let no_bitmap ( ) = Gdk . Bitmap . create_from_data ~ width : 1 ~ height : 1 " \ 000 " |
let move_selection state n_opt1 n_opt2 = let set_props o col bitmap = match o with None -> ( ) | Some o -> o # set [ ` FILL_COLOR col ; ` FILL_STIPPLE bitmap ] in let n_obj n_opt = match n_opt with | None -> None | Some n -> ViewGraph_core . get_obj n in let obj1 = n_obj n_opt1 in let obj2 = n_obj n_opt2 in let reset_old i = set_props state . gui_sel . ( i ) " black " ( no_bitmap ( ) ) in reset_old 0 ; reset_old 1 ; state . gui_sel . ( 0 ) <- obj1 ; state . gui_sel . ( 1 ) <- obj2 ; set_props obj1 state . opt . sel_1_color ( sel_1_bitmap ( ) ) ; set_props obj2 state . opt . sel_2_color ( sel_2_bitmap ( ) ) |
let show_selection state = let n_opt , txt1 , txt2 , txt3 = match state . selected with | None -> None , " ( none ) " , " " , " " | Some n -> let txt1 = ViewGraph_core . get_id n in let n_opt , txt2 , txt3 = match state . neighbours with | None -> None , " " , " " | Some info -> match CircLists . current_node info with | None -> None , " --- " , " ( none ) " | Some ( pred_first , n ) -> let txt2 = if pred_first then " <-- " else " --> " in Some n , txt2 , ViewGraph_core . get_id n in n_opt , txt1 , txt2 , txt3 in state . w . sel_1_txt # set_text txt1 ; state . w . sel_edge_txt # set_text txt2 ; state . w . sel_2_txt # set_text txt3 ; move_selection state state . selected n_opt ; if state . opt . center_node_when_selected then center_selected_node state |
let select_node state n_opt = state . selected <- n_opt ; state . neighbours <- None ; show_selection state |
let select_neighbour state = match state . graph with None -> ( ) | Some graph -> match state . selected with None -> ( ) | Some n -> let new_info = match state . neighbours with | None -> let neighbours = ViewGraph_core . get_neighbours graph n in CircLists . mk neighbours | Some info -> CircLists . go_next info in state . neighbours <- Some ( new_info ) ; show_selection state |
let goto_neighbour state = match state . graph with None -> ( ) | Some graph -> match state . neighbours with | None -> ( ) | Some info -> match CircLists . current_node info with | None -> ( ) | Some ( _ , n ) -> match state . selected with | None -> assert false | Some old_n -> state . selected <- Some n ; let neighbours = ViewGraph_core . get_neighbours graph n in let neighbours = CircLists . mk neighbours in let neighbours = CircLists . goto_n neighbours old_n in state . neighbours <- Some neighbours ; show_selection state |
let clear_state state = state . graph <- None ; state . ppu <- 1 . ; state . selected <- None ; state . neighbours <- None ; state . gui_sel <- [ | None ; None ] ; | show_selection state |
module SelectCb ( UserCb : ViewGraph_core . SigCb ) = struct type t_env = UserCb . t_env * t_state let button_one_press_on_graph ( u_env , state ) = select_node state None ; UserCb . button_one_press_on_graph ( u_env ) let button_two_press_on_graph ( u_env , state ) = select_neighbour state ; UserCb . button_two_press_on_graph ( u_env ) let button_three_press_on_graph ( u_env , state ) = goto_neighbour state ; UserCb . button_three_press_on_graph ( u_env ) let button_one_press_on_node ( u_env , state ) n = select_node state ( Some n ) ; UserCb . button_one_press_on_node ( u_env ) n let button_two_press_on_node ( ( u_env , _state ) as env ) n = button_two_press_on_graph env ; UserCb . button_two_press_on_node ( u_env ) n let button_three_press_on_node ( ( u_env , _state ) as env ) n = button_three_press_on_graph env ; UserCb . button_three_press_on_node ( u_env ) n let enter_node ( u_env , _state ) n = begin match ViewGraph_core . get_obj n with None -> assert false | Some n_item -> n_item # set [ ` OUTLINE_COLOR " red " ] end ; UserCb . enter_node ( u_env ) n let leave_node ( u_env , _state ) n = begin match ViewGraph_core . get_obj n with None -> assert false | Some n_item -> n_item # set [ ` NO_OUTLINE_COLOR ] end ; UserCb . leave_node ( u_env ) n end |
module VG ( UserCb : ViewGraph_core . SigCb ) = struct module Cb = SelectCb ( UserCb ) module V = ViewGraph_core . M ( Cb ) let open_dot_file u_env state ( ? dot_cmd " = dot " ) file = let canvas = state . w . canvas in ( match state . graph with None -> ( ) | Some g -> V . clear canvas g ) ; let _ = clear_state state in let env = ( u_env , state ) in let graph = V . open_dot_file env canvas ~ dot_cmd file in state . graph <- Some graph ; graph end |
let show_help ( ) = GToolbox . message_box ~ title " : Help " " Selection :\ n - use the mouse button - 1 to select a node : \ it should turn red and ( optionally ) be centered . - when a node is selected , button - 2 selects one of its neighbour : \ it should turn green . - using button - 2 again selects the next neighbour , and so on . - when a neighbour is selected , button - 3 makes it the selected node , and the previously selected node become the selected neighbour , so pressing the button - 3 again brings back to it . - button - 1 outside a node deselect everything . Have a look at the bottom line to see the selection . Moving arround :\ n - the scrollbars , as well as the arrows , can be used to move in the window . - the Page - Up and Page - Down keys can be used to zoom \ ( ugly zoom at the moment ) . ! - the Home key centers the selected node in the window . " |
module CbTest = struct type t_env = unit let button_one_press_on_graph _env = Format . printf " [ CbTest ] button_one_press_on_graph . " @ let button_two_press_on_graph _env = Format . printf " [ CbTest ] button_two_press_on_graph . " @ let button_three_press_on_graph _env = Format . printf " [ CbTest ] button_three_press_on_graph . " @ let button_one_press_on_node _env n = Format . printf " [ CbTest ] button_one_press_on_node % s . " @ ( ViewGraph . get_id n ) let button_two_press_on_node _env n = Format . printf " [ CbTest ] button_two_press_on_node % s . " @ ( ViewGraph . get_id n ) let button_three_press_on_node _env n = Format . printf " [ CbTest ] button_three_press_on_node % s . " @ ( ViewGraph . get_id n ) let enter_node _env n = Format . printf " [ CbTest ] enter_node % s . " @ ( ViewGraph . get_id n ) let leave_node _env n = Format . printf " [ CbTest ] leave_node % s . " @ ( ViewGraph . get_id n ) end |
module V = ViewGraph_select . VG ( CbTest ) |
let open_file select_init_env file = try let env = ( ) in let _graph = V . open_dot_file env select_init_env file in ( ) with ViewGraph . DotError cmd -> GToolbox . message_box " Error " ( Printf . sprintf " % s failed \ nDidn ' t succed to build graph for % s \ nSorry " ! cmd file ) |
let open_cb select_init_env ( ) = match GToolbox . select_file ~ title " : Select a dot file " ( ) with | None -> ( ) | Some filename -> open_file select_init_env filename |
let help_act_cb _ac = ViewGraph_select . show_help ( ) |
let error_act_cb ac = GToolbox . message_box " Error " ( Printf . sprintf " Action ' % s ' activated : no callback ?\ n " ac # name ) |
let quit_cb ( ) = GMain . Main . quit ( ) |
let quit_act_cb _a = quit_cb ( ) |
let menu_desc = " < ui >\ < menubar name ' = MenuBar ' >\ < menu action ' = FileMenu ' >\ < menuitem action ' = Open ' />\ < separator />\ < menuitem action ' = Quit ' />\ </ menu >\ < menu action ' = HelpMenu ' >\ < menuitem action ' = Help ' />\ </ menu >\ </ menubar >\ </ ui " > |
let create_menu ( ) = let ui_m = GAction . ui_manager ( ) in let actions = GAction . action_group ~ name " : Actions " ( ) in GAction . add_actions actions [ GAction . add_action " FileMenu " ~ label " : File " ; GAction . add_action " Open " ~ label " : Open " ~ accel " : o " ; GAction . add_action " Quit " ~ label " : Quit " ~ accel " : q " ~ callback : quit_act_cb ; GAction . add_action " HelpMenu " ~ label " : Help " ; GAction . add_action " Help " ~ label " : Help " ~ accel " : h " ~ callback : help_act_cb ; ] ; ui_m # insert_action_group actions 0 ; let _ = ui_m # add_ui_from_string menu_desc in let help_item = ui_m # get_widget " / MenuBar / HelpMenu " in let help_item = GtkMenu . MenuItem . cast help_item # as_widget in GtkMenu . MenuItem . set_right_justified help_item true ; ui_m |
let create_gui ( ) = let window = GWindow . window ~ title " : ViewGraph " ~ allow_shrink : true ~ allow_grow : true ( ) in let vbox = GPack . vbox ~ border_width : 4 ~ spacing : 4 ~ packing : window # add ( ) in let ui_m = create_menu ( ) in window # add_accel_group ui_m # get_accel_group ; vbox # pack ~ expand : false ( ui_m # get_widget " / MenuBar " ) ; let frame = GBin . frame ~ label " : How to use this " : ~ packing : vbox # pack ( ) in let _ = GMisc . label ~ text " :\ n Open the Help window to know more . . . \ n " ~ packing : frame # add ( ) in let pack = vbox # pack ~ expand : true ~ fill : true in let canvas = ViewGraph_utils . create_scrolled_canvas pack in let hbox = GPack . hbox ~ spacing : 4 ~ packing : vbox # pack ( ) in let select_init_env = ViewGraph_select . init ViewGraph_select . default_options canvas ( hbox # pack ~ expand : true ~ fill : true ) in let actions = match ui_m # get_action_groups with | a [ ] :: -> a | _ -> assert false in let open_action = actions # get_action " Open " in let _ = open_action # connect # activate ~ callback ( : open_cb select_init_env ) in let _ = window # connect # destroy ~ callback : quit_cb in let _ = window # show ( ) in ( canvas , select_init_env ) |
let main ( ) = let _ = GMain . Main . init ( ) in let canvas , select_init_env = create_gui ( ) in if Array . length Sys . argv = 2 then open_file select_init_env Sys . argv . ( 1 ) ; GMain . Main . main ( ) |
let _ = Printexc . print main ( ) |
let create_scrolled_canvas packing = let frame = GBin . frame ~ shadow_type ` : IN ( ) in let canvas = let aa = false in GnoCanvas . canvas ~ aa ~ width : 600 ~ height : 400 ~ packing : frame # add ( ) in let _ = canvas # set_center_scroll_region true in let table = GPack . table ~ packing ~ rows : 2 ~ columns : 2 ~ row_spacings : 4 ~ col_spacings : 4 ( ) in let _ = table # attach ~ left : 0 ~ right : 1 ~ top : 0 ~ bottom : 1 ~ expand ` : BOTH ~ fill ` : BOTH ~ shrink ` : BOTH ~ xpadding : 0 ~ ypadding : 0 frame # coerce in let w = GRange . scrollbar ` HORIZONTAL ~ adjustment : canvas # hadjustment ( ) in let _ = table # attach ~ left : 0 ~ right : 1 ~ top : 1 ~ bottom : 2 ~ expand ` : X ~ fill ` : BOTH ~ shrink ` : X ~ xpadding : 0 ~ ypadding : 0 w # coerce in let w = GRange . scrollbar ` VERTICAL ~ adjustment : canvas # vadjustment ( ) in let _ = table # attach ~ left : 1 ~ right : 2 ~ top : 0 ~ bottom : 1 ~ expand ` : Y ~ fill ` : BOTH ~ shrink ` : Y ~ xpadding : 0 ~ ypadding : 0 w # coerce in canvas |
let create_graph_win title = let window = GWindow . window ~ title ~ allow_shrink : true ~ allow_grow : true ( ) in let vbox = GPack . vbox ~ border_width : 4 ~ spacing : 4 ~ packing : window # add ( ) in let help_but = GButton . button ~ label " : Help " ~ packing ( : vbox # pack ~ expand : false ~ fill : true ) ( ) in let _ = help_but # connect # clicked ~ callback : ViewGraph_select . show_help in let canvas = create_scrolled_canvas ( vbox # pack ~ expand : true ~ fill : true ) in let hbox = GPack . hbox ~ spacing : 4 ~ packing : vbox # pack ( ) in let select_init_env = ViewGraph_select . init ViewGraph_select . default_options canvas ( hbox # pack ~ expand : true ~ fill : true ) in window # show ( ) ; select_init_env |
let left_click = ref GLUT_UP ; ; |
let right_click = ref GLUT_UP ; ; |
let xold = ref 0 ; ; |
let yold = ref 0 ; ; |
let width = ref 0 ; ; |
let height = ref 0 ; ; |
let rotate_x = ref 30 . 0 ; ; |
let rotate_y = ref 15 . 0 ; ; |
let alpha = ref 0 . 0 ; ; |
let beta = ref 0 . 0 ; ; |
let teapot ( ) = glBegin ( GL_LINES ) ; glColor3 ( 1 . 0 ) ( 0 . 0 ) ( 0 . 0 ) ; glVertex3 ( - 1 . 0 ) ( - 1 . 0 ) ( - 1 . 0 ) ; glVertex3 ( 1 . 0 ) ( - 1 . 0 ) ( - 1 . 0 ) ; glColor3 ( 0 . 0 ) ( 1 . 0 ) ( 0 . 0 ) ; glVertex3 ( - 1 . 0 ) ( - 1 . 0 ) ( - 1 . 0 ) ; glVertex3 ( - 1 . 0 ) ( 1 . 0 ) ( - 1 . 0 ) ; glColor3 ( 0 . 0 ) ( 0 . 0 ) ( 1 . 0 ) ; glVertex3 ( - 1 . 0 ) ( - 1 . 0 ) ( - 1 . 0 ) ; glVertex3 ( - 1 . 0 ) ( - 1 . 0 ) ( 1 . 0 ) ; glEnd ( ) ; glRotate ( ! beta ) ( 1 . 0 ) ( 0 . 0 ) ( 0 . 0 ) ; glRotate ( ! alpha ) ( 0 . 0 ) ( 1 . 0 ) ( 0 . 0 ) ; glColor3 ( 1 . 0 ) ( 1 . 0 ) ( 1 . 0 ) ; glutWireTeapot ( 0 . 5 ) ; ; ; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.