/// <summary> /// a helper function to creat a node boundary curve /// </summary> /// <param name="node">the node</param> /// <param name="width">the node width</param> /// <param name="height">the node height</param> /// <returns></returns> public static ICurve GetNodeBoundaryCurve(Node node, double width, double height) { if (node == null) { throw new InvalidOperationException(); } NodeAttr nodeAttr = node.Attr; switch (nodeAttr.Shape) { case Shape.Ellipse: case Shape.DoubleCircle: return(CurveFactory.CreateEllipse(width, height, new P2(0, 0))); case Shape.Circle: { double r = Math.Max(width / 2, height / 2); return(CurveFactory.CreateEllipse(r, r, new P2(0, 0))); } case Shape.Box: if (nodeAttr.XRadius != 0 || nodeAttr.YRadius != 0) { return(CurveFactory.CreateRectangleWithRoundedCorners(width, height, nodeAttr.XRadius, nodeAttr.YRadius, new P2(0, 0))); } return(CurveFactory.CreateRectangle(width, height, new P2(0, 0))); case Shape.Diamond: return(CurveFactory.CreateDiamond( width, height, new P2(0, 0))); case Shape.House: return(CurveFactory.CreateHouse(width, height, new P2())); case Shape.InvHouse: return(CurveFactory.CreateInvertedHouse(width, height, new P2())); case Shape.Hexagon: return(CurveFactory.CreateHexagon(width, height, new P2())); case Shape.Octagon: return(CurveFactory.CreateOctagon(width, height, new P2())); #if TEST_MSAGL case Shape.TestShape: return(CurveFactory.CreateTestShape(width, height)); #endif default: { return(new Ellipse( new P2(width / 2, 0), new P2(0, height / 2), new P2())); } } }
private void TestShowAllPaths(VisibilityVertex source, VertexEntry mostRecentlyExtendedPath) { // ReSharper restore UnusedMember.Local var edges = GetAllEdgesTest(source).Select(e => (ICurve)(new LineSegment(e.SourcePoint, e.TargetPoint))). Select(c => new DebugCurve(c)); var q = queue.Select(ent => CurveFactory.CreateDiamond(2, 2, ent.Vertex.Point)).Select(c => new DebugCurve(c)); var so = new[] { new DebugCurve(1, "brown", new Ellipse(3, 3, source.Point)), new DebugCurve(1, "purple", CurveFactory.CreateDiamond(4, 4, Target.Point)), new DebugCurve(1, "red", CurveFactory.CreateDiamond(6, 6, mostRecentlyExtendedPath.Vertex.Point)) }; var pathEdges = new List <DebugCurve>(); var newEntries = new List <VertexEntry>(); var count = this.visitedVertices.Count; for (int ii = 0; ii < count; ++ii) { var vertex = this.visitedVertices[ii]; if (vertex.VertexEntries == null) { continue; // this is the source vertex } foreach (var entry in vertex.VertexEntries) { if (entry == null) { continue; } var color = "green"; if (entry.PreviousEntry == mostRecentlyExtendedPath) { newEntries.Add(entry); color = "red"; } else if (!entry.IsClosed) { color = "yellow"; } pathEdges.Add(new DebugCurve(2, color, new LineSegment(entry.PreviousVertex.Point, vertex.Point))); } } Debug.WriteLine("entry {0} seq = {1} len = {2} nbend = {3} ccost = {4} hcost = {5} iters = {6}/{7}", mostRecentlyExtendedPath, this.lastDequeueTimestamp, mostRecentlyExtendedPath.Length, mostRecentlyExtendedPath.NumberOfBends, this.CombinedCost(mostRecentlyExtendedPath.Length, mostRecentlyExtendedPath.NumberOfBends), this.HeuristicDistanceFromVertexToTarget(mostRecentlyExtendedPath.Vertex.Point, mostRecentlyExtendedPath.Direction), this.currentIterations, totalIterations); foreach (var newEntry in newEntries) { Debug.WriteLine(" newEntry {0} len = {1} nbend = {2} ccost = {3} hcost = {4}", newEntry, newEntry.Length, newEntry.NumberOfBends, this.CombinedCost(newEntry.Length, newEntry.NumberOfBends), this.HeuristicDistanceFromVertexToTarget(newEntry.Vertex.Point, newEntry.Direction)); } DevTraceDisplay(edges.Concat(q).Concat(so).Concat(pathEdges)); }
static internal void ShowHubs(MetroGraphData metroGraphData, IMetroMapOrderingAlgorithm metroMapOrdering, Station station) { var ttt = GetAllDebugCurves(metroMapOrdering, metroGraphData); if (station != null) { ttt = ttt.Concat(new[] { new DebugCurve(255, 3, "pink", CurveFactory.CreateDiamond(20, 20, station.Position)) }); } LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(ttt); }
private void TestShowPath(VisibilityVertex source, IEnumerable <Point> pathPoints, double cost, double length, int numberOfBends) { // ReSharper restore UnusedMember.Local var edges = GetAllEdgesTest(source).Select(e => (ICurve)(new LineSegment(e.SourcePoint, e.TargetPoint))). Select(c => new DebugCurve(c)); var so = new[] { new DebugCurve(1, "brown", new Ellipse(3, 3, source.Point)), new DebugCurve(1, "purple", CurveFactory.CreateDiamond(4, 4, Target.Point)), }; List <DebugCurve> pathEdges = GetPathEdgeDebugCurves(pathPoints, "green"); System.Diagnostics.Debug.WriteLine("path {0} -> {1} cost = {2} len = {3} nbend = {4} iters = {5}/{6}", source.Point, this.Target.Point, cost, length, numberOfBends, this.currentIterations, totalIterations); DevTraceDisplay(edges.Concat(so).Concat(pathEdges)); }
// ReSharper disable UnusedMember.Local void ShowGraphLocal() { // ReSharper restore UnusedMember.Local var l = new List <ICurve>(); l.Clear(); foreach (var e in geometryGraph.Edges) { { l.Add(new Ellipse(2, 2, e.Curve.Start)); l.Add(CurveFactory.CreateDiamond(5, 5, e.Curve.End)); l.Add(e.Curve); } } SplineRouter.ShowVisGraph(VisibilityGraph, LooseHierarchy.GetAllLeaves(), null, l); }
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); }
static void Main(string[] args) { var drawingGraph = new Graph(); drawingGraph.AddNode("A").LabelText = "AText"; drawingGraph.AddNode("B").LabelText = "BText"; var e = drawingGraph.AddEdge("A", "B"); // now the drawing graph has nodes A,B and and an edge A -> B\ // the geometry graph is still null, so we are going to create it e.LabelText = "from " + e.SourceNode.LabelText + " to " + e.TargetNode.LabelText; drawingGraph.CreateGeometryGraph(); // Now the drawing graph elements point to the corresponding geometry elements, // however the node boundary curves are not set. // Setting the node boundaries int i = 0; foreach (var n in drawingGraph.Nodes) { if (i % 2 == 0) { // Ideally we should look at the drawing node attributes, and figure out, the required node size // I am not sure how to find out the size of a string rendered in SVG. Here, we just blindly assign // to each node a rectangle with width 60 and height 40, and round its corners. n.GeometryNode.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(60, 40, 3, 2, new Point(0, 0)); } else { n.GeometryNode.BoundaryCurve = CurveFactory.CreateDiamond(60, 80, new Point(0, 0)); n.Attr.Shape = Shape.Diamond; } ++i; } AssignLabelsDimensions(drawingGraph); LayoutHelpers.CalculateLayout(drawingGraph.GeometryGraph, new SugiyamaLayoutSettings(), null); PrintSvgAsString(drawingGraph); }
private static IEnumerable <DebugCurve> MarkPathVerts(Path path) { bool first = true; var p = new Point(); foreach (var p0 in path.PathPoints) { if (first) { yield return(new DebugCurve(200, 1, "violet", CurveFactory.CreateDiamond(5, 5, p0))); first = false; } else { yield return(new DebugCurve(100, 0.5, "brown", CurveFactory.CreateEllipse(1.5, 1.5, p0))); } p = p0; } yield return(new DebugCurve(200, 1, "green", CurveFactory.CreateDiamond(3, 3, p))); }
/// <summary> /// Controlling the draw because a need to control the size. /// /// Supporting these shapes : /// Box /// Ellipse /// Circle /// Plaintext /// Point /// </summary> /// <param name="node"></param> /// <param name="centerLocation"></param> /// <param name="width"></param> /// <param name="hight"></param> /// <returns></returns> ICurve DrawCurve(Microsoft.Msagl.Drawing.Node node) { ICurve shape = null; switch (node.Attr.Shape) { case Shape.Box: shape = CurveFactory.CreateRectangle(NodeWidth, NodeHeight, NodeCenter); break; case Shape.Ellipse: shape = CurveFactory.CreateEllipse(NodeWidth, NodeHeight, NodeCenter); break; case Shape.Circle: shape = CurveFactory.CreateCircle(NodeWidth, NodeCenter); break; case Shape.Point: shape = CurveFactory.CreateCircle(0.5, NodeCenter); break; case Shape.Diamond: shape = CurveFactory.CreateDiamond(NodeWidth, NodeHeight, NodeCenter); break; case Shape.Hexagon: shape = CurveFactory.CreateHexagon(NodeWidth, NodeHeight, NodeCenter); break; case Shape.Octagon: shape = CurveFactory.CreateOctagon(NodeWidth, NodeHeight, NodeCenter); break; } return(shape); }
public static ICurve GetNodeBoundary(Microsoft.Msagl.Drawing.Node n) { double cell = s_random.Next(50, 80); double ecc = (((double)s_random.Next(20, 100) / 100.00) * cell); switch (n.Id.Split()[0]) { case "Rhombus": return(CurveFactory.CreateDiamond(cell / 2.0, ecc / 2.0, new Microsoft.Msagl.Core.Geometry.Point())); case "Circle": return(CurveFactory.CreateCircle(cell / 2.0, new Microsoft.Msagl.Core.Geometry.Point())); case "Ellipse": return(CurveFactory.CreateEllipse(cell / 2.0, ecc / 2.0, new Microsoft.Msagl.Core.Geometry.Point())); case "Rectangle": return(CurveFactory.CreateRectangle(cell, ecc, new Point())); case "Parallelogram": { ICurve baseRect = CurveFactory.CreateRectangle(cell, ecc, new Point()); return(baseRect.Transform(new PlaneTransformation(1, (double)s_random.Next(0, 100) / 100.00, 0, 0, 1, 0))); } case "CurvedRectangle": return(CurveFactory.CreateRectangleWithRoundedCorners(cell * 2, ecc, ecc / 4, ecc / 4, new Microsoft.Msagl.Core.Geometry.Point())); case "Process": { Curve curve = (Curve)CurveFactory.CreateRectangle(cell * 2, ecc, new Microsoft.Msagl.Core.Geometry.Point()); Curve curveInner = (Curve)CurveFactory.CreateRectangle(cell * 1.5, ecc, new Microsoft.Msagl.Core.Geometry.Point()); Curve.CloseCurve(curve); Curve.CloseCurve(curveInner); Curve.AddLineSegment(curve, curve.Start, curveInner.Start); curve.AddSegment(curveInner); return(curve); } case "ElongatedEllipse": { var curve = new Curve(); double x = cell; double y = ecc; double r = x / 2; curve.AddSegment(new Ellipse(1.5 * Math.PI, 2.5 * Math.PI, new Point(r, 0), new Point(0, y), new Point(x, 0))); curve.AddSegment(new LineSegment(curve.End, new Point(-1 * x, y))); curve.AddSegment(new Ellipse(0.5 * Math.PI, 1.5 * Math.PI, new Point(r, 0), new Point(0, y), new Point(-1 * x, 0))); Curve.CloseCurve(curve); return(curve); } case "Database": { var curve = new Curve(); double x = ecc; double y = cell; double r = y / 2; curve.AddSegment(new Ellipse(new Point(x, 0), new Point(0, r), new Point(0, 0))); curve.AddSegment(new Ellipse(0, Math.PI, new Point(x, 0), new Point(0, r), new Point(0, 0))); curve.AddSegment(new LineSegment(curve.End, new Point(-1 * x, -1 * y))); curve.AddSegment(new LineSegment(curve.End, new Point(x, -1 * y))); Curve.CloseCurve(curve); return(curve); } } throw new Exception("unrecognised shape type"); }