コード例 #1
0
        private void treeView2_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            TreeNode node = treeView2.SelectedNode;

            MessageBox.Show(string.Format("You selected: {0}", node.Text));

            UDNGroup instance = CreateInstance(node.Text, BaseModels[node.Text].Ports, "None");

            document.ActiveLayer.AddChild(instance);
            instanceList.Add(instance);

            setInstancesPos(instanceList, inPortList, outPortList);

            document.SizeToContent();
        }
コード例 #2
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);
        }
コード例 #3
0
        private void Update_instance(Module mod)
        {
            Module _module = (Module)mod.ShallowCopy();

            inPortList.Clear();
            outPortList.Clear();
            instanceList.Clear();
            objMDict.Clear();

            if (_module.Name != topModuleName)
            {
                _module.Name = string.Copy(ModulePool[_module.Type].Name);
            }

            // draw global port
            for (int i = 0; i < _module.Ports.Count; i++)
            {
                UDNGroup gPort = CreateGlobalPort(_module.Ports[i].Name, _module.Ports[i].Type);
                document.ActiveLayer.AddChild(gPort);
                if (_module.Ports[i].Type == PortType.IN)
                {
                    inPortList.Add(gPort);
                }
                else
                {
                    outPortList.Add(gPort);
                }
                objMDict[_module.Name, _module.Ports[i].Name] = gPort;
            }


            for (int i = 0; i < _module.Instances.Count; i++)
            {
                string   key      = _module.Instances[i].Name;
                UDNGroup instance = CreateInstance(key, ModulePool[_module.Instances[i].Type].Ports, _module.Instances[i].Id);
                document.ActiveLayer.AddChild(instance);
                instanceList.Add(instance);
                for (int j = 0; j < ModulePool[_module.Instances[i].Type].Ports.Count; j++)
                {
                    objMDict[key, ModulePool[_module.Instances[i].Type].Ports[j].Name] = instance;
                }
            }

            setInstancesPos(instanceList, inPortList, outPortList);


            NRoutableConnector routableConnector;

            for (int i = 0; i < _module.Instances.Count; i++)
            {
                for (int j = 0; j < _module.Instances[i].Couplings.Count; j++)
                {
                    routableConnector                   = new NRoutableConnector(RoutableConnectorType.DynamicHV, RerouteAutomatically.Always);
                    routableConnector.Name              = "name";
                    routableConnector.StyleSheetName    = NDR.NameConnectorsStyleSheet;
                    routableConnector.Style.StrokeStyle = new NStrokeStyle(1, Color.Blue);
                    document.ActiveLayer.AddChild(routableConnector);

                    var cou = _module.Instances[i].Couplings[j];

                    var sourIns = objMDict[cou.From, cou.FPort];
                    var destIns = objMDict[cou.To, cou.TPort];

                    routableConnector.StartPlug.Connect(((NShape)(sourIns.Shapes.GetChildByName(cou.FPort, 0))).Ports.GetChildByName(cou.FPort, 0) as NPort);
                    routableConnector.EndPlug.Connect(((NShape)(destIns.Shapes.GetChildByName(cou.TPort, 0))).Ports.GetChildByName(cou.TPort, 0) as NPort);
                    routableConnector.Reroute();
                }
            }


            document.SizeToContent();

            _module = null;
        }
コード例 #4
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);
        }
コード例 #5
0
        private void InitDocument()
        {
            // draw global port
            for (int i = 0; i < topModule.Ports.Count; i++)
            {
                UDNGroup gPort = CreateGlobalPort(topModule.Ports[i].Name, topModule.Ports[i].Type);
                document.ActiveLayer.AddChild(gPort);
                if (topModule.Ports[i].Type == PortType.IN)
                {
                    inPortList.Add(gPort);
                }
                else
                {
                    outPortList.Add(gPort);
                }
                objMDict[topModule.Name, topModule.Ports[i].Name] = gPort;
            }


            for (int i = 0; i < topModule.Instances.Count; i++)
            {
                string   key      = topModule.Instances[i].Name;
                UDNGroup instance = CreateInstance(key, ModulePool[topModule.Instances[i].Type].Ports, topModule.Instances[i].Id);
                document.ActiveLayer.AddChild(instance);
                instanceList.Add(instance);
                //objDict[key] = instance;
                for (int j = 0; j < ModulePool[topModule.Instances[i].Type].Ports.Count; j++)
                {
                    objMDict[key, ModulePool[topModule.Instances[i].Type].Ports[j].Name] = instance;
                }
            }

            setInstancesPos(instanceList, inPortList, outPortList);


            NRoutableConnector routableConnector;

            for (int i = 0; i < topModule.Instances.Count; i++)
            {
                for (int j = 0; j < topModule.Instances[i].Couplings.Count; j++)
                {
                    routableConnector = new NRoutableConnector(RoutableConnectorType.DynamicHV, RerouteAutomatically.Always);
                    routableConnector.StyleSheetName    = NDR.NameConnectorsStyleSheet;
                    routableConnector.Style.StrokeStyle = new NStrokeStyle(1, Color.Blue);
                    document.ActiveLayer.AddChild(routableConnector);

                    var cou = topModule.Instances[i].Couplings[j];

                    var sourIns = objMDict[cou.From, cou.FPort];
                    var destIns = objMDict[cou.To, cou.TPort];

                    routableConnector.StartPlug.Connect(((NShape)(sourIns.Shapes.GetChildByName(cou.FPort, 0))).Ports.GetChildByName(cou.FPort, 0) as NPort);
                    routableConnector.EndPlug.Connect(((NShape)(destIns.Shapes.GetChildByName(cou.TPort, 0))).Ports.GetChildByName(cou.TPort, 0) as NPort);
                    routableConnector.DoubleClick += new NodeViewEventHandler(routableConnector_DoubleClick);

                    routableConnector.Reroute();
                }
            }


            document.SizeToContent();
        }