------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Cheddar is a GNU GPL real-time scheduling analysis tool. -- This program provides services to automatically check schedulability and -- other performance criteria of real-time architecture models. -- -- Copyright (C) 2002-2023, Frank Singhoff, Alain Plantec, Jerome Legrand, -- Hai Nam Tran, Stephane Rubini -- -- The Cheddar project was started in 2002 by -- Frank Singhoff, Lab-STICC UMR 6285, Université de Bretagne Occidentale -- -- Cheddar has been published in the "Agence de Protection des Programmes/France" in 2008. -- Since 2008, Ellidiss technologies also contributes to the development of -- Cheddar and provides industrial support. -- -- The full list of contributors and sponsors can be found in README.md -- -- This program 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. -- -- This program 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 this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- -- -- Contact : cheddar@listes.univ-brest.fr -- ------------------------------------------------------------------------------ -- Last update : -- $Rev: 3657 $ -- $Date: 2020-12-13 13:25:49 +0100 (dim., 13 déc. 2020) $ -- $Author: singhoff $ ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with Ada.Text_IO; use Ada.Text_IO; with Ada.Exceptions; use Ada.Exceptions; with Ada.IO_Exceptions; use Ada.IO_Exceptions; with Glib; use Glib; with Glib.Object; use Glib.Object; with Gtk; use Gtk; with Gtk.Main; use Gtk.Main; with Gtk.Widget; use Gtk.Widget; with aadl_config; use aadl_config; with graphical_editor.message_text; use graphical_editor.message_text; with Ada.Direct_IO; with Ada.Exceptions; use Ada.Exceptions; with Ada.IO_Exceptions; use Ada.IO_Exceptions; with Ada.Text_IO; use Ada.Text_IO; with Ada.Text_IO.Text_Streams; use Ada.Text_IO.Text_Streams; with Ada.Unchecked_Deallocation; with GNAT.Command_Line; use GNAT.Command_Line; with GNAT.Expect; use GNAT.Expect; with GNAT.Current_Exception; use GNAT.Current_Exception; with GNAT.OS_Lib; use GNAT.OS_Lib; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Glib; use Glib; with Glib.Object; use Glib.Object; with Gtk; use Gtk; with Gtk.Widget; use Gtk.Widget; with Gtk.Enums; use Gtk.Enums; with Gtk.Menu_Item; use Gtk.Menu_Item; with Gtk.Main; use Gtk.Main; with Glib.Error; use Glib.Error; with Gtk.Widget; use Gtk.Widget; with Gtk.Button; use Gtk.Button; with Gtk.Label; use Gtk.Label; with Gtk.Drawing_Area; use Gtk.Drawing_Area; with Gtk.Handlers; use Gtk.Handlers; with Gdk; use Gdk; with Gdk.Color; use Gdk.Color; with Gdk.Window; use Gdk.Window; with Gdk.Event; use Gdk.Event; with Pango.Font; use Pango.Font; with gtkada; use gtkada; with gtkada.file_selection; use gtkada.file_selection; with gtkada.builder; use gtkada.builder; with Gtk.File_Chooser_Widget; use Gtk.File_Chooser_Widget; with Gtk.File_Chooser; use Gtk.File_Chooser; with Gtk.File_Chooser_Dialog; use Gtk.File_Chooser_Dialog; with translate; use translate; with framework_config; use framework_config; with systems; use systems; with xml_generic_parsers; use xml_generic_parsers; with aadl_parsers; use aadl_parsers; with xml_generic_parsers; use xml_generic_parsers; with xml_generic_parsers.architecture; use xml_generic_parsers.architecture; with multiprocessor_services; use multiprocessor_services; with arinc_653_schema; use arinc_653_schema; with arinc_653_services; use arinc_653_services; with unbounded_strings; use unbounded_strings; with Unicode.CES; use Unicode.CES; with Unicode.Encodings; use Unicode.Encodings; with DOM.Core.Documents; use DOM.Core, DOM.Core.Documents; with DOM.Core; use DOM.Core; with DOM.Core.Nodes; use DOM.Core.Nodes; with DOM.Readers; use DOM.Readers; with Input_Sources.File; use Input_Sources.File; with Input_Sources.Http; use Input_Sources.Http; with Input_Sources; use Input_Sources; with Sax.Encodings; use Sax.Encodings; with Sax.Readers; use Sax.Readers; with Sax.Symbols; with Sax.Utils; use Sax.Utils; with io_tools; use io_tools; with graphical_editor.message_text; use graphical_editor.message_text; with graphical_editor.user_message; use graphical_editor.user_message; with graphical_editor.generic_package_widget; use graphical_editor.generic_package_widget; with graphical_editor.draw_scheduling; use graphical_editor.draw_scheduling; with graphical_editor.scheduling_simulations_callbacks; use graphical_editor.scheduling_simulations_callbacks; with graphical_editor.file_selector; use graphical_editor.file_selector; package body graphical_editor.file_selector_callbacks is procedure save_button (object : access gtkada_builder_record'class) is my_widget : gobject; selected_file : unbounded_string; begin my_widget := Get_Object (object, "filechooserdialog1"); selected_file:=empty_string; selected_file := to_unbounded_string(get_filename(Gtk_File_Chooser_dialog(my_widget))); if (selected_file /= empty_string) then case current_kind is when saveas_xml_file => on_saveas_xml_ok_pressed(selected_file); when export_event_table => on_export_event_table_ok_pressed(selected_file); when aadl_export => on_aadl_export_ok_pressed(selected_file); when export_arinc653_tsp => on_export_arinc653_tsp_ok_pressed(selected_file); when others => null; end case; Destroy (gtk_widget (my_widget)); Gtk.Main.Main_Quit; end if; end save_button; procedure file_select (object : access gtkada_builder_record'class) is my_widget : gobject; selected_file : unbounded_string; begin my_widget := Get_Object (object, "filechooserdialog1"); selected_file := to_unbounded_string(get_filename(Gtk_File_Chooser_dialog(my_widget))); Destroy (gtk_widget (my_widget)); Gtk.Main.Main_Quit; case current_kind is when open_xml_file => on_open_xml_ok_pressed(selected_file); when aadl_import => on_aadl_import_ok_pressed(selected_file); when import_event_table => on_import_event_table_ok_pressed(selected_file); when others => null; end case; end file_select; procedure cancel_button (object : access gtkada_builder_record'class) is my_widget : gobject; begin my_widget := Get_Object (object, "filechooserdialog1"); Destroy (gtk_widget (my_widget)); Gtk.Main.Main_Quit; end cancel_button; ----------------------------------------- -- Open XML file specific subprograms ----------------------------------------- procedure on_open_xml_ok_pressed (selected_file : in unbounded_string) is begin do_open; xml_project_file_name := selected_file; begin systems.read_from_xml_file (sys, project_file_dir_list, xml_project_file_name); Set_Text (model_file_name_entry, To_String (simple_name (xml_project_file_name))); is_saved := True; starting_text; exception when xml_read_error => show_message_box (lb_can_not_read_file (current_language) & To_Unbounded_String (" ; Xml Fatal Error ; ") & Exception_Message); when Ada.IO_Exceptions.Name_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Name_Error")); when Ada.IO_Exceptions.Status_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Status_Error")); when Ada.IO_Exceptions.Mode_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Mode_Error")); when Ada.IO_Exceptions.Use_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Use_Error")); when Ada.IO_Exceptions.Device_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Device_Error")); when Ada.IO_Exceptions.End_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", End_Error")); when Ada.IO_Exceptions.Data_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Data_Error")); when Ada.IO_Exceptions.Layout_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Layout_Error")); when others => show_message_box (lb_can_not_read_file (current_language) & " ; " & Exception_Name & " ; " & Exception_Message); end; end on_open_xml_ok_pressed; ----------------------------------------- -- Saveas XML file specific subprograms ----------------------------------------- procedure on_saveas_xml_ok_pressed (selected_file : in unbounded_string) is begin xml_project_file_name := selected_file; begin systems.write_to_xml_file (sys, xml_project_file_name); Set_Text (model_file_name_entry, To_String (simple_name (xml_project_file_name))); is_saved := True; is_new := False; exception when Ada.IO_Exceptions.Name_Error => xml_project_file_name := empty_string; show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Name_Error")); when Ada.IO_Exceptions.Status_Error => xml_project_file_name := empty_string; show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Status_Error")); when Ada.IO_Exceptions.Mode_Error => xml_project_file_name := empty_string; show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Mode_Error")); when Ada.IO_Exceptions.Use_Error => xml_project_file_name := empty_string; show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Use_Error")); when Ada.IO_Exceptions.Device_Error => xml_project_file_name := empty_string; show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Device_Error")); when Ada.IO_Exceptions.End_Error => xml_project_file_name := empty_string; show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", End_Error")); when Ada.IO_Exceptions.Data_Error => xml_project_file_name := empty_string; show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Data_Error")); when Ada.IO_Exceptions.Layout_Error => xml_project_file_name := empty_string; show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Layout_Error")); when others => xml_project_file_name := empty_string; show_message_box (lb_can_not_save_file (current_language) & " ; Exception name : " & Exception_Name & " ; " & "Exception message : " & Exception_Message); end; end on_saveas_xml_ok_pressed; ----------------------------------------- -- AADL import file specific subprograms ----------------------------------------- procedure on_aadl_import_ok_pressed (selected_file : in unbounded_string) is temp : constant unbounded_string_ptr := new Unbounded_String; begin do_aadl_import; temp.all := selected_file; begin add (aadl_project_file_name, temp); systems.read_from_aadl_file (sys, project_file_dir_list, aadl_project_file_name); Set_Text (model_file_name_entry, To_String (simple_name (temp.all))); is_saved := True; starting_text; exception when aadl_read_error => show_message_box (lb_can_not_read_file (current_language) & To_Unbounded_String (" ; AADL parsing Error ; ") & Exception_Message); when Ada.IO_Exceptions.Name_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Name_Error")); when Ada.IO_Exceptions.Status_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Status_Error")); when Ada.IO_Exceptions.Mode_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Mode_Error")); when Ada.IO_Exceptions.Use_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Use_Error")); when Ada.IO_Exceptions.Device_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Device_Error")); when Ada.IO_Exceptions.End_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", End_Error")); when Ada.IO_Exceptions.Data_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Data_Error")); when Ada.IO_Exceptions.Layout_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Layout_Error")); when others => show_message_box (lb_can_not_read_file (current_language) & " ; " & Exception_Name & " ; " & Exception_Message); end; end on_aadl_import_ok_pressed; ----------------------------------------- -- AADL export file specific subprograms ----------------------------------------- procedure on_aadl_export_ok_pressed (selected_file : in unbounded_string) is begin do_aadl_export; begin systems.write_to_aadl_file (sys, selected_file); Set_Text (model_file_name_entry, To_String (simple_name (selected_file))); exception when Ada.IO_Exceptions.Name_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Name_Error")); when Ada.IO_Exceptions.Status_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Status_Error")); when Ada.IO_Exceptions.Mode_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Mode_Error")); when Ada.IO_Exceptions.Use_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Use_Error")); when Ada.IO_Exceptions.Device_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Device_Error")); when Ada.IO_Exceptions.End_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", End_Error")); when Ada.IO_Exceptions.Data_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Data_Error")); when Ada.IO_Exceptions.Layout_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Layout_Error")); when others => show_message_box (lb_can_not_save_file (current_language) & " ; Exception name : " & Exception_Name & " ; " & "Exception message : " & Exception_Message); end; end on_aadl_export_ok_pressed; ------------------------------------------------------ -- Import XML event table file specific subprograms ------------------------------------------------------ procedure on_import_event_table_ok_pressed (selected_file : in unbounded_string) is begin xml_event_table_file_name := selected_file; begin read_from_xml_file (framework.sched, sys, xml_event_table_file_name); exception when xml_read_error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Xml Fatal Error")); when Ada.IO_Exceptions.Name_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Name_Error")); when Ada.IO_Exceptions.Status_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Status_Error")); when Ada.IO_Exceptions.Mode_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Mode_Error")); when Ada.IO_Exceptions.Use_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Use_Error")); when Ada.IO_Exceptions.Device_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Device_Error")); when Ada.IO_Exceptions.End_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", End_Error")); when Ada.IO_Exceptions.Data_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Data_Error")); when Ada.IO_Exceptions.Layout_Error => show_message_box (lb_can_not_open_file (current_language) & To_Unbounded_String (", Layout_Error")); when others => show_message_box (lb_can_not_open_file (current_language) & " ; Exception name : " & Exception_Name & " ; " & "Exception message : " & Exception_Message); end; end on_import_event_table_ok_pressed; ------------------------------------------------------ -- Export XML event table file specific subprograms ------------------------------------------------------ procedure on_export_event_table_ok_pressed (selected_file : in unbounded_string) is begin xml_event_table_file_name := selected_file; begin write_to_xml_file (framework.sched, sys, xml_event_table_file_name); exception when Ada.IO_Exceptions.Name_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Name_Error")); when Ada.IO_Exceptions.Status_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Status_Error")); when Ada.IO_Exceptions.Mode_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Mode_Error")); when Ada.IO_Exceptions.Use_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Use_Error")); when Ada.IO_Exceptions.Device_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Device_Error")); when Ada.IO_Exceptions.End_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", End_Error")); when Ada.IO_Exceptions.Data_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Data_Error")); when Ada.IO_Exceptions.Layout_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Layout_Error")); when others => show_message_box (lb_can_not_open_file (current_language) & " ; Exception name : " & Exception_Name & " ; " & "Exception message : " & Exception_Message); end; end on_export_event_table_ok_pressed; ------------------------------------------------------ -- Export XML ARINS 653 TSP ------------------------------------------------------ procedure on_export_arinc653_tsp_ok_pressed (selected_file : in unbounded_string) is input : file_input; reader : tree_reader; d : document; into : File_Type; -- The ARINC module to produce from the Cheddar ADL model -- a_module : arinc_653_module_ptr; begin begin -- Compute PST -- a_module := build_arinc653_module (framework.sched, sys, framework.scheduling_base_period); -- Open file and Write XML Header -- Create (into, Mode => Out_File, Name => To_String (selected_file)); Put_Line (into, " "); New_Line (into, 2); Put (into, To_String (xml_string (a_module))); Close (into); Open (To_String (selected_file), input); Parse (reader, input); d := Get_Tree (reader); Close (input); Create (into, Mode => Out_File, Name => To_String (selected_file)); Write (Stream => Stream (into), N => d, Print_Comments => False, Print_XML_Declaration => True, With_URI => False, EOL_Sequence => "" & ASCII.LF, Pretty_Print => True, Encoding => Unicode.Encodings.Get_By_Name ("utf-8"), Collapse_Empty_Nodes => False); Free (reader); Close (into); exception when Ada.IO_Exceptions.Name_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Name_Error")); when Ada.IO_Exceptions.Status_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Status_Error")); when Ada.IO_Exceptions.Mode_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Mode_Error")); when Ada.IO_Exceptions.Use_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Use_Error")); when Ada.IO_Exceptions.Device_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Device_Error")); when Ada.IO_Exceptions.End_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", End_Error")); when Ada.IO_Exceptions.Data_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Data_Error")); when Ada.IO_Exceptions.Layout_Error => show_message_box (lb_can_not_save_file (current_language) & To_Unbounded_String (", Layout_Error")); when others => show_message_box (lb_can_not_open_file (current_language) & " ; Exception name : " & Exception_Name & " ; " & "Exception message : " & Exception_Message); end; end on_export_arinc653_tsp_ok_pressed; end graphical_editor.file_selector_callbacks;