Пример #1
0
        public static ConnectionRoute DrawRouteBetweenShapes(
            this Canvas InCanvas, Shape Shape1, Shape Shape2)
        {
            ConnectionRoute selectedRoute = null;

            // for each direction from the from shape.
            var possibleRoutes = new List <ConnectionRoute>();

            foreach (var dir in WhichDirectionExt.Directions())
            {
                var side = new ShapeSide(Shape1, dir.ToSide());

                var route = new ConnectionRoute(side, Shape2);

                {
                    var leg = route.DrawInitialLegToShape();
                    if (leg == null)
                    {
                        continue;
                    }
                    route.AddLeg(leg);
                }
                while (true)
                {
                    if (Shape2.Intersects(route.LastLeg.End))
                    {
                        break;
                    }

                    var leg = route.DrawLegToShape();

                    route.AddLeg(leg);
                }

                // add the route to the possible routes list.
                possibleRoutes.Add(route);
            }

            // select the route with the fewest number of legs.
            foreach (var route in possibleRoutes)
            {
                if (selectedRoute == null)
                {
                    selectedRoute = route;
                }
                else if (route.LegCount < selectedRoute.LegCount)
                {
                    selectedRoute = route;
                }
            }

            if (selectedRoute != null)
            {
                InCanvas.DrawLinesOfRoute(selectedRoute);
                Shape1.StoreConnection(selectedRoute, Shape2);
                Shape2.StoreConnection(selectedRoute, Shape1);
            }

            return(selectedRoute);
        }
Пример #2
0
        public static ConnectionRoute StartConnectionRouteToShape(
            Shape FromShape, WhichSide StartSide, Shape ToShape)
        {
            var             fromSide = new ShapeSide(FromShape, StartSide);
            ConnectionRoute route    = new ConnectionRoute(fromSide, ToShape);

            return(route);
        }
Пример #3
0
 public ConnectionRoute(ShapeSide FromSide, Shape ToShape)
 {
     this.FromSide = FromSide;
     this.ToShape  = ToShape;
 }
Пример #4
0
 /// <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;
 }