예제 #1
0
        /*
         *  called by wayside controller
         *  updates the current occupancy of block and check if a train is going to yard
         *  removes trains going to yard
         *
         */
        public void updateBlockOccupancy(int bId, bool occupied)
        {
            foreach (Train t in myTrainList)
            {
                if (!occupied && (bId == t.currBlock))
                {
                    Block b         = findBlock(bId);
                    Block prevBlock = findBlock(t.prevBlock);
                    Block currBlock = findBlock(t.currBlock);
                    t.prevBlock = t.currBlock;
                    if (prevBlock == currBlock)
                    {
                        prevBlock = null;
                    }
                    Block nextBlock = getNextBlock(prevBlock, currBlock, bId);
                    if (nextBlock != null)
                    {
                        t.currBlock = nextBlock.blockId;
                    }
                    if (b.lineId == 2) //red line
                    {
                        foreach (ListViewItem item in systemListView.Items)
                        {
                            if (item.Index == (nextBlock.blockNum))
                            {
                                item.SubItems[2] = new ListViewItem.ListViewSubItem()
                                {
                                    Text = "Train " + t.trainId.ToString()
                                };
                            }

                            if (item.Index == (b.blockNum))
                            {
                                item.SubItems[2] = new ListViewItem.ListViewSubItem()
                                {
                                    Text = "-"
                                };
                            }
                        }

                        if ((t.currBlock == 229) && (t.prevBlock == 161))
                        {
                            tm_window = trainModelArray[t.trainId];
                            tm_window.closeTrainController();
                            tm_window.Close();
                            tm_window = null;
                            trainModelArray[t.trainId] = null;
                            throughCounter++;
                            updateThroughput(trainCounter, throughCounter);
                            //t = null;
                            //myTrainList.Remove(t);
                        }
                    }

                    if (b.lineId == 1) //green line
                    {
                        if (nextBlock != null)
                        {
                            foreach (ListViewItem item in systemListView2.Items)
                            {
                                if (item.Index == (nextBlock.blockNum))
                                {
                                    item.SubItems[2] = new ListViewItem.ListViewSubItem()
                                    {
                                        Text = "Train " + t.trainId.ToString()
                                    };
                                }

                                if (item.Index == (b.blockNum))
                                {
                                    item.SubItems[2] = new ListViewItem.ListViewSubItem()
                                    {
                                        Text = "-"
                                    };
                                }
                            }
                        }
                        if ((t.currBlock == 57) || (b.isToYard))
                        {
                            tm_window = trainModelArray[t.trainId];
                            tm_window.closeTrainController();
                            tm_window.Close();
                            tm_window = null;
                            trainModelArray[t.trainId] = null;
                            throughCounter++;
                            updateThroughput(trainCounter, throughCounter);
                            //t = null;
                            //myTrainList.Remove(t);
                        }
                    }
                }
            }
        }