private void AddNewEdgeControl(EdgeViewModel edgeViewModel) { var prevVerVertex = this.previosVertex?.Vertex as NodeViewModel; var ctrlVerVertex = this.currentVertex?.Vertex as NodeViewModel; if (this.currentVertex is VertexControlWithVCP && this.previosVertex is VertexControlWithVCP) { VertexConnectionPoint targetVCP = null; foreach (var x in this.currentVertex.VertexConnectionPointsList) { var aVCPforGH = x as VertexConnectionPoint; if (aVCPforGH != null && aVCPforGH.IsOccupied == false && aVCPforGH.IsSource == false) { aVCPforGH.IsOccupied = true; targetVCP = aVCPforGH; break; } } if (targetVCP != null) { this.Graph.SetTargetVCPId(edgeViewModel, targetVCP.Id); } else { if (ctrlVerVertex.Node.Name == "aInterval") { this.editorManager.DestroyVirtualEdge(); return; } var newId = this.currentVertex.VertexConnectionPointsList.Last().Id + 1; targetVCP = new VertexConnectionPoint() { Id = newId, IsOccupied = true, IsSource = false }; var ctrl = new Border { Margin = new Thickness(0, 2, 2, 0), Padding = new Thickness(0), Child = targetVCP }; ((VertexControlWithVCP)this.currentVertex).VCPTargetRoot.Children.Add(ctrl); this.currentVertex.VertexConnectionPointsList.Add(targetVCP); this.Graph.SetTargetVCPId(edgeViewModel, targetVCP.Id); } VertexConnectionPoint sourceVCP = null; foreach (var x in this.previosVertex.VertexConnectionPointsList) { var aVCPforGH = x as VertexConnectionPoint; if (aVCPforGH != null && aVCPforGH.IsOccupied == false && aVCPforGH.IsSource == true) { aVCPforGH.IsOccupied = true; sourceVCP = aVCPforGH; break; } } if (sourceVCP != null) { this.Graph.SetSourceVCPId(edgeViewModel, sourceVCP.Id); } else { var newId = this.previosVertex.VertexConnectionPointsList.Last().Id + 1; sourceVCP = new VertexConnectionPoint() { Id = newId, IsOccupied = true, IsSource = true }; var ctrl = new Border { Margin = new Thickness(0, 2, 2, 0), Padding = new Thickness(0), Child = sourceVCP }; ((VertexControlWithVCP)this.previosVertex).VCPSourceRoot.Children.Add(ctrl); this.previosVertex.VertexConnectionPointsList.Add(sourceVCP); this.Graph.SetSourceVCPId(edgeViewModel, newId); } } var ec = new EdgeControl(this.previosVertex, this.currentVertex, edgeViewModel); this.previosVertex = null; this.editorManager.DestroyVirtualEdge(); this.graphArea.InsertEdge(edgeViewModel, ec); }
public void AddVertexConnectionPoints() { foreach (var vertex in this.graphArea.VertexList) { foreach (var edge in this.Graph.DataGraph.Edges) { if (edge.Target == vertex.Key) { VertexConnectionPoint targetVCP = null; foreach (var x in vertex.Value.VertexConnectionPointsList) { var aVCPforGH = x as VertexConnectionPoint; if (aVCPforGH != null && !aVCPforGH.IsOccupied && !aVCPforGH.IsSource) { aVCPforGH.IsOccupied = true; targetVCP = aVCPforGH; break; } } if (targetVCP != null) { edge.TargetConnectionPointId = targetVCP.Id; } else { // if the model is initially incorrect if (vertex.Key.Node.Name == "aInterval") { return; } var newId = vertex.Value.VertexConnectionPointsList.Last().Id + 1; var vcp = new VertexConnectionPoint() { Id = newId, IsOccupied = true, IsSource = false }; var ctrl = new Border { Margin = new Thickness(0, 2, 2, 0), Padding = new Thickness(0), Child = vcp }; ((VertexControlWithVCP)vertex.Value).VCPTargetRoot.Children.Add(ctrl); vertex.Value.VertexConnectionPointsList.Add(vcp); edge.TargetConnectionPointId = newId; } } if (edge.Source == vertex.Key) { VertexConnectionPoint sourceVCP = null; foreach (var x in vertex.Value.VertexConnectionPointsList) { var aVCPforGH = x as VertexConnectionPoint; if (aVCPforGH != null && !aVCPforGH.IsOccupied && aVCPforGH.IsSource) { aVCPforGH.IsOccupied = true; sourceVCP = aVCPforGH; break; } } if (sourceVCP != null) { edge.SourceConnectionPointId = sourceVCP.Id; } else { var newId = vertex.Value.VertexConnectionPointsList.Last().Id + 1; sourceVCP = new VertexConnectionPoint() { Id = newId, IsOccupied = true, IsSource = true }; var ctrl = new Border { Margin = new Thickness(0, 2, 2, 0), Padding = new Thickness(0), Child = sourceVCP }; ((VertexControlWithVCP)vertex.Value).VCPSourceRoot.Children.Add(ctrl); vertex.Value.VertexConnectionPointsList.Add(sourceVCP); edge.SourceConnectionPointId = newId; } } this.graphArea.EdgesList[edge].UpdateEdge(); } } }