protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; for (i = 0; i < n; i++) { for (j = 0; j < i; j++) { if (matAdj[i, j] != null) { a = matAdj[i, j]; vi = getVertice(i); vj = getVertice(j); e.Graphics.DrawLine(new Pen(a.getCor()), vi.getX() + 5, vi.getY() + 5, vj.getX() + 5, vj.getY() + 5); if (exibirPesos) { tam = (int)e.Graphics.MeasureString(a.getPeso().ToString(), new Font(Font.Name, 10, FontStyle.Regular)).Width; int tam1 = (tam / 2); e.Graphics.FillRectangle(new SolidBrush(Color.Gray), (vi.getX() + vj.getX() + 10) / 2 - tam1, (vi.getY() + vj.getY()) / 2 - 3.5f, tam, 18); e.Graphics.DrawString(a.getPeso().ToString(), new Font(Font.Name, 10, FontStyle.Regular), new SolidBrush(Color.White), (vi.getX() + vj.getX() + 10) / 2 - tam1, (vi.getY() + vj.getY() - 5) / 2); } } } } }
// LARGURA public void largura(int v) { visitado = new bool[getN()]; Fila fila = new Fila(getN()); fila.enfileirar(v); visitado[v] = true; while (!fila.vazia()) { int d = fila.desenfileirar(); for (int i = 0; i < getN(); i++) { for (int j = 0; j < getN(); j++) { Aresta a = getAresta(i, j); if (getN() != 0 && !visitado[i]) { visitado[i] = true; fila.enfileirar(i); getVertice(i).setCor(Color.Yellow); } if (a != null) { a.setCor(Color.Red); } } } } }
public void abrirArquivo(string path) { try { int i, j; string[] p; int ultimo, vx, vy; string nome; StreamReader s = new StreamReader(path); Limpar(); n = int.Parse(s.ReadLine()); ultimo = int.Parse(s.ReadLine()); s.ReadLine(); for (i = 0; i < n; i++) { string[] data = s.ReadLine().Split(' '); vx = int.Parse(data[0]); // coordenada x vy = int.Parse(data[1]); // coordenada y nome = data[2]; AddVertice(i, nome, vx, vy); } s.ReadLine(); s.ReadLine(); for (i = 0; i < n; i++) { s.ReadLine(); } for (i = 1; i < n; i++) { p = s.ReadLine().TrimEnd().Split(' '); for (j = 0; j < i; j++) { int numero = 0; bool resultado = Int32.TryParse(p[j], out numero); if (resultado) { MatAdj[i, j] = MatAdj[j, i] = new Aresta(numero, Color.DarkBlue, this); } else { Console.WriteLine($"A conversão de '{p[j]}' Falhou."); } } } s.Close(); this.Refresh(); } catch (Exception eX) { MessageBox.Show("Erro ao abrir arquivo. " + eX.Message); } }
public void abrirArquivo(string path) { try { int i, j; string[] p; int ultimo, vx, vy; string nome; StreamReader s = new StreamReader(path); limpar(); n = int.Parse(s.ReadLine()); ultimo = int.Parse(s.ReadLine()); s.ReadLine(); for (i = 0; i < n; i++) { string[] data = s.ReadLine().Split(' '); vx = int.Parse(data[0]); // coordenada x vy = int.Parse(data[1]); // coordenada y nome = data[2]; AddVertice(i, nome, vx, vy); } s.ReadLine(); s.ReadLine(); for (i = 0; i < n; i++) { // for(j = 0; j < i; j++) // { //s.nextInt(); s.ReadLine(); // } } for (i = 1; i < n; i++) { p = s.ReadLine().TrimEnd().Split(' '); for (j = 0; j < i; j++) { if (int.Parse(p[j]) > 0) { matAdj[i, j] = matAdj[j, i] = new Aresta(int.Parse(p[j]), Color.Black, this); } } } s.Close(); this.Refresh(); } catch (Exception eX) { MessageBox.Show("Erro ao abrir arquivo. " + eX.Message); } }
public void clicouVertice(Vertice v) { if (v.getMarcado()) { v.desmarcar(); vMarcado = null; } else { v.marcar(); if (vMarcado != null) { int peso; if (getPesosAleatorios()) { peso = (int)(randNum.Next(1, 100)); } else { peso = 1; } Aresta a = new Aresta(peso, Color.Black, this); // cria a nova aresta if (matAdj[vMarcado.getNum(), v.getNum()] == null) { matAdj[vMarcado.getNum(), v.getNum()] = matAdj[v.getNum(), vMarcado.getNum()] = a; vMarcado.desmarcar(); vMarcado = v; } else { a = null; v.desmarcar(); } } else { vMarcado = v; } } Refresh(); }
public void clicouVertice(Vertice v) { if (v.Marcado) { v.Desmarcar(); VMarcado = null; } else { v.Marcar(); if (VMarcado != null) { int peso; if (getPesosAleatorios()) { peso = (int)(randNum.Next(1, 100)); } else { peso = 1; } Aresta a = new Aresta(peso, Color.DarkBlue, this); if (MatAdj[VMarcado.GetNum(), v.GetNum()] == null) { MatAdj[VMarcado.GetNum(), v.GetNum()] = MatAdj[v.GetNum(), VMarcado.GetNum()] = a; VMarcado.Desmarcar(); VMarcado = v; } else { a = null; v.Desmarcar(); } } else { VMarcado = v; } } Refresh(); }
public void setAresta(int i, int j, int peso) { matAdj[i, j] = matAdj[j, i] = new Aresta(peso, Color.Blue, this); Refresh(); }
public void SetAresta(int i, int j, int peso) { MatAdj[i, j] = MatAdj[j, i] = new Aresta(peso, Color.DarkBlue, this); }