Esempio n. 1
0
        /// <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()));
            }
            }
        }