/// <summary> /// Create a sample graph with edge/edge intersections and edge/group node intersections /// </summary> /// <param name="graph"></param> private void InitializeGraph(IGraph graph) { INode[] nodes = new INode[16]; int count = 0; for (int i = 1; i < 5; i++) { nodes[count++] = graph.CreateNode(new PointD(50 + 40 * i, 260)); nodes[count++] = graph.CreateNode(new PointD(50 + 40 * i, 40)); nodes[count++] = graph.CreateNode(new PointD(40, 50 + 40 * i)); nodes[count++] = graph.CreateNode(new PointD(260, 50 + 40 * i)); } for (int i = 0; i < nodes.Length; i++) { graph.AddLabel(nodes[i], "" + i); } graph.CreateEdge(nodes[0], nodes[1]); IPort p1 = graph.AddPort(nodes[0], new PointD(0, 0)); graph.SetRelativePortLocation(p1, new PointD(5, 0)); IPort p2 = graph.AddPort(nodes[1], new PointD(0, 0)); graph.SetRelativePortLocation(p2, new PointD(5, 0)); graph.CreateEdge(p1, p2); graph.CreateEdge(nodes[5], nodes[4]); graph.CreateEdge(nodes[2], nodes[3]); graph.CreateEdge(nodes[7], nodes[6]); graph.CreateEdge(nodes[2 + 8], nodes[3 + 8]); graph.CreateEdge(nodes[7 + 8], nodes[6 + 8]); graph.CreateEdge(nodes[0 + 8], nodes[1 + 8]); graph.CreateEdge(nodes[5 + 8], nodes[4 + 8]); INode n1 = graph.CreateNode(new PointD(300, 150)); INode n2 = graph.CreateNode(new PointD(400, 150)); INode n3 = graph.CreateNode(new PointD(500, 150)); graph.CreateEdge(n1, n3); INode groupNode = graph.CreateGroupNode(); graph.AddLabel(groupNode, "Group Node", InteriorStretchLabelModel.North); graph.SetParent(n2, groupNode); graph.AdjustGroupNodeLayout(groupNode); graphControl.UpdateContentRect(); }
/// <summary> /// Adds some ports to the given node. /// </summary> private static IPort[] CreateSamplePorts(IGraph graph, INode node, bool toEastSide) { var model = FreeNodePortLocationModel.Instance; var x = toEastSide ? 0.9 : 0.1; var ports = new IPort[4]; ports[0] = graph.AddPort(node, model.CreateParameter(new PointD(x, 0.05))); ports[1] = graph.AddPort(node, model.CreateParameter(new PointD(x, 0.35))); ports[2] = graph.AddPort(node, model.CreateParameter(new PointD(x, 0.65))); ports[3] = graph.AddPort(node, model.CreateParameter(new PointD(x, 0.95))); return(ports); }
/// <summary> /// Creates a node of the specified type. /// </summary> /// <remarks> /// The method will specify the ports that the node should have based on its type. /// </remarks> private void CreateNode(IGraph graph, PointD location, LogicGateType type, string label, SizeD?size = null) { RectD newBounds = RectD.FromCenter(location, graph.NodeDefaults.Size); INode node; if (type >= LogicGateType.Timer) { node = graph.CreateNode(RectD.FromCenter(location, (SizeD)size), new ShapeNodeStyle { Pen = new Pen(Brushes.Black, 2) }); } else { node = graph.CreateNode(newBounds, new LogicGateNodeStyle { GateType = type }); } graph.AddLabel(node, label, InteriorLabelModel.Center); var portDescriptors = PortDescriptor.CreatePortDescriptors(type); // use relative port locations var model = new FreeNodePortLocationModel(); // add ports for all descriptors using the descriptor as the tag of the port foreach (var descriptor in portDescriptors) { // use the descriptor's location as offset var portLocationModelParameter = model.CreateParameter(PointD.Origin, new PointD(descriptor.X, descriptor.Y)); graph.AddPort(node, portLocationModelParameter, tag: descriptor); } }
/// <summary> /// Adds ports with different colors to the node. /// </summary> private void AddIndividualPorts(IGraph graph, INode node) { var portStyle = new ColorPortStyle(); graph.AddPort(node, FreeNodePortLocationModel.Instance.CreateParameter(new PointD(0.25, 0)), portStyle, Color.Firebrick); graph.AddPort(node, FreeNodePortLocationModel.Instance.CreateParameter(new PointD(0.75, 0)), portStyle, Color.Green); graph.AddPort(node, FreeNodePortLocationModel.Instance.CreateParameter(new PointD(0, 0.25)), portStyle, Color.Black); graph.AddPort(node, FreeNodePortLocationModel.Instance.CreateParameter(new PointD(0, 0.75)), portStyle, Color.Black); graph.AddPort(node, FreeNodePortLocationModel.Instance.CreateParameter(new PointD(1, 0.25)), portStyle, Color.RoyalBlue); graph.AddPort(node, FreeNodePortLocationModel.Instance.CreateParameter(new PointD(1, 0.75)), portStyle, Color.Orange); graph.AddPort(node, FreeNodePortLocationModel.Instance.CreateParameter(new PointD(0.25, 1)), portStyle, Color.Purple); graph.AddPort(node, FreeNodePortLocationModel.Instance.CreateParameter(new PointD(0.75, 1)), portStyle, Color.Purple); }
/// <summary> /// Copy the ports from a provided node of the original input graph to a node of the resulting multi-page graph view. /// </summary> protected void CopyPorts(IGraph pageView, Node layoutNode, INode viewNode, INode modelNode) { foreach (IPort port in modelNode.Ports) { IPort viewPort = pageView.AddPort(viewNode, (IPortLocationModelParameter)port.LocationParameter.Clone()); if (port.Style != null) { pageView.SetStyle(viewPort, (IPortStyle)port.Style.Clone()); } modelToViewPort[port] = viewPort; } }
private void CreateSampleGraph() { IGraph graph = graphControl.Graph; CreateNode(graph, 100, 100, 80, 30, Colors.Firebrick, "No Edge"); CreateNode(graph, 350, 100, 80, 30, Colors.Green, "Green Only"); CreateNode(graph, 100, 200, 80, 30, Colors.Green, "Green Only"); CreateNode(graph, 350, 200, 80, 30, Colors.Firebrick, "No Edge"); // The blue nodes have predefined ports var portStyle = new ColorPortStyle(); var blue1 = CreateNode(graph, 100, 300, 80, 30, Colors.RoyalBlue, "One Port"); graph.AddPort(blue1, blue1.Layout.GetCenter(), portStyle).Tag = Colors.Black; var blue2 = CreateNode(graph, 350, 300, 100, 100, Colors.RoyalBlue, "Many Ports"); var portCandidateProvider = PortCandidateProviders.FromShapeGeometry(blue2, 0, 0.25, 0.5, 0.75); portCandidateProvider.Style = portStyle; portCandidateProvider.Tag = Colors.Black; var candidates = portCandidateProvider.GetSourcePortCandidates(graphControl.InputModeContext); foreach (IPortCandidate portCandidate in candidates) { if (portCandidate.Validity != PortCandidateValidity.Dynamic) { portCandidate.CreatePort(graphControl.InputModeContext); } } // The orange node CreateNode(graph, 100, 400, 100, 100, Colors.Orange, "Dynamic Ports"); INode n = CreateNode(graph, 100, 540, 100, 100, Colors.Purple, "Individual\nPort Constraints"); AddIndividualPorts(graph, n); n = CreateNode(graph, 350, 540, 100, 100, Colors.Purple, "Individual\nPort Constraints"); AddIndividualPorts(graph, n); }