123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108(**************************************************************************)(* *)(* SPDX-License-Identifier LGPL-2.1 *)(* Copyright (C) *)(* CEA (Commissariat à l'énergie atomique et aux énergies alternatives) *)(* *)(**************************************************************************)type('a,'b,'c)metrics_panel={top:'aoption;bottom:'boption;actions:'clist;};;(* The option type for top and bottom GTK objects is compulsory in order not to
have warnings at runtime.
Creation of GTK objects cannot be made before the general window is
initialized.
The option type with a None value marks the fact that this value is not
initialized either (it will only be at register time).
*)letget_panel,set_panel,add_panel_action=letpanel=ref{top=None;bottom=None;actions=[];}in(fun()->!panel),(funtop_widgetbottom_widget->panel:={top=top_widget;bottom=bottom_widget;actions=[];}),(funaction->panel:={!panelwithactions=action::!panel.actions;});;(** Display the [table_contents] matrix as a GTK table *)letdisplay_as_tabletable_contents(parent:GPack.box)=lettable=GPack.table~columns:(List.length(List.hdtable_contents))~rows:(List.lengthtable_contents)~homogeneous:true~packing:parent#pack()inList.iteri(funirow->List.iteri(funjtext->table#attach~left:j~top:i((GMisc.label~justify:`LEFT~text:text()):>GObj.widget))row)table_contents;;;(** Remove all sub-elements of a GUI object *)letclear_containerw=List.iter(func->c#destroy())w#children;;(** The panel of Metrics has two parts:
- The upper part contains the various choices of the user;
- The bottom part displays the result.
*)letinit_panel(main_ui:Design.main_window_extension_points)=letv=GPack.vbox()in(* Titles, buttons, and headers *)letup=GPack.hbox~width:120~packing:(v#pack~expand:true)()in(* Results *)letbottom=GPack.vbox~width:120~packing:(v#pack~expand:true)()inletchoices=GEdit.combo_box_text~active:0~strings:[]~packing:(up#pack)()inletlaunch_button=GButton.button~label:"Launch"~packing:(up#pack)()inignore(launch_button#connect#clicked~callback:(fun()->letactions=(get_panel()).actionsinletsopt=GEdit.text_combo_get_activechoicesinmatchsoptwith|None->()|Somes->ifList.mem_assocsactionsthenletaction=List.assocsactionsinclear_containerbottom;ignore(main_ui#full_protect~cancelable:true(fun()->actionbottom))else()));set_panel(Somechoices)(Somebottom);v;;letreset_panel_=letmetrics_panel=get_panel()inmatchmetrics_panel.bottomwith|None->()|Someb->clear_containerb;;;(** Returning a value to register in Frama-C's GUI *)letcoerce_panel_to_uipanel_box_main_ui="Metrics",panel_box#coerce,None;;(** Add a new metrics to its dedicated panel.
The text is added to the combo box while the action is added to the
association lists of possible actions.
*)letregister_metrics?(apply=false)namedisplay_function=add_panel_action(name,display_function);letmetrics_panel=get_panel()inGEdit.text_combo_add(Option.getmetrics_panel.top)name;ifapplythendisplay_function(Option.getmetrics_panel.bottom);;;