Exemplo n.º 1
0
        private UDNGroup CreateGlobalPort(string name, PortType type)
        {
            int width  = 10;
            int height = 15;

            UDNGroup group = new UDNGroup();

            group.Name = name;

            NShape port = new NPolygonShape(new NPointF[] { new NPointF(0, 0),
                                                            new NPointF((int)(width * 1.5), 0),
                                                            new NPointF((int)(width * 1.5 + 10), (int)(height / 2)),
                                                            new NPointF((int)(width * 1.5), (int)(height)),
                                                            new NPointF(0, (int)(height)) });

            group.Shapes.AddChild(port);

            port.Name = name;

            port.CreateShapeElements(ShapeElementsMask.Ports);

            NDynamicPort portInner;

            if (type == PortType.IN)
            {
                portInner = new NDynamicPort(new NContentAlignment(50, 0), DynamicPortGlueMode.GlueToContour);
            }
            else
            {
                portInner = new NDynamicPort(new NContentAlignment(-50, 0), DynamicPortGlueMode.GlueToContour);
            }
            portInner.Name = name;
            port.Ports.AddChild(portInner);

            NTextShape nodeName;

            if (type == PortType.IN)
            {
                nodeName = new NTextShape(name, -(name.Length * 8), 0, name.Length * 8, height);
            }
            else
            {
                nodeName = new NTextShape(name, port.Bounds.Width, 0, name.Length * 8, height);
            }
            nodeName.Style.TextStyle           = new NTextStyle();
            nodeName.Style.TextStyle.FontStyle = new NFontStyle(new Font("Arial", 9));
            if (type == PortType.IN)
            {
                nodeName.Style.TextStyle.StringFormatStyle.HorzAlign = Nevron.HorzAlign.Right;
            }
            else
            {
                nodeName.Style.TextStyle.StringFormatStyle.HorzAlign = Nevron.HorzAlign.Left;
            }

            group.Shapes.AddChild(nodeName);

            group.UpdateModelBounds();

            return(group);
        }
Exemplo n.º 2
0
        private UDNGroup CreateInstance(string name, List <Port> ports, string id)
        {
            int instanceWidth  = 50;
            int instanceHeight = 50;

            int InputMaxSize  = 10;
            int InputCnt      = 0;
            int OutputMaxSize = 10;
            int OutputCnt     = 0;

            int offsetWidth   = 9;
            int offsetHeight  = 30;
            int widthPadding  = 10;
            int heightPadding = 10;

            int    textWidth  = 30;
            int    textHeight = 15;
            double textOffset = 1.5;

            int curInPtCnt  = 0;
            int curOutPtCnt = 0;

            UDNGroup group = new UDNGroup();

            group.Name = name;

            // find max input/output port size
            for (int i = 0; i < ports.Count; i++)
            {
                if (ports[i].Type == PortType.IN)
                {
                    InputCnt += 1;
                    if (InputMaxSize < ports[i].Name.Length)
                    {
                        InputMaxSize = ports[i].Name.Length;
                    }
                }
                else
                {
                    OutputCnt += 1;
                    if (OutputMaxSize < ports[i].Name.Length)
                    {
                        OutputMaxSize = ports[i].Name.Length;
                    }
                }
            }

            instanceWidth  = (InputMaxSize * offsetWidth) + (OutputMaxSize * offsetWidth) + widthPadding;
            instanceHeight = (InputCnt > OutputCnt ? InputCnt : OutputCnt) * offsetHeight + heightPadding;

            textWidth = instanceWidth;

            // Add Instance
            NRectangleShape node = new NRectangleShape(0, 0, (int)instanceWidth, (int)instanceHeight);

            node.Name = name;
            group.Shapes.AddChild(node);

            NTextShape nodeName = new NTextShape(name, 0, -15, textWidth, textHeight);

            nodeName.Style.TextStyle           = new NTextStyle();
            nodeName.Style.TextStyle.FontStyle = new NFontStyle(new Font("Arial", 9));
            group.Shapes.AddChild(nodeName);

            // Add Port

            for (int i = 0; i < ports.Count; i++)
            {
                NShape port = createPort(ports[i].Name, ports[i].Type);
                group.Shapes.AddChild(port);
                if (ports[i].Type == PortType.IN)
                {
                    curInPtCnt   += 1;
                    port.Location = new NPointF(-port.Bounds.Width / 2, (node.Bounds.Height / (InputCnt + 1)) * curInPtCnt);

                    NTextShape portName = new NTextShape(ports[i].Name,
                                                         port.Bounds.Width / 2, (node.Bounds.Height / (InputCnt + 1)) * curInPtCnt,
                                                         ports[i].Name.Length * 9, (int)(port.Bounds.Height * textOffset));
                    portName.Style.TextStyle           = new NTextStyle();
                    portName.Style.TextStyle.FontStyle = new NFontStyle(new Font("Arial", 9));
                    portName.Style.TextStyle.StringFormatStyle.HorzAlign = Nevron.HorzAlign.Left;
                    group.Shapes.AddChild(portName);
                }
                else
                {
                    curOutPtCnt  += 1;
                    port.Location = new NPointF((-port.Bounds.Width / 2) + node.Bounds.Width, (node.Bounds.Height / (OutputCnt + 1)) * curOutPtCnt);

                    NTextShape portName = new NTextShape(ports[i].Name,
                                                         node.Bounds.Width - (port.Bounds.Width / 2) - (ports[i].Name.Length * 9), (node.Bounds.Height / (OutputCnt + 1)) * curOutPtCnt,
                                                         ports[i].Name.Length * 9, (int)(port.Bounds.Height * textOffset));
                    portName.Style.TextStyle           = new NTextStyle();
                    portName.Style.TextStyle.FontStyle = new NFontStyle(new Font("Arial", 9));
                    portName.Style.TextStyle.StringFormatStyle.HorzAlign = Nevron.HorzAlign.Right;
                    group.Shapes.AddChild(portName);
                }



                port.CreateShapeElements(ShapeElementsMask.Ports);

                NDynamicPort portInner;
                if (ports[i].Type == PortType.IN)
                {
                    portInner      = new NDynamicPort(new NContentAlignment(-50, 0), DynamicPortGlueMode.GlueToContour);
                    portInner.Name = ports[i].Name;
                }
                else
                {
                    portInner      = new NDynamicPort(new NContentAlignment(50, 0), DynamicPortGlueMode.GlueToContour);
                    portInner.Name = ports[i].Name;
                }
                port.Ports.AddChild(portInner);
            }

            group.UpdateModelBounds();

            return(group);
        }