Пример #1
0
        /// <summary>
        /// Функция вывода графа на экран
        /// </summary>
        /// <param name="graf">
        /// матрица смежности графа котороый нужно построить
        /// </param>
        public void paintGraf(Graph graf)
        {
            System.Drawing.Point pointStart = new System.Drawing.Point();
            System.Drawing.Point pointEnd = new System.Drawing.Point();
            System.Drawing.Graphics grafic = this.panel.CreateGraphics();
            grafic.Clear(Color.FromName("Control"));

            //рисую точки графа
            for (int y = 0; y < graf.getGrafDecart().getSizeDecartGrafMatrixY() ; y++)
            {
                for (int x = 0; x < graf.getGrafDecart().getSizeDecartGrafMatrixX() ; x++)
                {
                    if (graf.getGrafDecart().getElementDecartGraf(x, y) > 0)
                    {
                        pointStart =
                            new System.Drawing.Point(x*scaleGraf + displasmentX,
                                                     y*scaleGraf + displasmentY);
                        String stringWay = "";
                        int bufi = graf.getGrafDecart().getElementDecartGraf(x, y);
                        if (graf.GrafSizeWay.Count>0)
                        stringWay = "(" + graf.GrafSizeWay[bufi-1][bufi-1].SizeWay.ToString() + ")";
                        if (graf.contractionDot == graf.getGrafDecart().getElementDecartGraf(x, y))
                        {
                            grafic.DrawRectangle(System.Drawing.Pens.Red,
                                                 new System.Drawing.Rectangle(pointStart.X - getBetweenScalePoint(),
                                                                              pointStart.Y - getBetweenScalePoint(),
                                                                              scalePoint, scalePoint));
                            grafic.DrawString(Convert.ToString(graf.getGrafDecart().getElementDecartGraf(x, y))+stringWay,
                                              new Font("Arial", 10), new SolidBrush(Color.Red), pointStart);
                        }
                        else
                        {
                            grafic.DrawRectangle(System.Drawing.Pens.Black,
                                                 new System.Drawing.Rectangle(pointStart.X - getBetweenScalePoint(),
                                                                              pointStart.Y - getBetweenScalePoint(),
                                                                              scalePoint, scalePoint));
                            grafic.DrawString(Convert.ToString(graf.getGrafDecart().getElementDecartGraf(x, y))+stringWay,
                                              new Font("Arial", 10), new SolidBrush(Color.Black), pointStart);
                        }

                    }
                   /* if (coordinates.getEdge())
                    {
                            grafic.DrawLine(System.Drawing.Pens.Black, pointStart , pointEnd);
                    }*/
                }
            }
            //рисую ребра графа
               for (int y = 0; y<graf.getGraf().Count;y++)
               {
               for (int x = 0; x < graf.getGraf().Count; x++)
               {
                   if (graf.getCoordinates(x, y))
                   {

                       pointStart =
                           new Point(graf.getCoordinatePoint(x).getStartCoordinate().getX()*scaleGraf + displasmentX,
                                     graf.getCoordinatePoint(x).getStartCoordinate().getY()*scaleGraf + displasmentY);
                       pointEnd =
                           new Point(graf.getCoordinatePoint(y).getStartCoordinate().getX()*scaleGraf + displasmentX,
                                     graf.getCoordinatePoint(y).getStartCoordinate().getY()*scaleGraf + displasmentY);
                       grafic.DrawLine(System.Drawing.Pens.Black, pointStart, pointEnd);
                       Point pointString = new Point(((pointStart.X + pointEnd.X)/2),
                                                     ((pointStart.Y + pointEnd.Y)/2));
                    /*   if(x<y)
                       {
                           if (graf.GrafSizeWay[x][y].SizeWay == 0)
                           {
                               grafic.DrawString(Convert.ToString(graf.GrafSizeWay[y][x].SizeWay),
                                                 new Font("Arial", 10), new SolidBrush(Color.Brown), pointString);
                           }
                       else
                           {

                               grafic.DrawString(Convert.ToString(graf.GrafSizeWay[x][y].SizeWay),
                                                 new Font("Arial", 10), new SolidBrush(Color.Brown), pointString);
                           }
                       }*/
                   }

               }
               }
        }
Пример #2
0
        public Graph setWith(Graph graf)
        {
            Graph graf1 = new Graph(graf.getGrafDecart().count());

            //заполняю координаты в пространстве
            Nodes grafDecart = new Nodes(graf.getGrafDecart().getSizeDecartGrafMatrixX(),
                                                   graf.getGrafDecart().getSizeDecartGrafMatrixY(), false);
            for (int y = 0; y < graf.getGrafDecart().getSizeDecartGrafMatrixY(); y++)
            {
                for (int x = 0; x < graf.getGrafDecart().getSizeDecartGrafMatrixX(); x++)
                {
                    grafDecart.setGrafMatrixDecart(x, y, graf.getGrafDecart().getElementDecartGraf(x, y));
                }
            }
            graf1.setGrafDecart(grafDecart);

            //заполняю грани в пространстве
            for (int y = 0; y < graf.getSize(); y++)
            {
                for (int x = 0; x < graf.getSize(); x++)
                {
                    graf1.setCoordinates(x, y, graf.getCoordinates(x, y));
                }
            }
            //заполняю размеры путей
            for (int y = 0; y < graf.getSize(); y++)
            {
                List<OptionsGraf> listbuf = new List<OptionsGraf>();
                for (int x = 0; x < graf.getSize(); x++)
                {
                    listbuf.Add(graf.grafSizeWay[x][y]);
                }
                graf1.grafSizeWay.Add(listbuf);
            }

            for (int y = 0; y < graf.getSize(); y++)
            {
                List<OptionsGraf> listbuf = new List<OptionsGraf>();
                for (int x = 0; x < graf.getSize(); x++)
                {
                    listbuf.Add(graf.resultSizeWay[x][y]);
                }
                graf1.resultSizeWay.Add(listbuf);
            }

            return graf1;
        }
Пример #3
0
        private void createGrafDecartInfo(Graph graf1)
        {
            if (graf1==null)
                return;
            dataGridView1.DataSource = null;
            dataGridView1.Rows.Clear();
            dataGridView1.Columns.Clear();
            for (int i = 0; i < graf1.getGrafDecart().getSizeDecartGrafMatrixX(); i++)
            {
                DataGridViewColumn col = new DataGridViewTextBoxColumn();
                col.Name = Convert.ToString(i+1);
                col.HeaderText = Convert.ToString(i+1);
                col.ValueType = typeof(string);
                col.Width = 50;
                dataGridView1.Columns.Add(col);
            }

            for (int y = 0; y < graf1.getGrafDecart().getSizeDecartGrafMatrixY(); y++)
            {
                DataGridViewRow row = new DataGridViewRow();
                for (int x = 0; x < graf1.getGrafDecart().getSizeDecartGrafMatrixX(); x++)
                {
                        DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
                        cell.ValueType = typeof (int);
                        cell.Value = graf1.getGrafDecart().getElementDecartGraf(x,y);
                        row.Cells.Add(cell);
                }
                row.HeaderCell.Value = Convert.ToString(y + 1);
                dataGridView1.Rows.Add(row);
            }
        }