private static ICurve GetRandomShape(Random random) { //we support rectangle, roundedRectangle, circle, ellipse, diamond, Octagon, triangle, star int index = random.Next(8); switch (index) { case 0: return(CurveFactory.CreateRectangle(25, 15, new Microsoft.Msagl.Core.Geometry.Point())); case 1: return(CurveFactory.CreateRectangleWithRoundedCorners(35, 25, 3, 3, new Microsoft.Msagl.Core.Geometry.Point())); case 2: return(CurveFactory.CreateCircle(19, new Microsoft.Msagl.Core.Geometry.Point())); case 3: return(CurveFactory.CreateEllipse(26, 18, new Microsoft.Msagl.Core.Geometry.Point())); case 4: return(CurveFactory.CreateDiamond(25, 15, new Microsoft.Msagl.Core.Geometry.Point())); case 5: return(CurveFactory.CreateOctagon(25, 15, new Microsoft.Msagl.Core.Geometry.Point())); case 6: return(CurveFactory.CreateInteriorTriangle(30, 20, new Microsoft.Msagl.Core.Geometry.Point())); case 7: return(CurveFactory.CreateStar(33, new Microsoft.Msagl.Core.Geometry.Point())); } return(null); }
/// <summary> /// Shows the current state of the algorithm for debug purposes. /// </summary> /// <param name="treeEdges"></param> /// <param name="proximityEdges"></param> /// <param name="nodeSizes"></param> /// <param name="nodePos"></param> /// <param name="rootId"></param> void ShowAndMoveBoxesRemoveLater(List <Tuple <int, int, double, double, double> > treeEdges, List <Tuple <int, int, double, double, double> > proximityEdges, Size[] nodeSizes, Point[] nodePos, int rootId) { var l = new List <DebugCurve>(); foreach (var tuple in proximityEdges) { l.Add(new DebugCurve(100, 0.5, "black", new LineSegment(nodePos[tuple.Item1], nodePos[tuple.Item2]))); } //just for debug var nodeBoxes = new Rectangle[nodeSizes.Length]; for (int i = 0; i < nodePos.Length; i++) { nodeBoxes[i] = new Rectangle(nodeSizes[i], nodePos[i]); } l.AddRange(nodeBoxes.Select(b => new DebugCurve(100, 0.3, "green", b.Perimeter()))); if (treeEdges != null) { l.AddRange( treeEdges.Select( e => new DebugCurve(200, GetEdgeWidth(e), "red", new LineSegment(nodePos[e.Item1], nodePos[e.Item2])))); } if (rootId >= 0) { l.Add(new DebugCurve(100, 10, "blue", CurveFactory.CreateOctagon(30, 30, nodePos[rootId]))); } LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(l); }
private static ICurve CreateLabelAndBoundary(NavigationPoint navigationPoint, Microsoft.Msagl.Drawing.Node node) { node.Attr.LabelMargin *= 2; node.Label.IsVisible = false; var y = (navigationPoint.Latitude - airfield.Latitude) * 200000; var x = (navigationPoint.Longitude - airfield.Longitude) * 200000; var positionalPoint = new Microsoft.Msagl.Core.Geometry.Point(x, y); switch (navigationPoint) { case Runway _: node.Attr.Color = Color.Green; return(CurveFactory.CreateCircle(50, positionalPoint)); case Junction _: node.Attr.Shape = Shape.Hexagon; node.Attr.Color = Color.Blue; return(CurveFactory.CreateHexagon(100, 30, positionalPoint)); case ParkingSpot _: node.Attr.Color = Color.Orange; return(CurveFactory.CreateOctagon(100, 30, positionalPoint)); case WayPoint _: node.Attr.Color = Color.Purple; return(CurveFactory.CreateRectangle(100, 30, positionalPoint)); } return(CurveFactory.CreateCircle(5, positionalPoint)); }
/// <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 DEBUG case Shape.TestShape: return(CurveFactory.CreateTestShape(width, height)); #endif default: { // Console.WriteLine("creating ellipse for shape {0}",nodeAttr.Shape); return(new Ellipse( new P2(width / 2, 0), new P2(0, height / 2), new P2())); } } }
/// <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); }