Example #1
0
        /// <summary>
        /// Manages Trains on Track
        /// </summary>
        public void PopulateTrack()
        {
            _populateTrackMutex.WaitOne();
            //_env.stopTick();
            //_env.Tick -= _env_Tick;
            //clear current trains
            //foreach(IBlock b in _containedBlocks)
            for (int i = 0; i < _containedTrainAndBlock.Count; i++)
            {
                IBlock b = _containedTrainAndBlock[i].Block;
                if (b.Line.CompareTo("Red") == 0)
                {
                    if (!(b.SpeedLimit == 500 || b.SpeedLimit == -1))
                    {
                        LayoutCellDataContainer c = _redLineData.TriangulateContainer(b);
                        c.Tile  = _redLineData.GetBlockType(b);
                        c.Train = null;
                        if (c.Panel != null)
                        {
                            c.Panel.ReDrawMe();
                        }
                    }
                }//end if
                else
                {
                    if (!(b.SpeedLimit == 500 || b.SpeedLimit == -1))
                    {
                        LayoutCellDataContainer c = _greenLineData.TriangulateContainer(b);
                        c.Tile  = _greenLineData.GetBlockType(b);
                        c.Train = null;
                        if (c.Panel != null)
                        {
                            c.Panel.ReDrawMe();
                        }
                    }
                } //end if
            }     //end foreach

            //make list of new trains
            _containedTrainAndBlock.Clear();
            //foreach (ITrainModel t in _env.AllTrains)
            for (int i = 0; i < _env.AllTrains.Count; i++)
            {
                ITrainModel   t  = _env.AllTrains[i];
                TrainAndBlock tb = new TrainAndBlock();
                tb.Train = t;
                tb.Block = t.CurrentBlock;
                _containedTrainAndBlock.Add(tb);
            }//end foreach

            //update graphics
            //foreach (IBlock b in _containedBlocks)
            for (int i = 0; i < _containedTrainAndBlock.Count; i++)
            {
                TrainAndBlock tb = _containedTrainAndBlock[i];
                if (tb.Block.Line.CompareTo("Red") == 0)
                {
                    if (!(tb.Block.SpeedLimit == 500 || tb.Block.SpeedLimit == -1))
                    {
                        LayoutCellDataContainer c = _redLineData.TriangulateContainer(tb.Block);
                        c.Tile  = _res.Train;
                        c.Train = tb.Train;

                        if (c.Panel != null)
                        {
                            string msg = "Red Line: Train ID: " + c.Train.TrainID + " is now on Block: " + c.Block.BlockID + ".";
                            _messages.Add(msg);
                            _env.SendLogEntry("CTC Office: " + msg);
                            c.Panel.ReDrawMe();
                        }
                    }
                }//end if
                else
                {
                    if (!(tb.Block.SpeedLimit == 500 || tb.Block.SpeedLimit == -1))
                    {
                        LayoutCellDataContainer c = _greenLineData.TriangulateContainer(tb.Block);
                        c.Tile  = _res.Train;
                        c.Train = tb.Train;
                        if (c.Panel != null)
                        {
                            string msg = "Green Line: Train ID: " + c.Train.TrainID + " is now on Block: " + c.Block.BlockID + ".";
                            _messages.Add(msg);
                            _env.SendLogEntry("CTC Office: " + msg);
                            c.Panel.ReDrawMe();
                        }
                    }
                } //end if
            }     //end for each

            _populateTrackMutex.ReleaseMutex();
            //_env.Tick += _env_Tick;
            //_env.startTick();
        }//End Populate Track
        /// <summary>
        /// Manages Trains on Track
        /// </summary>
        public void PopulateTrack()
        {
            _populateTrackMutex.WaitOne();
            //_env.stopTick();
            //_env.Tick -= _env_Tick;
            //clear current trains
            //foreach(IBlock b in _containedBlocks)
            for (int i = 0; i < _containedTrainAndBlock.Count; i++)
            {
                IBlock b = _containedTrainAndBlock[i].Block;
                if (b.Line.CompareTo("Red") == 0)
                {
                    if (!(b.SpeedLimit == 500 || b.SpeedLimit == -1))
                    {
                        LayoutCellDataContainer c = _redLineData.TriangulateContainer(b);
                        c.Tile = _redLineData.GetBlockType(b);
                        c.Train = null;
                        if (c.Panel != null)
                        {
                            c.Panel.ReDrawMe();
                        }
                    }
                }//end if
                else
                {
                    if (!(b.SpeedLimit == 500 || b.SpeedLimit == -1))
                    {
                        LayoutCellDataContainer c = _greenLineData.TriangulateContainer(b);
                        c.Tile = _greenLineData.GetBlockType(b);
                        c.Train = null;
                        if (c.Panel != null)
                        {
                            c.Panel.ReDrawMe();
                        }
                    }
                }//end if
            }//end foreach

            //make list of new trains
            _containedTrainAndBlock.Clear();
            //foreach (ITrainModel t in _env.AllTrains)
            for (int i = 0; i < _env.AllTrains.Count; i++)
            {
                ITrainModel t = _env.AllTrains[i];
                TrainAndBlock tb = new TrainAndBlock();
                tb.Train = t;
                tb.Block = t.CurrentBlock;
                _containedTrainAndBlock.Add(tb);
            }//end foreach

            //update graphics
            //foreach (IBlock b in _containedBlocks)
            for (int i = 0; i < _containedTrainAndBlock.Count; i++)
            {
                TrainAndBlock tb = _containedTrainAndBlock[i];
                if (tb.Block.Line.CompareTo("Red") == 0)
                {
                    if (!(tb.Block.SpeedLimit == 500 || tb.Block.SpeedLimit == -1))
                    {
                        LayoutCellDataContainer c = _redLineData.TriangulateContainer(tb.Block);
                        c.Tile = _res.Train;
                        c.Train = tb.Train;

                        if (c.Panel != null)
                        {
                            string msg = "Red Line: Train ID: " + c.Train.TrainID + " is now on Block: " + c.Block.BlockID + ".";
                            _messages.Add(msg);
                            _env.SendLogEntry("CTC Office: " + msg);
                            c.Panel.ReDrawMe();
                        }
                    }

                }//end if
                else
                {
                    if (!(tb.Block.SpeedLimit == 500 || tb.Block.SpeedLimit == -1))
                    {
                        LayoutCellDataContainer c = _greenLineData.TriangulateContainer(tb.Block);
                        c.Tile = _res.Train;
                        c.Train = tb.Train;
                        if (c.Panel != null)
                        {
                            string msg = "Green Line: Train ID: " + c.Train.TrainID + " is now on Block: " + c.Block.BlockID + ".";
                            _messages.Add(msg);
                            _env.SendLogEntry("CTC Office: " + msg);
                            c.Panel.ReDrawMe();
                        }
                    }
                }//end if
            }//end for each

            _populateTrackMutex.ReleaseMutex();
            //_env.Tick += _env_Tick;
            //_env.startTick();
        }