Пример #1
0
        /// <summary>
        /// Return a ConnectionLeg which contains draw instructions for a line that runs
        /// from the DepartureSide of a shape to the location of the orbit that runs
        /// around the shape.
        /// </summary>
        /// <param name="FromShape"></param>
        /// <param name="DepartureSide"></param>
        /// <returns></returns>
        public static ConnectionLeg DrawLegToOrbit(Shape FromShape, WhichSide DepartureSide)
        {
            var           sideCoor    = FromShape.GetSide(DepartureSide);
            var           midPt       = sideCoor.MidPoint;
            double        lgthToOrbit = 30;
            ConnectionLeg leg         = null;

            // draw line depending on the side of the shape.
            LineCoordinates legCoor  = null;
            var             whichDir = DepartureSide.ToDirection();

            legCoor = new LineCoordinates(midPt, new LineVector(lgthToOrbit, whichDir));

            // line is off the canvas. do not create a connection leg.
            if ((legCoor.Start.X < 0) || (legCoor.Start.Y < 0) || (legCoor.End.X < 0) ||
                (legCoor.End.Y < 0))
            {
                leg = null;
            }

            else
            {
                leg = new ConnectionLeg()
                {
                    Start     = midPt,
                    LineCoor  = legCoor,
                    Direction = whichDir
                };
            }

            return(leg);
        }
Пример #2
0
        public void AddLeg(ConnectionLeg Connector)
        {
            var node = new LinkedListNode <ConnectionLeg>(Connector);

            Connector.Node = node;
            this.LegList.AddLast(node);
        }
Пример #3
0
        public static ConnectionLeg DrawLegToShape(
            Shape FromShape, Shape ToShape, ConnectionLeg LastLeg,
            WhichDirection Direction)
        {
            ConnectionLeg   leg     = null;
            LineCoordinates legCoor = null;

            var toShapeInfo = ToShape.DirectionToShape(LastLeg.End);

            // start point of the leg.
            var legStart = LastLeg.End;

            // attempt to draw a direct line to the shape.
            if (legCoor == null)
            {
                legCoor = ConnectionRoute.TryDrawDirectLineToShape(
                    toShapeInfo, legStart, Direction);
            }

            // drawing a vertical line. draw it to the halfway point of the vertical side
            // of the shape.
            if ((legCoor == null) &&
                Direction.IsVertical() &&
                (toShapeInfo.VertDirection.Equals(Direction)))
            {
                var toPoint = new Point(legStart.X, toShapeInfo.VertSide.MidPoint.Y);
                legCoor = new LineCoordinates(legStart, toPoint);
            }

            // drawing a horizontal line. draw it to the halfway point of the horiz side of
            // the shape.
            if ((legCoor == null) &&
                Direction.IsHorizontal() &&
                (toShapeInfo.HorizDirection.Equals(Direction)))
            {
                var toPoint = new Point(toShapeInfo.HorizSide.MidPoint.X, legStart.Y);
                legCoor = new LineCoordinates(legStart, toPoint);
            }

            // leg not drawn. The current leg is part of an orbit around a shape. Have to draw to
            // the next corner of the orbit.
            if (legCoor == null)
            {
                var rectMore = ShapeMore.Construct(FromShape);
                legCoor = rectMore.DrawLineToOrbitCorner(legStart, Direction);
            }

            leg = new ConnectionLeg()
            {
                Direction = Direction,
                LineCoor  = legCoor,
                Start     = legStart
            };

            return(leg);
        }
Пример #4
0
        public static ConnectionLeg DrawLegFromPoint(Point FromPoint, LineVector Vector)
        {
            // draw line depending on the side of the shape.
            var legCoor = new LineCoordinates(FromPoint, Vector);

            var leg = new ConnectionLeg()
            {
                Start     = FromPoint,
                LineCoor  = legCoor,
                Direction = Vector.Direction
            };

            return(leg);
        }
Пример #5
0
        public ConnectionLeg DrawInitialLegToShape()
        {
            ConnectionLeg   leg      = null;
            LineCoordinates legCoor  = null;
            Point?          legStart = null;

            // starting side
            var fromSide    = this.FromSide;
            var toShapeInfo = new SideToShapeInfo(fromSide, this.ToShape);

            // the direction of the initial line.
            var dir = fromSide.WhichSide.ToDirection();

            // draw horizontal line staight to the target shape.
            if (toShapeInfo.HorizDirection.Equals(dir) &&
                (toShapeInfo.VertIntersect != null) &&
                (toShapeInfo.VertIntersect.Length > 0))
            {
                var    vi = toShapeInfo.VertIntersect;
                double centeredIntersect1 = vi.Line1Ofs + (vi.Length / 2);
                legStart = vi.Line1.CalcVerticalPointOnLine(centeredIntersect1);
                double centeredIntersect2 = vi.Line2Ofs + (vi.Length / 2);
                Point  toPt = vi.Line2.CalcVerticalPointOnLine(centeredIntersect2);
                legCoor = new LineCoordinates(legStart.Value, toPt);
            }

            // draw vertical staight to the target shape.
            else if (toShapeInfo.VertDirection.Equals(dir) &&
                     (toShapeInfo.HorizIntersect != null) &&
                     (toShapeInfo.HorizIntersect.Length > 0))
            {
                var    hi = toShapeInfo.HorizIntersect;
                double centeredIntersect1 = hi.Line1Ofs + (hi.Length / 2);
                legStart = hi.Line1.CalcHorizontalPointOnLine(centeredIntersect1);
                double centeredIntersect2 = hi.Line2Ofs + (hi.Length / 2);
                Point  toPt = hi.Line2.CalcHorizontalPointOnLine(centeredIntersect2);
                legCoor = new LineCoordinates(legStart.Value, toPt);
            }

            // drawing a vertical line.
            // The end destination shape is in the direction of the vertical line.
            // ( ex: drawing the line down and the shape is below the side )
            // Draw the line to the mid point of the vertical side of the to_shape.
            else if (toShapeInfo.VertDirection.Equals(dir))
            {
                // start the leg at the mid point of the start from side.
                legStart = fromSide.LineCoor.MidPoint;

                // draw the line down ( or up ) to the mid point of the vertical side
                // ( either left or right side ) of the "to shape".
                var toY    = toShapeInfo.VertSide.MidPoint.Y;
                var legEnd = new Point(legStart.Value.X, toY);
                legCoor = new LineCoordinates(legStart.Value, legEnd);
            }

            // drawing a horizontal line.
            // The end destination shape is in the direction of the horizontal line.
            // ( ex: drawing the line to the right and the shape is to the righ of the side )
            // Draw the line to the mid point of the horizonntal side of the to_shape.
            else if (toShapeInfo.HorizDirection.Equals(dir))
            {
                // start the leg at the mid point of the start from side.
                legStart = fromSide.LineCoor.MidPoint;

                // draw the line left ( or right ) to the mid point of the horiz side
                var toX    = toShapeInfo.HorizSide.MidPoint.X;
                var legEnd = new Point(toX, legStart.Value.Y);

                legCoor = new LineCoordinates(legStart.Value, legEnd);
            }

            // create the leg.
            if (legCoor != null)
            {
                leg = new ConnectionLeg()
                {
                    Direction = dir,
                    LineCoor  = legCoor,
                    Start     = legStart.Value
                };
            }

            // draw a short line from the shape to the next available orbit location
            // around the from shape.
            else
            {
                leg = ConnectionLeg.DrawLegToOrbit(this.FromSide.Shape, this.FromSide.WhichSide);
            }

            return(leg);
        }