private static GleeGraph CreateAndLayoutGraph(string fileName) { // Read the file as one string var fileString = string.Empty; using (var myFile = new StreamReader(fileName)) { fileString = myFile.ReadToEnd(); } var xmlParser = new XmlParser(fileString); startNode = xmlParser.StartState; var graph = new GleeGraph { Margins = margin }; foreach (var state in xmlParser.States) { graph.AddNode(new Node(state, new Ellipse(nodeWidth, nodeHeight, new P()))); } foreach (var transition in xmlParser.Transitions) { var e = new Edge(graph.NodeMap[transition.From], graph.NodeMap[transition.To]) { UserData = transition.Trigger }; graph.AddEdge(e); } graph.CalculateLayout(); return(graph); }
private static GleeGraph CreateAndLayoutGraph(XmlModel xmlParser) { startNode = xmlParser.StartState; var graph = new GleeGraph { Margins = margin }; foreach (var state in xmlParser.States) { graph.AddNode(new Node(state, new Ellipse(nodeWidth, nodeHeight, new P()))); } foreach (var transition in xmlParser.Transitions) { var e = new Edge(graph.NodeMap[transition.From], graph.NodeMap[transition.To]) { UserData = transition.Trigger }; graph.AddEdge(e); } graph.CalculateLayout(); return(graph); }
private GleeGraph CreateAndLayoutGraph() { double w = 30; double h = 20; GleeGraph graph = new GleeGraph(); Node a = new Node("a", new Ellipse(w, h, new P())); Node b = new Node("b", CurveFactory.CreateBox(w, h, new P())); graph.AddNode(a); graph.AddNode(b); Edge e = new Edge(a, b); e.ArrowHeadAtSource = true; graph.AddEdge(e); graph.AddEdge(new Edge(a, b)); graph.CalculateLayout(); return(graph); }
/// <summary> /// Layouts the diagram by using the GLEE library. /// </summary> /// <param name="diagram">Diagram.</param> public static void Layout(Diagram diagram) { Dictionary<string, NodeShape> shapesMap = new Dictionary<string, NodeShape>(); List<LinkShape> dEdges = new List<LinkShape>(); List<LinkShape> edges = new List<LinkShape>(); List<LinkShape> edgesLocal = new List<LinkShape>(); // create glee graph GleeGraph g = new GleeGraph(); g.Margins = GraphMargins; g.MinNodeHeight = MinNodeHeight; g.MinNodeWidth = GraphMargins; foreach (NodeShape shape in diagram.Children) { // layout shape if it has children if (shape.Children.Count > 0) LayoutShape(shape, edges, dEdges); // collect edges on the same level foreach (LinkShape linkShape in shape.OutgoingLinkShapes) { if (linkShape.ToShape.Parent == null) edgesLocal.Add(linkShape); else dEdges.Add(linkShape); } AddNode(g, shape, shapesMap); } // 2. add edges foreach (LinkShape linkShape in edgesLocal) { g.AddEdge(new Edge( g.NodeMap[linkShape.FromShape.Id.ToString()], g.NodeMap[linkShape.ToShape.Id.ToString()])); } edges.AddRange(edgesLocal); // layout graph g.CalculateLayout(); // apply layout information to diagram double left = g.Left; double top = g.Top; ApplyShapesLayout(g, shapesMap, left, top); // update absolute location of shapes UpdateAbsoluteLocation(diagram); // update layout of link shapes foreach (LinkShape linkShape in edges) { linkShape.Layout(FixedGeometryPoints.None); linkShape.SourceAnchor.DiscardLocationChange = false; linkShape.TargetAnchor.DiscardLocationChange = false; } // update layout of discarded link shapes foreach (LinkShape linkShape in dEdges) { linkShape.Layout(FixedGeometryPoints.None); linkShape.SourceAnchor.DiscardLocationChange = false; linkShape.TargetAnchor.DiscardLocationChange = false; } // layout included diagrams foreach (Diagram incD in diagram.IncludedDiagrams) Layout(incD); }
/// <summary> /// Layout a subgraph defined by a given shape by using the GLEE layout library. /// </summary> /// <param name="shape">Main shape.</param> /// <remarks> /// This method needs to be called within a modeling transaction. /// </remarks> private static void LayoutShape(NodeShape shape, List<LinkShape> edges, List<LinkShape> dEdges) { Dictionary<string, NodeShape> shapesMap = new Dictionary<string, NodeShape>(); // create glee graph GleeGraph g = new GleeGraph(); g.Margins = GraphMargins; g.MinNodeHeight = MinNodeHeight; g.MinNodeWidth = GraphMargins; // transform the information in the diagram into the glee graph List<LinkShape> edgesLocal = new List<LinkShape>(); foreach (NodeShape childShape in shape.Children) { // layout shape if it has children if (childShape.Children.Count > 0) LayoutShape(childShape, edges, dEdges); // collect edges on the same level foreach (LinkShape linkShape in childShape.OutgoingLinkShapes) { if (linkShape.ToShape.Parent == shape) edgesLocal.Add(linkShape); else dEdges.Add(linkShape); } AddNode(g, childShape, shapesMap); } // 2. add edges foreach (LinkShape linkShape in edgesLocal) { g.AddEdge(new Edge( g.NodeMap[linkShape.FromShape.Id.ToString()], g.NodeMap[linkShape.ToShape.Id.ToString()])); } edges.AddRange(edgesLocal); // layout graph g.CalculateLayout(); // apply layout information to diagram if (shape.Children.Count > 0) // we have no way of knowning what min size a shape has for now.. { if (shape.ResizingBehaviour == ShapeResizingBehaviour.Normal) shape.SetSize(new SizeD(g.Width + HostMargin, g.Height + HostMargin)); else if (shape.ResizingBehaviour == ShapeResizingBehaviour.FixedWidth) shape.SetSize(new SizeD(shape.Size.Width, g.Height + HostMargin)); else if (shape.ResizingBehaviour == ShapeResizingBehaviour.FixedHeight) shape.SetSize(new SizeD(g.Width + HostMargin, shape.Size.Height)); } ApplyShapesLayout(g, shapesMap, g.Left, g.Top); // update absolute location of shapes UpdateAbsoluteLocation(shape); }
/// <summary> /// Layouts the diagram by using the GLEE library. /// </summary> /// <param name="diagram">Diagram.</param> public static void Layout(Diagram diagram) { Dictionary <string, NodeShape> shapesMap = new Dictionary <string, NodeShape>(); List <LinkShape> dEdges = new List <LinkShape>(); List <LinkShape> edges = new List <LinkShape>(); List <LinkShape> edgesLocal = new List <LinkShape>(); // create glee graph GleeGraph g = new GleeGraph(); g.Margins = GraphMargins; g.MinNodeHeight = MinNodeHeight; g.MinNodeWidth = GraphMargins; foreach (NodeShape shape in diagram.Children) { // layout shape if it has children if (shape.Children.Count > 0) { LayoutShape(shape, edges, dEdges); } // collect edges on the same level foreach (LinkShape linkShape in shape.OutgoingLinkShapes) { if (linkShape.ToShape.Parent == null) { edgesLocal.Add(linkShape); } else { dEdges.Add(linkShape); } } AddNode(g, shape, shapesMap); } // 2. add edges foreach (LinkShape linkShape in edgesLocal) { g.AddEdge(new Edge( g.NodeMap[linkShape.FromShape.Id.ToString()], g.NodeMap[linkShape.ToShape.Id.ToString()])); } edges.AddRange(edgesLocal); // layout graph g.CalculateLayout(); // apply layout information to diagram double left = g.Left; double top = g.Top; ApplyShapesLayout(g, shapesMap, left, top); // update absolute location of shapes UpdateAbsoluteLocation(diagram); // update layout of link shapes foreach (LinkShape linkShape in edges) { linkShape.Layout(FixedGeometryPoints.None); linkShape.SourceAnchor.DiscardLocationChange = false; linkShape.TargetAnchor.DiscardLocationChange = false; } // update layout of discarded link shapes foreach (LinkShape linkShape in dEdges) { linkShape.Layout(FixedGeometryPoints.None); linkShape.SourceAnchor.DiscardLocationChange = false; linkShape.TargetAnchor.DiscardLocationChange = false; } // layout included diagrams foreach (Diagram incD in diagram.IncludedDiagrams) { Layout(incD); } }
/// <summary> /// Layout a subgraph defined by a given shape by using the GLEE layout library. /// </summary> /// <param name="shape">Main shape.</param> /// <remarks> /// This method needs to be called within a modeling transaction. /// </remarks> private static void LayoutShape(NodeShape shape, List <LinkShape> edges, List <LinkShape> dEdges) { Dictionary <string, NodeShape> shapesMap = new Dictionary <string, NodeShape>(); // create glee graph GleeGraph g = new GleeGraph(); g.Margins = GraphMargins; g.MinNodeHeight = MinNodeHeight; g.MinNodeWidth = GraphMargins; // transform the information in the diagram into the glee graph List <LinkShape> edgesLocal = new List <LinkShape>(); foreach (NodeShape childShape in shape.Children) { // layout shape if it has children if (childShape.Children.Count > 0) { LayoutShape(childShape, edges, dEdges); } // collect edges on the same level foreach (LinkShape linkShape in childShape.OutgoingLinkShapes) { if (linkShape.ToShape.Parent == shape) { edgesLocal.Add(linkShape); } else { dEdges.Add(linkShape); } } AddNode(g, childShape, shapesMap); } // 2. add edges foreach (LinkShape linkShape in edgesLocal) { g.AddEdge(new Edge( g.NodeMap[linkShape.FromShape.Id.ToString()], g.NodeMap[linkShape.ToShape.Id.ToString()])); } edges.AddRange(edgesLocal); // layout graph g.CalculateLayout(); // apply layout information to diagram if (shape.Children.Count > 0) // we have no way of knowning what min size a shape has for now.. { if (shape.ResizingBehaviour == ShapeResizingBehaviour.Normal) { shape.SetSize(new SizeD(g.Width + HostMargin, g.Height + HostMargin)); } else if (shape.ResizingBehaviour == ShapeResizingBehaviour.FixedWidth) { shape.SetSize(new SizeD(shape.Size.Width, g.Height + HostMargin)); } else if (shape.ResizingBehaviour == ShapeResizingBehaviour.FixedHeight) { shape.SetSize(new SizeD(g.Width + HostMargin, shape.Size.Height)); } } ApplyShapesLayout(g, shapesMap, g.Left, g.Top); // update absolute location of shapes UpdateAbsoluteLocation(shape); }