// METHOD: TrainController
 //--------------------------------------------------------------------------------------
 /// <summary>
 /// Primary constructor
 /// </summary>
 /// 
 /// <param name="myTrain">The train associated with this controller</param>
 //--------------------------------------------------------------------------------------
 public TrainController(ITrain myTrain)
 {
     this.m_myTrain = myTrain;
     this.m_currentState = m_myTrain.GetState();
     this.m_trainID = m_currentState.TrainID;
     this.m_currentBlock = m_currentState.CurrentBlock;
     this.m_passengerGenerator = new Random((int)DateTime.Now.Ticks);
     this.ManualSpeed = -1;
 }
Exemple #2
0
 // METHOD: TrainController
 //--------------------------------------------------------------------------------------
 /// <summary>
 /// Primary constructor
 /// </summary>
 ///
 /// <param name="myTrain">The train associated with this controller</param>
 //--------------------------------------------------------------------------------------
 public TrainController(ITrain myTrain)
 {
     this.m_myTrain            = myTrain;
     this.m_currentState       = m_myTrain.GetState();
     this.m_trainID            = m_currentState.TrainID;
     this.m_currentBlock       = m_currentState.CurrentBlock;
     this.m_passengerGenerator = new Random((int)DateTime.Now.Ticks);
     this.ManualSpeed          = -1;
 }
        // METHOD: TrainOperator
        //--------------------------------------------------------------------------------------
        /// <summary>
        /// Secondary constructor, to be used by the CTC
        /// </summary>
        ///
        /// <param name="myTrain">The train associated with this GUI</param>
        /// <param name="myTrainController">The train controller associated with this GUI</param>
        //--------------------------------------------------------------------------------------
        public TrainOperator(ITrain myTrain, TrainController myTrainController)
        {
            InitializeComponent();
            m_isDemo                 = false;
            this.m_myTrain           = myTrain;
            this.m_myTrainState      = m_myTrain.GetState();
            this.m_myTrainController = myTrainController;

            engineFailure.Enabled  = false;
            brakeFailure.Enabled   = false;
            powerFailure.Enabled   = false;
            circuitFailure.Enabled = false;
        }
        // METHOD: TrainOperator
        //--------------------------------------------------------------------------------------
        /// <summary>
        /// Secondary constructor, to be used by the CTC
        /// </summary>
        /// 
        /// <param name="myTrain">The train associated with this GUI</param>
        /// <param name="myTrainController">The train controller associated with this GUI</param>
        //--------------------------------------------------------------------------------------
        public TrainOperator(ITrain myTrain, TrainController myTrainController)
        {
            InitializeComponent();
            m_isDemo = false;
            this.m_myTrain = myTrain;
            this.m_myTrainState = m_myTrain.GetState();
            this.m_myTrainController = myTrainController;

            engineFailure.Enabled = false;
            brakeFailure.Enabled = false;
            powerFailure.Enabled = false;
            circuitFailure.Enabled = false;
        }
Exemple #5
0
        private void UpdateState(object sender, EventArgs e)
        {
            train.Update(clock.Interval / 1000.0);
            TrainState ts = train.GetState();

            brakeBox.Checked          = train.GetBrake();
            emergencyBrakeBox.Checked = train.GetEmergencyBrake();
            brakeFailureBox.Checked   = ts.BrakeFailure;
            switch (ts.Direction)
            {
            case CommonLib.Direction.East:
                directionTextBox.Text = "East";
                break;

            case CommonLib.Direction.North:
                directionTextBox.Text = "North";
                break;

            case CommonLib.Direction.Northeast:
                directionTextBox.Text = "Northeast";
                break;

            case CommonLib.Direction.Northwest:
                directionTextBox.Text = "Northwest";
                break;

            case CommonLib.Direction.South:
                directionTextBox.Text = "South";
                break;

            case CommonLib.Direction.Southeast:
                directionTextBox.Text = "Southeast";
                break;

            case CommonLib.Direction.Southwest:
                directionTextBox.Text = "Southwest";
                break;

            case CommonLib.Direction.West:
                directionTextBox.Text = "West";
                break;

            default:
                break;                         // Unreachable
            }
            progressTextBox.Text     = String.Format("{0:F0}", (ts.BlockProgress / ts.CurrentBlock.LengthMeters) * 100);
            speedTextBox.Text        = String.Format("{0:F3}", ts.Speed);
            accelerationTextBox.Text = String.Format("{0:F3}", train.GetAcceleration());
        }
Exemple #6
0
        /// <summary>
        /// Sets the text information for a train
        /// </summary>
        /// <param name="train">Train</param>
        public void SetTrainInfo(ITrain train)
        {
            if (train == null)
            {
                return;
            }

            TrainState state = train.GetState();

            if (state == null)
            {
                return;
            }

            m_displayedBlock = null;
            m_displayedTrain = train;

            Dictionary <string, string> info = new Dictionary <string, string>();

            info.Add("Number of cars:", state.Cars.ToString());
            info.Add("Crew members:", state.Crew.ToString());
            info.Add("Direction:", state.Direction.ToString());
            info.Add("Door Status:", state.Doors.ToString());
            info.Add("Light Status:", state.Lights.ToString());
            info.Add("Mass:", state.Mass.ToString());
            info.Add("Passengers:", state.Passengers.ToString());
            info.Add("Speed:", string.Format("{0:0.00} {1}", state.Speed.ToString(), KPH));
            info.Add("Temperature:", state.Temperature.ToString());
            info.Add("Position:", string.Format("{0:0.00} , {1:0.00}", state.X.ToString(), state.Y.ToString()));

            if (state.TrainID != null)
            {
                SetInfo(state.TrainID.ToString(), info);
            }
            else
            {
                SetInfo(UNKNOWN_TEXT, info);
            }
        }
        // METHOD: CreateTrain_Click
        //--------------------------------------------------------------------------------------
        /// <summary>
        /// Start the GUI, and create a train and train controller if in a demo
        /// </summary>
        ///
        /// <param name="sender">Sender</param>
        /// <param name="e">Event Arguments</param>
        //--------------------------------------------------------------------------------------
        private void CreateTrain_Click(object sender, EventArgs e)
        {
            if (m_isDemo)
            {
                m_startingBlock                                                   = new TrackBlock("Block1", TrackOrientation.EastWest, new Point(0, 0), 1650, 0, 0, false, false, 70, TrackAllowedDirection.Both, false, "controller1", "controller2", "Block0", "Block2");
                m_startingBlock.NextBlock                                         = new TrackBlock("Block2", TrackOrientation.EastWest, new Point(1650, 0), 50, 0, 0, true, false, 70, TrackAllowedDirection.Both, false, "controller1", "controller2", "Block1", "Block3");
                m_startingBlock.Authority                                         = new BlockAuthority(70, 3);
                m_startingBlock.NextBlock.Authority                               = new BlockAuthority(70, 2);
                m_startingBlock.NextBlock.NextBlock                               = new TrackBlock("Block3", TrackOrientation.EastWest, new Point(1700, 0), 1000, 0, 0, true, false, 70, TrackAllowedDirection.Both, false, "controller1", "controller2", "Block2", "Block4");
                m_startingBlock.NextBlock.NextBlock.NextBlock                     = new TrackBlock("Block4", TrackOrientation.EastWest, new Point(2700, 0), 100, 0, 0, false, false, 70, TrackAllowedDirection.Both, false, "controller1", "controller2", "Block3", "Block5");
                m_startingBlock.NextBlock.NextBlock.NextBlock.NextBlock           = new TrackBlock("Block5", TrackOrientation.EastWest, new Point(2800, 0), 100, 0, 0, false, false, 70, TrackAllowedDirection.Both, false, "controller1", "controller2", "Block4", "Block6");
                m_startingBlock.NextBlock.NextBlock.NextBlock.NextBlock.NextBlock = new TrackBlock("Block6", TrackOrientation.EastWest, new Point(2800, 0), 100, 0, 0, false, false, 70, TrackAllowedDirection.Both, false, "controller1", "controller2", "Block5", "Block7");
                m_startingBlock.NextBlock.NextBlock.Authority                     = new BlockAuthority(70, 1);

                m_startingBlock.NextBlock.NextBlock.NextBlock.Authority                     = new BlockAuthority(40, 0);
                m_startingBlock.NextBlock.NextBlock.NextBlock.NextBlock.Authority           = new BlockAuthority(40, 0);
                m_startingBlock.NextBlock.NextBlock.NextBlock.NextBlock.NextBlock.Authority = new BlockAuthority(40, 0);

                m_startingBlock.Transponder           = new Transponder("SHADYSIDE", 1);
                m_startingBlock.NextBlock.Transponder = new Transponder("SHADYSIDE", 0);

                m_myTrain                    = new TrainLib.Train("train1", m_startingBlock, Direction.East);
                m_myTrainState               = m_myTrain.GetState();
                m_myTrainController          = new TrainController(m_myTrain);
                m_myTrainController.Schedule = GetRedlineSchedule();

                Timer updateTimer = new Timer();
                updateTimer.Tick    += new EventHandler(Update);
                updateTimer.Interval = 40;
                updateTimer.Enabled  = true;
                updateTimer.Start();
            }

            m_myTimer          = new Timer();
            m_myTimer.Tick    += new EventHandler(UpdateDisplay);
            m_myTimer.Interval = 500;
            m_myTimer.Enabled  = true;
            m_myTimer.Start();
        }
Exemple #8
0
        /// <summary>
        /// Sets the text information for a train
        /// </summary>
        /// <param name="train">Train</param>
        public void SetTrainInfo(ITrain train)
        {
            if (train == null) return;

            TrainState state = train.GetState();

            if (state == null) return;

            Dictionary<string, string> info = new Dictionary<string, string>();

            info.Add("Number of cars:", state.Cars.ToString());
            info.Add("Crew members:", state.Crew.ToString());
            info.Add("Direction:", state.Direction.ToString());
            info.Add("Door Status:", state.Doors.ToString());
            info.Add("Light Status:", state.Lights.ToString());
            info.Add("Mass:", state.Mass.ToString());
            info.Add("Passengers:", state.Passengers.ToString());
            info.Add("Speed:", state.Speed.ToString() + " " + KPH);
            info.Add("Temperature:", state.Temperature.ToString());
            info.Add("Position:", state.X.ToString() + ", " + state.Y.ToString());

            SetInfo(state.TrainID.ToString(), info);
        }
        // METHOD: CreateTrain_Click
        //--------------------------------------------------------------------------------------
        /// <summary>
        /// Start the GUI, and create a train and train controller if in a demo
        /// </summary>
        /// 
        /// <param name="sender">Sender</param>
        /// <param name="e">Event Arguments</param>
        //--------------------------------------------------------------------------------------
        private void CreateTrain_Click(object sender, EventArgs e)
        {
            if (m_isDemo)
            {
                m_startingBlock = new TrackBlock("Block1", TrackOrientation.EastWest, new Point(0, 0), 1650, 0, 0, false, false, 70, TrackAllowedDirection.Both, false, "controller1", "controller2", "Block0", "Block2");
                m_startingBlock.NextBlock = new TrackBlock("Block2", TrackOrientation.EastWest, new Point(1650, 0), 50, 0, 0, true, false, 70, TrackAllowedDirection.Both, false, "controller1", "controller2", "Block1", "Block3");
                m_startingBlock.Authority = new BlockAuthority(70, 3);
                m_startingBlock.NextBlock.Authority = new BlockAuthority(70, 2);
                m_startingBlock.NextBlock.NextBlock = new TrackBlock("Block3", TrackOrientation.EastWest, new Point(1700, 0), 1000, 0, 0, true, false, 70, TrackAllowedDirection.Both, false, "controller1", "controller2", "Block2", "Block4");
                m_startingBlock.NextBlock.NextBlock.NextBlock = new TrackBlock("Block4", TrackOrientation.EastWest, new Point(2700, 0), 100, 0, 0, false, false, 70, TrackAllowedDirection.Both, false, "controller1", "controller2", "Block3", "Block5");
                m_startingBlock.NextBlock.NextBlock.NextBlock.NextBlock = new TrackBlock("Block5", TrackOrientation.EastWest, new Point(2800, 0), 100, 0, 0, false, false, 70, TrackAllowedDirection.Both, false, "controller1", "controller2", "Block4", "Block6");
                m_startingBlock.NextBlock.NextBlock.NextBlock.NextBlock.NextBlock = new TrackBlock("Block6", TrackOrientation.EastWest, new Point(2800, 0), 100, 0, 0, false, false, 70, TrackAllowedDirection.Both, false, "controller1", "controller2", "Block5", "Block7");
                m_startingBlock.NextBlock.NextBlock.Authority = new BlockAuthority(70, 1);

                m_startingBlock.NextBlock.NextBlock.NextBlock.Authority = new BlockAuthority(40, 0);
                m_startingBlock.NextBlock.NextBlock.NextBlock.NextBlock.Authority = new BlockAuthority(40, 0);
                m_startingBlock.NextBlock.NextBlock.NextBlock.NextBlock.NextBlock.Authority = new BlockAuthority(40, 0);

                m_startingBlock.Transponder = new Transponder("SHADYSIDE", 1);
                m_startingBlock.NextBlock.Transponder = new Transponder("SHADYSIDE", 0);

                m_myTrain = new TrainLib.Train("train1", m_startingBlock, Direction.East);
                m_myTrainState = m_myTrain.GetState();
                m_myTrainController = new TrainController(m_myTrain);
                m_myTrainController.Schedule = GetRedlineSchedule();

                Timer updateTimer = new Timer();
                updateTimer.Tick += new EventHandler(Update);
                updateTimer.Interval = 40;
                updateTimer.Enabled = true;
                updateTimer.Start();
            }

            m_myTimer = new Timer();
            m_myTimer.Tick += new EventHandler(UpdateDisplay);
            m_myTimer.Interval = 500;
            m_myTimer.Enabled = true;
            m_myTimer.Start();
        }
Exemple #10
0
        /// <summary>
        /// Sets the text information for a train
        /// </summary>
        /// <param name="train">Train</param>
        public void SetTrainInfo(ITrain train)
        {
            if (train == null) return;

            TrainState state = train.GetState();

            if (state == null) return;

            m_displayedBlock = null;
            m_displayedTrain = train;

            Dictionary<string, string> info = new Dictionary<string, string>();

            info.Add("Number of cars:", state.Cars.ToString());
            info.Add("Crew members:", state.Crew.ToString());
            info.Add("Direction:", state.Direction.ToString());
            info.Add("Door Status:", state.Doors.ToString());
            info.Add("Light Status:", state.Lights.ToString());
            info.Add("Mass:", state.Mass.ToString());
            info.Add("Passengers:", state.Passengers.ToString());
            info.Add("Speed:", string.Format("{0:0.00} {1}", state.Speed.ToString(), KPH));
            info.Add("Temperature:", state.Temperature.ToString());
            info.Add("Position:", string.Format("{0:0.00} , {1:0.00}", state.X.ToString(), state.Y.ToString()));

            if (state.TrainID != null)
            {
                SetInfo(state.TrainID.ToString(), info);
            }
            else
            {
                SetInfo(UNKNOWN_TEXT, info);
            }
        }