Пример #1
0
        private void AddConnectedInputPorts(ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkPort port, ISet <ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkPort> visited)
        {
            visited.Add(port);

            if (port.Attributes.SimulinkPortDirection == ISIS.GME.Dsml.CyPhyML.Classes.SimulinkPort.AttributesClass.SimulinkPortDirection_enum.@in && port.ParentContainer is ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkModel)
            {
                var parentComponentName =
                    SimulinkBlock.GetBlockName((ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkModel)port.ParentContainer);
                var portId = GetPortId(port);
                ConnectedInputPorts.Add(string.Format("{0}/{1}", parentComponentName, portId));
                SimulinkGenerator.GMEConsole.Info.WriteLine("Connection: {0}/{1}", parentComponentName, portId);
            }

            foreach (var connection in port.SrcConnections.PortCompositionCollection)
            {
                var adjacent = connection.SrcEnd;
                if (adjacent is ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkPort && !visited.Contains(adjacent))
                {
                    AddConnectedInputPorts((ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkPort)adjacent, visited);
                }
            }

            foreach (var connection in port.DstConnections.PortCompositionCollection)
            {
                var adjacent = connection.DstEnd;
                if (adjacent is ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkPort && !visited.Contains(adjacent))
                {
                    AddConnectedInputPorts((ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkPort)adjacent, visited);
                }
            }
        }
Пример #2
0
        private static string GetPortId(ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkPort port)
        {
            var portId = port.Attributes.SimulinkPortID;

            if (string.IsNullOrWhiteSpace(portId))
            {
                throw new ArgumentException(String.Format("Port '{0}' in object '{1}' has no SimulinkPortID", port.Name, port.ParentContainer.Name));
            }
            return(portId);
        }
Пример #3
0
        public static SimulinkPort FromDomainPort(ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkPort port)
        {
            if (port.Attributes.SimulinkPortDirection != ISIS.GME.Dsml.CyPhyML.Classes.SimulinkPort.AttributesClass.SimulinkPortDirection_enum.@out)
            {
                return(null);
            }
            else
            {
                var result = new SimulinkPort(GetPortId(port));
                result.AddConnectedInputPorts(port, new HashSet <ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkPort>());

                return(result);
            }
        }
Пример #4
0
        public void AddSimulinkObjectToModel(CyPhy.Component component, string blockPath, IEnumerable <string> selectedParams,
                                             IDictionary <string, string> inPorts, IDictionary <string, string> outPorts)
        {
            const int INNER_LEFT_COLUMN_X          = 50;
            const int INNER_RIGHT_COLUMN_X         = 500;
            const int INNER_VERTICAL_OFFSET        = 25;
            const int INNER_VERTICAL_PARAM_SPACING = 100;
            const int INNER_VERTICAL_PORT_SPACING  = 175;

            const int OUTER_LEFT_COLUMN_HORIZONTAL_OFFSET  = -300;
            const int OUTER_RIGHT_COLUMN_HORIZONTAL_OFFSET = 300;
            const int OUTER_VERTICAL_PARAM_SPACING         = 40;
            const int OUTER_VERTICAL_PORT_SPACING          = 100;

            int baseXPosition, baseYPosition;

            getNewModelInitialCoordinates(component, out baseXPosition, out baseYPosition);

            int nextInnerLeftYPosition  = 0;
            int nextInnerRightYPosition = 0;

            int nextOuterLeftYPosition  = baseYPosition;
            int nextOuterRightYPosition = baseYPosition;

            CyPhy.SimulinkModel newSimulinkModel = CyPhyClasses.SimulinkModel.Create(component);
            newSimulinkModel.Name = blockPath;
            newSimulinkModel.Attributes.BlockType        = blockPath;
            newSimulinkModel.Preferences.PortLabelLength = 0;
            setFCOPosition(newSimulinkModel.Impl as MgaFCO, baseXPosition, baseYPosition);


            foreach (var param in selectedParams)
            {
                CyPhy.SimulinkParameter newParam = CyPhyClasses.SimulinkParameter.Create(newSimulinkModel);
                newParam.Name = param;
                setFCOPosition(newParam.Impl as MgaFCO, INNER_LEFT_COLUMN_X, INNER_VERTICAL_OFFSET + nextInnerLeftYPosition);

                CyPhy.Property newProperty = CyPhyClasses.Property.Create(component);
                newProperty.Name = param;
                CyPhyClasses.SimulinkParameterPortMap.Connect(newProperty, newParam);
                setFCOPosition(newProperty.Impl as MgaFCO, baseXPosition + OUTER_LEFT_COLUMN_HORIZONTAL_OFFSET, nextOuterLeftYPosition);

                nextInnerLeftYPosition += INNER_VERTICAL_PARAM_SPACING;
                nextOuterLeftYPosition += OUTER_VERTICAL_PARAM_SPACING;
            }

            foreach (var inPort in inPorts)
            {
                CyPhy.SimulinkPort newPort = CyPhyClasses.SimulinkPort.Create(newSimulinkModel);

                var portName = inPort.Value;
                if (string.IsNullOrWhiteSpace(portName))
                {
                    portName = string.Format("in-{0}", inPort.Key);
                }
                newPort.Name = portName;
                newPort.Attributes.SimulinkPortDirection = CyPhyClasses.SimulinkPort.AttributesClass.SimulinkPortDirection_enum.@in;
                newPort.Attributes.SimulinkPortID        = inPort.Key.ToString();
                setFCOPosition(newPort.Impl as MgaFCO, INNER_LEFT_COLUMN_X, INNER_VERTICAL_OFFSET + nextInnerLeftYPosition);

                CyPhy.Connector newConnector = CyPhyClasses.Connector.Create(component);
                newConnector.Name = portName;
                CyPhy.SimulinkPort connectorPort = CyPhyClasses.SimulinkPort.Create(newConnector);
                connectorPort.Name = portName;
                connectorPort.Attributes.SimulinkPortDirection = CyPhyClasses.SimulinkPort.AttributesClass.SimulinkPortDirection_enum.@in;
                connectorPort.Attributes.SimulinkPortID        = inPort.Key.ToString();
                CyPhyClasses.PortComposition.Connect(connectorPort, newPort, null, null, component);
                setFCOPosition(newConnector.Impl as MgaFCO, baseXPosition + OUTER_LEFT_COLUMN_HORIZONTAL_OFFSET, nextOuterLeftYPosition);

                nextInnerLeftYPosition += INNER_VERTICAL_PORT_SPACING;
                nextOuterLeftYPosition += OUTER_VERTICAL_PORT_SPACING;
            }

            foreach (var outPort in outPorts)
            {
                CyPhy.SimulinkPort newPort = CyPhyClasses.SimulinkPort.Create(newSimulinkModel);

                var portName = outPort.Value;
                if (string.IsNullOrWhiteSpace(portName))
                {
                    portName = string.Format("out-{0}", outPort.Key);
                }
                newPort.Name = portName;
                newPort.Attributes.SimulinkPortDirection = CyPhyClasses.SimulinkPort.AttributesClass.SimulinkPortDirection_enum.@out;
                newPort.Attributes.SimulinkPortID        = outPort.Key.ToString();
                setFCOPosition(newPort.Impl as MgaFCO, INNER_RIGHT_COLUMN_X, INNER_VERTICAL_OFFSET + nextInnerRightYPosition);

                CyPhy.Connector newConnector = CyPhyClasses.Connector.Create(component);
                newConnector.Name = portName;
                CyPhy.SimulinkPort connectorPort = CyPhyClasses.SimulinkPort.Create(newConnector);
                connectorPort.Name = portName;
                connectorPort.Attributes.SimulinkPortDirection = CyPhyClasses.SimulinkPort.AttributesClass.SimulinkPortDirection_enum.@out;
                connectorPort.Attributes.SimulinkPortID        = outPort.Key.ToString();
                CyPhyClasses.PortComposition.Connect(newPort, connectorPort, null, null, component);
                setFCOPosition(newConnector.Impl as MgaFCO, baseXPosition + OUTER_RIGHT_COLUMN_HORIZONTAL_OFFSET, nextOuterRightYPosition);

                nextInnerRightYPosition += INNER_VERTICAL_PORT_SPACING;
                nextOuterRightYPosition += OUTER_VERTICAL_PORT_SPACING;
            }
        }