Exemple #1
0
 private static World FLoad(string str)
 {
     string fName = Regex.Match(str, @"\(.*?\)").Value.Replace("(", "").Replace(")", "").Trim();
     var node = new Node(fName + ".binhl");
     var world = new World(node,fName);
     return world;
 }
Exemple #2
0
        private static void Main(string[] args)
        {
            string fileName = args.Length < 1 ? "test" : args[0];

            var node = new Node(fileName + ".binhl");
            string genScript = "";
            genScript += "// $Id$\r\n";

            genScript += "importPackage(Packages.java.io);\r\n";
            genScript += "importPackage(Packages.java.awt);\r\n";
            genScript += "importPackage(Packages.com.sk89q.worldedit);\r\n";
            genScript += "importPackage(Packages.com.sk89q.worldedit.blocks);\r\n";
            genScript += "var origin = player.getBlockOn();\r\n";
            genScript += "var sess = context.remember();\r\n";

            int tempFunctionNum = 0;
            int stringNums = 0;

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendFormat("function v{0} (){{\r\n", tempFunctionNum);
            for (int x = 0; x < node.SizeX; x++)
            {
                for (int y = 0; y < node.SizeY; y++)
                {
                    int iy = node.SizeY - y -1;
                    for (int z = 0; z < node.SizeZ; z++)
                    {
                        if (node.DataMatrix[x, y, z] == "0") continue;
                        stringBuilder.Append(GetCoordSring(x, iy, z));
                        stringBuilder.Append(GetBlockStr(node.DataMatrix[x, y, z]));
                        stringNums++;
                        if (stringNums <= 200) continue;
                        stringBuilder.Append("};\r\n");
                        stringBuilder.AppendFormat("v{0}();\r\n", tempFunctionNum);
                        tempFunctionNum++;
                        Console.Write(tempFunctionNum);
                        stringBuilder.AppendFormat("function v{0} (){{\r\n", tempFunctionNum);
                        stringNums = 0;
                    }
                }
            }

            stringBuilder.Append("};\r\n");
            stringBuilder.AppendFormat("v{0}();\r\n", tempFunctionNum);

            genScript += stringBuilder.ToString();

            File.WriteAllText(fileName + ".js", genScript);
        }
Exemple #3
0
 public void PlaceAnotherNode(Node node, int xCoord, int yCoord, int zCoord)
 {
     for (int x = 0; x < node.SizeX; x++)
     {
         for (int y = 0; y < node.SizeY; y++)
         {
             for (int z = 0; z < node.SizeZ; z++)
             {
                 DataMatrix[xCoord + x, yCoord + y, zCoord + z] = node.DataMatrix[x, y, z];
             }
         }
     }
 }
Exemple #4
0
        static void Main(string[] args)
        {
            string fileName = args.Length < 1 ? "tm" : args[0];

            string ostr = "";
            string[] instr = System.IO.File.ReadAllLines(fileName+".edf");
            int ldes = 0;//library DESIGN
            while (!instr[ldes].Contains("library DESIGN"))
            {
                ldes++;
            }
            int portstart = ldes;
            while (!instr[portstart].Contains("(port "))
            {
                portstart++;
            }
            int portend = portstart;
            while (!instr[portend].Contains("(contents"))
            {
                if (instr[portend].Contains("(port "))
                {
                    string parseStr = instr[portend].Replace(")", " ").Replace("(", " ").Replace("  ", " ").Replace("  ", " ").Replace("  ", " ").Replace("  ", " ");
                    string[] mstr = parseStr.Split(' ');
                    if (mstr[2] == "rename")
                    {
                        if (mstr[6] == "INPUT")
                        {
                            ostr += "NODE:INPort:" + mstr[3] + "\n";
                            Mainportlist.Add(mstr[3]);
                            MainportlistT.Add("I");
                        }
                        if (mstr[6] == "OUTPUT")
                        {
                            ostr += "NODE:OUTPort:" + mstr[3] + "\n";
                            Mainportlist.Add(mstr[3]);
                            MainportlistT.Add("O");
                        }
                    }
                    else
                    {
                        if (mstr[4] == "INPUT")
                        {
                            ostr += "NODE:INPort:" + mstr[2] + "\n";
                            Mainportlist.Add(mstr[2]);
                            MainportlistT.Add("I");
                        }
                        if (mstr[4] == "OUTPUT")
                        {
                            ostr += "NODE:OUTPort:" + mstr[2] + "\n";
                            Mainportlist.Add(mstr[2]);
                            MainportlistT.Add("O");
                        }
                    }
                }
                portend++;
            }
            while (!instr[portend].Contains("(design "))
            {
                if (instr[portend].Contains("instance "))
                {
                    string parseStr = instr[portend].Replace(")", " ").Replace("(", " ").Replace("  ", " ").Replace("  ", " ").Replace("  ", " ").Replace("  ", " ");
                    string[] mstr = parseStr.Split(' ');
                    ostr += "NODE:" + mstr[6] + ":" + mstr[2] + "\n";
                    var node = new Node(mstr[6] + ".binhl");
                    foreach (InPort port in node.InPorts)
                    {
                        Mainportlist.Add(mstr[2] + "-" +port.Name);
                        MainportlistT.Add("I");
                    }
                    foreach (OutPort port in node.OutPorts)
                    {
                        Mainportlist.Add(mstr[2] + "-" + port.Name);
                        MainportlistT.Add("O");
                    }
                }
                if (instr[portend].Contains("(net "))
                {
                    string parseStr = instr[portend].Replace(")", " ").Replace("(", " ").Replace("  ", " ").Replace("  ", " ").Replace("  ", " ").Replace("  ", " ");
                    string[] mstr = parseStr.Split(' ');
                    var portlist = new List<string>();
                    var portlistT = new List<string>();
                    for (int i = 0; i < mstr.Length; i++)
                    {
                        if (mstr[i] == "portRef")
                        {
                            if (mstr[i + 2] == "instanceRef")
                            {
                                portlist.Add(mstr[i + 3] + "-" + mstr[i + 1]);
                                portlistT.Add(FindPortType(mstr[i + 3] + "-" + mstr[i + 1]));
                            }
                            else
                            {
                                if (FindPortType(mstr[i + 1]) == "I")
                                {
                                    portlistT.Add("O");
                                    portlist.Add(mstr[i + 1] + "-O0");
                                }
                                else
                                {
                                    portlistT.Add("I");
                                    portlist.Add(mstr[i + 1] + "-I0");
                                }
                            }
                        }
                    }
                    if (portlist.Count == 2)
                    {
                        if (portlistT[0] == "O")
                        {
                            ostr += "WIRE:" + portlist[0] + ":" + portlist[1] + "\n";
                        }
                        else
                        {
                            ostr += "WIRE:" + portlist[1] + ":" + portlist[0] + "\n";
                        }
                    }
                    if (portlist.Count == 3)
                    {
                        ostr += "NODE:dup2:" + mstr[2] + "\n";
                        int op = 0;
                        for (int j = 0; j < portlist.Count; j++)
                        {
                            if (portlistT[j] == "O")
                            {
                                ostr += "WIRE:" + portlist[j] + ":" + mstr[2] + "-I0" + "\n";
                            }
                            else
                            {
                                ostr += "WIRE:" + mstr[2] + "-O" + op + ":" + portlist[j] + "\n";
                                op++;
                            }
                        }
                    }
                }
                portend++;
            }

            System.IO.File.WriteAllText(fileName+".MNET", ostr);
            //for (int i = 0; i < instr.Length; i++)
            //{

            //}
        }
Exemple #5
0
        public World(Node node, string fileName)
        {
            debug = false;
            worldName = fileName;
            _objectMatrix = new WorldObject[node.SizeX, node.SizeY, node.SizeZ];
            WorldSizeX = node.SizeX;
            WorldSizeY = node.SizeY;
            WorldSizeZ = node.SizeZ;
            for (int x = 0; x < node.SizeX; x++)
            {
                for (int y = 0; y < node.SizeY; y++)
                {
                    for (int z = 0; z < node.SizeZ; z++)
                    {
                        switch (node.DataMatrix[x, WorldSizeY - y - 1, z])
                        {
                            case "k":
                                _objectMatrix[x, y, z] = new Cloth(x, y, z, this);
                                break;
                            case "W":
                                _objectMatrix[x, y, z] = new Cloth(x, y, z, this);
                                break;
                            case "w":
                                _objectMatrix[x, y, z] = new Cloth(x, y, z, this);
                                break;
                            case "S":
                                _objectMatrix[x, y, z] = new Cloth(x, y, z, this);
                                break;
                            case "0":
                                _objectMatrix[x, y, z] = new Air(x, y, z, this);
                                break;
                            case "#":
                                _objectMatrix[x, y, z] = new RedstoneWire(x, y, z, this);
                                break;
                            case "^":
                                _objectMatrix[x, y, z] = new RedstoneRepiter(x, y, z, Direction.Forward, 1, this);
                                break;
                            case "<":
                                _objectMatrix[x, y, z] = new RedstoneRepiter(x, y, z, Direction.Right, 1, this);
                                break;
                            case ">":
                                _objectMatrix[x, y, z] = new RedstoneRepiter(x, y, z, Direction.Left, 1, this);
                                break;
                            case "v":
                                _objectMatrix[x, y, z] = new RedstoneRepiter(x, y, z, Direction.Backword, 1, this);
                                break;
                            case "=":
                                _objectMatrix[x, y, z] = new RedstoneRepiter(x, y, z, Direction.Forward, 2, this);
                                break;
                            case "_":
                                _objectMatrix[x, y, z] = new RedstoneTorch(x, y, z, Direction.Backword, this);
                                break;
                            case "-":
                                _objectMatrix[x, y, z] = new RedstoneTorch(x, y, z, Direction.Forward, this);
                                break;
                            case "*":
                                _objectMatrix[x, y, z] = new RedstoneTorch(x, y, z, Direction.Down, this);
                                break;
                        }
                    }
                }
            }

            //Загрузка портов
            inPorts = new List<IoPort>();
            outPorts = new List<IoPort>();

            foreach (InPort port in node.InPorts)
            {
                int x = port.PosX;
                int y = WorldSizeY - port.PosY - 1;
                int z = 0;
                for (int j = 0; j < WorldSizeZ; j++)
                {
                    if (_objectMatrix[x, y, j].GetType() == typeof (Cloth))
                    {
                        z = j+1;
                    }
                }
                var p = new IoPort {X = x, Y = y, Z = z, Name = port.Name, Value = false};
                inPorts.Add(p);
                _objectMatrix[x, y, z] = new RedstoneWire(x, y, z, this);
                ((RedstoneWire) _objectMatrix[x, y, z]).Blocked = true;
                //((WorldObjects.RedstoneWire)ObjectMatrix[x, y, z]).RedValue = 15;
                //((WorldObjects.RedstoneWire)ObjectMatrix[x, y, z]).IsActivated = true;
            }

            foreach (OutPort port in node.OutPorts)
            {
                int x = port.PosX;
                int y = WorldSizeY - port.PosY - 1;
                int z = 0;
                for (int j = 0; j < WorldSizeZ; j++)
                {
                    if (_objectMatrix[x, y, j].GetType() == typeof (Cloth))
                    {
                        z = j+1;
                    }
                }
                var p = new IoPort {X = x, Y = y, Z = z, Name = port.Name, Value = false};
                outPorts.Add(p);
                _objectMatrix[x, y, z] = new RedstoneWire(x, y, z, this);
            }

            R = new Render(this);
        }
Exemple #6
0
        static void Main(string[] args)
        {
            if (args.Contains("-OFast"))
            {
                Step = 10;
            }
            if (args.Contains("-OMax"))
            {
                Step = 1;
            }
            if (args.Contains("-debug"))
            {
                DrawAstar = true;
            }
            //string file = "test_D_O";
            string file = "test_D_O";
            //string file = "lut_00BB_D_O";
            //string file = "lut_00AB_D_O";

            if (args.Length > 0)
            {
                file = args[0];
            }

            var mainNetwork = new Mnet();
            mainNetwork.ReadMnetFile(file + @".MNET");

            //Удаление GNDS

            var gnds = mainNetwork.nodes.Where(t => t.NodeType == "GND" && !mainNetwork.wires.Any(t2=>t2.SrcName == t.NodeName)).ToList();
            foreach (var node in gnds)
            {
                var wires = mainNetwork.wires.Where(t => t.SrcName == node.NodeName).ToList();
                foreach (var wire in wires) mainNetwork.wires.Remove(wire);
                mainNetwork.nodes.Remove(node);
            }

            mainNetwork.wireGroups = new List<WireGroup>();

            //Перевести соеденения DUP в группы
            Console.WriteLine("Конвертирование DUP");
            var dupList = mainNetwork.nodes.Where(t => t.NodeType.Contains("DUP")).ToList();

            //Обьеденение DUP
            List<Node> list = dupList;
            var dupdupWires = mainNetwork.wires.Where(t => list.FirstOrDefault(a => a.NodeName == t.SrcName) != null &&
                                                           list.FirstOrDefault(a => a.NodeName == t.DistName) != null);
            while (dupdupWires.Any())

            {
                var wire = dupdupWires.First();
                var firstDup = dupList.First(a => a.NodeName == wire.SrcName);
                var secondDup = dupList.First(a => a.NodeName == wire.DistName);
                var fromSecondWires = mainNetwork.wires.Where(t => t.SrcName == secondDup.NodeName).ToList();
                foreach (var w in fromSecondWires)
                {
                    w.SrcName = firstDup.NodeName;
                }
                mainNetwork.wires.Remove(wire);
                mainNetwork.nodes.Remove(secondDup);
            }
            var orList = mainNetwork.nodes.Where(t => t.NodeType.Contains("OR")).ToList();
            dupList = mainNetwork.nodes.Where(t => t.NodeType.Contains("DUP")).ToList();

            //Обьеденение OR
            var opt = true;
            while (opt)
            {
                opt = false;
                var OrToOrWires = new List<Wire>();
                foreach (var node in orList)
                {
                    foreach (var node2 in orList)
                    {
                        OrToOrWires.AddRange(mainNetwork.wires.Where(t => t.SrcName == node.NodeName && node2.NodeName == t.DistName));
                    }
                }
                if (OrToOrWires.Count > 0)
                {
                    opt = true;
                    foreach (var wire in OrToOrWires)
                    {
                        var fromor = mainNetwork.nodes.First(t => t.NodeName == wire.SrcName);
                        var toor = mainNetwork.nodes.First(t => t.NodeName == wire.DistName);
                        var wires = new List<Wire>();
                        wires.AddRange(mainNetwork.wires.Where(t => t.DistName == fromor.NodeName));
                        wires.AddRange(mainNetwork.wires.Where(t => t.DistName == toor.NodeName));
                        wires.Remove(wire);
                        foreach (var w in wires)
                        {
                            w.DistName = wire.DistName;
                        }
                        mainNetwork.wires.Remove(wire);
                        mainNetwork.nodes.Remove(fromor);
                    }

                }
                else
                {

                }
            }
            //Создание Dummy обьектов
            //Поиск соеденений подходящих под DUMMY
            var dupToOrWires = new List<Wire>();
            foreach (var node in dupList)
            {
                foreach (var node2 in orList)
                {
                    dupToOrWires.AddRange(mainNetwork.wires.Where(t => t.SrcName == node.NodeName && node2.NodeName == t.DistName));
                }
            }
            //Поиск обратных связей
            foreach (var node in orList)
            {
                foreach (var node2 in dupList)
                {
                    dupToOrWires.AddRange(mainNetwork.wires.Where(t => t.SrcName == node.NodeName && node2.NodeName == t.DistName));
                }
            }

            //Создание DUMMY
            int dummynum = 0;
            foreach (var wire in dupToOrWires)
            {
                mainNetwork.nodes.Add(new Node { NodeName = "DUMMY_" + dummynum, NodeType = "DUMMY" });
                var newWire = new Wire { SrcName = "DUMMY_" + dummynum, SrcPort = "O0", DistName = wire.DistName, DistPort = wire.DistPort };
                wire.DistName = "DUMMY_" + dummynum;
                wire.DistPort = "I0";
                mainNetwork.wires.Add(newWire);
                dummynum++;
            }

            //Преобразование DUP В wireGroup
            dupList = mainNetwork.nodes.Where(t => t.NodeType.Contains("DUP")).ToList();

            var delinwirelist = new List<Wire>();
            var deloutwirelist = new List<Wire>();
            foreach (Node node in dupList)
            {
                string targetNodeName = node.NodeName;
                var inWires = mainNetwork.wires.Where(t => t.DistName == targetNodeName).ToList();
                var outWires = mainNetwork.wires.Where(t => t.SrcName == targetNodeName).ToList();
                foreach (var t in outWires)
                {
                    t.SrcName = inWires.First().SrcName;
                    t.SrcPort = inWires.First().SrcPort;
                }
                mainNetwork.wireGroups.Add(new WireGroup { GroupName = node.NodeName, WList = outWires,groupType = "DUP" });
                delinwirelist.AddRange(inWires);
                deloutwirelist.AddRange(outWires);
            }

            //Преобразование OR в WireGroup
            orList = mainNetwork.nodes.Where(t => t.NodeType.Contains("OR")).ToList();

            foreach (Node node in orList)
            {
                string targetNodeName = node.NodeName;
                var inWires = mainNetwork.wires.Where(t => t.DistName == targetNodeName).ToList();
                var outWires = mainNetwork.wires.Where(t => t.SrcName == targetNodeName).ToList();
                foreach (var t in inWires)
                {
                    t.DistName = outWires.First().DistName;
                    t.DistPort = outWires.First().DistPort;
                }
                mainNetwork.wireGroups.Add(new WireGroup { GroupName = node.NodeName, WList = inWires,groupType = "OR" });
                delinwirelist.AddRange(outWires);
                deloutwirelist.AddRange(inWires);
            }

            //Удаление соеденений

            foreach (var t in delinwirelist) mainNetwork.wires.Remove(t);
            foreach (var t in dupList) mainNetwork.nodes.Remove(t);
            foreach (var t in orList) mainNetwork.nodes.Remove(t);

            //loadnodes
            Console.WriteLine("Загрузка темплейтов");
            var mcNodes = new RouteUtils.Node[mainNetwork.nodes.Count];
            for (int i = 0; i < mainNetwork.nodes.Count; i++)
            {
                mcNodes[i] = new RouteUtils.Node(mainNetwork.nodes[i].NodeType + ".binhl")
                {
                    NodeName = mainNetwork.nodes[i].NodeName
                };
                mainNetwork.nodes[i].McNode = mcNodes[i];
            }
            Console.WriteLine("OK");
            //Place nodes
            int placeLayer;
            int baseSize;

            PlaceOptimal(mainNetwork, mcNodes, out placeLayer, out baseSize);

            //Удаление оставшихся соеденений
            foreach (var t in deloutwirelist) mainNetwork.wires.Remove(t);

            Console.WriteLine("Размещение ОК");

            var cpoints = new List<Cpoint>();

            //CreateCpointList

            for (int i = 0; i < mainNetwork.nodes.Count; i++)
            {
                cpoints.AddRange(mcNodes[i].InPorts.Select(t => new Cpoint
                {
                    BaseX = t.PosX + mainNetwork.nodes[i].X,
                    BaseY = t.PosY + mainNetwork.nodes[i].Y,
                    PointName = mainNetwork.nodes[i].NodeName + "-" + t.Name,
                    Indat = true
                }));

                cpoints.AddRange(mcNodes[i].OutPorts.Select(t => new Cpoint
                {
                    BaseX = t.PosX + mainNetwork.nodes[i].X,
                    BaseY = t.PosY + mainNetwork.nodes[i].Y,
                    PointName = mainNetwork.nodes[i].NodeName + "-" + t.Name,
                    Indat = false
                }));
            }

            SortWire(cpoints, mainNetwork, baseSize);

            var mcWires = new RouteUtils.Wire[mainNetwork.wires.Count];
            //Draw wires in layer
            int totalLayers = 0;
            for (int j = 0; j < 24; j++)
            {
                int currentWireLayer = j * 2 + 1;
                if (j > 4) currentWireLayer += 5;
                if (j > 9) currentWireLayer += 5;
                if (j > 14) currentWireLayer += 5;

                int currentRealLayer = placeLayer - 1 - j * 2;

                if (j > 4) currentRealLayer -= 2;
                if (j > 9) currentRealLayer -= 2;
                if (j > 14) currentRealLayer -= 2;

                int wireNum = 0;

                var wireMask = new char[baseSize, baseSize];

                //Разводка групп
                bool  canplace = true;
                while (canplace)
                {
                    //Разводка Группы

                    //Поиск лучшей группы для разводки
                    foreach (WireGroup group in mainNetwork.wireGroups)
                    {
                        if (!group.Placed)
                        {
                            group.weight = 0;
                            group.CanPlace = true;
                            foreach (Wire wire in group.WList)
                            {
                                //Поиск точек входа выхода
                                Cpoint startPoint = FindCpoint(wire.SrcName + "-" + wire.SrcPort, cpoints);
                                Cpoint endPoint = FindCpoint(wire.DistName + "-" + wire.DistPort, cpoints);

                                //Маскировка неиспользуемых точек;
                                foreach (Cpoint cpoint in cpoints)
                                {
                                    if (cpoint.UsedLayer == 0)
                                        DrawAtMask(wireMask, cpoint.BaseX, cpoint.BaseY + currentWireLayer, 1, 2);
                                }
                                //Отмена маскировки на конечных точках соеденения

                                startPoint.BaseY += currentWireLayer;
                                endPoint.BaseY += currentWireLayer;

                                UnmaskCpoint(wireMask, startPoint);
                                UnmaskCpoint(wireMask, endPoint);
                                var aStarTable = CalcAstar(baseSize, wireMask, startPoint, endPoint);

                                //CalcAstar

                                startPoint.BaseY -= currentWireLayer;
                                endPoint.BaseY -= currentWireLayer;
                                int weight = aStarTable[endPoint.BaseX, endPoint.BaseY + currentWireLayer];
                                if (weight == 0) group.CanPlace = false;
                                group.weight += weight;
                                wire.len = weight;
                                if (DrawAstar) RenderATable(wire + ".png", aStarTable, baseSize, startPoint, endPoint);

                            }
                        }
                    }

                    var bestGroup = mainNetwork.wireGroups.Where(q => q.CanPlace && !q.Placed).OrderBy(t => t.weight).FirstOrDefault();

                    //Разводка

                    if (bestGroup != null)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("Разводка группы {0} из {1} соеденений", bestGroup.GroupName,bestGroup.WList.Count);
                        Console.ForegroundColor = ConsoleColor.White;
                        bestGroup.Placed = true;
                        bestGroup.WList = bestGroup.WList.OrderBy(t => t.len).ToList();
                        bestGroup.WList.Reverse();
                        foreach (Wire wire in bestGroup.WList)
                        {
                            Cpoint startPoint = FindCpoint(wire.SrcName + "-" + wire.SrcPort, cpoints);
                            Cpoint endPoint = FindCpoint(wire.DistName + "-" + wire.DistPort, cpoints);

                            if (bestGroup.groupType == "OR")
                            {
                                endPoint = FindCpoint(wire.SrcName + "-" + wire.SrcPort, cpoints);
                                startPoint = FindCpoint(wire.DistName + "-" + wire.DistPort, cpoints);
                            }

                            //Маскировка неиспользуемых точек;
                            foreach (Cpoint cpoint in cpoints)
                            {
                                if (cpoint.UsedLayer == 0)
                                    DrawAtMask(wireMask, cpoint.BaseX, cpoint.BaseY + currentWireLayer, 1, 2);
                            }
                            //Отмена маскировки на конечных точках соеденения

                            startPoint.BaseY += currentWireLayer;
                            endPoint.BaseY += currentWireLayer;

                            UnmaskCpoint(wireMask, startPoint);
                            UnmaskCpoint(wireMask, endPoint);

                            var aStarTable = CalcAstar(baseSize, wireMask, startPoint, endPoint);
                            MultiWareAstarUpdate(aStarTable, bestGroup);

                            List<int> wpx;
                            List<int> wpy;

                            bool placed = TryPlaceWire(startPoint, endPoint, aStarTable, out wpx, out wpy);
                            if (placed)
                            {
                                //WireRemask
                                wire.WirePoints = new List<WirePoint>();
                                for (int i = 0; i < wpx.Count; i++)
                                {
                                    wire.WirePoints.Add(new WirePoint { x = wpx[i], y = wpy[i], z = currentRealLayer });
                                }
                                wire.WirePoints.Reverse();

                                startPoint.UsedLayer = currentWireLayer;
                                endPoint.UsedLayer = currentWireLayer;
                                wire.Placed = true;
                            }

                            //startPoint.BaseY -= 1;
                            //endPoint.BaseY -= 1;
                            startPoint.BaseY -= currentWireLayer;
                            endPoint.BaseY -= currentWireLayer;
                            wireNum++;
                            //RenderATable(wire + ".png", aStarTable, baseSize, startPoint, endPoint);
                        }

                        foreach (Wire wire in bestGroup.WList)
                        {
                            foreach (var point in wire.WirePoints)
                            {
                                DrawAtMask(wireMask, point.x, point.y, 1, 1);
                            }
                            if (bestGroup.groupType == "OR")
                            {
                                wire.WirePoints.Reverse();
                            }
                        }
                    }
                    else
                    {
                        canplace = false;
                    }
                }

                //Разводка Соеденений

                for (int i = 0; i < mainNetwork.wires.Count; i++)
                {
                    int mink = 999999;
                    int bestN = 0;

                    for (int k = 0; k < mainNetwork.wires.Count; k++)
                    {
                        if (!mainNetwork.wires[k].Placed)
                        {
                            int bw = FindBestWireToRoute(mainNetwork, baseSize, cpoints, currentWireLayer, currentRealLayer, k, mcWires, wireMask);
                            if (mink > bw && bw != 0)
                            {
                                mink = bw;
                                bestN = k;
                            }
                        }
                    }
                    if (!mainNetwork.wires[bestN].Placed)
                    {
                        List<int> wpx;
                        List<int> wpy;
                        PlaceWire(mainNetwork, baseSize, cpoints, currentWireLayer, currentRealLayer, bestN, mcWires, wireMask, out wpx, out wpy);
                        if (mainNetwork.wires[bestN].Placed)
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            wireNum++;
                            Console.WriteLine(mainNetwork.wires[bestN].ToString());
                        }
                        else
                        {
                            i = mainNetwork.wires.Count;
                            Console.ForegroundColor = ConsoleColor.White;
                        }

                    }
                    else
                    {
                        i = mainNetwork.wires.Count;
                    }
                }
                Console.WriteLine("Разведено в текущем слое:" + wireNum);
                if (wireNum > 0)
                {
                    totalLayers++;
                }
                else
                {
                    break;
                }
            }
            Console.WriteLine("Всего Слоев:" + totalLayers);

            var outNode = new RouteUtils.Node("OUT", baseSize, baseSize, placeLayer + 10);

            //OutNode.PlaceAnotherNode(new RouteUtils.Node("DUP23.binhl"), 0, 0, 0);
            for (int i = 0; i < mainNetwork.nodes.Count; i++)
            {
                outNode.PlaceAnotherNode(mcNodes[i], mainNetwork.nodes[i].X, mainNetwork.nodes[i].Y, mainNetwork.nodes[i].Z);

            }
            //LongCpoint

            foreach (Cpoint cpoint in cpoints)
            {
                if (cpoint.UsedLayer >= 10)
                {
                    cpoint.UsedLayer -= 4;
                    outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 12, placeLayer - 11] = "W";
                    if (cpoint.Indat)
                        outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 12, placeLayer - 10] = "^";
                    else
                        outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 12, placeLayer - 10] = "v";

                    outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 13, placeLayer - 11] = "W";
                    outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 13, placeLayer - 10] = "#";
                    outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 14, placeLayer - 11] = "W";
                    outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 14, placeLayer - 10] = "#";
                }

                if (cpoint.UsedLayer >= 22)
                {
                    cpoint.UsedLayer -= 3;
                    outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 27, placeLayer - 23] = "W";
                    if (cpoint.Indat)
                        outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 27, placeLayer - 22] = "^";
                    else
                        outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 27, placeLayer - 22] = "v";

                    outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 28, placeLayer - 23] = "W";
                    outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 28, placeLayer - 22] = "#";
                    outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 29, placeLayer - 23] = "W";
                    outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 29, placeLayer - 22] = "#";
                }

                if (cpoint.UsedLayer >= 34)
                {
                    cpoint.UsedLayer -= 3;
                    outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 42, placeLayer - 35] = "W";
                    if (cpoint.Indat)
                        outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 42, placeLayer - 34] = "^";
                    else
                        outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 42, placeLayer - 34] = "v";

                    outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 43, placeLayer - 35] = "W";
                    outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 43, placeLayer - 34] = "#";
                    outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 44, placeLayer - 35] = "W";
                    outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + 44, placeLayer - 34] = "#";
                }

                for (int j = 0; j < cpoint.UsedLayer; j++)
                {
                    if (j <= 10)
                    {
                        outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + j + 1, placeLayer - j - 1] = "w";
                        outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + j + 1, placeLayer - j - 0] = "#";
                    }
                    if (j > 10 && j <= 22)
                    {
                        outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + j + 4, placeLayer - j - 1] = "w";
                        outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + j + 4, placeLayer - j - 0] = "#";
                    }
                    if (j > 22 && j <= 34)
                    {
                        outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + j + 7, placeLayer - j - 1] = "w";
                        outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + j + 7, placeLayer - j - 0] = "#";
                    }

                    if (j > 34)
                    {
                        outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + j + 10, placeLayer - j - 1] = "w";
                        outNode.DataMatrix[cpoint.BaseX, cpoint.BaseY + j + 10, placeLayer - j - 0] = "#";
                    }
                }
            }
            //PlaceReapiters
            for (int i = 0; i < mainNetwork.wires.Count; i++)
            {
                mcWires[i].PlaceRepeaters();
            }

            //Установка репитеров для групп
            foreach (var group in mainNetwork.wireGroups)
            {
                group.PlaceRepitors();
            }
            //Установка групп соеденений

            //SyncWires
            var wiresToSync = new List<RouteUtils.Wire>();
            for (int i = 0; i < mainNetwork.wires.Count; i++)
            {
                if (mainNetwork.wires[i].DistPort == "clk")
                {
                    wiresToSync.Add(mcWires[i]);
                }
            }
            int syncLen = wiresToSync.Select(t => t.CalcRepCount()).Concat(new[] {0}).Max();

            foreach (RouteUtils.Wire wire in wiresToSync)
            {
                wire.RepCompincate(syncLen - wire.CalcRepCount());
                wire.Synced = true;
            }

            foreach (var group in mainNetwork.wireGroups)
            {
                foreach (var wire in group.WList)
                {
                    foreach (var point in wire.WirePoints)
                    {
                        outNode.DataMatrix[point.x, point.y, point.z] = "S";
                        if (wire.repError)
                            outNode.DataMatrix[point.x, point.y, point.z] = "W";

                        outNode.DataMatrix[point.x, point.y, point.z + 1] = "#";
                        if (point.Repiter)
                            outNode.DataMatrix[point.x, point.y, point.z + 1] = point.RepVapl;
                    }
                }
            }
            //отрисовка ошибочного соеденения
            foreach (var group in mainNetwork.wireGroups)
            {
                foreach (var wire in group.WList)
                {
                    if (wire.repError)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(wire);
                        Console.ForegroundColor = ConsoleColor.White;
                        foreach (var point in wire.WirePoints)
                        {
                            outNode.DataMatrix[point.x, point.y, point.z] = "S";
                            if (wire.repError)
                                outNode.DataMatrix[point.x, point.y, point.z] = "W";

                            outNode.DataMatrix[point.x, point.y, point.z + 1] = "#";
                            if (point.Repiter)
                                outNode.DataMatrix[point.x, point.y, point.z + 1] = point.RepVapl;
                        }
                    }
                }
            }

            //PlaceWires
            for (int i = 0; i < mainNetwork.wires.Count; i++)
            {
                if (mainNetwork.wires[i].Placed)
                {
                    for (int j = 0; j < mcWires[i].WirePointX.Length; j++)
                    {
                        if (mcWires[i].Synced)
                        {
                            outNode.DataMatrix[mcWires[i].WirePointX[j], mcWires[i].WirePointY[j], mcWires[i].WirePointZ[j]] = "S";
                        }
                        else
                        {
                            outNode.DataMatrix[mcWires[i].WirePointX[j], mcWires[i].WirePointY[j], mcWires[i].WirePointZ[j]] = "w";
                        }
                        if (mcWires[i].Rep[j])
                        {
                            outNode.DataMatrix[mcWires[i].WirePointX[j], mcWires[i].WirePointY[j], mcWires[i].WirePointZ[j] + 1] = mcWires[i].RepNp[j];
                        }
                        else
                        {
                            outNode.DataMatrix[mcWires[i].WirePointX[j], mcWires[i].WirePointY[j], mcWires[i].WirePointZ[j] + 1] = "#";
                        }
                    }
                }
            }

            //Обрезка
            Console.WriteLine("Обрезка рабочей Облости");
            var outNodeO = CutOutputNode(placeLayer, baseSize, outNode);
            //Маркировка портов ввода вывода
            outNodeO.InPorts = mainNetwork.nodes.Where(t => t.NodeType == "INPort").Select(t => new InPort(t.NodeName, t.X + 1, t.Y)).ToArray();
            outNodeO.OutPorts = mainNetwork.nodes.Where(t => t.NodeType == "OUTPort").Select(t => new OutPort(t.NodeName, t.X + 1, t.Y)).ToArray();

            Console.WriteLine("Экспорт");
            outNodeO.Export(file + ".binhl");
        }
Exemple #7
0
        private static RouteUtils.Node CutOutputNode(int PlaceLayer, int BaseSize, RouteUtils.Node OutNode)
        {
            //find xs
            int xs = 0;
            int ys = 0;
            int zs = 0;
            for (int i = 1; i < BaseSize; i++)
            {
                int pn = 0;
                for (int y = 0; y < BaseSize; y++)
                {
                    for (int z = 0; z < (PlaceLayer + 10); z++)
                    {
                        if (OutNode.DataMatrix[i, y, z] != "0")
                        {
                            pn++;
                        }
                    }
                }
                if (pn != 0)
                {
                    xs = i - 1;
                    break;
                }
            }

            for (int i = 1; i < BaseSize; i++)
            {
                int pn = 0;
                for (int x = 0; x < BaseSize; x++)
                {
                    for (int z = 0; z < (PlaceLayer + 10); z++)
                    {
                        if (OutNode.DataMatrix[x, i, z] != "0")
                        {
                            pn++;
                        }
                    }
                }
                if (pn != 0)
                {
                    ys = i - 1;
                    break;
                }
            }

            for (int i = 1; i < (PlaceLayer + 10); i++)
            {
                int pn = 0;
                for (int x = 0; x < BaseSize; x++)
                {
                    for (int y = 0; y < BaseSize; y++)
                    {
                        if (OutNode.DataMatrix[x, y, i] != "0")
                        {
                            pn++;
                        }
                    }
                }
                if (pn != 0)
                {
                    zs = i - 1;
                    break;
                }
            }

            int xe = 0;
            int ye = 0;
            int ze = 0;
            for (int i = 1; i < BaseSize; i++)
            {
                int qi = BaseSize - 1 - i;
                int pn = 0;
                for (int y = 0; y < BaseSize; y++)
                {
                    for (int z = 0; z < (PlaceLayer + 10); z++)
                    {
                        if (OutNode.DataMatrix[qi, y, z] != "0")
                        {
                            pn++;
                        }
                    }
                }
                if (pn != 0)
                {
                    xe = qi + 2;
                    break;
                }
            }

            for (int i = 1; i < BaseSize; i++)
            {
                int qi = BaseSize - 1 - i;
                int pn = 0;
                for (int x = 0; x < BaseSize; x++)
                {
                    for (int z = 0; z < (PlaceLayer + 10); z++)
                    {
                        if (OutNode.DataMatrix[x, qi, z] != "0")
                        {
                            pn++;
                        }
                    }
                }
                if (pn != 0)
                {
                    ye = qi + 2;
                    break;
                }
            }

            for (int i = 1; i < (PlaceLayer + 10); i++)
            {
                int qi = (PlaceLayer + 10) - 1 - i;

                int pn = 0;
                for (int x = 0; x < BaseSize; x++)
                {
                    for (int y = 0; y < BaseSize; y++)
                    {
                        if (OutNode.DataMatrix[x, y, qi] != "0")
                        {
                            pn++;
                        }
                    }
                }
                if (pn != 0)
                {
                    ze = qi + 2;
                    break;
                }
            }

            RouteUtils.Node OutNodeO = new RouteUtils.Node("OUT", xe - xs, ye - ys, ze - zs);

            for (int x = xs; x < xe; x++)
            {
                for (int y = ys; y < ye; y++)
                {
                    for (int z = zs; z < ze; z++)
                    {
                        OutNodeO.DataMatrix[x - xs, y - ys, z - zs] = OutNode.DataMatrix[x, y, z];
                    }
                }
            }

            return OutNodeO;
        }
Exemple #8
0
        private static void Main(string[] args)
        {
            string FileName = "";
            if (args.Length < 1)
            {
                FileName = "tm";
            }
            else
            {
                FileName = args[0];
            }

            int placewidch = 2;
            //ReadNet
            string[] InFileStr = File.ReadAllLines(FileName + ".MNET");
            _nlist = new List<Node>();
            _wlist = new List<Wire>();
            _uname = new List<string>();

            for (int i = 0; i < InFileStr.Length; i++)
            {
                string[] IfDat = InFileStr[i].Split(':');
                if (IfDat[0] == "NODE")
                {
                    _nlist.Add(new Node(IfDat[1] + ".binhl"));
                    _uname.Add(IfDat[2]);
                }
                if (IfDat[0] == "WIRE")
                {
                    _wlist.Add(new Wire(IfDat[1], IfDat[2]));
                }
            }

            _wprior = new int[_wlist.Count];

            for (int i = 0; i < _wprior.Length; i++)
            {
                _wprior[i] = 0;
            }

            restart:
            Console.WriteLine("SZMod " + _szMod);
            Console.WriteLine("VsizeMod " + VsizeMod);
            Console.WriteLine("placewidch " + placewidch);

            _restartnum++;
            Console.Write(".");
            if (_wprior[0] > _wprior.Length)
            {
                for (int i = 0; i < _wprior.Length; i++)
                {
                    //Wprior[i] = 0;
                    Console.Write("ERRR");
                }
                placewidch++;
                VsizeMod++;
            }

            if (_restartnum > 100)
            {
                _restartnum = 0;
                if (Vmode)
                {
                    VsizeMod++;
                }
                else
                {
                    _szMod++;
                }
            }
            //wlist sort
            for (int i = 0; i < _wprior.Length; i++)
            {
                for (int j = 1; j < _wprior.Length; j++)
                {
                    if (_wprior[j - 1] < _wprior[j])
                    {
                        int t0 = _wprior[j];
                        _wprior[j] = _wprior[j - 1];
                        _wprior[j - 1] = t0;
                        Wire t1 = _wlist[j];
                        _wlist[j] = _wlist[j - 1];
                        _wlist[j - 1] = t1;
                    }
                }
            }

            //Placer
            int maxx = 0;
            int maxy = 0;
            int maxports = 0;
            int NotPortNodeNum = 0;
            int outpnum = 0;
            int inpnum = 0;

            for (int i = 0; i < _nlist.Count; i++)
            {
                if (_nlist[i].SizeX > maxx)
                {
                    maxx = _nlist[i].SizeX;
                }
                if (_nlist[i].SizeY > maxy)
                {
                    maxy = _nlist[i].SizeY;
                }
                if (_nlist[i].InPorts.Length > maxports)
                {
                    maxports = _nlist[i].InPorts.Length;
                }
                if (_nlist[i].OutPorts.Length > maxports)
                {
                    maxports = _nlist[i].OutPorts.Length;
                }
                if (_nlist[i].Name != "INPort")
                {
                    if (_nlist[i].Name != "OUTPort")
                    {
                        NotPortNodeNum++;
                    }
                }

                if (_nlist[i].Name == "INPort")
                {
                    inpnum++;
                }
                if (_nlist[i].Name == "OUTPort")
                {
                    outpnum++;
                }
            }

            if (!Vmode)
            {
                SizeX = (Convert.ToInt32(Math.Sqrt(NotPortNodeNum)) + 1)*(maxx + maxports*2) + inpnum*2 + outpnum*2 +
                        _szMod;
                _sizeY = (Convert.ToInt32(Math.Sqrt(NotPortNodeNum)) + 1)*(maxy + maxports*2) + inpnum*2 + outpnum*2 +
                         _szMod;
                if (_sizeY < 1 || SizeX < 1)
                {
                    _szMod++;
                    //goto restart;
                }
            }
            else
            {
                SizeX = (Convert.ToInt32(Math.Sqrt(NotPortNodeNum)) + 1)*(maxx + maxports*2) + inpnum*2 + outpnum*2 +
                        _szMod;
                _sizeY = (Convert.ToInt32(Math.Sqrt(NotPortNodeNum)) + 1)*(maxy + maxports*2) + inpnum*2 + outpnum*2 +
                         _szMod + VsizeMod;
                if (_sizeY < 1 || SizeX < 1)
                {
                    VsizeMod++;
                    goto restart;
                }
            }
            SizeX = 128;
            _sizeY = 256;
            int pmax = Convert.ToInt32(Math.Sqrt(NotPortNodeNum));
            //int px = 0;
            //int py = 0;

            _coordX = new List<int>();
            _coordY = new List<int>();

            int tipn = 0;
            int topn = 0;

            _portNum = new List<int>();

            //MultiLineSort
            var RyadList = new int[_uname.Count];
            PovtorSort:
            var KFList = new int[_uname.Count];
            int kz = 0;
            string s = _uname[0];

            for (int i = 0; i < _wlist.Count; i++)
            {
                string Sname = _wlist[i].StartName.Split('-')[0];
                string Ename = _wlist[i].EndName.Split('-')[0];
                //finding Sindex
                int Sidx = 0;
                int Eidx = 0;
                for (int j = 0; j < _uname.Count; j++)
                {
                    if (_uname[j] == Sname)
                    {
                        Sidx = j;
                    }
                    if (_uname[j] == Ename)
                    {
                        Eidx = j;
                    }
                }
                if (_nlist[Sidx].Name != "INPort")
                {
                    if (_nlist[Eidx].Name != "OUTPort")
                    {
                        if (Sidx != Eidx)
                        {
                            if (RyadList[Sidx] == RyadList[Eidx])
                            {
                                KFList[Eidx]++;
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < _nlist.Count; i++)
            {
                if (_nlist[i].InPorts.Length <= KFList[i]*2)
                {
                    kz++;
                    RyadList[i]++;
                }
            }
            if (kz > 0) goto PovtorSort;

            int RyadNum = Max(RyadList) + 1;

            for (int i = 0; i < _nlist.Count; i++)
            {
                if (_nlist[i].Name != "INPort")
                {
                    if (_nlist[i].Name != "OUTPort")
                    {
                        _coordX.Add(0);
                        _coordY.Add(0);
                        _portNum.Add(0);
                    }
                }
                if (_nlist[i].Name == "INPort")
                {
                    _coordX.Add(tipn*2 + 3);
                    _coordY.Add(0);
                    _portNum.Add(tipn);
                    tipn++;
                }
                if (_nlist[i].Name == "OUTPort")
                {
                    _coordX.Add(topn*2 + 3);
                    _coordY.Add(_sizeY - 3);
                    _portNum.Add(topn);
                    topn++;
                }
            }
            /*
            for (int i = 0; i < Nlist.Count; i++)
            {
                for (int j = 0; j < Nlist[i].InPorts.Length; j++)
                {
                    for (int k = 0; k < Uname.Count; k++)
                    {
                        if (k != i)
                        {
                            //if (Uname[k] == Wlist[i].StartName.Split('-')[0]
                        }
                    }
                }
            }
            */
            //MultiLinePlace

            var INPortInRyad = new int[RyadNum];
            var OUTPortInRyad = new int[RyadNum];
            var MaxVsizeObjInRyad = new int[RyadNum];
            var MinVsizeObjInRyad = new int[RyadNum];
            int INPortNum = 0;
            int OUTPortNum = 0;
            //pass1
            int Tline = 3 + tipn*2 + 1 + 2;

            for (int i = 0; i < RyadNum; i++)
            {
                MinVsizeObjInRyad[i] = 9999999;
                int lastx = 2;
                int n = 0;
                for (int j = 0; j < _nlist.Count; j++)
                {
                    if (RyadList[j] == i)
                    {
                        if (_nlist[j].Name != "INPort")
                        {
                            if (_nlist[j].Name != "OUTPort")
                            {
                                _coordX[j] = lastx;
                                _coordY[j] = Tline; //(RyadList[j] + 1) * 40;
                                lastx += _nlist[j].SizeX + n;
                                INPortInRyad[i] += _nlist[j].InPorts.Length;
                                OUTPortInRyad[i] += _nlist[j].OutPorts.Length;
                                if (MaxVsizeObjInRyad[i] < _nlist[j].SizeY) MaxVsizeObjInRyad[i] = _nlist[j].SizeY;
                                if (MinVsizeObjInRyad[i] > _nlist[j].SizeY) MinVsizeObjInRyad[i] = _nlist[j].SizeY;
                                //n--;
                            }
                        }
                        if (_nlist[j].Name == "INPort")
                        {
                            INPortNum++;
                        }
                        if (_nlist[j].Name == "OUTPort")
                        {
                            OUTPortNum++;
                        }
                    }
                }
            }
            //pass 2
            for (int i = 0; i < RyadNum; i++)
            {
                MinVsizeObjInRyad[i] = 9999999;
                int lastx = 2;
                int n = 0;
                for (int j = 0; j < _nlist.Count; j++)
                {
                    if (RyadList[j] == i)
                    {
                        if (_nlist[j].Name != "INPort")
                        {
                            if (_nlist[j].Name != "OUTPort")
                            {
                                _coordX[j] = lastx;
                                _coordY[j] = Tline + 0 + INPortInRyad[i]*2; //(RyadList[j] + 1) * 40;
                                lastx += _nlist[j].SizeX + n;
                                //INPortInRyad[i] += Nlist[j].InPorts.Length;
                                //OUTPortInRyad[i] += Nlist[j].OutPorts.Length;
                                //if (MaxVsizeObjInRyad[i] < Nlist[j].SizeY) MaxVsizeObjInRyad[i] = Nlist[j].SizeY;
                                //if (MinVsizeObjInRyad[i] > Nlist[j].SizeY) MinVsizeObjInRyad[i] = Nlist[j].SizeY;
                                //n--;
                            }
                        }
                    }
                }
                Tline += INPortInRyad[i]*2 + MaxVsizeObjInRyad[i] + OUTPortInRyad[i]*2 + 2;
            }
            _sizeY = Tline + OUTPortNum*2 + 4;
            SizeX = _sizeY;
            //SizeY = 128;
            for (int i = 0; i < _nlist.Count; i++)
            {
                if (_nlist[i].Name == "OUTPort")
                {
                    _coordY[i] = _sizeY - 3;
                }
            }

            /*
            for (int i = 0; i < Nlist.Count; i++)
            {
                if (Nlist[i].Name != "INPort")
                {
                    if (Nlist[i].Name != "OUTPort")
                    {
                        PortNum.Add(0);
                        CoordX.Add(px * ((maxx + maxports * 2)+placewidch)+6);
                        CoordY.Add(py * ((maxy + maxports * 2)+placewidch) + maxports * 2 + inpnum * 2+6);
                        px++;
                        if (px > pmax)
                        {
                            px = 0;
                            py++;
                        }
                    }
                }

                if (Nlist[i].Name == "INPort")
                {

                    CoordX.Add(tipn * 2+3);
                    CoordY.Add(0);
                    PortNum.Add(tipn);
                    tipn++;
                }
                if (Nlist[i].Name == "OUTPort")
                {
                    CoordX.Add(topn * 2+3);
                    CoordY.Add(SizeY - 3);
                    PortNum.Add(topn);
                    topn++;
                }
            }
             */
            //makebasemask
            _mask = new string[SizeX, _sizeY, 2];

            for (int i = 0; i < SizeX; i++)
            {
                for (int j = 0; j < _sizeY; j++)
                {
                    if (i == 0)
                    {
                        _mask[i, j, 0] = " ";
                        _mask[i, j, 1] = " ";
                    }
                    else
                    {
                        _mask[i, j, 0] = " ";
                        _mask[i, j, 1] = " ";
                    }
                }
            }

            try
            {
                for (int i = 0; i < _nlist.Count; i++)
                {
                    for (int j = 0; j < _nlist[i].SizeX; j++)
                    {
                        for (int k = 0; k < _nlist[i].SizeY; k++)
                        {
                            _mask[_coordX[i] + j, _coordY[i] + k, 0] = "#";
                            _mask[_coordX[i] + j, _coordY[i] + k, 1] = "#";
                        }
                    }
                }
            }
            catch
            {
                _szMod++;
                goto restart;
            }
            //maskupdate

            //DrawMask();
            //IOLonger
            tipn = 0;
            topn = 0;

            for (int i = 0; i < _wlist.Count; i++)
            {
                for (int j = 0; j < _nlist.Count; j++)
                {
                    if (_wlist[i].StartName.Split('-')[0] == _uname[j])
                    {
                        for (int k = 0; k < _nlist[j].OutPorts.Length; k++)
                        {
                            if (_wlist[i].StartName.Split('-')[1] == _nlist[j].OutPorts[k].Name)
                            {
                                _wlist[i].StartX = _nlist[j].OutPorts[k].PosX + _coordX[j];
                                _wlist[i].StartY = _nlist[j].OutPorts[k].PosY + _coordY[j];
                                _mask[_wlist[i].StartX, _wlist[i].StartY, 0] = " ";
                                _mask[_wlist[i].StartX, _wlist[i].StartY, 1] = " ";
                                for (int q = 0; q < (k + 1)*2; q++)
                                {
                                    try
                                    {
                                        _mask[_wlist[i].StartX - 1, _wlist[i].StartY + q, 0] = "x";
                                        _mask[_wlist[i].StartX + 1, _wlist[i].StartY + q, 0] = "x";
                                    }
                                    catch
                                    {
                                        goto restart;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < _wlist.Count; i++)
            {
                for (int j = 0; j < _nlist.Count; j++)
                {
                    if (_wlist[i].EndName.Split('-')[0] == _uname[j])
                    {
                        for (int k = 0; k < _nlist[j].InPorts.Length; k++)
                        {
                            if (_wlist[i].EndName.Split('-')[1] == _nlist[j].InPorts[k].Name)
                            {
                                _wlist[i].EndX = _nlist[j].InPorts[k].PosX + _coordX[j];
                                _wlist[i].EndY = _nlist[j].InPorts[k].PosY + _coordY[j];
                                _mask[_wlist[i].EndX, _wlist[i].EndY, 0] = " ";
                                _mask[_wlist[i].EndX, _wlist[i].EndY, 1] = " ";

                                for (int q = 0; q < (k + 1)*2; q++)
                                {
                                    _mask[_wlist[i].EndX + 1, _wlist[i].EndY - q, 0] = "x";
                                    _mask[_wlist[i].EndX - 1, _wlist[i].EndY - q, 0] = "x";
                                }
                            }
                        }
                    }
                }
            }
            //mask2
            for (int i = 0; i < RyadNum; i++)
            {
                for (int j = 0; j < _nlist.Count; j++)
                {
                    if (RyadList[j] == i)
                    {
                        if (_nlist[j].Name != "INPort")
                        {
                            if (_nlist[j].Name != "OUTPort")
                            {
                                for (int port = 0; port < _nlist[j].InPorts.Length; port++)
                                {
                                    int portStx = _nlist[j].InPorts[port].PosX + _coordX[j];
                                    int portSty = _nlist[j].InPorts[port].PosY + _coordY[j];
                                    for (int k = 0; k < INPortInRyad[i]*2 + 2; k++)
                                    {
                                        _mask[portStx - 1, portSty - k, 0] = "X";
                                        _mask[portStx + 1, portSty - k, 0] = "X";
                                    }
                                    portSty = portSty - INPortInRyad[i]*2 + 0;
                                    _mask[portStx, portSty - 1, 0] = "X";
                                    for (int k = portStx + 1; k < SizeX; k++)
                                    {
                                        _mask[k, portSty - 1, 0] = "X";
                                        _mask[k, portSty - 0, 0] = " ";
                                        _mask[k, portSty + 1, 0] = "X";
                                    }
                                    INPortInRyad[i]--;
                                }
                                for (int port = 0; port < _nlist[j].OutPorts.Length; port++)
                                {
                                    int portStx = _nlist[j].OutPorts[port].PosX + _coordX[j];
                                    int portSty = _nlist[j].OutPorts[port].PosY + _coordY[j];
                                    for (int k = 0;
                                        k < OUTPortInRyad[i]*2 + 3 + MaxVsizeObjInRyad[i] - _nlist[j].SizeY;
                                        k++)
                                    {
                                        _mask[portStx - 1, portSty + k, 0] = "X";
                                        _mask[portStx + 1, portSty + k, 0] = "X";
                                    }

                                    portSty = portSty + OUTPortInRyad[i]*2 + 1 + MaxVsizeObjInRyad[i] - _nlist[j].SizeY;
                                    _mask[portStx, portSty + 1, 0] = "X";
                                    for (int k = portStx + 1; k < SizeX; k++)
                                    {
                                        _mask[k, portSty - 1, 0] = "X";
                                        _mask[k, portSty - 0, 0] = " ";
                                        _mask[k, portSty + 1, 0] = "X";
                                    }

                                    OUTPortInRyad[i]--;
                                }
                            }
                        }

                        if (_nlist[j].Name == "INPort")
                        {
                            for (int port = 0; port < _nlist[j].OutPorts.Length; port++)
                            {
                                int portStx = _nlist[j].OutPorts[port].PosX + _coordX[j];
                                int portSty = _nlist[j].OutPorts[port].PosY + _coordY[j];
                                //for (int k = 0; k < OUTPortNum * 2 + 3 + MaxVsizeObjInRyad[i] - Nlist[j].SizeY; k++)
                                for (int k = 0; k < INPortNum*2 + 3 + 0; k++)
                                {
                                    _mask[portStx - 1, portSty + k, 0] = "X";
                                    _mask[portStx + 1, portSty + k, 0] = "X";
                                }

                                //portSty = portSty + OUTPortNum * 2 + 1 + MaxVsizeObjInRyad[i] - Nlist[j].SizeY;
                                portSty = portSty + INPortNum*2 + 1 + 0;
                                _mask[portStx, portSty + 1, 0] = "X";
                                for (int k = portStx + 1; k < SizeX; k++)
                                {
                                    _mask[k, portSty - 1, 0] = "X";
                                    _mask[k, portSty - 0, 0] = " ";
                                    _mask[k, portSty + 1, 0] = "X";
                                }

                                INPortNum--;
                            }
                        }
                        if (_nlist[j].Name == "OUTPort")
                        {
                            for (int port = 0; port < _nlist[j].InPorts.Length; port++)
                            {
                                int portStx = _nlist[j].InPorts[port].PosX + _coordX[j];
                                int portSty = _nlist[j].InPorts[port].PosY + _coordY[j];
                                for (int k = 0; k < OUTPortNum*2 + 2; k++)
                                {
                                    _mask[portStx - 1, portSty - k, 0] = "X";
                                    _mask[portStx + 1, portSty - k, 0] = "X";
                                }
                                portSty = portSty - OUTPortNum*2 + 0;
                                _mask[portStx, portSty - 1, 0] = "X";
                                for (int k = portStx + 1; k < SizeX; k++)
                                {
                                    _mask[k, portSty - 1, 0] = "X";
                                    _mask[k, portSty - 0, 0] = " ";
                                    _mask[k, portSty + 1, 0] = "X";
                                }
                                OUTPortNum--;
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < RyadNum; i++)
            {
                for (int j = 0; j < _nlist.Count; j++)
                {
                    if (RyadList[j] == i)
                    {
                        if (_nlist[j].Name != "INPort")
                        {
                            if (_nlist[j].Name != "OUTPort")
                            {
                                for (int port = 0; port < _nlist[j].InPorts.Length; port++)
                                {
                                    //portStx =
                                }
                            }
                        }
                    }
                }
            }

            //goto maker;

            //Router
            int Over9000 = SizeX + _sizeY*2;

            //DrawMask();

            for (int i = 0; i < _wlist.Count; i++)
            {
                Console.Write(".");
                _wavemap = new int[SizeX, _sizeY, 2];

                int wlen = 1;

                _wavemap[_wlist[i].StartX, _wlist[i].StartY, 0] = 1;

                for (int j = 1; j < Over9000; j++)
                {
                    for (int k = 0; k < SizeX; k++)
                    {
                        for (int l = 0; l < _sizeY; l++)
                        {
                            for (int m = 0; m < 2; m++)
                            {
                                if (_wavemap[k, l, m] == j && k - 1 >= 0)
                                {
                                    if (_wavemap[k - 1, l, m] == 0)
                                    {
                                        if (_mask[k - 1, l, m] == " ")
                                        {
                                            _wavemap[k - 1, l, m] = j + 1;
                                        }
                                    }
                                }

                                if (_wavemap[k, l, m] == j && k + 1 < SizeX)
                                {
                                    if (_wavemap[k + 1, l, m] == 0)
                                    {
                                        if (_mask[k + 1, l, m] == " ")
                                        {
                                            _wavemap[k + 1, l, m] = j + 1;
                                        }
                                    }
                                }

                                if (_wavemap[k, l, m] == j && l - 1 >= 0)
                                {
                                    if (_wavemap[k, l - 1, m] == 0)
                                    {
                                        if (_mask[k, l - 1, m] == " ")
                                        {
                                            _wavemap[k, l - 1, m] = j + 1;
                                        }
                                    }
                                }

                                if (_wavemap[k, l, m] == j && l + 1 < _sizeY)
                                {
                                    if (_wavemap[k, l + 1, m] == 0)
                                    {
                                        if (_mask[k, l + 1, m] == " ")
                                        {
                                            _wavemap[k, l + 1, m] = j + 1;
                                        }
                                    }
                                }

                                if (_wavemap[k, l, m] == j && m - 1 >= 0)
                                {
                                    if (_wavemap[k, l, m - 1] == 0)
                                    {
                                        if (_mask[k, l, m - 1] == " ")
                                        {
                                            _wavemap[k, l, m - 1] = j + 1;
                                        }
                                    }
                                }

                                if (_wavemap[k, l, m] == j && m + 1 <= 1)
                                {
                                    if (_wavemap[k, l, m + 1] == 0)
                                    {
                                        if (_mask[k, l, m + 1] == " ")
                                        {
                                            _wavemap[k, l, m + 1] = j + 1;
                                        }
                                    }
                                }

                                if (k == _wlist[i].EndX)
                                {
                                    if (l == _wlist[i].EndY)
                                    {
                                        if (m == 0)
                                        {
                                            if (_wavemap[k, l, m] > 0)
                                            {
                                                wlen = j;
                                                j = Over9000 + 1;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (wlen == 1)
                {
                    _wprior[i]++;
                    if (i == 0) placewidch++;
                    Console.WriteLine("Unrouted " + i);
                    goto restart;
                }

                //DrawWave(); //to debug
                //BackTracing
                _wlist[i].WirePointX = new int[wlen + 1];
                _wlist[i].WirePointY = new int[wlen + 1];
                _wlist[i].WirePointZ = new int[wlen + 1];
                _wlist[i].WirePointX[wlen] = _wlist[i].EndX;
                _wlist[i].WirePointY[wlen] = _wlist[i].EndY;
                _wlist[i].WirePointZ[wlen] = 0;

                _wlist[i].WirePointX[0] = _wlist[i].StartX;
                _wlist[i].WirePointY[0] = _wlist[i].StartY;
                _wlist[i].WirePointZ[0] = 0;

                int tx = _wlist[i].EndX;
                int ty = _wlist[i].EndY;
                int tz = 0;

                for (int j = 1; j < wlen; j++)
                {
                    if ((tx - 1) > 0)
                        if (_wavemap[tx - 1, ty, tz] < _wavemap[tx, ty, tz] && _wavemap[tx - 1, ty, tz] > 0)
                        {
                            tx = tx - 1;
                            goto endselect;
                        }

                    if ((tx + 1) < SizeX)
                        if (_wavemap[tx + 1, ty, tz] < _wavemap[tx, ty, tz] && _wavemap[tx + 1, ty, tz] > 0)
                        {
                            tx = tx + 1;
                            goto endselect;
                        }

                    if ((ty - 1) > 0)
                        if (_wavemap[tx, ty - 1, tz] < _wavemap[tx, ty, tz] && _wavemap[tx, ty - 1, tz] > 0)
                        {
                            ty = ty - 1;
                            goto endselect;
                        }

                    if ((ty + 1) < _sizeY)
                        if (_wavemap[tx, ty + 1, tz] < _wavemap[tx, ty, tz] && _wavemap[tx, ty + 1, tz] > 0)
                        {
                            ty = ty + 1;
                            goto endselect;
                        }

                    if ((tz + 1) < 2)
                        if (_wavemap[tx, ty, tz + 1] < _wavemap[tx, ty, tz] && _wavemap[tx, ty, tz + 1] > 0)
                        {
                            tz = tz + 1;
                            goto endselect;
                        }

                    if ((tz - 1) >= 0)
                        if (_wavemap[tx, ty, tz - 1] < _wavemap[tx, ty, tz] && _wavemap[tx, ty, tz - 1] > 0)
                        {
                            tz = tz - 1;
                        }

                    endselect:

                    _wlist[i].WirePointX[wlen - j] = tx;
                    _wlist[i].WirePointY[wlen - j] = ty;
                    _wlist[i].WirePointZ[wlen - j] = tz;
                }

                // update mask

                for (int j = 0; j < _wlist[i].WirePointX.Length; j++)
                {
                    _mask[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], _wlist[i].WirePointZ[j]] = "#";

                    if (_wlist[i].WirePointX[j] - 1 > 0)
                    {
                        _mask[_wlist[i].WirePointX[j] - 1, _wlist[i].WirePointY[j], _wlist[i].WirePointZ[j]] = "#";
                    }
                    if (_wlist[i].WirePointX[j] + 1 < SizeX)
                    {
                        _mask[_wlist[i].WirePointX[j] + 1, _wlist[i].WirePointY[j], _wlist[i].WirePointZ[j]] = "#";
                    }
                    if (_wlist[i].WirePointY[j] - 1 > 0)
                    {
                        _mask[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j] - 1, _wlist[i].WirePointZ[j]] = "#";
                    }
                    if (_wlist[i].WirePointY[j] + 1 < _sizeY)
                    {
                        _mask[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j] + 1, _wlist[i].WirePointZ[j]] = "#";
                    }
                }
                //Console.Clear();
                //DrawMask();
            }

            //maker:
            //maker
            var outNode = new Node("4AND", SizeX, _sizeY, 4);

            for (int j = 0; j < outNode.SizeX; j++)
            {
                for (int k = 0; k < outNode.SizeY; k++)
                {
                    for (int l = 0; l < outNode.SizeZ; l++)
                    {
                        try
                        {
                            outNode.DataMatrix[j, k, l] = "0";
                        }
                        catch
                        {
                            VsizeMod++;
                            goto restart;
                        }
                    }
                }
            }

            for (int i = 0; i < _nlist.Count; i++)
            {
                for (int j = 0; j < _nlist[i].SizeX; j++)
                {
                    for (int k = 0; k < _nlist[i].SizeY; k++)
                    {
                        for (int l = 0; l < _nlist[i].SizeZ; l++)
                        {
                            outNode.DataMatrix[_coordX[i] + j, _coordY[i] + k, l] =
                                _nlist[i].DataMatrix[j, _nlist[i].SizeY - k - 1, l];
                        }
                    }
                }
            }
            outNode.InPorts = new InPort[inpnum];
            outNode.OutPorts = new OutPort[outpnum];

            int tip = 0;
            int top = 0;

            for (int i = 0; i < _nlist.Count; i++)
            {
                if (_nlist[i].Name == "INPort")
                {
                    outNode.InPorts[tip] = new InPort(_uname[i], _nlist[i].InPorts[0].PosX + _coordX[i],
                        _nlist[i].InPorts[0].PosY + _coordY[i]);
                    tip++;
                }
                if (_nlist[i].Name == "OUTPort")
                {
                    outNode.OutPorts[top] = new OutPort(_uname[i], _nlist[i].OutPorts[0].PosX + _coordX[i],
                        _nlist[i].OutPorts[0].PosY + _coordY[i]);
                    top++;
                }
            }
            //goto endmake;

            //make wire
            for (int i = 0; i < _wlist.Count; i++)
            {
                for (int j = 0; j < _wlist[i].WirePointX.Length; j++)
                {
                    if (_wlist[i].WirePointZ[j] == 0)
                    {
                        outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 0] = "w";
                        outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 1] = "#";
                    }

                    if (_wlist[i].WirePointZ[j] == 1)
                    {
                        outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 2] = "w";
                        outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 3] = "#";
                    }
                }
                //upper - downer
                for (int j = 1; j < _wlist[i].WirePointX.Length; j++)
                {
                    if (_wlist[i].WirePointZ[j] != _wlist[i].WirePointZ[j - 1])
                    {
                        outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 0] = "0";
                        outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 1] = "w";
                        outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 2] = "#";
                        outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 3] = "0";
                    }
                }
                //make wire repiters
                int tlen = 2;
                try
                {
                    for (int j = 2; j < _wlist[i].WirePointX.Length - 2; j++)
                    {
                        tlen++;
                        if (tlen > 13)
                        {
                            if (_wlist[i].WirePointZ[j - 1] == _wlist[i].WirePointZ[j + 1] &&
                                _wlist[i].WirePointZ[j + 1] == _wlist[i].WirePointZ[j + 2] &&
                                _wlist[i].WirePointZ[j - 1] == _wlist[i].WirePointZ[j - 2])
                            {
                                if (_wlist[i].WirePointY[j - 1] == _wlist[i].WirePointY[j + 1])
                                {
                                    if (_wlist[i].WirePointX[j - 1] < _wlist[i].WirePointX[j + 1])
                                    {
                                        if (_wlist[i].WirePointZ[j] == 0)
                                        {
                                            outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 1] =
                                                ">";
                                        }

                                        if (_wlist[i].WirePointZ[j] == 1)
                                        {
                                            outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 3] =
                                                ">";
                                        }
                                        tlen = 0;
                                    }
                                }
                            }

                            if (_wlist[i].WirePointZ[j - 1] == _wlist[i].WirePointZ[j + 1] &&
                                _wlist[i].WirePointZ[j + 1] == _wlist[i].WirePointZ[j + 2] &&
                                _wlist[i].WirePointZ[j - 1] == _wlist[i].WirePointZ[j - 2])
                            {
                                if (_wlist[i].WirePointY[j - 1] == _wlist[i].WirePointY[j + 1])
                                {
                                    if (_wlist[i].WirePointX[j - 1] > _wlist[i].WirePointX[j + 1])
                                    {
                                        if (_wlist[i].WirePointZ[j] == 0)
                                        {
                                            outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 1] =
                                                "<";
                                        }

                                        if (_wlist[i].WirePointZ[j] == 1)
                                        {
                                            outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 3] =
                                                "<";
                                        }
                                        tlen = 0;
                                    }
                                }
                            }

                            if (_wlist[i].WirePointZ[j - 1] == _wlist[i].WirePointZ[j + 1] &&
                                _wlist[i].WirePointZ[j + 1] == _wlist[i].WirePointZ[j + 2] &&
                                _wlist[i].WirePointZ[j - 1] == _wlist[i].WirePointZ[j - 2])
                            {
                                if (_wlist[i].WirePointX[j - 1] == _wlist[i].WirePointX[j + 1])
                                {
                                    if (_wlist[i].WirePointY[j - 1] > _wlist[i].WirePointY[j + 1])
                                    {
                                        if (_wlist[i].WirePointZ[j] == 0)
                                        {
                                            outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 1] =
                                                "v";
                                        }

                                        if (_wlist[i].WirePointZ[j] == 1)
                                        {
                                            outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 3] =
                                                "v";
                                        }
                                        tlen = 0;
                                    }
                                }
                            }

                            if (_wlist[i].WirePointZ[j - 1] == _wlist[i].WirePointZ[j + 1] &&
                                _wlist[i].WirePointZ[j + 1] == _wlist[i].WirePointZ[j + 2] &&
                                _wlist[i].WirePointZ[j - 1] == _wlist[i].WirePointZ[j - 2])
                            {
                                if (_wlist[i].WirePointX[j - 1] == _wlist[i].WirePointX[j + 1])
                                {
                                    if (_wlist[i].WirePointY[j - 1] < _wlist[i].WirePointY[j + 1])
                                    {
                                        if (_wlist[i].WirePointZ[j] == 0)
                                        {
                                            outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 1] =
                                                "^";
                                        }

                                        if (_wlist[i].WirePointZ[j] == 1)
                                        {
                                            outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 3] =
                                                "^";
                                        }
                                        tlen = 0;
                                    }
                                }
                            }

                            if (tlen != 0)
                            {
                                j -= 2;
                                if (j < 1)
                                {
                                    //to do check
                                    //j = Wlist[i].WirePointX.Length;
                                }
                            }
                        }
                    }
                }
                catch
                {
                    for (int j = 0; j < _wlist[i].WirePointX.Length; j++)
                    {
                        if (_wlist[i].WirePointZ[j] == 0)
                        {
                            outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 0] = "k";
                            //outNode.DataMatrix[Wlist[i].WirePointX[j], Wlist[i].WirePointY[j], 1] = "#";
                        }

                        if (_wlist[i].WirePointZ[j] == 1)
                        {
                            outNode.DataMatrix[_wlist[i].WirePointX[j], _wlist[i].WirePointY[j], 2] = "k";
                            //outNode.DataMatrix[Wlist[i].WirePointX[j], Wlist[i].WirePointY[j], 3] = "#";
                        }
                    }

                    //placewidch++;
                    //goto restart;
                }
            }

            //end make
            //endmake:

            //DrawOutMask

            tipn = 0;
            topn = 0;

            for (int i = 0; i < _wlist.Count; i++)
            {
                for (int j = 0; j < _nlist.Count; j++)
                {
                    if (_wlist[i].StartName.Split('-')[0] == _uname[j])
                    {
                        for (int k = 0; k < _nlist[j].OutPorts.Length; k++)
                        {
                            if (_wlist[i].StartName.Split('-')[1] == _nlist[j].OutPorts[k].Name)
                            {
                                _wlist[i].StartX = _nlist[j].OutPorts[k].PosX + _coordX[j];
                                _wlist[i].StartY = _nlist[j].OutPorts[k].PosY + _coordY[j];
                                _mask[_wlist[i].StartX, _wlist[i].StartY, 0] = " ";
                                _mask[_wlist[i].StartX, _wlist[i].StartY, 1] = " ";
                                for (int q = 0; q < (k + 1)*2; q++)
                                {
                                    try
                                    {
                                        //mask[Wlist[i].StartX - 1, Wlist[i].StartY + q, 0] = "X";
                                        //mask[Wlist[i].StartX + 1, Wlist[i].StartY + q, 0] = "X";
                                    }
                                    catch
                                    {
                                        goto restart;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < _wlist.Count; i++)
            {
                for (int j = 0; j < _nlist.Count; j++)
                {
                    if (_wlist[i].EndName.Split('-')[0] == _uname[j])
                    {
                        for (int k = 0; k < _nlist[j].InPorts.Length; k++)
                        {
                            if (_wlist[i].EndName.Split('-')[1] == _nlist[j].InPorts[k].Name)
                            {
                                _wlist[i].EndX = _nlist[j].InPorts[k].PosX + _coordX[j];
                                _wlist[i].EndY = _nlist[j].InPorts[k].PosY + _coordY[j];
                                _mask[_wlist[i].EndX, _wlist[i].EndY, 0] = " ";
                                _mask[_wlist[i].EndX, _wlist[i].EndY, 1] = " ";

                                for (int q = 0; q < (k + 1)*2; q++)
                                {
                                    //mask[Wlist[i].EndX + 1, Wlist[i].EndY - q, 0] = "X";
                                    //mask[Wlist[i].EndX - 1, Wlist[i].EndY - q, 0] = "X";
                                }
                            }
                        }
                    }
                }
            }
            //drawe
            /*
            for (int i = 0; i < RyadNum; i++)
            {
                for (int j = 0; j < Nlist.Count; j++)
                {

                    if (RyadList[j] == i)
                    {
                        if (Nlist[j].Name != "INPort")
                        {
                            if (Nlist[j].Name != "OUTPort")
                            {
                                for (int port = 0; port < Nlist[j].InPorts.Length; port++)
                                {
                                    int portStx = Nlist[j].InPorts[port].PosX + CoordX[j];
                                    int portSty = Nlist[j].InPorts[port].PosY + CoordY[j];
                                    for (int k = 0; k < INPortInRyad[i]*2+2; k++)
                                    {
                                        mask[portStx - 1, portSty - k, 0] = "X";
                                        mask[portStx + 1, portSty - k, 0] = "X";
                                    }
                                    portSty = portSty - INPortInRyad[i] * 2+0;
                                    mask[portStx, portSty - 1, 0] = "X";
                                    for (int k = portStx+1; k < SizeX; k++)
                                    {
                                        mask[k, portSty - 1, 0] = "X";
                                        mask[k, portSty - 0, 0] = " ";
                                        mask[k, portSty + 1, 0] = "X";
                                    }
                                    INPortInRyad[i]--;
                                }
                                for (int port = 0; port < Nlist[j].OutPorts.Length; port++)
                                {
                                    int portStx = Nlist[j].OutPorts[port].PosX + CoordX[j];
                                    int portSty = Nlist[j].OutPorts[port].PosY + CoordY[j];
                                    for (int k = 0; k < OUTPortInRyad[i] * 2 + 3; k++)
                                    {
                                        mask[portStx - 1, portSty + k, 0] = "X";
                                        mask[portStx + 1, portSty + k, 0] = "X";
                                    }

                                    portSty = portSty + OUTPortInRyad[i] * 2 + 1;
                                    mask[portStx, portSty + 1, 0] = "X";
                                    for (int k = portStx + 1; k < SizeX; k++)
                                    {
                                        mask[k, portSty - 1, 0] = "X";
                                        mask[k, portSty - 0, 0] = " ";
                                        mask[k, portSty + 1, 0] = "X";
                                    }

                                    OUTPortInRyad[i]--;
                                }
                            }
                        }
                    }
                }
            }
            */
            for (int i = 0; i < outNode.SizeX; i++)
            {
                for (int j = 0; j < outNode.SizeY; j++)
                {
                    if (_mask[i, j, 0] == "X")
                    {
                        //to Debug
                        //outNode.DataMatrix[i, j, 0] = "k";
                    }
                }
            }
            int maxR = 0;
            for (int i = 0; i < outNode.SizeX; i++)
            {
                for (int j = 0; j < outNode.SizeY; j++)
                {
                    if (_mask[i, j, 0] == "#")
                    {
                        if (maxR < i)
                        {
                            maxR = i;
                        }
                    }
                    if (_mask[i, j, 1] == "#")
                    {
                        if (maxR < i)
                        {
                            maxR = i;
                        }
                    }
                }
            }

            outNode.SizeX = maxR + 1;

            //exporter
            Vmode = true;
            if (Vmode)
            {
                outNode.Export(FileName + ".binhl");
            }
            else
            {
                Vmode = true;
                goto restart;
            }
        }