------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- 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-2020, 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 AUTHORS.txt and SPONSORS.txt -- -- 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$ -- $Date$ -- $Author: singhoff $ ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ 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.Dialog; use Gtk.Dialog; with Gtk.Button; use Gtk.Button; with Gtk.About_Dialog; use Gtk.About_Dialog; 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.GC; use Gdk.GC; with Gdk.Window; use Gdk.Window; with Gdk.Font; use Gdk.Font; with Gdk.Event; use Gdk.Event; with Pango.Font; use Pango.Font; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; 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 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_simulation_draw_callbacks; use graphical_editor.scheduling_simulation_draw_callbacks; with multiprocessor_services; use multiprocessor_services; with arinc_653_schema; use arinc_653_schema; with arinc_653_services; use arinc_653_services; with Unicode.CES; use Unicode.CES; with Unicode.Encodings; use Unicode.Encodings; 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 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 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 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; package body graphical_editor.file_selector is ----------------------------------------- -- Subprogram for all file selectors ----------------------------------------- procedure on_cancel_pressed (object : access gtk_button_record'class) is begin Destroy (Get_Toplevel (gtk_widget (object))); end on_cancel_pressed; procedure gtk_new (file_selector : out file_selector_access) is begin file_selector := new file_selector_record; end gtk_new; procedure initialize (file_selector : access file_selector_record'class; label : Unbounded_String) is begin Gtk.File_Selection.Initialize (file_selector, To_String (label)); Set_Show_File_Op_Buttons (file_selector, True); Set_Border_Width (file_selector, 10); Set_Title (file_selector, To_String (label)); Set_Policy (file_selector, False, True, False); Set_Position (file_selector, win_pos_center_always); Set_Modal (file_selector, True); file_selector.cancel_button := Get_Cancel_Button (file_selector); Set_Flags (file_selector.cancel_button, can_default); button_callback.Connect (file_selector.cancel_button, "clicked", button_callback.To_Marshaller (on_cancel_pressed'access)); end initialize; ----------------------------------------- -- Open XML file specific subprograms ----------------------------------------- procedure on_open_xml_ok_pressed (object : access gtk_button_record'class) is begin do_open; xml_project_file_name := To_Unbounded_String (Get_Filename (file_selector_widget)); 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; Destroy (file_selector_widget); end on_open_xml_ok_pressed; procedure initialize_open_xml_file (file_selector : access file_selector_record'class) is begin initialize (file_selector, lb_open_xml (current_language) & To_Unbounded_String (" ") & lb_file (current_language)); file_selector.ok_button := Get_Ok_Button (file_selector); Set_Flags (file_selector.ok_button, can_default); button_callback.Connect (file_selector.ok_button, "clicked", button_callback.To_Marshaller (on_open_xml_ok_pressed'access)); end initialize_open_xml_file; ----------------------------------------- -- Saveas XML file specific subprograms ----------------------------------------- procedure on_saveas_xml_ok_pressed (object : access gtk_button_record'class) is begin xml_project_file_name := To_Unbounded_String (Get_Filename (file_selector_widget)); 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; Destroy (file_selector_widget); end on_saveas_xml_ok_pressed; procedure initialize_saveas_xml_file (file_selector : access file_selector_record'class) is begin initialize (file_selector, lb_save_as_xml (current_language)); file_selector.ok_button := Get_Ok_Button (file_selector); Set_Flags (file_selector.ok_button, can_default); button_callback.Connect (file_selector.ok_button, "clicked", button_callback.To_Marshaller (on_saveas_xml_ok_pressed'access)); end initialize_saveas_xml_file; ----------------------------------------- -- AADL import file specific subprograms ----------------------------------------- procedure on_aadl_import_ok_pressed (object : access gtk_button_record'class) is file : Unbounded_String; temp : constant unbounded_string_ptr := new Unbounded_String; begin do_aadl_import; file := To_Unbounded_String (Get_Filename (file_selector_widget)); temp.all := 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; Destroy (file_selector_widget); end on_aadl_import_ok_pressed; procedure initialize_aadl_import (file_selector : access file_selector_record'class) is begin initialize (file_selector, lb_import_aadl (current_language)); file_selector.ok_button := Get_Ok_Button (file_selector); Set_Flags (file_selector.ok_button, can_default); button_callback.Connect (file_selector.ok_button, "clicked", button_callback.To_Marshaller (on_aadl_import_ok_pressed'access)); end initialize_aadl_import; ----------------------------------------- -- AADL export file specific subprograms ----------------------------------------- procedure on_aadl_export_ok_pressed (object : access gtk_button_record'class) is file : Unbounded_String; begin do_aadl_export; file := To_Unbounded_String (Get_Filename (file_selector_widget)); begin systems.write_to_aadl_file (sys, file); Set_Text (model_file_name_entry, To_String (simple_name (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; Destroy (file_selector_widget); end on_aadl_export_ok_pressed; procedure initialize_aadl_export (file_selector : access file_selector_record'class) is begin initialize (file_selector, lb_export_aadl (current_language)); file_selector.ok_button := Get_Ok_Button (file_selector); Set_Flags (file_selector.ok_button, can_default); button_callback.Connect (file_selector.ok_button, "clicked", button_callback.To_Marshaller (on_aadl_export_ok_pressed'access)); end initialize_aadl_export; ------------------------------------------------------ -- Import XML event table file specific subprograms ------------------------------------------------------ procedure on_import_event_table_ok_pressed (object : access gtk_button_record'class) is begin xml_event_table_file_name := To_Unbounded_String (Get_Filename (file_selector_widget)); 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; Destroy (file_selector_widget); end on_import_event_table_ok_pressed; procedure initialize_import_event_table (file_selector : access file_selector_record'class) is begin initialize (file_selector, lb_import_event_table (current_language)); file_selector.ok_button := Get_Ok_Button (file_selector); Set_Flags (file_selector.ok_button, can_default); button_callback.Connect (file_selector.ok_button, "clicked", button_callback.To_Marshaller (on_import_event_table_ok_pressed'access)); end initialize_import_event_table; ------------------------------------------------------ -- Export XML event table file specific subprograms ------------------------------------------------------ procedure on_export_event_table_ok_pressed (object : access gtk_button_record'class) is begin xml_event_table_file_name := To_Unbounded_String (Get_Filename (file_selector_widget)); 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; Destroy (file_selector_widget); end on_export_event_table_ok_pressed; procedure initialize_export_event_table (file_selector : access file_selector_record'class) is begin initialize (file_selector, lb_export_event_table (current_language)); file_selector.ok_button := Get_Ok_Button (file_selector); Set_Flags (file_selector.ok_button, can_default); button_callback.Connect (file_selector.ok_button, "clicked", button_callback.To_Marshaller (on_export_event_table_ok_pressed'access)); end initialize_export_event_table; ------------------------------------------------------ -- Export XML ARINS 653 TSP ------------------------------------------------------ procedure on_export_arinc653_tsp_ok_pressed (object : access gtk_button_record'class) is file_name : Unbounded_String; 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 file_name := To_Unbounded_String (Get_Filename (file_selector_widget)); -- 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 (file_name)); Put_Line (into, " "); New_Line (into, 2); Put (into, To_String (xml_string (a_module))); Close (into); Open (To_String (file_name), input); Parse (reader, input); d := Get_Tree (reader); Close (input); Create (into, Mode => Out_File, Name => To_String (file_name)); 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; Destroy (file_selector_widget); end on_export_arinc653_tsp_ok_pressed; procedure initialize_export_arinc653_tsp (file_selector : access file_selector_record'class) is begin initialize (file_selector, lb_export_arinc653_tsp (current_language)); file_selector.ok_button := Get_Ok_Button (file_selector); Set_Flags (file_selector.ok_button, can_default); button_callback.Connect (file_selector.ok_button, "clicked", button_callback.To_Marshaller (on_export_arinc653_tsp_ok_pressed'access)); end initialize_export_arinc653_tsp; end graphical_editor.file_selector;