|
@@ -1,13 +1,7 @@
|
|
using Microsoft.Win32;
|
|
using Microsoft.Win32;
|
|
using System;
|
|
using System;
|
|
-using System.Collections.Generic;
|
|
|
|
-using System.Linq;
|
|
|
|
-using System.Text;
|
|
|
|
-using System.Threading.Tasks;
|
|
|
|
using System.Windows;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Controls;
|
|
-using System.Windows.Data;
|
|
|
|
-using System.Windows.Documents;
|
|
|
|
using System.Windows.Input;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Media.Imaging;
|
|
@@ -32,31 +26,78 @@ namespace GraphDrawer
|
|
InitializeComponent();
|
|
InitializeComponent();
|
|
VertexArray.vertexCount = 0;
|
|
VertexArray.vertexCount = 0;
|
|
|
|
|
|
-
|
|
|
|
|
|
+ ClearCanvas();
|
|
if (state)
|
|
if (state)
|
|
{
|
|
{
|
|
|
|
+ MessageBox.Show("asd");
|
|
int length = (int)Math.Sqrt(matrix.Length);
|
|
int length = (int)Math.Sqrt(matrix.Length);
|
|
for(int i = 0; i < length; i++)
|
|
for(int i = 0; i < length; i++)
|
|
VertexArray.AddVertex(canvas, rand.Next(1, 600), rand.Next(1, 300));
|
|
VertexArray.AddVertex(canvas, rand.Next(1, 600), rand.Next(1, 300));
|
|
|
|
|
|
for(int i = 0; i < length; i++)
|
|
for(int i = 0; i < length; i++)
|
|
{
|
|
{
|
|
|
|
+ var vertex1 = VertexArray.vertex[i];
|
|
for(int j = 0; j < length; j++)
|
|
for(int j = 0; j < length; j++)
|
|
{
|
|
{
|
|
|
|
+ var vertex2 = VertexArray.vertex[j];
|
|
|
|
+ if (matrix[i, j] == 1)
|
|
|
|
+ {
|
|
|
|
+ EdgeArray.edgeCount++;
|
|
|
|
+ Array.Resize(ref EdgeArray.edge, EdgeArray.edgeCount);
|
|
|
|
+ Array.Resize(ref EdgeArray.line, EdgeArray.edgeCount);
|
|
|
|
+ EdgeArray.line[EdgeArray.edgeCount - 1] = new Line()
|
|
|
|
+ {
|
|
|
|
+ Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0)),
|
|
|
|
+ StrokeThickness = 2,
|
|
|
|
+ X1 = vertex1.X + 5,
|
|
|
|
+ Y1 = vertex1.Y + 5,
|
|
|
|
+ X2 = vertex2.X + 5,
|
|
|
|
+ Y2 = vertex2.Y + 5
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ canvas.Children.Add(EdgeArray.line[EdgeArray.edgeCount - 1]);
|
|
|
|
+ EdgeArray.edge[EdgeArray.edgeCount - 1] = new Edge(EdgeArray.line[EdgeArray.edgeCount-1], vertex1, vertex2);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ int rows = matrix.GetLength(0);
|
|
|
|
+ int cols = matrix.GetLength(1);
|
|
|
|
+ Vertex buffer = null;
|
|
|
|
+
|
|
|
|
+ for(int i = 0; i < rows; i++)
|
|
|
|
+ {
|
|
|
|
+ VertexArray.AddVertex(canvas, rand.Next(1, 600), rand.Next(1, 300));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for(int j = 0; j < cols; j++)
|
|
|
|
+ {
|
|
|
|
+ for(int i = 0; i < rows; i++)
|
|
|
|
+ {
|
|
if (matrix[i, j] == 1)
|
|
if (matrix[i, j] == 1)
|
|
- EdgeArray.AddEdge(canvas, VertexArray.vertex[i], VertexArray.vertex[j]);
|
|
|
|
|
|
+ {
|
|
|
|
+ if (buffer == null)
|
|
|
|
+ buffer = VertexArray.vertex[i];
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ EdgeArray.AddEdge(canvas, buffer, VertexArray.vertex[i]);
|
|
|
|
+ buffer = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void backBtn_Click(object sender, RoutedEventArgs e) // Выбор режима рисования
|
|
|
|
|
|
+ private void BackBtn_Click(object sender, RoutedEventArgs e) // Выбор режима рисования
|
|
{
|
|
{
|
|
ChoiceMode regime = new ChoiceMode();
|
|
ChoiceMode regime = new ChoiceMode();
|
|
regime.Show();
|
|
regime.Show();
|
|
Close();
|
|
Close();
|
|
}
|
|
}
|
|
- private void canvas_MouseUp(object sender, MouseButtonEventArgs e)
|
|
|
|
|
|
+ private void Canvas_MouseUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
{
|
|
|
|
|
|
var point = e.GetPosition(canvas); // Получение позиции курсора
|
|
var point = e.GetPosition(canvas); // Получение позиции курсора
|
|
@@ -82,11 +123,11 @@ namespace GraphDrawer
|
|
int Y = Convert.ToInt32(point1.Y);
|
|
int Y = Convert.ToInt32(point1.Y);
|
|
for (int i = 0; i <= VertexArray.vertexCount - 1; i++)// Проверка на принадлежность точки к какой-либо вершине
|
|
for (int i = 0; i <= VertexArray.vertexCount - 1; i++)// Проверка на принадлежность точки к какой-либо вершине
|
|
{
|
|
{
|
|
- if (((X - VertexArray.vertex[i].X <= 8) && (X - VertexArray.vertex[i].X >= 0)) ||
|
|
|
|
- ((VertexArray.vertex[i].X - X <= 8) && (VertexArray.vertex[i].X - X >= 0)))
|
|
|
|
|
|
+ if (((X - VertexArray.vertex[i].X <= 15) && (X - VertexArray.vertex[i].X >= 0)) ||
|
|
|
|
+ ((VertexArray.vertex[i].X - X <= 15) && (VertexArray.vertex[i].X - X >= 0)))
|
|
{
|
|
{
|
|
- if (((Y - VertexArray.vertex[i].Y <= 8) && (Y - VertexArray.vertex[i].Y >= 0)) ||
|
|
|
|
- ((VertexArray.vertex[i].Y - Y <= 8) && (VertexArray.vertex[i].Y - Y >= 0)))
|
|
|
|
|
|
+ if (((Y - VertexArray.vertex[i].Y <= 15) && (Y - VertexArray.vertex[i].Y >= 0)) ||
|
|
|
|
+ ((VertexArray.vertex[i].Y - Y <= 15) && (VertexArray.vertex[i].Y - Y >= 0)))
|
|
{
|
|
{
|
|
if (VertexArray.buffer[0] == null)
|
|
if (VertexArray.buffer[0] == null)
|
|
{
|
|
{
|
|
@@ -110,11 +151,11 @@ namespace GraphDrawer
|
|
int Y = Convert.ToInt32(point1.Y);
|
|
int Y = Convert.ToInt32(point1.Y);
|
|
for (int i = 0; i <= VertexArray.vertexCount - 1; i++)// Проверка на принадлежность точки к какой-либо вершине
|
|
for (int i = 0; i <= VertexArray.vertexCount - 1; i++)// Проверка на принадлежность точки к какой-либо вершине
|
|
{
|
|
{
|
|
- if (((X - VertexArray.vertex[i].X <= 8) && (X - VertexArray.vertex[i].X >= 0)) ||
|
|
|
|
- ((VertexArray.vertex[i].X - X <= 8) && (VertexArray.vertex[i].X - X >= 0)))
|
|
|
|
|
|
+ if (((X - VertexArray.vertex[i].X <= 15) && (X - VertexArray.vertex[i].X >= 0)) ||
|
|
|
|
+ ((VertexArray.vertex[i].X - X <= 15) && (VertexArray.vertex[i].X - X >= 0)))
|
|
{
|
|
{
|
|
- if (((Y - VertexArray.vertex[i].Y <= 8) && (Y - VertexArray.vertex[i].Y >= 0)) ||
|
|
|
|
- ((VertexArray.vertex[i].Y - Y <= 8) && (VertexArray.vertex[i].Y - Y >= 0)))
|
|
|
|
|
|
+ if (((Y - VertexArray.vertex[i].Y <= 15) && (Y - VertexArray.vertex[i].Y >= 0)) ||
|
|
|
|
+ ((VertexArray.vertex[i].Y - Y <= 15) && (VertexArray.vertex[i].Y - Y >= 0)))
|
|
{
|
|
{
|
|
if (VertexArray.buffer[0] == null)
|
|
if (VertexArray.buffer[0] == null)
|
|
{
|
|
{
|
|
@@ -136,7 +177,7 @@ namespace GraphDrawer
|
|
|
|
|
|
|
|
|
|
// Получение рандомной кисти из заданных цветов
|
|
// Получение рандомной кисти из заданных цветов
|
|
- Random rand = new Random((DateTime.Now.Millisecond * DateTime.Now.Second) % DateTime.Now.Hour);
|
|
|
|
|
|
+ readonly Random rand = new Random((DateTime.Now.Millisecond * DateTime.Now.Second) % DateTime.Now.Hour);
|
|
public SolidColorBrush GetBrush()
|
|
public SolidColorBrush GetBrush()
|
|
{
|
|
{
|
|
SolidColorBrush[] brush = new SolidColorBrush[10];
|
|
SolidColorBrush[] brush = new SolidColorBrush[10];
|
|
@@ -154,7 +195,12 @@ namespace GraphDrawer
|
|
|
|
|
|
|
|
|
|
// Очистка канваса
|
|
// Очистка канваса
|
|
- private void clearBtn_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
+ private void ClearBtn_Click(object sender, RoutedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ ClearCanvas();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void ClearCanvas()
|
|
{
|
|
{
|
|
canvas.Children.Clear();
|
|
canvas.Children.Clear();
|
|
VertexArray.vertexCount = 0;
|
|
VertexArray.vertexCount = 0;
|
|
@@ -167,17 +213,17 @@ namespace GraphDrawer
|
|
|
|
|
|
|
|
|
|
// Кнопки меню
|
|
// Кнопки меню
|
|
- private void unfocusedGraphBtn_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
+ private void UnfocusedGraphBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
GraphState.focused = false;
|
|
GraphState.focused = false;
|
|
}
|
|
}
|
|
|
|
|
|
- private void focusedGraphBtn_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
+ private void FocusedGraphBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
GraphState.focused = true;
|
|
GraphState.focused = true;
|
|
}
|
|
}
|
|
|
|
|
|
- private void exportPngBtn_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
+ private void ExportPngBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
SaveFileDialog sfg = new SaveFileDialog
|
|
SaveFileDialog sfg = new SaveFileDialog
|
|
{
|
|
{
|
|
@@ -211,7 +257,7 @@ namespace GraphDrawer
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void delEdgeBtn_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
+ private void DelEdgeBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
for(int i = 0; i < EdgeArray.edgeCount; i++)
|
|
for(int i = 0; i < EdgeArray.edgeCount; i++)
|
|
{
|
|
{
|
|
@@ -221,18 +267,18 @@ namespace GraphDrawer
|
|
Array.Clear(EdgeArray.edge, 0, EdgeArray.edge.Length);
|
|
Array.Clear(EdgeArray.edge, 0, EdgeArray.edge.Length);
|
|
}
|
|
}
|
|
|
|
|
|
- private void printBtn_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
+ private void PrintBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
PrintDialog printDialog = new PrintDialog();
|
|
PrintDialog printDialog = new PrintDialog();
|
|
printDialog.PrintVisual(canvas, "Your graph");
|
|
printDialog.PrintVisual(canvas, "Your graph");
|
|
}
|
|
}
|
|
|
|
|
|
- private void namedGraphBtn_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
+ private void NamedGraphBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
GraphState.named = true;
|
|
GraphState.named = true;
|
|
}
|
|
}
|
|
|
|
|
|
- private void unnamedGraphBtn_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
+ private void UnnamedGraphBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
GraphState.named = false;
|
|
GraphState.named = false;
|
|
}
|
|
}
|
|
@@ -322,8 +368,8 @@ namespace GraphDrawer
|
|
vertex[vertexCount-1] = new Vertex(x, y);
|
|
vertex[vertexCount-1] = new Vertex(x, y);
|
|
ellipse[vertexCount - 1] = new Ellipse
|
|
ellipse[vertexCount - 1] = new Ellipse
|
|
{
|
|
{
|
|
- Height = 10,
|
|
|
|
- Width = 10,
|
|
|
|
|
|
+ Height = 20,
|
|
|
|
+ Width = 20,
|
|
StrokeThickness = 2,
|
|
StrokeThickness = 2,
|
|
Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0))
|
|
Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0))
|
|
};
|
|
};
|
|
@@ -341,9 +387,11 @@ namespace GraphDrawer
|
|
Array.Resize(ref ellipse, vertexCount);
|
|
Array.Resize(ref ellipse, vertexCount);
|
|
Array.Resize(ref label, vertexCount);
|
|
Array.Resize(ref label, vertexCount);
|
|
vertex[vertexCount - 1] = new Vertex(x, y);
|
|
vertex[vertexCount - 1] = new Vertex(x, y);
|
|
- label[vertexCount - 1] = new Label();
|
|
|
|
- label[vertexCount - 1].Foreground = new SolidColorBrush(Color.FromRgb(0,0,0));
|
|
|
|
- label[vertexCount - 1].FontSize = 18;
|
|
|
|
|
|
+ label[vertexCount - 1] = new Label
|
|
|
|
+ {
|
|
|
|
+ Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0)),
|
|
|
|
+ FontSize = 18
|
|
|
|
+ };
|
|
ellipse[vertexCount - 1] = new Ellipse
|
|
ellipse[vertexCount - 1] = new Ellipse
|
|
{
|
|
{
|
|
Height = 10,
|
|
Height = 10,
|
|
@@ -380,10 +428,10 @@ namespace GraphDrawer
|
|
edge[edgeCount-1] = new Edge(line[edgeCount-1], v1, v2);
|
|
edge[edgeCount-1] = new Edge(line[edgeCount-1], v1, v2);
|
|
line[edgeCount - 1].Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0));
|
|
line[edgeCount - 1].Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0));
|
|
line[edgeCount - 1].StrokeThickness = 2;
|
|
line[edgeCount - 1].StrokeThickness = 2;
|
|
- line[edgeCount - 1].X1 = v1.X+5;
|
|
|
|
- line[edgeCount - 1].Y1 = v1.Y+5;
|
|
|
|
- line[edgeCount - 1].X2 = v2.X+5;
|
|
|
|
- line[edgeCount - 1].Y2 = v2.Y+5;
|
|
|
|
|
|
+ line[edgeCount - 1].X1 = v1.X+10;
|
|
|
|
+ line[edgeCount - 1].Y1 = v1.Y+10;
|
|
|
|
+ line[edgeCount - 1].X2 = v2.X+10;
|
|
|
|
+ line[edgeCount - 1].Y2 = v2.Y+10;
|
|
canvas.Children.Add(line[edgeCount - 1]);
|
|
canvas.Children.Add(line[edgeCount - 1]);
|
|
}
|
|
}
|
|
}
|
|
}
|