//public void enableNum() //{ // if (isLocked && !eraseFlag) // { // if (surrounded) // { // numericCars.Enabled = false; // } // if (!surrounded) // { // numericCars.Enabled = true; // } // this.numericTrafficTime.Enabled = true; // //this.cBPedTraffic.Enabled = true; // this.btnFinishCrossing.Enabled = true; // this.btnRemove.Enabled = false; // } // if (isLocked && eraseFlag) // { // this.numericCars.Enabled = false; // this.numericTrafficTime.Enabled = false; // this.cBPedTraffic.Enabled = false; // this.btnFinishCrossing.Enabled = false; // this.btnRemove.Enabled = false; // selectedID = 0; // } // if (!eraseFlag && !isLocked) // { // this.numericCars.Enabled = false; // this.numericTrafficTime.Enabled = false; // this.cBPedTraffic.Enabled = false; // this.btnFinishCrossing.Enabled = false; // this.btnRemove.Enabled = true; // } // if (!isLocked && eraseFlag) // { // this.numericCars.Enabled = false; // this.numericTrafficTime.Enabled = false; // this.cBPedTraffic.Enabled = false; // this.btnFinishCrossing.Enabled = false; // this.btnRemove.Enabled = false; // selectedID = 0; // } // if (crossLocked) // { // this.numericCars.Enabled = false; // this.numericTrafficTime.Enabled = false; // this.cBPedTraffic.Enabled = false; // } // if (isLocked) // { // btnPlay.Enabled = true; // } // if (!play) // { // btnLock.Enabled = true; // btnToggleLight.Enabled = false; // } // if (play) // { // btnLock.Enabled = false; // btnToggleLight.Enabled = true; // } //} #endregion private void pictureBoxOnPaint(object sender, PaintEventArgs e) { PictureBox self = (PictureBox)sender; Artist painter = new Artist(e); Crossing crossing = Simulation.getCrossing(GetNumberOfPicturebox(self)); if (null != selectedPicBox) { if (self.Equals(selectedPicBox)) { painter.paintSelectionOutline(); crossLocked = false; this.btnFinishCrossing.Text = "Lock Crossing"; //enableNum(); } if (eraseFlag) { eraseFlag = false; this.btnFinishCrossing.Text = "Unlock Crossing"; //enableNum(); self.Invalidate(); } } #region Drawing Stuff // Drawing cars and lights, yay List <Car> tempCars = new List <Car>(); foreach (Crossing item in Simulation.Crossings) { if (!item.Equals(crossing)) { continue; } if (item is Crossing_B) { foreach (PedestrianLane p in ((Crossing_B)item).pLanes) { if (p.PLight != null) { painter.drawPedestrianLight(p, p.PLight.State); if (p.PLight.State) { painter.drawPedestrians(p, ((Crossing_B)item).style); } } } } foreach (TrafficLane j in item.Lanes) { if (j.TrafficLight != null) { painter.drawTrafficLight(j, j.TrafficLight.State); } foreach (Car c in j.Cars) { painter.drawCar(c, j.Direction); } } } #endregion #region Debug // enable/disable in the beginning of the class if (this.cBDebugPoint.Checked) { // Dots debug int picBoxNum = GetNumberOfPicturebox(self); bool test = Simulation.CrossingExist(picBoxNum); if (Simulation.CrossingExist(picBoxNum)) { crossing = Simulation.getCrossing(picBoxNum); List <TrafficLane> lanes = new List <TrafficLane>(crossing.Lanes); foreach (TrafficLane t in lanes) { foreach (Point p in t.Points) { e.Graphics.DrawEllipse(new Pen(Color.Red, 1), p.X, p.Y, 1, 1); } } if (this.cBDebugCars.Checked) { if (crossing is Crossing_A) { // Car debug #region Vertical Crossings // Lane 4 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 77, 1, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 77, 16, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 77, 31, 10, 13); // Lane 5 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 104, 1, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 104, 16, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 104, 31, 10, 13); // Lane 0 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 134, 1, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 134, 16, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 134, 31, 10, 13); // Lane 2 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 77, 111, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 77, 126, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 77, 141, 10, 13); // Lane 9 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 107, 111, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 107, 126, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 107, 141, 10, 13); // Lane 8 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 134, 111, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 134, 126, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 134, 141, 10, 13); #endregion #region Horizontal Crossings // Lane 6 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 157, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 172, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 187, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 202, 54, 13, 10); // Lane 7 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 157, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 172, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 187, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 202, 74, 13, 10); // Lane 1 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 157, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 172, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 187, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 202, 94, 13, 10); // Lane 3 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 5, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 20, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 35, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 50, 54, 13, 10); // Lane 11 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 5, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 20, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 35, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 50, 74, 13, 10); // Lane 10 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 5, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 20, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 35, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 50, 94, 13, 10); #endregion } if (crossing is Crossing_B) { // Car debug #region Vertical Crossings // Lane 4 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 85, 1, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 85, 16, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 85, 31, 10, 13); // Lane 0 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 128, 1, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 128, 16, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 128, 31, 10, 13); // Lane 2 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 85, 113, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 85, 128, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 85, 143, 10, 13); // Lane 7 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 128, 113, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 128, 128, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 128, 143, 10, 13); #endregion #region Horizontal Crossings // Lane 6 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 157, 73, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 172, 73, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 187, 73, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 202, 73, 13, 10); // Lane 8 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 5, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 20, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 35, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 50, 94, 13, 10); // Lane 5 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 157, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 172, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 187, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 202, 54, 13, 10); // Lane 9 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 5, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 20, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 35, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 50, 74, 13, 10); // Lane 1 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 157, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 172, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 187, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 202, 94, 13, 10); // Lane 3 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 5, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 20, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 35, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 50, 54, 13, 10); #endregion } } } } #endregion }
//public void enableNum() //{ // if (isLocked && !eraseFlag) // { // if (surrounded) // { // numericCars.Enabled = false; // } // if (!surrounded) // { // numericCars.Enabled = true; // } // this.numericTrafficTime.Enabled = true; // //this.cBPedTraffic.Enabled = true; // this.btnFinishCrossing.Enabled = true; // this.btnRemove.Enabled = false; // } // if (isLocked && eraseFlag) // { // this.numericCars.Enabled = false; // this.numericTrafficTime.Enabled = false; // this.cBPedTraffic.Enabled = false; // this.btnFinishCrossing.Enabled = false; // this.btnRemove.Enabled = false; // selectedID = 0; // } // if (!eraseFlag && !isLocked) // { // this.numericCars.Enabled = false; // this.numericTrafficTime.Enabled = false; // this.cBPedTraffic.Enabled = false; // this.btnFinishCrossing.Enabled = false; // this.btnRemove.Enabled = true; // } // if (!isLocked && eraseFlag) // { // this.numericCars.Enabled = false; // this.numericTrafficTime.Enabled = false; // this.cBPedTraffic.Enabled = false; // this.btnFinishCrossing.Enabled = false; // this.btnRemove.Enabled = false; // selectedID = 0; // } // if (crossLocked) // { // this.numericCars.Enabled = false; // this.numericTrafficTime.Enabled = false; // this.cBPedTraffic.Enabled = false; // } // if (isLocked) // { // btnPlay.Enabled = true; // } // if (!play) // { // btnLock.Enabled = true; // btnToggleLight.Enabled = false; // } // if (play) // { // btnLock.Enabled = false; // btnToggleLight.Enabled = true; // } //} #endregion private void pictureBoxOnPaint(object sender, PaintEventArgs e) { PictureBox self = (PictureBox)sender; Artist painter = new Artist(e); Crossing crossing = Simulation.getCrossing(GetNumberOfPicturebox(self)); if (null != selectedPicBox) { if (self.Equals(selectedPicBox)) { painter.paintSelectionOutline(); crossLocked = false; this.btnFinishCrossing.Text = "Lock Crossing"; //enableNum(); } if (eraseFlag) { eraseFlag = false; this.btnFinishCrossing.Text = "Unlock Crossing"; //enableNum(); self.Invalidate(); } } #region Drawing Stuff // Drawing cars and lights, yay List<Car> tempCars = new List<Car>(); foreach (Crossing item in Simulation.Crossings) { if (!item.Equals(crossing)) continue; if (item is Crossing_B) { foreach (PedestrianLane p in ((Crossing_B)item).pLanes) { if (p.PLight != null) { painter.drawPedestrianLight(p, p.PLight.State); if (p.PLight.State) { painter.drawPedestrians(p, ((Crossing_B)item).style); } } } } foreach (TrafficLane j in item.Lanes) { if (j.TrafficLight != null) painter.drawTrafficLight(j, j.TrafficLight.State); foreach (Car c in j.Cars) { painter.drawCar(c, j.Direction); } } } #endregion #region Debug // enable/disable in the beginning of the class if (this.cBDebugPoint.Checked) { // Dots debug int picBoxNum = GetNumberOfPicturebox(self); bool test = Simulation.CrossingExist(picBoxNum); if (Simulation.CrossingExist(picBoxNum)) { crossing = Simulation.getCrossing(picBoxNum); List<TrafficLane> lanes = new List<TrafficLane>(crossing.Lanes); foreach (TrafficLane t in lanes) { foreach (Point p in t.Points) { e.Graphics.DrawEllipse(new Pen(Color.Red, 1), p.X, p.Y, 1, 1); } } if (this.cBDebugCars.Checked) { if (crossing is Crossing_A) { // Car debug #region Vertical Crossings // Lane 4 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 77, 1, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 77, 16, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 77, 31, 10, 13); // Lane 5 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 104, 1, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 104, 16, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 104, 31, 10, 13); // Lane 0 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 134, 1, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 134, 16, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 134, 31, 10, 13); // Lane 2 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 77, 111, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 77, 126, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 77, 141, 10, 13); // Lane 9 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 107, 111, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 107, 126, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 107, 141, 10, 13); // Lane 8 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 134, 111, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 134, 126, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 134, 141, 10, 13); #endregion #region Horizontal Crossings // Lane 6 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 157, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 172, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 187, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 202, 54, 13, 10); // Lane 7 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 157, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 172, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 187, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 202, 74, 13, 10); // Lane 1 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 157, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 172, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 187, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 202, 94, 13, 10); // Lane 3 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 5, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 20, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 35, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 50, 54, 13, 10); // Lane 11 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 5, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 20, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 35, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 50, 74, 13, 10); // Lane 10 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 5, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 20, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 35, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 50, 94, 13, 10); #endregion } if (crossing is Crossing_B) { // Car debug #region Vertical Crossings // Lane 4 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 85, 1, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 85, 16, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 85, 31, 10, 13); // Lane 0 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 128, 1, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 128, 16, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 128, 31, 10, 13); // Lane 2 e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 85, 113, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 85, 128, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 85, 143, 10, 13); // Lane 7 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 128, 113, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 128, 128, 10, 13); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 128, 143, 10, 13); #endregion #region Horizontal Crossings // Lane 6 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 157, 73, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 172, 73, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 187, 73, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 202, 73, 13, 10); // Lane 8 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 5, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 20, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 35, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 50, 94, 13, 10); // Lane 5 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 157, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 172, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 187, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 202, 54, 13, 10); // Lane 9 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 5, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 20, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 35, 74, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 50, 74, 13, 10); // Lane 1 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 157, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 172, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 187, 94, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 202, 94, 13, 10); // Lane 3 e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 5, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Black, 1), 20, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), 35, 54, 13, 10); e.Graphics.DrawRectangle(new Pen(Color.Orange, 1), 50, 54, 13, 10); #endregion } } } } #endregion }