예제 #1
0
        }     //end track changed

        /// <summary>
        /// Updates Red Line
        /// </summary>
        private void UpdateRed()
        {
            _updateTrackMutex.WaitOne();
            //request blocks in red line
            IRouteInfo rtnfo = _env.TrackModel.requestRouteInfo(0);

            foreach (IBlock b in rtnfo.BlockList)
            {
                //find block in layout and change image
                //speed limit of 500 is unique to block id 0 (yard) on both red and green line
                if (b.SpeedLimit != 500)
                {
                    LayoutCellDataContainer c = _redLineData.TriangulateContainer(b);
                    if (c != null)
                    {
                        c.Tile = _redLineData.GetBlockType(b);
                        if (c.Panel != null)
                        {
                            string msg = "Red Line: Block ID: " + c.Block.BlockID + " is now " + c.Block.State.ToString();
                            _messages.Add(msg);
                            _env.SendLogEntry("CTC Office: " + msg);
                            c.Panel.ReDrawMe();
                        }
                    }
                }
            }
            rtnfo = null;
            _updateTrackMutex.ReleaseMutex();
        }
예제 #2
0
        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 void returnFeedback(string Feedback)
 {
     _environment.SendLogEntry(Feedback);
     if (_log.Length > 1000)
     {
         _log = "";
     }
     _log += Feedback;
 }
예제 #4
0
 /// <summary>
 /// Handles User interaction with login section of form
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void _btnLoginLogout_Click(object sender, EventArgs e)
 {
     if (_ctcOffice.IsAuth())
     {
         //if logged in.. log out
         _ctcOffice.Logout();
         //disable user controls (lock out op)
         DisableUserControls();
         _loginStatusImage.Image = _res.RedLight;
         _btnLoginLogout.Text    = "Login";
         MainDisplayLogo();
         //post to log
         _environment.SendLogEntry("CTCOffice: Operator Logged Out!");
     }
     else
     {
         //if logged out, login
         if (_ctcOffice.Login(_txtUsername.Text, _txtPassword.Text))
         {
             //if login pass (enable controls)
             EnableUserControls();
             _loginStatusImage.Image = _res.GreenLight;
             //show red line tab
             ShowRedLine();
             //remove password
             _txtPassword.Text = "";
             //change button txt
             _btnLoginLogout.Text = "Logout";
         }
         else
         {
             //if login fail (disable controls)
             DisableUserControls();
             _loginStatusImage.Image = _res.RedLight;
             _btnLoginLogout.Text    = "Login";
             //post to log
             _environment.SendLogEntry("CTCOffice: Operator Login Failed -> UnAuthorized!");
             //show logo
             MainDisplayLogo();
             //tell user invalid creds
             MessageBox.Show("Invalid Credentials", "Unauthorized", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }//end login/logout button click
예제 #5
0
        public CTCOffice(ISimulationEnvironment env, ITrackController redTC, ITrackController greenTC)
        {
            _populateTrackMutex = new Mutex(false);
            _updateTrackMutex   = new Mutex(false);
            _loadTrackMutex     = new Mutex(false);
            _rate      = 100; //num of ticks
            _tickCount = 0;
            _rate      = env.GetInterval();
            _env       = env;
            _primaryTrackControllerGreen = greenTC;
            _primaryTrackControllerRed   = redTC;

            _env.TrackModel.TrackChangedEvent += new EventHandler <EventArgs>(TrackModel_TrackChangedEvent);

            _messages = new List <string>();

            //subscribe to Environment Tick
            _env.Tick += _env_Tick;

            //create new resource wrapper
            _res = new ResourceWrapper();

            //create new operator object
            _op = new Operator();
            //set credentials
            _op.SetAuth("root", "admin");

            //create queues
            _requestsOut = new Queue <IRequest>();
            _requestsIn  = new Queue <IRequest>();

            //create queue events
            RequestQueueIn  += CTCOffice_RequestQueueIn;
            RequestQueueOut += CTCOffice_RequestQueueOut;

            //create queue processing flags / mutex
            _processingOutRequests = false;
            _processingInRequests  = false;

            _redLoaded   = false;
            _greenLoaded = false;

            _containedTrainAndBlock = new List <TrainAndBlock>();

            if (_env.TrackModel == null)
            {
                _env.SendLogEntry("CTCOffice: NULL Reference to TrackModel");
            }
        }//Constructor
예제 #6
0
        /// <summary>
        ///     Appends the given string to the information log.
        /// </summary>
        /// <param name="s">The string to to append.</param>
        private void appendInformationLog(string s)
        {
            if (_informationCount > 2000)
            {
                _informationLog   = ""; // clear the log
                _informationCount = 0;
            }

            _informationLog += "(" + DateTime.Now.ToString("h\\:mm\\:ss tt") + ") ";
            _informationLog += s + "\r\n";

            _environment.SendLogEntry("For " + this.ToString() + ": " + s);

            _informationCount++;
        }
        private void _btnSubmit_Click(object sender, EventArgs e)
        {
            double speed = ValidateSpeed();

            if (speed == -1)
            {
                //invalid do nothing (message box should alread appear)
                _env.SendLogEntry("CTCOffice:SpeedTool: Operator inserted invalid Speed.");
                MessageBox.Show("Speed cannot be negative! Please enter a positive double.");
            }
            else
            {
                if (SubmitSpeed != null)
                {
                    SubmitSpeed(this, new SpeedToolEventArgs(speed));
                }
            }
        }
        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 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;
        }
예제 #10
0
        public CTCOffice(ISimulationEnvironment env, ITrackController redTC, ITrackController greenTC)
        {
            _populateTrackMutex = new Mutex(false);
            _updateTrackMutex = new Mutex(false);
            _loadTrackMutex = new Mutex(false);
            _rate = 100; //num of ticks
            _tickCount = 0;
            _rate = env.GetInterval();
            _env = env;
            _primaryTrackControllerGreen = greenTC;
            _primaryTrackControllerRed = redTC;

            _env.TrackModel.TrackChangedEvent += new EventHandler<EventArgs>(TrackModel_TrackChangedEvent);

            _messages = new List<string>();

            //subscribe to Environment Tick
            _env.Tick += _env_Tick;

            //create new resource wrapper
            _res = new ResourceWrapper();

            //create new operator object
            _op = new Operator();
            //set credentials
            _op.SetAuth("root", "admin");

            //create queues
            _requestsOut = new Queue<IRequest>();
            _requestsIn = new Queue<IRequest>();

            //create queue events
            RequestQueueIn += CTCOffice_RequestQueueIn;
            RequestQueueOut += CTCOffice_RequestQueueOut;

            //create queue processing flags / mutex
            _processingOutRequests = false;
            _processingInRequests = false;

            _redLoaded = false;
            _greenLoaded = false;

            _containedTrainAndBlock = new List<TrainAndBlock>();

            if (_env.TrackModel == null)
            {
                _env.SendLogEntry("CTCOffice: NULL Reference to TrackModel");
            }
        }
예제 #11
0
        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;
        }