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); }
/// <summary> /// Fill and return a SideToShapeInfo object with info on /// </summary> /// <param name="Shape"></param> /// <param name="Side"></param> /// <returns></returns> public static SideToShapeInfo DirectionToShape(this Shape Shape, ShapeSide Side) { var info = new SideToShapeInfo(Side, Shape); return info; }