public void CalculateLayout_ReportsAllProgress() { GeometryGraph treeGraph = GraphGenerator.GenerateTree(20); var settings = new FastIncrementalLayoutSettings(); InitialLayout layout = new InitialLayout(treeGraph, settings); double progress = 0.0; EventHandler<ProgressChangedEventArgs> handler = (s, e) => progress = e.RatioComplete; try { layout.ProgressChanged += handler; layout.Run(); } finally { layout.ProgressChanged -= handler; } Assert.AreEqual(0, treeGraph.BoundingBox.Bottom); Assert.AreEqual(0, treeGraph.BoundingBox.Left); foreach (var v in treeGraph.Nodes) { Assert.IsTrue(treeGraph.BoundingBox.Contains(v.BoundingBox)); } Assert.AreEqual(1.0, progress, "Progress was never reported as 100%. Last update was at " + progress + "%"); }
/// <summary> /// The load content. /// </summary> public override void LoadContent() { this.mainFrame = new Rectangle( 0, 0, (int)DisplayManager.Instance.Dimensions.X, (int)DisplayManager.Instance.Dimensions.Y); this.background = TexturesManager.Instance.GetTexture("Menu", "background"); this.initialGui = new InitialLayout(PointTextures.TransparentPoint); }
/// <summary> /// Calculates the graph layout /// </summary> /// <exception cref="CancelException">Thrown when the layout is canceled.</exception> #else /// <summary> /// Calculates the graph layout /// </summary> /// <exception cref="System.OperationCanceledException">Thrown when the layout is canceled.</exception> #endif public static void CalculateLayout(GeometryGraph geometryGraph, LayoutAlgorithmSettings settings, CancelToken cancelToken) { Console.WriteLine("starting CalculateLayout"); if (settings is RankingLayoutSettings) { var rankingLayoutSettings = settings as RankingLayoutSettings; var rankingLayout = new RankingLayout(rankingLayoutSettings, geometryGraph); rankingLayout.Run(cancelToken); RouteAndLabelEdges(geometryGraph, settings, geometryGraph.Edges); } else if (settings is MdsLayoutSettings) { var mdsLayoutSettings = settings as MdsLayoutSettings; var mdsLayout = new MdsGraphLayout(mdsLayoutSettings, geometryGraph); mdsLayout.Run(cancelToken); if (settings.EdgeRoutingSettings.EdgeRoutingMode != EdgeRoutingMode.None) { RouteAndLabelEdges(geometryGraph, settings, geometryGraph.Edges); } } else if (settings is FastIncrementalLayoutSettings) { var incrementalSettings = settings as FastIncrementalLayoutSettings; incrementalSettings.AvoidOverlaps = true; var initialLayout = new InitialLayout(geometryGraph, incrementalSettings); initialLayout.Run(cancelToken); if (settings.EdgeRoutingSettings.EdgeRoutingMode != EdgeRoutingMode.None) { RouteAndLabelEdges(geometryGraph, settings, geometryGraph.Edges); } //incrementalSettings.IncrementalRun(geometryGraph); } else { var sugiyamaLayoutSettings = settings as SugiyamaLayoutSettings; if (sugiyamaLayoutSettings != null) { ProcessSugiamaLayout(geometryGraph, sugiyamaLayoutSettings, cancelToken); } else { Debug.Assert(settings is LgLayoutSettings); LayoutLargeGraphWithLayers(geometryGraph, settings, cancelToken); } } }
public void SimpleClusterGraphRectilinear() { var g = new GeometryGraph(); var node0 = new Node(CurveFactory.CreateRectangle(10, 10, new Point()), 0); var node1 = new Node(CurveFactory.CreateRectangle(10, 10, new Point()), 1); var cluster = new Cluster(new[] { node1 }); cluster.UserData = 2; cluster.BoundaryCurve = CurveFactory.CreateRectangle(10, 10, new Point()); var edge = new Edge(node0, node1) { Length = 100 }; g.Nodes.Add(node0); g.Nodes.Add(node1); g.Edges.Add(edge); var cluster2 = new Cluster(new[] { node0 }, new[] { cluster }); cluster2.UserData = 3; cluster2.BoundaryCurve = CurveFactory.CreateRectangle(10, 10, new Point()); g.RootCluster = cluster2; InitialLayout initialLayout = new InitialLayout(g, new FastIncrementalLayoutSettings() { AvoidOverlaps = true }); initialLayout.Run(); RectilinearEdgeRouter router = new RectilinearEdgeRouter(g, 1, 1, false); router.Run(); EnableDebugViewer(); ShowGraphInDebugViewer(g); var bb0 = node0.BoundingBox; bb0.Pad(1); Assert.IsTrue(bb0.Contains(edge.EdgeGeometry.Curve.Start)); var bb1 = node1.BoundingBox; bb1.Pad(1); Assert.IsTrue(bb1.Contains(edge.EdgeGeometry.Curve.End)); }
static void TestFD() { GeometryGraph graph = CreateGeometryGraphForFD(); //LayoutAlgorithmSettings.ShowGraph(graph); var settings = new FastIncrementalLayoutSettings { AvoidOverlaps = true, ApplyForces = false, RungeKuttaIntegration = true }; var ir = new InitialLayout(graph, settings); ir.Run(); RouteEdges(graph, settings); //LayoutAlgorithmSettings.ShowGraph(graph); // AddNodeFd(graph); var n = new Node(CurveFactory.CreateDiamond(200, 200, new Point(350, 230))); var e = new Edge(n, graph.Nodes[42]); graph.Edges.Add(e); e = new Edge(n, graph.Nodes[6]); graph.Edges.Add(e); e = new Edge(n, graph.Nodes[12]); graph.Edges.Add(e); graph.Nodes.Add(n); graph.RootCluster.AddChild(n); settings.algorithm = new FastIncrementalLayout(graph, settings, settings.MaxConstraintLevel, f => settings); settings.Unconverge(); settings.CreateLock(n, new Rectangle(200, 400, 500, 100)); do { settings.IncrementalRun(graph); } while (!settings.Converged); RouteEdges(graph, settings); #if TEST_MSAGL LayoutAlgorithmSettings.ShowGraph(graph); #endif Environment.Exit(0); }
private static void LayoutAndValidate(GeometryGraph graph, double separationRatio, ISet <Node> validationExcludedNodes) { const double downwardEdgeSeparation = 70; FastIncrementalLayoutSettings settings = new FastIncrementalLayoutSettings(); settings.IdealEdgeLength = new IdealEdgeLengthSettings { ConstrainedEdgeSeparation = downwardEdgeSeparation, EdgeDirectionConstraints = Directions.South }; settings.AvoidOverlaps = true; InitialLayout initialLayout = new InitialLayout(graph, settings); initialLayout.Run(); ShowGraphInDebugViewer(graph); ValidateDownwardEdgeConstraints(graph, downwardEdgeSeparation, validationExcludedNodes); }
private void ApplyLayout(GeometryGraph geometryGraph) { InitialLayout initialLayout = new InitialLayout(geometryGraph, new FastIncrementalLayoutSettings() { AvoidOverlaps = true }); initialLayout.Run(); RectilinearEdgeRouter router = new RectilinearEdgeRouter(geometryGraph, 1, 1, false); router.Run(); foreach (var msNode in geometryGraph.Nodes) { Entity entity = (Entity)msNode.UserData; AddPositionComponent(entity, msNode.BoundingBox.LeftTop); Console.WriteLine($"{entity.Name} is at {msNode.BoundingBox.LeftTop}"); } }
private void LayoutAndValidate(bool defaultSticky, double separation, double minSeparation, double maxSeparation) { InitialLayout initialLayout = new InitialLayout(graph, settings); initialLayout.Run(); // Apply incremental layout to satisfy constraints. settings.IncrementalRun(graph); //ShowGraphInDebugViewer(graph); // stick constraints have a little slack in their projection const double StickDelta = 1; double distance = (constrainedNodes[0].Center - constrainedNodes[1].Center).Length; if (defaultSticky) { Assert.AreEqual(separation, distance, StickDelta, string.Format("Distance {3} between node {0} to node {1} not approximately equal to stickConstraint separation {2}", constrainedNodes[0].UserData, constrainedNodes[1].UserData, separation, distance)); } else { Assert.IsTrue(distance >= minSeparation && distance <= maxSeparation, string.Format("Distance {4} between node {0} to node {1} not between min {2} and max {3}", constrainedNodes[0].UserData, constrainedNodes[1].UserData, minSeparation, maxSeparation, distance)); } }
private void Layout(bool repositionateAll) { if (settings != null && repositionateAll) { settings.ClearLocks(); return; } if (cancelToken != null) { cancelToken.Canceled = true; } try { var scenes = Controller.Instance.ChapterList.getSelectedChapterDataControl().getScenesList(); // Layout algorithm settings = new Microsoft.Msagl.Layout.Incremental.FastIncrementalLayoutSettings { EdgeRoutingSettings = new EdgeRoutingSettings { EdgeRoutingMode = EdgeRoutingMode.StraightLine, Padding = 10 }, AvoidOverlaps = true, ApplyForces = false, RungeKuttaIntegration = true, NodeSeparation = 10, PackingMethod = PackingMethod.Compact }; var canvasRect = new Rect(0, 0, SPACE_WIDTH, SPACE_HEIGHT); // Graph graph = new GeometryGraph { BoundingBox = new Microsoft.Msagl.Core.Geometry.Rectangle(0, 0, SPACE_WIDTH, SPACE_HEIGHT) }; sceneToNode = new Dictionary <SceneDataControl, Node>(); sceneLockPositions = new Dictionary <SceneDataControl, LockPosition>(); var present = new Dictionary <Tuple <Node, Node>, bool>(); foreach (var scene in scenes.getScenes()) { sizes.Remove(scene.getPreviewBackground()); var rect = ToGraphRect(GetSceneRect(scene, true), canvasRect, graph.BoundingBox); var node = new Node(CurveFactory.CreateRectangle(rect), scene.getId()); /*if (!repositionateAll && rect.LeftBottom != new Point(0,0)) * { * sceneLockPositions.Add(scene, settings.CreateLock(node, rect)); * }*/ graph.Nodes.Add(node); graph.RootCluster.AddChild(node); sceneToNode.Add(scene, node); } foreach (var scene in scenes.getScenes()) { var node = sceneToNode[scene]; foreach (var exit in scene.getExitsList().getExits()) { var index = scenes.getSceneIndexByID(exit.getNextSceneId()); // If the exit points to a cutscene it normally is out of the array if (index < 0 || index >= scenes.getScenes().Count) { continue; } var nextScene = scenes.getScenes()[index]; var t = new Tuple <Node, Node>(node, sceneToNode[nextScene]); if (!present.ContainsKey(t)) { present.Add(t, true); graph.Edges.Add(new Edge(node, sceneToNode[nextScene])); var exitOrigin = GetExitArea(scene, exit, true).ToRect().center; var originRect = GetSceneRect(scene, true); var pos = exitOrigin - originRect.position; pos.x = Mathf.Clamp01(pos.x / originRect.width); pos.y = Mathf.Clamp01(pos.y / originRect.height); // Positioning constraints /*if (pos.x < 0.3) * { * settings.AddStructuralConstraint(new LeftRightConstraint(t.Item2, t.Item1)); * } * if (pos.x > 0.7) * { * settings.AddStructuralConstraint(new LeftRightConstraint(t.Item1, t.Item2)); * }*/ } } } var ir = new InitialLayout(graph, settings); ir.Run(); // Do the layouting UpdatePositions(); } catch (Exception ex) { Debug.LogError(ex.Message + " : " + ex.StackTrace); } }