Procházet zdrojové kódy

Add project files.

Anton před 5 roky
rodič
revize
c32c3ba6fa

+ 25 - 0
DrawGraph.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29403.142
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrawGraph", "DrawGraph\DrawGraph.csproj", "{DA67A8A4-157B-4D45-9835-C4EA9D623D5B}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{DA67A8A4-157B-4D45-9835-C4EA9D623D5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{DA67A8A4-157B-4D45-9835-C4EA9D623D5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{DA67A8A4-157B-4D45-9835-C4EA9D623D5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{DA67A8A4-157B-4D45-9835-C4EA9D623D5B}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {15B7322F-40DD-447C-B475-4AC5B3C79969}
+	EndGlobalSection
+EndGlobal

+ 60 - 0
DrawGraph/Algorithms.cs

@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DrawGraph
+{
+    public class Algorithms
+    {
+        public static int MinDistance(int[] path, bool[] includedToPath, int n)
+        {
+            // Initialize min value 
+            int min = int.MaxValue, min_index = -1;
+
+            for (int v = 0; v < n; v++)
+                if (includedToPath[v] == false && path[v] <= min)
+                {
+                    min = path[v];
+                    min_index = v;
+                }
+
+            return min_index;
+        }
+
+        public static int DijkstraCount(int[,] adjacencyMatrix, int startIndex, int finishIndex)
+        {
+            int n = adjacencyMatrix.GetLength(0);
+            int[] path = new int[n];
+
+            bool[] includedToShortestPath = new bool[n];
+
+            for (int i = 0; i < n; i++)
+            {
+                path[i] = int.MaxValue;
+                includedToShortestPath[i] = false;
+            }
+
+            path[startIndex] = 0;
+
+            for (int i = 0; i < n - 1; i++)
+            {
+                int min = MinDistance(path, includedToShortestPath, n);
+
+                includedToShortestPath[min] = true;
+
+                for (int j = 0; j < n; j++)
+                {
+                    if (!includedToShortestPath[j] && adjacencyMatrix[min, j] != 0 &&
+                        path[min] + adjacencyMatrix[min, j] < path[j])
+                    {
+                        path[j] = path[min] + adjacencyMatrix[min, j];
+                    }
+                }
+            }
+
+            return path[finishIndex];
+        }
+    }
+}

+ 104 - 0
DrawGraph/ArrowLine.cs

@@ -0,0 +1,104 @@
+//------------------------------------------
+// ArrowLine.cs (c) 2007 by Charles Petzold
+//------------------------------------------
+using System.Windows;
+using System.Windows.Media;
+
+namespace DrawGraph
+{
+    public class ArrowLine : ArrowLineBase
+    {
+        /// <summary>
+        ///     Identifies the X1 dependency property.
+        /// </summary>
+        public static readonly DependencyProperty X1Property =
+            DependencyProperty.Register("X1",
+                typeof(double), typeof(ArrowLine),
+                new FrameworkPropertyMetadata(0.0,
+                        FrameworkPropertyMetadataOptions.AffectsMeasure));
+
+        /// <summary>
+        ///     Gets or sets the x-coordinate of the ArrowLine start point.
+        /// </summary>
+        public double X1
+        {
+            set { SetValue(X1Property, value); }
+            get { return (double)GetValue(X1Property); }
+        }
+
+        /// <summary>
+        ///     Identifies the Y1 dependency property.
+        /// </summary>
+        public static readonly DependencyProperty Y1Property =
+            DependencyProperty.Register("Y1",
+                typeof(double), typeof(ArrowLine),
+                new FrameworkPropertyMetadata(0.0,
+                        FrameworkPropertyMetadataOptions.AffectsMeasure));
+
+        /// <summary>
+        ///     Gets or sets the y-coordinate of the ArrowLine start point.
+        /// </summary>
+        public double Y1
+        {
+            set { SetValue(Y1Property, value); }
+            get { return (double)GetValue(Y1Property); }
+        }
+
+        /// <summary>
+        ///     Identifies the X2 dependency property.
+        /// </summary>
+        public static readonly DependencyProperty X2Property =
+            DependencyProperty.Register("X2",
+                typeof(double), typeof(ArrowLine),
+                new FrameworkPropertyMetadata(0.0,
+                        FrameworkPropertyMetadataOptions.AffectsMeasure));
+
+        /// <summary>
+        ///     Gets or sets the x-coordinate of the ArrowLine end point.
+        /// </summary>
+        public double X2
+        {
+            set { SetValue(X2Property, value); }
+            get { return (double)GetValue(X2Property); }
+        }
+
+        /// <summary>
+        ///     Identifies the Y2 dependency property.
+        /// </summary>
+        public static readonly DependencyProperty Y2Property =
+            DependencyProperty.Register("Y2",
+                typeof(double), typeof(ArrowLine),
+                new FrameworkPropertyMetadata(0.0,
+                        FrameworkPropertyMetadataOptions.AffectsMeasure));
+
+        /// <summary>
+        ///     Gets or sets the y-coordinate of the ArrowLine end point.
+        /// </summary>
+        public double Y2
+        {
+            set { SetValue(Y2Property, value); }
+            get { return (double)GetValue(Y2Property); }
+        }
+
+        /// <summary>
+        ///     Gets a value that represents the Geometry of the ArrowLine.
+        /// </summary>
+        protected override Geometry DefiningGeometry
+        {
+            get
+            {
+                // Clear out the PathGeometry.
+                pathgeo.Figures.Clear();
+
+                // Define a single PathFigure with the points.
+                pathfigLine.StartPoint = new Point(X1, Y1);
+                polysegLine.Points.Clear();
+                polysegLine.Points.Add(new Point(X2, Y2));
+                pathgeo.Figures.Add(pathfigLine);
+
+                // Call the base property to add arrows on the ends.
+                return base.DefiningGeometry;
+            }
+        }
+    }
+}

+ 176 - 0
DrawGraph/ArrowLineBase.cs

@@ -0,0 +1,176 @@
+//----------------------------------------------
+// ArrowLineBase.cs (c) 2007 by Charles Petzold
+//----------------------------------------------
+using System;
+using System.Windows;
+using System.Windows.Media;
+using System.Windows.Shapes;
+
+namespace DrawGraph
+{
+    public enum ArrowEnds
+    {
+        None = 0,
+        Start = 1,
+        End = 2,
+        Both = 3
+    }
+
+    public abstract class ArrowLineBase : Shape
+    {
+        protected PathGeometry pathgeo;
+        protected PathFigure pathfigLine;
+        protected PolyLineSegment polysegLine;
+
+        PathFigure pathfigHead1;
+        PolyLineSegment polysegHead1;
+        PathFigure pathfigHead2;
+        PolyLineSegment polysegHead2;
+
+        /// <summary>
+        ///     Identifies the ArrowAngle dependency property.
+        /// </summary>
+        public static readonly DependencyProperty ArrowAngleProperty =
+            DependencyProperty.Register("ArrowAngle",
+                typeof(double), typeof(ArrowLineBase),
+                new FrameworkPropertyMetadata(45.0,
+                        FrameworkPropertyMetadataOptions.AffectsMeasure));
+
+        /// <summary>
+        ///     Gets or sets the angle between the two sides of the arrowhead.
+        /// </summary>
+        public double ArrowAngle
+        {
+            set { SetValue(ArrowAngleProperty, value); }
+            get { return (double)GetValue(ArrowAngleProperty); }
+        }
+
+        /// <summary>
+        ///     Identifies the ArrowLength dependency property.
+        /// </summary>
+        public static readonly DependencyProperty ArrowLengthProperty =
+            DependencyProperty.Register("ArrowLength",
+                typeof(double), typeof(ArrowLineBase),
+                new FrameworkPropertyMetadata(12.0,
+                        FrameworkPropertyMetadataOptions.AffectsMeasure));
+
+        /// <summary>
+        ///     Gets or sets the length of the two sides of the arrowhead.
+        /// </summary>
+        public double ArrowLength
+        {
+            set { SetValue(ArrowLengthProperty, value); }
+            get { return (double)GetValue(ArrowLengthProperty); }
+        }
+
+        /// <summary>
+        ///     Identifies the ArrowEnds dependency property.
+        /// </summary>
+        public static readonly DependencyProperty ArrowEndsProperty =
+            DependencyProperty.Register("ArrowEnds",
+                typeof(ArrowEnds), typeof(ArrowLineBase),
+                new FrameworkPropertyMetadata(ArrowEnds.End,
+                        FrameworkPropertyMetadataOptions.AffectsMeasure));
+
+        /// <summary>
+        ///     Gets or sets the property that determines which ends of the
+        ///     line have arrows.
+        /// </summary>
+        public ArrowEnds ArrowEnds
+        {
+            set { SetValue(ArrowEndsProperty, value); }
+            get { return (ArrowEnds)GetValue(ArrowEndsProperty); }
+        }
+
+        /// <summary>
+        ///     Identifies the IsArrowClosed dependency property.
+        /// </summary>
+        public static readonly DependencyProperty IsArrowClosedProperty =
+            DependencyProperty.Register("IsArrowClosed",
+                typeof(bool), typeof(ArrowLineBase),
+                new FrameworkPropertyMetadata(false,
+                        FrameworkPropertyMetadataOptions.AffectsMeasure));
+
+        /// <summary>
+        ///     Gets or sets the property that determines if the arrow head
+        ///     is closed to resemble a triangle.
+        /// </summary>
+        public bool IsArrowClosed
+        {
+            set { SetValue(IsArrowClosedProperty, value); }
+            get { return (bool)GetValue(IsArrowClosedProperty); }
+        }
+
+        /// <summary>
+        ///     Initializes a new instance of ArrowLineBase.
+        /// </summary>
+        public ArrowLineBase()
+        {
+            pathgeo = new PathGeometry();
+
+            pathfigLine = new PathFigure();
+            polysegLine = new PolyLineSegment();
+            pathfigLine.Segments.Add(polysegLine);
+
+            pathfigHead1 = new PathFigure();
+            polysegHead1 = new PolyLineSegment();
+            pathfigHead1.Segments.Add(polysegHead1);
+
+            pathfigHead2 = new PathFigure();
+            polysegHead2 = new PolyLineSegment();
+            pathfigHead2.Segments.Add(polysegHead2);
+        }
+
+        /// <summary>
+        ///     Gets a value that represents the Geometry of the ArrowLine.
+        /// </summary>
+        protected override Geometry DefiningGeometry
+        {
+            get
+            {
+                int count = polysegLine.Points.Count;
+
+                if (count > 0)
+                {
+                    // Draw the arrow at the start of the line.
+                    if ((ArrowEnds & ArrowEnds.Start) == ArrowEnds.Start)
+                    {
+                        Point pt1 = pathfigLine.StartPoint;
+                        Point pt2 = polysegLine.Points[0];
+                        pathgeo.Figures.Add(CalculateArrow(pathfigHead1, pt2, pt1));
+                    }
+
+                    // Draw the arrow at the end of the line.
+                    if ((ArrowEnds & ArrowEnds.End) == ArrowEnds.End)
+                    {
+                        Point pt1 = count == 1 ? pathfigLine.StartPoint :
+                                                 polysegLine.Points[count - 2];
+                        Point pt2 = polysegLine.Points[count - 1];
+                        pathgeo.Figures.Add(CalculateArrow(pathfigHead2, pt1, pt2));
+                    }
+                }
+                return pathgeo;
+            }
+        }
+
+        PathFigure CalculateArrow(PathFigure pathfig, Point pt1, Point pt2)
+        {
+            Matrix matx = new Matrix();
+            Vector vect = pt1 - pt2;
+            vect.Normalize();
+            vect *= ArrowLength;
+
+            PolyLineSegment polyseg = pathfig.Segments[0] as PolyLineSegment;
+            polyseg.Points.Clear();
+            matx.Rotate(ArrowAngle / 2);
+            pathfig.StartPoint = pt2 + vect * matx;
+            polyseg.Points.Add(pt2);
+
+            matx.Rotate(-ArrowAngle);
+            polyseg.Points.Add(pt2 + vect * matx);
+            pathfig.IsClosed = IsArrowClosed;
+
+            return pathfig;
+        }
+    }
+}

+ 60 - 0
DrawGraph/DrawGraph.csproj

@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{DA67A8A4-157B-4D45-9835-C4EA9D623D5B}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>DrawGraph</RootNamespace>
+    <AssemblyName>DrawGraph</AssemblyName>
+    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <Deterministic>true</Deterministic>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="PresentationCore" />
+    <Reference Include="PresentationFramework" />
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+    <Reference Include="WindowsBase" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Algorithms.cs" />
+    <Compile Include="ArrowLine.cs" />
+    <Compile Include="ArrowLineBase.cs" />
+    <Compile Include="Edge.cs" />
+    <Compile Include="Export.cs" />
+    <Compile Include="GraphState.cs" />
+    <Compile Include="Matrix.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Settings.cs" />
+    <Compile Include="Vertex.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>

+ 101 - 0
DrawGraph/Edge.cs

@@ -0,0 +1,101 @@
+using System.Drawing;
+using System.Windows.Shapes;
+
+namespace DrawGraph
+{
+    public class Edge
+    {
+        public Line Line { get; }
+        public ArrowLine ArrowLine { get; }
+        public Vertex StartVertex { get; }
+        public Vertex FinishVertex { get; }
+        public int? Weight { get; set; }
+        public bool IsFocused { get; }
+
+        public Edge(Line line, Vertex v1, Vertex v2)
+        {
+            Line = line;
+            StartVertex = v1;
+            FinishVertex = v2;
+            IsFocused = false;
+        }
+
+        public Edge(ArrowLine line, Vertex v1, Vertex v2)
+        {
+            ArrowLine = line;
+            StartVertex = v1;
+            FinishVertex = v2;
+            IsFocused = true;
+        }
+
+        public Edge(Line line, Vertex v1, Vertex v2, int weight)
+        {
+            Line = line;
+            StartVertex = v1;
+            FinishVertex = v2;
+            Weight = weight;
+            IsFocused = false;
+        }
+        public Edge(ArrowLine line, Vertex v1, Vertex v2, int weight)
+        {
+            ArrowLine = line;
+            StartVertex = v1;
+            FinishVertex = v2;
+            IsFocused = true;
+            Weight = weight;
+
+            ArrowLine.X1 = v1.CenterByX;
+            ArrowLine.X2 = v2.CenterByX;
+            ArrowLine.Y1 = v1.CenterByY;
+            ArrowLine.Y2 = v2.CenterByY;
+            ArrowLine.StrokeThickness = 2;
+        }
+
+        public static double GetCenterByX(Edge edge)
+        {
+            var x = (edge.FinishVertex.X + edge.StartVertex.X) / 2;
+            return x;
+        }
+
+        public static double GetCenterByY(Edge edge)
+        {
+            var y = (edge.FinishVertex.Y + edge.StartVertex.Y) / 2;
+            return y;
+        }
+
+        public static bool IsCursorOnVertex(Point cursorPosition, Vertex vertex)
+        {
+                if (vertex.CenterByX - cursorPosition.X <= Settings.VertexWidth / 2 &&
+                    vertex.CenterByX - cursorPosition.X >= 0)
+                {
+                    if (vertex.CenterByY - cursorPosition.Y <= Settings.VertexHeight / 2 &&
+                        vertex.CenterByY - cursorPosition.Y >= 0)
+                    {
+                        return true;
+                    }
+                }
+
+                if (cursorPosition.X - vertex.CenterByX <= Settings.VertexWidth / 2 &&
+                    cursorPosition.X - vertex.CenterByX >= 0)
+                {
+                    if (cursorPosition.Y - vertex.CenterByY <= Settings.VertexWidth / 2 &&
+                        cursorPosition.Y - vertex.CenterByY >= 0)
+                    {
+                        return true;
+                    }
+
+                    return false;
+                }
+
+                return false;
+        }
+
+        public static bool IsVertexBelongToEdge(Edge edge, Vertex vertex)
+        {
+            if (Vertex.Compare(vertex, edge.StartVertex) || Vertex.Compare(vertex, edge.FinishVertex))
+                return true;
+
+            return false;
+        }
+    }
+}

+ 59 - 0
DrawGraph/Export.cs

@@ -0,0 +1,59 @@
+using System.IO;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+
+namespace DrawGraph
+{
+    class Export
+    {
+        public static void ToPng(Canvas canvas, string path)
+        {
+            RenderTargetBitmap renderBitmap = new RenderTargetBitmap(
+                (int)canvas.Width, (int)canvas.Height,
+                96d, 96d, PixelFormats.Pbgra32);
+            canvas.Measure(new Size((int)canvas.Width, (int)canvas.Height));
+            canvas.Arrange(new Rect(new Size((int)canvas.Width, (int)canvas.Height)));
+
+            renderBitmap.Render(canvas);
+
+            //JpegBitmapEncoder encoder = new JpegBitmapEncoder();
+            PngBitmapEncoder encoder = new PngBitmapEncoder();
+            encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
+
+            using (FileStream fs = new FileStream(path, FileMode.Create))
+            {
+                encoder.Save(fs);
+            }
+        }
+
+        public static void ToJpeg(Canvas canvas, string path)
+        {
+            RenderTargetBitmap renderBitmap = new RenderTargetBitmap(
+                (int)canvas.Width, (int)canvas.Height,
+                96d, 96d, PixelFormats.Pbgra32);
+            canvas.Measure(new Size((int)canvas.Width, (int)canvas.Height));
+            canvas.Arrange(new Rect(new Size((int)canvas.Width, (int)canvas.Height)));
+
+            renderBitmap.Render(canvas);
+
+            JpegBitmapEncoder encoder = new JpegBitmapEncoder();
+            encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
+
+            using (FileStream fs = new FileStream(path, FileMode.Create))
+            {
+                encoder.Save(fs);
+            }
+        }
+
+        public static void Print(Canvas canvas)
+        {
+            PrintDialog pd = new PrintDialog();
+            if (pd.ShowDialog() == true)
+            {
+                pd.PrintVisual(canvas, "Printed with DrawGraph");
+            }
+        }
+    }
+}

+ 14 - 0
DrawGraph/GraphState.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DrawGraph
+{
+    public class GraphState
+    {
+        public static bool focused = false;
+        public static bool named = false;
+    }
+}

+ 108 - 0
DrawGraph/Matrix.cs

@@ -0,0 +1,108 @@
+namespace DrawGraph
+{
+    public class Matrix
+    {
+        public static int[,] AdjacencyCreate(Vertex[] vertices, Edge[] edges)
+        {
+            int length = vertices.Length;
+            int[,] matrix = new int[length, length];
+            for (int i = 0; i < vertices.Length; i++)
+            {
+                var vertex1 = vertices[i];
+                for (int j = 0; j < vertices.Length; j++)
+                {
+                    if (i != j)
+                    {
+                        var vertex2 = vertices[j];
+                        for (int k = 0; k < edges.Length; k++)
+                        {
+                            var edge = edges[k];
+                            if (edge.IsFocused)
+                            {
+                                if (Vertex.Compare(edge.FinishVertex, vertex1) &&
+                                    Vertex.Compare(edge.StartVertex, vertex2))
+                                    if (edge.Weight > 0)
+                                        matrix[i, j] = (int) edge.Weight;
+                                    else
+                                        matrix[i, j] = 1;
+                                else if (Vertex.Compare(edge.StartVertex, vertex1) &&
+                                         Vertex.Compare(edge.FinishVertex, vertex2))
+                                    if (edge.Weight > 0)
+                                        matrix[i, j] = (int) edge.Weight;
+                            }
+                            else
+                            {
+                                if (Vertex.Compare(edge.FinishVertex, vertex1) &&
+                                    Vertex.Compare(edge.StartVertex, vertex2))
+                                    if (edge.Weight > 0)
+                                    {
+                                        matrix[i, j] = (int) edge.Weight;
+                                        InvertElement(matrix, i, j);
+                                    }
+                                    else
+                                    {
+                                        matrix[i, j] = 1;
+                                        InvertElement(matrix, i, j);
+                                    }
+                                else if (Vertex.Compare(edge.StartVertex, vertex1) &&
+                                         Vertex.Compare(edge.FinishVertex, vertex2))
+                                    if (edge.Weight > 0)
+                                    {
+                                        matrix[i, j] = (int) edge.Weight;
+                                        InvertElement(matrix, i, j);
+                                    }
+                                    else
+                                    {
+                                        matrix[i, j] = 1;
+                                        InvertElement(matrix, i, j);
+                                    }
+                            }
+                        }
+                    }
+                    else
+                    {
+                        matrix[i, j] = 0;
+                    }
+                }
+            }
+
+            return matrix;
+        }
+        public static int[,] InvertElement(int[,] matrix, int indexX, int indexY)
+        {
+            matrix[indexY, indexX] = matrix[indexX, indexY];
+            return matrix;
+        }
+        public static int[,] IncidenceCreate(Vertex[] vertices, Edge[] edges)
+        {
+            var rows = vertices.Length;
+            var cols = edges.Length;
+            var matrix = new int[rows, cols];
+            for (var i = 0; i < rows; i++)
+            {
+                var vertex = vertices[i];
+
+                for (var j = 0; j < cols; j++)
+                {
+                    var edge = edges[j];
+
+
+                    if (Vertex.Compare(vertex, edge.FinishVertex) && edge.IsFocused)
+                        matrix[i, j] = -1;
+                    else
+                    {
+                        if (Vertex.Compare(vertex, edge.FinishVertex) || Vertex.Compare(vertex, edge.StartVertex))
+                            if (edge.Weight > 0)
+                                matrix[i, j] = (int)edge.Weight;
+                            else
+                                matrix[i, j] = 1;
+                        else
+                            matrix[i, j] = 0;
+                    }
+                }
+            }
+
+            return matrix;
+        }
+    }
+}

+ 36 - 0
DrawGraph/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("DrawGraph")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("DrawGraph")]
+[assembly: AssemblyCopyright("Copyright ©  2019")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components.  If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("da67a8a4-157b-4d45-9835-c4ea9d623d5b")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 37 - 0
DrawGraph/Settings.cs

@@ -0,0 +1,37 @@
+using System;
+using System.Windows.Controls;
+using System.Windows.Media;
+using System.Windows.Shapes;
+
+namespace DrawGraph
+{
+    public class Settings
+    {
+        public static int VertexWidth = 10;
+        public static int VertexHeight = 10;
+        public static int StrokeThickness = 2;
+        public static int FontSize = 16;
+        public static Color FillColor = Color.FromRgb(0, 0, 0);
+
+        public static void ClearCanvas(Edge[] edges, Vertex[] vertices)
+        {
+            Array.Clear(edges, 0, edges.Length);
+            Array.Clear(vertices, 0, vertices.Length);
+        }
+
+        public static void RemoveAllEdges(Canvas canvas, Line[] lines, Edge[] edges)
+        {
+            Array.Clear(edges, 0, edges.Length);
+            for (int i = 0; i < lines.Length; i++)
+            {
+                canvas.Children.Remove(lines[i]);
+            }
+        }
+
+        public static void RemoveLastAdded(Canvas canvas)
+        {
+            int removingElement = canvas.Children.Count-1;
+            canvas.Children.RemoveAt(removingElement);
+        }
+    }
+}

+ 30 - 0
DrawGraph/Vertex.cs

@@ -0,0 +1,30 @@
+namespace DrawGraph
+{
+    public class Vertex
+    {
+        public int X { get; set; }
+        public int Y { get; set; }
+
+        public Vertex(int x, int y)
+        {
+            X = x;
+            Y = y;
+        }
+
+        public int CenterByX => (X * 2 + 10) / 2;
+
+        public int CenterByY => (Y * 2 + 10) / 2;
+
+        public static bool Compare(Vertex v1, Vertex v2)
+        {
+            if (Equals(v1, v2))
+                return true;
+            if (v1 == v2)
+                return true;
+            if (v1.X == v2.X && v1.Y == v2.Y)
+                return true;
+            return false;
+        }
+
+    }
+}