private void createGrafSizeWay(Graph graf1) { if (graf1 == null) return; dataGridView3.DataSource = null; dataGridView3.Rows.Clear(); dataGridView3.Columns.Clear(); dataGridView4.DataSource = null; dataGridView4.Rows.Clear(); dataGridView4.Columns.Clear(); for (int i = 0; i < graf1.getGraf().Count; i++) { DataGridViewColumn col = new DataGridViewTextBoxColumn(); col.Name = Convert.ToString(i + 1); col.HeaderText = Convert.ToString(i + 1); col.ValueType = typeof(string); col.Width = 50; DataGridViewColumn col1 = new DataGridViewTextBoxColumn(); col1.Name = Convert.ToString(i + 1); col1.HeaderText = Convert.ToString(i + 1); col1.ValueType = typeof(string); col1.Width = 50; dataGridView3.Columns.Add(col); dataGridView4.Columns.Add(col1); } for (int y = 0; y < graf1.getGraf().Count; y++) { DataGridViewRow row = new DataGridViewRow(); DataGridViewRow row1 = new DataGridViewRow(); for (int x = 0; x < graf1.getGraf().Count; x++) { DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell cell1 = new DataGridViewTextBoxCell(); cell1.ValueType = typeof (int); cell1.Value = Convert.ToInt32(graf1.resultSizeWay[x][y].SizeWay); cell.ValueType = typeof(int); cell.Value = Convert.ToInt32(graf1.GrafSizeWay[x][y].SizeWay); row.Cells.Add(cell); row1.Cells.Add(cell1); } row1.HeaderCell.Value = Convert.ToString(y + 1); row.HeaderCell.Value = Convert.ToString(y + 1); dataGridView3.Rows.Add(row); dataGridView4.Rows.Add(row1); } }
/// <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); } }*/ } } } }
private void createGrafInfo(Graph graf1) { if (graf1 == null) return; dataGridView2.DataSource = null; dataGridView2.Rows.Clear(); dataGridView2.Columns.Clear(); for (int i = 0; i < graf1.getGraf().Count; i++) { DataGridViewColumn col = new DataGridViewTextBoxColumn(); col.Name = Convert.ToString(i+1); col.HeaderText = Convert.ToString(i+1); col.ValueType = typeof(string); col.Width = 50; dataGridView2.Columns.Add(col); } for (int y = 0; y < graf1.getGraf().Count; y++) { DataGridViewRow row = new DataGridViewRow(); for (int x = 0; x < graf1.getGraf().Count; x++) { DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell(); cell.ValueType = typeof (int); cell.Value = Convert.ToInt32(graf1.getCoordinates(x,y)); row.Cells.Add(cell); } row.HeaderCell.Value = Convert.ToString(y + 1); dataGridView2.Rows.Add(row); } }