Пример #1
0
        public void AddBlockOnEdge(int[] edge)
        {
            IBlock b = new SquareBlock();

            blocks.Insert(edge[1], b);

            for (int i = graph.CountNodes() + 1; i > 0; i--)
            {
                if (i >= edge[1])
                {
                    graph.SetNodeShift(i, graph.GetNodeShift(i - 1));
                    graph.setNodeType(i, graph.GetNodeType(i - 1));
                    graph.GetAdj()[i] = new List <int>();
                    for (int j = 0; j < graph.GetAdj()[i - 1].Count; j++)
                    {
                        graph.GetAdj()[i].Add(graph.GetAdj()[i - 1][j]);
                    }
                }
                for (int j = 0; j < graph.GetAdj()[i].Count; j++)
                {
                    if (graph.GetAdj()[i][j] >= edge[1])
                    {
                        graph.GetAdj()[i][j]++;
                    }
                }
            }
            graph.SetNodeShift(edge[1], graph.GetNodeShift(edge[1] + 1));
            graph.setNodeType(edge[1], 1);
            graph.SetNodesNumber(graph.CountNodes() + 1);
            if (graph.GetAdj()[edge[0]][0] == edge[1] + 1 || graph.GetAdj()[edge[0]].Count == 1)
            {
                graph.GetAdj()[edge[0]][0] = edge[1];
            }
            else
            {
                graph.GetAdj()[edge[0]][1] = edge[1];
            }
            graph.GetAdj()[edge[1]] = new List <int>();
            graph.GetAdj()[edge[1]].Add(edge[1] + 1);
        }
Пример #2
0
        public Bitmap Draw(OrientedGraph graph, int scroll, int selectedID, int[] selectedEdge)
        {
            btm = new Bitmap(500, 800);
            gr  = Graphics.FromImage(btm);

            for (int i = 0; i < graph.CountNodes(); i++)
            {
                Pen pen;
                if (i == selectedID)
                {
                    pen = new Pen(Color.Red, 3);
                }
                else
                {
                    pen = new Pen(Color.Black, 3);
                }

                switch (graph.GetNodeType(i))
                {
                case 1:
                {
                    gr.DrawRectangle(pen, 200 + graph.GetNodeShift(i) * 100, 25 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll, 100, 100);
                    break;
                }

                case 2:
                {
                    Point[] p = new Point[4];
                    p[0] = new Point(200 + graph.GetNodeShift(i) * 100, 75 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    p[1] = new Point(250 + graph.GetNodeShift(i) * 100, 50 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    p[2] = new Point(300 + graph.GetNodeShift(i) * 100, 75 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    p[3] = new Point(250 + graph.GetNodeShift(i) * 100, 100 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    gr.DrawPolygon(pen, p);
                    break;
                }

                case 3:
                {
                    gr.DrawEllipse(pen, 200 + graph.GetNodeShift(i) * 100, 50 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll, 100, 50);
                    break;
                }

                case 5:
                {
                    Point[] p = new Point[4];
                    p[0] = new Point(200 + graph.GetNodeShift(i) * 100, 75 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    p[1] = new Point(250 + graph.GetNodeShift(i) * 100, 50 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    p[2] = new Point(300 + graph.GetNodeShift(i) * 100, 75 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    p[3] = new Point(250 + graph.GetNodeShift(i) * 100, 100 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    gr.DrawPolygon(pen, p);
                    break;
                }
                }
                for (int j = 0; j < graph.GetAdj()[i].Count; j++)
                {
                    if (selectedEdge[0] == i && selectedEdge[1] == graph.GetAdj()[i][j])
                    {
                        pen = Pens.Red;
                    }
                    else
                    {
                        pen = Pens.Black;
                    }
                    Point p1 = new Point(250 + graph.GetNodeShift(i) * 100, 75 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    Point p2 = new Point(250 + graph.GetNodeShift(graph.GetAdj()[i][j]) * 100, 75 + DIST_BETWEEN_BLOCKS * graph.GetAdj()[i][j] - SCROLL_SCALE * scroll);
                    Drawline(pen, graph.GetNodeType(i), graph.GetNodeType(graph.GetAdj()[i][j]), p1, p2);
                }
            }

            return(btm);
        }