-------------------------------------------------------- ------------------------ -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . D I A . P R I N T E R . A R R O W -- -- -- -- B o d y -- -- -- -- Copyright (C) 2005-2007, 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) -- -- -- ------------------------------------------------------------------------------ with DOM.Core.Nodes; with Ada.Text_IO; with Ocarina.Dia.Printer.Attribute; with Ocarina.Dia.Printer.Objects; with DOM.Core.Elements; with DOM.Core.Documents; with Ocarina.Dia.Printer.Misc; use Ocarina.Dia.Printer.Misc; with Ocarina.Entities; package body Ocarina.Dia.Printer.Arrow is -------------------- -- Add_Connection -- -------------------- procedure Add_Connection (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Handle : String; To : String; Connection : String) is use DOM.Core.Nodes; use DOM.Core.Documents; use DOM.Core.Elements; XML_Element : constant DOM.Core.element := Create_Element (Doc, "dia:connection"); XML_Node : DOM.Core.node; pragma warnings (Off, XML_Node); begin Set_Attribute (XML_Element, "handle", Handle); Set_Attribute (XML_Element, "to", To); Set_Attribute (XML_Element, "connection", Connection); XML_Node := Append_Child (Parent_Node, XML_Element); end Add_Connection; --------------- -- Add_Arrow -- --------------- procedure Add_Arrow (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Type_Arrow : String; Id_Arrow : Integer; Id_Root : String; FirstHandle : Integer; Id_Target : String; LastHandle : Integer) is use Ada.Text_IO; use DOM.Core.Nodes; use DOM.Core.Documents; use DOM.Core.Elements; use Ocarina.Dia.Printer.Attribute; XML_Element : constant DOM.Core.element := Create_Element (Doc, "dia:object"); XML_Node : DOM.Core.node; FirstHandle_String : constant String := Integer_To_String (FirstHandle); LastHandle_String : constant String := Integer_To_String (LastHandle); XML_Node_Temp : DOM.Core.node; XML_Element2 : constant DOM.Core.element := Create_Element (Doc, "dia:connections"); begin Set_Attribute (XML_Element, "type", "Standard - Line"); Set_Attribute (XML_Element, "version", "0"); Set_Attribute (XML_Element, "id", "O" & Integer_To_String (Id_Arrow)); 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", ((7.0, 5.0), (10.0, 12.0))); Add_Attr_Point (Doc, XML_Node, "conn_endpoints", (7.0, 6.0)); XML_Node_Temp := Last_Child (XML_Node); Add_Point (Doc, XML_Node_Temp, (7.0, 6.0)); Add_Attr_Int (Doc, XML_Node, "numcp", 1); Add_Attr_Enum (Doc, XML_Node, "line_style", Type_Arrow); Add_Attr_Enum (Doc, XML_Node, "end_arrow", "2"); Add_Attr_Real (Doc, XML_Node, "end_arrow_length", 0.5); Add_Attr_Real (Doc, XML_Node, "end_arrow_width", 0.5); XML_Node := Append_Child (XML_Node, XML_Element2); Add_Connection (Doc, XML_Node, "0", Id_Root, FirstHandle_String); Add_Connection (Doc, XML_Node, "1", Id_Target, LastHandle_String); Put_Line ("arrow added : " & "O" & Integer_To_String (Id_Arrow)); end Add_Arrow; -------------- -- Add_Line -- -------------- procedure Add_Line (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Id_Arrow : Integer; Id_Root : String; FirstHandle : Integer; Id_Target : String; LastHandle : Integer; Parent : Integer) is use Ada.Text_IO; use DOM.Core.Nodes; use DOM.Core.Documents; use DOM.Core.Elements; use Ocarina.Dia.Printer.Attribute; XML_Element : constant DOM.Core.element := Create_Element (Doc, "dia:object"); XML_Node : DOM.Core.node; FirstHandle_String : constant String := Integer_To_String (FirstHandle); LastHandle_String : constant String := Integer_To_String (LastHandle); XML_Node_Temp : DOM.Core.node; XML_Element2 : constant DOM.Core.element := Create_Element (Doc, "dia:connections"); XML_Attr : constant DOM.Core.element := Create_Element (Doc, "dia:childnode"); XML_Node2 : DOM.Core.node; begin Set_Attribute (XML_Element, "type", "Standard - Line"); Set_Attribute (XML_Element, "version", "0"); Set_Attribute (XML_Element, "id", "O" & Integer_To_String (Id_Arrow)); 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", ((7.0, 5.0), (10.0, 12.0))); Add_Attr_Point (Doc, XML_Node, "conn_endpoints", (7.0, 6.0)); XML_Node_Temp := Last_Child (XML_Node); Add_Point (Doc, XML_Node_Temp, (7.0, 6.0)); Add_Attr_Int (Doc, XML_Node, "numcp", 1); Add_Attr_Enum (Doc, XML_Node, "line_style", "0"); XML_Node2 := Append_Child (XML_Node, XML_Element2); Add_Connection (Doc, XML_Node2, "0", Id_Root, FirstHandle_String); Add_Connection (Doc, XML_Node2, "1", Id_Target, LastHandle_String); Set_Attribute (XML_Attr, "parent", "O" & Integer_To_String (Parent)); if Parent /= -1 then XML_Node := Append_Child (XML_Node, XML_Attr); end if; Put_Line ("Line added : " & "O" & Integer_To_String (Id_Arrow)); end Add_Line; ------------------------- -- Add_Link_Extenstion -- ------------------------- procedure Add_Link_Extension (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Root : DOM.Core.node; Target : node_id; Next_Id : Integer) is use Ada.Text_IO; use Ocarina.Dia.Printer.Attribute; FirstHandle : Integer; LastHandle : Integer; XML_Node : DOM.Core.node; begin Put_Line ("Extension found"); XML_Node := Find_Node (Doc, Target); FirstHandle := Add_Point_Connection (Doc, Root); LastHandle := Add_Point_Connection (Doc, XML_Node); Add_Arrow (Doc, Parent_Node, "0", Next_Id, Id (Root), FirstHandle, Id (XML_Node), LastHandle); end Add_Link_Extension; ----------------------------- -- Add_Link_Implementation -- ----------------------------- procedure Add_Link_Implementation (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Root : DOM.Core.node; Target : node_id; Next_Id : Integer) is use Ada.Text_IO; use Ocarina.Dia.Printer.Attribute; FirstHandle : Integer; LastHandle : Integer; XML_Node : DOM.Core.node; begin Put_Line ("Implementation found"); XML_Node := Find_Node (Doc, Target); FirstHandle := Add_Point_Connection (Doc, Root); LastHandle := Add_Point_Connection (Doc, XML_Node); Add_Arrow (Doc, Parent_Node, "4", Next_Id, Id (Root), FirstHandle, Id (XML_Node), LastHandle); end Add_Link_Implementation; ------------------------ -- Add_AADLConnection -- ------------------------ procedure Add_AADLConnection (Doc : DOM.Core.document; Parent_Node : DOM.Core.node; Root : node_id; Target : node_id; Next_Id : Integer; Parent : Integer; Name : String) is use Ada.Text_IO; use Ocarina.Dia.Printer.Objects; First_Handle : Integer; Last_Handle : Integer; pragma warnings (Off, First_Handle); pragma warnings (Off, Last_Handle); rootId : constant String := Get_Id_Of_Port (Doc, Root, Name); targetId : constant String := Get_Id_Of_Port (Doc, Target, Name); begin Put_Line ("AADL Connection created " & Get_Name (Root) & " -> " & Get_Name (Target)); First_Handle := Get_Connection_Number (Doc, Root, rootId); Last_Handle := Get_Connection_Number (Doc, Target, targetId); Put_Line ("id1 : " & rootId & " , id2 : " & targetId); Add_Line (Doc, Parent_Node, Next_Id, rootId, First_Handle, targetId, Last_Handle, Parent); end Add_AADLConnection; -------------------- -- Get_Id_Of_Port -- -------------------- function Get_Id_Of_Port (Doc : DOM.Core.document; Node : node_id; Name : String) return String is use Ada.Text_IO; use Ocarina.Dia.Printer.Objects; use DOM.Core.Nodes; use Ocarina.Entities; Name_Port : constant String := Get_Name (Node); Name_Port_Entity : constant String := Get_Name (Get_Referenced_Entity (Node)); N : Integer; N2 : Integer; XML_Node : DOM.Core.node := Doc; List_Node : DOM.Core.node; begin -- TODO : this function is dangerous N := Name_Port'length; N2 := Name_Port_Entity'length; XML_Node := Last_Child (Doc); XML_Node := Last_Child (XML_Node); List_Node := First_Child (XML_Node); if N = N2 then declare Name_Node : constant String := "#" & Name & "#"; begin while List_Node /= null loop if Name_Node = Get_Name_XML_Object (List_Node) then return Id (List_Node); end if; List_Node := Next_Sibling (List_Node); end loop; end; else declare Name_Node : constant String := "#" & Name_Port (1 .. (N - N2 - 1)) & "#"; begin while List_Node /= null loop if Name_Node = Get_Name_XML_Object (List_Node) then return Id (List_Node); end if; List_Node := Next_Sibling (List_Node); end loop; end; end if; Put_Line ("Attention, erreur possible"); return "O0"; end Get_Id_Of_Port; --------------------------- -- Get_Connection_Number -- --------------------------- function Get_Connection_Number (Doc : DOM.Core.document; Node : node_id; I : String) return Integer is use Ocarina.Dia.Printer.Objects; use Ocarina.Entities; use DOM.Core.Nodes; use Ada.Text_IO; XML_Node : DOM.Core.node := Last_Child (Find_Node (Doc, I)); XML_Childs : DOM.Core.node; List_Attr : named_node_map; Test_Node : DOM.Core.node; Num_Connec : Integer := 0; Name : constant String := "#" & Get_Name (Get_Referenced_Entity (Node)) & "#"; begin List_Attr := Attributes (XML_Node); if Length (List_Attr) /= 0 then 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; XML_Childs := First_Child (XML_Node); while XML_Childs /= null and then Get_Name_Of_XML_Port (XML_Childs) /= Name loop XML_Childs := Next_Sibling (XML_Childs); Num_Connec := Num_Connec + 2; end loop; -- WARNING : We don't know if the good result should be -- Num_Connec or Num_Connec+1 return Num_Connec + 1; end Get_Connection_Number; end Ocarina.Dia.Printer.Arrow;