---------------------------------- ------------------ ------------------------------ -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . D I A . P R I N T E R . O B J E C T S -- -- -- -- B o d y -- -- -- -- Copyright (C) 2005-2006, GET-Telecom Paris. -- -- -- -- Ocarina is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by the -- -- Free Software Foundation; either version 2, or (at your option) any -- -- later version. Ocarina 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 distributed with Ocarina; see file COPYING. -- -- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth -- -- Floor, Boston, MA 02111-1301, USA. -- -- -- -- As a special exception, if other files instantiate generics from this -- -- unit, or you link this unit with other files to produce an executable, -- -- this unit does not by itself cause the resulting executable to be -- -- covered by the GNU General Public License. This exception does not -- -- however invalidate any other reasons why the executable file might be -- -- covered by the GNU Public License. -- -- -- -- Ocarina is maintained by the Ocarina team -- -- (ocarina-users@listes.enst.fr) -- -- -- ------------------------------------------------------------------------------ -- This package contains the top-level procedures to create the -- objects of the Dia file with DOM.Core.Nodes; use DOM.Core.Nodes; with DOM.Core.Documents; with DOM.Core.Elements; with Ocarina.Dia.Printer.Attribute; with Ocarina.Entities.Messages; with Ocarina.Entities.Components; with Ocarina.Entities.Components.Subcomponents; with Ada.Text_IO; with Ocarina.Nodes; with Namet; with Ocarina.Nutils; with Ocarina.Dia.Printer.Misc; use Ocarina.Dia.Printer.Misc; with DOM.Core.Character_Datas; with DOM.Core.Attrs; with Ocarina.Dia.Printer.Arrow; use Ocarina.Dia.Printer.Arrow; package body Ocarina.Dia.Printer.Objects is function Port_Type (Node : node_id) return String; -------------- -- Add_Name -- -------------- procedure Add_Name (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Name : String) is use Ada.Text_IO; use DOM.Core.Documents; use DOM.Core.Elements; use Ocarina.Dia.Printer.Attribute; use Ocarina.Nodes; XML_Node : DOM.Core.node; XML_Element : constant DOM.Core.element := Create_Element (Doc, "dia:attribute"); XML_Element2 : constant DOM.Core.element := Create_Element (Doc, "dia:composite"); begin Set_Attribute (XML_Element, "name", "name"); Set_Attribute (XML_Element2, "type", "text"); XML_Node := Append_Child (Parent_Node, XML_Element); XML_Node := Append_Child (XML_Node, XML_Element2); Add_Attr_String (Doc, XML_Node, "string", Name); Add_Attr_Font (Doc, XML_Node, "font", "sans", "0", "Helvetica"); Add_Attr_Real (Doc, XML_Node, "height", 0.8); Add_Attr_Point (Doc, XML_Node, "pos", (7.0, 11.0)); Add_Attr_Color (Doc, XML_Node, "color", "#000000"); Add_Attr_Enum (Doc, XML_Node, "alignment", "0"); end Add_Name; ---------------- -- Add_Object -- ---------------- function Add_Object (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Node : node_id; Id : String; Parent_String : String; Typ : String; Decl : String; Name : String) return DOM.Core.node is use Ocarina.Nutils; use Ada.Text_IO; use Namet; use Ocarina.Entities.Components; use DOM.Core.Documents; use DOM.Core.Elements; use Ocarina.Dia.Printer.Attribute; use Ocarina.Nodes; XML_Node : DOM.Core.node; XML_Node2 : DOM.Core.node; pragma warnings (Off, XML_Node2); XML_Element : constant DOM.Core.element := Create_Element (Doc, "dia:object"); XML_Attr1 : constant DOM.Core.element := Create_Element (Doc, "dia:attribute"); XML_Attr2 : constant DOM.Core.element := Create_Element (Doc, "dia:attribute"); XML_Attr3 : constant DOM.Core.element := Create_Element (Doc, "dia:childnode"); List_Node : node_id; begin Set_Attribute (XML_Element, "type", Typ); Set_Attribute (XML_Element, "version", "0"); Set_Attribute (XML_Element, "id", Id); Set_Attribute (XML_Attr1, "name", "aadlbox_ports"); Set_Attribute (XML_Attr2, "name", "aadlbox_connections"); Set_Attribute (XML_Attr3, "parent", Parent_String); XML_Node := Append_Child (Parent_Node, XML_Element); Add_Attr_Point (Doc, XML_Node, "obj_pos", (7.0, 6.0)); Add_Attr_Rectangle (Doc, XML_Node, "obj_bb", ((19.0, 10.0), (23.0, 14.0))); Add_Attr_Point (Doc, XML_Node, "elem_corner", (7.0, 6.0)); Add_Attr_Real (Doc, XML_Node, "elem_width", 1.8); Add_Attr_Real (Doc, XML_Node, "elem_height", 1.8); Add_Attr_Real (Doc, XML_Node, "line_width", 0.0); Add_Attr_Color (Doc, XML_Node, "line_colour", "#000000"); Add_Attr_Color (Doc, XML_Node, "fill_colour", "#ffffff"); Add_Attr_Boolean (Doc, XML_Node, "show_background", True); Add_Attr_String (Doc, XML_Node, "declaration", Decl); -- TODO : find Refines_Type : ignored ? -- TODO : find Subcomponents -- TODO : find Calls -- TODO : find Connections -- TODO : find Flows -- TODO : find Modes -- TODO : find Properties if Kind (Node) = k_component_type and then Ocarina.Nodes.Features (Node) /= No_List then List_Node := First_Node (Ocarina.Nodes.Features (Node)); while Present (List_Node) loop Create_Feature (Doc, XML_Attr1, List_Node); List_Node := Next_Node (List_Node); end loop; end if; -- TODO : find Annexes Add_Name (Doc, XML_Node, Name); XML_Node2 := Append_Child (XML_Node, XML_Attr1); XML_Node2 := Append_Child (XML_Node, XML_Attr2); if Parent_String /= "O-1" then XML_Node2 := Append_Child (XML_Node, XML_Attr3); end if; Put_Line ("Object" & Id & "created"); return XML_Node; end Add_Object; -------------- -- Get_Name -- -------------- function Get_Name (Node : node_id) return String is use Ocarina.Nodes; use Namet; Name_Node : constant node_id := Identifier (Node); begin if Name_Node = No_Node then return ""; else return Get_Name_String (Display_Name (Name_Node)); end if; end Get_Name; ------------------------- -- Get_Name_XML_Object -- ------------------------- function Get_Name_XML_Object (XML_Node : DOM.Core.node) return String is use Ocarina.Nodes; use DOM.Core.Character_Datas; use Ada.Text_IO; List_Node : DOM.Core.node := First_Child (XML_Node); XML_Text : DOM.Core.text; Attr : named_node_map; begin while List_Node /= null loop Attr := Attributes (List_Node); if Length (Attr) /= 0 then if DOM.Core.Attrs.Value (Item (Attr, 0)) = "declaration" then List_Node := First_Child (List_Node); XML_Text := First_Child (List_Node); return Data (XML_Text); end if; end if; List_Node := Next_Sibling (List_Node); end loop; return "##"; end Get_Name_XML_Object; ----------------------- -- Get_Aadlbox_Ports -- ----------------------- function Get_Aadlbox_Ports (XML_Object : DOM.Core.node) return DOM.Core.node is XML_Node : DOM.Core.node := Last_Child (XML_Object); List_Attr : named_node_map; Test_Node : DOM.Core.node; begin if Length (List_Attr) /= 0 then List_Attr := Attributes (XML_Node); Test_Node := Get_Named_Item (List_Attr, "name"); end if; while (Length (List_Attr) = 0) or else Test_Node = null or else Node_Value (Test_Node) /= "aadlbox_ports" loop XML_Node := Previous_Sibling (XML_Node); List_Attr := Attributes (XML_Node); Test_Node := Get_Named_Item (List_Attr, "name"); end loop; return XML_Node; end Get_Aadlbox_Ports; ----------------- -- Port_Type -- ----------------- function Port_Type (Node : node_id) return String is use Ocarina.Nodes; begin if Is_In (Node) then if Is_Out (Node) then if Is_Event (Node) then if Is_Data (Node) then return "19"; else return "18"; end if; else if Is_Data (Node) then return "17"; else raise Program_Error; end if; end if; else if Is_Event (Node) then if Is_Data (Node) then return "13"; else return "12"; end if; else if Is_Data (Node) then return "11"; else raise Program_Error; end if; end if; end if; else if Is_Out (Node) then if Is_Event (Node) then if Is_Data (Node) then return "16"; else return "15"; end if; else if Is_Data (Node) then return "14"; else raise Program_Error; end if; end if; else raise Program_Error; end if; end if; end Port_Type; ------------------ -- Create_Ports -- ------------------ procedure Create_Ports (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Node : node_id) is use Ada.Text_IO; use DOM.Core.Documents; use DOM.Core.Elements; use Ocarina.Nodes; use Ocarina.Dia.Printer.Attribute; XML_Element : constant DOM.Core.element := Create_Element (Doc, "dia:composite"); XML_Node : DOM.Core.node; begin Set_Attribute (XML_Element, "name", "aadlport"); XML_Node := Append_Child (Parent_Node, XML_Element); Add_Attr_Point (Doc, XML_Node, "point", (28.0, 26.0)); Add_Attr_Enum (Doc, XML_Node, "port_type", Port_Type (Node)); Add_Attr_String (Doc, XML_Node, "port_declaration", "#" & Get_Name (Node) & "#"); -- TODO : finish this function, verify is Present (Class_Ref) -- is useful or not end Create_Ports; -------------------- -- Create_Feature -- -------------------- procedure Create_Feature (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Node : node_id) is use Ocarina.Nodes; use Ada.Text_IO; begin case Kind (Node) is when k_parameter => Put_Line ("Parameter ignored"); when k_port_spec => Create_Ports (Doc, Parent_Node, Node); Put_Line ("Port Spec found"); when k_port_group_spec => Put_Line ("Port Group Spec ignored"); when k_subcomponent_access => Put_Line ("Subcomponent Access ignored"); when k_subprogram_spec => Put_Line ("Subprogram Spec ignored"); when others => raise Program_Error; end case; -- TODO : finish this function end Create_Feature; -------------------- -- Node_To_String -- -------------------- function Node_To_String (Node : node_id) return String is use Ada.Text_IO; use Ocarina.Nodes; use Ocarina.Entities.Components; begin case component_category'val (Category (Node)) is when cc_data => return "AADL - Data"; when cc_subprogram => return "AADL - Subprogram"; when cc_thread => return "AADL - Thread"; when cc_threadgroup => return "AADL - Thread Group"; when cc_process => return "AADL - Process"; when cc_memory => return "AADL - Memory"; when cc_processor => return "AADL - Processor"; when cc_bus => return "AADL - Bus"; when cc_device => return "AADL - Device"; when cc_system => return "AADL - System"; when others => Put_Line ("Problème"); return ""; end case; end Node_To_String; --------------------------- -- Create_Component_Type -- --------------------------- function Create_Component_Type (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Node : node_id; Id : Integer; Parent : Integer) return Integer is use Ada.Text_IO; use Ocarina.Nutils; use Ocarina.Nodes; use Namet; use Ocarina.Entities.Components; use Ocarina.Entities.Messages; pragma assert (Node /= No_Node and then (Kind (Node) = k_component_type or else DNKE (Node))); Node_Parent : constant node_id := Ocarina.Nodes.Parent (Node); Next_Id : Integer := Id; XML_Node : DOM.Core.node; begin -- informations de debuggage Put_Line ("Creating Component Type : " & Node_To_String (Node)); -- TODO : finish this function XML_Node := Add_Object (Doc, Parent_Node, Node, "O" & Integer_To_String (Id), "O" & Integer_To_String (Parent), Node_To_String (Node), "#" & Get_Name (Node) & "#", "#" & Get_Name (Node) & "#"); if Present (Node_Parent) then Put_Line ("extension found"); Next_Id := Next_Id + 1; Add_Link_Extension (Doc, Parent_Node, XML_Node, Node_Parent, Next_Id); end if; -- TODO : find features -- TODO : find flows -- TODO : find what to do with properties (ignored ?) -- TODO : find what to do with annexes (ignored ?) return Next_Id + 1; end Create_Component_Type; ------------------------------------- -- Create_Component_Implementation -- ------------------------------------- function Create_Component_Implementation (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Node : node_id; Id : Integer; Parent : Integer) return Integer is use Ocarina.Nutils; use Namet; use DOM.Core.Elements; use Ocarina.Nodes; use Ada.Text_IO; use Ocarina.Entities.Messages; use Ocarina.Entities.Components; pragma assert (Node /= No_Node and then (Kind (Node) = k_component_implementation or else DNKE (Node))); -- Id_String : String := "256"; -- parent_String : String := "256"; Node_Parent : constant node_id := Ocarina.Nodes.Parent (Node); Next_Id : Integer := Id; Node_Object : DOM.Core.node; Node_Ref : constant node_id := Corresponding_Entity (Component_Type_Identifier (Node)); List_Node : node_id; begin -- informations de debuggage Put_Line ("Creating Component Implementation : " & Node_To_String (Node)); -- TODO : finish this function Node_Object := Add_Object (Doc, Parent_Node, Node, "O" & Integer_To_String (Id), "O" & Integer_To_String (Parent), Node_To_String (Node), "#" & Get_Name (Node) & "#", "#" & Get_Name (Node) & "#"); -- Component implementation take ports from his component type if not Is_Empty (Ocarina.Nodes.Features (Node_Ref)) then List_Node := First_Node (Ocarina.Nodes.Features (Node_Ref)); while Present (List_Node) loop Create_Feature (Doc, Get_Aadlbox_Ports (Node_Object), List_Node); List_Node := Next_Node (List_Node); end loop; end if; if Present (Node_Parent) then if not Is_Empty (Ocarina.Nodes.Features (Node_Parent)) then List_Node := First_Node (Ocarina.Nodes.Features (Node_Ref)); while Present (List_Node) loop Create_Feature (Doc, Get_Aadlbox_Ports (Node_Object), List_Node); List_Node := Next_Node (List_Node); end loop; end if; end if; Next_Id := Next_Id + 1; if not Is_Empty (Ocarina.Nodes.Subcomponents (Node)) then List_Node := First_Node (Ocarina.Nodes.Subcomponents (Node)); while Present (List_Node) loop Next_Id := Create_Subcomponent (Doc, Parent_Node, List_Node, Next_Id, Id); List_Node := Next_Node (List_Node); end loop; end if; if not Is_Empty (Ocarina.Nodes.Calls (Node)) then List_Node := First_Node (Ocarina.Nodes.Calls (Node)); while Present (List_Node) loop Next_Id := Create_Call (Doc, Parent_Node, List_Node, Next_Id); List_Node := Next_Node (List_Node); end loop; end if; if not Is_Empty (Ocarina.Nodes.Connections (Node)) then List_Node := First_Node (Ocarina.Nodes.Connections (Node)); while Present (List_Node) loop Next_Id := Next_Id + 1; Add_AADLConnection (Doc, Parent_Node, Source (List_Node), Destination (List_Node), Next_Id, Id, Get_Name (Node)); List_Node := Next_Node (List_Node); end loop; end if; if Present (Node_Parent) then Next_Id := Next_Id + 1; Add_Link_Extension (Doc, Parent_Node, Node_Object, Node_Parent, Next_Id); end if; Next_Id := Next_Id + 1; Add_Link_Implementation (Doc, Parent_Node, Node_Object, Node_Ref, Next_Id); return Next_Id + 1; end Create_Component_Implementation; ------------------------- -- Create_Subcomponent -- ------------------------- function Create_Subcomponent (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Node : node_id; Id : Integer; Id_Parent : Integer) return Integer is use Ada.Text_IO; use Ocarina.Nodes; use Ocarina.Nutils; use Ocarina.Entities.Components.Subcomponents; use Namet; Node_Object : DOM.Core.node; Class_Ref : constant node_id := Get_Corresponding_Component (Node); Node_Ref : node_id; List_Node : node_id; begin if Class_Ref /= No_Node then if Kind (Class_Ref) = k_component_implementation then Node_Ref := Corresponding_Entity (Component_Type_Identifier (Class_Ref)); else Node_Ref := Class_Ref; end if; Node_Object := Add_Object (Doc, Parent_Node, Class_Ref, "O" & Integer_To_String (Id), "O" & Integer_To_String (Id_Parent), Node_To_String (Node), "#" & Get_Name (Node) & "#", "#" & Get_Name (Node) & "#"); if not Is_Empty (Ocarina.Nodes.Features (Node_Ref)) then List_Node := First_Node (Ocarina.Nodes.Features (Node_Ref)); while Present (List_Node) loop Create_Feature (Doc, Get_Aadlbox_Ports (Node_Object), List_Node); List_Node := Next_Node (List_Node); end loop; end if; Put_Line ("Subcomponent created"); return Id + 1; else return Id; end if; end Create_Subcomponent; ----------------- -- Create_Call -- ----------------- function Create_Call (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Node : node_id; Id : Integer) return Integer is use Ada.Text_IO; pragma unreferenced (Node); pragma unreferenced (Parent_Node); pragma unreferenced (Doc); begin -- TODO : this function Put_Line ("call ignored"); return Id; end Create_Call; ----------------- -- Create_Flow -- ----------------- function Create_Flow (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Node : node_id; Id : Integer) return Integer is use Ada.Text_IO; pragma unreferenced (Node); pragma unreferenced (Parent_Node); pragma unreferenced (Doc); begin -- TODO : this function Put_Line ("flow ignored"); return Id; end Create_Flow; ----------------- -- Create_Mode -- ----------------- function Create_Mode (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Node : node_id; Id : Integer) return Integer is use Ada.Text_IO; pragma unreferenced (Node); pragma unreferenced (Parent_Node); pragma unreferenced (Doc); begin -- TODO : this function Put_Line ("mode ignored"); return Id; end Create_Mode; -------------------- -- Create_Package -- -------------------- function Create_Package (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Node : node_id; Id : Integer) return Integer is use Ada.Text_IO; pragma unreferenced (Node); pragma unreferenced (Parent_Node); pragma unreferenced (Doc); begin -- TODO : this function Put_Line ("package ignored"); return Id; end Create_Package; end Ocarina.Dia.Printer.Objects;