/// <summary> /// Initializes a new instance of the <see cref="Zebra"/> class. /// </summary> /// <param name="intersection">The intersection where the <see cref="Zebra"/> is.</param> /// <param name="pedestrianLight">The <see cref="PedestrianLight"/> for which the <see cref="Zebra"/> is /// assigned to.</param> protected Zebra(BaseIntersection intersection, PedestrianLight pedestrianLight) { this.Intersection = intersection; this.Position = this.HitBox.Location; this.Pedestrians = new List<Pedestrian>(); this.PedestrianLight = pedestrianLight; this.HitBox = this.CalculateHitBox(); }
/// <summary> /// Initializes a new instance of the <see cref="PedestrianLight"/> class. /// </summary> /// <param name="id">The id that will be used to create the <see cref="PedestrianLight"/>.</param> /// <param name="intersection">The <see cref="PedestrianIntersection"/> to which the <see cref="PedestrianLight"/> belongs.</param> public PedestrianLight(int id, BaseIntersection intersection) { this.ID = id; this.Intersection = intersection; this.GreenTime = 8; this.RedTime = 25; this.Position = this.GetTrafficLight(); this.HitBox = new Rectangle(this.Position, new Size(HITBOXWIDTH, HITBOXHEIGHT)); this.Image = this.GetTrafficLightImage(); }
/// <summary> /// Adds a <see cref="BaseIntersection"/> to the <see cref="Intersections"/> list. /// </summary> /// <param name="intersection">The intersection to be added.</param> /// <returns> /// Returns true if the <see cref="BaseIntersection"/> has been added;otherwise-false. /// </returns> public bool AddIntersection(BaseIntersection intersection) { if (this.Intersections.Count >= MAXAMOUNTINTERSECTIONS || intersection == null || this.Intersections.Any(inter => inter.ID == intersection.ID)) { return false; } this.Intersections.Add(intersection); this.AddNeighbor(intersection); this.Intersections.ForEach(inter => inter.DetermineFeederLanes()); return true; }
public ModifyIntersectionForm(BaseIntersection intersection) { InitializeComponent(); trafficMonitor = TrafficMonitor.Instance; this.numLeftLane.Enabled = false; this.numRightLane.Enabled = false; this.numLowerLane.Enabled = false; this.numUpperLane.Enabled = false; GetIntersection(intersection); GetPedestrians(); tbIntervalPedestrians.Text = 1.ToString(); this.pedestrianTimer = new Timer(); enableToolTip(); this.richTextBox1.Text += "Here we will record all your steps ☺!\n"; this.GetTrafficLightPicture(); this.CheckForSensors(); }
/// <summary> /// Removes all the neighbors for a given <see cref="BaseIntersection"/>. /// </summary> /// <param name="intersection">The given intersection.</param> private void RemoveNeighbor(BaseIntersection intersection) => intersection.Neighbors.ForEach(inter => inter.RemoveNeighbor(intersection));
private void panel3_MouseClick(object sender, MouseEventArgs e) { var point = GetClosestPoint(e.Location); if (intersectionType == 0) { selectedIntersection = trafficMonitor.GetIntersection(e.Location); return; } if (!CreateIntersection(point)) { MessageBox.Show("There is already an intersection at the selected location!"); this.richTextBox1.Text += DateTime.Now + "There is already an intersection at the selected location\n"; this.richTextBox1.Find("There is already an intersection at the selected location"); this.richTextBox1.SelectionColor = Color.Red; this.richTextBox1.Select(0, 0); intersectionType = 0; return; } InvalidateEvent.InvalidatePanel(); }
/// <summary> /// Gets the <see cref="TrafficLight"/> with the given <paramref name="id"/> /// for the given <paramref name="intersection"/>. /// </summary> /// <param name="id">The ID of the traffic light.</param> /// <param name="intersection">The intersection to which the traffic light belongs to.</param> /// <returns>A <see cref="TrafficLight"/> if it exists. Otherwise, it returns null.</returns> public TrafficLight GetTrafficLight(int id, BaseIntersection intersection) => this.Intersections.Where(i => i == intersection).SelectMany(i => i.TrafficLights).FirstOrDefault (t => t.ID == id);
/// <summary> /// Adds all the possible neighbors for a given <see cref="BaseIntersection"/>. /// </summary> /// <param name="intersection">The given intersection.</param> private void AddNeighbor(BaseIntersection intersection) { // Gets a list with all the possible IDs of the neighbors. var possibleNeighbors = this.neighborsDictionary[intersection.ID]; // Gets all the actual existing neighbors (checks for every possible neighbors if it exists). var existingNeighbors = this.Intersections.Where(inter => possibleNeighbors.Contains(inter.ID)).Select(i => i); foreach (var inter in existingNeighbors) { intersection.AddNeighbor(inter); inter.AddNeighbor(intersection); } }
/// <summary> /// Initializes a new instance of the <see cref="LeftLane"/> class. /// </summary> /// <param name="intersection">The intersection where the <see cref="LeftLane"/> is.</param> public LeftLane(BaseIntersection intersection) : base(intersection) { }
/// <summary> /// Removes a <see cref="BaseIntersection"/> from the <see cref="Intersections"/> list. /// </summary> /// <param name="intersection">The intersection to be removed.</param> /// <returns> /// Returns true if the <see cref="BaseIntersection"/> has been removed;otherwise-false. /// </returns> public bool RemoveIntersection(BaseIntersection intersection) { if (!this.Intersections.Contains(intersection)) { return false; } this.RemoveNeighbor(intersection); this.Intersections.Remove(intersection); this.Intersections.ForEach(inter => inter.DetermineFeederLanes()); return true; }
/// <summary> /// Initializes a new instance of the <see cref="LeftZebra"/> class. /// </summary> /// <param name="intersection">The intersection where the <see cref="LeftZebra"/> is.</param> /// <param name="pedestrianLight">The <see cref="PedestrianLight"/> for which the <see cref="LeftZebra"/> is /// assigned to.</param> public LeftZebra(BaseIntersection intersection, PedestrianLight pedestrianLight) : base(intersection, pedestrianLight) { }
private void pbPede4_Click(object sender, EventArgs e) { this.groupBox4.Text = "Lower left"; panel2.Enabled = true; selectedIntersection = selectedIntersection as PedestrianIntersectionType2; PedestrianLight pt = trafficMonitor.GetPedestrianLightForIntersection2(1, (PedestrianIntersectionType2) selectedIntersection); this.tbRedPedestrian.Text = pt.RedTime.ToString(); this.tbGreenPedestrian.Text = pt.GreenTime.ToString(); if (pt.LightColor == PedestrianLightColor.GREEN) { this.rbGreenPedestrian.Checked = true; } else { this.rbRedPedestrian.Checked = true; } }
public void GetIntersection(BaseIntersection intersection) { this.selectedIntersection = intersection; if (selectedIntersection is NormalIntersection) { pbIntersection.BackgroundImage = Properties.Resources.junction1; } else if (selectedIntersection is PedestrianIntersection) { pbIntersection.BackgroundImage = Properties.Resources.junction2_NoSensors; } else { pbIntersection.BackgroundImage = Properties.Resources.junction3_NoSensors; } if (this.selectedIntersection is NormalIntersection) { cbPedestrianSensors.Enabled = false; cbAddPedestrians.Enabled = false; pbPede1.Visible = false; pbPede2.Visible = false; pbPede3.Visible = false; pbPede4.Visible = false; } else if (this.selectedIntersection is PedestrianIntersection) { cbPedestrianSensors.Enabled = true; cbAddPedestrians.Enabled = true; pbPede1.Visible = true; pbPede2.Visible = true; pbPede3.Visible = false; pbPede4.Visible = false; } else if (this.selectedIntersection is PedestrianIntersectionType2) { cbPedestrianSensors.Enabled = true; cbAddPedestrians.Enabled = true; pbPede1.Visible = false; pbPede2.Visible = false; pbPede3.Visible = true; pbPede4.Visible = true; } if (intersection.LeftLane.EndLane) { this.numLeftLane.Enabled = true; this.numLeftLane.Value = this.selectedIntersection.LeftLane.DefaultNumberOfCars; } if (intersection.RightLane.EndLane) { this.numRightLane.Enabled = true; this.numRightLane.Value = this.selectedIntersection.RightLane.DefaultNumberOfCars; } if (intersection.LowerLane.EndLane) { this.numLowerLane.Enabled = true; this.numLowerLane.Value = this.selectedIntersection.LowerLane.DefaultNumberOfCars; } if (intersection.UpperLane.EndLane) { this.numUpperLane.Enabled = true; this.numUpperLane.Value = this.selectedIntersection.UpperLane.DefaultNumberOfCars; } }
private void btnDelete_Click_1(object sender, EventArgs e) { if (selectedIntersection == null) return; trafficMonitor.RemoveIntersection(selectedIntersection); selectedIntersection = null; InvalidateEvent.InvalidatePanel(); this.richTextBox1.Text += DateTime.Now + "Intersection removed succesfully.\n"; this.richTextBox1.Find("Intersection removed succesfully."); this.richTextBox1.SelectionColor = Color.Green; this.richTextBox1.Select(0, 0); }
private bool CreateIntersection(Point loc) { if (trafficMonitor.Intersections.Any(inter => inter.HitBox.Contains(loc))) { return false; } var id = this.GetIdForIntersection(loc); BaseIntersection intersection = null; if (this.intersectionType == 1) { intersection = new NormalIntersection(Properties.Resources.newjunction1, loc, id); } else if (this.intersectionType == 2) { intersection = new PedestrianIntersection(Properties.Resources.newjunction2_NoSensors, loc, id); } else if (this.intersectionType == 3) { intersection = new PedestrianIntersectionType2(Properties.Resources.newjunction3_NoSensors, loc, id); } bool added = trafficMonitor.AddIntersection(intersection); InvalidateEvent.InvalidatePanel(); intersectionType = 0; if (added) { selectedIntersection = intersection; } toolTip.SetToolTip(panel3, "Double click on an intersection to change its properties"); return added; }
/// <summary> /// Removes the passed <see cref="BaseIntersection"/> from the <see cref="Neighbors"/>. /// </summary> /// <param name="intersection">The intersection to be removed.</param> public void RemoveNeighbor(BaseIntersection intersection) { if (this.Neighbors.Contains(intersection)) { this.Neighbors.Remove(intersection); } }
/// <summary> /// Adds the passed <see cref="BaseIntersection"/> to the <see cref="Neighbors"/>. /// </summary> /// <param name="intersection">The intersection to be added.</param> public void AddNeighbor(BaseIntersection intersection) { if (!this.Neighbors.Contains(intersection)) { this.Neighbors.Add(intersection); } }
/// <summary> /// Initializes a new instance of the <see cref="LowerLane"/> class. /// </summary> /// <param name="intersection">The <see cref="BaseIntersection"/> where the <see cref="LowerLane"/> is.</param> public LowerLane(BaseIntersection intersection) : base(intersection) { }
/// <summary> /// Initializes a new instance of the <see cref="UpperLane"/> class. /// </summary> /// <param name="intersection">The <see cref="BaseIntersection"/> where the <see cref="UpperLane"/> is.</param> public UpperLane(BaseIntersection intersection) : base(intersection) { }