private void Routes(List <Vertex> route) { for (int i = 0; i < route.Count; i++) { G.drawVertex(route[i].x, route[i].y, route.Count.ToString()); sheet.Image = G.GetBitmap(); if (i + 1 < route.Count) { E.Add(new Edge(i, i + 1)); G.drawEdge(route[i], route[i + 1], E[E.Count - 1], E.Count - 1); sheet.Image = G.GetBitmap(); } } }
private void DrawFromMatrix_Click(object sender, EventArgs e) { numberOfVertices = Convert.ToInt32(textBox1.Text); int[,] DrawMatrix = new int[numberOfVertices, numberOfVertices]; for (int i = 0; i < numberOfVertices; i++) { for (int j = 0; j < numberOfVertices; j++) { DrawMatrix[i, j] = Convert.ToInt32(dataGridView1.Rows[i].Cells[j].Value); } } int x = 50; int y = 50; Random randomX = new Random(); Random randomY = new Random(); V.Clear(); E.Clear(); G.clearSheet(); for (int i = 0; i < numberOfVertices; i++) { x = randomX.Next(20, 500); y = randomX.Next(20, 500); V.Add(new Vertex(x, y)); G.drawVertex(x, y, V.Count.ToString()); sheet.Image = G.GetBitmap(); } for (int i = 0; i < numberOfVertices; i++) { for (int j = 0; j < numberOfVertices; j++) { if (DrawMatrix[i, j] != 0) { E.Add(new Edge(i, j)); G.drawEdge(V[i], V[j], E[E.Count - 1], E.Count - 1); sheet.Image = G.GetBitmap(); } } } }
private void sheet_MouseClick(object sender, MouseEventArgs e) { //нажата кнопка "выбрать вершину", ищем степень вершины if (selectButton.Enabled == false) { for (int i = 0; i < V.Count; i++) { if (Math.Pow((V[i].x - e.X), 2) + Math.Pow((V[i].y - e.Y), 2) <= G.R * G.R) { if (selected1 != -1) { selected1 = -1; G.clearSheet(); G.drawALLGraph(V, E, W); sheet.Image = G.GetBitmap(); } if (selected1 == -1) { G.drawSelectedVertex(V[i].x, V[i].y); selected1 = i; sheet.Image = G.GetBitmap(); createAdjAndOut(); listBoxMatrix.Items.Clear(); int degree = 0; for (int j = 0; j < V.Count; j++) { degree += AMatrix[selected1, j]; } listBoxMatrix.Items.Add("Степень вершины №" + (selected1 + 1) + " равна " + degree); break; } } } } //нажата кнопка "рисовать вершину" if (drawVertexButton.Enabled == false) { V.Add(new Vertex(e.X, e.Y)); G.drawVertex(e.X, e.Y, V.Count.ToString()); sheet.Image = G.GetBitmap(); } //нажата кнопка "рисовать ребро" if (drawEdgeButton.Enabled == false) { if (e.Button == MouseButtons.Left) { for (int i = 0; i < V.Count; i++) { if (Math.Pow((V[i].x - e.X), 2) + Math.Pow((V[i].y - e.Y), 2) <= G.R * G.R) { if (selected1 == -1) { G.drawSelectedVertex(V[i].x, V[i].y); selected1 = i; sheet.Image = G.GetBitmap(); break; } if (selected2 == -1) { G.drawSelectedVertex(V[i].x, V[i].y); selected2 = i; E.Add(new Edge(selected1, selected2)); Value.Add(textBox1.Text); W.Add(new Weight(selected1, selected2, Value[Value.Count - 1])); G.drawEdge(V[selected1], V[selected2], E[E.Count - 1], E.Count - 1, W[W.Count - 1]); selected1 = -1; selected2 = -1; sheet.Image = G.GetBitmap(); break; } } } } if (e.Button == MouseButtons.Right) { if ((selected1 != -1) && (Math.Pow((V[selected1].x - e.X), 2) + Math.Pow((V[selected1].y - e.Y), 2) <= G.R * G.R)) { G.drawVertex(V[selected1].x, V[selected1].y, (selected1 + 1).ToString()); selected1 = -1; sheet.Image = G.GetBitmap(); } } } //нажата кнопка "удалить элемент" if (deleteButton.Enabled == false) { bool flag = false; //удалили ли что-нибудь по ЭТОМУ клику //ищем, возможно была нажата вершина for (int i = 0; i < V.Count; i++) { if (Math.Pow((V[i].x - e.X), 2) + Math.Pow((V[i].y - e.Y), 2) <= G.R * G.R) { for (int j = 0; j < E.Count; j++) { if ((E[j].v1 == i) || (E[j].v2 == i)) { E.RemoveAt(j); j--; } else { if (E[j].v1 > i) { E[j].v1--; } if (E[j].v2 > i) { E[j].v2--; } } } V.RemoveAt(i); flag = true; break; } } //ищем, возможно было нажато ребро if (!flag) { for (int i = 0; i < E.Count; i++) { if (E[i].v1 == E[i].v2) //если это петля { if ((Math.Pow((V[E[i].v1].x - G.R - e.X), 2) + Math.Pow((V[E[i].v1].y - G.R - e.Y), 2) <= ((G.R + 2) * (G.R + 2))) && (Math.Pow((V[E[i].v1].x - G.R - e.X), 2) + Math.Pow((V[E[i].v1].y - G.R - e.Y), 2) >= ((G.R - 2) * (G.R - 2)))) { E.RemoveAt(i); flag = true; break; } } else //не петля { if (((e.X - V[E[i].v1].x) * (V[E[i].v2].y - V[E[i].v1].y) / (V[E[i].v2].x - V[E[i].v1].x) + V[E[i].v1].y) <= (e.Y + 4) && ((e.X - V[E[i].v1].x) * (V[E[i].v2].y - V[E[i].v1].y) / (V[E[i].v2].x - V[E[i].v1].x) + V[E[i].v1].y) >= (e.Y - 4)) { if ((V[E[i].v1].x <= V[E[i].v2].x && V[E[i].v1].x <= e.X && e.X <= V[E[i].v2].x) || (V[E[i].v1].x >= V[E[i].v2].x && V[E[i].v1].x >= e.X && e.X >= V[E[i].v2].x)) { E.RemoveAt(i); flag = true; break; } } } } } //если что-то было удалено, то обновляем граф на экране if (flag) { G.clearSheet(); G.drawALLGraph(V, E, W); sheet.Image = G.GetBitmap(); } } }
public Form1() { InitializeComponent(); AllRotationsPoints = new List <Point>(); AllRotationsPoints.Add(new Point(204, 438)); AllRotationsPoints.Add(new Point(247, 577)); AllRotationsPoints.Add(new Point(490, 530)); AllRotationsPoints.Add(new Point(574, 708)); AllRotationsPoints.Add(new Point(642, 728)); AllRotationsPoints.Add(new Point(739, 658)); AllRotationsPoints.Add(new Point(854, 794)); AllRotationsPoints.Add(new Point(1063, 633)); AllRotationsPoints.Add(new Point(1043, 575)); AllRotationsPoints.Add(new Point(1036, 541)); AllRotationsPoints.Add(new Point(931, 390)); AllRotationsPoints.Add(new Point(1029, 320)); AllRotationsPoints.Add(new Point(974, 247)); AllRotationsPoints.Add(new Point(878, 311)); AllRotationsPoints.Add(new Point(848, 277)); AllRotationsPoints.Add(new Point(680, 268)); AllRotationsPoints.Add(new Point(684, 69)); AllRotationsPoints.Add(new Point(797, 68)); AllRotationsPoints.Add(new Point(847, 121)); AllRotationsPoints.Add(new Point(1032, 2)); AllRotationsPoints.Add(new Point(1109, 12)); AllRotationsPoints.Add(new Point(213, 484)); AllRotationsPoints.Add(new Point(167, 513)); AllRotationsPoints.Add(new Point(179, 563)); AllRotationsPoints.Add(new Point(163, 579)); AllRotationsPoints.Add(new Point(164, 620)); AllRotationsPoints.Add(new Point(0, 642)); AllRotationsPoints.Add(new Point(888, 278)); AllRotationsPoints.Add(new Point(890, 187)); AllRotationsPoints.Add(new Point(373, 377)); AllRotationsPoints.Add(new Point(400, 375)); AllRotationsPoints.Add(new Point(565, 276)); AllRotationsPoints.Add(new Point(1034, 187)); //// AllRotationsPoints.Add(new Point(1515, 547)); AllRotationsPoints.Add(new Point(1452, 567)); AllRotationsPoints.Add(new Point(1411, 573)); AllRotationsPoints.Add(new Point(1341, 609)); AllRotationsPoints.Add(new Point(1175, 606)); AllRotationsPoints.Add(new Point(1151, 507)); AllRotationsPoints.Add(new Point(1079, 544)); //AllRotationsPoints.Add(new Point(1036, 541)); AllRotationsPoints.Add(new Point(869, 312)); AllRotationsPoints.Add(new Point(828, 342)); AllRotationsPoints.Add(new Point(805, 448)); AllRotationsPoints.Add(new Point(804, 565)); AllRotationsPoints.Add(new Point(814, 608)); AllRotationsPoints.Add(new Point(912, 736)); AllRotationsPoints.Add(new Point(728, 871)); route7 = new List <Vertex>(); route7.Add(new Vertex(AllRotationsPoints[0].X, AllRotationsPoints[0].Y)); route7.Add(new Vertex(AllRotationsPoints[1].X, AllRotationsPoints[1].Y)); route7.Add(new Vertex(AllRotationsPoints[2].X, AllRotationsPoints[2].Y)); route7.Add(new Vertex(AllRotationsPoints[3].X, AllRotationsPoints[3].Y)); route7.Add(new Vertex(AllRotationsPoints[4].X, AllRotationsPoints[4].Y)); route7.Add(new Vertex(AllRotationsPoints[5].X, AllRotationsPoints[5].Y)); route7.Add(new Vertex(AllRotationsPoints[6].X, AllRotationsPoints[6].Y)); route7.Add(new Vertex(AllRotationsPoints[7].X, AllRotationsPoints[7].Y)); route7.Add(new Vertex(AllRotationsPoints[8].X, AllRotationsPoints[8].Y)); route7.Add(new Vertex(AllRotationsPoints[9].X, AllRotationsPoints[9].Y)); route7.Add(new Vertex(AllRotationsPoints[10].X, AllRotationsPoints[10].Y)); route7.Add(new Vertex(AllRotationsPoints[11].X, AllRotationsPoints[11].Y)); route7.Add(new Vertex(AllRotationsPoints[12].X, AllRotationsPoints[12].Y)); route7.Add(new Vertex(AllRotationsPoints[13].X, AllRotationsPoints[13].Y)); route7.Add(new Vertex(AllRotationsPoints[14].X, AllRotationsPoints[14].Y)); route7.Add(new Vertex(AllRotationsPoints[15].X, AllRotationsPoints[15].Y)); route7.Add(new Vertex(AllRotationsPoints[16].X, AllRotationsPoints[16].Y)); route7.Add(new Vertex(AllRotationsPoints[17].X, AllRotationsPoints[17].Y)); route7.Add(new Vertex(AllRotationsPoints[18].X, AllRotationsPoints[18].Y)); route7.Add(new Vertex(AllRotationsPoints[19].X, AllRotationsPoints[19].Y)); route7.Add(new Vertex(AllRotationsPoints[20].X, AllRotationsPoints[20].Y)); route62 = new List <Vertex>(); route62.Add(CallRotationPoint(AllRotationsPoints, 1034, 187)); route62.Add(CallRotationPoint(AllRotationsPoints, 890, 187)); route62.Add(CallRotationPoint(AllRotationsPoints, 888, 278)); route62.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(565, 276))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(565, 276))].Y)); route62.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(400, 375))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(400, 375))].Y)); route62.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(373, 377))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(373, 377))].Y)); route62.Add(new Vertex(AllRotationsPoints[0].X, AllRotationsPoints[0].Y)); route62.Add(route7[1]); route62.Add(route7[2]); route62.Add(route7[3]); route62.Add(route7[4]); route62.Add(route7[5]); route62.Add(route7[6]); route62.Add(route7[7]); route62.Add(route7[8]); route62.Add(route7[9]); route62.Add(route7[14]); route62.Add(CallRotationPoint(AllRotationsPoints, 888, 278)); route62.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(890, 187))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(890, 187))].Y)); route62.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1034, 187))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1034, 187))].Y)); route23 = new List <Vertex>(); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(0, 642))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(0, 642))].Y)); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(164, 620))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(164, 620))].Y)); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(163, 579))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(163, 579))].Y)); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(179, 563))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(179, 563))].Y)); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(167, 513))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(167, 513))].Y)); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(213, 484))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(213, 484))].Y)); route23.Add(route7[1]); route23.Add(route7[2]); route23.Add(route7[3]); route23.Add(route7[4]); route23.Add(route7[5]); route23.Add(route7[6]); route23.Add(route7[7]); route23.Add(route7[8]); route23.Add(route7[9]); route23.Add(route7[14]); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(888, 278))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(888, 278))].Y)); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(890, 187))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(890, 187))].Y)); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1034, 187))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1034, 187))].Y)); route404 = new List <Vertex>(); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1515, 547))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1515, 547))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1452, 567))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1452, 567))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1411, 573))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1411, 573))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1341, 609))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1341, 609))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1175, 606))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1175, 606))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1151, 507))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1151, 507))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1079, 544))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1079, 544))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1036, 541))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1036, 541))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(869, 312))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(869, 312))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(828, 342))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(828, 342))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(805, 448))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(805, 448))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(804, 565))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(804, 565))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(814, 608))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(814, 608))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(912, 736))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(912, 736))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(728, 871))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(728, 871))].Y)); G = new DrawGraph(sheet.Width, sheet.Height); E = new List <Edge>(); for (int i = 0; i < route62.Count; i++) { G.drawVertex(route62[i].x, route62[i].y, route62.Count.ToString()); sheet.Image = G.GetBitmap(); if (i + 1 < route62.Count) { E.Add(new Edge(i, i + 1)); G.drawEdge(route62[i], route62[i + 1], E[E.Count - 1], E.Count - 1); sheet.Image = G.GetBitmap(); } } for (int i = 0; i < route7.Count; i++) { G.drawVertex(route7[i].x, route7[i].y, route7.Count.ToString()); sheet.Image = G.GetBitmap(); if (i + 1 < route7.Count) { E.Add(new Edge(i, i + 1)); G.drawEdge(route7[i], route7[i + 1], E[E.Count - 1], E.Count - 1); sheet.Image = G.GetBitmap(); } } for (int i = 0; i < route23.Count; i++) { G.drawVertex(route23[i].x, route23[i].y, route23.Count.ToString()); sheet.Image = G.GetBitmap(); if (i + 1 < route23.Count) { E.Add(new Edge(i, i + 1)); G.drawEdge(route23[i], route23[i + 1], E[E.Count - 1], E.Count - 1); sheet.Image = G.GetBitmap(); } } Bus7_1 = new BusPark(route7, pictureBus7_1, 0); Bus7_2 = new BusPark(route7, pictureBox7_3, 10); Bus7_3 = new BusPark(route7, pictureBus7_2, 20); Bus23_1 = new BusPark(route23, pictureBus23_1, 5); Bus23_2 = new BusPark(route23, pictureBus23_2, 14); Bus62_1 = new BusPark(route62, pictureBus62_1, 1); Bus404_1 = new BusPark(route404, pictureBus404_1, 1); Bus404_2 = new BusPark(route404, pictureBus404_2, route404.Count - 1); timer1.Interval = 1; timer1.Start(); }
private void sheet2_MouseClick(object sender, MouseEventArgs e) { //нажата кнопка "выбрать вершину", ищем степень вершины if (selectButton.Enabled == false) { foreach (int i in V2.Keys) { if (Math.Pow((V2[i].x - e.X), 2) + Math.Pow((V2[i].y - e.Y), 2) <= G2.R * G2.R) { if (selected_B1 != -1) { selected_B1 = -1; G2.clearSheet(); G2.drawALLGraph(V2, E2); sheet2.Image = G2.GetBitmap(); } if (selected_B1 == -1) { G2.drawSelectedVertex(V2[i].x, V2[i].y); selected_B1 = i; sheet2.Image = G2.GetBitmap(); listBox.Items.Clear(); int degree = 0; foreach (var para in E2) { if ((para.v1 == selected_B1) || (para.v2 == selected_B1)) { degree += 1; } } listBox.Items.Add("Степень вершины №" + (selected_B1 + 1) + " равна " + degree); break; } } } } //нажата кнопка "рисовать вершину" if (drawVertexButton.Enabled == false) { V2.Add(CountV2, new Vertex(e.X, e.Y)); G2.drawVertex(e.X, e.Y, CountV2.ToString()); sheet2.Image = G2.GetBitmap(); CountV2++; } //нажата кнопка "рисовать ребро" if (drawEdgeButton.Enabled == false) { if (e.Button == MouseButtons.Left) { foreach (int i in V2.Keys) { if (Math.Pow((V2[i].x - e.X), 2) + Math.Pow((V2[i].y - e.Y), 2) <= G2.R * G2.R) { if (selected_B1 == -1) { G2.drawSelectedVertex(V2[i].x, V2[i].y); selected_B1 = i; sheet2.Image = G2.GetBitmap(); break; } if (selected_B2 == -1) { G2.drawSelectedVertex(V2[i].x, V2[i].y); selected_B2 = i; E2.Add(new Edge(selected_B1, selected_B2, E2.Count)); G2.drawEdge(V2[selected_B1], V2[selected_B2], E2[E2.Count - 1]); selected_B1 = -1; selected_B2 = -1; sheet2.Image = G2.GetBitmap(); break; } } } } if (e.Button == MouseButtons.Right) { if ((selected_B1 != -1) && (Math.Pow((V2[selected_B1].x - e.X), 2) + Math.Pow((V2[selected_B1].y - e.Y), 2) <= G2.R * G2.R)) { G2.drawVertex(V2[selected_B1].x, V2[selected_B1].y, (selected_B1 + 1).ToString()); selected_B1 = -1; sheet2.Image = G2.GetBitmap(); } } } //нажата кнопка "удалить элемент" if (deleteButton.Enabled == false) { bool flag = false; //удалили ли что-нибудь по ЭТОМУ клику //ищем, возможно была нажата вершина foreach (int i in V2.Keys) { if (Math.Pow((V2[i].x - e.X), 2) + Math.Pow((V2[i].y - e.Y), 2) <= G2.R * G2.R) { for (int j = 0; j < E2.Count; j++) { if ((E2[j].v1 == i) || (E2[j].v2 == i)) { E2.RemoveAt(j); j--; } } V2.Remove(i); flag = true; break; } } //ищем, возможно было нажато ребро if (!flag) { for (int i = 0; i < E2.Count; i++) { if (E2[i].v1 == E2[i].v2) //если это петля { if ((Math.Pow((V2[E2[i].v1].x - G2.R - e.X), 2) + Math.Pow((V2[E2[i].v1].y - G2.R - e.Y), 2) <= ((G2.R + 2) * (G2.R + 2))) && (Math.Pow((V2[E2[i].v1].x - G2.R - e.X), 2) + Math.Pow((V2[E2[i].v1].y - G2.R - e.Y), 2) >= ((G2.R - 2) * (G2.R - 2)))) { E2.RemoveAt(i); flag = true; break; } } else //не петля { if (((e.X - V2[E2[i].v1].x) * (V2[E2[i].v2].y - V2[E2[i].v1].y) / (V2[E2[i].v2].x - V2[E2[i].v1].x) + V2[E2[i].v1].y) <= (e.Y + 4) && ((e.X - V2[E2[i].v1].x) * (V2[E2[i].v2].y - V2[E2[i].v1].y) / (V2[E2[i].v2].x - V2[E2[i].v1].x) + V2[E2[i].v1].y) >= (e.Y - 4)) { if ((V2[E2[i].v1].x <= V2[E2[i].v2].x && V2[E2[i].v1].x <= e.X && e.X <= V2[E2[i].v2].x) || (V2[E2[i].v1].x >= V2[E2[i].v2].x && V2[E2[i].v1].x >= e.X && e.X >= V2[E2[i].v2].x)) { E2.RemoveAt(i); flag = true; break; } } } } } //если что-то было удалено, то обновляем граф на экране if (flag) { G2.clearSheet(); G2.drawALLGraph(V2, E2); sheet2.Image = G2.GetBitmap(); } } }
private void sheet_MouseClick(object sender, MouseEventArgs e) { //если нажата кнопка "выбрать вершину", ищем степень вершины if (selectButton.Enabled == false) { /* for (int i = 0; i < V.Count; i++) * { * if (Math.Pow((V[i].x - e.X), 2) + Math.Pow((V[i].y - e.Y), 2) <= G.R * G.R) * { * if (isClick) * { * G.drawVertex(e.X, e.Y, V[i].ToString()); * sheet.Image = G.GetBitmap(); * //V[i].x = e.X - V[i].x; * // V[i].y = e.Y - V[i].y; * } * * } * }*/ } // если нажата кнопка "рисовать вершину" if (drawVertexButton.Enabled == false) { V.Add(new Vertex(e.X, e.Y)); G.drawVertex(e.X, e.Y, V.Count.ToString()); sheet.Image = G.GetBitmap(); } //если нажата кнопка "рисовать ребро" if (drawEdgeButton.Enabled == false) { if (e.Button == MouseButtons.Left) { for (int i = 0; i < V.Count; i++) { if (Math.Pow((V[i].x - e.X), 2) + Math.Pow((V[i].y - e.Y), 2) <= G.R * G.R) { if (selected1 == -1) { G.drawSelectedVertex(V[i].x, V[i].y); selected1 = i; sheet.Image = G.GetBitmap(); break; } if (selected2 == -1) { G.drawSelectedVertex(V[i].x, V[i].y); selected2 = i; E.Add(new Edge(selected1, selected2)); G.drawEdge(V[selected1], V[selected2], E[E.Count - 1]); selected1 = -1; selected2 = -1; sheet.Image = G.GetBitmap(); break; } } } } if (e.Button == MouseButtons.Right) { if ((selected1 != -1) && (Math.Pow((V[selected1].x - e.X), 2) + Math.Pow((V[selected1].y - e.Y), 2) <= G.R * G.R)) { G.drawVertex(V[selected1].x, V[selected1].y, (selected1 + 1).ToString()); selected1 = -1; sheet.Image = G.GetBitmap(); } } } //если нажата кнопка "удалить элемент" if (deleteButton.Enabled == false) { bool flag = false; //удалили ли что-нибудь по ЭТОМУ клику //ищем, возможно была нажата вершина for (int i = 0; i < V.Count; i++) { if (Math.Pow((V[i].x - e.X), 2) + Math.Pow((V[i].y - e.Y), 2) <= G.R * G.R) { for (int j = 0; j < E.Count; j++) { if ((E[j].v1 == i) || (E[j].v2 == i)) { E.RemoveAt(j); j--; } else { if (E[j].v1 > i) { E[j].v1--; } if (E[j].v2 > i) { E[j].v2--; } } } V.RemoveAt(i); flag = true; break; } } // ищем, возможно было нажато ребро if (!flag) { for (int i = 0; i < E.Count; i++) { if (E[i].v1 == E[i].v2) //если это петля { if ((Math.Pow((V[E[i].v1].x - G.R - e.X), 2) + Math.Pow((V[E[i].v1].y - G.R - e.Y), 2) <= ((G.R + 2) * (G.R + 2))) && (Math.Pow((V[E[i].v1].x - G.R - e.X), 2) + Math.Pow((V[E[i].v1].y - G.R - e.Y), 2) >= ((G.R - 2) * (G.R - 2)))) { E.RemoveAt(i); G.DelWT(i); flag = true; break; } } else //не петля { if (((e.X - V[E[i].v1].x) * (V[E[i].v2].y - V[E[i].v1].y) / (V[E[i].v2].x - V[E[i].v1].x) + V[E[i].v1].y) <= (e.Y + 4) && ((e.X - V[E[i].v1].x) * (V[E[i].v2].y - V[E[i].v1].y) / (V[E[i].v2].x - V[E[i].v1].x) + V[E[i].v1].y) >= (e.Y - 4)) { if ((V[E[i].v1].x <= V[E[i].v2].x && V[E[i].v1].x <= e.X && e.X <= V[E[i].v2].x) || (V[E[i].v1].x >= V[E[i].v2].x && V[E[i].v1].x >= e.X && e.X >= V[E[i].v2].x)) { G.DelWT(i); E.RemoveAt(i); flag = true; break; } } } } } //если что-то было удалено, то обновляем граф на экране if (flag) { G.clearOne(); G.drawALLGraph(V, E); sheet.Image = G.GetBitmap(); } } }
public Form1() { InitializeComponent(); AllRotationsPoints = new List <Point>(); AllRotationsPoints.Add(new Point(204, 438)); AllRotationsPoints.Add(new Point(247, 577)); AllRotationsPoints.Add(new Point(490, 530)); AllRotationsPoints.Add(new Point(574, 708)); AllRotationsPoints.Add(new Point(642, 728)); AllRotationsPoints.Add(new Point(739, 658)); AllRotationsPoints.Add(new Point(854, 794)); AllRotationsPoints.Add(new Point(1063, 633)); AllRotationsPoints.Add(new Point(1043, 575)); AllRotationsPoints.Add(new Point(1036, 541)); AllRotationsPoints.Add(new Point(931, 390)); AllRotationsPoints.Add(new Point(1029, 320)); AllRotationsPoints.Add(new Point(974, 247)); AllRotationsPoints.Add(new Point(878, 311)); AllRotationsPoints.Add(new Point(848, 277)); AllRotationsPoints.Add(new Point(680, 268)); AllRotationsPoints.Add(new Point(684, 69)); AllRotationsPoints.Add(new Point(797, 68)); AllRotationsPoints.Add(new Point(847, 121)); AllRotationsPoints.Add(new Point(1032, 2)); AllRotationsPoints.Add(new Point(1109, 12)); AllRotationsPoints.Add(new Point(213, 484)); AllRotationsPoints.Add(new Point(167, 513)); AllRotationsPoints.Add(new Point(179, 563)); AllRotationsPoints.Add(new Point(163, 579)); AllRotationsPoints.Add(new Point(164, 620)); AllRotationsPoints.Add(new Point(0, 642)); AllRotationsPoints.Add(new Point(888, 278)); AllRotationsPoints.Add(new Point(890, 187)); AllRotationsPoints.Add(new Point(373, 377)); AllRotationsPoints.Add(new Point(400, 375)); AllRotationsPoints.Add(new Point(565, 276)); AllRotationsPoints.Add(new Point(1034, 187)); //// AllRotationsPoints.Add(new Point(1515, 547)); AllRotationsPoints.Add(new Point(1452, 567)); AllRotationsPoints.Add(new Point(1411, 573)); AllRotationsPoints.Add(new Point(1341, 609)); AllRotationsPoints.Add(new Point(1175, 606)); AllRotationsPoints.Add(new Point(1151, 507)); AllRotationsPoints.Add(new Point(1079, 544)); //AllRotationsPoints.Add(new Point(1036, 541)); AllRotationsPoints.Add(new Point(869, 312)); AllRotationsPoints.Add(new Point(828, 342)); AllRotationsPoints.Add(new Point(805, 448)); AllRotationsPoints.Add(new Point(804, 565)); AllRotationsPoints.Add(new Point(814, 608)); AllRotationsPoints.Add(new Point(912, 736)); AllRotationsPoints.Add(new Point(728, 871)); route7 = new List <Vertex>(); route7.Add(new Vertex(AllRotationsPoints[0].X, AllRotationsPoints[0].Y)); route7.Add(new Vertex(AllRotationsPoints[1].X, AllRotationsPoints[1].Y)); route7.Add(new Vertex(AllRotationsPoints[2].X, AllRotationsPoints[2].Y)); route7.Add(new Vertex(AllRotationsPoints[3].X, AllRotationsPoints[3].Y)); route7.Add(new Vertex(AllRotationsPoints[4].X, AllRotationsPoints[4].Y)); route7.Add(new Vertex(AllRotationsPoints[5].X, AllRotationsPoints[5].Y)); route7.Add(new Vertex(AllRotationsPoints[6].X, AllRotationsPoints[6].Y)); route7.Add(new Vertex(AllRotationsPoints[7].X, AllRotationsPoints[7].Y)); route7.Add(new Vertex(AllRotationsPoints[8].X, AllRotationsPoints[8].Y)); route7.Add(new Vertex(AllRotationsPoints[9].X, AllRotationsPoints[9].Y)); route7.Add(new Vertex(AllRotationsPoints[10].X, AllRotationsPoints[10].Y)); route7.Add(new Vertex(AllRotationsPoints[11].X, AllRotationsPoints[11].Y)); route7.Add(new Vertex(AllRotationsPoints[12].X, AllRotationsPoints[12].Y)); route7.Add(new Vertex(AllRotationsPoints[13].X, AllRotationsPoints[13].Y)); route7.Add(new Vertex(AllRotationsPoints[14].X, AllRotationsPoints[14].Y)); route7.Add(new Vertex(AllRotationsPoints[15].X, AllRotationsPoints[15].Y)); route7.Add(new Vertex(AllRotationsPoints[16].X, AllRotationsPoints[16].Y)); route7.Add(new Vertex(AllRotationsPoints[17].X, AllRotationsPoints[17].Y)); route7.Add(new Vertex(AllRotationsPoints[18].X, AllRotationsPoints[18].Y)); route7.Add(new Vertex(AllRotationsPoints[19].X, AllRotationsPoints[19].Y)); route7.Add(new Vertex(AllRotationsPoints[20].X, AllRotationsPoints[20].Y)); route62 = new List <Vertex>(); route62.Add(CallRotationPoint(AllRotationsPoints, 1034, 187)); route62.Add(CallRotationPoint(AllRotationsPoints, 890, 187)); route62.Add(CallRotationPoint(AllRotationsPoints, 888, 278)); route62.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(565, 276))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(565, 276))].Y)); route62.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(400, 375))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(400, 375))].Y)); route62.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(373, 377))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(373, 377))].Y)); route62.Add(new Vertex(AllRotationsPoints[0].X, AllRotationsPoints[0].Y)); route62.Add(route7[1]); route62.Add(route7[2]); route62.Add(route7[3]); route62.Add(route7[4]); route62.Add(route7[5]); route62.Add(route7[6]); route62.Add(route7[7]); route62.Add(route7[8]); route62.Add(route7[9]); route62.Add(route7[14]); route62.Add(CallRotationPoint(AllRotationsPoints, 888, 278)); route62.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(890, 187))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(890, 187))].Y)); route62.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1034, 187))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1034, 187))].Y)); route23 = new List <Vertex>(); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(0, 642))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(0, 642))].Y)); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(164, 620))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(164, 620))].Y)); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(163, 579))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(163, 579))].Y)); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(179, 563))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(179, 563))].Y)); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(167, 513))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(167, 513))].Y)); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(213, 484))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(213, 484))].Y)); route23.Add(route7[1]); route23.Add(route7[2]); route23.Add(route7[3]); route23.Add(route7[4]); route23.Add(route7[5]); route23.Add(route7[6]); route23.Add(route7[7]); route23.Add(route7[8]); route23.Add(route7[9]); route23.Add(route7[14]); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(888, 278))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(888, 278))].Y)); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(890, 187))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(890, 187))].Y)); route23.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1034, 187))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1034, 187))].Y)); route404 = new List <Vertex>(); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1515, 547))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1515, 547))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1452, 567))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1452, 567))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1411, 573))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1411, 573))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1341, 609))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1341, 609))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1175, 606))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1175, 606))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1151, 507))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1151, 507))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1079, 544))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1079, 544))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1036, 541))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(1036, 541))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(869, 312))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(869, 312))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(828, 342))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(828, 342))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(805, 448))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(805, 448))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(804, 565))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(804, 565))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(814, 608))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(814, 608))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(912, 736))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(912, 736))].Y)); route404.Add(new Vertex(AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(728, 871))].X, AllRotationsPoints[AllRotationsPoints.IndexOf(new Point(728, 871))].Y)); G = new DrawGraph(sheet.Width, sheet.Height); E = new List <Edge>(); for (int i = 0; i < route62.Count; i++) { G.drawVertex(route62[i].x, route62[i].y, route62.Count.ToString()); sheet.Image = G.GetBitmap(); if (i + 1 < route62.Count) { E.Add(new Edge(i, i + 1)); G.drawEdge(route62[i], route62[i + 1], E[E.Count - 1], E.Count - 1); sheet.Image = G.GetBitmap(); } } for (int i = 0; i < route7.Count; i++) { G.drawVertex(route7[i].x, route7[i].y, route7.Count.ToString()); sheet.Image = G.GetBitmap(); if (i + 1 < route7.Count) { E.Add(new Edge(i, i + 1)); G.drawEdge(route7[i], route7[i + 1], E[E.Count - 1], E.Count - 1); sheet.Image = G.GetBitmap(); } } for (int i = 0; i < route23.Count; i++) { G.drawVertex(route23[i].x, route23[i].y, route23.Count.ToString()); sheet.Image = G.GetBitmap(); if (i + 1 < route23.Count) { E.Add(new Edge(i, i + 1)); G.drawEdge(route23[i], route23[i + 1], E[E.Count - 1], E.Count - 1); sheet.Image = G.GetBitmap(); } } testim = new List <Epicenters>(); testim.Add(new Epicenters(pictureBox5, 500, 500, 100)); testim.Add(new Epicenters(pictureBox5, 900, 400, 50)); Bus7_1 = new BusPark(route7, pictureBus7_1, 0, testim, pictureBox5); Bus7_2 = new BusPark(route7, pictureBox7_3, 10, testim, pictureBox5); Bus7_3 = new BusPark(route7, pictureBus7_2, 20, testim, pictureBox5); Bus7_4 = new BusPark(route7, pictureBox1, 1, testim, pictureBox5); Bus7_5 = new BusPark(route7, pictureBox2, 3, true, testim, pictureBox5); Bus7_6 = new BusPark(route7, pictureBox3, 5, testim, pictureBox5); Bus7_7 = new BusPark(route7, pictureBox4, 7, testim, pictureBox5); Bus7_8 = new BusPark(route7, pictureBox6, 9, true, testim, pictureBox5); Bus7_9 = new BusPark(route7, pictureBox8, 16, testim, pictureBox5); Bus7_10 = new BusPark(route7, pictureBox9, 13, testim, pictureBox5); Bus7_11 = new BusPark(route7, pictureBox10, 14, testim, pictureBox5); Bus7_12 = new BusPark(route7, pictureBox11, 16, true, testim, pictureBox5); Bus7_13 = new BusPark(route7, pictureBox12, 18, testim, pictureBox5); Bus7_14 = new BusPark(route7, pictureBox13, 20, testim, pictureBox5); Bus7_15 = new BusPark(route7, pictureBox14, 6, testim, pictureBox5); Bus7_16 = new BusPark(route7, pictureBox7, 10, true, testim, pictureBox5); Bus23_1 = new BusPark(route23, pictureBus23_1, 5, testim, pictureBox5); Bus23_2 = new BusPark(route23, pictureBus23_2, 14, testim, pictureBox5); Bus62_1 = new BusPark(route62, pictureBus62_1, 1, testim, pictureBox5); Bus404_1 = new BusPark(route404, pictureBus404_1, 1, testim, pictureBox5); Bus404_2 = new BusPark(route404, pictureBus404_2, route404.Count - 1, testim, pictureBox5); // pictureBox5.CreateGraphics().FillEllipse(new LinearGradientBrush(new Point(0, 10), new Point(200, 10), Color.FromArgb(255, 255, 0, 0), Color.FromArgb(255, 0, 0, 255)), 0, 30, 200, 100); timer1.Interval = 1; timer1.Start(); }