Esempio n. 1
0
        public static string GetBlockName(ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkModel domainModel)
        {
            if (_blockNameCache.ContainsKey(domainModel))
            {
                return(_blockNameCache[domainModel]);
            }
            else
            {
                var originalCandidateName = domainModel.ParentContainer.Name;
                var candidateName         = originalCandidateName;

                if (string.IsNullOrWhiteSpace(candidateName))
                {
                    throw new ArgumentException(string.Format("Parent of SimulinkModel '{0}' has no name", domainModel.Name));
                }

                while (_usedBlockNames.Contains(candidateName))
                {
                    candidateName = string.Format("{0}-{1:X}", originalCandidateName, _random.Next(0xFFFFFF));
                }

                _usedBlockNames.Add(candidateName);
                _blockNameCache[domainModel] = candidateName;

                return(candidateName);
            }
        }
Esempio n. 2
0
        public static SimulinkBlock FromDomainModel(ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkModel domainModel)
        {
            var result = new SimulinkBlock(GetBlockName(domainModel), domainModel.Attributes.BlockType);

            foreach (var param in domainModel.Children.SimulinkParameterCollection)
            {
                var simulinkParam = SimulinkParameter.FromDomainParameter(param);
                if (simulinkParam != null)
                {
                    result.Parameters.Add(simulinkParam);
                }
            }

            foreach (var port in domainModel.Children.SimulinkPortCollection)
            {
                var simulinkPort = SimulinkPort.FromDomainPort(port);
                if (simulinkPort != null)
                {
                    result.OutgoingPorts.Add(simulinkPort);
                }
            }

            return(result);
        }
Esempio n. 3
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;
            }
        }