Exemple #1
0
 private IHoldBusesUI NextBackwards(BusCore bus)
 {
     for (int i = ways.Count - 1; i >= 0; i--)
     {
         if (BusAt(bus.Current, ways[i]))
         {
             return(i > 1 ? ways[i - 1] : ways.First());
         }
     }
     throw new Exception();
 }
Exemple #2
0
 private IHoldBusesUI NextForward(BusCore bus)
 {
     for (int i = 0; i < ways.Count; i++)
     {
         if (BusAt(bus.Current, ways[i]))
         {
             return(i < ways.Count - 1 ? ways[i + 1] : ways.First());
         }
     }
     throw new Exception();
 }
Exemple #3
0
        public IHoldBusesUI Next(BusCore bus)
        {
            if (bus.Current is null)
            {
                return(ways.First());
            }

            if (bus.IsForward)
            {
                return(NextForward(bus));
            }
            else
            {
                return(NextBackwards(bus));
            }
        }
Exemple #4
0
        public void UpdatePos(BusCore bus, int delay)
        {
            int segments = Delay;
            var pos      = CalculateCoordinate(bus, segments, delay);

            //Debug.WriteLine($"Bus #{bus.SimulationModel} set to [{(int)pos.X}:{(int)pos.Y}]");

            bus.View.Dispatcher.Invoke(() =>
            {
                Canvas.SetLeft(bus.View, pos.X);
                Canvas.SetTop(bus.View, pos.Y);
                if (!canvas.Children.Contains(bus.View))
                {
                    canvas.Children.Add(bus.View);
                }
            });
        }
Exemple #5
0
        public void AddBus(BusCore bus)
        {
            buses.Add(bus);
            var pos = CalculateCoordinate(bus, road.Length, road.Length);

            //double x = CalculateLeft(bus, _simulationModel.Length, _simulationModel.Length);
            //double y = CalculateTop(bus, _simulationModel.Length, _simulationModel.Length);

            bus.View.Dispatcher.Invoke(() =>
            {
                Canvas.SetLeft(bus.View, pos.X);
                Canvas.SetTop(bus.View, pos.Y);
                if (!canvas.Children.Contains(bus.View))
                {
                    canvas.Children.Add(bus.View);
                }
            });
        }
Exemple #6
0
        private Point CalculateCoordinate(BusCore bus, int segments, int segment)
        {
            double x, y;
            double lX1 = 0, lX2 = 0;
            double lY1 = 0, lY2 = 0;
            double prevX = 0, prevY = 0;
            bool   left = false, up = false;

            View.Dispatcher.Invoke(() =>
            {
                lX1 = line.X1; // + padding;
                lX2 = line.X2; // - padding;
                lY1 = line.Y1;
                lY2 = line.Y2;
            });

            bus.Previous.View.Dispatcher.Invoke(() =>
            {
                prevY = Canvas.GetTop(bus.Previous.View);
                prevX = Canvas.GetLeft(bus.Previous.View);
                left  = Math.MaxMagnitude(prevX - lX1, prevX - lX2) != prevX - lX1;
                up    = Math.MaxMagnitude(prevY - lY1, prevY - lY2) != prevY - lY1;
            });

            x = left ? CalculateCoordinate(lX1, lX2, segments, segment) : CalculateCoordinate(lX2, lX1, segments, segment);
            y = up   ? CalculateCoordinate(lY1, lY2, segments, segment) : CalculateCoordinate(lY2, lY1, segments, segment);
            if (!up && !left)
            {
                x -= padding;
                y += padding;
            }

            if (up && left)
            {
                x += padding;
                y -= padding;
            }

            return(new Point(x, y));
        }
Exemple #7
0
 public void RemoveBus(BusCore bus)
 {
     buses.Remove(bus);
 }