private void RemoveVertex(VertexControl ellipse) { var vertex = _ellipses[ellipse]; _vertices.Remove(vertex); _ellipses.Remove(ellipse); Container.Children.Remove(ellipse); _graph.DeleteVertex(vertex); }
/// <summary> /// Обрабатывает событие нажатия на вершину, при добавлении нового ребра. /// </summary> private void CreateEdge(VertexControl ellipse, Point mousePosition) { switch (_currentCreateEdgeActionState) { case CreateEdgeActionState.SelectFirstVertex: _edgeStart = ellipse; var startPointX = Canvas.GetLeft(_edgeStart) + VertexSettings.Size / 2; var startPointY = Canvas.GetTop(_edgeStart) + VertexSettings.Size / 2; var finishPointX = mousePosition.X + VertexSettings.Size / 2; var finishPointY = mousePosition.Y + VertexSettings.Size / 2; var startPoint = new Point(startPointX, startPointY); var endPoint = new Point(finishPointX, finishPointY); _movingLine = InitializeLine(startPoint, endPoint); Container.Children.Add(_movingLine); _currentCreateEdgeActionState = CreateEdgeActionState.SelectSecondVertex; break; case CreateEdgeActionState.SelectSecondVertex: _edgeFinish = ellipse; if (Equals(_edgeFinish, _edgeStart) || _ellipses[_edgeStart].AdjacentVertices.Contains(_ellipses[_edgeFinish])) { break; } var finishX = Canvas.GetLeft(_edgeFinish) + VertexSettings.Size / 2; var finishY = Canvas.GetTop(_edgeFinish) + VertexSettings.Size / 2; _movingLine.X2 = finishX; _movingLine.Y2 = finishY; var edge = _graph.AddEdge(_ellipses[_edgeStart], _ellipses[_edgeFinish]); _edges[edge] = _movingLine; _lines[_movingLine] = edge; _movingLine.MouseEnter += (sender, args) => ((Line)sender).StrokeThickness = 10; _movingLine.MouseLeave += (sender, args) => ((Line)sender).StrokeThickness = 5; var weightTextBox = InitializeWeightTextBox(_movingLine); _edgeWeightMapping[edge] = weightTextBox; _weightEdgeMapping[weightTextBox] = edge; UpdateWeightTextBoxPosition(_movingLine); Container.Children.Add(weightTextBox); _currentCreateEdgeActionState = CreateEdgeActionState.SelectFirstVertex; _movingLine = null; break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Создает контрол вершины с требуемыми параметрами. /// </summary> /// <param name="vertex"></param> /// <param name="point">Координаты вершины.</param> /// <returns></returns> private VertexControl InitializeVertexControl(Vertex vertex, Point point) { var vertexControl = new VertexControl(vertex.Index) { Style = FindResource("Vertex") as Style }; Panel.SetZIndex(vertexControl, VertexSettings.ZIndex); Canvas.SetTop(vertexControl, point.Y); Canvas.SetLeft(vertexControl, point.X); return(vertexControl); }
private void StartMovingVertex(VertexControl ellipse) { _isVertexMoving = true; Panel.SetZIndex(ellipse, VertexSettings.MovingZIndex); _movingEllipse = ellipse; }