public LineData(IBlock[,] layout, ISimulationEnvironment env, ResourceWrapper res) { _env = env; _res = res; _trains = new List<ITrainModel>(); _blocks = new List<IBlock>(); _layout = new LayoutCellDataContainer[layout.GetUpperBound(0) + 1,layout.GetUpperBound(1) + 1]; //for each item in the 1st dimension (row) for (int i = 0; i <= layout.GetUpperBound(0); i++) { //for each item in the 2nd dimension (col) for (int j = 0; j <= layout.GetUpperBound(1); j++) { //make a new container var container = new LayoutCellDataContainer(); //determine tile if (layout[i, j] == null) { //null container container.BaseTile = _res.Unpopulated; container.Tile = container.BaseTile; container.Block = null; container.Train = null; } else { container.Train = null; _blocks.Add(layout[i, j]); container.Block = layout[i, j]; //expand after prototype if (layout[i, j].Line.CompareTo("Red") == 0 || layout[i, j].Line.CompareTo("red") == 0 || layout[i, j].Line.CompareTo("R") == 0 || layout[i, j].Line.CompareTo("r") == 0) { //red line container.BaseTile = GetBlockType(container.Block); container.Tile = container.BaseTile; } else if (layout[i, j].Line.CompareTo("Green") == 0 || layout[i, j].Line.CompareTo("green") == 0 || layout[i, j].Line.CompareTo("G") == 0 || layout[i, j].Line.CompareTo("g") == 0) { //green line container.BaseTile = GetBlockType(container.Block); container.Tile = container.BaseTile; } else { container.BaseTile = _res.TrackError; container.Tile = container.BaseTile; env.SendLogEntry("CTC Office: Line Data - IBlock.Line is invalid"); } } //end determine tile //add the container to the layout panel _layout[i, j] = container; } //end for 2nd dimension } //end for 1st dimentsion }
public TileContainerStats(int i, int j, int x, int y, LayoutCellDataContainer c, Panel drawingPanel) { _gridI = i; _gridJ = j; _gridX = x; _gridY = y; _container = c; _drawingPanel = drawingPanel; /* MyPictureBox pane = new MyPictureBox(_panelRedLine,this); _panelRedLine.Controls.Add(pane); pane.Name = "_imgGridRed_" + i + "_" + j; pane.SizeMode = PictureBoxSizeMode.CenterImage; pane.Size = new Size(20, 20); pane.Location = new Point(x, y); pane.Image = _redLineData.Layout[i, j].Tile; pane.Tag = _redLineData.Layout[i, j]; _redLineData.Layout[i, j].Panel = pane; pane.MouseClick += _layoutPiece_MouseClick; //pane.MouseHover += new EventHandler(this._layoutPiece_MouseHover); x += 20; */ }
/// <summary> /// Creates the request that is sent to the PTC's /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void HandleMenuClick(object sender, EventArgs e) { var s = (MenuItem)sender; var c = (LayoutCellDataContainer)s.Tag; //assing last right click container _lastRightClickContainer = c; if (s.Text.CompareTo("Open Track") == 0) { _ctcOffice.openTrackBlockRequest(c.Block.TrackCirID, c.Block); } else if (s.Text.CompareTo("Close Track") == 0) { _ctcOffice.closeTrackBlockRequest(c.Block.TrackCirID, c.Block); } else if (s.Text.CompareTo("Display Track Info") == 0) { //TODO IBlock block = c.Block; } else if (s.Text.CompareTo("Assign Train Route") == 0) { //get route somehow //TODO OpenRoutingTool(c.Block, RoutingMode.Update); //_ctcOffice.assignTrainRouteRequest(c.Train.TrainID, c.Block.TrackCirID, null, c.Block); } else if (s.Text.CompareTo("Set Train Authority") == 0) { OpenAuthorityTool(); } else if (s.Text.CompareTo("Set Train Speed") == 0) { OpenSpeedTool(); } else if (s.Text.CompareTo("Set Train OOS") == 0) { _ctcOffice.setTrainOutOfServiceRequest(c.Train.TrainID, c.Block.TrackCirID, c.Block); } else if (s.Text.CompareTo("Display Train Info") == 0) { if (ShowTrain != null) { ShowTrain(this, new ShowTrainEventArgs(c.Train)); } } //else do noting }
public CTCOfficeGUI(ISimulationEnvironment env, CTCOffice ctc) { InitializeComponent(); //set refs to ctc office and environment _ctcOffice = ctc; _environment = env; _speedState = 0; _res = _ctcOffice.Resource; _ctcOffice.LoadData += new EventHandler<EventArgs>(_ctcOffice_LoadData); _ctcOffice.UnlockLogin += new EventHandler<EventArgs>(_ctcOffice_UnlockLogin); _ctcOffice.MessagesReady += new EventHandler<EventArgs>(_ctcOffice_MessagesReady); _ctcOffice.UpdatedData += new EventHandler<EventArgs>(_ctcOffice_UpdatedData); _loginState = false; _btnLoginLogout.Enabled = _loginState; _txtPassword.Enabled = _loginState; _txtUsername.Enabled = _loginState; _rate = 100; _tickCount = 0; //init routing vars _routeTool = null; _inRoutingPoint = false; _routingToolOpen = false; _routeToolMode = RoutingMode.Dispatch; _lastRightClickContainer = null; _keyForm = null; _keyOpen = false; //subscribe to Environment Tick _environment.Tick += _environment_Tick; //ensure the user is logged out _ctcOffice.Logout(); //change button text _btnLoginLogout.Text = "Login"; //show team logo (block out user) MainDisplayLogo(); DisableUserControls(); _loginStatusImage.Image = _res.RedLight; _imageTeamLogo.Image = Properties.Resources.TerminalVelocity; UpdateMetrics(); RefreshStatus(); //populate red line and green line panel //parseLineData(); //enables double buffering for control drawings //this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); //post to log that the gui has loaded _environment.SendLogEntry("CTCOffice: GUI Loaded"); _tt = null; }
public MyPictureBox MakePane(int i, int j, int x, int y, LayoutCellDataContainer c, Panel drawingPanel) { /* if (this.InvokeRequired) { //this.Invoke(new Action(this.MakePane(i,j,x,y,c,drawingPanel))); //return; } */ MyPictureBox pane = new MyPictureBox(drawingPanel, this); pane.Name = "_imgGridGreen_" + i + "_" + j; pane.SizeMode = PictureBoxSizeMode.CenterImage; pane.Size = new Size(20, 20); pane.Location = new Point(x, y); pane.Tag = c; pane.Image = c.Tile; c.Panel = pane; TileContainerStats attribs = new TileContainerStats(i, j, x, y, c, drawingPanel); pane.Attributes = attribs; pane.MouseClick += _layoutPiece_MouseClick; if (c.Train != null) { pane.MouseHover += new EventHandler(pane_MouseHover); pane.MouseLeave += new EventHandler(pane_MouseLeave); } else if (c.Block != null) { if (c.Block.hasStation()) { pane.MouseHover += new EventHandler(pane_MouseHover); pane.MouseLeave += new EventHandler(pane_MouseLeave); } } pane.ForceRedraw += _layoutPiece_ForceRedraw; drawingPanel.Controls.Add(pane); return pane; }