public void DeletePort(PortPainter portPainter) { if (portPainter == null) { return; } foreach (CompositionInstance composition in Compositions) { List <PortConnection> connectionPainters = composition.Connections.FindConnections(portPainter); if (connectionPainters.Count > 0) { foreach (PortConnection connection in connectionPainters) { composition.Connections.Remove(connection); } } } IElementWithPorts componentPainter = FindComponentInstanceByPortGuid(portPainter.GUID); if (componentPainter != null) { componentPainter.Ports.Remove(portPainter); } }
public bool CouldPortsBeAssigned(PortPainter port1, PortPainter port2) { /* Ports shall be different */ if (port1 == port2) { return(false); } /* ports shall have different parent */ IElementWithPorts component1 = AutosarApplication.GetInstance().FindComponentInstanceByPort(port1); IElementWithPorts component2 = AutosarApplication.GetInstance().FindComponentInstanceByPort(port2); if ((component1 == component2) || (component1 == null) || (component2 == null)) { return(false); } /* Ports shall have the same interfaces */ PortDefenition portDef1 = AutosarApplication.GetInstance().GetPortDefenition(port1.PortDefenitionGuid); PortDefenition portDef2 = AutosarApplication.GetInstance().GetPortDefenition(port2.PortDefenitionGuid); if (!portDef1.InterfaceGUID.Equals(portDef2.InterfaceGUID)) { return(false); } if (!port1.IsDelegatePort && !port2.IsDelegatePort) { /* Another port shall be the correspondent type */ bool check = (portDef1.PortType == PortType.Client) && (portDef2.PortType == PortType.Server); check |= (portDef1.PortType == PortType.Server) && (portDef2.PortType == PortType.Client); check |= (portDef1.PortType == PortType.Receiver) && (portDef2.PortType == PortType.Sender); check |= (portDef1.PortType == PortType.Sender) && (portDef2.PortType == PortType.Receiver); if (!check) { return(false); } } else /* One of the ports is delegate */ { /* Port shall have the same type */ bool check = (portDef1.PortType == portDef2.PortType); if (!check) { return(false); } } return(true); }
/* Search if this port has been already used in other connection */ bool IsThisPointConnectionExists(IElementWithPorts component, PortPainter port) { foreach (PortConnection connection in this) { if ((connection.Component1 == component) && (connection.Port1 == port)) { return(true); } if ((connection.Component2 == component) && (connection.Port2 == port)) { return(true); } } return(false); }
void GenerateStaticVariablesForSenderPortsWithoutMultipleInstantiation(StreamWriter writer, PortPainter port, SenderReceiverInterfaceField field) { /* Declare variable and its default value */ IElementWithPorts compInst = AutosarApplication.GetInstance().FindComponentInstanceByPortGuid(port.GUID); String staticVariableName = RteFunctionsGenerator.GenerateRte_Component_SRInterface_Name(compInst.Name, port.Name, field); if (!field.IsPointer) { writer.Write("static " + field.DataTypeName + " " + staticVariableName + " ="); writer.Write(GenerateRteComponentSenderReceiverInterfaceField_DefaultValue(compInst.Name, port.Name, field)); } else { writer.Write("static " + field.DataTypeName + "* " + staticVariableName + " = 0"); } writer.WriteLine(";"); writer.WriteLine(""); }
public void GetOppositePortAndComponent(PortPainter portPainter, out ComponentInstance oppositeComponent, out PortPainter oppositePort) { oppositeComponent = null; oppositePort = null; if (portPainter.PortDefenition.InterfaceName == "isrDesiredForce") { } PortsConnectionsList portConnections = GetPortConnections(portPainter); if (portConnections.Count != 0) { oppositePort = portConnections[0].GetOppositePort(portPainter); if (oppositePort != null) { IElementWithPorts elem = FindComponentInstanceByPort(oppositePort); if (elem is ComponentInstance) { /* No problem just return the component*/ oppositeComponent = elem as ComponentInstance; } /* the port belongs to the composition */ else if (elem is CompositionInstance) { CompositionInstance composition = elem as CompositionInstance; PortPainter middlePort; /* Is it composition's external port?*/ int externalPortIndex = composition.Ports.IndexOf(oppositePort); if (externalPortIndex >= 0) { /* get internal index */ middlePort = composition.InternalPortsInstances[externalPortIndex]; } else /* It was internal port */ { /* get external port */ int internalPortIndex = composition.InternalPortsInstances.IndexOf(oppositePort); middlePort = composition.Ports[internalPortIndex]; } /* Get middle port connections */ portConnections = GetPortConnections(middlePort); if (portConnections.Count > 0) { PortConnection connection = portConnections[0]; oppositePort = connection.GetOppositePort(middlePort); Object oppositeObject = FindComponentInstanceByPort(oppositePort); /* Check if another port belongs to composition */ if (oppositeObject is CompositionInstance) { CompositionInstance oppositeComposition = oppositeObject as CompositionInstance; PortPainter middlePort2; int externalPortIndex2 = oppositeComposition.Ports.IndexOf(oppositePort); /* get internal index */ middlePort2 = oppositeComposition.InternalPortsInstances[externalPortIndex2]; /* Get middle port connections */ PortsConnectionsList portConnections2 = GetPortConnections(middlePort2); if (portConnections2.Count > 0) { PortConnection connection3 = portConnections2[0]; oppositePort = connection3.GetOppositePort(middlePort2); oppositeComponent = FindComponentInstanceByPort(oppositePort) as ComponentInstance; } } else { oppositeComponent = oppositeObject as ComponentInstance; } } } } } }
public void TranslatePortPainter(PortPainter portPainter, Point worldCordinates, double deltaX, double deltaY) { IElementWithPorts Owner = AutosarApplication.GetInstance().FindComponentInstanceByPortGuid(portPainter.GUID); /* Move port of the component */ if (!AutosarApplication.GetInstance().ActiveComposition.Equals(Owner)) { RectangleSide side; Point closestPoint = MathUtility.getNearestPointInPerimeter( Owner.Painter.Left, Owner.Painter.Top, Owner.Painter.Width, Owner.Painter.Height, worldCordinates.X, worldCordinates.Y, out side ); if (side == portPainter.ConnectionPortLocation) { if ((side == RectangleSide.Left) || (side == RectangleSide.Right)) { if ((worldCordinates.Y >= Owner.Painter.Top) && (worldCordinates.Y <= Owner.Painter.Bottom)) { double newPos = portPainter.Painter.Top + deltaY; if ((newPos >= Owner.Painter.Top) && (newPos <= Owner.Painter.Bottom)) { portPainter.Painter.Top = newPos; } else { portPainter.Painter.Left = closestPoint.X - portPainter.Painter.Width / 2.0f; portPainter.Painter.Top = closestPoint.Y - portPainter.Painter.Height / 2.0f; } } else { portPainter.Painter.Left = closestPoint.X - portPainter.Painter.Width / 2.0f; portPainter.Painter.Top = closestPoint.Y - portPainter.Painter.Height / 2.0f; } } else { if ((worldCordinates.X >= Owner.Painter.Left) && (worldCordinates.X <= Owner.Painter.Right)) { double newPos = portPainter.Painter.Left + deltaX; if ((newPos >= Owner.Painter.Left - portPainter.Painter.Width / 2) && (newPos <= Owner.Painter.Right - portPainter.Painter.Width / 2)) { portPainter.Painter.Left = newPos; } else { portPainter.Painter.Left = closestPoint.X - portPainter.Painter.Width / 2.0f; portPainter.Painter.Top = closestPoint.Y - portPainter.Painter.Height / 2.0f; } } else { portPainter.Painter.Left = closestPoint.X - portPainter.Painter.Width / 2.0f; portPainter.Painter.Top = closestPoint.Y - portPainter.Painter.Height / 2.0f; } } } else { portPainter.Painter.Left = closestPoint.X - portPainter.Painter.Width / 2.0f; portPainter.Painter.Top = closestPoint.Y - portPainter.Painter.Height / 2.0f; portPainter.ConnectionPortLocation = side; } } else /* Move composition's port inside the composition */ { portPainter.Painter.Left += deltaX; portPainter.Painter.Top += deltaY; } }