/// <summary> /// Draw the edge on the graph that connects 2 nodes passed, if edge param is null, create a new edge /// </summary> /// <param name="startNode"></param> /// <param name="endNode"></param> /// <param name="edge"></param> private void DrawEdge(CanvasNode startNode, CanvasNode endNode, CanvasEdge edge = null) { Point startPoint, endPoint; startPoint = new Point(startNode.X, startNode.Y); endPoint = new Point(endNode.X, endNode.Y); if (edge == null) { edge = new CanvasEdge() { Stroke = Brushes.DarkGray, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, StrokeThickness = 3, X1 = startNode.X, Y1 = startNode.Y, X2 = endNode.X, Y2 = endNode.Y, IsDirected = ArcType.SelectedItem == DirectedArc }; // Add attributes to the edge foreach (KeyValuePair <string, double> attr in graph.CommonAttributes) { if (!edge.Impl.HasNumericAttribute(attr.Key)) { edge.Impl.NumericAttributes.Add(attr.Key, attr.Value); } } graph.Call(graph => { graph.ConnectNodeToWith(startNode.Impl, endNode.Impl, edge.Impl); }); graph[edge.Impl] = edge; } else { edge.Stroke = Brushes.DarkGray; edge.HorizontalAlignment = HorizontalAlignment.Center; edge.VerticalAlignment = VerticalAlignment.Center; edge.StrokeThickness = 3; } MainCanvas.Children.Add(edge); Canvas.SetZIndex(edge, -1); startNode.OutLines.Add(edge); endNode.InLines.Add(edge); MainCanvas.UpdateLines(startNode); MainCanvas.UpdateLines(endNode); }
/// <summary> /// Add edge to the graph, avoid duplicates /// </summary> /// <param name="cgraph"></param> /// <param name="cnode"></param> private void AddIfNotContain(CanvasGraph cgraph, CanvasNode cnode) { INode resultNode = cnode.Impl; //if (resultNode.GetType() != typeof(ResultNode)) // throw new Exception("AddIfNotContain Error!"); if (cgraph.Call(graph => !graph.Contains(resultNode))) { cgraph.Call(graph => graph.Add(resultNode)); } }
public void Save(String path, CanvasGraph graph) { cgraph = graph; XElement root = new XElement("NetworkObservability"); DumpTo(graph.Call(graphImpl => graphImpl), ref root); root.Add(CreateCommonAttributes(cgraph.CommonAttributes)); File.Add(root); // New way to save File.Save(path); }