示例#1
0
 public bool AddCarStream(CarStream c)
 {
     if (c != null)
     {
         this.ListOfCarStreams.Add(c);
         return(true);
     }
     return(false);
 }
示例#2
0
        public void RemoveCarStream(Point startPoint)
        {
            CarStream carStreamToRemove = null;

            foreach (CarStream carstream in this.ListOfCarStreams)
            {
                if (carstream.Road.First() == startPoint)
                {
                    carStreamToRemove = carstream;
                }
            }
            if (carStreamToRemove != null)
            {
                this.ListOfCarStreams.Remove(carStreamToRemove);
            }
        }
 public FormCarStream(ref Controller cl, MainForm mf, ref CarStream editedCarStream)
 {
     this.InitializeComponent();
     this.gpNewStream.ForeColor = Color.FromArgb(77, 188, 233);
     this.gpNewStream.BackColor = Color.FromArgb(95, 90, 92);
     this.BackColor             = Color.FromArgb(95, 90, 92);
     this.controler             = cl;
     this.mainForm             = mf;
     this.editCarStream        = editedCarStream;
     this.nmNrCars.Value       = this.editCarStream.CarList.Count();
     this.Text                 = "Edit Car Stream";
     this.btnCreateOrEdit.Text = "Edit stream";
     if (editedCarStream != null)
     {
         this.nmNrCars.Value = editedCarStream.CarList.Count();
     }
     this.Refresh();
 }
示例#4
0
        private void button1_Click(object sender, EventArgs e)
        {
            foreach (Crossing crozz in this.cl.ActiveGrid.ListOfCrossings)
            {
                this.cl.ActiveGrid.MakeNeighbours(crozz);
            }
            this.cl.ActiveGrid.SetAllStartPoints();
            MessageBox.Show(this.cl.ActiveGrid.ListOfAllStartPoints.Count.ToString());

            Lane l = this.cl.ActiveGrid.ListOfCrossings.ElementAt(0).LisftOfLanes.ElementAt(0);

            Crossing c = this.cl.ActiveGrid.ListOfCrossings[0];

            c.UserChosenStartPoint = c.LisftOfLanes[0].Road[0];
            this.cl.ActiveGrid.CreateRoads(c, new List <Point>(), new List <Crossing>());
            CarStream cs = new CarStream(0, 10, this.cl.ActiveGrid.AllRoads.First());

            this.cl.ActiveGrid.AddCarStream(cs);
            this.cl.ActiveGrid.SetCurrentCrossingsToCars();

            MessageBox.Show(this.cl.ActiveGrid.AllRoads.Count.ToString());
            this.Invalidate();
        }
示例#5
0
        private void GridMouseDown_Down(object sender, MouseEventArgs e)
        {
            Point p            = e.Location;
            Point pointClicked = new Point(0, 0);//To be used differently by the different cases

            if (e.Button == MouseButtons.Right)
            {
                mouseMode             = WhatToDo.None;
                RemoveCarStreamToggle = false;
                EditCarStreamToggle   = false;
            }
            if (((p.X >= 240) && (p.X <= 1140)) && ((p.Y >= 30) && (p.Y <= 710)))
            {
                int spotInput = this.cl.ActiveGrid.GetCrossingSlot(p);
                switch (mouseMode)
                {
                case WhatToDo.SimpleCrossing:
                    if (this.cl.ActiveGrid.IsSpotFree(p))
                    {
                        SimpleCrossing cr = new SimpleCrossing(this.cl.ActiveGrid.CrossingSlots[spotInput], spotInput);
                        this.cl.ActiveGrid.AddCrossing(cr, spotInput);
                        this.cl.ActiveGrid.MakeNeighbours(cr);
                        //Reset Mouse mode
                        this.cl.ActiveGrid.IsChanged = true;
                        this.UpdateToolStrip();
                    }
                    else
                    {
                        MessageBox.Show("This slot is already taken, place the crossing on an EMPTY one!");
                    }
                    this.Refresh();
                    break;

                case WhatToDo.ComplexCrossing:
                    if (this.cl.ActiveGrid.IsSpotFree(p))
                    {
                        ComplexCrossing crCom = new ComplexCrossing(this.cl.ActiveGrid.CrossingSlots[spotInput], spotInput);
                        this.cl.ActiveGrid.MakeNeighbours(crCom);
                        this.cl.ActiveGrid.AddCrossing(crCom, spotInput);
                        this.cl.ActiveGrid.IsChanged = true;
                        this.UpdateToolStrip();
                    }
                    else
                    {
                        MessageBox.Show("This slot is already taken, place the crossing on an EMPTY one!");
                    }
                    this.Refresh();
                    break;

                case WhatToDo.RemoveCrossing:
                    Crossing s = this.cl.ActiveGrid.GetCrossing(p);

                    if (this.cl.ActiveGrid.RemoveCrossing(s))
                    {
                        this.Invalidate();
                        this.cl.ActiveGrid.IsChanged = true;
                        this.UpdateToolStrip();
                    }
                    this.Refresh();
                    break;

                case WhatToDo.AddEditCarStream:
                    SelectedStartPoint = this.cl.ActiveGrid.GetStartingPoint(p);
                    if (SelectedStartPoint != new Point(0, 0))
                    {
                        this.cl.ActiveGrid.GetCrossing(SelectedStartPoint).UserChosenStartPoint = SelectedStartPoint;
                        this.cl.ActiveGrid.CreateRoads(this.cl.ActiveGrid.GetCrossing(SelectedStartPoint), new List <Point>(), new List <Crossing>());
                        this.formNewStream = new FormCarStream(ref this.cl, this);
                        this.formNewStream.Show();
                        this.cl.ActiveGrid.ListOfAllStartPoints.Clear();
                    }
                    else
                    {
                        SelectedStartPoint = this.cl.ActiveGrid.FindPointInList(p, this.cl.ActiveGrid.GetAllCarStreamStartPoints(), 10);
                        if (SelectedStartPoint != new Point(0, 0))
                        {
                            CarStream selectedCarStream = this.cl.ActiveGrid.GetCarStreamByStartPoint(SelectedStartPoint);
                            PossibleEndPoints  = this.cl.ActiveGrid.GetAllEndPointsWithStart(SelectedStartPoint);
                            this.formNewStream = new FormCarStream(ref this.cl, this, ref selectedCarStream);
                            this.formNewStream.Show();
                        }
                    }
                    this.Invalidate();
                    this.UpdateToolStrip();

                    break;

                case WhatToDo.AddEditCarStreamEnd:
                    pointClicked = this.cl.ActiveGrid.FindPointInList(p, this.cl.ActiveGrid.GetAllEndPointsWithStart(SelectedStartPoint), 10);
                    if (pointClicked != new Point(0, 0))
                    {
                        SelectedEndPoint = pointClicked;
                        this.formNewStream.Show();
                        PossibleEndPoints.Clear();
                        this.Refresh();
                        this.UpdateToolStrip();
                    }
                    break;

                case WhatToDo.RemoveCarStream:
                    pointClicked = this.cl.ActiveGrid.FindPointInList(p, this.cl.ActiveGrid.GetAllCarStreamStartPoints(), 10);
                    if (pointClicked != new Point(0, 0))
                    {
                        this.cl.ActiveGrid.RemoveCarStream(pointClicked);
                    }
                    RemoveCarStreamToggle = false;
                    this.Refresh();
                    break;

                case WhatToDo.AddEditPedestrianStreamStart:
                    foreach (List <Point> points in this.cl.ActiveGrid.ListOfPossiblePedestrianStreams)
                    {
                        pointClicked = this.cl.ActiveGrid.FindPointInList(p, points, 2);
                    }
                    if (pointClicked != new Point(0, 0))
                    {
                        this.selectedPedestrianStartPoint = pointClicked;
                        mouseMode = WhatToDo.AddEditPedestrianStreamEnd;
                    }
                    this.Refresh();
                    break;

                case WhatToDo.AddEditPedestrianStreamEnd:
                    foreach (List <Point> possiblePedestrianStream in this.cl.ActiveGrid.ListOfPossiblePedestrianStreams)
                    {
                        pointClicked = this.cl.ActiveGrid.FindPointInList(p, possiblePedestrianStream, 2);
                    }
                    if (pointClicked != new Point(0, 0))
                    {
                        this.cl.ActiveGrid.ListOfPedestrianStreams.Add(new PedestrianStream(this.selectedPedestrianStartPoint, this.selectedPedestrianEndPoint, 5));
                    }
                    mouseMode = WhatToDo.None;
                    this.Refresh();
                    break;

                case WhatToDo.None:

                    break;
                }
            }
            else
            {
                MessageBox.Show("Click inside!");
            }
        }
 public bool AddCarStream(CarStream carsteam)
 {
     this.StartingStreams.Add(carsteam);
     return(true);
 }